Skip to main content

Direct

Direct​

SetReserveId​

event SetReserveId(address reserveId)

reserveId is set in the constructor by emitting this event, an indexer will be able to keep track of what reserve is used.

Parameters​

NameTypeDescription
reserveIdaddressidentifier of this contract's reserve when using a router. This is indexed so that RPC calls can filter on it.

RESERVE_ID​

address RESERVE_ID

identifier of this contract's reserve when using a router

two contracts using the same RESERVE_ID will share funds, therefore strat builder must make sure this contract is allowed to pull into the given reserve Id. a safe value for RESERVE_ID is address(this) in which case the funds will never be shared with another maker contract.

constructor​

constructor(contract IMangrove mgv, contract AbstractRouter router_, address reserveId) internal

Direct's constructor.

reserveId==address(0) will set RESERVE_ID to address(this).

Parameters​

NameTypeDescription
mgvcontract IMangroveThe Mangrove deployment that is allowed to call this for trade execution and posthook.
router_contract AbstractRouterthe router that this contract will use to pull/push liquidity from offer maker's reserve. This can be NO_ROUTER.
reserveIdaddressidentifier of this contract's reserve when using a router.

_newOffer​

function _newOffer(struct IOfferLogic.OfferArgs args) internal returns (uint256 offerId, bytes32 status)

Inserts a new offer in Mangrove Offer List.

Parameters​

NameTypeDescription
argsstruct IOfferLogic.OfferArgsFunction arguments stored in memory.

Return Values​

NameTypeDescription
offerIduint256Identifier of the newly created offer. Returns 0 if offer creation was rejected by Mangrove and args.noRevert is set to true.
statusbytes32NEW_OFFER_SUCCESS if the offer was successfully posted on Mangrove. Returns Mangrove's revert reason otherwise.

_updateOffer​

function _updateOffer(struct IOfferLogic.OfferArgs args, uint256 offerId) internal returns (bytes32 status)

Updates the offer specified by offerId on Mangrove with the parameters in args.

Parameters​

NameTypeDescription
argsstruct IOfferLogic.OfferArgsA memory struct containing the offer parameters to update.
offerIduint256An unsigned integer representing the identifier of the offer to be updated.

Return Values​

NameTypeDescription
statusbytes32status a bytes32 value representing either REPOST_SUCCESS if the update is successful, or an error message if an error occurs and OfferArgs.noRevert is true. If OfferArgs.noRevert is false, the function reverts with the error message as the reason.

_retractOffer​

function _retractOffer(struct OLKey olKey, uint256 offerId, bool deprovision) internal 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 admin 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.

provisionOf​

function provisionOf(struct OLKey olKey, uint256 offerId) external view returns (uint256 provision)

computes the amount of native tokens that can be redeemed when deprovisioning a given offer.

Parameters​

NameTypeDescription
olKeystruct OLKeythe offer list key.
offerIduint256the identifier of the offer in the offer list

Return Values​

NameTypeDescription
provisionuint256the amount of native tokens that can be redeemed when deprovisioning the offer

put​

function __put__(uint256, struct MgvLib.SingleOrder) internal virtual returns (uint256)

direct contract do not need to do anything specific with incoming funds during trade

one should override this function if one wishes to leverage taker's fund during trade execution

Parameters​

NameTypeDescription
uint256
struct MgvLib.SingleOrder

Return Values​

NameTypeDescription
[0]uint256

get​

function __get__(uint256 amount, struct MgvLib.SingleOrder order) internal virtual returns (uint256)

__get__ hook for Direct is to ask the router to pull liquidity from reserveId if strat is using a router otherwise the function simply returns what's missing in the local balance

if the last nested call to __get__ returns a non zero value, trade execution will revert

Parameters​

NameTypeDescription
amountuint256of outbound tokens that still needs to be brought to the balance of this contract when entering this function
orderstruct MgvLib.SingleOrderis a recall of the taker order that is at the origin of the current trade.

Return Values​

NameTypeDescription
[0]uint256

posthookSuccess​

function __posthookSuccess__(struct MgvLib.SingleOrder order, bytes32 makerData) internal virtual returns (bytes32)

Direct posthook flushes outbound and inbound token back to the router (if any)

Parameters​

NameTypeDescription
orderstruct MgvLib.SingleOrderis a recall of the taker order that is at the origin of the current trade.
makerDatabytes32is the returned value of the __lastLook__ hook, triggered during trade execution. The special value "lastLook/retract" should be treated as an instruction not to repost the offer on the list.

Return Values​

NameTypeDescription
[0]bytes32

checkList​

function __checkList__(contract IERC20 token) internal view virtual

if strat has a router, verifies that the router is ready to pull/push on behalf of reserve id

Parameters​

NameTypeDescription
tokencontract IERC20a token that is traded by this contract