Skip to main content

KandelLib

KandelLib​

transportDestination​

function transportDestination(enum OfferType ba, uint256 index, uint256 step, uint256 pricePoints) internal pure returns (uint256 better)

returns the destination index to transport received liquidity to - a better (for Kandel) price index for the offer type.

Parameters​

NameTypeDescription
baenum OfferTypethe offer type to transport to
indexuint256the price index one is willing to improve
stepuint256the number of price steps improvements
pricePointsuint256the number of price points

Return Values​

NameTypeDescription
betteruint256destination index

createGeometricDistribution​

function createGeometricDistribution(uint256 from, uint256 to, Tick baseQuoteTickIndex0, uint256 _baseQuoteTickOffset, uint256 firstAskIndex, uint256 bidGives, uint256 askGives, uint256 pricePoints, uint256 stepSize) external pure returns (struct DirectWithBidsAndAsksDistribution.Distribution distribution)

Creates a distribution of bids and asks given by the parameters. Dual offers are included with gives=0.

the absolute price of an offer is the ratio of quote/base volumes of tokens it trades the tick of offers on Mangrove are in relative taker price of maker's inbound/outbound volumes of tokens it trades for Bids, outbound_tkn=quote, inbound_tkn=base so relative taker price of a a bid is the inverse of the absolute price. for Asks, outbound_tkn=base, inbound_tkn=quote so relative taker price of an ask coincides with absolute price. Index0 will contain the ask with the lowest relative price and the bid with the highest relative price. Absolute price is geometrically increasing over indexes. tickOffset moves an offer relative price s.t. `AskTick{i+1} = AskTicki + tickOffsetandBidTick{i+1} = BidTicki - tickOffsetA hole is left in the middle at the size of stepSize - either an offer or its dual is posted, not both. The caller should make sure the minimum and maximum tick does not exceed the MIN_TICK and MAX_TICK from respectively; otherwise, populate will fail for those offers. If type(uint).max is used forbidGivesoraskGives` then very high or low prices can yield gives=0 (which results in both offer an dual being dead) or gives>=type(uin96).max which is not supported by Mangrove.

Parameters​

NameTypeDescription
fromuint256populate offers starting from this index (inclusive). Must be at most pricePoints.
touint256populate offers until this index (exclusive). Must be at most pricePoints.
baseQuoteTickIndex0Tickthe tick for the price point at index 0 given as a tick on the base, quote offer list, i.e. corresponding to an ask with a quote/base ratio. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
_baseQuoteTickOffsetuint256the tick offset used for the geometric progression deployment. Must be at least 1. It is recommended that this is a multiple of tickSpacing for the offer lists to avoid rounding.
firstAskIndexuint256the (inclusive) index after which offer should be an ask. Must be at most pricePoints.
bidGivesuint256The initial amount of quote to give for all bids. If 0, only book the offer, if type(uint).max then askGives is used as base for bids, and the quote the bid gives is set to according to the price.
askGivesuint256The initial amount of base to give for all asks. If 0, only book the offer, if type(uint).max then bidGives is used as quote for asks, and the base the ask gives is set to according to the price.
pricePointsuint256the number of price points for the Kandel instance. Must be at least 2.
stepSizeuint256in amount of price points to jump for posting dual offer. Must be less than pricePoints.

Return Values​

NameTypeDescription
distributionstruct DirectWithBidsAndAsksDistribution.Distributionthe distribution of bids and asks to populate