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:

NameTypeDescription
owneraddressThe address of the owner
pooladdressThe address of the pool
maxIntervaluint256The maximum interval

getTokenMMInfoForPool#

function getTokenMMInfoForPool(
    address token
) external view returns (Types.TokenMMInfo tokenMMInfo,
    uint256 tokenIndex)

Returns the TokenMMInfo for a given token

Parameters:

NameTypeDescription
tokenaddressThe address of the token

Return Values:

NameTypeDescription
tokenMMInfostruct Types.TokenMMInfoThe TokenMMInfo of the token
tokenIndexuint256The 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:

NameTypeDescription
tokenaddressThe address of the token

Return Values:

NameTypeDescription
priceSetuint80The 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:

NameTypeDescription
tokenaddressThe address of the token

getStableTokenInfo#

function getStableTokenInfo() external view returns (uint256 numberOfStable,
    uint256[] tokenPriceStable,
    uint256 curFlag)

get all stable token Info

Return Values:

NameTypeDescription
numberOfStableuint256stable tokens' quantity
tokenPriceStableuint256[]stable tokens' price slot array. each data contains up to 3 token prices
curFlaguint256current 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:

NameTypeDescription
numberuint256stable tokens' quantity
tokenPricesuint256[]stable tokens' price slot array. each data contains up to 3 token prices
curFlaguint256current 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:

NameTypeDescription
priceSlotuint256origin price slot
slotInnerIndexuint256token index in slot
priceSetuint256the 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:

NameTypeDescription
databytes[]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:

NameTypeDescription
tokenaddresstoken's address
stableOrNotbooldescribe this token is stable or not, true = stable coin
priceSetuint80packed price, [mid price(16)
amountSetuint64describe ask and bid amount and K, [ask amounts(16)
kAskuint16k of ask curve
kBiduint16k of bid curve

setTokensPrice#

function setTokensPrice(
    address[] tokens,
    uint80[] tokenPrices
) external

set token prices

Parameters:

NameTypeDescription
tokensaddress[]token address set
tokenPricesuint80[]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:

NameTypeDescription
slotIndexuint256[]tokenPriceNS index
priceSlotsuint256[]tokenPriceNS price info, every data has packed all 3 token price info
newAllFlaguint256maker 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:

NameTypeDescription
slotIndexuint256[]tokenPriceStable index
priceSlotsuint256[]tokenPriceStable price info, every data has packed all 3 token price info
newAllFlaguint256maker 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:

NameTypeDescription
tokensaddress[]token address set
tokenAmountsuint64[]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:

NameTypeDescription
tokensaddress[]token address set
tokenKsuint32[]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:

NameTypeDescription
newMaxIntervaluint256The new max interval for heartbeat