Maker contract
Overview
Trade Execution
function makerExecute(MgvLib.SingleOrder calldata order)
internal
returns (uint gasused, bytes32 makerData);Example
import {IERC20, IMaker, SingleOrder} from "@mgv/src/core/MgvLib.sol";
contract MyOffer is IMaker {
// IMangrove mgv = IMangrove(payable(<address of Mangrove>));
// Mangrove contract
IMangrove mgv = IMangrove(payable(mgv));
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 market order.
function makerExecute(MgvLib.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.offer.gives()).balanceOf(address(this)) >= order.offer.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.offer.wants()).transfer(reserve, order.offer.gives());
// this string will be passed to `makerPosthook`
return "MyOffer/tradeSuccess";
}
}Inputs
Outputs
Important Notes
Security
Failing Early
Gas Efficiency
Reentrancy Protection
Locked Offer List
Trade Posthook
Example
Inputs
Outputs
Important Notes
Last updated
Was this helpful?