Creating & Updating offers

How to write Mangrovian offers

Posting a new offer

New offers should mostly be posted by contracts able to source liquidity when asked by Mangrove.

newOffer is payable and can be used to credit the Offer Logic's balance on Mangrove on the fly. A non zero msg.value will allow Mangrove to credit Offer Logic's balance prior to locking the provision of the newly posted offer.

function newOffer(
    address outboundTkn,
    address inboundTkn,
    uint wants, // amount of inbound Tokens
    uint gives, // amount of outbound Tokens
    uint gasreq,
    uint gasprice,
    uint pivotId
) external payable returns (uint offerId);

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 density parameter.

  • gasreq amount of gas that will be given to the offer's account. Must fit in a uint24 and be lower than gasmax. Should be sufficient to cover all calls to the offer logic posting the offer (makerExecute and makerPosthook). Must be compatible with the offered volume gives and the offer list's density parameter.

  • gasprice gas price override used to compute the order provision (see offer bounties). Any value lower than Mangrove's current gasprice will be ignored (thus 0 means "use Mangrove's current gasprice"). 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 best offer. Should be the id of the existing live offer with the price closest to the price of the offer being posted.

Outputs

  • offerId the id of the newly created offer. Note that offer ids are scoped to offer lists, so many offers can share the same id.

Updating an existing offer

Offers are updated through the aptly-named updateOffer function described below (source code is here).

function updateOffer( 
    address outboundToken, 
    address inboundToken, 
    uint wants, 
    uint gives, 
    uint gasreq, 
    uint gasprice, 
    uint pivotId, 
    uint offerId
) external;

Inputs

  • offerId is the offer id of the offer to be updated.

  • For the other parameters, see above.

Outputs

None.

Offer updater

An offer can only be updated if msg.sender is the account that created the offer.

Retracting an offer

An offer can be withdrawn from the order book via the retractOffer function described below.

function retractOffer(
    address outboundToken,
    address inboundToken,
    uint offerId,
    bool deprovision
  ) external;

Inputs

  • offerId is the offer id of the offer to be updated.

  • deprovision if true, will free the offer's ETH provision so that you can withdraw them. Otherwise, will leave the provision in the offer.

  • For the other parameters, see above.

Outputs

None.

Last updated