Offer provisions

How taker compensation for failing offers works.

Summary

When an offer fails, the caller has wasted some gas. To compensate the caller, Mangrove gives them a bounty in native tokens. Offers must provision enough ethers to maximize the chances that Mangrove can compensate the caller. In more details:

  • Every offer logic that posted an offer has a balance in ethers held by Mangrove. Funds can be freely added to or withdrawn from the balance.

  • Whenever the logic creates or updates an offer, its balance is adjusted so that enough native tokens are locked as the offer's provision.

    • If the offer is retracted that provision is credited back to the logic's account balance.

    • If the offer is executed and fails, part or all of the provision is sent as compensation, to the caller. We call that the bounty. The rest of the provision is credited back to the offer logic's account balance.

Balance funding & withdrawal

Funding an offer

There are three ways an offer logic can credit its balance on Mangrove. (1) The logic may either call the fund function, or (2) make a call to the fallback function with some value, or (3) pay on the fly when a new offer is posted.

function fund(address maker) public payable;

Inputs

  • maker the offer logic's balance on Mangrove to credit

Checking an account balance

function balanceOf(address who) external view returns (uint balance);

Inputs

  • who The account of which you want to read the balance.

Outputs

  • balance The available balance of who.

Withdrawing

At any time, your available balance can be withdrawn. It may be less than what you deposited: your balance adjusts every time you create/update an offer.

function withdraw(uint amount) external returns (bool noRevert);

Inputs

  • amount the amount of ethers (in wei) one wishes to withdraw from Mangrove's provisions.

Outputs

  • noRevert whether the ether transfer was successful.

Balance adjustment when creating/updating offers

Whenever an offer is created or updated, Mangrove applies to following formula to get the offer's required provision in wei:

provision=max(gaspricemgv,gaspriceofr)×(gasreq+gasbasemgv)×109\textrm{provision} = \max(\textrm{gasprice}_{\textrm{mgv}},\textrm{gasprice}_{\textrm{ofr}}) \times (\textrm{gasreq} + \textrm{gasbase}_{\textrm{mgv}}) \times 10^9

  • gaspricemgv\textrm{gasprice}_{\textrm{mgv}} is the gasprice global governance parameter (in gwei per gas units)

  • gaspriceofr\textrm{gasprice}_{\textrm{ofr}} is the gasprice argument of the function being called (newOffer or updateOffer) also in gwei per gas units.

  • gasreq\textrm{gasreq} is the gasreq argument of the function being called (in gas units).

  • gasbasemgv\textrm{gasbase}_{\rm mgv}is the offer_gasbase local governance parameter.

Mangrove will adjust the balance of the caller to ensure that provision\textrm{provision} wei are available as bounty if the offer fails. If the offer was already provisioned, the adjustment may be small, and the balance may actually increase -- for instance, if the gasprice dropped recently.

Incentivized book cleaning

Provisions are calculated so that, within reasonable gas estimates, taking a failing offer should be profitable for the taker.

Provision and offer bounty

getProvision.sol
import "src/IMangrove.sol";
import {MgvStructs} from "src/MgvLib.sol";
//context 
IMangrove mgv;
address outbound_tkn;
address inbound_tkn;
uint offer_gasreq;
(MgvStructs.GlobalPacked global32, MgvStructs.LocalPacked local32) = mgv.config(outbound_tkn, inbound_tkn);

// computing minimal provision to cover an offer requiring `offer_gasreq` gas units 
uint provision = (offer_gasreq + local32.offer_gasbase()) * global32.gasprice() * 10 ** 9;

Last updated