Skip to main content

ifx_sdk/
lib.rs

1//! Off-chain Ifx SDK — build `ifx_create_frame`, `ifx_let`, `ifx_assert`, `ifx_patched_cpi`,
2//! `ifx_if_else`, and related instructions as [`solana_sdk::instruction::Instruction`] values.
3//!
4//! Same layer as `@ifx-run/sdk` and `go-sdk`: wire encoding and planner helpers only —
5//! **no** RPC, wallet, or transaction submission wrapper.
6//!
7//! # Example
8//!
9//! Typical **business tx** on an existing Frame (create Frame is a separate one-time tx):
10//! read a token balance mid-flow, then **close the ATA only when amount is zero** —
11//! otherwise **Skip** so the rest of the transaction still succeeds.
12//!
13//! ```no_run
14//! use ifx_sdk::expr;
15//! use ifx_sdk::if_else::{args, cpi, skip};
16//! use ifx_sdk::patched_cpi::{build_static_cpi, with_owner_signer};
17//! use ifx_sdk::scratch::FrameScratch;
18//! # use solana_sdk::pubkey::Pubkey;
19//!
20//! # fn plan(
21//! #     scratch: &mut FrameScratch,
22//! #     token_account: Pubkey,
23//! #     owner: Pubkey,
24//! #     rent_destination: Pubkey,
25//! #     close_tpl: solana_sdk::instruction::Instruction,
26//! # ) -> Result<(), ifx_sdk::ScratchError> {
27//! scratch.ix_reset();
28//!
29//! let mut b = scratch.let_builder();
30//! let amount = b.spl_token_amount(token_account)?;
31//! b.build_ix()?;
32//!
33//! let close_ix = with_owner_signer(&close_tpl, owner, true);
34//! let close_built = build_static_cpi(&close_ix)?;
35//!
36//! scratch.ix_if_else(
37//!     &args(
38//!         expr::is_zero(expr::r(&amount)),
39//!         cpi(close_built.cpi.clone()),
40//!         skip(),
41//!     ),
42//!     &close_built.remaining,
43//! )?;
44//! # Ok(())
45//! # }
46//! ```
47//!
48//! Full guide, examples, and integration tests: <https://github.com/ifx-run/ifx/tree/main/rust-sdk>.
49
50#![deny(unsafe_code)]
51
52pub mod binding;
53pub mod constants;
54pub mod cpi;
55pub mod decode;
56pub mod decode_ix;
57pub mod error;
58pub mod expr;
59pub mod frame;
60pub mod frame_authority;
61pub mod if_else;
62pub mod ix;
63pub mod let_bindings;
64pub mod let_builder;
65pub mod parse_logs;
66pub mod patched_cpi;
67#[cfg(test)]
68mod parity;
69pub mod scratch;
70pub mod typed;
71pub mod wire_ix;
72
73pub use ifx_core as core;
74
75pub use binding::{eval_const_bool, eval_const_u64, infer_binding_ty, remap_account_index};
76pub use constants::*;
77pub use cpi::{
78    encode_cpi, normalize_remaining, normalize_remaining_metas, resolve_cpi_remaining,
79    CpiWireBuildResult,
80};
81pub use decode::{decode_frame_account, DecodedFrame};
82pub use decode_ix::{decode_ifx_instruction, ifx_ix_hint, DecodedIfxInstruction, IfxIxName};
83pub use error::ScratchError;
84pub use frame::{encode_create_frame_args, frame_pda};
85pub use frame_authority::{
86    frame_authority_requires_signer, frame_write_authority_meta, prepend_write_authority_remaining,
87    public_frame_authority,
88};
89pub use if_else::{args as if_else_args, cpi as if_else_cpi, revert as if_else_revert, skip as if_else_skip};
90pub use ix::{
91    build_ix_assert, build_ix_assert_multi, build_ix_close_frame, build_ix_create_frame,
92    build_ix_cpi, build_ix_if_else, build_ix_let, build_ix_reset_frame, if_else_args_skip_skip,
93    let_args_from_bindings, CreateFrameParams, CreateFrameResult, IxOpts,
94};
95pub use let_builder::{LetBuilder, LetBuilderFinish};
96pub use parse_logs::{
97    first_ifx_error_in_logs, parse_ifx_logs, ParsedIfxLog, ParsedIfxLogKind,
98};
99pub use patched_cpi::{
100    build_raw_cpi, build_static_cpi, build_structured_cpi, frame_value, raw_cpi_patch,
101    structured_system_transfer, structured_token_transfer, system_transfer_template,
102    with_owner_signer,
103};
104pub use scratch::{FrameScratch, PlanNewFrameParams, PlanNewFrameResult};
105pub use typed::ScratchValue;
106pub use wire_ix::{AssertMultiArgs, IfElseArgs};