CLI Usage
Describes how to use the contract via CLI.
We will use $CONTRACT_ID
for contract account id and $USER_ID
for user account id. $TOKEN1
, $TOKEN2
, etc are accounts for tokens.
You can set these variables via CLI: export CONTRACT_ID=ref-finance.testnet
Deploy contract
Deploy to TestNet, to an account $CONTRACT_ID
you have access keys for:
Add a simple pool
Add simple pool with 2 tokens and 0.3% total fee (0.04% goes to exchange and 0.01% goes to referral).
Query pools
To query first 10 pools:
Register account in the exchange
If there is a token that is not in whitelist, you also need to register it separately:
Query whitelisted tokens
This is list of tokens that don't need extra registration from the user. They are well known to the contract governance and are not expected to spam user's storage.
Check that account is registered and storage available
Deposit funds
Before sending funds for token X, make sure that exchange is registered for token X.
Actually deposit funds to the exchange (attaching 1yN for security):
Query deposit balances in the exchange
Add liquidity to a pool
Get pool's information
Get pool's accumulated volume
Get number of liquidity shares in the pool
Remove liquidity from a pool
Output amount after swap
Swap
Swap via a single pool:
Withdraw funds
To withdraw specific token from exchange back to user's account:
Check owner
Free up user's storage
First, during withdrawing tokens, if withdrawing everything - user can specify unregister: true
to also remove storage occupied by given token. Alternatively can call near call $CONTRACT_ID unregister_tokens "{\"token_ids\": [\"$TOKEN1\"]}" --accountId $USER_ID
to remove balance of $TOKEN1 from user.
When all storage has been freed up (e.g. near view $CONTRACT_ID get_deposits "{\"account_id\": \"$USER_ID\"}"
returns empty set), the user's account can be completely deleted:
Last updated