Skip to content

Feature: Liquidity Mining CLI #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feat/liquidity-mining
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,104 @@ url = "https://api.mainnet-beta.solana.com"
[[test.validator.clone]]
# Solend Main Pool - (USDC) Reserve State
address = "BgxfHJDzm44T7XG68MYKx7YisTjZu73tVovyZSjJMpmw"
# What follows is a list of some more reserves to clone to test batch upgrade
[[test.validator.clone]]
address = "46t9bCbiBwiVsjQPz2CLYcMULCtsZTBbwqLdAz7s2xXy"
[[test.validator.clone]]
address = "6RLEnWjEUR8MTTn8MtFXmw1Fz1JWjUVcC1bQFPqDXbgy"
[[test.validator.clone]]
address = "4o8bqVMVrjwbUEU69axoQB7LFDHHt58d2XMtPXFJ8tK1"
[[test.validator.clone]]
address = "3xLmLkoKSKddqg7ejPNq679ApQNnm2dn3VVvtV7isSDo"
[[test.validator.clone]]
address = "44JpnzauMCjmwHBN1VJe4rFVjidozsAeGMR5srzuWp55"
[[test.validator.clone]]
address = "4YA39gkfuskkp3ir1NZ9jySkHYocSnZoPY2oT64BRmb5"
[[test.validator.clone]]
address = "3NdKfP3qLSzxqQTkJpYL2gGBza1esdyakRrAyMLt64R2"
[[test.validator.clone]]
address = "59KjpUPKXsoYZUNdc8g2Yi32uAw9Brm6g8bQCfFVomyJ"
[[test.validator.clone]]
address = "5noExw6LxoDaoAbcaFj5YZbBhpXoMqazzZuBrAUeFiUj"
[[test.validator.clone]]
address = "5eLCVf61tRmv4V6WASMfR7X4skqXpEakqyaLMFrQETSB"
[[test.validator.clone]]
address = "rKBpHeyPyn9YU4VNtxaX6Tu618Y2R4sWybxUpea5ph4"
[[test.validator.clone]]
address = "5yq5AJTJMoRQvGFbA2h6wKRQMV7Z6CjfbZCa3cAJS2r5"
[[test.validator.clone]]
address = "gY2sQUkxEQPDcn2s72KBKmw9q343QpVhxU5WLu2sxjr"
[[test.validator.clone]]
address = "6TsJpaAbwJMTFZdAEHcVb86zQaLoNmbabYX1kkW1NAj7"
[[test.validator.clone]]
address = "6JLJ3eq8sHDjUBLy4zjvLjvyMjrqnUDizQEdcZqgaYrG"
[[test.validator.clone]]
address = "4kgzahtogzibeopWQBrKcCYPiavEAaV9sJjuZy9dUuic"
[[test.validator.clone]]
address = "6uhoHHFPQbRpssDphCjxU6hMmXp3GLS2qAZmCExZkwap"
[[test.validator.clone]]
address = "13Ts1ERfwAM11MVQAU3zCz49fGkWmdZbfXuTGyKz6ENy"
[[test.validator.clone]]
address = "14aRZgQAQtGRES3mNTFvEVEfEqtnKJa73ryENDAvJFaQ"
[[test.validator.clone]]
address = "6e8zg2Y9skA5AMm7J62GJQ8Ui4reuzEytBS74zHV8S7A"
[[test.validator.clone]]
address = "6QNF4ovs4vWqjjvNUNoJLhXCW34iEm2QGipRKJdk725n"
[[test.validator.clone]]
address = "yjuWAA6XXhEwxWuzbPfDPnYiohCLFqAfgCDA4EdHHDm"
[[test.validator.clone]]
address = "XK8FEMEziMX9W46ivFmjddjvW3aY8dkVvucEGLmrt5D"
[[test.validator.clone]]
address = "2WBEmjZbUMXZbs9ucG3B7254y2C34d72uv2qHjvR1T4n"
[[test.validator.clone]]
address = "yxW7QwpJzKxfNo2QkbcmgjpgFxEL4UGbUivkFWtkmd3"
[[test.validator.clone]]
address = "66RtjhW1bMXTJ2ZL8TMowUTAtraHiksKGGQSArGRZKAZ"
[[test.validator.clone]]
address = "3Cv8evqFV1MWirL1ohv2VsdTAmpDvNWy4veGjYDFrWn2"
[[test.validator.clone]]
address = "5rDqwn1GMMrSkjvZS1G7BZ2tR5Q4JS13wnSHn11La9a9"
[[test.validator.clone]]
address = "4ERjFetPd5DQDK8N9wL4i36ozs4zeW1MeGbPbKw9QMsy"
[[test.validator.clone]]
address = "5hevPuvhqmXdQcuiB2mqekxQcqL9kVix8D5ckRGyA8yk"
[[test.validator.clone]]
address = "62M3oYeJ2agvuHsgHfzJuiWsTbEewZCFJbMHXKDkKMqL"
[[test.validator.clone]]
address = "6DF8vRKZKdAK2rdirJTwG3TWogjgByqcEi5WbnwXb3YZ"
[[test.validator.clone]]
address = "3mSMHPvNewL8RTwAcA6GTCLjS19J3NK2huJxgA553oHy"
[[test.validator.clone]]
address = "75EgKN1rrVssMQr6KjvR5w6Gnth8FkqECgZ6Q4mDDCx6"
[[test.validator.clone]]
address = "2tSNdecgEHEidEemg9vCbgFPzg6nyok97xJc1Lse3mG8"
[[test.validator.clone]]
address = "3Hr5qshXDQgbL1za6Sayug61Hwt5rjnV7dbyE9NUQDaZ"
[[test.validator.clone]]
address = "2v3Y19ahC3dtV6CnrmT5vZfpJy7HkyFoxkRgTeuk6cC4"
[[test.validator.clone]]
address = "53oro4QCCqqtDgfs1qfeH5LyvfdSexjXXaT14drTJ2Xj"
[[test.validator.clone]]
address = "7kL41rV8tgRBticXUyp3LfCV7eBGKUrAwL2e7GJB5ooP"
[[test.validator.clone]]
address = "7t3QnGAqse8zvAohJJX7robsBviyP5Bg7xNBxi7HSPNy"
[[test.validator.clone]]
address = "7vcWs9Gut1HE8o24cfuYkjuFCdBMEkBALqqvLDnQsBQT"
[[test.validator.clone]]
address = "2j8XVnUFk6Hxm75QdJn6MDyxVE9QCbCe5BauGg82ANZU"
[[test.validator.clone]]
address = "81EGVb5RD8yft1N3SGxitn2QnvJg7Pbq5k4CiXkf3f5A"
[[test.validator.clone]]
address = "7UgZy6RzhfSG66qrdD7Q5LHrVJRm7bUqhRHPh9siBqQQ"
[[test.validator.clone]]
address = "3kWqRMVepJ5HSmXF16bBWQYQ5C7YNGvJJqCPt3A7zKWH"
[[test.validator.clone]]
address = "8NVfgFqWPiy7B4o4yQQ8XSTwSihidtdftA1wzeePnCeJ"
[[test.validator.clone]]
address = "3738W1f4ygKayow8TrFGuDbhFovQ3QhM2MPY8AF375ki"
[[test.validator.clone]]
address = "7ssc2gVnucKKwsh6DS4HYHUWAigJomW6v37T65SXJVEr"
[[test.validator.clone]]
address = "2wDArvF5bAdLmmm4QZNVFJDrML6CCBbfbCeCLEb7c6QN"
[[test.validator.clone]]
address = "41SrrxMb1yzivSbUNjLShRV5yZf7S7YdQ1Emg2AxCviu"
40 changes: 24 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion token-lending/LIQUIDITY_MINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Users will still be able to claim rewards they accrued until this point.
#### Cancel

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

