R
R
Ref Finance
Search…
CLI Farming
Commande-Line Interface Usage for Ref Farming
You can setup the following parameters:
1
export FARMING=ref-farming.testnet
2
export EX=ref-finance.testnet
3
export TOKEN=token.ref-finance.testnet
Copied!

View general information

1
near view $FARMING get_metadata
Copied!

View all farms with pagination

1
near view $FARMING list_farms '{"from_index": 0, "limit": 100}'
Copied!
Notes:
  • Outdated_farms are excluded
  • There are three farm_status in contract, they are Created, Running, Ended
  • start_at is timestamp in seconds
  • session_interval is timestamp in seconds

View all seeds with pagination

1
near view $FARMING list_seeds_info '{"from_index": 0, "limit": 100}'
Copied!

View all rewards with pagination

1
near view $FARMING list_rewards_info '{"from_index": 0, "limit": 100}'
Copied!

View single seed information

1
near view $FARMING get_seed_info "{\"seed_id\": \"[email protected]\"}"
Copied!

View all farms per seed

1
near view $FARMING list_farms_by_seed "{\"seed_id\": \"[email protected]\"}"
Copied!

View single farm information

1
near view $FARMING get_farm "{\"farm_id\": \"[email protected]#0\"}"
Copied!

View rewards per user

1
near view $FARMING list_rewards '{"account_id": "pika456.testnet"}'
Copied!

View unclaimed rewards per user

1
near view $FARMING get_unclaimed_reward "{\"account_id\": \"pika456.testnet\", \"farm_id\": \"[email protected]#0\"}"
Copied!

View seeds per user

1
near view $FARMING list_user_seeds '{"account_id": "pika456.testnet"}'
Copied!

Stake/Unstake seed

1
# if needed, register user to the farming
2
near call $FARMING storage_deposit '{"account_id": "u1.testnet", "registration_only": true}' --account_id=u1.testnet --amount=1
3
4
# if needed, register farming contract to seed token
5
near call $EX mft_register "{\"token_id\":\"31\", \"account_id\": \"$FARMING\"}" --account_id=u1.testnet --amount=0.01
6
7
# staking
8
near call $EX mft_transfer_call "{\"receiver_id\": \"$FARMING\", \"token_id\":\"31\", \"amount\": \"1000000000000000000000000\", \"msg\": \"\"}" --account_id=u1.testnet --amount=0.000000000000000000000001
9
10
# unstaking
11
near call $FARMING withdraw_seed "{\"seed_id\": \"[email protected]\", \"amount\": \"1000000000000000000000000\"}" --account_id=u1.testnet --amount=0.000000000000000000000001
Copied!

Claim rewards

1
# you can claim reward per farm
2
near call $FARMING claim_reward_by_farm "{\"farm_id\": \"[email protected]#1\"}" --account_id=u1.testnet --amount=0.000000000000000000000001
3
4
# or you can claim reward per seed (kind of batch claim)
5
near call $FARMING claim_reward_by_seed "{\"seed_id\": \"[email protected]\"}" --account_id=u1.testnet --amount=0.000000000000000000000001
Copied!

Withdraw reward token

1
# amount set to 0 means withdraw all balance
2
near call $FARMING withdraw_reward "{\"token_id\": \"$TOKEN\", \"amount\": \"0\"}" --account_id=u1.testnet --amount=0.000000000000000000000001
Copied!

Create farm

At the moment, only the owner of this contract can create farms
To create a farm, you need to prepare the farming terms accordingly.
1
near call $FARMING create_simple_farm "{\"terms\": {\"seed_id\": \"[email protected]\", \"reward_token\": \"$TOKEN\", \"start_at\": 0, \"reward_per_session\": \"10000000000000000000\", \"session_interval\": 3600}}\" --account_id=pika456.testnet --amount 0.01
2
# this will return a farm id like [email protected]#0
Copied!
At this point, this is a farm with no reward deposited, farm status is Created.
To activate a farm, deposit some reward tokens into the farm with ft_transfer_call.
1
# if needed, register farming contract to reward token
2
near call $TOKEN storage_deposit "{\"account_id\": \"$FARMING\"}" --account_id=pika456.testnet --amount 0.00125
3
4
# deposit reward token into the farm
5
near call $TOKEN ft_transfer_call "{\"receiver_id\": \"$FARMING\", \"amount\": \"2400000000000000000000\", \"msg\": \"[email protected]#0\"}" --account_id=$REF_OWNER --amount=0.000000000000000000000001 --gas=100000000000000
Copied!