On-Chain Order/Swap
The current Orderly architecture has an off-chain order book, and the orders are placed through an off-chain RESTful API.
Users might want to perform a swap/trade without interacting with off-chain components. We have created on-chain order support, where orders can be placed directly through the smart contract rather than the RESTful API.
The on-chain swap includes three steps under a single smart contract call: deposit, trade, and withdraw.
The on-chain order includes two steps under a single smart contract call: trade and withdraw.
Please note, all quotes and trades are against USDC as the quote currency
Before placing an order, a user first has to announce Orderly and Trading Key and make a storage deposit, more info here.
After the required steps are completed, the following smart contract function can be called to initiate an order:
All on-chain orders require a signature, more details on how to generate one can be found here
Create an On-chain Order
create_onchain_order
Parameters:
Example:
Create an On-chain Swap
Fungible token
Storage has to be paid for each token being swapped from and to, otherwise, tokens may fail to withdraw with the error message “Smart contract panicked: panicked at 'The account is not registered'
” Check here for more details on storage deposit.
ft_transfer_call
Parameters:
Example:
NEAR token
deposit_and_create_order
Parameters:
Example:
Get the On-chain Order Fee
get_onchain_order_fee
Parameters:
Returns the fee needed to create an on-chain order in Yocto NEAR amount.
When placing an order, an amount of NEAR equivalent to the result from this function has to be attached to the contract call.