Skip to main content

hopper/
prelude.rs

1//! One-import path for authored Hopper programs.
2
3// Core prelude
4pub use hopper_core::prelude::*;
5
6// ABI wire types (explicit for discoverability)
7pub use hopper_core::abi::{
8    WireBool, WireI128, WireI16, WireI32, WireI64, WireU128, WireU16, WireU32, WireU64,
9};
10
11// Macros
12pub use crate::{
13    const_assert_pod, hopper_accounts, hopper_check, hopper_close, hopper_error, hopper_init,
14    hopper_interface, hopper_invariant, hopper_layout, hopper_manifest, hopper_register_discs,
15    hopper_require, hopper_segment, hopper_validate, hopper_verify_pda, hopper_virtual,
16};
17
18#[cfg(feature = "proc-macros")]
19pub use crate::{
20    account, accounts, context, hopper_context, hopper_program, hopper_state, program, state,
21    Accounts,
22};
23
24// New systems
25pub use hopper_core::account::segment_role::{
26    SegmentRole, SEG_ROLE_AUDIT, SEG_ROLE_CACHE, SEG_ROLE_CORE, SEG_ROLE_EXTENSION, SEG_ROLE_INDEX,
27    SEG_ROLE_JOURNAL, SEG_ROLE_SHARD,
28};
29pub use hopper_core::account::{
30    segment_id, SegmentEntry, SegmentId, SegmentRegistry, SegmentRegistryMut,
31};
32#[cfg(feature = "graph")]
33pub use hopper_core::check::graph::{
34    AccountConstraint, TransactionConstraint, ValidationContext, ValidationGraph,
35};
36#[cfg(feature = "collections")]
37pub use hopper_core::collections::journal::{Journal, JournalReader};
38#[cfg(feature = "collections")]
39pub use hopper_core::collections::slab::Slab;
40#[cfg(feature = "diff")]
41pub use hopper_core::diff::{StateDiff, StateSnapshot};
42#[cfg(feature = "policy")]
43pub use hopper_core::policy::{
44    Capability, CapabilitySet, InstructionPolicy, PolicyRequirement, RequirementSet,
45};
46#[cfg(feature = "receipt")]
47pub use hopper_core::receipt::{
48    FailureStage, StateReceipt, FAILED_INVARIANT_NONE, RECEIPT_SIZE, RECEIPT_SIZE_LEGACY,
49};
50#[cfg(feature = "virtual-state")]
51pub use hopper_core::virtual_state::{ShardedAccess, VirtualSlot, VirtualState};
52
53// Runtime essentials
54pub use hopper_associated_token;
55pub use hopper_associated_token::instructions as associated_token_instructions;
56pub use hopper_associated_token::ATA_PROGRAM_ID;
57pub use hopper_runtime::cpi::{
58    invoke as cpi_invoke, invoke_signed as cpi_invoke_signed,
59    set_return_data as cpi_set_return_data,
60};
61pub use hopper_runtime::error::ProgramError;
62pub use hopper_runtime::fast_entrypoint;
63pub use hopper_runtime::hopper_entrypoint;
64pub use hopper_runtime::hopper_fast_entrypoint;
65pub use hopper_runtime::hopper_lazy_entrypoint;
66pub use hopper_runtime::layout::{
67    init_header, read_disc, read_layout_id, read_version, write_header, HopperHeader, LayoutInfo,
68};
69pub use hopper_runtime::lazy_entrypoint;
70pub use hopper_runtime::program_entrypoint;
71pub use hopper_runtime::{no_allocator, nostd_panic_handler};
72pub use hopper_runtime::{
73    AccountView, Address, Context, InstructionAccount, InstructionView, LayoutContract,
74    ProgramResult, Seed, Signer, TailCodec, TransparentAddress,
75};
76pub use hopper_system;
77pub use hopper_system::instructions as system_instructions;
78pub use hopper_system::SYSTEM_PROGRAM_ID;
79pub use hopper_token;
80pub use hopper_token::instructions as token_instructions;
81pub use hopper_token::TOKEN_PROGRAM_ID;
82pub use hopper_token_2022;
83pub use hopper_token_2022::instructions as token_2022_instructions;
84pub use hopper_token_2022::TOKEN_2022_PROGRAM_ID;
85
86// SPL Memo CPI helper. Stays small (one builder, one program id pair)
87// so it lands in the prelude rather than behind a feature.
88pub use hopper_memo;
89pub use hopper_memo::{Memo, MAX_MEMO_SIGNERS, MEMO_PROGRAM_ID};
90
91// Token + Token-2022 polymorphic readers and the matching
92// `transfer_checked` CPI helper. The wrappers validate the account is
93// owned by either SPL Token or Token-2022 and expose the unified
94// reader surface; the CPI helper forwards to the right program based
95// on the source account's owner.
96pub use hopper_solana::interface::{
97    interface_transfer_checked, interface_transfer_checked_signed, InterfaceMint,
98    InterfaceTokenAccount, TokenProgramKind,
99};
100
101// Metaplex (NFT) builders - opt-in via `--features metaplex`. Emits
102// `CreateMetadataAccountV3`, `CreateMasterEditionV3`,
103// `UpdateMetadataAccountV2`, plus PDA helpers (`metadata_pda`,
104// `master_edition_pda`). The crate adds compile time and an
105// instruction-data Borsh encoder, so it stays optional.
106#[cfg(feature = "metaplex")]
107pub use hopper_metaplex;
108#[cfg(feature = "metaplex")]
109pub use hopper_metaplex::{
110    master_edition_pda, master_edition_pda_with_bump, metadata_pda, metadata_pda_with_bump,
111    CreateMasterEditionV3, CreateMetadataAccountV3, DataV2, UpdateMetadataAccountV2,
112    MPL_TOKEN_METADATA_PROGRAM_ID,
113};
114
115// Field maps
116pub use hopper_core::account::HEADER_LEN;
117pub use hopper_core::field_map::{FieldInfo, FieldMap};
118pub use hopper_core::invariant::InvariantSet;
119pub use hopper_core::segment_map::{SegmentMap, StaticSegment};
120
121#[cfg(target_os = "solana")]
122pub use crate::pda::{
123    create_program_address, find_program_address, verify_pda, verify_pda_with_bump,
124};
125
126// Hopper Lang guards (function form - pass bool, call with `?`)
127pub use crate::guards::{
128    require, require_address, require_data_len, require_disc, require_eq, require_gt, require_gte,
129    require_has_data, require_keys_eq, require_keys_neq, require_layout, require_neq,
130    require_owner, require_payer, require_signer, require_unique_2, require_unique_3,
131    require_version, require_writable,
132};
133
134// Anchor-parity guard macros (declarative form - pass condition as
135// expression, bails via `return Err(...)`). Function forms above and
136// macro forms coexist because Rust places macros and values in
137// separate namespaces. At a call site, `require!(cond, err)` resolves
138// to the macro (trailing `!`) and `require(cond, err)?` resolves to
139// the function. The two macros without function siblings (`require_lt`,
140// `require_lte`) are unambiguous.
141//
142// Note: `require`, `require_eq`, `require_neq`, `require_keys_eq`,
143// `require_keys_neq`, `require_gt`, `require_gte` already come in via
144// their hopper_runtime `#[macro_export]` declarations and are in scope
145// under `hopper::require!` etc. via the `pub use hopper_runtime::*` at
146// the root crate level where needed. We explicitly pull in the two
147// that don't have function siblings so they're unambiguous here.
148pub use hopper_runtime::{require_lt, require_lte};
149
150// Anchor-parity short-form error macros. Functionally identical to
151// `hopper_error!` but match Anchor's `err!` / `error!` spelling so
152// ported code needs no rename.
153pub use hopper_runtime::{err, error};
154
155// Handy destructuring sugar for the raw-dispatch authoring path.
156// Replaces `let [user, vault, ..] = accounts else { return Err(...); };`
157// with `hopper_load!(accounts => [user, vault]);`. Only useful when you
158// are NOT going through `#[hopper::context]`; the proc-macro path already
159// destructures for you.
160pub use crate::hopper_load;
161
162// Receipts
163pub use crate::receipts::{
164    emit_receipt, emit_tagged_receipt, emit_typed_receipt, set_return_data, Receipt,
165};