Procedural macros for the Solzempic framework.
This crate provides compile-time code generation for Solana programs built with Solzempic. The macros reduce boilerplate while maintaining zero runtime overhead through compile-time expansion.
Available Macros
| Macro | Type | Purpose |
|---|---|---|
[SolzempicDispatch] |
Attribute | Dispatch enum + framework types |
[instruction] |
Attribute | Instruction trait implementations |
[Account] |
Derive | Account struct with discriminator |
Quick Start
use solzempic::SolzempicDispatch;
// 1. Define dispatch enum (generates framework types)
#[SolzempicDispatch("Your11111111111111111111111111111111111111")]
pub enum MyInstruction {
Initialize = 0,
Transfer = 1,
}
// 2. Define instruction struct
pub struct Transfer<'a> {
from: AccountRefMut<'a, TokenAccount>,
to: AccountRefMut<'a, TokenAccount>,
}
// 3. Implement with #[instruction] macro
#[instruction(TransferParams)]
impl<'a> Transfer<'a> {
fn build(accounts: &'a [AccountInfo], params: &TransferParams) -> Result<Self, ProgramError> {
// Parse accounts...
}
fn validate(&self, program_id: &Pubkey, params: &TransferParams) -> ProgramResult {
// Validate state...
}
fn execute(&self, program_id: &Pubkey, params: &TransferParams) -> ProgramResult {
// Execute logic...
}
}
// 4. In entrypoint:
MyInstruction::process(program_id, accounts, instruction_data)?;
Generated Code
From SolzempicDispatch
ID- Program ID constantSolzempic- Framework type implementingFrameworktraitAccountRef<'a, T>- Type alias for read-only accountsAccountRefMut<'a, T>- Type alias for writable accountsShardRefContext<'a, T>- Type alias for shard tripletsid()- Returns&'static PubkeyTryFrom<u8>- Discriminator parsingdispatch()- Handler dispatch (after enum construction)process()- Direct dispatch (more efficient)
From instruction
InstructionParamsimpl with associatedParamstypeInstruction<'a>impl withbuild,validate,executemethods
From Account derive
#[repr(C)]for stable memory layoutClone,Copy,Pod,Zeroablederives- Prepended
discriminator: [u8; 8]field Loadableimpl for zero-copy loading
Performance
All macros expand at compile time with zero runtime cost. The process()
method is more efficient than dispatch() because it avoids constructing
the enum variant before dispatching.