spl_transfer_hook_interface/
lib.rs

1//! Crate defining an interface for performing a hook on transfer, where the
2//! token program calls into a separate program with additional accounts after
3//! all other logic, to be sure that a transfer has accomplished all required
4//! preconditions.
5
6#![allow(clippy::arithmetic_side_effects)]
7#![deny(missing_docs)]
8#![cfg_attr(not(test), forbid(unsafe_code))]
9
10pub mod error;
11pub mod instruction;
12pub mod offchain;
13pub mod onchain;
14
15// Export current sdk types for downstream users building with a different sdk
16// version
17use solana_pubkey::Pubkey;
18pub use {
19    solana_account_info, solana_cpi, solana_instruction, solana_msg, solana_program_error,
20    solana_pubkey,
21};
22
23/// Namespace for all programs implementing transfer-hook
24pub const NAMESPACE: &str = "spl-transfer-hook-interface";
25
26/// Seed for the state
27const EXTRA_ACCOUNT_METAS_SEED: &[u8] = b"extra-account-metas";
28
29/// Get the state address PDA
30pub fn get_extra_account_metas_address(mint: &Pubkey, program_id: &Pubkey) -> Pubkey {
31    get_extra_account_metas_address_and_bump_seed(mint, program_id).0
32}
33
34/// Function used by programs implementing the interface, when creating the PDA,
35/// to also get the bump seed
36pub fn get_extra_account_metas_address_and_bump_seed(
37    mint: &Pubkey,
38    program_id: &Pubkey,
39) -> (Pubkey, u8) {
40    Pubkey::find_program_address(&collect_extra_account_metas_seeds(mint), program_id)
41}
42
43/// Function used by programs implementing the interface, when creating the PDA,
44/// to get all of the PDA seeds
45pub fn collect_extra_account_metas_seeds(mint: &Pubkey) -> [&[u8]; 2] {
46    [EXTRA_ACCOUNT_METAS_SEED, mint.as_ref()]
47}
48
49/// Function used by programs implementing the interface, when creating the PDA,
50/// to sign for the PDA
51pub fn collect_extra_account_metas_signer_seeds<'a>(
52    mint: &'a Pubkey,
53    bump_seed: &'a [u8],
54) -> [&'a [u8]; 3] {
55    [EXTRA_ACCOUNT_METAS_SEED, mint.as_ref(), bump_seed]
56}