Links

Smart Contract API

This document describes how to interact with Orderly’s smart contract methods

Introduction

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

Contract Addresses (Mainnet)

Asset Manager asset-manager.orderly-network.near

Contract Addresses (Testnet)

Asset Manager asset-manager.orderly.testnet
USDC Faucet ft-faucet-usdc.orderly.testnet

Smart Contract Methods

Refer to this guide on how to use the listed methods.
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"}'

Authentication/Key Management

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*
Any data stored in the contract requires storage staking as per NEAR architecture
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

Storage Staking

Any data stored in the contract requires storage staking as per NEAR architecture
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

Deposit

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.

Asset Manager Methods

In order to deposit NEAR into the asset manager contract, call the following method:
get
user_deposit_native_token
Deposits NEAR into a wallet

Fungible Token Methods

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

Withdrawal

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

General Data Access

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

User Data

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
This guide is a WIP. If you have any suggestions or questions please contact us by email