MangroveOrder
A GTC order is a buy (sell) limit order complemented by a bid (ask) limit order, called a resting order, that occurs when the buy (sell) order was partially filled. If the GTC is for some amount $a_{goal}$ at a price $p$, and the corresponding limit order was partially filled for $a_{now} < a_{goal}$, the resting order should be posted for an amount $a_{later} = a_{goal} - a_{now}$ at price $p$. A FOK order is simply a buy or sell limit order that is either completely filled or cancelled. No resting order is posted.
requiring no partial fill and a resting order is interpreted here as an instruction to revert if the resting order fails to be posted (e.g., if below density).
expiring
expiring[olKey.hash()][offerId]
gives timestamp beyond which offerId
on the olKey.(outbound_tkn, inbound_tkn, tickSpacing)
offer list should renege on trade.
if the order tx is included after the expiry date, it reverts.
0 means no expiry.
constructor
MangroveOrder is a Forwarder logic with a simple router.
Parameters
mgv
contract IMangrove
The mangrove contract on which this logic will run taker and maker orders.
deployer
address
The address of the admin of this
at the end of deployment
setExpiry
Updates the expiry date for a specific offer.
We also allow Mangrove to call this so that it can part of an offer logic.
Parameters
olKeyHash
bytes32
the hash of the offer list key.
offerId
uint256
The offer id whose expiry date is to be set.
date
uint256
in seconds since unix epoch
updateOffer
updates an offer on Mangrove
this can be used to update price of the resting order
Parameters
olKey
struct OLKey
the offer list key.
tick
Tick
the tick
gives
uint256
new amount of olKey.outbound_tkn
offer owner gives
gasreq
uint256
new gas req for the restingOrder
offerId
uint256
the id of the offer to be updated
retractOffer
Retracts an offer from an Offer List of Mangrove.
An offer that is retracted without deprovision
is retracted from the offer list, but still has its provisions locked by Mangrove.
Calling this function, with the deprovision
flag, on an offer that is already retracted must be used to retrieve the locked provisions.
Parameters
olKey
struct OLKey
the offer list key.
offerId
uint256
the identifier of the offer in the offer list
deprovision
bool
if set to true
if offer owner wishes to redeem the offer's provision.
Return Values
freeWei
uint256
the amount of native tokens (in WEI) that have been retrieved by retracting the offer.
__lastLook__
Checks the current timestamps and reneges on trade (by reverting) if the offer has expired.
_ __lastLook__ should revert if trade is to be reneged on. If not, returned bytes32
are passed to makerPosthook
in the makerData
field. _
Parameters
order
struct MgvLib.SingleOrder
is a recall of the taker order that is at the origin of the current trade.
Return Values
[0]
bytes32
checkCompleteness
compares a taker order with a market order result and checks whether the order was entirely filled
Parameters
tko
struct IOrderLogic.TakerOrder
the taker order
res
struct IOrderLogic.TakerOrderResult
the market order result
Return Values
[0]
bool
true if the order was entirely filled, false otherwise.
take
Implements "Fill or kill" or "Good till cancelled" orders on a given offer list.
Parameters
tko
struct IOrderLogic.TakerOrder
the arguments in memory of the taker order
Return Values
res
struct IOrderLogic.TakerOrderResult
the result of the taker order. If offerId==0
, no resting order was posted on msg.sender
's behalf.
logOrderData
logs MangroveOrderStart
this function avoids loading too many variables on the stack
Parameters
tko
struct IOrderLogic.TakerOrder
the arguments in memory of the taker order
postRestingOrder
posts a maker order on the (olKey
) offer list.
:::info If relative limit price of taker order is $\text{ratio}$ in the (outboundtkn, inbound_tkn) offer list (represented by $\text{tick}=log{1.0001}(\text{ratio})$ ) then entailed relative price for resting order must be $\frac{1}{\text{ratio}}$ (relative price on the (inbound_tkn, outbound_tkn) offer list) so with ticks that is $-log(\text{ratio})$, or $-\text{tick}$. the price of the resting order should be the same as for the max price for the market order. :::
Parameters
tko
struct IOrderLogic.TakerOrder
the arguments in memory of the taker order
olKey
struct OLKey
the offer list key.
res
struct IOrderLogic.TakerOrderResult
the result of the taker order.
fund
uint256
amount of WEIs used to cover for the offer bounty (covered gasprice is derived from fund
).
Return Values
refund
uint256
the amount to refund to the taker of the fund.