Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.DS_Store
**/.DS_Store
credentials/
.pnpm-store/
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DepositReceipt {
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub base: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub owner: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub stake_pool: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub stake_pool_deposit_stake_authority: Pubkey,
pub deposit_time: u64,
pub lst_amount: u64,
pub cool_down_seconds: u64,
pub initial_fee_bps: u32,
pub bump_seed: u8,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 256],
}

impl DepositReceipt {
#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}

impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for DepositReceipt {
type Error = std::io::Error;

fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
let mut data: &[u8] = &(*account_info.data).borrow();
Self::deserialize(&mut data)
}
}

#[cfg(feature = "fetch")]
pub fn fetch_deposit_receipt(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<DepositReceipt>, std::io::Error> {
let accounts = fetch_all_deposit_receipt(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_deposit_receipt(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<DepositReceipt>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::other(e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::DecodedAccount<DepositReceipt>> = Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
let account = accounts[i].as_ref().ok_or(std::io::Error::other(format!(
"Account not found: {address}"
)))?;
let data = DepositReceipt::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
});
}
Ok(decoded_accounts)
}

#[cfg(feature = "fetch")]
pub fn fetch_maybe_deposit_receipt(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<DepositReceipt>, std::io::Error> {
let accounts = fetch_all_maybe_deposit_receipt(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_deposit_receipt(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::MaybeAccount<DepositReceipt>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::other(e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::MaybeAccount<DepositReceipt>> = Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
if let Some(account) = accounts[i].as_ref() {
let data = DepositReceipt::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::MaybeAccount::Exists(
crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
},
));
} else {
decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
}
}
Ok(decoded_accounts)
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountDeserialize for DepositReceipt {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
Ok(Self::deserialize(buf)?)
}
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountSerialize for DepositReceipt {}

#[cfg(feature = "anchor")]
impl anchor_lang::Owner for DepositReceipt {
fn owner() -> anchor_lang::prelude::Pubkey {
anchor_lang::prelude::Pubkey::new_from_array(crate::STAKE_DEPOSIT_INTERCEPTOR_ID.to_bytes())
}
}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::IdlBuild for DepositReceipt {}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for DepositReceipt {
const DISCRIMINATOR: &[u8] = &[0; 8];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

pub(crate) mod r#deposit_receipt;
pub(crate) mod r#stake_pool_deposit_stake_authority;

pub use self::r#deposit_receipt::*;
pub use self::r#stake_pool_deposit_stake_authority::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StakePoolDepositStakeAuthority {
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub base: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub stake_pool: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub pool_mint: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub authority: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub vault: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub stake_pool_program_id: Pubkey,
pub cool_down_seconds: u64,
pub inital_fee_bps: u32,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub fee_wallet: Pubkey,
pub bump_seed: u8,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub jito_whitelist_management_program_id: Pubkey,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 224],
}

impl StakePoolDepositStakeAuthority {
#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}

impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for StakePoolDepositStakeAuthority {
type Error = std::io::Error;

fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
let mut data: &[u8] = &(*account_info.data).borrow();
Self::deserialize(&mut data)
}
}

#[cfg(feature = "fetch")]
pub fn fetch_stake_pool_deposit_stake_authority(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<StakePoolDepositStakeAuthority>, std::io::Error> {
let accounts = fetch_all_stake_pool_deposit_stake_authority(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_stake_pool_deposit_stake_authority(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<StakePoolDepositStakeAuthority>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::other(e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::DecodedAccount<StakePoolDepositStakeAuthority>> =
Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
let account = accounts[i].as_ref().ok_or(std::io::Error::other(format!(
"Account not found: {address}"
)))?;
let data = StakePoolDepositStakeAuthority::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
});
}
Ok(decoded_accounts)
}

#[cfg(feature = "fetch")]
pub fn fetch_maybe_stake_pool_deposit_stake_authority(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<StakePoolDepositStakeAuthority>, std::io::Error> {
let accounts = fetch_all_maybe_stake_pool_deposit_stake_authority(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_stake_pool_deposit_stake_authority(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::MaybeAccount<StakePoolDepositStakeAuthority>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::other(e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::MaybeAccount<StakePoolDepositStakeAuthority>> =
Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
if let Some(account) = accounts[i].as_ref() {
let data = StakePoolDepositStakeAuthority::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::MaybeAccount::Exists(
crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
},
));
} else {
decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
}
}
Ok(decoded_accounts)
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountDeserialize for StakePoolDepositStakeAuthority {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
Ok(Self::deserialize(buf)?)
}
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountSerialize for StakePoolDepositStakeAuthority {}

#[cfg(feature = "anchor")]
impl anchor_lang::Owner for StakePoolDepositStakeAuthority {
fn owner() -> anchor_lang::prelude::Pubkey {
anchor_lang::prelude::Pubkey::new_from_array(crate::STAKE_DEPOSIT_INTERCEPTOR_ID.to_bytes())
}
}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::IdlBuild for StakePoolDepositStakeAuthority {}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for StakePoolDepositStakeAuthority {
const DISCRIMINATOR: &[u8] = &[0; 8];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! <https://github.com/codama-idl/codama>
//!

pub mod accounts;
pub mod errors;
pub mod instructions;
pub mod programs;
Expand Down
23 changes: 23 additions & 0 deletions codama-pod-primitives-visitor.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

/**
* Maps spl_pod-style IDL aliases (PodU64 / PodU32) to plain number types after
* Anchor → Codama conversion (defined type links become podU64 / podU32).
*/
const { bottomUpTransformerVisitor, numberTypeNode, assertIsNode } = require("codama");

const POD_TO_PRIMITIVE = {
podU64: () => numberTypeNode("u64"),
podU32: () => numberTypeNode("u32"),
};

module.exports = bottomUpTransformerVisitor([
{
select: "[definedTypeLinkNode]",
transform: (node) => {
assertIsNode(node, "definedTypeLinkNode");
const build = POD_TO_PRIMITIVE[node.name];
return build ? build() : node;
},
},
]);
2 changes: 1 addition & 1 deletion codama.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"idl": "stake_deposit_interceptor/idl/stake_deposit_interceptor.json",
"before": [],
"before": ["./codama-pod-primitives-visitor.cjs"],
"scripts": {
"rust": {
"from": "@codama/renderers-rust",
Expand Down
Loading
Loading