sanctum-macros
Inspired by https://github.com/Ellipsis-Labs/ellipsis-macros
Compile-Time Pubkey consts Generation
solana_program
should be a declared dependency in the crates using these macros.
declare_program_keys!
// first arg = program ID
// second arg = list of static PDA names and their seeds.
//
// Rules from solana runtime:
// - Each seed can have a max length of 32 bytes.
// - Each PDA can have max 16 seeds.
declare_program_keys!;
expands to
pub const ID_STR: &str = "9BoN4yBYwH63LFM9fDamaHK62YjM56hWYZqok7MnAakJ";
pub const ID_BYTES: = ;
pub const ID: Pubkey = new_from_array;
// let (STATE_ID, STATE_BUMP) = Pubkey::find_program_address(&[STATE_SEED], &ID);
pub const STATE_SEED: & = b"state";
pub const STATE_BUMP: u8 = 255;
pub const STATE_ID_BYTES: = ;
pub const STATE_ID: Pubkey = new_from_array;
pub const STATE_ID_STR: &str = "DJq3bbgiJq34LKrH37UEb7rXDaWTUGjnieLZamkRvu5R";
// let (EMPTY_KEBAB_ID, EMPTY_KEBAB_BUMP) = Pubkey::find_program_address(&[EMPTY_KEBAB_SEED], &ID);
pub const EMPTY_KEBAB_SEED: & = b"";
pub const EMPTY_KEBAB_BUMP: u8 = 255;
pub const EMPTY_KEBAB_ID_BYTES: = ;
pub const EMPTY_KEBAB_ID: Pubkey = new_from_array;
pub const EMPTY_KEBAB_ID_STR: &str = "B5SqYyds9eLeX5mK4uycKGgZHft1URCbTzU6LoWhCV63";
// let (MULTISEED_ID, MULTISEED_BUMP) = Pubkey::find_program_address(&[MULTISEED_SEED_0, MULTISEED_SEED_1], &ID);
pub const MULTISEED_SEED_0: & = b"two";
pub const MULTISEED_SEED_1: & = b"seeds";
pub const MULTISEED_BUMP: u8 = 255;
pub const MULTISEED_ID_BYTES: = ;
pub const MULTISEED_ID: Pubkey = new_from_array;
pub const MULTISEED_ID_STR: &str = "7dCVGBbemkex9cQNMp17kupcL41jueGXwjSrc2NWf6Ek";
create_with_seed!
Create a Pubkey
with Pubkey::create_with_seed
.
// args: (base, seed, owner)
create_with_seed!;
expands to
// let ID = Pubkey::create_with_seed(&BASE_ID, SEED, OWNER_ID).unwrap();
pub const ID_BYTES: = ;
pub const ID_STR: &str = "FLgYDs1daqCvXAmz5vqij39zFdSraks4S6xuKvf2NJsZ";
pub const ID: Pubkey = new_from_array;
pub const BASE_ID_BYTES: = ;
pub const BASE_ID_STR: &str = "9BoN4yBYwH63LFM9fDamaHK62YjM56hWYZqok7MnAakJ";
pub const BASE_ID: Pubkey = new_from_array;
pub const SEED: &str = "seed";
pub const OWNER_ID_BYTES: = ;
pub const OWNER_ID_STR: &str = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
pub const OWNER_ID: Pubkey = new_from_array;
When used with system_instruction::create_account_with_seed()
, a new account owned by OWNER_ID
program will be created at ID
. BASE_ID
must be a signer.