Created
January 24, 2025 01:42
-
-
Save dehypnosis/d9abb1a95692c8e609e66657b4447aea to your computer and use it in GitHub Desktop.
NSOL pool account deserialization example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anchor_lang::{AnchorDeserialize, Discriminator}; | |
use solana_sdk::pubkey::Pubkey; | |
use solana_sdk::pubkey; | |
use solana_client::nonblocking::rpc_client::RpcClient; | |
const ID: Pubkey = pubkey!("fragnAis7Bp6FTsMoa6YcH8UffhEw43Ph79qAiK3iF3"); | |
const NSOL_POOL: Pubkey = pubkey!("AkbZvKxUAxMKz92FF7g5k2YLCJftg8SnYEPWdmZTt3mp"); | |
const NSOL_POOL_DISCRIMINATOR: [u8; 8] = [7, 113, 233, 177, 153, 66, 175, 56]; | |
#[derive(AnchorDeserialize, Clone, Debug)] | |
pub enum Asset { | |
SOL(u64), | |
Token(Pubkey, Option<[u8; 33]>, u64), | |
} | |
#[derive(AnchorDeserialize, Clone, Debug)] | |
pub struct TokenValue { | |
pub numerator: Vec<Asset>, | |
pub denominator: u64, | |
} | |
#[derive(AnchorDeserialize, Clone, Debug)] | |
pub struct NormalizedSupportedToken { | |
pub mint: Pubkey, | |
pub program: Pubkey, | |
pub lock_account: Pubkey, | |
pub locked_amount: u64, | |
pub decimals: u8, | |
pub withdrawal_reserved_amount: u64, | |
pub one_token_as_sol: u64, | |
pub pricing_source: [u8; 33], | |
pub reserved: [u8; 14], | |
} | |
#[derive(AnchorDeserialize, Clone, Debug)] | |
pub struct NormalizedTokenPoolAccount { | |
pub data_version: u16, | |
pub bump: u8, | |
pub normalized_token_mint: Pubkey, | |
pub normalized_token_program: Pubkey, | |
pub supported_tokens: Vec<NormalizedSupportedToken>, | |
pub normalized_token_decimals: u8, | |
pub normalized_token_supply_amount: u64, | |
pub normalized_token_value: TokenValue, | |
pub normalized_token_value_updated_slot: u64, | |
pub one_normalized_token_as_sol: u64, | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[tokio::test] | |
async fn test_simulate_nsol_redemption() { | |
let client = RpcClient::new("https://api.mainnet-beta.solana.com".to_string()); | |
let mut data = client.get_account(&NSOL_POOL).await.unwrap().data; | |
assert_eq!(data[..8], NSOL_POOL_DISCRIMINATOR[..]); | |
let ntp = NormalizedTokenPoolAccount::deserialize(&mut &data[8..]).unwrap(); | |
println!("{:?}", ntp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment