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
Chain | Address |
---|---|
Arbitrum Sepolia | 0x294a924417374ee0E07FdeA88eAE8dE72226f2A0 |
Base Sepolia | 0x0AB4bb5Aa6eeEE30F09f6F6d65439083B14c5E6c |
Base Mainnet | 0x02b50df0429d074F9A07FE354188284589E5eCFC |
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
Name | Type | Description |
---|---|---|
owner | address | The owner of the order. |
orderLabel | OrderNumber | The user-defined label of the order. |
Return Values
Name | Type | Description |
---|---|---|
[0] | OrderId | OrderId Globally-unique order ID |
executeOrders
Execute a batch of orders. See:
executeOrder()
.
function executeOrders(
address[] _addresses,
OrderNumber[] _orderNumbers,
address payable _feeReceiver
) external
Parameters
Name | Type | Description |
---|---|---|
_addresses | address[] | List of addresses for which to execute orders |
_orderNumbers | OrderNumber[] | List of OrderNumbers to execute, paired with addresses |
_feeReceiver | address payable | Desired 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
Name | Type | Description |
---|---|---|
_address | address payable | Owner of the orders |
_orderNumber | OrderNumber[] | 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
Name | Type | Description |
---|---|---|
_orderParams | struct IOrderBookDomain.OrderParams[] | OrderParams for each order. |
_signature | struct IOrderBookV1.Signature | Optional 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
zeroes are allowed since DomFiPerp allows it. You probably shouldn't try to change a position by 0 though.
Parameters
Name | Type | Description |
---|---|---|
actionType | enum IOrderBookDomain.ActionType | |
productId | ProductId | |
isLong | bool | |
storageOrder | struct OrderPtr | storage location for this order. |
newAction | struct IOrderBookDomain.OrderDetails | new 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
Name | Type | Description |
---|---|---|
owner | address | Address of order's owner |
_orderNumber | OrderNumber | Label of order to cancel |
proxySender | address | If 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
Name | Type | Description |
---|---|---|
orderOwner | address | owner of order to cancel |
_orderNumber | OrderNumber | Owner-level number of order to cancel |
collateralRecipient | address | Address to receive collateral refund |
sender | address | The 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
Name | Type | Description |
---|---|---|
orderLabel | OrderNumber | User-defined label of the order to modify. |
_newActionType | enum IOrderBookDomain.ActionType | |
_newProductId | ProductId | |
_newAction | struct IOrderBookDomain.OrderDetails | Updated actions. Cannot change its type. If additional collateral will be required, must approve() it beforehand or fill out _signature . |
_isLong | bool | |
_newTrigger | struct IOrderBookDomain.TriggerDetails | Updated trigger. Cannot change its type. |
_userData | bytes | Updated user data, for use in off-chain tagging |
_signature | struct IOrderBookV1.Signature | Optional 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
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
Name | Type | Description |
---|---|---|
_owner | address | Owner of this order |
_orderNumber | OrderNumber | User-defined OrderNumber of the order to execute |
_feeReceiver | address payable | Desired 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
Name | Type | Description |
---|---|---|
_orderParams | struct IOrderBookDomain.OrderParams | Order in question |
Return Values
Name | Type | Description |
---|---|---|
tradeFee | uint256 | Expected trade fee (collateral token) |
executionFee | uint256 | Expected execution fee (network tokens) |
getOrder
function getOrder(
address owner,
OrderNumber orderNumber
) external view returns (
struct IOrderBookDomain.Order order
)