Expand description
§Orca Whirlpools Client SDK
§Overview
This package provides developers with low-level functionalities for interacting with the Whirlpool Program on Solana. It serves as a foundational tool that allows developers to manage and integrate detailed operations into their Rust projects, particularly those related to Orca’s Whirlpool Program. This package offers granular control for advanced use cases.
NOTE: To ensure compatibility, use version 1.18 of the
solana-sdk
crate, which matches the version used to build the Whirlpool program.
§Key Features
- Codama Client: The package includes a set of generated client code based on the Whirlpool Program IDL. This ensures all the necessary program information is easily accessible in a structured format. It handles all decoding and encoding of instructions and account data, making it much easier to interact with the program.
- PDA (Program Derived Addresses) Utilities: This feature contains utility functions that help derive Program Derived Addresses (PDAs) for accounts within the Whirlpool Program, simplifying address derivation for developers.
§Installation
cargo add orca_whirlpools_client
§Usage
Here are some basic examples of how to use the package:
§Deriving a PDA
To derive a PDA for a Whirlpool account, you can use the get_whirlpool_address
PDA utility.
use orca_whirlpools_client::get_whirlpool_address;
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;
fn main() {
let whirlpool_config_address = Pubkey::from_str("FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR").unwrap();
let token_mint_a = Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap(); // wSOL
let token_mint_b = Pubkey::from_str("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k").unwrap(); // DevUSDC
let tick_spacing = 64;
let (whirlpool_pda, _bump) = get_whirlpool_address(&whirlpool_config_address, &token_mint_a, &token_mint_b, tick_spacing).unwrap();
println!("{:?}", whirlpool_pda);
}
§Example: Initialize Pool Instruction
The following example demonstrates how to create an InitializePool
instruction:
use orca_whirlpools_client::{
instructions::InitializePoolV2Builder,
get_fee_tier_address,
get_token_badge_address,
get_whirlpool_address,
};
use solana_sdk::{
pubkey::Pubkey,
signer::{keypair::Keypair, Signer},
};
use std::str::FromStr;
fn main() {
let whirlpool_config_address = Pubkey::from_str("FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR").unwrap();
let token_mint_a = Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap(); // wSOL
let token_mint_b = Pubkey::from_str("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k").unwrap(); // DevUSDC
let (token_badge_a, _bump) = get_token_badge_address(&whirlpool_config_address, &token_mint_a).unwrap();
let (token_badge_b, _bump) = get_token_badge_address(&whirlpool_config_address, &token_mint_b).unwrap();
let wallet = Keypair::new(); // CAUTION: this wallet is not persistent
let tick_spacing = 8;
let (whirlpool_pda, _bump) = get_whirlpool_address(&whirlpool_config_address, &token_mint_a, &token_mint_b, tick_spacing).unwrap();
let token_vault_a = Keypair::new();
let token_vault_b = Keypair::new();
let (fee_tier, _bump) = get_fee_tier_address(&whirlpool_config_address, tick_spacing).unwrap();
let token_program_a = Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap();
let token_program_b = Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap();
let initial_sqrt_price = 7459106261056563200u128;
let initialize_pool_v2_instruction = InitializePoolV2Builder::new()
.whirlpools_config(whirlpool_config_address)
.token_mint_a(token_mint_a)
.token_mint_b(token_mint_b)
.token_badge_a(token_badge_a)
.token_badge_b(token_badge_b)
.funder(wallet.pubkey())
.whirlpool(whirlpool_pda)
.token_vault_a(token_vault_a.pubkey())
.token_vault_b(token_vault_b.pubkey())
.fee_tier(fee_tier)
.token_program_a(token_program_a)
.token_program_b(token_program_b)
.tick_spacing(tick_spacing)
.initial_sqrt_price(initial_sqrt_price)
.instruction();
println!("{:?}", initialize_pool_v2_instruction);
}
Structs§
- Accounts.
- Instruction builder for
CloseBundledPosition
. close_bundled_position
CPI instruction.close_bundled_position
CPI accounts.- Instruction builder for
CloseBundledPosition
via CPI. - Accounts.
- Instruction builder for
ClosePosition
. close_position
CPI instruction.close_position
CPI accounts.- Instruction builder for
ClosePosition
via CPI. - Accounts.
- Instruction builder for
ClosePositionWithTokenExtensions
. close_position_with_token_extensions
CPI instruction.close_position_with_token_extensions
CPI accounts.- Instruction builder for
ClosePositionWithTokenExtensions
via CPI. - Accounts.
- Instruction builder for
CollectFees
. collect_fees
CPI instruction.collect_fees
CPI accounts.- Instruction builder for
CollectFees
via CPI. - Accounts.
- Instruction builder for
CollectFeesV2
. collect_fees_v2
CPI instruction.collect_fees_v2
CPI accounts.- Instruction builder for
CollectFeesV2
via CPI. - Accounts.
- Instruction builder for
CollectProtocolFees
. collect_protocol_fees
CPI instruction.collect_protocol_fees
CPI accounts.- Instruction builder for
CollectProtocolFees
via CPI. - Accounts.
- Instruction builder for
CollectProtocolFeesV2
. collect_protocol_fees_v2
CPI instruction.collect_protocol_fees_v2
CPI accounts.- Instruction builder for
CollectProtocolFeesV2
via CPI. - Accounts.
- Instruction builder for
CollectReward
. collect_reward
CPI instruction.collect_reward
CPI accounts.- Instruction builder for
CollectReward
via CPI. - Accounts.
- Instruction builder for
CollectRewardV2
. collect_reward_v2
CPI instruction.collect_reward_v2
CPI accounts.- Instruction builder for
CollectRewardV2
via CPI. - Accounts.
- Instruction builder for
DecreaseLiquidity
. decrease_liquidity
CPI instruction.decrease_liquidity
CPI accounts.- Instruction builder for
DecreaseLiquidity
via CPI. - Accounts.
- Instruction builder for
DecreaseLiquidityV2
. decrease_liquidity_v2
CPI instruction.decrease_liquidity_v2
CPI accounts.- Instruction builder for
DecreaseLiquidityV2
via CPI. - Accounts.
- Instruction builder for
DeletePositionBundle
. delete_position_bundle
CPI instruction.delete_position_bundle
CPI accounts.- Instruction builder for
DeletePositionBundle
via CPI. - Accounts.
- Instruction builder for
DeleteTokenBadge
. delete_token_badge
CPI instruction.delete_token_badge
CPI accounts.- Instruction builder for
DeleteTokenBadge
via CPI. - Accounts.
- Instruction builder for
IncreaseLiquidity
. increase_liquidity
CPI instruction.increase_liquidity
CPI accounts.- Instruction builder for
IncreaseLiquidity
via CPI. - Accounts.
- Instruction builder for
IncreaseLiquidityV2
. increase_liquidity_v2
CPI instruction.increase_liquidity_v2
CPI accounts.- Instruction builder for
IncreaseLiquidityV2
via CPI. - Accounts.
- Instruction builder for
InitializeConfig
. initialize_config
CPI instruction.initialize_config
CPI accounts.- Instruction builder for
InitializeConfig
via CPI. - Accounts.
- Instruction builder for
InitializeConfigExtension
. initialize_config_extension
CPI instruction.initialize_config_extension
CPI accounts.- Instruction builder for
InitializeConfigExtension
via CPI. - Accounts.
- Instruction builder for
InitializeFeeTier
. initialize_fee_tier
CPI instruction.initialize_fee_tier
CPI accounts.- Instruction builder for
InitializeFeeTier
via CPI. - Accounts.
- Instruction builder for
InitializePool
. initialize_pool
CPI instruction.initialize_pool
CPI accounts.- Instruction builder for
InitializePool
via CPI. - Accounts.
- Instruction builder for
InitializePoolV2
. initialize_pool_v2
CPI instruction.initialize_pool_v2
CPI accounts.- Instruction builder for
InitializePoolV2
via CPI. - Accounts.
- Instruction builder for
InitializePositionBundle
. initialize_position_bundle
CPI instruction.initialize_position_bundle
CPI accounts.- Instruction builder for
InitializePositionBundle
via CPI. - Accounts.
- Instruction builder for
InitializePositionBundleWithMetadata
. initialize_position_bundle_with_metadata
CPI instruction.initialize_position_bundle_with_metadata
CPI accounts.- Instruction builder for
InitializePositionBundleWithMetadata
via CPI. - Accounts.
- Instruction builder for
InitializeReward
. initialize_reward
CPI instruction.initialize_reward
CPI accounts.- Instruction builder for
InitializeReward
via CPI. - Accounts.
- Instruction builder for
InitializeRewardV2
. initialize_reward_v2
CPI instruction.initialize_reward_v2
CPI accounts.- Instruction builder for
InitializeRewardV2
via CPI. - Accounts.
- Instruction builder for
InitializeTickArray
. initialize_tick_array
CPI instruction.initialize_tick_array
CPI accounts.- Instruction builder for
InitializeTickArray
via CPI. - Accounts.
- Instruction builder for
InitializeTokenBadge
. initialize_token_badge
CPI instruction.initialize_token_badge
CPI accounts.- Instruction builder for
InitializeTokenBadge
via CPI. - Accounts.
- Instruction builder for
OpenBundledPosition
. open_bundled_position
CPI instruction.open_bundled_position
CPI accounts.- Instruction builder for
OpenBundledPosition
via CPI. - Accounts.
- Instruction builder for
OpenPosition
. open_position
CPI instruction.open_position
CPI accounts.- Instruction builder for
OpenPosition
via CPI. - Accounts.
- Instruction builder for
OpenPositionWithMetadata
. open_position_with_metadata
CPI instruction.open_position_with_metadata
CPI accounts.- Instruction builder for
OpenPositionWithMetadata
via CPI. - Accounts.
- Instruction builder for
OpenPositionWithTokenExtensions
. open_position_with_token_extensions
CPI instruction.open_position_with_token_extensions
CPI accounts.- Instruction builder for
OpenPositionWithTokenExtensions
via CPI. - Accounts.
- Instruction builder for
SetCollectProtocolFeesAuthority
. set_collect_protocol_fees_authority
CPI instruction.set_collect_protocol_fees_authority
CPI accounts.- Instruction builder for
SetCollectProtocolFeesAuthority
via CPI. - Accounts.
- Instruction builder for
SetConfigExtensionAuthority
. set_config_extension_authority
CPI instruction.set_config_extension_authority
CPI accounts.- Instruction builder for
SetConfigExtensionAuthority
via CPI. - Accounts.
- Instruction builder for
SetDefaultFeeRate
. set_default_fee_rate
CPI instruction.set_default_fee_rate
CPI accounts.- Instruction builder for
SetDefaultFeeRate
via CPI. - Accounts.
- Instruction builder for
SetDefaultProtocolFeeRate
. set_default_protocol_fee_rate
CPI instruction.set_default_protocol_fee_rate
CPI accounts.- Instruction builder for
SetDefaultProtocolFeeRate
via CPI. - Accounts.
- Instruction builder for
SetFeeAuthority
. set_fee_authority
CPI instruction.set_fee_authority
CPI accounts.- Instruction builder for
SetFeeAuthority
via CPI. - Accounts.
- Instruction builder for
SetFeeRate
. set_fee_rate
CPI instruction.set_fee_rate
CPI accounts.- Instruction builder for
SetFeeRate
via CPI. - Accounts.
- Instruction builder for
SetProtocolFeeRate
. set_protocol_fee_rate
CPI instruction.set_protocol_fee_rate
CPI accounts.- Instruction builder for
SetProtocolFeeRate
via CPI. - Accounts.
- Instruction builder for
SetRewardAuthority
. - Accounts.
- Instruction builder for
SetRewardAuthorityBySuperAuthority
. set_reward_authority_by_super_authority
CPI instruction.set_reward_authority_by_super_authority
CPI accounts.- Instruction builder for
SetRewardAuthorityBySuperAuthority
via CPI. set_reward_authority
CPI instruction.set_reward_authority
CPI accounts.- Instruction builder for
SetRewardAuthority
via CPI. - Accounts.
- Instruction builder for
SetRewardEmissions
. set_reward_emissions
CPI instruction.set_reward_emissions
CPI accounts.- Instruction builder for
SetRewardEmissions
via CPI. - Accounts.
- Instruction builder for
SetRewardEmissionsSuperAuthority
. set_reward_emissions_super_authority
CPI instruction.set_reward_emissions_super_authority
CPI accounts.- Instruction builder for
SetRewardEmissionsSuperAuthority
via CPI. - Accounts.
- Instruction builder for
SetRewardEmissionsV2
. set_reward_emissions_v2
CPI instruction.set_reward_emissions_v2
CPI accounts.- Instruction builder for
SetRewardEmissionsV2
via CPI. - Accounts.
- Instruction builder for
SetTokenBadgeAuthority
. set_token_badge_authority
CPI instruction.set_token_badge_authority
CPI accounts.- Instruction builder for
SetTokenBadgeAuthority
via CPI. - Accounts.
- Instruction builder for
Swap
. swap
CPI instruction.swap
CPI accounts.- Instruction builder for
Swap
via CPI. - Accounts.
- Instruction builder for
SwapV2
. swap_v2
CPI instruction.swap_v2
CPI accounts.- Instruction builder for
SwapV2
via CPI. - Accounts.
- Instruction builder for
TwoHopSwap
. two_hop_swap
CPI instruction.two_hop_swap
CPI accounts.- Instruction builder for
TwoHopSwap
via CPI. - Accounts.
- Instruction builder for
TwoHopSwapV2
. two_hop_swap_v2
CPI instruction.two_hop_swap_v2
CPI accounts.- Instruction builder for
TwoHopSwapV2
via CPI. - Accounts.
- Instruction builder for
UpdateFeesAndRewards
. update_fees_and_rewards
CPI instruction.update_fees_and_rewards
CPI accounts.- Instruction builder for
UpdateFeesAndRewards
via CPI. - Stores the state relevant for tracking liquidity mining rewards at the
Whirlpool
level. These values are used in conjunction withPositionRewardInfo
,Tick.reward_growths_outside
, andWhirlpool.reward_last_updated_timestamp
to determine how many rewards are earned by open positions.
Enums§
Constants§
whirlpool
program ID.whirlpool
program ID.