Skip to content

Commit

Permalink
Fix: fix for client support token2022 (raydium-io#51)
Browse files Browse the repository at this point in the history
* Fix: fix for client support token2022

* Fix: fix for client support tickarray bitmap extension and update dependencies version

* Fix: fix for overflowing_pow error during build contract

* Fix: fix for remaining accounts sequence over the decrease_liquidity and update client

* Style: update client dependencies
  • Loading branch information
RainRaydium authored Oct 25, 2023
1 parent 21bb307 commit cea4d49
Show file tree
Hide file tree
Showing 18 changed files with 3,428 additions and 2,003 deletions.
34 changes: 19 additions & 15 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ rust-version = "1.56"
edition = "2021"

[dependencies]
anchor-client = "0.26.0"
anchor-lang = "0.26.0"
raydium-amm-v3 = {path = "../programs/amm", features = ["no-entrypoint"]}
solana-sdk = "1.13.5"
solana-client = "1.13.5"
solana-account-decoder = "1.13.5"
spl-token = { version = "3.5.0", features=["no-entrypoint"] }
spl-associated-token-account = "1.0.3"
mpl-token-metadata = { version = "1.2.7", features = ["no-entrypoint"] }
clap = { version = "3.0.0-rc.0", features = ["derive"] }
shellexpand = "2.1.0"
anchor-client = "0.28.0"
anchor-lang = "0.28.0"
raydium-amm-v3 = {path = "../programs/amm", features = ["no-entrypoint", "client"]}
solana-sdk = ">=1.14, <1.17"
solana-client = ">=1.14, <1.17"
solana-account-decoder = ">=1.14, <1.17"
solana-transaction-status = ">=1.14, <1.17"
spl-token = { version = "4.0.0", features=["no-entrypoint"] }
spl-token-client = "0.7.0"
spl-memo = "4.0.0"
spl-associated-token-account = { version = "2.2.0", features = ["no-entrypoint"]}
spl-token-2022 = { version = "0.9.0", features = ["no-entrypoint"]}
mpl-token-metadata = { version = "^1.11.0", features = ["no-entrypoint"] }
clap = { version = "4.1.8", features = ["derive"] }
anyhow = "1.0.32"
rand = "0.7.3"
hex = "0.4.3"
configparser = "3.0.0"
borsh = "0.9.0"
serde_json = { version = "1.0.78" }
serde = { version = "1.0", features = ["derive"] }
arrayref = "0.3.6"
bs58 = { version = "0.4.0"}
bincode = { version = "1.3.3" }
arrayref = "0.3.7"
bs58 = { version = "0.5.0"}
bincode = { version = "1.3.3" }
regex = "1"
colorful = "0.2.2"
124 changes: 103 additions & 21 deletions client/src/instructions/amm_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn create_amm_config_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let (amm_config_key, __bump) = Pubkey::find_program_address(
&[AMM_CONFIG_SEED.as_bytes(), &config_index.to_be_bytes()],
&program.id(),
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn update_amm_config_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let instructions = program
.request()
.accounts(raydium_accounts::UpdateAmmConfig {
Expand All @@ -80,7 +80,7 @@ pub fn create_operation_account_instr(config: &ClientConfig) -> Result<Vec<Instr
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let (operation_account_key, __bump) =
Pubkey::find_program_address(&[OPERATION_SEED.as_bytes()], &program.id());
let instructions = program
Expand All @@ -104,7 +104,7 @@ pub fn update_operation_account_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let (operation_account_key, __bump) =
Pubkey::find_program_address(&[OPERATION_SEED.as_bytes()], &program.id());
let instructions = program
Expand All @@ -125,14 +125,17 @@ pub fn create_pool_instr(
observation_key: Pubkey,
token_mint_0: Pubkey,
token_mint_1: Pubkey,
token_program_0: Pubkey,
token_program_1: Pubkey,
tick_array_bitmap: Pubkey,
sqrt_price_x64: u128,
open_time: u64,
) -> Result<Vec<Instruction>> {
let payer = read_keypair_file(&config.payer_path)?;
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let (pool_account_key, __bump) = Pubkey::find_program_address(
&[
POOL_SEED.as_bytes(),
Expand Down Expand Up @@ -169,7 +172,9 @@ pub fn create_pool_instr(
token_vault_0,
token_vault_1,
observation_state: observation_key,
token_program: spl_token::id(),
tick_array_bitmap,
token_program_0,
token_program_1,
system_program: system_program::id(),
rent: sysvar::rent::id(),
})
Expand All @@ -186,23 +191,27 @@ pub fn open_position_instr(
pool_account_key: Pubkey,
token_vault_0: Pubkey,
token_vault_1: Pubkey,
token_mint_0: Pubkey,
token_mint_1: Pubkey,
nft_mint_key: Pubkey,
nft_to_owner: Pubkey,
user_token_account_0: Pubkey,
user_token_account_1: Pubkey,
remaining_accounts: Vec<AccountMeta>,
liquidity: u128,
amount_0_max: u64,
amount_1_max: u64,
tick_lower_index: i32,
tick_upper_index: i32,
tick_array_lower_start_index: i32,
tick_array_upper_start_index: i32,
with_matedata: bool,
) -> Result<Vec<Instruction>> {
let payer = read_keypair_file(&config.payer_path)?;
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let nft_ata_token_account =
spl_associated_token_account::get_associated_token_address(&program.payer(), &nft_mint_key);
let (metadata_account_key, _bump) = Pubkey::find_program_address(
Expand Down Expand Up @@ -244,7 +253,7 @@ pub fn open_position_instr(
);
let instructions = program
.request()
.accounts(raydium_accounts::OpenPosition {
.accounts(raydium_accounts::OpenPositionV2 {
payer: program.payer(),
position_nft_owner: nft_to_owner,
position_nft_mint: nft_mint_key,
Expand All @@ -264,15 +273,21 @@ pub fn open_position_instr(
token_program: spl_token::id(),
associated_token_program: spl_associated_token_account::id(),
metadata_program: mpl_token_metadata::id(),
token_program_2022: spl_token_2022::id(),
vault_0_mint: token_mint_0,
vault_1_mint: token_mint_1,
})
.args(raydium_instruction::OpenPosition {
.accounts(remaining_accounts)
.args(raydium_instruction::OpenPositionV2 {
liquidity,
amount_0_max,
amount_1_max,
tick_lower_index,
tick_upper_index,
tick_array_lower_start_index,
tick_array_upper_start_index,
with_matedata,
base_flag: None,
})
.instructions()?;
Ok(instructions)
Expand All @@ -283,9 +298,12 @@ pub fn increase_liquidity_instr(
pool_account_key: Pubkey,
token_vault_0: Pubkey,
token_vault_1: Pubkey,
token_mint_0: Pubkey,
token_mint_1: Pubkey,
nft_mint_key: Pubkey,
user_token_account_0: Pubkey,
user_token_account_1: Pubkey,
remaining_accounts: Vec<AccountMeta>,
liquidity: u128,
amount_0_max: u64,
amount_1_max: u64,
Expand All @@ -298,7 +316,7 @@ pub fn increase_liquidity_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let nft_ata_token_account =
spl_associated_token_account::get_associated_token_address(&program.payer(), &nft_mint_key);
let (tick_array_lower, __bump) = Pubkey::find_program_address(
Expand Down Expand Up @@ -333,7 +351,7 @@ pub fn increase_liquidity_instr(

let instructions = program
.request()
.accounts(raydium_accounts::IncreaseLiquidity {
.accounts(raydium_accounts::IncreaseLiquidityV2 {
nft_owner: program.payer(),
nft_account: nft_ata_token_account,
pool_state: pool_account_key,
Expand All @@ -346,11 +364,16 @@ pub fn increase_liquidity_instr(
token_vault_0,
token_vault_1,
token_program: spl_token::id(),
token_program_2022: spl_token_2022::id(),
vault_0_mint: token_mint_0,
vault_1_mint: token_mint_1,
})
.args(raydium_instruction::IncreaseLiquidity {
.accounts(remaining_accounts)
.args(raydium_instruction::IncreaseLiquidityV2 {
liquidity,
amount_0_max,
amount_1_max,
base_flag: None,
})
.instructions()?;
Ok(instructions)
Expand All @@ -361,6 +384,8 @@ pub fn decrease_liquidity_instr(
pool_account_key: Pubkey,
token_vault_0: Pubkey,
token_vault_1: Pubkey,
token_mint_0: Pubkey,
token_mint_1: Pubkey,
nft_mint_key: Pubkey,
user_token_account_0: Pubkey,
user_token_account_1: Pubkey,
Expand All @@ -377,7 +402,7 @@ pub fn decrease_liquidity_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let nft_ata_token_account =
spl_associated_token_account::get_associated_token_address(&program.payer(), &nft_mint_key);
let (personal_position_key, __bump) = Pubkey::find_program_address(
Expand Down Expand Up @@ -411,7 +436,7 @@ pub fn decrease_liquidity_instr(
);
let instructions = program
.request()
.accounts(raydium_accounts::DecreaseLiquidity {
.accounts(raydium_accounts::DecreaseLiquidityV2 {
nft_owner: program.payer(),
nft_account: nft_ata_token_account,
personal_position: personal_position_key,
Expand All @@ -424,9 +449,13 @@ pub fn decrease_liquidity_instr(
recipient_token_account_0: user_token_account_0,
recipient_token_account_1: user_token_account_1,
token_program: spl_token::id(),
token_program_2022: spl_token_2022::id(),
memo_program: spl_memo::id(),
vault_0_mint: token_mint_0,
vault_1_mint: token_mint_1,
})
.accounts(remaining_accounts)
.args(raydium_instruction::DecreaseLiquidity {
.args(raydium_instruction::DecreaseLiquidityV2 {
liquidity,
amount_0_min,
amount_1_min,
Expand All @@ -443,7 +472,7 @@ pub fn close_personal_position_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let nft_ata_token_account =
spl_associated_token_account::get_associated_token_address(&program.payer(), &nft_mint_key);
let (personal_position_key, __bump) = Pubkey::find_program_address(
Expand Down Expand Up @@ -485,7 +514,7 @@ pub fn swap_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;
let instructions = program
.request()
.accounts(raydium_accounts::SwapSingle {
Expand All @@ -511,6 +540,56 @@ pub fn swap_instr(
Ok(instructions)
}

pub fn swap_v2_instr(
config: &ClientConfig,
amm_config: Pubkey,
pool_account_key: Pubkey,
input_vault: Pubkey,
output_vault: Pubkey,
observation_state: Pubkey,
user_input_token: Pubkey,
user_out_put_token: Pubkey,
input_vault_mint: Pubkey,
output_vault_mint: Pubkey,
remaining_accounts: Vec<AccountMeta>,
amount: u64,
other_amount_threshold: u64,
sqrt_price_limit_x64: Option<u128>,
is_base_input: bool,
) -> Result<Vec<Instruction>> {
let payer = read_keypair_file(&config.payer_path)?;
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(payer));
let program = client.program(config.raydium_v3_program)?;
let instructions = program
.request()
.accounts(raydium_accounts::SwapSingleV2 {
payer: program.payer(),
amm_config,
pool_state: pool_account_key,
input_token_account: user_input_token,
output_token_account: user_out_put_token,
input_vault,
output_vault,
observation_state,
token_program: spl_token::id(),
token_program_2022: spl_token_2022::id(),
memo_program: spl_memo::id(),
input_vault_mint,
output_vault_mint,
})
.accounts(remaining_accounts)
.args(raydium_instruction::Swap {
amount,
other_amount_threshold,
sqrt_price_limit_x64: sqrt_price_limit_x64.unwrap_or(0u128),
is_base_input,
})
.instructions()?;
Ok(instructions)
}

pub fn initialize_reward_instr(
config: &ClientConfig,
pool_account_key: Pubkey,
Expand All @@ -519,6 +598,7 @@ pub fn initialize_reward_instr(
reward_token_mint: Pubkey,
reward_token_vault: Pubkey,
user_reward_token: Pubkey,
reward_token_program: Pubkey,
open_time: u64,
end_time: u64,
emissions_per_second_x64: u128,
Expand All @@ -527,7 +607,7 @@ pub fn initialize_reward_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(admin));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;

let instructions = program
.request()
Expand All @@ -539,7 +619,7 @@ pub fn initialize_reward_instr(
operation_state: operation_account_key,
reward_token_mint,
reward_token_vault,
token_program: spl_token::id(),
reward_token_program,
system_program: system_program::id(),
rent: sysvar::rent::id(),
})
Expand Down Expand Up @@ -570,7 +650,7 @@ pub fn set_reward_params_instr(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(admin));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;

let remaining_accounts = vec![
AccountMeta::new(reward_token_vault, false),
Expand All @@ -585,6 +665,8 @@ pub fn set_reward_params_instr(
amm_config,
pool_state: pool_account_key,
operation_state: operation_account_key,
token_program: spl_token::id(),
token_program_2022: spl_token_2022::id(),
})
.accounts(remaining_accounts)
.args(raydium_instruction::SetRewardParams {
Expand All @@ -606,7 +688,7 @@ pub fn transfer_reward_owner(
let url = Cluster::Custom(config.http_url.clone(), config.ws_url.clone());
// Client.
let client = Client::new(url, Rc::new(admin));
let program = client.program(config.raydium_v3_program);
let program = client.program(config.raydium_v3_program)?;

let instructions = program
.request()
Expand Down
Loading

0 comments on commit cea4d49

Please sign in to comment.