Executing offers
Offers are created with an associated account (a %%maker contract|maker-contract%% or EOA) and listed on Mangrove offer lists.
- If the account is an EOA, no logic will be associated to the offer. These %%on-the-fly|on-the-fly-offer%% offers should have the promised liquidity on the EOA when the offer is matched during a market order.
- If the account is a maker contract, it should implement the offer logic through the IMaker interface. It must at least implement the
makerExecute
function, otherwise all offer executions will fail.
Here is the offer lifecycle, with the parts addressed in this section bolded:
- A contract
maker.eth
creates an offer. - Mangrove stores the offer info, including the address
maker.eth
. - Account
user.eth
sends a market order to Mangrove which matches that offer. - Mangrove transfers tokens from
user.eth
tomaker.eth
. - Mangrove calls the function
makerExecute
ofmaker.eth
. - Mangrove transfers tokens from
maker.eth
touser.eth
. - The offer is now out of its offer list, but may be updated at step 9 by
maker.eth
. - If the transfer at step 6 is not a success, Mangrove reverts to the state prior to the transfer of step 4, and sends a %%bounty|bounty%% to
user.eth
taken from the offer's %%provision|provision%%. - Mangrove calls the function
makerPosthook
ofmaker.eth
.
An account can post more than one offer. When it gets called through makerExecute
, it will receive the %%id|offer-id%% of the offer being executed as well as additional information.
Suppose that an offer managed by a contract promises 100,000 DAI in exchange for 100,000 USDC.
Upon being called, the contract has 100,000 USDC available (just given to it by Mangrove) and may source DAI from anywhere on the chain. It needs to end execution with 100,000 DAI available and ready to be transferred by Mangrove through transferFrom
.