Skip to content
Open
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ solana-sdk = "3"
solana-sdk-ids = "3"
solana-sha256-hasher = { version = "3", features = ["sha2"] }
solana-system-interface = "3"
spl-associated-token-account-interface = { version = "2" }
spl-associated-token-account-interface = "2"
spl-token = "9"
spl-token-interface = "2"

Expand Down
34 changes: 34 additions & 0 deletions client/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,40 @@ impl From<Initialize> for Instruction {
}
}

/// Builder for a `ReclaimBuffer` instruction closing the buffer for each of
/// `mints`.
///
/// **Warning:** any token balance still held by a buffer is burned, not
/// recovered, before the buffer is closed. Only reclaim buffers expected to
/// be empty, or to write off dust/dead balances — never one that might still
/// hold funds of useful value.
Comment on lines +195 to +198

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// **Warning:** any token balance still held by a buffer is burned, not
/// recovered, before the buffer is closed. Only reclaim buffers expected to
/// be empty, or to write off dust/dead balances — never one that might still
/// hold funds of useful value.
/// **Warning:** if a buffer account has nonzero balance, it will be silently
/// skipped. This is done to prevent accidental loss of funds.

pub struct ReclaimBuffer<'a> {
pub program_id: Pubkey,
pub reclaim_authority: Pubkey,
pub mints: &'a [Pubkey],
}

impl From<ReclaimBuffer<'_>> for Instruction {
fn from(builder: ReclaimBuffer<'_>) -> Self {
let (state_pda, _bump) = find_state_pda(&builder.program_id);
let buffers: Vec<(Pubkey, Pubkey)> = builder
.mints
.iter()
.map(|mint| {
let (buffer_pda, _bump) = find_buffer_pda(&builder.program_id, mint);
(buffer_pda, *mint)
})
.collect();
settlement_interface::instruction::reclaim_buffer::ReclaimBuffer {
program_id: builder.program_id,
state_pda,
reclaim_authority: builder.reclaim_authority,
buffers: &buffers,
}
.into()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions interface/src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{recover_discriminator, SettlementInstruction};
pub mod create_buffer;
pub mod create_order;
pub mod initialize;
pub mod reclaim_buffer;
pub mod reclaim_order;
pub mod settle;

Expand Down
Loading