Expand description
Protocol-grade Hopper surface.
Import this when a program deliberately reaches beyond framework mode into layout contracts, segment registries, receipts, policies, migrations, manifests, overlays, or cross-program interface pinning.
Re-exports§
pub use crate::interface;pub use crate::layout;pub use crate::migration;pub use crate::policy;pub use crate::receipt;pub use crate::schema;pub use crate::segment;pub use crate::interface::*;pub use crate::layout::*;pub use crate::migration::*;pub use crate::policy::*;pub use crate::receipt::*;pub use crate::schema::*;pub use crate::segment::*;
Macros§
- const_
assert_ pod - Compile-time assertion for safe manual
Podimplementations. - fast_
entrypoint - Backward-compatible alias for the fast Hopper entrypoint macro.
- hopper_
accounts - Generate a typed instruction context struct with validated account parsing.
- hopper_
assert_ compatible - Assert that two layout versions have compatible fingerprints.
- hopper_
assert_ fingerprint - Assert that a layout’s fingerprint matches an expected value.
- hopper_
check - Composable account constraint checking.
- hopper_
close - Safely close an account with sentinel protection.
- hopper_
dynamic_ fields - Explicit sugar for declaring bounded dynamic-tail fields.
- hopper_
dynamic_ tail - Declare a dynamic-tail payload with bounded dynamic fields.
- hopper_
entrypoint - Declare the explicit Hopper runtime entrypoint bridge.
- hopper_
error - Generate sequential error codes.
- hopper_
fast_ entrypoint - Declare the fast two-argument Hopper entrypoint.
- hopper_
init - Initialize an account: allocate, assign, zero-init, write header.
- hopper_
interface - Declare a cross-program interface view.
- hopper_
invariant - Invariant checking macro.
- hopper_
layout - Define a zero-copy account layout.
- hopper_
lazy_ entrypoint - Declare the Hopper lazy entrypoint.
- hopper_
load - Destructuring sugar for raw-dispatch handlers.
- hopper_
manifest - Generate a layout manifest for schema tooling.
- hopper_
register_ discs - Discriminator registry – compile-time uniqueness enforcement.
- hopper_
require - Require a condition, returning a custom error if false.
- hopper_
segment - Declare a segmented account with typed segments.
- hopper_
validate - Build a validation pipeline declaratively.
- hopper_
verify_ pda - PDA verification with BUMP_OFFSET optimization.
- hopper_
virtual - Declare a multi-account virtual state mapping.
- layout_
migrations - Compose a layout’s
LayoutMigration::MIGRATIONSchain from a list of#[hopper::migrate]-emitted edge constants. - lazy_
entrypoint - Backward-compatible alias for the lazy Hopper entrypoint macro.
- no_
allocator - nostd_
panic_ handler - program_
entrypoint - Declare the canonical Hopper program entrypoint.
Structs§
- Account
- A typed, owner-validated account (immutable).
- Account
Header - The 16-byte account header, overlay-safe.
- Account
Mut - A typed, owner-validated account (mutable).
- Account
Reader - Header-aware read-only account reader.
- Authority
- Marker: an authority/signer address.
- Bounded
String - Bounded UTF-8 string for Hopper dynamic tails.
- Bounded
Vec - Bounded dynamic vector for Hopper dynamic tails.
- Cached
Clock - Cached Clock sysvar fields.
- Cached
Rent - Cached Rent sysvar fields.
- CpiAccount
- C-ABI account info passed to
sol_invoke_signed_c. - Dynamic
View - An inline dynamic view that caches offsets for O(1) field access.
- Dynamic
View Mut - Mutable inline dynamic view for writing dynamic fields.
- Field
Info - Descriptor for one field in a Hopper layout.
- Hopper
Account - A layout-bound, owner-validated account.
- Hopper
Cpi - Stack-allocated CPI call with compile-time-known account count and data size.
- Hopper
CpiBuf - Variable-data CPI builder – const accounts, runtime data length.
- Hopper
Ctx - Typed instruction context carrying validated accounts, bumps, and metadata.
- Instruction
Account - Metadata for an account referenced in a CPI instruction.
- Instruction
View - A cross-program instruction to invoke.
- Invariant
Set - Batch invariant checker.
- Mint
- Marker: a mint address.
- Mut
- Writable wrapper – validates that the account is writable.
- Program
- Marker: a program address (executable).
- Program
Account - A generic program-owned account.
- Program
Ref - A verified executable program reference.
- Realloc
Guard - Per-instruction realloc budget guard.
- Seed
- A single PDA seed for CPI signing.
- Segment
- Compile-time descriptor of a typed byte range inside an account.
- Segment
Borrow - A single active segment borrow.
- Segment
Borrow Registry - Instruction-scoped segment borrow registry.
- Segment
Entry - A segment entry in the registry.
- Segment
Registry - Read-only view over a segmented account’s registry.
- Segment
Registry Mut - Mutable view over a segmented account’s registry.
- Segmented
Account - A segmented account with role-aware region access.
- Signer
- Signer wrapper – validates that the account is a signer.
- Signer
Account - A verified signer account.
- Static
Segment - A compile-time constant segment descriptor.
- Sysvar
Context - Combined sysvar context for a single instruction.
- Token
Account - Marker: a token account address.
- Trust
Flags - Policy flags for additional constraints.
- Trust
Profile - A foreign-account trust profile.
- Typed
Address - A 32-byte public key tagged with a phantom layout type.
- Unchecked
Account - An unchecked account. No validation is performed.
- Untyped
Address - An untyped 32-byte address (interop bridge).
- Verified
Account - Immutable verified account – proof that validation passed.
- Verified
Account Mut - Mutable verified account – proof that validation passed, with write access.
Enums§
- Access
Kind - Read or write access intent for a segment borrow.
- Segment
Role - Segment role classification.
- Trust
Level - Trust level for foreign account validation.
Constants§
- CLOSE_
SENTINEL - Sentinel byte written to byte 0 when an account is closed. Prevents account revival attacks.
- EVENT_
CPI_ PREFIX - Event CPI prefix. Programs should check for this at dispatch entry
and return
Ok(())to allow self-CPI events to pass through. - HEADER_
EXECUTABLE - Non-duplicate + executable.
- HEADER_
LEN - Header length in bytes.
- HEADER_
SIGNER - Non-duplicate + signer.
- HEADER_
SIGNER_ WRITABLE - Non-duplicate + signer + writable.
- HEADER_
WRITABLE - Non-duplicate + writable.
- SEG_
ROLE_ AUDIT - SEG_
ROLE_ CACHE - SEG_
ROLE_ CORE - Segment role flags – convenience constants for
SegmentEntry::new(). - SEG_
ROLE_ EXTENSION - SEG_
ROLE_ INDEX - SEG_
ROLE_ JOURNAL - SEG_
ROLE_ SHARD
Traits§
- Account
Meta Provider - Trait for types that provide static metadata about themselves.
- Field
Map - Trait for layouts that expose field metadata in wire order.
- Fixed
Layout - Trait for types with a compile-time known wire size.
- From
Account - Trait for types that can be constructed from an AccountView with validation.
- HasView
- Helper trait for types that hold an
&AccountView. - Hopper
Accounts - Trait implemented by account structs (manually or via derive).
- Hopper
Ix - Trait defining a Hopper instruction.
- Hopper
Layout - Trait implemented by
hopper_layout!types providing layout metadata. - Pod
- Marker for types that can be safely overlaid on raw account bytes.
- Tail
Codec - Canonical serializer for dynamic-tail payloads.
- Tail
Element - Element type accepted by
#[tail(vec<T, N>)]in#[hopper::dynamic_account]. - Validate
Account - Trait for accounts that can self-validate.
Functions§
- assert_
segment_ field_ alignment - Compile-time assertion that a type’s
SegmentMapandFieldMapare isomorphic: same count, same names, same offsets, same sizes. - bps_of
- Basis-point fee (floor):
amount * bps / 10_000. - bps_
of_ ceil - Basis-point fee (ceiling):
ceil(amount * bps / 10_000). - cast_
unchecked ⚠ - Raw unchecked cast from bytes to an immutable reference.
- cast_
unchecked_ ⚠mut - Raw unchecked cast from bytes to a mutable reference.
- check_
account - Combined account check: owner + discriminator + minimum size.
- check_
account_ fast - Fast single-compare account validation.
- check_
authority_ fast - Validate a signer + writable account (authority) with single u32 compare.
- check_
cooldown_ elapsed - Check that enough time has elapsed since the last operation.
- check_
deadline_ not_ passed - Check that a deadline has NOT passed (now < deadline).
- check_
discriminator - Check that the discriminator byte matches.
- check_
executable - Check that an account is executable (a program).
- check_
executable_ fast - Validate an executable (program) account with single u32 compare.
- check_
has_ one - Check
has_one: a stored address in account data matches another account’s address. - check_
invariant - Check a single invariant condition.
- check_
invariant_ fn - Check a single invariant with a closure (lazy evaluation).
- check_
keys_ eq - Check that two account addresses are equal.
- check_
lamport_ conservation - Verify SOL conservation: total lamports before == total lamports after.
- check_
no_ subsequent_ invocation - Ensure our program is not invoked after the current instruction.
- check_
owner - Check that an account is owned by the expected program.
- check_
owner_ multi - Check that an account is owned by one of the given program IDs.
- check_
program - Check that an account is a specific program: its key matches
expected_program_idand it is flagged executable. - check_
rent_ exempt - Check that an account is rent exempt.
- check_
signer - Check that an account is a signer.
- check_
signer_ fast - Validate a signer account with single u32 compare.
- check_
size - Check minimum data size.
- check_
staleness - Check that data is not stale (updated recently enough).
- check_
state_ transition - Check that a state transition is valid.
- check_
writable - Check that an account is writable.
- check_
writable_ coherence - Validate that every writable account in the slice is also a signer OR is owned by our program.
- check_
writable_ fast - Validate a writable account with single u32 compare.
- checked_
add - Checked addition.
- checked_
div - Checked division (returns error on divide by zero).
- checked_
div_ ceil - Checked ceiling division:
ceil(a / b). - checked_
mul - Checked multiplication.
- checked_
mul_ div - Compute
(a * b) / cwith u128 intermediate to prevent overflow. - checked_
mul_ div_ ceil - Compute
ceil((a * b) / c)with u128 intermediate. - checked_
pow - Checked exponentiation via repeated squaring.
- checked_
sub - Checked subtraction.
- detect_
flash_ loan_ bracket - Detect flash-loan bracket: same program called before AND after current.
- dispatch_
instruction - Read a 1-byte dispatch tag from instruction data.
- dispatch_
instruction_ 8 - Read an 8-byte discriminator (Anchor/Quasar compatible).
- dispatch_
instruction_ u16 - Read a 2-byte dispatch tag (for programs with >256 instructions).
- div_
ceil - Compute
ceil(a / b)without overflow (for u64). - emit_
event - Emit a Pod event via
sol_log_data. - emit_
event_ tagged - Emit event with a discriminator prefix for easy client-side filtering.
- emit_
slices - Emit one or more byte slices as a single
sol_log_dataentry. - find_
and_ verify_ pda - Find a PDA and verify it matches the account, returning the bump.
- hopper_
entry - Typed instruction entry point.
- is_
zero_ address - Check if a 32-byte address is all zeros (the default/system address).
- keys_
eq_ fast - Fast 32-byte key equality check using 4x u64 comparisons.
- load_
foreign_ with_ profile - Load a foreign account with a trust profile, returning a typed overlay.
- overlay
- Overlay immutable reference to a Pod type at the start of a byte slice.
- overlay_
mut - Overlay mutable reference to a Pod type at the start of a byte slice.
- pod_
from_ bytes - Zero-copy cast from bytes to an immutable reference.
- pod_
from_ bytes_ mut - Zero-copy cast from bytes to a mutable reference.
- pod_
read - Copy a Pod value from bytes (alignment-safe).
- pod_
write - Write a Pod value to bytes (alignment-safe).
- read_
dynamic_ u8 - Read a u8-prefixed dynamic field: returns (data_slice, next_offset).
- read_
dynamic_ u16 - Read a u16-prefixed dynamic field.
- read_
dynamic_ u32 - Read a u32-prefixed dynamic field.
- read_
layout_ id - Read the 8-byte layout_id.
- rent_
exempt_ min - Rent-exempt minimum lamports for a given data size.
- require_
all_ unique - Verify that all accounts in a slice have unique addresses.
- require_
authority - Validate an authority account: must be signer, owned by expected program.
- require_
owned_ writable - Validate a writable program-owned account.
- require_
payer - Validate a payer account: must be signer + writable.
- require_
top_ level - Require that the current instruction is top-level (not a CPI).
- require_
unique_ signers - Verify that no duplicated account is used as a signer.
- require_
unique_ writable - Verify that no duplicated account is writable.
- safe_
close - Safely close an account by draining all lamports to
destination. - safe_
close_ with_ sentinel - Close with sentinel – writes
CLOSE_SENTINELto byte 0 after zeroing. - safe_
realloc - Reallocate an account to a new size.
- scale_
amount - Scale a token amount between different decimal precisions (floor).
- scale_
amount_ ceil - Scale a token amount between decimal precisions, rounding up.
- scale_
bps - Scale a value in basis points (BPS).
value * bps / 10_000, with overflow protection via u128 intermediate. - scale_
fraction - Scale a value by a fraction
(numerator / denominator). - segment_
id - Compute a segment ID from a name (const FNV-1a hash, truncated to 4 bytes).
- snapshot_
lamports - Snapshot lamport values for conservation checking.
- to_u64
- Safe narrowing cast from u128 to u64.
- verify_
pda - Verify a PDA with bump, using the cheap
create_program_addresspath. - verify_
pda_ cached - Verify a PDA by reading the bump from account data at a known offset.
- write_
dynamic_ u8 - Write a u8-prefixed dynamic field. Returns next offset after written data.
- write_
dynamic_ u16 - Write a u16-prefixed dynamic field.
- write_
dynamic_ u32 - Write a u32-prefixed dynamic field.
- write_
header - Write a complete header to the beginning of
data. - zero_
init - Zero-initialize a byte slice. Must be called before
write_header.
Type Aliases§
- Hopper
String - Short alias for bounded UTF-8 strings in dynamic tails.
- Hopper
Vec - Short alias for bounded vectors in dynamic tails.
- Segment
Id - A 4-byte segment identifier, computed from a name at compile time.
- Token
- Alias for
TokenAccount.