Makers

Posting a New Offer

Most offers are posted by maker contracts, which source liquidity on demand when Mangrove calls them.

  • Smart offers: offers posted via maker contracts.

  • On-the-fly offers: offers posted directly by EOAs (Externally Owned Accounts).

There are two ways to post offers and specify an offer's price:

  • newOfferByTick - price defined by a tick

  • newOfferByVolume - price defined by the ratio wants/gives.

*ByVolume is a convenience wrapper around *ByTick. Both functions return the same output and behave identically.

 function newOfferByTick(
    OLKey memory olKey,
    Tick tick, 
    uint gives, 
    uint gasreq, 
    uint gasprice
) external payable returns (uint offerId);

function newOfferByVolume(
    OLKey memory olKey,
    uint wants,
    uint gives,
    uint gasreq,
    uint gasprice
) external payable returns (uint offerId);

Both functions are payable. A non-zero msg.value will credit the maker's Mangrove balance before locking the offer's provision.

Inputs

  • olKey: identifies the offer list

    • outbound_tkn: token sent by the offer

    • inbound_tkn: token received by the offer

    • tickSpacing: spacing between valid ticks (see Ticks, ratios, and prices)

  • gives: amount of outbound_tkn promised by the offer.

    • Must be > 0 and fit in 127 bits.

    • Must meet offer list density and gasreq constraints.

  • gasreq: gas made available to the offer execution logic.

  • gasprice: gas price override in Mwei/gas used to compute the order provision (see offer bounties).

    • Lower values than Mangrove's current gasprice are ignored (thus 0 means "use Mangrove's current gasprice").

    • Must fit in 26 bits.

newOfferByTick(olKey, tick, gives, gasreq, gasprice)

  • tick: the desired "price" tick.

    The actual tick is rounder up to the nearest valid tick satisfying offerTick % tickSpacing == 0.

newOfferByVolume(olKey, wants, gives, gasreq, gasprice)

  • wants: the amount of inbound tokens requested by the offer.

  • Must fit in 127 bits and be strictly positive.

  • The ratio wants/gives (rounded down) specifies the desired "price" ratio and thus tick.

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 if they belong to different offer lists.

Provisioning

Each offer must be provisioned in native tokens. If an offer fails, a portion of its provision compensates the taker for gas spent.

Ensure your maker contract holds enough provision before posting an offer. You can fund it by sending native tokens to Mangrove; the balance is stored and reused automatically.

Offer Execution

If the offer’s account is a contract, it must implement the IMaker interface:

Otherwise, Mangrove will revert on execution.

The offer account must also:

  • Maintain a sufficient ERC20 allowance for outbound_tkn (used via transferFrom).

  • Satisfy density requirements (tokens per gas spent).

Example

Events

Event
Description

OfferWrite

Emitted when a new offer is written to the order book.

DebitWei

Emitted when the maker’s Mangrove balance is debited to cover offer provision.

CreditWei

Emitted when the maker’s Mangrove balance is credited (e.g., from msg.value).

Event definitions

Gatekeeping and Errors

Error
Meaning

mgv/dead

Mangrove contract is terminated

mgv/inactive

Target market is inactive

mgv/offerIdOverflow

Max number of offers (2²⁴) reached

mgv/writeOffer/gasprice/tooBig

Gas price too large

mgv/writeOffer/gives/tooBig

Offer volume too large

mgv/writeOffer/gasreq/tooHigh

Gasreq above gasmax

mgv/writeOffer/gives/tooLow

Gives must be > 0

mgv/writeOffer/density/tooLow

Density too low

mgv/writeOffer/tick/outOfRange

Tick invalid

mgv/insufficientProvision

Maker provision insufficient

Updating an Offer

Offers can be updated using the same two price-specification methods:

  • updateOfferByTick

  • updateOfferByVolume

updateOfferByVolume converts the volumes into a tick internally. Both versions are payable and can top up the maker’s balance via msg.value.

Inputs

  • offerId — ID of the offer to update

  • All other parameters are identical to newOfferByTick and newOfferByVolume (see above)

Output

  • None

Offer Updater

Only the creator of the offer (msg.sender) can update it. Unauthorized calls revert with mgv/updateOffer/unauthorized.

Example

Events

Event
Description

OfferWrite

Emitted when an offer is updated.

DebitWei

Maker debited if provision needs to increase.

CreditWei

Maker credited if provision decreased.

Reusing Offers

Executed or retracted offers are removed from the offer list but can be updated and reinserted. Updating existing offers is significantly cheaper than creating new ones.

Gatekeeping and Errors

Error
Meaning

mgv/dead

Mangrove is terminated

mgv/inactive

Offer list is inactive

mgv/writeOffer/gives/tooLow

Gives ≤ 0

mgv/writeOffer/gasreq/tooHigh

Gasreq above limit

mgv/writeOffer/density/tooLow

Density constraint not met

mgv/updateOffer/unauthorized

Caller not offer owner

mgv/insufficientProvision

Provision insufficient

Retracting an offer

An offer can be withdrawn from the order book using retractOffer .

Inputs

  • olKey — identifies the offer list

  • offerId — ID of the offer to retract

  • deprovision — if true, releases the offer’s provision (in wei)

Output

  • provision — amount of native tokens released (in wei)

Example

If you choose to deprovision, you can later withdraw the funds using:

Events

Event
Description

OfferRetract

Emitted when an offer is removed from the book.

Credit

Emitted when provision is released back to the maker.

Authorization

Only the maker contract that created the offer may call retractOffer. Unauthorized calls revert with mgv/retractOffer/unauthorized.

Last updated