D3Maker#
D3Maker is a dependent price controll model. Maker could set token price and other price parameters to control swap. The key part is MakerState(in D3Maker) and flag(in D3MM) parameter. MakerState contains token price, amount and swap fee. Specially for token price, which is supposed to be set frequently, we use one slot to compress 3 token price with dependent price array. Flags in D3MM decide whether this token's cumulative volumn change, which means resetting integral start point. Every function should reset cumulative volumn.
maker could not delete token function
init#
function init(
address owner,
address pool,
uint256 maxInterval
) external
Initializes the contract with the owner, pool, and maxInterval
Parameters:
Name | Type | Description |
---|---|---|
owner | address | The address of the owner |
pool | address | The address of the pool |
maxInterval | uint256 | The maximum interval |
getTokenMMInfoForPool#
function getTokenMMInfoForPool(
address token
) external view returns (Types.TokenMMInfo tokenMMInfo,
uint256 tokenIndex)
Returns the TokenMMInfo for a given token
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token |
Return Values:
Name | Type | Description |
---|---|---|
tokenMMInfo | struct Types.TokenMMInfo | The TokenMMInfo of the token |
tokenIndex | uint256 | The index of the token |
getOneTokenPriceSet#
function getOneTokenPriceSet(
address token
) public view returns (uint80 priceSet)
This function returns the price set for a given token
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token |
Return Values:
Name | Type | Description |
---|---|---|
priceSet | uint80 | The price set of the token |
getOneTokenOriginIndex#
function getOneTokenOriginIndex(
address token
) public view returns (int256)
get one token index. odd for none-stable, even for stable, true index = (tokenIndex[address] - 1) / 2
Parameters:
Name | Type | Description |
---|---|---|
token | address | The address of the token |
getStableTokenInfo#
function getStableTokenInfo() external view returns (uint256 numberOfStable,
uint256[] tokenPriceStable,
uint256 curFlag)
get all stable token Info
Return Values:
Name | Type | Description |
---|---|---|
numberOfStable | uint256 | stable tokens' quantity |
tokenPriceStable | uint256[] | stable tokens' price slot array. each data contains up to 3 token prices |
curFlag | uint256 | current flags for all token in one slot |
getNSTokenInfo#
function getNSTokenInfo() external view returns (uint256 number,
uint256[] tokenPrices,
uint256 curFlag)
get all non-stable token Info
Return Values:
Name | Type | Description |
---|---|---|
number | uint256 | stable tokens' quantity |
tokenPrices | uint256[] | stable tokens' price slot array. each data contains up to 3 token prices |
curFlag | uint256 | current flags for all token in one slot |
stickPrice#
function stickPrice(
uint256 priceSlot,
uint256 slotInnerIndex,
uint256 priceSet
) public pure returns (uint256 newPriceSlot)
used for construct several price in one price slot
Parameters:
Name | Type | Description |
---|---|---|
priceSlot | uint256 | origin price slot |
slotInnerIndex | uint256 | token index in slot |
priceSet | uint256 | the token info needed to update |
checkHeartbeat#
function checkHeartbeat() public view returns (bool)
check heartbeat
getPoolTokenListFromMaker#
function getPoolTokenListFromMaker() external view returns (address[] tokenlist)
get pool's token list
multicall#
function multicall(
bytes[] data
) external returns (bytes[] results)
maker could use multicall to set different params in one tx.
Parameters:
Name | Type | Description |
---|---|---|
data | bytes[] | A list of calldata to call |
setNewToken#
function setNewToken(
address token,
bool stableOrNot,
uint80 priceSet,
uint64 amountSet,
uint16 kAsk,
uint16 kBid
) external
maker set a new token info
Parameters:
Name | Type | Description |
---|---|---|
token | address | token's address |
stableOrNot | bool | describe this token is stable or not, true = stable coin |
priceSet | uint80 | packed price, [mid price(16) |
amountSet | uint64 | describe ask and bid amount and K, [ask amounts(16) |
kAsk | uint16 | k of ask curve |
kBid | uint16 | k of bid curve |
setTokensPrice#
function setTokensPrice(
address[] tokens,
uint80[] tokenPrices
) external
set token prices
Parameters:
Name | Type | Description |
---|---|---|
tokens | address[] | token address set |
tokenPrices | uint80[] | token prices set, each number pack one token all price.Each format is the same with priceSet [mid price(16) |
setNSPriceSlot#
function setNSPriceSlot(
uint256[] slotIndex,
uint256[] priceSlots,
uint256 newAllFlag
) external
user set PriceListInfo.tokenPriceNS price info, only for none-stable coin
maker should be responsible for data availability
Parameters:
Name | Type | Description |
---|---|---|
slotIndex | uint256[] | tokenPriceNS index |
priceSlots | uint256[] | tokenPriceNS price info, every data has packed all 3 token price info |
newAllFlag | uint256 | maker update token cumulative status, for allFlag, tokenOriIndex represent bit index in allFlag. eg: tokenA has origin index 3, that means (allFlag >> 3) & 1 = token3's flag flag = 0 means to reset cumulative. flag = 1 means not to reset cumulative. |
setStablePriceSlot#
function setStablePriceSlot(
uint256[] slotIndex,
uint256[] priceSlots,
uint256 newAllFlag
) external
user set PriceListInfo.tokenPriceStable price info, only for stable coin
maker should be responsible for data availability
Parameters:
Name | Type | Description |
---|---|---|
slotIndex | uint256[] | tokenPriceStable index |
priceSlots | uint256[] | tokenPriceStable price info, every data has packed all 3 token price info |
newAllFlag | uint256 | maker update token cumulative status, for allFlag, tokenOriIndex represent bit index in allFlag. eg: tokenA has origin index 3, that means (allFlag >> 3) & 1 = token3's flag flag = 0 means to reset cumulative. flag = 1 means not to reset cumulative. |
setTokensAmounts#
function setTokensAmounts(
address[] tokens,
uint64[] tokenAmounts
) external
set token Amounts
Parameters:
Name | Type | Description |
---|---|---|
tokens | address[] | token address set |
tokenAmounts | uint64[] | token amounts set, each number pack one token all amounts.Each format is the same with amountSetAndK [ask amounts(16) |
setTokensKs#
function setTokensKs(
address[] tokens,
uint32[] tokenKs
) external
set token Ks
Parameters:
Name | Type | Description |
---|---|---|
tokens | address[] | token address set |
tokenKs | uint32[] | token k_ask and k_bid, structure like [kAsk(16) |
setHeartbeat#
function setHeartbeat(
uint256 newMaxInterval
) public
set acceptable setting interval, if setting gap > maxInterval, swap will revert.
Parameters:
Name | Type | Description |
---|---|---|
newMaxInterval | uint256 | The new max interval for heartbeat |