Skip to main content

tensor_eigen/commands/pool/
edit.rs

1use super::*;
2
3use borsh::BorshDeserialize;
4use serde::{Deserialize, Serialize};
5use tensor_amm::{
6    instructions::{EditPool, EditPoolInstructionArgs},
7    types::{CurveType, PoolConfig, PoolType},
8    NullableU16,
9};
10
11pub struct EditPoolParams {
12    pub keypair_path: Option<PathBuf>,
13    pub rpc_url: Option<String>,
14    pub pool: Pubkey,
15    pub edit_pool_config_path: PathBuf,
16}
17
18#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
19struct EditPoolArgs {
20    pub new_config: Option<EditPoolConfig>,
21    pub cosigner: Option<Pubkey>,
22    pub expire_in_sec: Option<u64>,
23    pub max_taker_sell_count: Option<u32>,
24    pub reset_price_offset: bool,
25}
26
27#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
28pub struct EditPoolConfig {
29    pub curve_type: CurveType,
30    pub starting_price: u64,
31    pub delta: u64,
32    pub mm_compound_fees: bool,
33    pub mm_fee_bps: NullableU16,
34}
35
36impl EditPoolConfig {
37    fn convert(&self, pool_type: PoolType) -> PoolConfig {
38        PoolConfig {
39            pool_type,
40            curve_type: self.curve_type,
41            starting_price: self.starting_price,
42            delta: self.delta,
43            mm_compound_fees: self.mm_compound_fees,
44            mm_fee_bps: self.mm_fee_bps.clone(),
45        }
46    }
47}
48
49impl EditPoolArgs {
50    fn convert(&self, pool_type: PoolType) -> EditPoolInstructionArgs {
51        EditPoolInstructionArgs {
52            new_config: self.new_config.as_ref().map(|c| c.convert(pool_type)),
53            cosigner: self.cosigner,
54            expire_in_sec: self.expire_in_sec,
55            max_taker_sell_count: self.max_taker_sell_count,
56            reset_price_offset: self.reset_price_offset,
57        }
58    }
59}
60
61pub fn edit_pool(args: EditPoolParams) -> Result<()> {
62    let config = CliConfig::new(args.keypair_path, args.rpc_url)?;
63
64    let owner = config.keypair.pubkey();
65
66    // Fetch and decode pool account.
67    let pool_data = config.client.get_account_data(&args.pool)?;
68    let pool_type = Pool::try_from_slice(&pool_data)?.config.pool_type;
69
70    let edit_pool_args: EditPoolArgs =
71        serde_json::from_reader(std::fs::File::open(args.edit_pool_config_path)?)?;
72
73    println!("{:?}", edit_pool_args);
74
75    let ix = EditPool {
76        owner,
77        pool: args.pool,
78        system_program: solana_sdk::system_program::id(),
79    }
80    .instruction(edit_pool_args.convert(pool_type));
81
82    let tx = transaction!(&[&config.keypair], &[ix], &config.client);
83
84    config.client.send_and_confirm_transaction(&tx)?;
85
86    println!("Pool updated: {}", args.pool);
87
88    Ok(())
89}