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 | 0xE8a81387c48FA9F1124cb21f0554e0fe5dC51100 |
Zircuit | 0x35330a50aD10D20889E26a9532396847922BE6A2 |
Functions
setKeeper
legacy: This OrderBook is permissionless
function setKeeper(address, bool) external pure
constructor
constructor(
uint256 _minExecutionFee,
contract IDomFiPerp _domFiPerp,
contract IPriceFeed _oracle,
contract IFeeCalculator _feeCalculator
) public
setOracle
Update the stored price feed. Admin only.
function setOracle(contract IPriceFeed _oracle) external
setFeeCalculator
Update the stored IFeeCalculator. Admin only.
function setFeeCalculator(contract IFeeCalculator _feeCalculator) external
setMinExecutionFee
Update the minimum execution fee. Admin only.
function setMinExecutionFee(uint256 _minExecutionFee) external
setAdmin
Update the contract administrator. Governance only.
function setAdmin(address _admin) 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. Emit ExecuteOrderError
or ExecuteOrderFailure for any that fail. 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 OrderParams[] _orderParams, struct Signature _signature) external payable
Parameters
Name | Type | Description |
---|---|---|
_orderParams | struct OrderParams[] | OrderParams for each order. |
_signature | struct Signature | Optional EIP-2612 Signature. |
checkValidUnresolved
Before editing an order, must check that
- it has a
submittedAt
(i.e., it's not all 0s) - it hasn't been marked executed/canceled/expired
function checkValidUnresolved(struct Order order) internal view
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 ActionType actionType,
bytes32 productId,
bool isLong,
struct Order storageOrder,
struct 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 ActionType | |
productId | bytes32 | |
isLong | bool | |
storageOrder | struct Order | storage location for this order. |
newAction | struct OrderDetails | new action to update in storage |
storeTrigger
function storeTrigger(struct Order order, struct TriggerDetails trigger) internal
hasExecutableTrigger
Evaluate the specified Trigger.
function hasExecutableTrigger(struct Order order, address owner) internal returns (bool executable)
Parameters
Name | Type | Description |
---|---|---|
order | struct Order | Order whose execution trigger to evaluate |
owner | address |
Return Values
Name | Type | Description |
---|---|---|
executable | bool | True if this trigger is active; false if not |
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 ActionType _newActionType,
bytes32 _newProductId,
struct OrderDetails _newAction,
bool _isLong,
struct TriggerDetails _newTrigger,
bytes _userData,
struct Signature _signature
) external payable
Parameters
Name | Type | Description |
---|---|---|
orderLabel | OrderNumber | User-defined label of the order to modify. |
_newActionType | enum ActionType | |
_newProductId | bytes32 | |
_newAction | struct 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 TriggerDetails | Updated trigger. Cannot change its type. |
_userData | bytes | Updated user data, for use in off-chain tagging |
_signature | struct 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 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 OrderParams _orderParams,
address /* ignoredParameter */
) external view returns (
uint256 tradeFee,
uint256 executionFee
)
Parameters
Name | Type | Description |
---|---|---|
_orderParams | struct 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 Order order)
onlyAdmin
function onlyAdmin() internal view
Events
CancelOrderError
event CancelOrderError(address owner, OrderNumber orderLabel, string executionError)
CancelOrderFailure
event CancelOrderFailure(address owner, OrderNumber orderLabel, bytes lowLevelData)
UpdateMinExecutionFee
event UpdateMinExecutionFee(uint256 minExecutionFee)
UpdateAdmin
event UpdateAdmin(address admin)
Errors
ContractOnly
error ContractOnly()
AdminOnly
error AdminOnly()
OrderOwnerOnly
error OrderOwnerOnly()
ArrayLengthMismatch
error ArrayLengthMismatch()
ActionLengthMismatch
error ActionLengthMismatch()
OrderNumberUsed
error OrderNumberUsed(uint256 argIndex)
ExecutionFeeBelowMinimum
error ExecutionFeeBelowMinimum(uint256 argIndex)
ExecutionFeeInsufficient
error ExecutionFeeInsufficient(uint256 argIndex)
InsufficientCollateralSupplied
Execution of this order is guaranteed to fail unless you submit it with more collateral.
error InsufficientCollateralSupplied(uint256 collateralAtActionIndex, uint256 collateralRequiredByAction)
Parameters
Name | Type | Description |
---|---|---|
collateralAtActionIndex | uint256 | collateral available to this action during execution |
collateralRequiredByAction | uint256 | collateral this action would need to succeed |
PositionIdMissing
error PositionIdMissing()
ExpiredExecutionDeadline
error ExpiredExecutionDeadline()
IrrelevantTriggerDetails
error IrrelevantTriggerDetails()
MissingTriggerDetails
error MissingTriggerDetails()
MismatchedTriggerType
error MismatchedTriggerType()
InvalidTriggerType
error InvalidTriggerType()
OutOfCollateral
error OutOfCollateral()
IrrelevantActionDetails
error IrrelevantActionDetails()
MissingActionDetails
error MissingActionDetails()
ActionTypeMismatch
error ActionTypeMismatch()
InvalidActionSkipIf
error InvalidActionSkipIf()
UninitializedOrder
error UninitializedOrder()
UninitializedPosition
Attempted to decrease a position, or preview doing so, but the position did not exist.
error UninitializedPosition()
OrderCanceled
error OrderCanceled()
OrderExecuted
Order could not be canceled because it's already been executed
error OrderExecuted()
OrderExpired
error OrderExpired()
TriggerUnmet
error TriggerUnmet()
AddressUnset
error AddressUnset()
EmptyTriggers
error EmptyTriggers()
InvalidOrderNumber
error InvalidOrderNumber()
OrderUnexpired
error OrderUnexpired()
Variables
allowPublicKeeper
legacy: This OrderBook is permissionless
minTimeExecuteDelay
legacy: This OrderBook has no execution delay
lastOrderNumber
domFiPerp
IDomFiPerp
used for position triggers and actions.
collateralToken
Collateral token collected by orders; used for positions and vault deposits.
admin
Administrator permitted to update stored addresses and parameters of this contract. Updatable by governance.
oracle
IPriceFeed
used for price triggers.
feeCalculator
IFeeCalculator
used to calculate total cost of INCREASE_SIZE
actions.
minExecutionFee
The minimum execution fee, below which order submissions will be rejected with ExecutionFeeBelowMinimum.
OrderId
bytes32
globally-unique ID of an order. See getOrderId
.