For the complete documentation index, see llms.txt. This page is also available as Markdown.

Executing offers

How to write offer execution logic

Offer Logic

The logic associated with an offer must be implemented through a makerExecute callback function. (See data structures for SingleOrder type).

function makerExecute(MgvLib.SingleOrder calldata order)
external returns (bytes32 makerData);
MakerContract-0.sol
import {IERC20, IMaker, SingleOrder} "src/MgvLib.sol";

contract MyOffer is IMaker {
    address MGV; // address of Mangrove
    address reserve; // token reserve for inbound tokens
    
    // an example of offer execution that simply verifies that `this` contract has enough outbound tokens to satisfy the taker Order.
    function makerExecute(SingleOrder calldata order) 
    external returns (bytes32 makerData){
        // revert below (in case of insufficient funds) to signal mangrove we renege on trade
        // reverting as soon as early to minimize bounty
        require(
           IERC20(order.outbound_tkn).balanceOf(address(this)) >= order.wants),
           "MyOffer/NotEnoughFunds";
        );
        // do not perform any state changing call if caller is not Mangrove!
        require(msg.sender == MGV, "MyOffer/OnlyMangroveCanCallMe");
        // `order.gives` has been transfered by Mangrove to `this` balance
        // sending incoming tokens to reserve
        IERC20(order.inbound_tkn).transfer(reserve, order.gives);
        // this string will be passed to `makerPosthook`
        return "MyOffer/tradeSuccess";
    }
}
    
    

Inputs

  • order is a data structure containing a recap of the taker order and Mangrove's current configuration state. The protocol guarantees that order.gives/order.wants will match the price of the offer that is being executed up to a small precision.

Outputs

  • makerData is an arbitrary bytes32 that will be passed to makerPosthoook in the makerData field.

Offer post-hook

The logic associated with an offer may include a makerPosthook callback function. Its intended use is to update offers in the offer list containing the offer that was just executed.

Inputs

  • order same as in makerExecute.

  • result A struct containing:

    • the return value of makerExecute

    • additional data sent by Mangrove, more info available here.

Outputs

None.