Accounts / Access Keys
Account Structure
A wallet owner can register an account on Orderly for each supported builder. Each wallet owner can thus have multiple accounts (not interlinked with each other) registered with Orderly.Account ID
Each account is identified by an account ID, calculated as follows:- Convert the wallet address to bytes
- Convert the keccak256 hash of the
brokerIdstring to bytes - Concatenate the results of (1) and (2)
- Take the keccak256 hash of (3) and convert back to a hex string
Authorization
Orderly uses the EIP-712 standard to authenticate wallets and accounts for critical actions, such as:- Account creation
- Access key (Orderly key) addition
- Withdrawal requests
Access Key (Orderly Key)
Orderly uses the ed25519 elliptic curve standard for access keys. Users can generate access keys using any public ed25519 library and then add them to any account through a REST API. Access keys can have different scopes:- read — access all private read-only APIs
- trading — in addition to read access, access all order APIs (create order, batch create order, edit order, cancel order, cancel order by client_order_id, cancel orders in bulk, batch cancel orders, batch cancel orders by client_order_id)
Account Registration
To register an account on Orderly:- Choose a valid chain/builder to register the account on
- Check if the wallet is already registered via this API or if the account already exists via this API
- Get a nonce from the Get registration nonce API
- Sign a message from the wallet using the EIP-712 standard in the following format and obtain the signature:
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those supported by the Network) |
| timestamp | timestamp | Y | Timestamp in UNIX milliseconds |
| registrationNonce | string | Y | Valid nonce from Get registration nonce |
Add Access Key
To add a new access key on Orderly:- Generate an ed25519 key pair
- Sign a message from the wallet using the EIP-712 standard in the following format and obtain the signature:
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those supported by the Network) |
| orderlyKey | string | Y | ed25519 public key |
| scope | string | Y | Valid scopes are read, trading; multiple scopes can be sent, comma separated |
| timestamp | timestamp | Y | Timestamp in UNIX milliseconds |
| expiration | timestamp | Y | Expiration time of the key in UNIX milliseconds. Maximum allowed expiration is 365 days from add |
- Send all the necessary information via the Add Orderly key API
Deposits / Withdrawals
Deposit
Token deposits can be made on any supported chain. To create a deposit request:- Approve spending of the token by the smart contract
- Call the deposit function of the smart contract with the following structured data:
| Name | Type | Required | Description |
|---|---|---|---|
| accountId | bytes | Y | The account ID of the user in bytes |
| brokerHash | bytes | Y | The keccak256 hash of the builder ID (e.g. “woofi_dex”) |
| tokenHash | bytes | Y | The keccak256 hash of the token string (e.g. “USDC”) |
| tokenAmount | int | Y | Amount of tokens to be deposited |
Withdrawal
To withdraw tokens from Orderly:- Choose a valid chain to withdraw your funds to
- Check if the chain has sufficient liquidity
- Get a withdrawal nonce
- Sign an EIP-712 message in the following format:
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of withdrawing chain (within those supported by the Network) |
| receiver | string | Y | Address of the receiver, which should be equal to the address of the account |
| token | string | Y | The string representation of the token being withdrawn (e.g. “USDC”) |
| amount | string | Y | Amount of tokens to be withdrawn |
| withdrawNonce | int | Y | Valid withdrawal nonce from Get withdrawal nonce |
| timestamp | timestamp | Y | Current timestamp in UNIX milliseconds |
- Call the request to withdraw API to complete the withdrawal request
Settle PnL
Any realized and unrealized PnL accrued from open or closed positions needs to be “settled” into the USDC balance of the account. PnL settlement can happen anytime for any account if other users trigger a settlement. Any user can also trigger PnL settlement of their own account by following these steps:- Get a Settle PnL nonce
- Sign an EIP-712 message in the following format:
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those supported by the Network) |
| settleNonce | int | Y | Valid settlement nonce from Get Settle PnL nonce |
| timestamp | timestamp | Y | Current timestamp in UNIX milliseconds |
- Call the Settle PnL API to complete the request