solana_central/meteora/
update_meteora_vaultinfo.rs

1use crate::CentralContext;
2use crate::types::meteora_vault::MeteoraVault;
3use borsh::BorshDeserialize;
4use solana_sdk::account::ReadableAccount;
5use std::sync::Arc;
6use crate::protocol_idls::meteora::{VaultIdlBig, VaultIdlSmall};
7
8impl MeteoraVault {
9  /// Update vault information from on-chain account data
10  ///
11  /// Fetches the vault account and updates all vault state including locked profit
12  /// tracker, total amount, and LP token supply. Supports both big (10240 bytes)
13  /// and small (1232 bytes) vault account formats.
14  pub fn update_vault_info(&mut self, central_context: Arc<CentralContext>) {
15    let vault_address = self.vault;
16    let binding = central_context
17      .json_rpc_client
18      .get_account(&vault_address)
19      .unwrap();
20    let vault_data = binding.data();
21
22    // if it is a big vault and the data length is 10240, then we need to use the big vault idl
23    if vault_data.len() == 10240 {
24      let decoded = VaultIdlBig::try_from_slice(&vault_data).unwrap();
25
26      self.last_updated_locked_profit = decoded.locked_profit_tracker.last_updated_locked_profit;
27      self.last_report = decoded.locked_profit_tracker.last_report;
28      self.locked_profit_degradation = decoded.locked_profit_tracker.locked_profit_degradation;
29      self.total_amount = decoded.total_amount;
30      /*
31      There are some cases where if you deterministically derive a popular token like USDC or USDT or
32      WSOL then the actual address will be different. In this case, lookup the actual address.
33      */
34      self.lp_token_address = decoded.lp_mint;
35      self.lp_supply = central_context
36        .json_rpc_client
37        .get_token_supply(&decoded.lp_mint)
38        .unwrap()
39        .amount
40        .parse()
41        .unwrap();
42    } else if vault_data.len() == 1232 {
43      let decoded = VaultIdlSmall::try_from_slice(&vault_data).unwrap();
44
45      self.last_updated_locked_profit = decoded.locked_profit_tracker.last_updated_locked_profit;
46      self.last_report = decoded.locked_profit_tracker.last_report;
47      self.locked_profit_degradation = decoded.locked_profit_tracker.locked_profit_degradation;
48      self.total_amount = decoded.total_amount;
49      /*
50      There are some cases where if you deterministically derive a popular token like USDC or USDT or
51      WSOL then the actual address will be different. In this case, lookup the actual address.
52      */
53      self.lp_token_address = decoded.lp_mint;
54      self.lp_supply = central_context
55        .json_rpc_client
56        .get_token_supply(&decoded.lp_mint)
57        .unwrap()
58        .amount
59        .parse()
60        .unwrap();
61    } else {
62      println!(
63        "update_meteora_vaultinfo: Unknown vault data length for vault: {:?}",
64        vault_address
65      );
66    }
67  }
68}