Accounts / Access keys
Account Structure
A wallet owner can register an account on Orderly for each builder that is supported. Each wallet owner could thus have multiple accounts (that are not interlinked with each other) registered with Orderly.Account ID
Each account is identified by an account id, which can be calculated by- Converting the wallet address to bytes
- Converting the keccak256 hash of the brokerId string to bytes
- Concatenating (1) and (2)
- Convert back to Hex String, the keccak256 hash of the result of (3)
Authorization
Orderly relies on 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 libraries (such as this one) and then be added to any account through a REST API. Access keys can have different scopes. A read scope API can access all private read-only APIs, and a trading scope can, in addition, 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). Access keys also have expirations for security reasons. The maximum allowed expiration of an access key is 365 days.Account Registration
Follow the following steps 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 account already exists via this API.
- Get a nonce from Get registration nonce API
- Sign a message from the wallet in the following format using the EIP-712 standard and obtain the signature
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those that are supported by the Network) |
| timestamp | timestamp | Y | timestamp in UNIX milliseconds |
| registrationNonce | string | Y | Valid nonce from Get registration nonce |
Add Access Key
Follow the following steps to add a new access key on Orderly:- Generate an ed25519 key-pair
- Sign a message from the wallet in the following format using the EIP-712 standard and obtain the signature
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those that are 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 Add Orderly key API Users can also check the validity of a particularly Orderly access key via the Get Orderly key API.
Deposits / Withdrawals
Deposit
Token deposits can be made on any supported chains To create a deposit request, users can follow the following steps:- Approve spending of the token by the smart contract
- Call the deposit function of the smart contract, containing 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 (eg “woofi_dex”) |
| tokenHash | bytes | Y | The keccak256 hash of the token string (eg “USDC”) |
| tokenAmount | int | Y | Amount of tokens to be deposited |
Withdrawal
Follow the following steps to withdraw your 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 that are 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 that is being withdrawn (eg “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
- Call the Settle PnL API to complete the request
| Name | Type | Required | Description |
|---|---|---|---|
| brokerId | string | Y | Builder ID |
| chainId | int | Y | Chain ID of registering chain (within those that are supported by the Network) |
| settleNonce | int | Y | Valid settlement nonce from Get Settle PnL nonce |
| timestamp | timestamp | Y | current timestamp in UNIX milliseconds |