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
17pub use miraland_program;
18use miraland_program::pubkey::Pubkey;
19
20/// Namespace for all programs implementing transfer-hook
21pub const NAMESPACE: &str = "solarti-transfer-hook-interface";
22
23/// Seed for the state
24const EXTRA_ACCOUNT_METAS_SEED: &[u8] = b"extra-account-metas";
25
26/// Get the state address PDA
27pub fn get_extra_account_metas_address(mint: &Pubkey, program_id: &Pubkey) -> Pubkey {
28    get_extra_account_metas_address_and_bump_seed(mint, program_id).0
29}
30
31/// Function used by programs implementing the interface, when creating the PDA,
32/// to also get the bump seed
33pub fn get_extra_account_metas_address_and_bump_seed(
34    mint: &Pubkey,
35    program_id: &Pubkey,
36) -> (Pubkey, u8) {
37    Pubkey::find_program_address(&collect_extra_account_metas_seeds(mint), program_id)
38}
39
40/// Function used by programs implementing the interface, when creating the PDA,
41/// to get all of the PDA seeds
42pub fn collect_extra_account_metas_seeds(mint: &Pubkey) -> [&[u8]; 2] {
43    [EXTRA_ACCOUNT_METAS_SEED, mint.as_ref()]
44}
45
46/// Function used by programs implementing the interface, when creating the PDA,
47/// to sign for the PDA
48pub fn collect_extra_account_metas_signer_seeds<'a>(
49    mint: &'a Pubkey,
50    bump_seed: &'a [u8],
51) -> [&'a [u8]; 3] {
52    [EXTRA_ACCOUNT_METAS_SEED, mint.as_ref(), bump_seed]
53}