IOrderBookV1
IOrderBookV1
Simple order book specification 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 |
---|
Functions
getOrder
function getOrder(address, OrderNumber) external returns (struct Order)
domFiPerp
function domFiPerp() external view returns (contract IDomFiPerp)
collateralToken
function collateralToken() external view returns (contract IERC20)
minExecutionFee
function minExecutionFee() external view returns (uint256)
minTimeExecuteDelay
legacy: This OrderBook has no execution delay
function minTimeExecuteDelay() external view returns (uint64)
allowPublicKeeper
legacy: This OrderBook is permissionless
function allowPublicKeeper() external view returns (bool)
setKeeper
legacy: This OrderBook is permissionless
function setKeeper(address _account, bool _isActive) external
executeOrders
function executeOrders(
address[] _addresses,
OrderNumber[] _orderIndices,
address payable _feeReceiver
) external
cancelMultiple
function cancelMultiple(address payable _address, OrderNumber[] _orderIndices) external
createOrders
function createOrders(struct OrderParams[] _orderParams, struct Signature _signature) external payable
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 OrderParams _orderParams,
address executor
) external view returns (
uint256 tradeFee,
uint256 executionFee
)
Parameters
Name | Type | Description |
---|---|---|
_orderParams | struct OrderParams | Order in question |
executor | address | Ignored legacy parameter |
Return Values
Name | Type | Description |
---|---|---|
tradeFee | uint256 | Expected trade fee (collateral token) |
executionFee | uint256 | Expected execution fee (network tokens) |
Events
CreateOrder
event CreateOrder(
address account,
OrderNumber orderNumber,
bytes32 productId,
PositionLabel accountPositionId,
enum ActionType actionType,
struct Order order
)
CancelOrder
event CancelOrder(
address account,
OrderNumber orderNumber,
bytes32 productId,
PositionLabel accountPositionId,
enum ActionType actionType,
struct Order order
)
UpdateOrder
event UpdateOrder(
address account,
OrderNumber orderNumber,
bytes32 productId,
PositionLabel accountPositionId,
enum ActionType actionType,
struct Order prevOrder,
struct Order newOrder
)
ExecuteOrder
event ExecuteOrder(
address account,
OrderNumber orderNumber,
bytes32 productId,
PositionLabel accountPositionId,
FPUnsigned executionPrice,
FPSigned currentPnL,
enum ActionType actionType,
struct Order order
)
Parameters
Name | Type | Description |
---|---|---|
account | address | |
orderNumber | OrderNumber | |
productId | bytes32 | |
accountPositionId | PositionLabel | |
executionPrice | FPUnsigned | Legacy interface, left blank in impl |
currentPnL | FPSigned | Legacy interface, left blank in impl |
actionType | enum ActionType | |
order | struct Order |
ExecuteOrderError
event ExecuteOrderError(address account, OrderNumber orderNumber, string executionError)
ExecuteOrderFailure
event ExecuteOrderFailure(address account, OrderNumber orderNumber, bytes lowLevelData)
OrderNumber
uint256
incrementing number to identify orders. Sequential and unique per user.
ActionType
The type of an Action
Values
Name | Description |
---|---|
INCREASE_SIZE | call DomFiPerp.increasePosition |
DECREASE_SIZE | call DomFiPerp.decreasePositionWithId |
ADD_MARGIN | call DomFiPerp.increasePosition with 0 leverage |
REMOVE_MARGIN | call DomFiPerp.removeMargin |
enum ActionType {
INCREASE_SIZE,
DECREASE_SIZE,
ADD_MARGIN,
REMOVE_MARGIN
}
TriggerType
The type of a Trigger
Values
Name | Description |
---|---|
INVALID | Revert if encountered. Guards against accidental 0x00 |
PRICE | Compare price of a product vs a specified price |
PNL_RATE | Compare PnL of a position vs a specified % |
enum TriggerType {
INVALID,
PRICE,
PNL_RATE
}
TriggerCondition
Whether a trigger should activate below or above a value
Values
Name | Description |
---|---|
LTE | Activate if the current value is <= the target value |
GTE | Activate if the current value is >= the target value |
enum TriggerCondition {
LTE,
GTE
}
TriggerDetails
Details for an order's execution criteria
Fields
Name | Type | Description |
---|---|---|
triggerType | enum TriggerType | The type of comparison to make |
triggerCondition | enum TriggerCondition | should trigger >= or <= threshold? |
triggerPnLRate | FPSigned | Target PnL rate, a position's PnL divided by its margin, to be compared with conditions on chain. |
triggerPrice | FPUnsigned | Target price, to be compared with on-chain product price. |
struct TriggerDetails {
enum TriggerType triggerType;
enum TriggerCondition triggerCondition;
FPSigned triggerPnLRate;
FPUnsigned triggerPrice;
}
OrderDetails
The action taken when an order is executed. Each OrderDetails instance must contain only the relevant fields for its trigger and action types.
Fields
Name | Type | Description |
---|---|---|
leverage | FPUnsigned | For INCREASE_SIZE only; leverage of increase |
margin | uint256 | This slot is:
|
tradeFee | uint256 | For INCREASE_SIZE only; pre-collected trade fee. |
size | FPUnsigned | For DECREASE_SIZE only; size to decrease by |
removeMarginFactor | FPUnsigned | This slot is:
|
struct OrderDetails {
FPUnsigned leverage;
uint256 margin;
uint256 tradeFee;
FPUnsigned size;
FPUnsigned removeMarginFactor;
}
Order
A user order on the exchange.
Fields
Name | Type | Description |
---|---|---|
executionFee | uint256 | Amount of network token reimbursed to order executor |
submittedAt | uint64 | Unix timestamp, in seconds, of last update. |
canceledAt | uint64 | Unix timestamp, in seconds, of cancelation. 0 if not yet canceled. |
executedAt | uint64 | Unix timestamp, in seconds, of execution. 0 if not yet executed. |
executionDeadline | uint64 | |
productId | bytes32 | |
actionType | enum ActionType | See OrderBook.ActionType |
action | struct OrderDetails | Action that will be taken when the order executes. |
triggerDetails | struct TriggerDetails | |
isLong | bool | Required for INCREASE_SIZE only, since we might be creating a new position |
owner | address payable | The creator and beneficiary of this order. |
accountPositionId | PositionLabel | |
userData | bytes | User-specified data to attach to the order. |
struct Order {
uint256 executionFee;
uint64 submittedAt;
uint64 canceledAt;
uint64 executedAt;
uint64 executionDeadline;
bytes32 productId;
enum ActionType actionType;
struct OrderDetails action;
struct TriggerDetails triggerDetails;
bool isLong;
address payable owner;
PositionLabel accountPositionId;
bytes userData;
}
OrderParams
Parameters to create an order. The same thing as Order,
except it does not include owner
(set to msg.sender
) or any of the
timestamp fields (which users cannot modify directly).
struct OrderParams {
PositionLabel accountPositionId;
bytes32 productId;
bool isLong;
enum ActionType actionType;
struct OrderDetails action;
struct TriggerDetails triggerDetails;
uint256 executionFee;
uint64 executionDeadline;
bytes userData;
}
Signature
a signature for use with EIP-2612
struct Signature {
uint256 amount;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}