Skip to content

Commit a16b59f

Browse files
committed
Merge branch 'main' into add_sfrax
2 parents a708597 + 5f6ec6d commit a16b59f

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

doc/user_interfaces.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Ref V1 User Interfaces
2+
3+
## user swap
4+
```bash
5+
# prerequisite: make sure you have registered the swap-out token
6+
near view token_out.testnet storage_balance_of '{"account_id": "alice.testnet"}'
7+
# if not, register it
8+
near call token_out.testnet storage_deposit '{"account_id": "alice.testnet", "registration_only": true}' --accountId=alice.testnet --deposit=1
9+
10+
# compose your instant swap actions
11+
export ACT='{\"pool_id\": 123, \"token_in\": \"token_in.testnet\", \"token_out\": \"token_out.testnet\", \"min_amount_out\": \"0\"}'
12+
export ACTS='{\"actions\": ['$ACT']}'
13+
14+
# multiple actions are also supported
15+
export ACT1='{\"pool_id\": 123, \"token_in\": \"token1.testnet\", \"token_out\": \"token2.testnet\", \"min_amount_out\": \"0\"}'
16+
export ACT2='{\"pool_id\": 456, \"token_in\": \"token2.testnet\", \"token_out\": \"token3.testnet\", \"min_amount_out\": \"0\"}'
17+
export ACTS='{\"actions\": ['$ACT1', '$ACT2']}'
18+
19+
# referral_id is optional
20+
export ACTS='{\"actions\": ['$ACT'],\"referral_id\":\"referral.testnet\"}'
21+
22+
# can set optional skip_unwrap_near to false to request auto-unwrap wnear to near if the finally swap_out token is wnear
23+
# the default behavior is to skip the unwrap, sent wnear directly.
24+
export ACTS='{\"actions\": ['$ACT'],\"skip_unwrap_near\":false}'
25+
26+
# finally, send the swap request
27+
near call token1.testnet ft_transfer_call '{"receiver_id": "ref-v1.testnet", "amount": "1000", "msg": "'$ACTS'"}' --accountId=alice.testnet --depositYocto=1 --gas=100$TGAS
28+
```
29+
30+
## liquidity management
31+
### inner account
32+
```bash
33+
# user should establish inner account before interact with liquidity
34+
# prerequisit: register to be ref-v1 user
35+
near call ref-v1.testnet storage_deposit '{"account_id": "alice.testnet", "registration_only": false}' --accountId=alice.testnet --deposit=0.1
36+
near view ref-v1.testnet storage_balance_of '{"account_id": "alice.testnet"}'
37+
38+
# deposit tokens into ref-v1
39+
near call token1.testnet ft_transfer_call '{"receiver_id": "ref-v1.testnet", "amount": "100", "msg": ""}' --accountId=alice.testnet --depositYocto=1 --gas=100$TGAS
40+
# can check the deposited tokens in user's ref-v1 inner account
41+
near view ref-v1.testnet get_deposits '{"account_id": "alice.testnet"}'
42+
near view ref-v1.testnet get_deposit '{"account_id": "alice.testnet", "token_id": "token1.testnet"}'
43+
44+
# withdraw at any time
45+
# the skip_unwrap_near indicator also works here
46+
near call ref-v1.testnet withdraw '{"skip_unwrap_near": false, "token_id": "wrap.testnet","amount": "1000000000000000000000000","unregister": false}' --account_id=alice.testnet --depositYocto=1 --gas=100$TGAS
47+
```
48+
### Add Liquidity
49+
Use tokens in inner account to add liquidity to the given pool.
50+
```bash
51+
# query pools
52+
near view ref-v1.testnet get_pool_by_ids '{"pool_ids": [1, 2, 5]}'
53+
near view ref-v1.testnet get_stable_pool '{"pool_id": 0}'
54+
near view ref-v1.testnet get_rated_pool '{"pool_id": 1}'
55+
near view ref-v1.testnet get_pool '{"pool_id": 2}'
56+
near view ref-v1.testnet get_pool_share_price '{"pool_id": 3}'
57+
# add liquidity to the pool,
58+
# the tokens would be added proportionally,
59+
# and the unused part would stay in user's ref-v1 inner account
60+
near call ref-v1.testnet add_liquidity '{"pool_id": 123, "amounts":[ "100","200"]}' --accountId=alice.testnet --deposit=0.01
61+
62+
# for stable pools and rated stable pools, can add liquidity with a subset of tokens and arbitrary amounts
63+
near call ref-v1.testnet add_liquidity '{"pool_id": 1234, "amounts":[ "100","0"]}' --accountId=alice.testnet --deposit=0.01
64+
65+
# user can check his lp token balance
66+
near view ref-v1.testnet mft_balance_of '{"token_id": ":123", "account_id": "alice.testnet"}'
67+
```
68+
### Transfer Liquidity
69+
```bash
70+
# prerequisit: make sure the recipient has registered the lp token on the given pool
71+
near view ref-v1.testnet mft_has_registered '{"token_id":":123", "account_id": "bob.testnet"}'
72+
near call ref-v1.testnet mft_register '{"token_id":":123", "account_id": "bob.testnet"}' --accountId=alice.testnet --deposit=0.01
73+
74+
# transfer lp token to other user, memo is optional
75+
near call call ref-v1.testnet mft_transfer '{"token_id":":123", "receiver_id": "bob.testnet", "amount": "12345", "memo": "test transfer"}' --accountId=alice.testnet --depositYocto 1 --gas=100$TGAS
76+
```
77+
78+
### remove liquidity
79+
Tokens acquired from remove liqidity goes to user's inner account.
80+
```bash
81+
# remove by shares
82+
near call ref-v1.testnet remove_liquidity '{"pool_id": 123, "shares": "1234", "min_amounts": ["0", "0"]}' --accountId=alice.testnet --depositYocto=1
83+
84+
# for stable pools and rated stable pools, can also remove by tokens
85+
near call ref-v1.testnet remove_liquidity_by_tokens '{"pool_id": 1234, "amounts": [ "123", "98"], "max_burn_shares": "120"}' --account_id=alice.testnet --depositYocto=1
86+
```

0 commit comments

Comments
 (0)