Executing offers
How to write offer execution logic
Last updated
How to write offer execution logic
Last updated
The logic associated with an offer must be implemented through a makerExecute
callback function. (See for SingleOrder
type).
order
is a containing a recap of the 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.
makerData
is an arbitrary bytes32
that will be passed to makerPosthoook
in the makerData
field.
Security concerns
Your contract should ensure that only Mangrove can call makerExecute
to avoid unwanted state change.
How to succeed
To successfully execute, the logic must not revert during the call to makerExecute
and have at least wants
outbound tokens available for Mangrove to transfer by the end of the function's execution.
How to renege on trade
The proper way to renege on an offer is to make the execution of makerExecute
throw with a reason that can be cast to a bytes32
. Having a balance of outbound tokens that is lower than order.wants
will also make trade fail, but with a higher incurred gas cost and thus a higher .
Better fail early!
The taken from the offer maker's provision is to the gas consumed by makerExecute
. To minimize costs, try to fail as early as possible.
Mangrove is guarded against reentrancy during makerExecute
The offer list for the outbound / inbound token pair is temporarily locked during calls to makerExecute
. Its offers cannot be modified in any way. The offer logic must use makerPosthook
to repost/update its offers, since the offer list will unlocked by then.
order
same as in makerExecute
.
the return value of makerExecute
None.
Security concerns
Your contract should ensure that only Mangrove can call makerPosthook
to avoid unwanted state change.
Gas management
MakerPosthook
is given the executed offer's gasreq
minus the gas used by makerExecute
.
Updating offers during posthook
Reverting
Reverting during makerPosthook
does not renege on trade, which is settled at the end of makerExecute
.
The logic associated with an offer may include a makerPosthook
callback function. Its intended use is to update offers in the containing the that was just executed.
result
A containing:
additional data sent by Mangrove, more info .
During the execution of a posthook, the executed offer's list is unlocked. This feature can be used to repost an (even the one that was just executed), possibly at a different price.