#### Shorten
Expand Down
17 changes: 9 additions & 8 deletions token-lending/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solend-program-cli"
version.workspace = true
version = "2.1.0"
authors = ["Solend Maintainers <[email protected]>"]
description = "Solend Program CLI"
edition = "2018"
Expand All @@ -9,21 +9,22 @@ license = "Apache-2.0"
repository = "https://github.com/solendprotocol/solana-program-library"

[dependencies]
bincode = "1.3.3"
clap = "=2.34.0"
indicatif = "0.17.11"
reqwest = { version = "0.12.2", features = ["blocking", "json"] }
serde_json = "1.0.120"
solana-account-decoder = "1.14.10"
solana-clap-utils = "1.14.10"
solana-cli-config = "1.14.10"
solana-client = "1.14.10"
solana-logger = "1.14.10"
solana-sdk = "1.14.10"
solana-program = "1.14.10"
solend-sdk = { path = "../sdk" }
solana-sdk = "1.14.10"
solend-program = { path = "../program", features = ["no-entrypoint"] }
spl-token = { version = "3.3.0", features = ["no-entrypoint"] }
solend-sdk = { path = "../sdk" }
spl-associated-token-account = "1.0"
solana-account-decoder = "1.14.10"
reqwest = { version = "0.12.2", features = ["blocking", "json"] }
bincode = "1.3.3"
serde_json = "1.0.120"
spl-token = { version = "3.3.0", features = ["no-entrypoint"] }

