Skip to main content

CoreKandel

CoreKandel​

CoreKandel is agnostic to the chosen price distribution.

SetGasprice​

event SetGasprice(uint256 value)

the gasprice has been set. By emitting this data, an indexer will be able to keep track of what gasprice is used.

Parameters​

NameTypeDescription
valueuint256the gasprice for offers.

SetGasreq​

event SetGasreq(uint256 value)

the gasreq has been set. By emitting this data, an indexer will be able to keep track of what gasreq is used.

Parameters​

NameTypeDescription
valueuint256the gasreq (including router's gasreq) for offers

SetStepSize​

event SetStepSize(uint256 value)

the step size has been set.

Parameters​

NameTypeDescription
valueuint256the step size in amount of price points to jump for posting dual offer

Credit​

event Credit(contract IERC20 token, uint256 amount)

the Kandel instance is credited of amount by its owner. By emitting this data, an indexer will be able to keep track of what credits are made.

Parameters​

NameTypeDescription
tokencontract IERC20the asset. This is indexed so that RPC calls can filter on it.
amountuint256the amount.

Debit​

event Debit(contract IERC20 token, uint256 amount)

the Kandel instance is debited of amount by its owner. By emitting this data, an indexer will be able to keep track of what debits are made.

Parameters​

NameTypeDescription
tokencontract IERC20the asset. This is indexed so that RPC calls can filter on it.
amountuint256the amount.

Params​

Core Kandel parameters

Parameters​

NameTypeDescription
struct Params {
uint32 gasprice;
uint24 gasreq;
uint32 stepSize;
uint32 pricePoints;
}

params​

struct CoreKandel.Params params

Storage of the parameters for the strat.

setStepSize​

function setStepSize(uint256 stepSize) public

sets the step size

Parameters​

NameTypeDescription
stepSizeuint256the step size.

setGasprice​

function setGasprice(uint256 gasprice) public

sets the gasprice for offers

Parameters​

NameTypeDescription
gaspriceuint256the gasprice.

setGasreq​

function setGasreq(uint256 gasreq) public

sets the gasreq (including router's gasreq) for offers

Parameters​

NameTypeDescription
gasrequint256the gasreq.

setParams​

function setParams(struct CoreKandel.Params newParams) internal

Updates the params to new values.

Parameters​

NameTypeDescription
newParamsstruct CoreKandel.Paramsthe new params to set.

constructor​

constructor(contract IMangrove mgv, struct OLKey olKeyBaseQuote, address reserveId) internal

Constructor

Parameters​

NameTypeDescription
mgvcontract IMangroveThe Mangrove deployment.
olKeyBaseQuotestruct OLKeyThe OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.
reserveIdaddressidentifier of this contract's reserve when using a router.

populate​

function populate(struct DirectWithBidsAndAsksDistribution.Distribution distribution, struct CoreKandel.Params parameters, uint256 baseAmount, uint256 quoteAmount) public payable

publishes bids/asks for the distribution in the indices. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead).

This function is used at initialization and can fund with provision for the offers. Use populateChunk to split up initialization or re-initialization with same parameters, as this function will emit. If this function is invoked with different pricePoints or stepSize, then first retract all offers. msg.value must be enough to provision all posted offers (for chunked initialization only one call needs to send native tokens).

Parameters​

NameTypeDescription
distributionstruct DirectWithBidsAndAsksDistribution.Distributionthe distribution of bids and asks to populate
parametersstruct CoreKandel.Paramsthe parameters for Kandel. Only changed parameters will cause updates. Set gasreq and gasprice to 0 to keep existing values.
baseAmountuint256base amount to deposit
quoteAmountuint256quote amount to deposit

populateChunk​

function populateChunk(struct DirectWithBidsAndAsksDistribution.Distribution distribution) external

Publishes bids/asks for the distribution in the indices. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead). This function is used externally after populate to reinitialize some indices or if multiple transactions are needed to split initialization due to gas cost. This function is not payable, use populate to fund along with populate.

Parameters​

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

reserveBalance​

function reserveBalance(enum OfferType ba) public view virtual returns (uint256 balance)

the total balance available for the strat of the offered token for the given offer type.

Parameters​

NameTypeDescription
baenum OfferTypethe offer type.

Return Values​

NameTypeDescription
balanceuint256the balance of the token.

logUpdateOfferStatus​

function logUpdateOfferStatus(uint256 offerId, struct IOfferLogic.OfferArgs args, bytes32 updateOfferStatus) internal

takes care of status for updating dual and logging of potential issues.

Parameters​

NameTypeDescription
offerIduint256the Mangrove offer id.
argsstruct IOfferLogic.OfferArgsthe arguments of the offer.
updateOfferStatusbytes32the status returned from the _updateOffer function.

transportSuccessfulOrder​

function transportSuccessfulOrder(struct MgvLib.SingleOrder order) internal

update or create dual offer according to transport logic

Parameters​

NameTypeDescription
orderstruct MgvLib.SingleOrderis a recall of the taker order that is at the origin of the current trade.

transportLogic​

function transportLogic(enum OfferType ba, struct MgvLib.SingleOrder order) internal virtual returns (uint256 dualOfferId, struct IOfferLogic.OfferArgs args)

transport logic followed by Kandel

Parameters​

NameTypeDescription
baenum OfferTypewhether the offer that was executed is a bid or an ask
orderstruct MgvLib.SingleOrdera recap of the taker order (order.offer is the executed offer)

Return Values​

NameTypeDescription
dualOfferIduint256the offer id of the dual offer
argsstruct IOfferLogic.OfferArgsthe argument for updating an offer

pending​

function pending(enum OfferType ba) external view returns (int256)

gets pending liquidity for base (ask) or quote (bid). Will be negative if funds are not enough to cover all offer's promises.

Gas costly function, better suited for off chain calls.

Parameters​

NameTypeDescription
baenum OfferTypeoffer type.

Return Values​

NameTypeDescription
[0]int256the pending amount

depositFunds​

function depositFunds(uint256 baseAmount, uint256 quoteAmount) public virtual

Deposits funds to the contract's reserve

Parameters​

NameTypeDescription
baseAmountuint256the amount of base tokens to deposit.
quoteAmountuint256the amount of quote tokens to deposit.

withdrawFunds​

function withdrawFunds(uint256 baseAmount, uint256 quoteAmount, address recipient) public virtual

withdraws funds from the contract's reserve

it is up to the caller to make sure there are still enough funds for live offers.

Parameters​

NameTypeDescription
baseAmountuint256the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
quoteAmountuint256the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
recipientaddressthe address to which the withdrawn funds should be sent to.

withdrawFundsForToken​

function withdrawFundsForToken(contract IERC20 token, uint256 amount, address recipient) internal virtual

withdraws funds from the contract's reserve for the given token

Parameters​

NameTypeDescription
tokencontract IERC20the token to withdraw.
amountuint256the amount of tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
recipientaddressthe address to which the withdrawn funds should be sent to.

retractAndWithdraw​

function retractAndWithdraw(uint256 from, uint256 to, uint256 baseAmount, uint256 quoteAmount, uint256 freeWei, address payable recipient) external

Retracts offers, withdraws funds, and withdraws free wei from Mangrove.

Parameters​

NameTypeDescription
fromuint256retract offers starting from this index.
touint256retract offers until this index.
baseAmountuint256the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
quoteAmountuint256the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.
freeWeiuint256the amount of wei to withdraw from Mangrove. Use type(uint).max to withdraw entire available balance.
recipientaddress payablethe recipient of the funds.