Maker contract
Info : A maker contract is a smart contract that is bound to an offer posted on Mangrove. It is the contract that is called by Mangrove should the offer be matched during a market order. The offer logic is the part of the maker contract that executes as a consequence of a call by Mangrove. The offer logic is split into trade execution and trade posthook.
Trade Execution
The logic associated with an offer must be implemented in the makerExecute
callback function. (See data structures for SingleOrder
type).
Inputs
sor
is a data structure containing a recap of the market order and Mangrove's current configuration state.It also contains
olKey
, which concerns the entire market order, because it will be sent to the maker, who needs that information.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
gasused
is the gas consumed by the execution.makerData
is an arbitrarybytes32
returned after executing the offer. It will be passed tomakerPosthoook
in themakerData
field.
Important notes
Security concerns
Your contract should ensure that only Mangrove can call
makerExecute
to avoid unwanted state change.The prev/next pointers from an offer are removed before sending it to the maker. This ensures that the maker has no information about the state of the book when it gets called. More information in the data structure table.
How to succeed
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 abytes32
.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 bounty.
Better fail early
The bounty taken from the offer maker's provision is proportional to the gas consumed by
makerExecute
. To minimize costs, try to fail as early as possible.
Mangrove is guarded against reentrancy during makerExecute
[ADD details about READ not being possible]
:::
Trade posthook
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.
!!![code Offer Logic TBD]!!!
Inputs
sor
is the same as inmakerExecute
.result
is a struct containing:the return value of
makerExecute
additional data sent by Mangrove, more info available here.
Outputs
None.
Important notes
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'sgasreq
minus the gas used bymakerExecute
.Updating offers during posthook: during the execution of a posthook, the executed offer's list is unlocked. This feature can be used to repost an offer (even the one that was just executed), possibly at a different price.
Reverting**
Reverting during
makerPosthook
does not renege on trade, which is settled at the end ofmakerExecute
.
Last updated