Executing offers
How to write offer execution logic
Offer Logic
function makerExecute(MgvLib.SingleOrder calldata order)
external returns (bytes32 makerData);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
Outputs
Offer post-hook
Inputs
Outputs
Last updated
Was this helpful?