Skip to main content

MangroveOrder

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 agoala_goal at a price pp, and the corresponding limit order was partially filled for anow<agoala_now < a_goal, the resting order should be posted for an amount alater=agoalβˆ’anowa_later = a_goal - a_now at price pp. 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​

mapping(bytes32 => mapping(uint256 => uint256)) 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​

constructor(contract IMangrove mgv, address deployer) public

MangroveOrder is a Forwarder logic with a simple router.

Parameters​

NameTypeDescription
mgvcontract IMangroveThe mangrove contract on which this logic will run taker and maker orders.
deployeraddressThe address of the admin of this at the end of deployment

setExpiry​

function setExpiry(bytes32 olKeyHash, uint256 offerId, uint256 date) public

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​

NameTypeDescription
olKeyHashbytes32the hash of the offer list key.
offerIduint256The offer id whose expiry date is to be set.
dateuint256in seconds since unix epoch

updateOffer​

function updateOffer(struct OLKey olKey, Tick tick, uint256 gives, uint256 gasreq, uint256 offerId) external payable

updates an offer on Mangrove

this can be used to update price of the resting order

Parameters​

NameTypeDescription
olKeystruct OLKeythe offer list key.
tickTickthe tick
givesuint256new amount of olKey.outbound_tkn offer owner gives
gasrequint256new gas req for the restingOrder
offerIduint256the id of the offer to be updated

retractOffer​

function retractOffer(struct OLKey olKey, uint256 offerId, bool deprovision) public returns (uint256 freeWei)

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​

NameTypeDescription
olKeystruct OLKeythe offer list key.
offerIduint256the identifier of the offer in the offer list
deprovisionboolif set to true if offer owner wishes to redeem the offer's provision.

Return Values​

NameTypeDescription
freeWeiuint256the amount of native tokens (in WEI) that have been retrieved by retracting the offer.

lastLook​

function __lastLook__(struct MgvLib.SingleOrder order) internal virtual returns (bytes32)

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​

NameTypeDescription
orderstruct MgvLib.SingleOrderis a recall of the taker order that is at the origin of the current trade.

Return Values​

NameTypeDescription
[0]bytes32

checkCompleteness​

function checkCompleteness(struct IOrderLogic.TakerOrder tko, struct IOrderLogic.TakerOrderResult res) internal pure returns (bool)

compares a taker order with a market order result and checks whether the order was entirely filled

Parameters​

NameTypeDescription
tkostruct IOrderLogic.TakerOrderthe taker order
resstruct IOrderLogic.TakerOrderResultthe market order result

Return Values​

NameTypeDescription
[0]booltrue if the order was entirely filled, false otherwise.

take​

function take(struct IOrderLogic.TakerOrder tko) external payable returns (struct IOrderLogic.TakerOrderResult res)

Implements "Fill or kill" or "Good till cancelled" orders on a given offer list.

Parameters​

NameTypeDescription
tkostruct IOrderLogic.TakerOrderthe arguments in memory of the taker order

Return Values​

NameTypeDescription
resstruct IOrderLogic.TakerOrderResultthe result of the taker order. If offerId==0, no resting order was posted on msg.sender's behalf.

logOrderData​

function logOrderData(struct IOrderLogic.TakerOrder tko) internal

logs MangroveOrderStart

this function avoids loading too many variables on the stack

Parameters​

NameTypeDescription
tkostruct IOrderLogic.TakerOrderthe arguments in memory of the taker order

postRestingOrder​

function postRestingOrder(struct IOrderLogic.TakerOrder tko, struct OLKey olKey, struct IOrderLogic.TakerOrderResult res, uint256 fund) internal returns (uint256 refund)

posts a maker order on the (olKey) offer list.

if relative limit price of taker order is ratio in the (outbound_tkn, inbound_tkn) offer list (represented by `tick=log{1.0001}(ratio)) then entailed relative price for resting order must be1/ratio(relative price on the (inbound_tkn, outbound_tkn) offer list) so with ticks that is-log(ratio)`, or -tick. the price of the resting order should be the same as for the max price for the market order._

Parameters​

NameTypeDescription
tkostruct IOrderLogic.TakerOrderthe arguments in memory of the taker order
olKeystruct OLKeythe offer list key.
resstruct IOrderLogic.TakerOrderResultthe result of the taker order.
funduint256amount of WEIs used to cover for the offer bounty (covered gasprice is derived from fund).

Return Values​

NameTypeDescription
refunduint256the amount to refund to the taker of the fund.