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 Sepolia0xE8a81387c48FA9F1124cb21f0554e0fe5dC51100

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

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. Emit ExecuteOrderError or ExecuteOrderFailure for any that fail. 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 OrderParams[] _orderParams, struct Signature _signature) external payable

Parameters

NameTypeDescription
_orderParamsstruct OrderParams[]OrderParams for each order.
_signaturestruct SignatureOptional 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
Dev note

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

Parameters

NameTypeDescription
actionTypeenum ActionType
productIdbytes32
isLongbool
storageOrderstruct Orderstorage location for this order.
newActionstruct OrderDetailsnew 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

NameTypeDescription
orderstruct OrderOrder whose execution trigger to evaluate
owneraddress

Return Values

NameTypeDescription
executableboolTrue 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

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 ActionType _newActionType,
bytes32 _newProductId,
struct OrderDetails _newAction,
bool _isLong,
struct TriggerDetails _newTrigger,
bytes _userData,
struct Signature _signature
) external payable

Parameters

NameTypeDescription
orderLabelOrderNumberUser-defined label of the order to modify.
_newActionTypeenum ActionType
_newProductIdbytes32
_newActionstruct OrderDetailsUpdated actions. Cannot change its type. If additional collateral will be required, must approve() it beforehand or fill out _signature.
_isLongbool
_newTriggerstruct TriggerDetailsUpdated trigger. Cannot change its type.
_userDatabytesUpdated user data, for use in off-chain tagging
_signaturestruct 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 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

NameTypeDescription
_orderParamsstruct 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 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

NameTypeDescription
collateralAtActionIndexuint256collateral available to this action during execution
collateralRequiredByActionuint256collateral 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.