Limit Orders

The LimitOrders.sol contract is a settlement contract for executing orders from our off-chain limit order service. Users approve the contract to spend their tokens and provide signatures of their Order to an off-chain API. An order execution bot monitors markets and executes them against this contract when allowed. Orders are executed on the contract by providing the Order parameters and an EIP712 Typed Data Signature of the Order, using the contracts domain information, to the executeOrder function. The functions to execute orders on the contract are permissioned in the initial version as a security precaution.

Data Structures

struct Order {
    uint256 marketId;
    address recipient;
    address referrer;
    uint256 amount;
    uint256 minAmountOut;
    uint256 maxFee;
    uint256 submitted;
    uint256 deadline;
    address user;
}
FieldTypeDescription

marketId

uint256

ID of the market that the order is for

recipient

address

Address that will receive the payout of the order

referrer

address

Referrer address for the order. May receive a fee if set on the Teller contract for the market.

amount

uint256

Amount of quote tokens to spend on the order, in quote token decimals

minAmountOut

uint256

Minimum amount of payout tokens to receive from the order, in payout token decimals

maxFee

uint256

Maximum fee in the quote token that the user is willing to process the order, in quote token decimals

submitted

uint256

Timestamp that the order was submitted at. Used by the off-chain service to give priority to equivalent orders. API will not accept an order where the submitted date is a certain amount older than the current time.

deadline

uint256

Timestamp that the order is valid until. The order will not be executable after this time.

user

address

Address that the order proceeds will come from and that is required to sign the order.

enum Status {
    Open,
    Executed,
    Cancelled
}

Public Variables and View Methods

DOMAIN_SEPARATOR

function DOMAIN_SEPARATOR() external view returns (bytes32)

The current domain separator hashed used to verify EIP712 signatures.

aggregator

function aggregator() external view returns (contract IBondAggregator)

The Bond Aggregator contract (i.e. top-level contract of the bond system) that this settlement contract supports.

authority

function authority() external view returns (contract Authority)

The Authority contract that determine access to permissioned functions on the contract.

chainId

function chainId() external view returns (uint256)

Currently cached value for the chain ID.

getDigest

function getDigest(LimitOrders.Order order_) external view returns (bytes32)

Returns the hash digest of the provided order. Used to calculate a unique order identifier and verify EIP712 signatures of Orders.

orderStatus

function orderStatus(bytes32) external view returns (enum LimitOrders.Status)turns

Returns the Status of an order (identified by its hash digest).

State-Mutating Methods

cancelOrder

function cancelOrder(LimitOrders.Order order_) external nonpayable

Cancels an order on the settlement contract. A cancelled order cannot be executed, even by a permissioned executor.

Parameters

NameTypeDescription

order_

LimitOrders.Order

Order parameters. Specified in the Data Structures section above.

executeOrder

function executeOrder(LimitOrders.Order order_, bytes signature_, uint256 fee_) external nonpayable

Execute a single order. Permissioned.

Parameters

NameTypeDescription

order_

LimitOrders.Order

Order parameters. Specified in the Data Structures section above.

signature_

bytes

ECDSA signature of the EIP712 hash digest of the order_ by order_.user

fee_

uint256

Amount of quote tokens to charge as a fee. Must be less than or equal to order_.maxFee. Determined by the executor based on network gas fees and token prices at the time of execution.

executeOrders

function executeOrders(LimitOrders.Order[] orders_, bytes[] signatures_, uint256[] fees_) external nonpayable

Execute multiple orders in one transaction. Permissioned.

Parameters

NameTypeDescription

orders_

LimitOrders.Order[]

Array of Order parameters. Specified in the Data Structures section above.

signatures_

bytes[]

Array of ECDSA signatures of the EIP712 hash digest of the corresponding order_ by order_.user

fees_

uint256[]

Array of quote token amounts to charge as a fee on the corresponding order_. Must be less than or equal to order_.maxFee. Determined by the executor based on network gas fees and token prices at the time of execution.

reinstateOrder

function reinstateOrder(LimitOrders.Order order_) external nonpayable

Reinstates a previously cancelled order.

Parameters

NameTypeDescription

order_

LimitOrders.Order

undefined

updateDomainSeparator

function updateDomainSeparator() external nonpayable

Updates the cached domain separator in the event that the chainId changes. Saves gas on future digest computations.

Events

AuthorityUpdated

event AuthorityUpdated(address indexed user, contract Authority indexed newAuthority)

Parameters

NameTypeDescription

user indexed

address

undefined

newAuthority indexed

contract Authority

undefined

OrderCancelled

event OrderCancelled(bytes32 digest)

Parameters

NameTypeDescription

digest

bytes32

undefined

OrderExecuted

event OrderExecuted(bytes32 digest)

Parameters

NameTypeDescription

digest

bytes32

undefined

OrderReinstated

event OrderReinstated(bytes32 digest)

Parameters

NameTypeDescription

digest

bytes32

undefined

OwnerUpdated

event OwnerUpdated(address indexed user, address indexed newOwner)

Parameters

NameTypeDescription

user indexed

address

undefined

newOwner indexed

address

undefined

Errors

LimitOrders_AlreadyExecuted

error LimitOrders_AlreadyExecuted(bytes32 digest)

Parameters

NameTypeDescription

digest

bytes32

undefined

LimitOrders_InvalidFee

error LimitOrders_InvalidFee(uint256 fee, uint256 maxFee)

Parameters

NameTypeDescription

fee

uint256

undefined

maxFee

uint256

undefined

LimitOrders_InvalidParams

error LimitOrders_InvalidParams()

LimitOrders_InvalidSignature

error LimitOrders_InvalidSignature(bytes signature)

Parameters

NameTypeDescription

signature

bytes

undefined

LimitOrders_InvalidUpdate

error LimitOrders_InvalidUpdate()

LimitOrders_InvalidUser

error LimitOrders_InvalidUser()

LimitOrders_MarketClosed

error LimitOrders_MarketClosed(uint256 marketId)

Parameters

NameTypeDescription

marketId

uint256

undefined

LimitOrders_NotAuthorized

error LimitOrders_NotAuthorized()

LimitOrders_OrderCancelled

error LimitOrders_OrderCancelled(bytes32 digest)

Parameters

NameTypeDescription

digest

bytes32

undefined

LimitOrders_OrderExpired

error LimitOrders_OrderExpired(uint256 deadline)

Parameters

NameTypeDescription

deadline

uint256

undefined

Last updated