Skip to content

Commit 7783c5d

Browse files
committed
feat: add meteora vault decoder
1 parent e605efb commit 7783c5d

37 files changed

+1044
-0
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Decoders for most popular Solana programs are published and maintained:
255255
| `carbon-meteora-damm-v2-decoder` | Meteora DAMM V2 Program Decoder | cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG |
256256
| `carbon-meteora-dlmm-decoder` | Meteora DLMM Program Decoder | LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo |
257257
| `carbon-meteora-pools-decoder` | Meteora Pools Program Decoder | Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB |
258+
| `carbon-meteora-vault-decoder` | Meteora Vault Program Decoder | 24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi |
258259
| `carbon-moonshot-decoder` | Moonshot Program Decoder | MoonCVVNZFSYkqNXP6bxHLPL6QQJiMagDL3qcqUQTrG |
259260
| `carbon-mpl-core-decoder` | MPL Core Program Decoder | CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d |
260261
| `carbon-mpl-token-metadata-decoder` | MPL Token Metadata Program Decoder | metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "carbon-meteora-vault-decoder"
3+
version = "0.1.0"
4+
description = "Meteora vault program decoder"
5+
edition = { workspace = true }
6+
license = { workspace = true }
7+
readme = "README.md"
8+
keywords = ["solana", "decoder", "meteora"]
9+
categories = ["encoding"]
10+
11+
[lib]
12+
crate-type = ["rlib"]
13+
14+
[dependencies]
15+
carbon-core = { workspace = true }
16+
serde = { workspace = true }
17+
solana-account = { workspace = true }
18+
solana-instruction = { workspace = true, default-features = false }
19+
solana-pubkey = { workspace = true }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Carbon Meteora Vault Program Decoder
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use {
2+
super::MeteoraVaultDecoder,
3+
crate::PROGRAM_ID,
4+
carbon_core::{account::AccountDecoder, deserialize::CarbonDeserialize},
5+
};
6+
pub mod strategy;
7+
pub mod vault;
8+
9+
#[allow(clippy::large_enum_variant)]
10+
pub enum MeteoraVaultAccount {
11+
Vault(vault::Vault),
12+
Strategy(strategy::Strategy),
13+
}
14+
15+
impl AccountDecoder<'_> for MeteoraVaultDecoder {
16+
type AccountType = MeteoraVaultAccount;
17+
fn decode_account(
18+
&self,
19+
account: &solana_account::Account,
20+
) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
21+
if !account.owner.eq(&PROGRAM_ID) {
22+
return None;
23+
}
24+
25+
if let Some(decoded_account) = vault::Vault::deserialize(account.data.as_slice()) {
26+
return Some(carbon_core::account::DecodedAccount {
27+
lamports: account.lamports,
28+
data: MeteoraVaultAccount::Vault(decoded_account),
29+
owner: account.owner,
30+
executable: account.executable,
31+
rent_epoch: account.rent_epoch,
32+
});
33+
}
34+
35+
if let Some(decoded_account) = strategy::Strategy::deserialize(account.data.as_slice()) {
36+
return Some(carbon_core::account::DecodedAccount {
37+
lamports: account.lamports,
38+
data: MeteoraVaultAccount::Strategy(decoded_account),
39+
owner: account.owner,
40+
executable: account.executable,
41+
rent_epoch: account.rent_epoch,
42+
});
43+
}
44+
45+
None
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::super::types::*;
2+
3+
use carbon_core::{borsh, CarbonDeserialize};
4+
5+
#[derive(
6+
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
7+
)]
8+
#[carbon(discriminator = "0xae6e2777526aa966")]
9+
pub struct Strategy {
10+
pub reserve: solana_pubkey::Pubkey,
11+
pub collateral_vault: solana_pubkey::Pubkey,
12+
pub strategy_type: StrategyType,
13+
pub current_liquidity: u64,
14+
pub bumps: [u8; 10],
15+
pub vault: solana_pubkey::Pubkey,
16+
pub is_disable: u8,
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use super::super::types::*;
2+
3+
use carbon_core::{borsh, CarbonDeserialize};
4+
5+
#[derive(
6+
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
7+
)]
8+
#[carbon(discriminator = "0xd308e82b02987577")]
9+
pub struct Vault {
10+
pub enabled: u8,
11+
pub bumps: VaultBumps,
12+
pub total_amount: u64,
13+
pub token_vault: solana_pubkey::Pubkey,
14+
pub fee_vault: solana_pubkey::Pubkey,
15+
pub token_mint: solana_pubkey::Pubkey,
16+
pub lp_mint: solana_pubkey::Pubkey,
17+
pub strategies: [solana_pubkey::Pubkey; 30],
18+
pub base: solana_pubkey::Pubkey,
19+
pub admin: solana_pubkey::Pubkey,
20+
pub operator: solana_pubkey::Pubkey,
21+
pub locked_profit_tracker: LockedProfitTracker,
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use carbon_core::{borsh, CarbonDeserialize};
2+
3+
#[derive(
4+
CarbonDeserialize, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Hash,
5+
)]
6+
#[carbon(discriminator = "0xe445a52e51cb9a1d1f5e7d5ae3343dba")]
7+
pub struct AddLiquidityEvent {
8+
pub lp_mint_amount: u64,
9+
pub token_amount: u64,
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use carbon_core::{account_utils::next_account, borsh, CarbonDeserialize};
2+
3+
#[derive(
4+
CarbonDeserialize, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Hash,
5+
)]
6+
#[carbon(discriminator = "0x407b7fe3c0eac614")]
7+
pub struct AddStrategy {}
8+
9+
#[derive(Debug, PartialEq, Eq, Clone, Hash, serde::Serialize, serde::Deserialize)]
10+
pub struct AddStrategyInstructionAccounts {
11+
pub vault: solana_pubkey::Pubkey,
12+
pub strategy: solana_pubkey::Pubkey,
13+
pub admin: solana_pubkey::Pubkey,
14+
}
15+
16+
impl carbon_core::deserialize::ArrangeAccounts for AddStrategy {
17+
type ArrangedAccounts = AddStrategyInstructionAccounts;
18+
19+
fn arrange_accounts(
20+
accounts: &[solana_instruction::AccountMeta],
21+
) -> Option<Self::ArrangedAccounts> {
22+
let mut iter = accounts.iter();
23+
let vault = next_account(&mut iter)?;
24+
let strategy = next_account(&mut iter)?;
25+
let admin = next_account(&mut iter)?;
26+
27+
Some(AddStrategyInstructionAccounts {
28+
vault,
29+
strategy,
30+
admin,
31+
})
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use super::super::types::*;
2+
3+
use carbon_core::{borsh, CarbonDeserialize};
4+
5+
#[derive(
6+
CarbonDeserialize, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Hash,
7+
)]
8+
#[carbon(discriminator = "0xe445a52e51cb9a1d947486cc16ab555f")]
9+
pub struct ClaimRewardEvent {
10+
pub strategy_type: StrategyType,
11+
pub token_amount: u64,
12+
pub mint_account: solana_pubkey::Pubkey,
13+
}

0 commit comments

Comments
 (0)