Smart Contract API
This document describes how to interact with Orderly’s smart contract methods
Smart contract frontend integration builds are based on the Near API JS library. Please review the Overview section to learn about action flows.
Orderly has three main contracts deployed that users will interact with:
asset-manager.orderly-network.near
asset-manager.orderly.testnet
ft-faucet-usdc.orderly.testnet
Asset Manager
asset-manager.orderly-network.near
Asset Manager
asset-manager.orderly.testnet
USDC Faucet
ft-faucet-usdc.orderly.testnet
Use NEAR API JS library to interact with the smart contract methods or the following format if using the CLI:
near call $CONTRACT function_name '{"parameter": "YOUR ACCOUNT_ID"}'
Our interfaces require two keys to access, Orderly Key Pair (
ed25519
) and Trading Key Pair (secp256k1
). Orderly Access Key Pair is generated by the wallet and more information can be found here and instructions on how to create the keys can be found here. Trading keys should be generated by the GUI.It is recommended to use function call keys rather than full access keys for safety
For first-time users, the following method is called to create an account:
get
storage_deposit
Registers an account in the smart contract/Deposit storage fee*
If an account already exists, the following method will connect Orderly Access keys to the smart contract:
get
user_announce_key
Binds Orderly Access Keys to the smart contract
After Orderly Access keys are generated and submitted to the smart contract, the trading keys should be generated using elliptic-curve cryptography, which can be found here, stored in the local storage, and then sent to the smart contract using the following method:
get
user_request_set_trading_key
Creates and binds user’s trading key to a users's orderly key
get
is_orderly_key_announced
Check if Orderly Key is announced
get
is_trading_key_set
Check if the Trading Key has been set
get
user_request_key_removal
Removes Orderly key
Use the following method if a user wishes to withdraw a specified amount of NEAR that was previously deposited for storage staking:
get
storage_withdraw
Withdraw a specified amount of NEAR from storage staking
get
storage_balance_bounds
Queries min and max values of storage cost required for initial registration
get
storage_balance_of
Checks the deposited value for storage staking
get
storage_cost_of_announce_key
Checks the cost of announcing key
get
storage_cost_of_token_balance
Check the cost of adding a new token
get
storage_unregister
Unregister the predecessor account and returns the storage NEAR deposit back
There are two ways to deposit tokens into a wallet, depending on the token type. NEAR is the only native token and all the other tokens are fungible tokens.
In order to deposit NEAR into the asset manager contract, call the following method:
get
user_deposit_native_token
Deposits NEAR into a wallet
In order to deposit any other token, known as fungible tokens, use the following method which will transfer tokens from a wallet into a smart contract.
get
ft_transfer_call
Transfers tokens from a wallet to the smart contract
If a user wishes to withdraw funds from the asset manager into their wallet, call the following method:
get
user_request_withdraw
Requests for token withdrawal
The number of pending withdrawals is limited to 10 per each user
get
user_withdraw_pending
Queries user's pending withdrawals
get
is_token_listed
Checks if a token is supported by Orderly
To retrieve a list of whitelisted tokens supported by Orderly use the following method. This can also be retrieved through Off-Chain APIs described in the next section.
get
get_listed_tokens
Gets a token whitelist
get
is_symbol_listed
Checks if a trading pair is listed
Given the off-chain/on-chain architecture, when users withdraw their funds, the smart contract checks the off-chain matching engine for pending orders to prevent double-spending. Orderly has implemented a fallback mechanism in case communication is lost between the two modules for a certain amount of time which can be checked using the following API:
get
get_max_operator_downtime_nanos
Manual withdrawal timelimit
This API checks for the time remaining until the contract goes into manual withdrawal mode:
get
get_withdraw_unlock_duration_nanos
Time left for manual withdrawal
get
get_user_info
Get user's account state
get
user_account_exists
Checks if user account exists
get
get_user_token_balance
Retrieves the user's balance for the specified token
To retrieve your trading key use the following function:
get
get_user_trading_key
Returns a trading key of the user
Last modified 1mo ago