Skip to main content

OrderBookV1

OrderBookV1

Simple order book for Domination Finance perpetual exchange.

Allows users to create/edit/cancel orders with single triggers. Once conditions are met for a user's order to be executed, an order bot will call executeOrder to change a position on their behalf.

Addresses

ChainAddress
Arbitrum Sepolia0x294a924417374ee0E07FdeA88eAE8dE72226f2A0
Base Sepolia0x0AB4bb5Aa6eeEE30F09f6F6d65439083B14c5E6c
Base Mainnet0x02b50df0429d074F9A07FE354188284589E5eCFC

Functions

initialize

function initialize(struct StorageInstance _app, uint256 _minExecutionFee) external

minExecutionFee

function minExecutionFee() public view returns (uint256)

minTimeExecuteDelay

legacy: This OrderBook has no execution delay

function minTimeExecuteDelay() public view returns (uint64)

allowPublicKeeper

legacy: This OrderBook is permissionless

function allowPublicKeeper() public view returns (bool)

oracle

function oracle() public view returns (contract IPriceFeed)

feeCalculator

function feeCalculator() public view returns (contract IFeeCalculator)

domFiPerp

function domFiPerp() public view returns (contract IDomFiPerp)

collateralToken

function collateralToken() public view returns (contract IERC20)

lastOrderNumber

function lastOrderNumber(address account) external view returns (OrderNumber)

setMinExecutionFee

Update the minimum execution fee. Admin only.

function setMinExecutionFee(uint256 _minExecutionFee) external

getOrderId

Compute the global order ID for an order. Order may not exist yet.

function getOrderId(address owner, OrderNumber orderLabel) public view returns (OrderId)

Parameters

NameTypeDescription
owneraddressThe owner of the order.
orderLabelOrderNumberThe user-defined label of the order.

Return Values

NameTypeDescription
[0]OrderIdOrderId Globally-unique order ID

executeOrders

Execute a batch of orders. See: executeOrder().

function executeOrders(
address[] _addresses,
OrderNumber[] _orderNumbers,
address payable _feeReceiver
) external

Parameters

NameTypeDescription
_addressesaddress[]List of addresses for which to execute orders
_orderNumbersOrderNumber[]List of OrderNumbers to execute, paired with addresses
_feeReceiveraddress payableDesired order.executionFee recipient for all orders

cancelMultiple

Cancel one or more orders and return collateral to the owner.

function cancelMultiple(address payable _address, OrderNumber[] _orderNumber) external

Parameters

NameTypeDescription
_addressaddress payableOwner of the orders
_orderNumberOrderNumber[]OrderNumbers to cancel. Log an error for each order that fails to cancel.

createOrders

Create one or more orders for msg.sender. Caller must either approve the total necessary collateral to OrderBook or include sufficient approval in _signature. Caller must also submit the total order.executionFee, in network tokens, with this function call. Any extra network tokens submitted beyond that amount are lost.

function createOrders(
struct IOrderBookDomain.OrderParams[] _orderParams,
struct IOrderBookV1.Signature _signature
) external payable

Parameters

NameTypeDescription
_orderParamsstruct IOrderBookDomain.OrderParams[]OrderParams for each order.
_signaturestruct IOrderBookV1.SignatureOptional EIP-2612 Signature.

storeAction

Store order action, reverting if it's malformed. Actions must contain the relevant field(s) for their ActionType and no others. When updating an order, new Actions must be the same types as the old.

function storeAction(
enum IOrderBookDomain.ActionType actionType,
ProductId productId,
bool isLong,
struct OrderPtr storageOrder,
struct IOrderBookDomain.OrderDetails newAction
) internal
Dev note

zeroes are allowed since DomFiPerp allows it. You probably shouldn't try to change a position by 0 though.

Parameters

NameTypeDescription
actionTypeenum IOrderBookDomain.ActionType
productIdProductId
isLongbool
storageOrderstruct OrderPtrstorage location for this order.
newActionstruct IOrderBookDomain.OrderDetailsnew action to update in storage

storeTrigger

function storeTrigger(struct OrderPtr order, struct IOrderBookDomain.TriggerDetails next) internal

cancelOrder

Cancel an order, refunding any submitted collateral and execution fee to the owner. Unless the caller is the order's owner, reverts if the order hasn't expired

function cancelOrder(address owner, OrderNumber _orderNumber, address proxySender) external

Parameters

NameTypeDescription
owneraddressAddress of order's owner
_orderNumberOrderNumberLabel of order to cancel
proxySenderaddressIf this is a recursive call, the address of the external caller. Otherwise ignored.

_cancelOrder

Cancel a single order.

function _cancelOrder(
address orderOwner,
OrderNumber _orderNumber,
address collateralRecipient,
address sender
) internal

Parameters

NameTypeDescription
orderOwneraddressowner of order to cancel
_orderNumberOrderNumberOwner-level number of order to cancel
collateralRecipientaddressAddress to receive collateral refund
senderaddressThe ultimate originator of this call. If it's the owner, skip checking the cancelation trigger.

updateOrder

Tweak parameters of a pending order belonging to the sender. Any network tokens sent increase the order's stored executionFee. Pull or refund additional collateral as necessary for INCREASE and ADD_MARGIN.

function updateOrder(
OrderNumber orderLabel,
enum IOrderBookDomain.ActionType _newActionType,
ProductId _newProductId,
struct IOrderBookDomain.OrderDetails _newAction,
bool _isLong,
struct IOrderBookDomain.TriggerDetails _newTrigger,
bytes _userData,
struct IOrderBookV1.Signature _signature
) external payable

Parameters

NameTypeDescription
orderLabelOrderNumberUser-defined label of the order to modify.
_newActionTypeenum IOrderBookDomain.ActionType
_newProductIdProductId
_newActionstruct IOrderBookDomain.OrderDetailsUpdated actions. Cannot change its type. If additional collateral will be required, must approve() it beforehand or fill out _signature.
_isLongbool
_newTriggerstruct IOrderBookDomain.TriggerDetailsUpdated trigger. Cannot change its type.
_userDatabytesUpdated user data, for use in off-chain tagging
_signaturestruct IOrderBookV1.SignatureOptional signature for additional collateral

executeOrder

Execute an Order, return any excess collateral to the order's owner, and mark the order as executed. See executeOrders().

function executeOrder(address _owner, OrderNumber _orderNumber, address payable _feeReceiver) public
Dev note

Reverts if:

  • the order has already been canceled or executed
  • the order does not exist
  • the order is not ready to execute
  • execution of any action fails

Parameters

NameTypeDescription
_owneraddressOwner of this order
_orderNumberOrderNumberUser-defined OrderNumber of the order to execute
_feeReceiveraddress payableDesired recipient of order.executionFee

canExecute

function canExecute(address owner, OrderNumber orderIndex) external returns (bool executable)

canCancel

function canCancel(address owner, OrderNumber orderIndex) external view returns (bool executable)

getFees

Get the trade fee that the sender would need to provide when creating this order, in addition to any margin that might be required.

function getFees(
struct IOrderBookDomain.OrderParams _orderParams,
address /* ignoredParameter */
) external view returns (
uint256 tradeFee,
uint256 executionFee
)

Parameters

NameTypeDescription
_orderParamsstruct IOrderBookDomain.OrderParamsOrder in question

Return Values

NameTypeDescription
tradeFeeuint256Expected trade fee (collateral token)
executionFeeuint256Expected execution fee (network tokens)

getOrder

function getOrder(
address owner,
OrderNumber orderNumber
) external view returns (
struct IOrderBookDomain.Order order
)