Skip to content

Commit c163f11

Browse files
authored
Feature: Liquidity Mining CLI (#218)
* CLI has a script that upgrades all reserves * Adding CLI commands * Adding also reward views into the CLI * Note on looped rewards
1 parent 81cafd5 commit c163f11

21 files changed

+1301
-69
lines changed

Anchor.toml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,104 @@ url = "https://api.mainnet-beta.solana.com"
2929
[[test.validator.clone]]
3030
# Solend Main Pool - (USDC) Reserve State
3131
address = "BgxfHJDzm44T7XG68MYKx7YisTjZu73tVovyZSjJMpmw"
32+
# What follows is a list of some more reserves to clone to test batch upgrade
33+
[[test.validator.clone]]
34+
address = "46t9bCbiBwiVsjQPz2CLYcMULCtsZTBbwqLdAz7s2xXy"
35+
[[test.validator.clone]]
36+
address = "6RLEnWjEUR8MTTn8MtFXmw1Fz1JWjUVcC1bQFPqDXbgy"
37+
[[test.validator.clone]]
38+
address = "4o8bqVMVrjwbUEU69axoQB7LFDHHt58d2XMtPXFJ8tK1"
39+
[[test.validator.clone]]
40+
address = "3xLmLkoKSKddqg7ejPNq679ApQNnm2dn3VVvtV7isSDo"
41+
[[test.validator.clone]]
42+
address = "44JpnzauMCjmwHBN1VJe4rFVjidozsAeGMR5srzuWp55"
43+
[[test.validator.clone]]
44+
address = "4YA39gkfuskkp3ir1NZ9jySkHYocSnZoPY2oT64BRmb5"
45+
[[test.validator.clone]]
46+
address = "3NdKfP3qLSzxqQTkJpYL2gGBza1esdyakRrAyMLt64R2"
47+
[[test.validator.clone]]
48+
address = "59KjpUPKXsoYZUNdc8g2Yi32uAw9Brm6g8bQCfFVomyJ"
49+
[[test.validator.clone]]
50+
address = "5noExw6LxoDaoAbcaFj5YZbBhpXoMqazzZuBrAUeFiUj"
51+
[[test.validator.clone]]
52+
address = "5eLCVf61tRmv4V6WASMfR7X4skqXpEakqyaLMFrQETSB"
53+
[[test.validator.clone]]
54+
address = "rKBpHeyPyn9YU4VNtxaX6Tu618Y2R4sWybxUpea5ph4"
55+
[[test.validator.clone]]
56+
address = "5yq5AJTJMoRQvGFbA2h6wKRQMV7Z6CjfbZCa3cAJS2r5"
57+
[[test.validator.clone]]
58+
address = "gY2sQUkxEQPDcn2s72KBKmw9q343QpVhxU5WLu2sxjr"
59+
[[test.validator.clone]]
60+
address = "6TsJpaAbwJMTFZdAEHcVb86zQaLoNmbabYX1kkW1NAj7"
61+
[[test.validator.clone]]
62+
address = "6JLJ3eq8sHDjUBLy4zjvLjvyMjrqnUDizQEdcZqgaYrG"
63+
[[test.validator.clone]]
64+
address = "4kgzahtogzibeopWQBrKcCYPiavEAaV9sJjuZy9dUuic"
65+
[[test.validator.clone]]
66+
address = "6uhoHHFPQbRpssDphCjxU6hMmXp3GLS2qAZmCExZkwap"
67+
[[test.validator.clone]]
68+
address = "13Ts1ERfwAM11MVQAU3zCz49fGkWmdZbfXuTGyKz6ENy"
69+
[[test.validator.clone]]
70+
address = "14aRZgQAQtGRES3mNTFvEVEfEqtnKJa73ryENDAvJFaQ"
71+
[[test.validator.clone]]
72+
address = "6e8zg2Y9skA5AMm7J62GJQ8Ui4reuzEytBS74zHV8S7A"
73+
[[test.validator.clone]]
74+
address = "6QNF4ovs4vWqjjvNUNoJLhXCW34iEm2QGipRKJdk725n"
75+
[[test.validator.clone]]
76+
address = "yjuWAA6XXhEwxWuzbPfDPnYiohCLFqAfgCDA4EdHHDm"
77+
[[test.validator.clone]]
78+
address = "XK8FEMEziMX9W46ivFmjddjvW3aY8dkVvucEGLmrt5D"
79+
[[test.validator.clone]]
80+
address = "2WBEmjZbUMXZbs9ucG3B7254y2C34d72uv2qHjvR1T4n"
81+
[[test.validator.clone]]
82+
address = "yxW7QwpJzKxfNo2QkbcmgjpgFxEL4UGbUivkFWtkmd3"
83+
[[test.validator.clone]]
84+
address = "66RtjhW1bMXTJ2ZL8TMowUTAtraHiksKGGQSArGRZKAZ"
85+
[[test.validator.clone]]
86+
address = "3Cv8evqFV1MWirL1ohv2VsdTAmpDvNWy4veGjYDFrWn2"
87+
[[test.validator.clone]]
88+
address = "5rDqwn1GMMrSkjvZS1G7BZ2tR5Q4JS13wnSHn11La9a9"
89+
[[test.validator.clone]]
90+
address = "4ERjFetPd5DQDK8N9wL4i36ozs4zeW1MeGbPbKw9QMsy"
91+
[[test.validator.clone]]
92+
address = "5hevPuvhqmXdQcuiB2mqekxQcqL9kVix8D5ckRGyA8yk"
93+
[[test.validator.clone]]
94+
address = "62M3oYeJ2agvuHsgHfzJuiWsTbEewZCFJbMHXKDkKMqL"
95+
[[test.validator.clone]]
96+
address = "6DF8vRKZKdAK2rdirJTwG3TWogjgByqcEi5WbnwXb3YZ"
97+
[[test.validator.clone]]
98+
address = "3mSMHPvNewL8RTwAcA6GTCLjS19J3NK2huJxgA553oHy"
99+
[[test.validator.clone]]
100+
address = "75EgKN1rrVssMQr6KjvR5w6Gnth8FkqECgZ6Q4mDDCx6"
101+
[[test.validator.clone]]
102+
address = "2tSNdecgEHEidEemg9vCbgFPzg6nyok97xJc1Lse3mG8"
103+
[[test.validator.clone]]
104+
address = "3Hr5qshXDQgbL1za6Sayug61Hwt5rjnV7dbyE9NUQDaZ"
105+
[[test.validator.clone]]
106+
address = "2v3Y19ahC3dtV6CnrmT5vZfpJy7HkyFoxkRgTeuk6cC4"
107+
[[test.validator.clone]]
108+
address = "53oro4QCCqqtDgfs1qfeH5LyvfdSexjXXaT14drTJ2Xj"
109+
[[test.validator.clone]]
110+
address = "7kL41rV8tgRBticXUyp3LfCV7eBGKUrAwL2e7GJB5ooP"
111+
[[test.validator.clone]]
112+
address = "7t3QnGAqse8zvAohJJX7robsBviyP5Bg7xNBxi7HSPNy"
113+
[[test.validator.clone]]
114+
address = "7vcWs9Gut1HE8o24cfuYkjuFCdBMEkBALqqvLDnQsBQT"
115+
[[test.validator.clone]]
116+
address = "2j8XVnUFk6Hxm75QdJn6MDyxVE9QCbCe5BauGg82ANZU"
117+
[[test.validator.clone]]
118+
address = "81EGVb5RD8yft1N3SGxitn2QnvJg7Pbq5k4CiXkf3f5A"
119+
[[test.validator.clone]]
120+
address = "7UgZy6RzhfSG66qrdD7Q5LHrVJRm7bUqhRHPh9siBqQQ"
121+
[[test.validator.clone]]
122+
address = "3kWqRMVepJ5HSmXF16bBWQYQ5C7YNGvJJqCPt3A7zKWH"
123+
[[test.validator.clone]]
124+
address = "8NVfgFqWPiy7B4o4yQQ8XSTwSihidtdftA1wzeePnCeJ"
125+
[[test.validator.clone]]
126+
address = "3738W1f4ygKayow8TrFGuDbhFovQ3QhM2MPY8AF375ki"
127+
[[test.validator.clone]]
128+
address = "7ssc2gVnucKKwsh6DS4HYHUWAigJomW6v37T65SXJVEr"
129+
[[test.validator.clone]]
130+
address = "2wDArvF5bAdLmmm4QZNVFJDrML6CCBbfbCeCLEb7c6QN"
131+
[[test.validator.clone]]
132+
address = "41SrrxMb1yzivSbUNjLShRV5yZf7S7YdQ1Emg2AxCviu"

Cargo.lock

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token-lending/LIQUIDITY_MINING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ We keep adding `(total_rewards * time_passed) / (total_time)` every time someone
3939
This value is used to transfer the unallocated rewards to the admin.
4040
However, this can be calculated dynamically which avoids storing an extra packed decimal (16 bytes) on each reserve's pool reward (30).
4141

42+
In Suilend, we disable looped rewards.
43+
For example, if an obligation has reserve $USDC and $USDT, this obligation cannot claim rewards.
44+
This is not done in Save.
45+
4246
## New ixs
4347

4448
There's a common concept of reward vault and reward vault authority across the ixs.
@@ -73,7 +77,7 @@ Users will still be able to claim rewards they accrued until this point.
7377
#### Cancel
7478

7579
Cancelling a pool reward can be done by setting the end time to 0.
76-
Note that only rewards longer than [solend_sdk::MIN_REWARD_PERIOD_SECS] can be cancelled.
80+
Note that only rewards longer than `solend_sdk::MIN_REWARD_PERIOD_SECS` can be cancelled.
7781
In this case we transfer tokens from the reward vault to the lending market reward token account.
7882

7983
#### Shorten

token-lending/cli/Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "solend-program-cli"
3-
version.workspace = true
3+
version = "2.1.0"
44
authors = ["Solend Maintainers <[email protected]>"]
55
description = "Solend Program CLI"
66
edition = "2018"
@@ -9,21 +9,22 @@ license = "Apache-2.0"
99
repository = "https://github.com/solendprotocol/solana-program-library"
1010

1111
[dependencies]
12+
bincode = "1.3.3"
1213
clap = "=2.34.0"
14+
indicatif = "0.17.11"
15+
reqwest = { version = "0.12.2", features = ["blocking", "json"] }
16+
serde_json = "1.0.120"
17+
solana-account-decoder = "1.14.10"
1318
solana-clap-utils = "1.14.10"
1419
solana-cli-config = "1.14.10"
1520
solana-client = "1.14.10"
1621
solana-logger = "1.14.10"
17-
solana-sdk = "1.14.10"
1822
solana-program = "1.14.10"
19-
solend-sdk = { path = "../sdk" }
23+
solana-sdk = "1.14.10"
2024
solend-program = { path = "../program", features = ["no-entrypoint"] }
21-
spl-token = { version = "3.3.0", features = ["no-entrypoint"] }
25+
solend-sdk = { path = "../sdk" }
2226
spl-associated-token-account = "1.0"
23-
solana-account-decoder = "1.14.10"
24-
reqwest = { version = "0.12.2", features = ["blocking", "json"] }
25-
bincode = "1.3.3"
26-
serde_json = "1.0.120"
27+
spl-token = { version = "3.3.0", features = ["no-entrypoint"] }
2728

2829
[[bin]]
2930
name = "solend-cli"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! CLI commands related to liquidity mining.
2+
3+
mod add_pool_reward;
4+
mod close_pool_reward;
5+
mod crank_pool_rewards;
6+
mod edit_pool_reward;
7+
mod find_obligations_to_fund;
8+
mod migrate_all_reserves;
9+
mod view_obligation_rewards;
10+
mod view_reserve_rewards;
11+
12+
pub(crate) use add_pool_reward::command as command_add_pool_reward;
13+
pub(crate) use close_pool_reward::command as command_close_pool_reward;
14+
pub(crate) use crank_pool_rewards::command as command_crank_pool_rewards;
15+
pub(crate) use edit_pool_reward::command as command_edit_pool_reward;
16+
pub(crate) use find_obligations_to_fund::command as command_find_obligations_to_fund_for_liquidity_mining;
17+
pub(crate) use migrate_all_reserves::command as command_migrate_all_reserves_for_liquidity_mining;
18+
pub(crate) use view_obligation_rewards::command as command_view_obligation_rewards;
19+
pub(crate) use view_reserve_rewards::command as command_view_reserve_rewards;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//! Adds a pool reward to a reserve.
2+
//!
3+
//! The signer must be the owner of the lending market, and there must be a free slot in the reserve.
4+
5+
use std::{borrow::Borrow, str::FromStr};
6+
7+
use solana_program::program_pack::Pack;
8+
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction};
9+
use solend_sdk::{
10+
instruction::{add_pool_reward, find_reward_vault_authority},
11+
state::{LendingMarket, PoolRewardEntry, PositionKind, Reserve},
12+
};
13+
14+
use crate::{send_transaction, CommandResult, Config};
15+
16+
pub(crate) fn command(
17+
config: &mut Config,
18+
reserve_pubkey: Pubkey,
19+
position_kind: PositionKind,
20+
source_reward_token_account_pubkey: Pubkey,
21+
start_time_secs: u64,
22+
duration_secs: u32,
23+
token_amount: u64,
24+
) -> CommandResult {
25+
let reserve_info = config.rpc_client.get_account(&reserve_pubkey)?;
26+
let reserve = Reserve::unpack_from_slice(reserve_info.data.borrow())?;
27+
let lending_market_info = config.rpc_client.get_account(&reserve.lending_market)?;
28+
let lending_market = LendingMarket::unpack(lending_market_info.data.borrow())?;
29+
30+
if config.fee_payer.pubkey() != lending_market.owner {
31+
return Err(format!(
32+
"The fee payer must be the owner of the lending market '{}'",
33+
reserve.lending_market
34+
)
35+
.into());
36+
}
37+
38+
let has_free_slot = reserve
39+
.pool_reward_manager(position_kind)
40+
.pool_rewards
41+
.iter()
42+
.any(|pr| matches!(pr, PoolRewardEntry::Vacant { .. }));
43+
44+
if !has_free_slot {
45+
return Err(
46+
"There are no vacant slots to add the pool reward. Please crank it first".into(),
47+
);
48+
}
49+
50+
let Some(source_reward_token_account) = config
51+
.rpc_client
52+
.get_token_account(&source_reward_token_account_pubkey)?
53+
else {
54+
return Err(format!(
55+
"Failed to fetch source token account '{}'",
56+
source_reward_token_account_pubkey
57+
)
58+
.into());
59+
};
60+
61+
let reward_mint = Pubkey::from_str(&source_reward_token_account.mint)?;
62+
63+
let reward_vault_keypair = Keypair::new();
64+
65+
let create_account_ix = system_instruction::create_account(
66+
&config.fee_payer.pubkey(),
67+
&reward_vault_keypair.pubkey(),
68+
config
69+
.rpc_client
70+
.get_minimum_balance_for_rent_exemption(spl_token::state::Account::LEN)?,
71+
spl_token::state::Account::LEN as _,
72+
&spl_token::id(),
73+
);
74+
75+
let (reward_vault_authority, reward_authority_bump) = find_reward_vault_authority(
76+
&config.lending_program_id,
77+
&reserve.lending_market,
78+
&reward_vault_keypair.pubkey(),
79+
);
80+
81+
let add_reward_ix = add_pool_reward(
82+
config.lending_program_id,
83+
reward_authority_bump,
84+
position_kind,
85+
start_time_secs,
86+
start_time_secs + duration_secs as u64,
87+
token_amount,
88+
reserve_pubkey,
89+
reward_mint,
90+
source_reward_token_account_pubkey,
91+
reward_vault_authority,
92+
reward_vault_keypair.pubkey(),
93+
reserve.lending_market,
94+
lending_market.owner,
95+
);
96+
97+
let recent_blockhash = config.rpc_client.get_latest_blockhash()?;
98+
99+
let message = solana_sdk::message::Message::new_with_blockhash(
100+
&[create_account_ix, add_reward_ix],
101+
Some(&config.fee_payer.pubkey()),
102+
&recent_blockhash,
103+
);
104+
105+
let transaction = solana_sdk::transaction::Transaction::new(
106+
&vec![config.fee_payer.as_ref()],
107+
message,
108+
recent_blockhash,
109+
);
110+
111+
send_transaction(config, transaction)?;
112+
113+
Ok(())
114+
}

0 commit comments

Comments
 (0)