[[bin]]
name = "solend-cli"
Expand Down
19 changes: 19 additions & 0 deletions token-lending/cli/src/liquidity_mining.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! CLI commands related to liquidity mining.

mod add_pool_reward;
mod close_pool_reward;
mod crank_pool_rewards;
mod edit_pool_reward;
mod find_obligations_to_fund;
mod migrate_all_reserves;
mod view_obligation_rewards;
mod view_reserve_rewards;

pub(crate) use add_pool_reward::command as command_add_pool_reward;
pub(crate) use close_pool_reward::command as command_close_pool_reward;
pub(crate) use crank_pool_rewards::command as command_crank_pool_rewards;
pub(crate) use edit_pool_reward::command as command_edit_pool_reward;
pub(crate) use find_obligations_to_fund::command as command_find_obligations_to_fund_for_liquidity_mining;
pub(crate) use migrate_all_reserves::command as command_migrate_all_reserves_for_liquidity_mining;
pub(crate) use view_obligation_rewards::command as command_view_obligation_rewards;
pub(crate) use view_reserve_rewards::command as command_view_reserve_rewards;
114 changes: 114 additions & 0 deletions token-lending/cli/src/liquidity_mining/add_pool_reward.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//! Adds a pool reward to a reserve.
//!
//! The signer must be the owner of the lending market, and there must be a free slot in the reserve.

use std::{borrow::Borrow, str::FromStr};

use solana_program::program_pack::Pack;
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction};
use solend_sdk::{
instruction::{add_pool_reward, find_reward_vault_authority},
state::{LendingMarket, PoolRewardEntry, PositionKind, Reserve},
};

use crate::{send_transaction, CommandResult, Config};

pub(crate) fn command(
config: &mut Config,
reserve_pubkey: Pubkey,
position_kind: PositionKind,
source_reward_token_account_pubkey: Pubkey,
start_time_secs: u64,
duration_secs: u32,
token_amount: u64,
) -> CommandResult {
let reserve_info = config.rpc_client.get_account(&reserve_pubkey)?;
let reserve = Reserve::unpack_from_slice(reserve_info.data.borrow())?;
let lending_market_info = config.rpc_client.get_account(&reserve.lending_market)?;
let lending_market = LendingMarket::unpack(lending_market_info.data.borrow())?;

if config.fee_payer.pubkey() != lending_market.owner {
return Err(format!(
"The fee payer must be the owner of the lending market '{}'",
reserve.lending_market
)
.into());
}

let has_free_slot = reserve
.pool_reward_manager(position_kind)
.pool_rewards
.iter()
.any(|pr| matches!(pr, PoolRewardEntry::Vacant { .. }));

if !has_free_slot {
return Err(
"There are no vacant slots to add the pool reward. Please crank it first".into(),
);
}

let Some(source_reward_token_account) = config
.rpc_client
.get_token_account(&source_reward_token_account_pubkey)?
else {
return Err(format!(
"Failed to fetch source token account '{}'",
source_reward_token_account_pubkey
)
.into());
};

let reward_mint = Pubkey::from_str(&source_reward_token_account.mint)?;

let reward_vault_keypair = Keypair::new();

let create_account_ix = system_instruction::create_account(
&config.fee_payer.pubkey(),
&reward_vault_keypair.pubkey(),
config
.rpc_client
.get_minimum_balance_for_rent_exemption(spl_token::state::Account::LEN)?,
spl_token::state::Account::LEN as _,
&spl_token::id(),
);

let (reward_vault_authority, reward_authority_bump) = find_reward_vault_authority(
&config.lending_program_id,
&reserve.lending_market,
&reward_vault_keypair.pubkey(),
);

let add_reward_ix = add_pool_reward(
config.lending_program_id,
reward_authority_bump,
position_kind,
start_time_secs,
start_time_secs + duration_secs as u64,
token_amount,
reserve_pubkey,
reward_mint,
source_reward_token_account_pubkey,
reward_vault_authority,
reward_vault_keypair.pubkey(),
reserve.lending_market,
lending_market.owner,
);

let recent_blockhash = config.rpc_client.get_latest_blockhash()?;

let message = solana_sdk::message::Message::new_with_blockhash(
&[create_account_ix, add_reward_ix],
Some(&config.fee_payer.pubkey()),
&recent_blockhash,
);

let transaction = solana_sdk::transaction::Transaction::new(
&vec![config.fee_payer.as_ref()],
message,
recent_blockhash,
);

send_transaction(config, transaction)?;

Ok(())
}
Loading
Loading