farms-cli

0.4.0 • Public • Published

Farms

The aim of this program is to provide a generic Farm/Staking Pool

The logic is the following:

  1. There is 1 global_admin which is used to manage flags that can enable/disable actions on the farm this will be expanded when new usecases are implemented
  2. Farms are permissionless and each farm can have a different global_admin, so anyone can create their own farm
  3. Each farm has one staking token but many staking rewards (the max number of reward tokens is defined in programs/farms/utils/consts.rs). 1 Staking token -> Many Reward Tokens
  4. Each farm/pool has many users
  5. A user can stake/unstake at any time and their accumulated rewards can be harvested separately. There is also a min_claim_duration that can be set for each individual reward in order to enforce a minimum time you need to wait until you can claim.
  6. The treasury vault is where fees can be accumulated. Initially there will be a 10% fee for any of the reward tokens, set in the global admin.

The staking logic is based on the current Hubble staking structure which is also based on the MasterChefV2 logic: https://github.com/1coinswap/core/blob/master/contracts/MasterChefV2.sol

Reward type

There are 2 types of rewards:

  • Proportional rewards: The reward is proportional to the amount of staked tokens. This is the default reward type. It is essentially a constant amount shared between all stakers and, by nature, dillutive. This is useful for yield farming.
  • Constant rewards: The reward is defined as per_staked amount not per_total_stake, and therefore not dillutive. This is useful for points or airdrops.

Rewards per second

  • Can be issues per second or per slot (you have to change the TimeUnit setting)
  • Can also be fractional if you set the reward_per_second_decimals to be > 0 such that we don't issue too much due to integer constraints
  • Rewards per second curve:
    • Rewards can be scheduled also on a step-wise curve

Locking

There are three locking methods:

  • None - no locking
  • Continuous:
    • Each user has their own locking period, therefore the locking duration applies from the moment the last "stake" action was performed
    • Note: In the case of Continuous locking, if you staked and are waiting for the locking duration to elapse and you stake again, then the timer will reset
  • WithExpiry:
    • The whole pool has the same locking expiry, which is equal to locking_start_timestamp + locking_duration

If locking_early_withdrawal_penalty_bps is set, then users could withdraw early after the penalty is applies. Note: the penalty is irreversible and it's going to the Farm's tresury, the admin of the fund being the only one able to withdraw.

How to install the SDK

yarn install

Client (CLI) Usage

.env file

In order to use the CLI, you will need a .env file. An example of it:

RPC=rpc
ADMIN=../user.json
FARMS_GLOBAL_CONFIG=6UodrBjL2ZreDy7QdR4YV1oxqMBjVYSEyrFpctqqwGwL
KLEND_PROGRAM_ID=SLendK7ySfcEzyaFqy93gDnD3RtrpXJcnRwb6zFHJSh
LENDING_MARKET=6WVSwDQXrBZeQVnu6hpnsRZhodaJTZBUaC334SiiBKdb
KLEND_POINTS_MINT=KpsgfQAhVwUosX1SL2eiwBHejcTe8UvwSj4UWwnZiBU
SCOPE_PRICES=3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C
MULTISIG=BbM3mbcLsa3QcYEVx8iovwfKaA1iZ6DK5fEbbtHwS3N8

cp ./.env.example ./.env

--mode parameter

Most commands will allow you to specify --mode which is used to specify how the txns are ran:

  • --mode simulate - Prints all the logs and simulates the transaction without execution
  • --mode execute - Prints all the logs and executes the transaction
  • --mode multisig - Prints no logs at all. The only output is the transaction in base58 - to be used for multisig

--priority-fee-multiplier paramter

Most commands will allow you to specify --priority-fee-multiplier which is used to set the multiplier pritority fee. The base is 1 lamport so --priority-fee-multiplier 50000 would mean 50_000 lamports.

How to create a global config

yarn ts-node farms-sdk/src/client.ts init-global-config

How to create a farm

yarn ts-node farms-sdk/src/client.ts init-farm --token-mint <mint_pk> --priority-fee-multiplier 50000 --mode execute

How to create a klend farm

npx ts-node farms-sdk/src/client.ts init-klend-farm --reserve <reserve_pk> --kind Collateral/Debt --multisig-to-execute <multisig_auth_pk> --pending-admin <multisig_auth_pk> --priority-fee-multiplier 50000 --mode execute

How to init a reward for a farm

npx ts-node farms-sdk/src/client.ts init-reward --farm <farm_pk> --reward-mint <mint_pk> --priority-fee-multiplier 50000 --mode execute

Initializing a reward can also be done by adding it to the config of an existing farm config. More details of this flow explained below.

How to update a farm

The easiest way to update and batch update farms is to use the following flow:

  1. Download all farm configs: npx ts-node farms-sdk/src/client.ts download-all-farm-configs --target-path configs/latest This will download all farms split in 3 main folders:
  • lending -> split in further folders for each market - based on the API, contains all farms (Coll/Debt) for all reserves for each market.
  • yvaults -> contains all farms for live strategies
  • standaloneFarms -> contains farms which are not included in the first two main folders
  1. Modify the configs you want to. Most modifications are straightforward and almost everything can be changed. To note:
  • rewardAvailable - only shows how much there is available - modifying won't change anything
  • rewardToTopUp - by default always 0 - modify this in order to create a top up change. By default this will be executed by your .env admin as this ixn is permissionless.
  • rewardToTopUpDurationDays - works with rewardToTopUp and is used to calculated the reqiured RPS for the given topUp -> will update the rewardCurve only if it's a signle value curve and it's not modified by you.
  1. Update everything by running: npx ts-node farms-sdk/src/client.ts upsert-all-farm-configs --target-path configs/latest --priority-fee-multiplier 50000 --mode print - to only see the diff of your changes npx ts-node farms-sdk/src/client.ts upsert-all-farm-configs --target-path configs/latest --priority-fee-multiplier 50000 --mode simulate - to only see the transaction simulation of your changes npx ts-node farms-sdk/src/client.ts upsert-all-farm-configs --target-path configs/latest --priority-fee-multiplier 50000 --mode execute/multisig - to either execute or get the bs58 txns for multisig

How to Initialize and Refresh user obligation for new Klend farm

  1. Download the obligations: npx ts-node farms-sdk/src/client.ts download-all-user-obligations-for-reserve --market <market> --reserve <reserve>

  2. Initialize all user obligations: npx ts-node farms-sdk/src/client.ts init-all-klend-user-obligation-farms-from-file --market <market> --file obligations-<reserve>.json

  3. Refresh all user obligations: npx ts-node farms-sdk/src/client.ts refresh-all-klend-obligation-farms-from-file --market <market> --file obligations-<reserve>.json

Readme

Keywords

none

Package Sidebar

Install

npm i farms-cli

Weekly Downloads

1

Version

0.4.0

License

ISC

Unpacked Size

52.6 MB

Total Files

305

Last publish

Collaborators

  • elliotkennedy