Skip to main content

rialo_s_spl_transfer_hook_interface/
lib.rs

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