use borsh::{BorshDeserialize, BorshSerialize};
use solana_sdk::{instruction::{AccountMeta, Instruction}, pubkey::Pubkey};
pub const PROGRAM_ID: Pubkey = solana_sdk::pubkey!("HaWDr94LKJQT2fXuHJGsSGeQf6M7S68FXpEQLcE5RYs6");
pub const IDL: &str = include_str!("../../idl/swap.json");
pub const GLOBAL_CONFIG_PREFIX: &[u8] = &[103, 108, 111, 98, 97, 108, 95, 99, 111, 110, 102, 105, 103];
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AdminChanged {
pub old_admin: Pubkey,
pub new_admin: Pubkey,
}
impl AdminChanged {
pub const DISCRIMINATOR: [u8; 8] = [232, 34, 31, 226, 62, 18, 19, 114];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AssetConfig {
pub mint_address: Pubkey,
pub nav_data: Vec<NavData>,
pub price_difference_bps: u16,
pub paused: bool,
pub version: u8,
pub asset_type: AssetType,
pub used_in_pairs_count: u16,
pub bump: u8,
pub padding: Vec<[u8; 128]>,
}
impl AssetConfig {
pub const DISCRIMINATOR: [u8; 8] = [57, 112, 247, 166, 247, 64, 140, 23];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl AssetConfig {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AssetConfigInitialized {
pub asset_config: Pubkey,
pub mint: Pubkey,
pub asset_type: AssetType,
pub price_difference_bps: u16,
pub nav_data: Vec<NavData>,
}
impl AssetConfigInitialized {
pub const DISCRIMINATOR: [u8; 8] = [155, 228, 155, 62, 174, 164, 61, 147];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AssetConfigUpdated {
pub asset_config: Pubkey,
pub mint: Pubkey,
pub asset_type: AssetType,
pub price_difference_bps: u16,
pub nav_data: Vec<NavData>,
}
impl AssetConfigUpdated {
pub const DISCRIMINATOR: [u8; 8] = [12, 97, 64, 94, 123, 177, 111, 10];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AssetPauseChanged {
pub mint: Pubkey,
pub paused: bool,
}
impl AssetPauseChanged {
pub const DISCRIMINATOR: [u8; 8] = [30, 56, 152, 180, 133, 188, 179, 249];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Copy)]
pub enum AssetType {
Rwa,
Stable,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Copy)]
pub enum ExactMode {
ExactIn,
ExactOut,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct FeesClaimed {
pub fee_wallet: Pubkey,
pub fee_mint: Pubkey,
pub amount: u64,
}
impl FeesClaimed {
pub const DISCRIMINATOR: [u8; 8] = [22, 104, 110, 222, 38, 157, 14, 62];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct GlobalConfig {
pub admin: Pubkey,
pub fee_wallet: Pubkey,
pub protocol_fees_bps: u16,
pub paused: bool,
pub pending_new_admin: Option<Pubkey>,
pub bump: u8,
pub fee_token_mint: Pubkey,
pub spread_protocol_fees_bps: u16,
pub padding: [u8; 94],
}
impl GlobalConfig {
pub const DISCRIMINATOR: [u8; 8] = [149, 8, 156, 202, 160, 252, 176, 217];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl GlobalConfig {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct GlobalConfigInitialized {
pub admin: Pubkey,
pub fee_wallet: Pubkey,
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
pub fee_token_mint: Pubkey,
pub paused: bool,
}
impl GlobalConfigInitialized {
pub const DISCRIMINATOR: [u8; 8] = [5, 221, 172, 158, 77, 87, 157, 113];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct GlobalConfigUpdated {
pub fee_wallet: Pubkey,
pub paused: bool,
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
pub fee_token_mint: Pubkey,
}
impl GlobalConfigUpdated {
pub const DISCRIMINATOR: [u8; 8] = [232, 238, 158, 123, 210, 172, 159, 46];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LiquidityAdded {
pub liquidity_provider: Pubkey,
pub mint_address: Pubkey,
pub amount: u64,
pub treasury_deposit_amount: u64,
}
impl LiquidityAdded {
pub const DISCRIMINATOR: [u8; 8] = [154, 26, 221, 108, 238, 64, 217, 161];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LiquidityRemoved {
pub liquidity_provider: Pubkey,
pub mint_address: Pubkey,
pub amount: u64,
pub amount_transferred: u64,
pub treasury_backed: bool,
}
impl LiquidityRemoved {
pub const DISCRIMINATOR: [u8; 8] = [225, 105, 216, 39, 124, 116, 169, 189];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpFeeAccountClosed {
pub liquidity_provider: Pubkey,
pub fee_token_mint: Pubkey,
pub amount_returned: u64,
}
impl LpFeeAccountClosed {
pub const DISCRIMINATOR: [u8; 8] = [103, 159, 170, 253, 58, 140, 131, 138];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpProtocolFeeConfig {
pub liquidity_provider: Pubkey,
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
pub bump: u8,
pub treasury_enabled: bool,
pub padding: [u8; 128],
}
impl LpProtocolFeeConfig {
pub const DISCRIMINATOR: [u8; 8] = [135, 75, 123, 10, 42, 109, 206, 172];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl LpProtocolFeeConfig {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpProtocolFeeConfigUpdated {
pub liquidity_provider: Pubkey,
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
}
impl LpProtocolFeeConfigUpdated {
pub const DISCRIMINATOR: [u8; 8] = [58, 157, 1, 126, 238, 158, 141, 180];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpStableConfig {
pub quote_token_mint_address: Pubkey,
pub paused: bool,
pub liquidity_provider: Pubkey,
pub bump: u8,
pub padding: [u8; 128],
}
impl LpStableConfig {
pub const DISCRIMINATOR: [u8; 8] = [178, 48, 23, 140, 152, 86, 22, 226];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl LpStableConfig {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpStableConfigPauseChanged {
pub liquidity_provider: Pubkey,
pub mint: Pubkey,
pub paused: bool,
}
impl LpStableConfigPauseChanged {
pub const DISCRIMINATOR: [u8; 8] = [127, 23, 108, 124, 24, 91, 232, 50];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct LpTreasuryEnabledChanged {
pub liquidity_provider: Pubkey,
pub enabled: bool,
}
impl LpTreasuryEnabledChanged {
pub const DISCRIMINATOR: [u8; 8] = [105, 98, 154, 187, 217, 205, 205, 126];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub enum NavData {
U64FixedAddress {
nav_account_address: Pubkey,
nav_price_offset: u16,
price_decimals: u8,
},
Hardcoded {
hardcoded_price: u64,
price_decimals: u8,
},
PythPush {
pyth_push_account_address: Pubkey,
feed_id: [u8; 32],
max_age_secs: u64,
max_conf_bps: u16,
},
RedstonePush {
price_feed_account: Pubkey,
feed_id: [u8; 32],
max_age_secs: u64,
},
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct NewAdminProposed {
pub current_admin: Pubkey,
pub pending_admin: Pubkey,
}
impl NewAdminProposed {
pub const DISCRIMINATOR: [u8; 8] = [28, 150, 26, 229, 207, 97, 30, 242];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct Pair {
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub liquidity_provider: Pubkey,
pub paused: bool,
pub bump: u8,
pub padding: [u8; 128],
}
impl Pair {
pub const DISCRIMINATOR: [u8; 8] = [85, 72, 49, 176, 182, 228, 141, 82];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl Pair {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct PairClosed {
pub pair: Pubkey,
pub liquidity_provider: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub quote_amount_returned: u64,
pub base_amount_returned: u64,
}
impl PairClosed {
pub const DISCRIMINATOR: [u8; 8] = [44, 133, 115, 118, 95, 41, 87, 136];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct PairInitialized {
pub pair: Pubkey,
pub liquidity_provider: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
}
impl PairInitialized {
pub const DISCRIMINATOR: [u8; 8] = [32, 143, 168, 185, 98, 225, 71, 148];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct PairUpdated {
pub pair: Pubkey,
pub liquidity_provider: Pubkey,
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
pub paused: bool,
}
impl PairUpdated {
pub const DISCRIMINATOR: [u8; 8] = [208, 67, 143, 117, 86, 212, 167, 194];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Copy)]
pub enum SwapDirection {
QuoteToBase,
BaseToQuote,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SwapExecuted {
pub requestor: Pubkey,
pub amount_in: u64,
pub protocol_fee_amount: u64,
pub discount_bps: u16,
pub amount_out: u64,
pub pair: Pubkey,
pub swap_direction: SwapDirection,
pub swap_type: SwapType,
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
}
impl SwapExecuted {
pub const DISCRIMINATOR: [u8; 8] = [150, 166, 26, 225, 28, 89, 38, 79];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Copy)]
pub enum SwapType {
ExactIn,
ExactOut,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct TreasuryPositionClosed {
pub liquidity_provider: Pubkey,
pub lp_vault_authority: Pubkey,
pub treasury_user_position: Pubkey,
pub lamports_returned: u64,
}
impl TreasuryPositionClosed {
pub const DISCRIMINATOR: [u8; 8] = [180, 80, 87, 94, 238, 17, 237, 43];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct UserVaultInfo {
pub user: Pubkey,
pub mint_address: Pubkey,
pub used: u16,
pub bump: u8,
pub padding: [u8; 128],
}
impl UserVaultInfo {
pub const DISCRIMINATOR: [u8; 8] = [100, 30, 4, 32, 178, 226, 105, 0];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
impl UserVaultInfo {
pub async fn fetch_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Option<Self>> {
rpc.get_account(address).await?
.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from))
.transpose()
}
pub async fn fetch<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
address: &Pubkey,
) -> crate::error::Result<Self> {
Self::fetch_maybe(rpc, address).await?
.ok_or(crate::error::SdkError::AccountNotFound(*address))
}
pub async fn fetch_all_maybe<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Option<Self>>> {
let accounts = rpc.get_multiple_accounts(addresses).await?;
if accounts.len() != addresses.len() {
return Err(crate::error::SdkError::Rpc("get_multiple_accounts returned an unexpected account count".into()));
}
accounts.into_iter().map(|account| {
account.map(|account| Self::decode(&account.data).map_err(crate::error::SdkError::from)).transpose()
}).collect()
}
pub async fn fetch_all<R: crate::rpc::Rpc + ?Sized>(
rpc: &R,
addresses: &[Pubkey],
) -> crate::error::Result<Vec<Self>> {
Self::fetch_all_maybe(rpc, addresses).await?.into_iter().zip(addresses)
.map(|(account, address)| account.ok_or(crate::error::SdkError::AccountNotFound(*address)))
.collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct AddLiquidityArgs {
pub amount: u64,
pub treasury_nav_account_count: u8,
pub treasury_apy_account_count: u8,
pub amount_threshold: Option<u64>,
}
impl AddLiquidityArgs {
pub const DISCRIMINATOR: [u8; 8] = [181, 157, 89, 67, 143, 182, 52, 72];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AddLiquidityAccounts {
pub liquidity_provider: Pubkey,
pub mint_address: Pubkey,
pub lp_token_account: Pubkey,
pub vault_token_account: Pubkey,
pub lp_vault_authority: Pubkey,
pub global_config: Pubkey,
pub lp_protocol_fee_config: Pubkey,
pub asset_config: Pubkey,
pub lp_stable_config: Option<Pubkey>,
pub treasury_program: Option<Pubkey>,
pub treasury_global_config: Option<Pubkey>,
pub treasury_asset_config: Option<Pubkey>,
pub treasury_user_position: Option<Pubkey>,
pub treasury_vault_authority: Option<Pubkey>,
pub treasury_mint: Option<Pubkey>,
pub treasury_asset_vault: Option<Pubkey>,
pub treasury_user_treasury_token_account: Option<Pubkey>,
pub treasury_token_program: Option<Pubkey>,
pub treasury_associated_token_program: Option<Pubkey>,
pub treasury_system_program: Option<Pubkey>,
pub token_program: Pubkey,
}
impl AddLiquidityAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &AddLiquidityArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(21 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new(self.lp_token_account, false));
accounts.push(AccountMeta::new(self.vault_token_account, false));
accounts.push(AccountMeta::new(self.lp_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.lp_protocol_fee_config, false));
accounts.push(AccountMeta::new_readonly(self.asset_config, false));
accounts.push(match self.lp_stable_config {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_global_config {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_asset_config {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_user_position {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_vault_authority {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_mint {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_asset_vault {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_user_treasury_token_account {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_token_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_associated_token_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_system_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(AccountMeta::new_readonly(self.token_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedAddLiquidityInstruction {
pub program_id: Pubkey,
pub accounts: AddLiquidityAccounts,
pub args: AddLiquidityArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_add_liquidity_instruction(instruction: &Instruction) -> std::io::Result<ParsedAddLiquidityInstruction> {
let args = AddLiquidityArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 21 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "add_liquidity requires 21 accounts"));
}
Ok(ParsedAddLiquidityInstruction {
program_id: instruction.program_id,
accounts: AddLiquidityAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
mint_address: instruction.accounts[1].pubkey,
lp_token_account: instruction.accounts[2].pubkey,
vault_token_account: instruction.accounts[3].pubkey,
lp_vault_authority: instruction.accounts[4].pubkey,
global_config: instruction.accounts[5].pubkey,
lp_protocol_fee_config: instruction.accounts[6].pubkey,
asset_config: instruction.accounts[7].pubkey,
lp_stable_config: (instruction.accounts[8].pubkey != instruction.program_id).then_some(instruction.accounts[8].pubkey),
treasury_program: (instruction.accounts[9].pubkey != instruction.program_id).then_some(instruction.accounts[9].pubkey),
treasury_global_config: (instruction.accounts[10].pubkey != instruction.program_id).then_some(instruction.accounts[10].pubkey),
treasury_asset_config: (instruction.accounts[11].pubkey != instruction.program_id).then_some(instruction.accounts[11].pubkey),
treasury_user_position: (instruction.accounts[12].pubkey != instruction.program_id).then_some(instruction.accounts[12].pubkey),
treasury_vault_authority: (instruction.accounts[13].pubkey != instruction.program_id).then_some(instruction.accounts[13].pubkey),
treasury_mint: (instruction.accounts[14].pubkey != instruction.program_id).then_some(instruction.accounts[14].pubkey),
treasury_asset_vault: (instruction.accounts[15].pubkey != instruction.program_id).then_some(instruction.accounts[15].pubkey),
treasury_user_treasury_token_account: (instruction.accounts[16].pubkey != instruction.program_id).then_some(instruction.accounts[16].pubkey),
treasury_token_program: (instruction.accounts[17].pubkey != instruction.program_id).then_some(instruction.accounts[17].pubkey),
treasury_associated_token_program: (instruction.accounts[18].pubkey != instruction.program_id).then_some(instruction.accounts[18].pubkey),
treasury_system_program: (instruction.accounts[19].pubkey != instruction.program_id).then_some(instruction.accounts[19].pubkey),
token_program: instruction.accounts[20].pubkey,
},
args,
remaining_accounts: instruction.accounts[21..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct ClaimFeesArgs {
pub fee_wallet: Pubkey,
}
impl ClaimFeesArgs {
pub const DISCRIMINATOR: [u8; 8] = [82, 251, 233, 156, 12, 52, 184, 202];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClaimFeesAccounts {
pub fee_mint: Pubkey,
pub fee_wallet_token_account: Pubkey,
pub program_authority: Pubkey,
pub fee_token_account: Pubkey,
pub global_config: Pubkey,
pub token_program: Pubkey,
}
impl ClaimFeesAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &ClaimFeesArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.fee_mint, false));
accounts.push(AccountMeta::new(self.fee_wallet_token_account, false));
accounts.push(AccountMeta::new_readonly(self.program_authority, false));
accounts.push(AccountMeta::new(self.fee_token_account, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.token_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedClaimFeesInstruction {
pub program_id: Pubkey,
pub accounts: ClaimFeesAccounts,
pub args: ClaimFeesArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_claim_fees_instruction(instruction: &Instruction) -> std::io::Result<ParsedClaimFeesInstruction> {
let args = ClaimFeesArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 6 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "claim_fees requires 6 accounts"));
}
Ok(ParsedClaimFeesInstruction {
program_id: instruction.program_id,
accounts: ClaimFeesAccounts {
fee_mint: instruction.accounts[0].pubkey,
fee_wallet_token_account: instruction.accounts[1].pubkey,
program_authority: instruction.accounts[2].pubkey,
fee_token_account: instruction.accounts[3].pubkey,
global_config: instruction.accounts[4].pubkey,
token_program: instruction.accounts[5].pubkey,
},
args,
remaining_accounts: instruction.accounts[6..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct CloseLpFeeAccountArgs {
}
impl CloseLpFeeAccountArgs {
pub const DISCRIMINATOR: [u8; 8] = [188, 218, 123, 57, 25, 51, 105, 181];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CloseLpFeeAccountAccounts {
pub liquidity_provider: Pubkey,
pub lp_fee_vault_authority: Pubkey,
pub global_config: Pubkey,
pub fee_token_mint_address: Pubkey,
pub lp_fee_token_account: Pubkey,
pub lp_destination_token_account: Pubkey,
pub token_program_fee: Pubkey,
}
impl CloseLpFeeAccountAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &CloseLpFeeAccountArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new_readonly(self.lp_fee_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.fee_token_mint_address, false));
accounts.push(AccountMeta::new(self.lp_fee_token_account, false));
accounts.push(AccountMeta::new(self.lp_destination_token_account, false));
accounts.push(AccountMeta::new_readonly(self.token_program_fee, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedCloseLpFeeAccountInstruction {
pub program_id: Pubkey,
pub accounts: CloseLpFeeAccountAccounts,
pub args: CloseLpFeeAccountArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_close_lp_fee_account_instruction(instruction: &Instruction) -> std::io::Result<ParsedCloseLpFeeAccountInstruction> {
let args = CloseLpFeeAccountArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 7 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "close_lp_fee_account requires 7 accounts"));
}
Ok(ParsedCloseLpFeeAccountInstruction {
program_id: instruction.program_id,
accounts: CloseLpFeeAccountAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
lp_fee_vault_authority: instruction.accounts[1].pubkey,
global_config: instruction.accounts[2].pubkey,
fee_token_mint_address: instruction.accounts[3].pubkey,
lp_fee_token_account: instruction.accounts[4].pubkey,
lp_destination_token_account: instruction.accounts[5].pubkey,
token_program_fee: instruction.accounts[6].pubkey,
},
args,
remaining_accounts: instruction.accounts[7..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct ClosePairArgs {
}
impl ClosePairArgs {
pub const DISCRIMINATOR: [u8; 8] = [45, 8, 194, 47, 65, 139, 172, 120];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClosePairAccounts {
pub admin: Pubkey,
pub liquidity_provider: Pubkey,
pub pair: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub lp_vault_authority: Pubkey,
pub quote_token_vault_token_account: Pubkey,
pub base_token_vault_token_account: Pubkey,
pub lp_quote_token_account: Pubkey,
pub lp_base_token_account: Pubkey,
pub lp_vault_quote_pda: Pubkey,
pub lp_vault_base_pda: Pubkey,
pub quote_asset_config: Pubkey,
pub base_asset_config: Pubkey,
pub global_config: Pubkey,
pub lp_protocol_fee_config: Pubkey,
pub treasury_user_position: Pubkey,
pub token_program_quote: Pubkey,
pub token_program_base: Pubkey,
}
impl ClosePairAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &ClosePairArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(19 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.admin, false));
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new(self.pair, false));
accounts.push(AccountMeta::new_readonly(self.quote_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.base_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.lp_vault_authority, false));
accounts.push(AccountMeta::new(self.quote_token_vault_token_account, false));
accounts.push(AccountMeta::new(self.base_token_vault_token_account, false));
accounts.push(AccountMeta::new(self.lp_quote_token_account, false));
accounts.push(AccountMeta::new(self.lp_base_token_account, false));
accounts.push(AccountMeta::new(self.lp_vault_quote_pda, false));
accounts.push(AccountMeta::new(self.lp_vault_base_pda, false));
accounts.push(AccountMeta::new(self.quote_asset_config, false));
accounts.push(AccountMeta::new(self.base_asset_config, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.lp_protocol_fee_config, false));
accounts.push(AccountMeta::new_readonly(self.treasury_user_position, false));
accounts.push(AccountMeta::new_readonly(self.token_program_quote, false));
accounts.push(AccountMeta::new_readonly(self.token_program_base, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedClosePairInstruction {
pub program_id: Pubkey,
pub accounts: ClosePairAccounts,
pub args: ClosePairArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_close_pair_instruction(instruction: &Instruction) -> std::io::Result<ParsedClosePairInstruction> {
let args = ClosePairArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 19 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "close_pair requires 19 accounts"));
}
Ok(ParsedClosePairInstruction {
program_id: instruction.program_id,
accounts: ClosePairAccounts {
admin: instruction.accounts[0].pubkey,
liquidity_provider: instruction.accounts[1].pubkey,
pair: instruction.accounts[2].pubkey,
quote_token_mint_address: instruction.accounts[3].pubkey,
base_token_mint_address: instruction.accounts[4].pubkey,
lp_vault_authority: instruction.accounts[5].pubkey,
quote_token_vault_token_account: instruction.accounts[6].pubkey,
base_token_vault_token_account: instruction.accounts[7].pubkey,
lp_quote_token_account: instruction.accounts[8].pubkey,
lp_base_token_account: instruction.accounts[9].pubkey,
lp_vault_quote_pda: instruction.accounts[10].pubkey,
lp_vault_base_pda: instruction.accounts[11].pubkey,
quote_asset_config: instruction.accounts[12].pubkey,
base_asset_config: instruction.accounts[13].pubkey,
global_config: instruction.accounts[14].pubkey,
lp_protocol_fee_config: instruction.accounts[15].pubkey,
treasury_user_position: instruction.accounts[16].pubkey,
token_program_quote: instruction.accounts[17].pubkey,
token_program_base: instruction.accounts[18].pubkey,
},
args,
remaining_accounts: instruction.accounts[19..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct CloseTreasuryPositionArgs {
}
impl CloseTreasuryPositionArgs {
pub const DISCRIMINATOR: [u8; 8] = [62, 152, 253, 37, 167, 251, 8, 64];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CloseTreasuryPositionAccounts {
pub liquidity_provider: Pubkey,
pub global_config: Pubkey,
pub treasury_global_config: Pubkey,
pub lp_vault_authority: Pubkey,
pub treasury_user_position: Pubkey,
pub treasury_mint: Pubkey,
pub treasury_user_treasury_token_account: Pubkey,
pub treasury_program: Pubkey,
pub token_program_treasury: Pubkey,
pub system_program: Pubkey,
}
impl CloseTreasuryPositionAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &CloseTreasuryPositionArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(10 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.treasury_global_config, false));
accounts.push(AccountMeta::new(self.lp_vault_authority, false));
accounts.push(AccountMeta::new(self.treasury_user_position, false));
accounts.push(AccountMeta::new_readonly(self.treasury_mint, false));
accounts.push(AccountMeta::new(self.treasury_user_treasury_token_account, false));
accounts.push(AccountMeta::new_readonly(self.treasury_program, false));
accounts.push(AccountMeta::new_readonly(self.token_program_treasury, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedCloseTreasuryPositionInstruction {
pub program_id: Pubkey,
pub accounts: CloseTreasuryPositionAccounts,
pub args: CloseTreasuryPositionArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_close_treasury_position_instruction(instruction: &Instruction) -> std::io::Result<ParsedCloseTreasuryPositionInstruction> {
let args = CloseTreasuryPositionArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 10 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "close_treasury_position requires 10 accounts"));
}
Ok(ParsedCloseTreasuryPositionInstruction {
program_id: instruction.program_id,
accounts: CloseTreasuryPositionAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
global_config: instruction.accounts[1].pubkey,
treasury_global_config: instruction.accounts[2].pubkey,
lp_vault_authority: instruction.accounts[3].pubkey,
treasury_user_position: instruction.accounts[4].pubkey,
treasury_mint: instruction.accounts[5].pubkey,
treasury_user_treasury_token_account: instruction.accounts[6].pubkey,
treasury_program: instruction.accounts[7].pubkey,
token_program_treasury: instruction.accounts[8].pubkey,
system_program: instruction.accounts[9].pubkey,
},
args,
remaining_accounts: instruction.accounts[10..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct ConfirmNewAdminArgs {
}
impl ConfirmNewAdminArgs {
pub const DISCRIMINATOR: [u8; 8] = [3, 109, 83, 170, 106, 54, 173, 117];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConfirmNewAdminAccounts {
pub global_config: Pubkey,
pub new_admin: Pubkey,
}
impl ConfirmNewAdminAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &ConfirmNewAdminArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.new_admin, true));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedConfirmNewAdminInstruction {
pub program_id: Pubkey,
pub accounts: ConfirmNewAdminAccounts,
pub args: ConfirmNewAdminArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_confirm_new_admin_instruction(instruction: &Instruction) -> std::io::Result<ParsedConfirmNewAdminInstruction> {
let args = ConfirmNewAdminArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 2 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "confirm_new_admin requires 2 accounts"));
}
Ok(ParsedConfirmNewAdminInstruction {
program_id: instruction.program_id,
accounts: ConfirmNewAdminAccounts {
global_config: instruction.accounts[0].pubkey,
new_admin: instruction.accounts[1].pubkey,
},
args,
remaining_accounts: instruction.accounts[2..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct InitAssetConfigAccountArgs {
pub nav_data: Vec<NavData>,
pub price_difference_bps: u16,
pub asset_type: AssetType,
}
impl InitAssetConfigAccountArgs {
pub const DISCRIMINATOR: [u8; 8] = [32, 66, 21, 159, 176, 230, 59, 11];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitAssetConfigAccountAccounts {
pub asset_config: Pubkey,
pub mint_address: Pubkey,
pub admin: Pubkey,
pub fee_vault_token_account: Pubkey,
pub program_authority: Pubkey,
pub global_config: Pubkey,
pub token_program: Pubkey,
pub system_program: Pubkey,
pub associated_token_program: Pubkey,
}
impl InitAssetConfigAccountAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &InitAssetConfigAccountArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.asset_config, false));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new(self.admin, true));
accounts.push(AccountMeta::new(self.fee_vault_token_account, false));
accounts.push(AccountMeta::new_readonly(self.program_authority, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.token_program, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.push(AccountMeta::new_readonly(self.associated_token_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedInitAssetConfigAccountInstruction {
pub program_id: Pubkey,
pub accounts: InitAssetConfigAccountAccounts,
pub args: InitAssetConfigAccountArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_init_asset_config_account_instruction(instruction: &Instruction) -> std::io::Result<ParsedInitAssetConfigAccountInstruction> {
let args = InitAssetConfigAccountArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 9 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "init_asset_config_account requires 9 accounts"));
}
Ok(ParsedInitAssetConfigAccountInstruction {
program_id: instruction.program_id,
accounts: InitAssetConfigAccountAccounts {
asset_config: instruction.accounts[0].pubkey,
mint_address: instruction.accounts[1].pubkey,
admin: instruction.accounts[2].pubkey,
fee_vault_token_account: instruction.accounts[3].pubkey,
program_authority: instruction.accounts[4].pubkey,
global_config: instruction.accounts[5].pubkey,
token_program: instruction.accounts[6].pubkey,
system_program: instruction.accounts[7].pubkey,
associated_token_program: instruction.accounts[8].pubkey,
},
args,
remaining_accounts: instruction.accounts[9..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct InitGlobalConfigArgs {
pub fee_wallet: Pubkey,
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
pub fee_token_mint: Pubkey,
}
impl InitGlobalConfigArgs {
pub const DISCRIMINATOR: [u8; 8] = [140, 136, 214, 48, 87, 0, 120, 255];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitGlobalConfigAccounts {
pub global_config: Pubkey,
pub admin: Pubkey,
pub program_data: Pubkey,
pub program_authority: Pubkey,
pub fee_token_mint_address: Pubkey,
pub fee_token_account: Pubkey,
pub token_program_fee: Pubkey,
pub associated_token_program: Pubkey,
pub system_program: Pubkey,
}
impl InitGlobalConfigAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &InitGlobalConfigArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.global_config, false));
accounts.push(AccountMeta::new(self.admin, true));
accounts.push(AccountMeta::new_readonly(self.program_data, false));
accounts.push(AccountMeta::new_readonly(self.program_authority, false));
accounts.push(AccountMeta::new_readonly(self.fee_token_mint_address, false));
accounts.push(AccountMeta::new(self.fee_token_account, false));
accounts.push(AccountMeta::new_readonly(self.token_program_fee, false));
accounts.push(AccountMeta::new_readonly(self.associated_token_program, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedInitGlobalConfigInstruction {
pub program_id: Pubkey,
pub accounts: InitGlobalConfigAccounts,
pub args: InitGlobalConfigArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_init_global_config_instruction(instruction: &Instruction) -> std::io::Result<ParsedInitGlobalConfigInstruction> {
let args = InitGlobalConfigArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 9 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "init_global_config requires 9 accounts"));
}
Ok(ParsedInitGlobalConfigInstruction {
program_id: instruction.program_id,
accounts: InitGlobalConfigAccounts {
global_config: instruction.accounts[0].pubkey,
admin: instruction.accounts[1].pubkey,
program_data: instruction.accounts[2].pubkey,
program_authority: instruction.accounts[3].pubkey,
fee_token_mint_address: instruction.accounts[4].pubkey,
fee_token_account: instruction.accounts[5].pubkey,
token_program_fee: instruction.accounts[6].pubkey,
associated_token_program: instruction.accounts[7].pubkey,
system_program: instruction.accounts[8].pubkey,
},
args,
remaining_accounts: instruction.accounts[9..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct InitPairArgs {
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
}
impl InitPairArgs {
pub const DISCRIMINATOR: [u8; 8] = [210, 79, 92, 60, 153, 69, 57, 157];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitPairAccounts {
pub liquidity_provider: Pubkey,
pub pair: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub lp_vault_authority: Pubkey,
pub lp_fee_vault_authority: Pubkey,
pub quote_token_vault_token_account: Pubkey,
pub base_token_vault_token_account: Pubkey,
pub lp_vault_quote_pda: Pubkey,
pub lp_vault_base_pda: Pubkey,
pub global_config: Pubkey,
pub fee_token_mint_address: Pubkey,
pub lp_fee_token_account: Pubkey,
pub lp_stable_config_quote: Option<Pubkey>,
pub lp_stable_config_base: Option<Pubkey>,
pub quote_asset_config: Pubkey,
pub base_asset_config: Pubkey,
pub token_program_quote: Pubkey,
pub token_program_base: Pubkey,
pub token_program_fee: Pubkey,
pub associated_token_program: Pubkey,
pub system_program: Pubkey,
}
impl InitPairAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &InitPairArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(22 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new(self.pair, false));
accounts.push(AccountMeta::new_readonly(self.quote_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.base_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.lp_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.lp_fee_vault_authority, false));
accounts.push(AccountMeta::new(self.quote_token_vault_token_account, false));
accounts.push(AccountMeta::new(self.base_token_vault_token_account, false));
accounts.push(AccountMeta::new(self.lp_vault_quote_pda, false));
accounts.push(AccountMeta::new(self.lp_vault_base_pda, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.fee_token_mint_address, false));
accounts.push(AccountMeta::new(self.lp_fee_token_account, false));
accounts.push(match self.lp_stable_config_quote {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.lp_stable_config_base {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(AccountMeta::new(self.quote_asset_config, false));
accounts.push(AccountMeta::new(self.base_asset_config, false));
accounts.push(AccountMeta::new_readonly(self.token_program_quote, false));
accounts.push(AccountMeta::new_readonly(self.token_program_base, false));
accounts.push(AccountMeta::new_readonly(self.token_program_fee, false));
accounts.push(AccountMeta::new_readonly(self.associated_token_program, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedInitPairInstruction {
pub program_id: Pubkey,
pub accounts: InitPairAccounts,
pub args: InitPairArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_init_pair_instruction(instruction: &Instruction) -> std::io::Result<ParsedInitPairInstruction> {
let args = InitPairArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 22 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "init_pair requires 22 accounts"));
}
Ok(ParsedInitPairInstruction {
program_id: instruction.program_id,
accounts: InitPairAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
pair: instruction.accounts[1].pubkey,
quote_token_mint_address: instruction.accounts[2].pubkey,
base_token_mint_address: instruction.accounts[3].pubkey,
lp_vault_authority: instruction.accounts[4].pubkey,
lp_fee_vault_authority: instruction.accounts[5].pubkey,
quote_token_vault_token_account: instruction.accounts[6].pubkey,
base_token_vault_token_account: instruction.accounts[7].pubkey,
lp_vault_quote_pda: instruction.accounts[8].pubkey,
lp_vault_base_pda: instruction.accounts[9].pubkey,
global_config: instruction.accounts[10].pubkey,
fee_token_mint_address: instruction.accounts[11].pubkey,
lp_fee_token_account: instruction.accounts[12].pubkey,
lp_stable_config_quote: (instruction.accounts[13].pubkey != instruction.program_id).then_some(instruction.accounts[13].pubkey),
lp_stable_config_base: (instruction.accounts[14].pubkey != instruction.program_id).then_some(instruction.accounts[14].pubkey),
quote_asset_config: instruction.accounts[15].pubkey,
base_asset_config: instruction.accounts[16].pubkey,
token_program_quote: instruction.accounts[17].pubkey,
token_program_base: instruction.accounts[18].pubkey,
token_program_fee: instruction.accounts[19].pubkey,
associated_token_program: instruction.accounts[20].pubkey,
system_program: instruction.accounts[21].pubkey,
},
args,
remaining_accounts: instruction.accounts[22..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct RemoveLiquidityArgs {
pub amount: u64,
pub treasury_nav_account_count: u8,
pub treasury_apy_account_count: u8,
pub exact_mode: ExactMode,
pub amount_threshold: Option<u64>,
}
impl RemoveLiquidityArgs {
pub const DISCRIMINATOR: [u8; 8] = [80, 85, 209, 72, 24, 206, 177, 108];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoveLiquidityAccounts {
pub liquidity_provider: Pubkey,
pub mint_address: Pubkey,
pub lp_token_account: Pubkey,
pub vault_token_account: Pubkey,
pub lp_vault_authority: Pubkey,
pub global_config: Pubkey,
pub lp_protocol_fee_config: Pubkey,
pub treasury_program: Option<Pubkey>,
pub treasury_global_config: Option<Pubkey>,
pub treasury_asset_config: Option<Pubkey>,
pub treasury_user_position: Option<Pubkey>,
pub treasury_vault_authority: Option<Pubkey>,
pub treasury_mint: Option<Pubkey>,
pub treasury_user_treasury_token_account: Option<Pubkey>,
pub treasury_asset_vault: Option<Pubkey>,
pub treasury_latest_apy_entry: Option<Pubkey>,
pub treasury_token_program: Option<Pubkey>,
pub treasury_associated_token_program: Option<Pubkey>,
pub token_program: Pubkey,
}
impl RemoveLiquidityAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &RemoveLiquidityArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(19 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.liquidity_provider, true));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new(self.lp_token_account, false));
accounts.push(AccountMeta::new(self.vault_token_account, false));
accounts.push(AccountMeta::new(self.lp_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.lp_protocol_fee_config, false));
accounts.push(match self.treasury_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_global_config {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_asset_config {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_user_position {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_vault_authority {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_mint {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_user_treasury_token_account {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_asset_vault {
Some(address) => AccountMeta::new(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_latest_apy_entry {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_token_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.treasury_associated_token_program {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(AccountMeta::new_readonly(self.token_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedRemoveLiquidityInstruction {
pub program_id: Pubkey,
pub accounts: RemoveLiquidityAccounts,
pub args: RemoveLiquidityArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_remove_liquidity_instruction(instruction: &Instruction) -> std::io::Result<ParsedRemoveLiquidityInstruction> {
let args = RemoveLiquidityArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 19 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "remove_liquidity requires 19 accounts"));
}
Ok(ParsedRemoveLiquidityInstruction {
program_id: instruction.program_id,
accounts: RemoveLiquidityAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
mint_address: instruction.accounts[1].pubkey,
lp_token_account: instruction.accounts[2].pubkey,
vault_token_account: instruction.accounts[3].pubkey,
lp_vault_authority: instruction.accounts[4].pubkey,
global_config: instruction.accounts[5].pubkey,
lp_protocol_fee_config: instruction.accounts[6].pubkey,
treasury_program: (instruction.accounts[7].pubkey != instruction.program_id).then_some(instruction.accounts[7].pubkey),
treasury_global_config: (instruction.accounts[8].pubkey != instruction.program_id).then_some(instruction.accounts[8].pubkey),
treasury_asset_config: (instruction.accounts[9].pubkey != instruction.program_id).then_some(instruction.accounts[9].pubkey),
treasury_user_position: (instruction.accounts[10].pubkey != instruction.program_id).then_some(instruction.accounts[10].pubkey),
treasury_vault_authority: (instruction.accounts[11].pubkey != instruction.program_id).then_some(instruction.accounts[11].pubkey),
treasury_mint: (instruction.accounts[12].pubkey != instruction.program_id).then_some(instruction.accounts[12].pubkey),
treasury_user_treasury_token_account: (instruction.accounts[13].pubkey != instruction.program_id).then_some(instruction.accounts[13].pubkey),
treasury_asset_vault: (instruction.accounts[14].pubkey != instruction.program_id).then_some(instruction.accounts[14].pubkey),
treasury_latest_apy_entry: (instruction.accounts[15].pubkey != instruction.program_id).then_some(instruction.accounts[15].pubkey),
treasury_token_program: (instruction.accounts[16].pubkey != instruction.program_id).then_some(instruction.accounts[16].pubkey),
treasury_associated_token_program: (instruction.accounts[17].pubkey != instruction.program_id).then_some(instruction.accounts[17].pubkey),
token_program: instruction.accounts[18].pubkey,
},
args,
remaining_accounts: instruction.accounts[19..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SetLpProtocolFeeConfigArgs {
pub protocol_fees_bps: u16,
pub spread_protocol_fees_bps: u16,
}
impl SetLpProtocolFeeConfigArgs {
pub const DISCRIMINATOR: [u8; 8] = [116, 84, 221, 0, 37, 34, 202, 205];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetLpProtocolFeeConfigAccounts {
pub admin: Pubkey,
pub global_config: Pubkey,
pub lp_protocol_fee_config: Pubkey,
pub liquidity_provider: Pubkey,
pub system_program: Pubkey,
}
impl SetLpProtocolFeeConfigAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SetLpProtocolFeeConfigArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.admin, true));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new(self.lp_protocol_fee_config, false));
accounts.push(AccountMeta::new_readonly(self.liquidity_provider, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSetLpProtocolFeeConfigInstruction {
pub program_id: Pubkey,
pub accounts: SetLpProtocolFeeConfigAccounts,
pub args: SetLpProtocolFeeConfigArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_set_lp_protocol_fee_config_instruction(instruction: &Instruction) -> std::io::Result<ParsedSetLpProtocolFeeConfigInstruction> {
let args = SetLpProtocolFeeConfigArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 5 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "set_lp_protocol_fee_config requires 5 accounts"));
}
Ok(ParsedSetLpProtocolFeeConfigInstruction {
program_id: instruction.program_id,
accounts: SetLpProtocolFeeConfigAccounts {
admin: instruction.accounts[0].pubkey,
global_config: instruction.accounts[1].pubkey,
lp_protocol_fee_config: instruction.accounts[2].pubkey,
liquidity_provider: instruction.accounts[3].pubkey,
system_program: instruction.accounts[4].pubkey,
},
args,
remaining_accounts: instruction.accounts[5..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SetLpTreasuryEnabledArgs {
pub enabled: bool,
}
impl SetLpTreasuryEnabledArgs {
pub const DISCRIMINATOR: [u8; 8] = [211, 145, 194, 69, 58, 232, 85, 175];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetLpTreasuryEnabledAccounts {
pub liquidity_provider: Pubkey,
pub global_config: Pubkey,
pub lp_protocol_fee_config: Pubkey,
pub lp_vault_authority: Pubkey,
pub treasury_global_config: Pubkey,
pub treasury_mint: Pubkey,
pub treasury_user_position: Pubkey,
pub system_program: Pubkey,
}
impl SetLpTreasuryEnabledAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SetLpTreasuryEnabledArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.liquidity_provider, true));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new(self.lp_protocol_fee_config, false));
accounts.push(AccountMeta::new(self.lp_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.treasury_global_config, false));
accounts.push(AccountMeta::new_readonly(self.treasury_mint, false));
accounts.push(AccountMeta::new_readonly(self.treasury_user_position, false));
accounts.push(AccountMeta::new_readonly(self.system_program, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSetLpTreasuryEnabledInstruction {
pub program_id: Pubkey,
pub accounts: SetLpTreasuryEnabledAccounts,
pub args: SetLpTreasuryEnabledArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_set_lp_treasury_enabled_instruction(instruction: &Instruction) -> std::io::Result<ParsedSetLpTreasuryEnabledInstruction> {
let args = SetLpTreasuryEnabledArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 8 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "set_lp_treasury_enabled requires 8 accounts"));
}
Ok(ParsedSetLpTreasuryEnabledInstruction {
program_id: instruction.program_id,
accounts: SetLpTreasuryEnabledAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
global_config: instruction.accounts[1].pubkey,
lp_protocol_fee_config: instruction.accounts[2].pubkey,
lp_vault_authority: instruction.accounts[3].pubkey,
treasury_global_config: instruction.accounts[4].pubkey,
treasury_mint: instruction.accounts[5].pubkey,
treasury_user_position: instruction.accounts[6].pubkey,
system_program: instruction.accounts[7].pubkey,
},
args,
remaining_accounts: instruction.accounts[8..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SetNewAdminArgs {
pub new_admin: Pubkey,
}
impl SetNewAdminArgs {
pub const DISCRIMINATOR: [u8; 8] = [62, 156, 4, 148, 79, 162, 148, 252];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetNewAdminAccounts {
pub global_config: Pubkey,
pub admin: Pubkey,
}
impl SetNewAdminAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SetNewAdminArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.admin, true));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSetNewAdminInstruction {
pub program_id: Pubkey,
pub accounts: SetNewAdminAccounts,
pub args: SetNewAdminArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_set_new_admin_instruction(instruction: &Instruction) -> std::io::Result<ParsedSetNewAdminInstruction> {
let args = SetNewAdminArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 2 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "set_new_admin requires 2 accounts"));
}
Ok(ParsedSetNewAdminInstruction {
program_id: instruction.program_id,
accounts: SetNewAdminAccounts {
global_config: instruction.accounts[0].pubkey,
admin: instruction.accounts[1].pubkey,
},
args,
remaining_accounts: instruction.accounts[2..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SetPausedForAssetArgs {
pub paused: bool,
}
impl SetPausedForAssetArgs {
pub const DISCRIMINATOR: [u8; 8] = [116, 141, 145, 189, 67, 108, 178, 238];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetPausedForAssetAccounts {
pub global_config: Pubkey,
pub asset_config: Pubkey,
pub mint_address: Pubkey,
pub admin: Pubkey,
}
impl SetPausedForAssetAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SetPausedForAssetArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new(self.asset_config, false));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new(self.admin, true));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSetPausedForAssetInstruction {
pub program_id: Pubkey,
pub accounts: SetPausedForAssetAccounts,
pub args: SetPausedForAssetArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_set_paused_for_asset_instruction(instruction: &Instruction) -> std::io::Result<ParsedSetPausedForAssetInstruction> {
let args = SetPausedForAssetArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 4 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "set_paused_for_asset requires 4 accounts"));
}
Ok(ParsedSetPausedForAssetInstruction {
program_id: instruction.program_id,
accounts: SetPausedForAssetAccounts {
global_config: instruction.accounts[0].pubkey,
asset_config: instruction.accounts[1].pubkey,
mint_address: instruction.accounts[2].pubkey,
admin: instruction.accounts[3].pubkey,
},
args,
remaining_accounts: instruction.accounts[4..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SetPausedForLpStableConfigArgs {
pub paused: bool,
}
impl SetPausedForLpStableConfigArgs {
pub const DISCRIMINATOR: [u8; 8] = [214, 35, 14, 32, 51, 46, 101, 150];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetPausedForLpStableConfigAccounts {
pub global_config: Pubkey,
pub lp_stable_config: Pubkey,
pub mint_address: Pubkey,
pub liquidity_provider: Pubkey,
pub signer: Pubkey,
}
impl SetPausedForLpStableConfigAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SetPausedForLpStableConfigArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new(self.lp_stable_config, false));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new_readonly(self.liquidity_provider, false));
accounts.push(AccountMeta::new_readonly(self.signer, true));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSetPausedForLpStableConfigInstruction {
pub program_id: Pubkey,
pub accounts: SetPausedForLpStableConfigAccounts,
pub args: SetPausedForLpStableConfigArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_set_paused_for_lp_stable_config_instruction(instruction: &Instruction) -> std::io::Result<ParsedSetPausedForLpStableConfigInstruction> {
let args = SetPausedForLpStableConfigArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 5 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "set_paused_for_lp_stable_config requires 5 accounts"));
}
Ok(ParsedSetPausedForLpStableConfigInstruction {
program_id: instruction.program_id,
accounts: SetPausedForLpStableConfigAccounts {
global_config: instruction.accounts[0].pubkey,
lp_stable_config: instruction.accounts[1].pubkey,
mint_address: instruction.accounts[2].pubkey,
liquidity_provider: instruction.accounts[3].pubkey,
signer: instruction.accounts[4].pubkey,
},
args,
remaining_accounts: instruction.accounts[5..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct SwapArgs {
pub amount: u64,
pub min_amount_out: Option<u64>,
pub max_amount_in: Option<u64>,
pub swap_direction: SwapDirection,
pub swap_type: SwapType,
pub treasury_nav_account_count: u8,
pub treasury_apy_account_count: u8,
}
impl SwapArgs {
pub const DISCRIMINATOR: [u8; 8] = [248, 198, 158, 145, 225, 117, 135, 200];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SwapAccounts {
pub user: Pubkey,
pub pair: Pubkey,
pub program_authority: Pubkey,
pub liquidity_provider: Pubkey,
pub lp_vault_authority: Pubkey,
pub lp_fee_vault_authority: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub base_token_user_token_account: Pubkey,
pub quote_token_user_token_account: Pubkey,
pub quote_token_vault_token_account: Pubkey,
pub base_token_vault_token_account: Pubkey,
pub global_config: Pubkey,
pub fee_token_mint_address: Pubkey,
pub lp_fee_token_account: Pubkey,
pub fee_token_account: Pubkey,
pub base_config: Pubkey,
pub quote_config: Pubkey,
pub fee_config: Pubkey,
pub lp_stable_config_quote: Option<Pubkey>,
pub lp_stable_config_base: Option<Pubkey>,
pub lp_protocol_fee_config: Pubkey,
pub token_program_quote: Pubkey,
pub token_program_base: Pubkey,
pub token_program_fee: Pubkey,
}
impl SwapAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &SwapArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(25 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.user, true));
accounts.push(AccountMeta::new_readonly(self.pair, false));
accounts.push(AccountMeta::new_readonly(self.program_authority, false));
accounts.push(AccountMeta::new_readonly(self.liquidity_provider, false));
accounts.push(AccountMeta::new(self.lp_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.lp_fee_vault_authority, false));
accounts.push(AccountMeta::new_readonly(self.quote_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.base_token_mint_address, false));
accounts.push(AccountMeta::new(self.base_token_user_token_account, false));
accounts.push(AccountMeta::new(self.quote_token_user_token_account, false));
accounts.push(AccountMeta::new(self.quote_token_vault_token_account, false));
accounts.push(AccountMeta::new(self.base_token_vault_token_account, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.fee_token_mint_address, false));
accounts.push(AccountMeta::new(self.lp_fee_token_account, false));
accounts.push(AccountMeta::new(self.fee_token_account, false));
accounts.push(AccountMeta::new_readonly(self.base_config, false));
accounts.push(AccountMeta::new_readonly(self.quote_config, false));
accounts.push(AccountMeta::new_readonly(self.fee_config, false));
accounts.push(match self.lp_stable_config_quote {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(match self.lp_stable_config_base {
Some(address) => AccountMeta::new_readonly(address, false),
None => AccountMeta::new_readonly(program_id, false),
});
accounts.push(AccountMeta::new_readonly(self.lp_protocol_fee_config, false));
accounts.push(AccountMeta::new_readonly(self.token_program_quote, false));
accounts.push(AccountMeta::new_readonly(self.token_program_base, false));
accounts.push(AccountMeta::new_readonly(self.token_program_fee, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedSwapInstruction {
pub program_id: Pubkey,
pub accounts: SwapAccounts,
pub args: SwapArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_swap_instruction(instruction: &Instruction) -> std::io::Result<ParsedSwapInstruction> {
let args = SwapArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 25 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "swap requires 25 accounts"));
}
Ok(ParsedSwapInstruction {
program_id: instruction.program_id,
accounts: SwapAccounts {
user: instruction.accounts[0].pubkey,
pair: instruction.accounts[1].pubkey,
program_authority: instruction.accounts[2].pubkey,
liquidity_provider: instruction.accounts[3].pubkey,
lp_vault_authority: instruction.accounts[4].pubkey,
lp_fee_vault_authority: instruction.accounts[5].pubkey,
quote_token_mint_address: instruction.accounts[6].pubkey,
base_token_mint_address: instruction.accounts[7].pubkey,
base_token_user_token_account: instruction.accounts[8].pubkey,
quote_token_user_token_account: instruction.accounts[9].pubkey,
quote_token_vault_token_account: instruction.accounts[10].pubkey,
base_token_vault_token_account: instruction.accounts[11].pubkey,
global_config: instruction.accounts[12].pubkey,
fee_token_mint_address: instruction.accounts[13].pubkey,
lp_fee_token_account: instruction.accounts[14].pubkey,
fee_token_account: instruction.accounts[15].pubkey,
base_config: instruction.accounts[16].pubkey,
quote_config: instruction.accounts[17].pubkey,
fee_config: instruction.accounts[18].pubkey,
lp_stable_config_quote: (instruction.accounts[19].pubkey != instruction.program_id).then_some(instruction.accounts[19].pubkey),
lp_stable_config_base: (instruction.accounts[20].pubkey != instruction.program_id).then_some(instruction.accounts[20].pubkey),
lp_protocol_fee_config: instruction.accounts[21].pubkey,
token_program_quote: instruction.accounts[22].pubkey,
token_program_base: instruction.accounts[23].pubkey,
token_program_fee: instruction.accounts[24].pubkey,
},
args,
remaining_accounts: instruction.accounts[25..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct UpdateAssetConfigAccountArgs {
pub nav_data: Vec<NavData>,
pub price_difference_bps: u16,
pub asset_type: AssetType,
}
impl UpdateAssetConfigAccountArgs {
pub const DISCRIMINATOR: [u8; 8] = [217, 201, 225, 177, 234, 99, 234, 162];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdateAssetConfigAccountAccounts {
pub asset_config: Pubkey,
pub mint_address: Pubkey,
pub admin: Pubkey,
pub global_config: Pubkey,
}
impl UpdateAssetConfigAccountAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &UpdateAssetConfigAccountArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.asset_config, false));
accounts.push(AccountMeta::new_readonly(self.mint_address, false));
accounts.push(AccountMeta::new_readonly(self.admin, true));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedUpdateAssetConfigAccountInstruction {
pub program_id: Pubkey,
pub accounts: UpdateAssetConfigAccountAccounts,
pub args: UpdateAssetConfigAccountArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_update_asset_config_account_instruction(instruction: &Instruction) -> std::io::Result<ParsedUpdateAssetConfigAccountInstruction> {
let args = UpdateAssetConfigAccountArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 4 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "update_asset_config_account requires 4 accounts"));
}
Ok(ParsedUpdateAssetConfigAccountInstruction {
program_id: instruction.program_id,
accounts: UpdateAssetConfigAccountAccounts {
asset_config: instruction.accounts[0].pubkey,
mint_address: instruction.accounts[1].pubkey,
admin: instruction.accounts[2].pubkey,
global_config: instruction.accounts[3].pubkey,
},
args,
remaining_accounts: instruction.accounts[4..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct UpdateGlobalConfigArgs {
pub fee_wallet: Option<Pubkey>,
pub paused: Option<bool>,
pub protocol_fees_bps: Option<u16>,
pub spread_protocol_fees_bps: Option<u16>,
pub fee_token_mint: Option<Pubkey>,
}
impl UpdateGlobalConfigArgs {
pub const DISCRIMINATOR: [u8; 8] = [164, 84, 130, 189, 111, 58, 250, 200];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdateGlobalConfigAccounts {
pub global_config: Pubkey,
pub admin: Pubkey,
}
impl UpdateGlobalConfigAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &UpdateGlobalConfigArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
accounts.push(AccountMeta::new(self.global_config, false));
accounts.push(AccountMeta::new_readonly(self.admin, true));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedUpdateGlobalConfigInstruction {
pub program_id: Pubkey,
pub accounts: UpdateGlobalConfigAccounts,
pub args: UpdateGlobalConfigArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_update_global_config_instruction(instruction: &Instruction) -> std::io::Result<ParsedUpdateGlobalConfigInstruction> {
let args = UpdateGlobalConfigArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 2 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "update_global_config requires 2 accounts"));
}
Ok(ParsedUpdateGlobalConfigInstruction {
program_id: instruction.program_id,
accounts: UpdateGlobalConfigAccounts {
global_config: instruction.accounts[0].pubkey,
admin: instruction.accounts[1].pubkey,
},
args,
remaining_accounts: instruction.accounts[2..].to_vec(),
})
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct UpdatePairArgs {
pub redemption_fee_bps: u16,
pub discount_rate_bps: u16,
pub paused: bool,
}
impl UpdatePairArgs {
pub const DISCRIMINATOR: [u8; 8] = [176, 62, 36, 215, 255, 206, 35, 12];
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
super::decode(data, Self::DISCRIMINATOR)
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
super::encode(self, Self::DISCRIMINATOR)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdatePairAccounts {
pub liquidity_provider: Pubkey,
pub pair: Pubkey,
pub quote_token_mint_address: Pubkey,
pub base_token_mint_address: Pubkey,
pub global_config: Pubkey,
}
impl UpdatePairAccounts {
pub fn instruction(
&self,
program_id: Pubkey,
args: &UpdatePairArgs,
remaining_accounts: &[AccountMeta],
) -> std::io::Result<Instruction> {
let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
accounts.push(AccountMeta::new_readonly(self.liquidity_provider, true));
accounts.push(AccountMeta::new(self.pair, false));
accounts.push(AccountMeta::new_readonly(self.quote_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.base_token_mint_address, false));
accounts.push(AccountMeta::new_readonly(self.global_config, false));
accounts.extend_from_slice(remaining_accounts);
Ok(Instruction { program_id, accounts, data: args.encode()? })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedUpdatePairInstruction {
pub program_id: Pubkey,
pub accounts: UpdatePairAccounts,
pub args: UpdatePairArgs,
pub remaining_accounts: Vec<AccountMeta>,
}
pub fn parse_update_pair_instruction(instruction: &Instruction) -> std::io::Result<ParsedUpdatePairInstruction> {
let args = UpdatePairArgs::decode(&instruction.data)?;
if instruction.accounts.len() < 5 {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "update_pair requires 5 accounts"));
}
Ok(ParsedUpdatePairInstruction {
program_id: instruction.program_id,
accounts: UpdatePairAccounts {
liquidity_provider: instruction.accounts[0].pubkey,
pair: instruction.accounts[1].pubkey,
quote_token_mint_address: instruction.accounts[2].pubkey,
base_token_mint_address: instruction.accounts[3].pubkey,
global_config: instruction.accounts[4].pubkey,
},
args,
remaining_accounts: instruction.accounts[5..].to_vec(),
})
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InstructionKind {
AddLiquidity,
ClaimFees,
CloseLpFeeAccount,
ClosePair,
CloseTreasuryPosition,
ConfirmNewAdmin,
InitAssetConfigAccount,
InitGlobalConfig,
InitPair,
RemoveLiquidity,
SetLpProtocolFeeConfig,
SetLpTreasuryEnabled,
SetNewAdmin,
SetPausedForAsset,
SetPausedForLpStableConfig,
Swap,
UpdateAssetConfigAccount,
UpdateGlobalConfig,
UpdatePair,
}
pub const INSTRUCTION_DISCRIMINATORS: &[(&str, [u8; 8])] = &[
("add_liquidity", AddLiquidityArgs::DISCRIMINATOR),
("claim_fees", ClaimFeesArgs::DISCRIMINATOR),
("close_lp_fee_account", CloseLpFeeAccountArgs::DISCRIMINATOR),
("close_pair", ClosePairArgs::DISCRIMINATOR),
("close_treasury_position", CloseTreasuryPositionArgs::DISCRIMINATOR),
("confirm_new_admin", ConfirmNewAdminArgs::DISCRIMINATOR),
("init_asset_config_account", InitAssetConfigAccountArgs::DISCRIMINATOR),
("init_global_config", InitGlobalConfigArgs::DISCRIMINATOR),
("init_pair", InitPairArgs::DISCRIMINATOR),
("remove_liquidity", RemoveLiquidityArgs::DISCRIMINATOR),
("set_lp_protocol_fee_config", SetLpProtocolFeeConfigArgs::DISCRIMINATOR),
("set_lp_treasury_enabled", SetLpTreasuryEnabledArgs::DISCRIMINATOR),
("set_new_admin", SetNewAdminArgs::DISCRIMINATOR),
("set_paused_for_asset", SetPausedForAssetArgs::DISCRIMINATOR),
("set_paused_for_lp_stable_config", SetPausedForLpStableConfigArgs::DISCRIMINATOR),
("swap", SwapArgs::DISCRIMINATOR),
("update_asset_config_account", UpdateAssetConfigAccountArgs::DISCRIMINATOR),
("update_global_config", UpdateGlobalConfigArgs::DISCRIMINATOR),
("update_pair", UpdatePairArgs::DISCRIMINATOR),
];
pub fn identify_instruction(data: &[u8]) -> std::io::Result<InstructionKind> {
match super::discriminator(data)? {
AddLiquidityArgs::DISCRIMINATOR => Ok(InstructionKind::AddLiquidity),
ClaimFeesArgs::DISCRIMINATOR => Ok(InstructionKind::ClaimFees),
CloseLpFeeAccountArgs::DISCRIMINATOR => Ok(InstructionKind::CloseLpFeeAccount),
ClosePairArgs::DISCRIMINATOR => Ok(InstructionKind::ClosePair),
CloseTreasuryPositionArgs::DISCRIMINATOR => Ok(InstructionKind::CloseTreasuryPosition),
ConfirmNewAdminArgs::DISCRIMINATOR => Ok(InstructionKind::ConfirmNewAdmin),
InitAssetConfigAccountArgs::DISCRIMINATOR => Ok(InstructionKind::InitAssetConfigAccount),
InitGlobalConfigArgs::DISCRIMINATOR => Ok(InstructionKind::InitGlobalConfig),
InitPairArgs::DISCRIMINATOR => Ok(InstructionKind::InitPair),
RemoveLiquidityArgs::DISCRIMINATOR => Ok(InstructionKind::RemoveLiquidity),
SetLpProtocolFeeConfigArgs::DISCRIMINATOR => Ok(InstructionKind::SetLpProtocolFeeConfig),
SetLpTreasuryEnabledArgs::DISCRIMINATOR => Ok(InstructionKind::SetLpTreasuryEnabled),
SetNewAdminArgs::DISCRIMINATOR => Ok(InstructionKind::SetNewAdmin),
SetPausedForAssetArgs::DISCRIMINATOR => Ok(InstructionKind::SetPausedForAsset),
SetPausedForLpStableConfigArgs::DISCRIMINATOR => Ok(InstructionKind::SetPausedForLpStableConfig),
SwapArgs::DISCRIMINATOR => Ok(InstructionKind::Swap),
UpdateAssetConfigAccountArgs::DISCRIMINATOR => Ok(InstructionKind::UpdateAssetConfigAccount),
UpdateGlobalConfigArgs::DISCRIMINATOR => Ok(InstructionKind::UpdateGlobalConfig),
UpdatePairArgs::DISCRIMINATOR => Ok(InstructionKind::UpdatePair),
_ => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Unknown instruction discriminator")),
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedInstruction {
AddLiquidity(ParsedAddLiquidityInstruction),
ClaimFees(ParsedClaimFeesInstruction),
CloseLpFeeAccount(ParsedCloseLpFeeAccountInstruction),
ClosePair(ParsedClosePairInstruction),
CloseTreasuryPosition(ParsedCloseTreasuryPositionInstruction),
ConfirmNewAdmin(ParsedConfirmNewAdminInstruction),
InitAssetConfigAccount(ParsedInitAssetConfigAccountInstruction),
InitGlobalConfig(ParsedInitGlobalConfigInstruction),
InitPair(ParsedInitPairInstruction),
RemoveLiquidity(ParsedRemoveLiquidityInstruction),
SetLpProtocolFeeConfig(ParsedSetLpProtocolFeeConfigInstruction),
SetLpTreasuryEnabled(ParsedSetLpTreasuryEnabledInstruction),
SetNewAdmin(ParsedSetNewAdminInstruction),
SetPausedForAsset(ParsedSetPausedForAssetInstruction),
SetPausedForLpStableConfig(ParsedSetPausedForLpStableConfigInstruction),
Swap(ParsedSwapInstruction),
UpdateAssetConfigAccount(ParsedUpdateAssetConfigAccountInstruction),
UpdateGlobalConfig(ParsedUpdateGlobalConfigInstruction),
UpdatePair(ParsedUpdatePairInstruction),
}
pub fn parse_instruction(instruction: &Instruction) -> std::io::Result<ParsedInstruction> {
match identify_instruction(&instruction.data)? {
InstructionKind::AddLiquidity => Ok(ParsedInstruction::AddLiquidity(parse_add_liquidity_instruction(instruction)?)),
InstructionKind::ClaimFees => Ok(ParsedInstruction::ClaimFees(parse_claim_fees_instruction(instruction)?)),
InstructionKind::CloseLpFeeAccount => Ok(ParsedInstruction::CloseLpFeeAccount(parse_close_lp_fee_account_instruction(instruction)?)),
InstructionKind::ClosePair => Ok(ParsedInstruction::ClosePair(parse_close_pair_instruction(instruction)?)),
InstructionKind::CloseTreasuryPosition => Ok(ParsedInstruction::CloseTreasuryPosition(parse_close_treasury_position_instruction(instruction)?)),
InstructionKind::ConfirmNewAdmin => Ok(ParsedInstruction::ConfirmNewAdmin(parse_confirm_new_admin_instruction(instruction)?)),
InstructionKind::InitAssetConfigAccount => Ok(ParsedInstruction::InitAssetConfigAccount(parse_init_asset_config_account_instruction(instruction)?)),
InstructionKind::InitGlobalConfig => Ok(ParsedInstruction::InitGlobalConfig(parse_init_global_config_instruction(instruction)?)),
InstructionKind::InitPair => Ok(ParsedInstruction::InitPair(parse_init_pair_instruction(instruction)?)),
InstructionKind::RemoveLiquidity => Ok(ParsedInstruction::RemoveLiquidity(parse_remove_liquidity_instruction(instruction)?)),
InstructionKind::SetLpProtocolFeeConfig => Ok(ParsedInstruction::SetLpProtocolFeeConfig(parse_set_lp_protocol_fee_config_instruction(instruction)?)),
InstructionKind::SetLpTreasuryEnabled => Ok(ParsedInstruction::SetLpTreasuryEnabled(parse_set_lp_treasury_enabled_instruction(instruction)?)),
InstructionKind::SetNewAdmin => Ok(ParsedInstruction::SetNewAdmin(parse_set_new_admin_instruction(instruction)?)),
InstructionKind::SetPausedForAsset => Ok(ParsedInstruction::SetPausedForAsset(parse_set_paused_for_asset_instruction(instruction)?)),
InstructionKind::SetPausedForLpStableConfig => Ok(ParsedInstruction::SetPausedForLpStableConfig(parse_set_paused_for_lp_stable_config_instruction(instruction)?)),
InstructionKind::Swap => Ok(ParsedInstruction::Swap(parse_swap_instruction(instruction)?)),
InstructionKind::UpdateAssetConfigAccount => Ok(ParsedInstruction::UpdateAssetConfigAccount(parse_update_asset_config_account_instruction(instruction)?)),
InstructionKind::UpdateGlobalConfig => Ok(ParsedInstruction::UpdateGlobalConfig(parse_update_global_config_instruction(instruction)?)),
InstructionKind::UpdatePair => Ok(ParsedInstruction::UpdatePair(parse_update_pair_instruction(instruction)?)),
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccountKind {
AssetConfig,
GlobalConfig,
LpProtocolFeeConfig,
LpStableConfig,
Pair,
UserVaultInfo,
}
pub const ACCOUNT_DISCRIMINATORS: &[(&str, [u8; 8])] = &[
("AssetConfig", AssetConfig::DISCRIMINATOR),
("GlobalConfig", GlobalConfig::DISCRIMINATOR),
("LpProtocolFeeConfig", LpProtocolFeeConfig::DISCRIMINATOR),
("LpStableConfig", LpStableConfig::DISCRIMINATOR),
("Pair", Pair::DISCRIMINATOR),
("UserVaultInfo", UserVaultInfo::DISCRIMINATOR),
];
pub fn identify_account(data: &[u8]) -> std::io::Result<AccountKind> {
match super::discriminator(data)? {
AssetConfig::DISCRIMINATOR => Ok(AccountKind::AssetConfig),
GlobalConfig::DISCRIMINATOR => Ok(AccountKind::GlobalConfig),
LpProtocolFeeConfig::DISCRIMINATOR => Ok(AccountKind::LpProtocolFeeConfig),
LpStableConfig::DISCRIMINATOR => Ok(AccountKind::LpStableConfig),
Pair::DISCRIMINATOR => Ok(AccountKind::Pair),
UserVaultInfo::DISCRIMINATOR => Ok(AccountKind::UserVaultInfo),
_ => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Unknown account discriminator")),
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Account {
AssetConfig(AssetConfig),
GlobalConfig(GlobalConfig),
LpProtocolFeeConfig(LpProtocolFeeConfig),
LpStableConfig(LpStableConfig),
Pair(Pair),
UserVaultInfo(UserVaultInfo),
}
impl Account {
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
match identify_account(data)? {
AccountKind::AssetConfig => Ok(Self::AssetConfig(AssetConfig::decode(data)?)),
AccountKind::GlobalConfig => Ok(Self::GlobalConfig(GlobalConfig::decode(data)?)),
AccountKind::LpProtocolFeeConfig => Ok(Self::LpProtocolFeeConfig(LpProtocolFeeConfig::decode(data)?)),
AccountKind::LpStableConfig => Ok(Self::LpStableConfig(LpStableConfig::decode(data)?)),
AccountKind::Pair => Ok(Self::Pair(Pair::decode(data)?)),
AccountKind::UserVaultInfo => Ok(Self::UserVaultInfo(UserVaultInfo::decode(data)?)),
}
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
match self {
Self::AssetConfig(value) => value.encode(),
Self::GlobalConfig(value) => value.encode(),
Self::LpProtocolFeeConfig(value) => value.encode(),
Self::LpStableConfig(value) => value.encode(),
Self::Pair(value) => value.encode(),
Self::UserVaultInfo(value) => value.encode(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EventKind {
AdminChanged,
AssetConfigInitialized,
AssetConfigUpdated,
AssetPauseChanged,
FeesClaimed,
GlobalConfigInitialized,
GlobalConfigUpdated,
LiquidityAdded,
LiquidityRemoved,
LpFeeAccountClosed,
LpProtocolFeeConfigUpdated,
LpStableConfigPauseChanged,
LpTreasuryEnabledChanged,
NewAdminProposed,
PairClosed,
PairInitialized,
PairUpdated,
SwapExecuted,
TreasuryPositionClosed,
}
pub const EVENT_DISCRIMINATORS: &[(&str, [u8; 8])] = &[
("AdminChanged", AdminChanged::DISCRIMINATOR),
("AssetConfigInitialized", AssetConfigInitialized::DISCRIMINATOR),
("AssetConfigUpdated", AssetConfigUpdated::DISCRIMINATOR),
("AssetPauseChanged", AssetPauseChanged::DISCRIMINATOR),
("FeesClaimed", FeesClaimed::DISCRIMINATOR),
("GlobalConfigInitialized", GlobalConfigInitialized::DISCRIMINATOR),
("GlobalConfigUpdated", GlobalConfigUpdated::DISCRIMINATOR),
("LiquidityAdded", LiquidityAdded::DISCRIMINATOR),
("LiquidityRemoved", LiquidityRemoved::DISCRIMINATOR),
("LpFeeAccountClosed", LpFeeAccountClosed::DISCRIMINATOR),
("LpProtocolFeeConfigUpdated", LpProtocolFeeConfigUpdated::DISCRIMINATOR),
("LpStableConfigPauseChanged", LpStableConfigPauseChanged::DISCRIMINATOR),
("LpTreasuryEnabledChanged", LpTreasuryEnabledChanged::DISCRIMINATOR),
("NewAdminProposed", NewAdminProposed::DISCRIMINATOR),
("PairClosed", PairClosed::DISCRIMINATOR),
("PairInitialized", PairInitialized::DISCRIMINATOR),
("PairUpdated", PairUpdated::DISCRIMINATOR),
("SwapExecuted", SwapExecuted::DISCRIMINATOR),
("TreasuryPositionClosed", TreasuryPositionClosed::DISCRIMINATOR),
];
pub fn identify_event(data: &[u8]) -> std::io::Result<EventKind> {
match super::discriminator(data)? {
AdminChanged::DISCRIMINATOR => Ok(EventKind::AdminChanged),
AssetConfigInitialized::DISCRIMINATOR => Ok(EventKind::AssetConfigInitialized),
AssetConfigUpdated::DISCRIMINATOR => Ok(EventKind::AssetConfigUpdated),
AssetPauseChanged::DISCRIMINATOR => Ok(EventKind::AssetPauseChanged),
FeesClaimed::DISCRIMINATOR => Ok(EventKind::FeesClaimed),
GlobalConfigInitialized::DISCRIMINATOR => Ok(EventKind::GlobalConfigInitialized),
GlobalConfigUpdated::DISCRIMINATOR => Ok(EventKind::GlobalConfigUpdated),
LiquidityAdded::DISCRIMINATOR => Ok(EventKind::LiquidityAdded),
LiquidityRemoved::DISCRIMINATOR => Ok(EventKind::LiquidityRemoved),
LpFeeAccountClosed::DISCRIMINATOR => Ok(EventKind::LpFeeAccountClosed),
LpProtocolFeeConfigUpdated::DISCRIMINATOR => Ok(EventKind::LpProtocolFeeConfigUpdated),
LpStableConfigPauseChanged::DISCRIMINATOR => Ok(EventKind::LpStableConfigPauseChanged),
LpTreasuryEnabledChanged::DISCRIMINATOR => Ok(EventKind::LpTreasuryEnabledChanged),
NewAdminProposed::DISCRIMINATOR => Ok(EventKind::NewAdminProposed),
PairClosed::DISCRIMINATOR => Ok(EventKind::PairClosed),
PairInitialized::DISCRIMINATOR => Ok(EventKind::PairInitialized),
PairUpdated::DISCRIMINATOR => Ok(EventKind::PairUpdated),
SwapExecuted::DISCRIMINATOR => Ok(EventKind::SwapExecuted),
TreasuryPositionClosed::DISCRIMINATOR => Ok(EventKind::TreasuryPositionClosed),
_ => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Unknown event discriminator")),
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
AdminChanged(AdminChanged),
AssetConfigInitialized(AssetConfigInitialized),
AssetConfigUpdated(AssetConfigUpdated),
AssetPauseChanged(AssetPauseChanged),
FeesClaimed(FeesClaimed),
GlobalConfigInitialized(GlobalConfigInitialized),
GlobalConfigUpdated(GlobalConfigUpdated),
LiquidityAdded(LiquidityAdded),
LiquidityRemoved(LiquidityRemoved),
LpFeeAccountClosed(LpFeeAccountClosed),
LpProtocolFeeConfigUpdated(LpProtocolFeeConfigUpdated),
LpStableConfigPauseChanged(LpStableConfigPauseChanged),
LpTreasuryEnabledChanged(LpTreasuryEnabledChanged),
NewAdminProposed(NewAdminProposed),
PairClosed(PairClosed),
PairInitialized(PairInitialized),
PairUpdated(PairUpdated),
SwapExecuted(SwapExecuted),
TreasuryPositionClosed(TreasuryPositionClosed),
}
impl Event {
pub fn decode(data: &[u8]) -> std::io::Result<Self> {
match identify_event(data)? {
EventKind::AdminChanged => Ok(Self::AdminChanged(AdminChanged::decode(data)?)),
EventKind::AssetConfigInitialized => Ok(Self::AssetConfigInitialized(AssetConfigInitialized::decode(data)?)),
EventKind::AssetConfigUpdated => Ok(Self::AssetConfigUpdated(AssetConfigUpdated::decode(data)?)),
EventKind::AssetPauseChanged => Ok(Self::AssetPauseChanged(AssetPauseChanged::decode(data)?)),
EventKind::FeesClaimed => Ok(Self::FeesClaimed(FeesClaimed::decode(data)?)),
EventKind::GlobalConfigInitialized => Ok(Self::GlobalConfigInitialized(GlobalConfigInitialized::decode(data)?)),
EventKind::GlobalConfigUpdated => Ok(Self::GlobalConfigUpdated(GlobalConfigUpdated::decode(data)?)),
EventKind::LiquidityAdded => Ok(Self::LiquidityAdded(LiquidityAdded::decode(data)?)),
EventKind::LiquidityRemoved => Ok(Self::LiquidityRemoved(LiquidityRemoved::decode(data)?)),
EventKind::LpFeeAccountClosed => Ok(Self::LpFeeAccountClosed(LpFeeAccountClosed::decode(data)?)),
EventKind::LpProtocolFeeConfigUpdated => Ok(Self::LpProtocolFeeConfigUpdated(LpProtocolFeeConfigUpdated::decode(data)?)),
EventKind::LpStableConfigPauseChanged => Ok(Self::LpStableConfigPauseChanged(LpStableConfigPauseChanged::decode(data)?)),
EventKind::LpTreasuryEnabledChanged => Ok(Self::LpTreasuryEnabledChanged(LpTreasuryEnabledChanged::decode(data)?)),
EventKind::NewAdminProposed => Ok(Self::NewAdminProposed(NewAdminProposed::decode(data)?)),
EventKind::PairClosed => Ok(Self::PairClosed(PairClosed::decode(data)?)),
EventKind::PairInitialized => Ok(Self::PairInitialized(PairInitialized::decode(data)?)),
EventKind::PairUpdated => Ok(Self::PairUpdated(PairUpdated::decode(data)?)),
EventKind::SwapExecuted => Ok(Self::SwapExecuted(SwapExecuted::decode(data)?)),
EventKind::TreasuryPositionClosed => Ok(Self::TreasuryPositionClosed(TreasuryPositionClosed::decode(data)?)),
}
}
pub fn encode(&self) -> std::io::Result<Vec<u8>> {
match self {
Self::AdminChanged(value) => value.encode(),
Self::AssetConfigInitialized(value) => value.encode(),
Self::AssetConfigUpdated(value) => value.encode(),
Self::AssetPauseChanged(value) => value.encode(),
Self::FeesClaimed(value) => value.encode(),
Self::GlobalConfigInitialized(value) => value.encode(),
Self::GlobalConfigUpdated(value) => value.encode(),
Self::LiquidityAdded(value) => value.encode(),
Self::LiquidityRemoved(value) => value.encode(),
Self::LpFeeAccountClosed(value) => value.encode(),
Self::LpProtocolFeeConfigUpdated(value) => value.encode(),
Self::LpStableConfigPauseChanged(value) => value.encode(),
Self::LpTreasuryEnabledChanged(value) => value.encode(),
Self::NewAdminProposed(value) => value.encode(),
Self::PairClosed(value) => value.encode(),
Self::PairInitialized(value) => value.encode(),
Self::PairUpdated(value) => value.encode(),
Self::SwapExecuted(value) => value.encode(),
Self::TreasuryPositionClosed(value) => value.encode(),
}
}
}
pub const ERRORS: &[super::ProgramErrorMetadata] = &[
super::ProgramErrorMetadata { code: 6000, name: "InvalidNav", message: "Invalid NAV" },
super::ProgramErrorMetadata { code: 6001, name: "ConfidenceTooLow", message: "Confidence too low" },
super::ProgramErrorMetadata { code: 6002, name: "OutOfRange", message: "Out of range" },
super::ProgramErrorMetadata { code: 6003, name: "MustProvideAtLeastOneNavData", message: "Must provide at least one NAV data" },
super::ProgramErrorMetadata { code: 6004, name: "MustProvideHardcodedPrice", message: "Must provide hardcoded price" },
super::ProgramErrorMetadata { code: 6005, name: "ProgramPaused", message: "Program paused" },
super::ProgramErrorMetadata { code: 6006, name: "AmountMustBePositive", message: "Amount must be positive" },
super::ProgramErrorMetadata { code: 6007, name: "InsufficientLiquidity", message: "Insufficient liquidity" },
super::ProgramErrorMetadata { code: 6008, name: "PairPaused", message: "Pair paused" },
super::ProgramErrorMetadata { code: 6009, name: "RwaPaused", message: "RWA paused" },
super::ProgramErrorMetadata { code: 6010, name: "StablePaused", message: "Stable paused" },
super::ProgramErrorMetadata { code: 6011, name: "Max5NavData", message: "Max 5 NAV data" },
super::ProgramErrorMetadata { code: 6012, name: "SwapAmountTooSmall", message: "Swap amount too small" },
super::ProgramErrorMetadata { code: 6013, name: "DiscountMustBePositive", message: "Discount must be positive" },
super::ProgramErrorMetadata { code: 6014, name: "AmountInMustBePositive", message: "Amount in must be positive" },
super::ProgramErrorMetadata { code: 6015, name: "AmountOutMustBePositive", message: "Amount out must be positive" },
super::ProgramErrorMetadata { code: 6016, name: "PriceDecimalsTooLarge", message: "Price decimals too large" },
super::ProgramErrorMetadata { code: 6017, name: "Unauthorized", message: "Unauthorized" },
super::ProgramErrorMetadata { code: 6018, name: "MathOverflow", message: "Math Overflow" },
super::ProgramErrorMetadata { code: 6019, name: "MathUnderflow", message: "Math Underflow" },
super::ProgramErrorMetadata { code: 6020, name: "InvalidAssetType", message: "Invalid asset type" },
super::ProgramErrorMetadata { code: 6021, name: "NavMustBePositive", message: "Nav must be positive" },
super::ProgramErrorMetadata { code: 6022, name: "FeesOutOfRange", message: "Fees out of range" },
super::ProgramErrorMetadata { code: 6023, name: "AssetConfigInUse", message: "Asset config in use" },
super::ProgramErrorMetadata { code: 6024, name: "InvalidNewAdmin", message: "Invalid new admin" },
super::ProgramErrorMetadata { code: 6025, name: "InvalidAccountPublicKey", message: "Invalid account public key" },
super::ProgramErrorMetadata { code: 6026, name: "AmountInTooHigh", message: "Amount in too high" },
super::ProgramErrorMetadata { code: 6027, name: "AmountOutTooLow", message: "Amount out too low" },
super::ProgramErrorMetadata { code: 6028, name: "InsufficientLpFeeBalance", message: "Insufficient LP fee balance" },
super::ProgramErrorMetadata { code: 6029, name: "InvalidFeedId", message: "Invalid pyth feed id" },
super::ProgramErrorMetadata { code: 6030, name: "InvalidMaxAge", message: "Pyth max age must be > 0" },
super::ProgramErrorMetadata { code: 6031, name: "MaxAgeTooLarge", message: "Pyth max age too high" },
super::ProgramErrorMetadata { code: 6032, name: "ConfBpsTooLarge", message: "Pyth max conf too high" },
super::ProgramErrorMetadata { code: 6033, name: "MissingPythAccount", message: "Pyth feed missing from remaining accounts" },
super::ProgramErrorMetadata { code: 6034, name: "FeedIdMismatch", message: "Pyth feed mismatch" },
super::ProgramErrorMetadata { code: 6035, name: "MissingTreasuryAccounts", message: "Missing treasury accounts" },
super::ProgramErrorMetadata { code: 6036, name: "InvalidTreasuryProgram", message: "Invalid treasury program" },
super::ProgramErrorMetadata { code: 6037, name: "TreasuryBalanceNonZero", message: "Treasury balance is non-zero" },
super::ProgramErrorMetadata { code: 6038, name: "MissingLpStableConfig", message: "LP stable config must be provided for stable tokens" },
super::ProgramErrorMetadata { code: 6039, name: "NonCanonicalTokenOrder", message: "Quote mint must be lexicographically less than base mint" },
super::ProgramErrorMetadata { code: 6040, name: "InvalidTreasuryMint", message: "Invalid treasury mint" },
super::ProgramErrorMetadata { code: 6041, name: "TransferFeeNotSupported", message: "Mints charging a Token-2022 transfer fee are not supported" },
super::ProgramErrorMetadata { code: 6042, name: "InvalidTokenExtensionData", message: "Token-2022 extension data could not be decoded" },
super::ProgramErrorMetadata { code: 6043, name: "UnauthorizedInitializer", message: "Caller must be the program upgrade authority" },
super::ProgramErrorMetadata { code: 6044, name: "LpVaultAuthorityUnderfunded", message: "LP vault authority has insufficient SOL to fund the treasury position rent" },
super::ProgramErrorMetadata { code: 6045, name: "FeeAssetPaused", message: "Protocol fee asset paused" },
super::ProgramErrorMetadata { code: 6046, name: "SignerInRemainingAccounts", message: "Remaining accounts must not contain signers" },
];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum ProgramError {
InvalidNav = 6000,
ConfidenceTooLow = 6001,
OutOfRange = 6002,
MustProvideAtLeastOneNavData = 6003,
MustProvideHardcodedPrice = 6004,
ProgramPaused = 6005,
AmountMustBePositive = 6006,
InsufficientLiquidity = 6007,
PairPaused = 6008,
RwaPaused = 6009,
StablePaused = 6010,
Max5NavData = 6011,
SwapAmountTooSmall = 6012,
DiscountMustBePositive = 6013,
AmountInMustBePositive = 6014,
AmountOutMustBePositive = 6015,
PriceDecimalsTooLarge = 6016,
Unauthorized = 6017,
MathOverflow = 6018,
MathUnderflow = 6019,
InvalidAssetType = 6020,
NavMustBePositive = 6021,
FeesOutOfRange = 6022,
AssetConfigInUse = 6023,
InvalidNewAdmin = 6024,
InvalidAccountPublicKey = 6025,
AmountInTooHigh = 6026,
AmountOutTooLow = 6027,
InsufficientLpFeeBalance = 6028,
InvalidFeedId = 6029,
InvalidMaxAge = 6030,
MaxAgeTooLarge = 6031,
ConfBpsTooLarge = 6032,
MissingPythAccount = 6033,
FeedIdMismatch = 6034,
MissingTreasuryAccounts = 6035,
InvalidTreasuryProgram = 6036,
TreasuryBalanceNonZero = 6037,
MissingLpStableConfig = 6038,
NonCanonicalTokenOrder = 6039,
InvalidTreasuryMint = 6040,
TransferFeeNotSupported = 6041,
InvalidTokenExtensionData = 6042,
UnauthorizedInitializer = 6043,
LpVaultAuthorityUnderfunded = 6044,
FeeAssetPaused = 6045,
SignerInRemainingAccounts = 6046,
}
impl ProgramError {
pub const fn from_code(code: u32) -> Option<Self> {
match code {
6000 => Some(Self::InvalidNav),
6001 => Some(Self::ConfidenceTooLow),
6002 => Some(Self::OutOfRange),
6003 => Some(Self::MustProvideAtLeastOneNavData),
6004 => Some(Self::MustProvideHardcodedPrice),
6005 => Some(Self::ProgramPaused),
6006 => Some(Self::AmountMustBePositive),
6007 => Some(Self::InsufficientLiquidity),
6008 => Some(Self::PairPaused),
6009 => Some(Self::RwaPaused),
6010 => Some(Self::StablePaused),
6011 => Some(Self::Max5NavData),
6012 => Some(Self::SwapAmountTooSmall),
6013 => Some(Self::DiscountMustBePositive),
6014 => Some(Self::AmountInMustBePositive),
6015 => Some(Self::AmountOutMustBePositive),
6016 => Some(Self::PriceDecimalsTooLarge),
6017 => Some(Self::Unauthorized),
6018 => Some(Self::MathOverflow),
6019 => Some(Self::MathUnderflow),
6020 => Some(Self::InvalidAssetType),
6021 => Some(Self::NavMustBePositive),
6022 => Some(Self::FeesOutOfRange),
6023 => Some(Self::AssetConfigInUse),
6024 => Some(Self::InvalidNewAdmin),
6025 => Some(Self::InvalidAccountPublicKey),
6026 => Some(Self::AmountInTooHigh),
6027 => Some(Self::AmountOutTooLow),
6028 => Some(Self::InsufficientLpFeeBalance),
6029 => Some(Self::InvalidFeedId),
6030 => Some(Self::InvalidMaxAge),
6031 => Some(Self::MaxAgeTooLarge),
6032 => Some(Self::ConfBpsTooLarge),
6033 => Some(Self::MissingPythAccount),
6034 => Some(Self::FeedIdMismatch),
6035 => Some(Self::MissingTreasuryAccounts),
6036 => Some(Self::InvalidTreasuryProgram),
6037 => Some(Self::TreasuryBalanceNonZero),
6038 => Some(Self::MissingLpStableConfig),
6039 => Some(Self::NonCanonicalTokenOrder),
6040 => Some(Self::InvalidTreasuryMint),
6041 => Some(Self::TransferFeeNotSupported),
6042 => Some(Self::InvalidTokenExtensionData),
6043 => Some(Self::UnauthorizedInitializer),
6044 => Some(Self::LpVaultAuthorityUnderfunded),
6045 => Some(Self::FeeAssetPaused),
6046 => Some(Self::SignerInRemainingAccounts),
_ => None,
}
}
pub const fn code(self) -> u32 { self as u32 }
pub const fn name(self) -> &'static str {
match self {
Self::InvalidNav => "InvalidNav",
Self::ConfidenceTooLow => "ConfidenceTooLow",
Self::OutOfRange => "OutOfRange",
Self::MustProvideAtLeastOneNavData => "MustProvideAtLeastOneNavData",
Self::MustProvideHardcodedPrice => "MustProvideHardcodedPrice",
Self::ProgramPaused => "ProgramPaused",
Self::AmountMustBePositive => "AmountMustBePositive",
Self::InsufficientLiquidity => "InsufficientLiquidity",
Self::PairPaused => "PairPaused",
Self::RwaPaused => "RwaPaused",
Self::StablePaused => "StablePaused",
Self::Max5NavData => "Max5NavData",
Self::SwapAmountTooSmall => "SwapAmountTooSmall",
Self::DiscountMustBePositive => "DiscountMustBePositive",
Self::AmountInMustBePositive => "AmountInMustBePositive",
Self::AmountOutMustBePositive => "AmountOutMustBePositive",
Self::PriceDecimalsTooLarge => "PriceDecimalsTooLarge",
Self::Unauthorized => "Unauthorized",
Self::MathOverflow => "MathOverflow",
Self::MathUnderflow => "MathUnderflow",
Self::InvalidAssetType => "InvalidAssetType",
Self::NavMustBePositive => "NavMustBePositive",
Self::FeesOutOfRange => "FeesOutOfRange",
Self::AssetConfigInUse => "AssetConfigInUse",
Self::InvalidNewAdmin => "InvalidNewAdmin",
Self::InvalidAccountPublicKey => "InvalidAccountPublicKey",
Self::AmountInTooHigh => "AmountInTooHigh",
Self::AmountOutTooLow => "AmountOutTooLow",
Self::InsufficientLpFeeBalance => "InsufficientLpFeeBalance",
Self::InvalidFeedId => "InvalidFeedId",
Self::InvalidMaxAge => "InvalidMaxAge",
Self::MaxAgeTooLarge => "MaxAgeTooLarge",
Self::ConfBpsTooLarge => "ConfBpsTooLarge",
Self::MissingPythAccount => "MissingPythAccount",
Self::FeedIdMismatch => "FeedIdMismatch",
Self::MissingTreasuryAccounts => "MissingTreasuryAccounts",
Self::InvalidTreasuryProgram => "InvalidTreasuryProgram",
Self::TreasuryBalanceNonZero => "TreasuryBalanceNonZero",
Self::MissingLpStableConfig => "MissingLpStableConfig",
Self::NonCanonicalTokenOrder => "NonCanonicalTokenOrder",
Self::InvalidTreasuryMint => "InvalidTreasuryMint",
Self::TransferFeeNotSupported => "TransferFeeNotSupported",
Self::InvalidTokenExtensionData => "InvalidTokenExtensionData",
Self::UnauthorizedInitializer => "UnauthorizedInitializer",
Self::LpVaultAuthorityUnderfunded => "LpVaultAuthorityUnderfunded",
Self::FeeAssetPaused => "FeeAssetPaused",
Self::SignerInRemainingAccounts => "SignerInRemainingAccounts",
}
}
pub const fn message(self) -> &'static str {
match self {
Self::InvalidNav => "Invalid NAV",
Self::ConfidenceTooLow => "Confidence too low",
Self::OutOfRange => "Out of range",
Self::MustProvideAtLeastOneNavData => "Must provide at least one NAV data",
Self::MustProvideHardcodedPrice => "Must provide hardcoded price",
Self::ProgramPaused => "Program paused",
Self::AmountMustBePositive => "Amount must be positive",
Self::InsufficientLiquidity => "Insufficient liquidity",
Self::PairPaused => "Pair paused",
Self::RwaPaused => "RWA paused",
Self::StablePaused => "Stable paused",
Self::Max5NavData => "Max 5 NAV data",
Self::SwapAmountTooSmall => "Swap amount too small",
Self::DiscountMustBePositive => "Discount must be positive",
Self::AmountInMustBePositive => "Amount in must be positive",
Self::AmountOutMustBePositive => "Amount out must be positive",
Self::PriceDecimalsTooLarge => "Price decimals too large",
Self::Unauthorized => "Unauthorized",
Self::MathOverflow => "Math Overflow",
Self::MathUnderflow => "Math Underflow",
Self::InvalidAssetType => "Invalid asset type",
Self::NavMustBePositive => "Nav must be positive",
Self::FeesOutOfRange => "Fees out of range",
Self::AssetConfigInUse => "Asset config in use",
Self::InvalidNewAdmin => "Invalid new admin",
Self::InvalidAccountPublicKey => "Invalid account public key",
Self::AmountInTooHigh => "Amount in too high",
Self::AmountOutTooLow => "Amount out too low",
Self::InsufficientLpFeeBalance => "Insufficient LP fee balance",
Self::InvalidFeedId => "Invalid pyth feed id",
Self::InvalidMaxAge => "Pyth max age must be > 0",
Self::MaxAgeTooLarge => "Pyth max age too high",
Self::ConfBpsTooLarge => "Pyth max conf too high",
Self::MissingPythAccount => "Pyth feed missing from remaining accounts",
Self::FeedIdMismatch => "Pyth feed mismatch",
Self::MissingTreasuryAccounts => "Missing treasury accounts",
Self::InvalidTreasuryProgram => "Invalid treasury program",
Self::TreasuryBalanceNonZero => "Treasury balance is non-zero",
Self::MissingLpStableConfig => "LP stable config must be provided for stable tokens",
Self::NonCanonicalTokenOrder => "Quote mint must be lexicographically less than base mint",
Self::InvalidTreasuryMint => "Invalid treasury mint",
Self::TransferFeeNotSupported => "Mints charging a Token-2022 transfer fee are not supported",
Self::InvalidTokenExtensionData => "Token-2022 extension data could not be decoded",
Self::UnauthorizedInitializer => "Caller must be the program upgrade authority",
Self::LpVaultAuthorityUnderfunded => "LP vault authority has insufficient SOL to fund the treasury position rent",
Self::FeeAssetPaused => "Protocol fee asset paused",
Self::SignerInRemainingAccounts => "Remaining accounts must not contain signers",
}
}
}
impl std::fmt::Display for ProgramError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.message())
}
}
impl std::error::Error for ProgramError {}