Skip to main content

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

ChainAddress

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

NameTypeDescription
_orderParamsstruct OrderParamsOrder in question
executoraddressIgnored legacy parameter

Return Values

NameTypeDescription
tradeFeeuint256Expected trade fee (collateral token)
executionFeeuint256Expected 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

NameTypeDescription
accountaddress
orderNumberOrderNumber
productIdbytes32
accountPositionIdPositionLabel
executionPriceFPUnsignedLegacy interface, left blank in impl
currentPnLFPSignedLegacy interface, left blank in impl
actionTypeenum ActionType
orderstruct 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

NameDescription
INCREASE_SIZEcall DomFiPerp.increasePosition
DECREASE_SIZEcall DomFiPerp.decreasePositionWithId
ADD_MARGINcall DomFiPerp.increasePosition with 0 leverage
REMOVE_MARGINcall DomFiPerp.removeMargin
enum ActionType {
INCREASE_SIZE,
DECREASE_SIZE,
ADD_MARGIN,
REMOVE_MARGIN
}

TriggerType

The type of a Trigger

Values

NameDescription
INVALIDRevert if encountered. Guards against accidental 0x00
PRICECompare price of a product vs a specified price
PNL_RATECompare 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

NameDescription
LTEActivate if the current value is <= the target value
GTEActivate if the current value is >= the target value
enum TriggerCondition {
LTE,
GTE
}

TriggerDetails

Details for an order's execution criteria

Fields

NameTypeDescription
triggerTypeenum TriggerTypeThe type of comparison to make
triggerConditionenum TriggerConditionshould trigger >= or <= threshold?
triggerPnLRateFPSignedTarget PnL rate, a position's PnL divided by its margin, to be compared with conditions on chain.
triggerPriceFPUnsignedTarget 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

NameTypeDescription
leverageFPUnsignedFor INCREASE_SIZE only; leverage of increase
marginuint256This slot is:
  • INCREASE_SIZE: margin to increase by. See leverage
  • DECREASE_SIZE: unused
  • ADD_MARGIN: margin to add
  • REMOVE_MARGIN: margin to remove. 0 if removeMarginFactor is present./
tradeFeeuint256For INCREASE_SIZE only; pre-collected trade fee.
sizeFPUnsignedFor DECREASE_SIZE only; size to decrease by
removeMarginFactorFPUnsignedThis slot is:
  • INCREASE_SIZE: unused
  • DECREASE_SIZE: unused
  • ADD_MARGIN: unused
  • REMOVE_MARGIN: fraction of available margin to remove (0,1]. 0 if margin is present
struct OrderDetails {
FPUnsigned leverage;
uint256 margin;
uint256 tradeFee;
FPUnsigned size;
FPUnsigned removeMarginFactor;
}

Order

A user order on the exchange.

Fields

NameTypeDescription
executionFeeuint256Amount of network token reimbursed to order executor
submittedAtuint64Unix timestamp, in seconds, of last update.
canceledAtuint64Unix timestamp, in seconds, of cancelation. 0 if not yet canceled.
executedAtuint64Unix timestamp, in seconds, of execution. 0 if not yet executed.
executionDeadlineuint64
productIdbytes32
actionTypeenum ActionTypeSee OrderBook.ActionType
actionstruct OrderDetailsAction that will be taken when the order executes.
triggerDetailsstruct TriggerDetails
isLongboolRequired for INCREASE_SIZE only, since we might be creating a new position
owneraddress payableThe creator and beneficiary of this order.
accountPositionIdPositionLabel
userDatabytesUser-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;
}