Creating & Updating offers
How to write Mangrovian offers
Last updated
How to write Mangrovian offers
Last updated
New offers should mostly be posted by able to source liquidity when asked by Mangrove.
Inputs
outbound_tkn
address of the outbound token (that the offer will provide).
inbound_tkn
address of the inbound token (that the offer will receive).
wants
amount of inbound tokens requested by the offer. Must fit in a uint96
.
gives
amount of outbound **** tokens promised by the offer. Must fit in a uint96
and be strictly positive. Must provide enough volume w.r.t to gasreq
and offer list's parameter.
gasreq
amount of gas that will be given to the offer's . Must fit in a uint24
and be lower than . Should be sufficient to cover all calls to the offer logic posting the offer ( and ). Must be compatible with the offered volume gives
and the offer list's parameter.
gasprice
gas price override used to compute the order provision (see ). Any value lower than Mangrove's current will be ignored (thus 0 means "use Mangrove's current "). Must fit in a uint16
.
pivotId
where to start the insertion process in the offer list. If pivotId
is not in the offer list at the time the transaction is processed, the new offer will be inserted starting from the offer list's offer. Should be the id of the existing live offer with the price closest to the price of the offer being posted.
Outputs
Provisioning
Offer execution
The offer account will need to give Mangrove a high enough allowance in outbound tokens since Mangrove will use the ERC20 standard's transferFrom
function to source your tokens.
offerId
is the offer id of the offer to be updated.
None.
Reusing offers
An offer can be withdrawn from the order book via the retractOffer
function described below.
offerId
is the offer id of the offer to be updated.
None.
offerId
the id of the newly created offer. Note that offer ids are scoped to , so many offers can share the same id.
Since offers can fail, Mangrove requires each offer to be in ETH. If an offer fails, part of that provision will be sent to the caller that executed the offer, as compensation.
Make sure that your offer is before calling newOffer
, otherwise the call will fail. The easiest way to go is to send a comfortable amount of ETH to Mangrove from your offer-posting contract. Mangrove will remember your ETH balance and use it when necessary.
If the offer account is a contract, it should implement the interface. At the very least, it must have a function with signature or it will systematically revert when called by Mangrove.
gives
and gasreq
are subject to constraints on the amount of outbound token provided per gas spent.
Offers are updated through the aptly-named updateOffer
function described below (source code is ).
For the other parameters, see .
An offer can only be updated if msg.sender
is the that created the offer.
After being executed or , an offer is moved out of the offer list. It can still be updated and reinserted in the offer list. We recommend updating offers instead of creating new ones, as it costs much less gas.
deprovision
if true, will free the offer's ETH provision so that you can them. Otherwise, will leave the provision in the offer.
For the other parameters, see .