Skip to main content

Crate multiliquid_svm_sdk

Crate multiliquid_svm_sdk 

Source
Expand description

§Multiliquid SVM SDK for Rust

Quote swaps, read accounts, and build unsigned transactions for Multiliquid’s swap and Treasury programs on Solana. Uses native types from the split Solana crates (solana-address, solana-instruction, solana-message, solana-transaction), with no solana-sdk, Anchor, or Node.js runtime dependency.

crates.io · API reference · Protocol documentation

§Quickstart

Use stable Rust 1.89 or later. Create an application and install the SDK:

cargo new multiliquid-quickstart
cd multiliquid-quickstart
cargo add multiliquid-svm-sdk@0.2.0

Replace src/main.rs with this program to list known mainnet pairs from the bundled registry:

use multiliquid_svm_sdk::{get_offline_pairs, Cluster};

fn main() {
    for pair in get_offline_pairs(Cluster::MainnetBeta, None) {
        println!(
            "pair={} quote={} base={} lp={}",
            pair.pair, pair.quote_mint, pair.base_mint, pair.liquidity_provider,
        );
    }
}

Run cargo run. This first example needs no RPC endpoint or wallet and also works with default features disabled. Registry entries describe known addresses; current liquidity and trading status require on-chain reads.

To fetch accounts and oracle state and calculate a swap quote, follow the HTTP quote walkthrough. It includes a complete Tokio program, dependencies, and environment settings that you can use in this application. The program is compiled in CI but has not been run against live mainnet state.

§Features and configuration

The default http feature provides HttpRpcClient, a reqwest/rustls RPC transport, and HTTP registry access. For offline operations or a custom Rpc implementation, install with --no-default-features. MultiliquidClient defaults to devnet; select Cluster::MainnetBeta in MultiliquidClientConfig when using a mainnet RPC endpoint. Commitment and HTTP settings belong to the RPC transport. See the integration guide for client configuration and custom transports.

§Common operations

TaskAPIParameters
Quote a swapclient.get_quote(&params).await?SwapParams
Build a swap transactionclient.build_swap_transaction(&params).await?SwapParams
Add or remove liquidityclient.build_add_liquidity_transaction(...), client.build_remove_liquidity_transaction(...)LpLiquidityParams
Fund an LP’s protocol-fee accountclient.build_fund_lp_fee_vault_transaction(&params).await?FundLpFeeVaultParams
Discover pairsclient.get_offline_pairs(None) or client.discover_pairs(None).await?Optional PairFilters
List capital providers (http feature)client.get_capital_providers(None).await?Optional CapitalProviderFetchOptions
Use program instructions and account codecsswap_program_client, treasury_program_client

Each parameter type documents its fields, including defaults for optional token accounts and slippage bounds. The HTTP quote walkthrough builds a complete SwapParams. Capital provider info comes from the Multiliquid API and is optional; builders never require it.

Amounts are in native token units (u64); quote calculations use checked u128 math. Transaction builders return unsigned v0 transactions. Your application supplies slippage bounds, signing, and submission.

treasury_program_client decodes every populated pending deposit in reallocated Treasury user positions. The original fixed 50-slot Treasury ABI remains available in generated::treasury. SWAP_IDL and TREASURY_IDL are the bundled IDLs as JSON strings.

§Integration notes

  • Program compatibility: the bundled production ABI includes optional amount_threshold bounds. Older instruction layouts are incompatible.
  • Liquidity hooks: Treasury-enabled transfer-hook assets are unsupported by all add/remove-liquidity convenience builders, including exact-out removal. Treasury-backed swap hook planning is supported.
  • Quotes and transactions: account state can change between quoting and execution. Rebuild and simulate before submitting.
  • LP fee vaults: swaps pay protocol fees from the liquidity provider’s fee-token account and fail until it exists and is funded. Swap builders reject a missing or empty account; see the integration guide.

§Guides and examples

These guides and complete examples are published with the API reference and require no repository access:

Rust and TypeScript releases are versioned independently. Licensed under MIT.

Re-exports§

pub use accounts::check_pause_status;
pub use accounts::decode_asset_config;
pub use accounts::decode_global_config;
pub use accounts::decode_lp_protocol_fee_config;
pub use accounts::decode_lp_stable_config;
pub use accounts::decode_pair;
pub use accounts::decode_user_vault_info_used;
pub use accounts::fetch_asset_config;
pub use accounts::fetch_global_config;
pub use accounts::fetch_global_config_and_pair;
pub use accounts::fetch_lp_protocol_fee_config;
pub use accounts::fetch_lp_stable_config;
pub use accounts::fetch_pair;
pub use accounts::fetch_swap_state;
pub use accounts::fetch_user_vault_info_used;
pub use accounts::resolve_swap_pair;
pub use client::MultiliquidClient;
pub use client::MultiliquidClientConfig;
pub use error::Result;
pub use error::SdkError;
pub use errors::create_no_liquidity_error;
pub use errors::create_no_user_funds_error;
pub use errors::parse_simulation_program_error;
pub use errors::parse_simulation_program_error_from_logs;
pub use errors::parse_swap_error;
pub use errors::parse_synthetic_simulation_error;
pub use errors::parse_treasury_error;
pub use errors::swap_error_category;
pub use errors::ParsedProgramError;
pub use errors::ParsedSimulationProgramError;
pub use errors::ProgramErrorMetadata;
pub use errors::SwapErrorMetadata;
pub use errors::SWAP_ERROR_MAP;
pub use errors::TREASURY_ERROR_MAP;
pub use events::decode_swap_executed_event;
pub use events::parse_swap_events_from_logs;
pub use events::parse_swap_events_from_transaction;
pub use format::to_human_readable;
pub use format::to_human_readable_signed;
pub use format::to_native_amount;
pub use generated::swap as swap_program_client;
pub use generated::swap::IDL as SWAP_IDL;
pub use generated::treasury::IDL as TREASURY_IDL;
pub use lp::build_add_liquidity_instruction;
pub use lp::build_add_liquidity_transaction;
pub use lp::build_close_pair_instruction;
pub use lp::build_close_pair_transaction;
pub use lp::build_fund_lp_fee_vault_instruction;
pub use lp::build_fund_lp_fee_vault_transaction;
pub use lp::build_init_pair_instruction;
pub use lp::build_init_pair_transaction;
pub use lp::build_remove_liquidity_instruction;
pub use lp::build_remove_liquidity_transaction;
pub use lp::build_update_pair_instruction;
pub use lp::build_update_pair_transaction;
pub use math::bps_to_fixed_point;
pub use math::calculate_protocol_fee_amount;
pub use math::calculate_spread_protocol_fee_rate;
pub use math::calculate_swap_results;
pub use math::ceil_div;
pub use math::SWAP_FIXED_POINT_SCALE;
pub use math::SWAP_ONE_BPS_FIXED_POINT;
pub use oracle::calculate_nav;
pub use oracle::read_i32_le;
pub use oracle::read_i64_le;
pub use oracle::read_u64_le;
pub use oracle::resolve_oracle_accounts;
pub use oracle::resolve_pyth_oracle_accounts;
pub use pda::canonicalize_pair_mints;
pub use pda::derive_asset_config;
pub use pda::derive_associated_token_account;
pub use pda::derive_fee_vault;
pub use pda::derive_global_config;
pub use pda::derive_lp_fee_vault;
pub use pda::derive_lp_fee_vault_authority;
pub use pda::derive_lp_protocol_fee_config;
pub use pda::derive_lp_stable_config;
pub use pda::derive_pair;
pub use pda::derive_program_authority;
pub use pda::derive_program_data;
pub use pda::derive_treasury_apy_entry;
pub use pda::derive_treasury_asset_config;
pub use pda::derive_treasury_global_config;
pub use pda::derive_treasury_user_position;
pub use pda::derive_treasury_vault;
pub use pda::derive_treasury_vault_authority;
pub use pda::derive_user_vault_info;
pub use pda::derive_vault;
pub use pda::derive_vault_authority;
pub use quote::get_quote;
pub use quote::get_quote_via_simulation;
pub use quote_core::compute_swap_quote;
pub use quote_core::compute_swap_quote_from_resolved_inputs;
pub use quote_core::fetch_cluster_unix_timestamp;
pub use quote_core::fetch_oracle_account_data_map;
pub use quote_core::quote_requires_cluster_timestamp;
pub use quote_core::SwapQuoteResolvedInputs;
pub use quote_core::CLUSTER_TIMESTAMP_LOOKBACK_SLOTS;
pub use registry::discover_pairs;
pub use registry::get_mainnet_rwa_transfer_hook;
pub use registry::get_offline_pairs;
pub use registry::DEFAULT_REGISTRY_API_URL;
pub use registry::DEFAULT_REGISTRY_FETCH_TIMEOUT_MS;
pub use registry::DEVNET_PAIRS;
pub use registry::MAINNET_PAIRS;
pub use registry::MAINNET_RWA_TRANSFER_HOOKS;
pub use registry::PAIR_REGISTRY;
pub use registry::get_capital_providers;
pub use registry::get_pairs;
pub use rpc::HttpRpcClient;
pub use rpc::Rpc;
pub use rpc::RpcFilter;
pub use rpc::SimulationResult;
pub use swap::build_swap_instruction;
pub use swap::build_swap_transaction;
pub use token::create_associated_token_account_idempotent_instruction;
pub use token::create_transfer_checked_instruction;
pub use token::detect_token_program;
pub use token::detect_token_program_from_account_info;
pub use token::ensure_ata_instructions;
pub use token::fetch_mint_account_contexts;
pub use token::merge_account_metas;
pub use token::parse_mint_account_context;
pub use token::read_mint_decimals;
pub use token::read_token_account_amount;
pub use token::resolve_transfer_hook_accounts;
pub use token::resolve_transfer_hook_accounts_for_program;
pub use token::MintAccountContext;
pub use token::TransferHookTransfer;
pub use transaction::build_unsigned_transaction;
pub use treasury::decode_treasury_user_position_account;
pub use treasury::decode_treasury_user_position_with_pending_deposits;
pub use treasury::encode_treasury_user_position_with_pending_deposits;
pub use treasury::fetch_all_maybe_treasury_user_position_accounts;
pub use treasury::fetch_all_treasury_user_position_accounts;
pub use treasury::fetch_maybe_treasury_user_position_account;
pub use treasury::fetch_treasury_user_position_account;
pub use treasury::fetch_treasury_user_position_with_pending_deposits;
pub use treasury::TreasuryUserPositionWithPendingDeposits;
pub use treasury_planner::resolve_treasury_liquidity_plan;
pub use treasury_planner::resolve_treasury_swap_plan;
pub use treasury_planner::ResolveTreasuryLiquidityPlanInput;
pub use treasury_planner::ResolveTreasurySwapPlanInput;
pub use treasury_planner::TreasuryLiquidityPlan;
pub use treasury_planner::TreasuryLiquidityPlanAccounts;
pub use treasury_planner::TreasuryOperation;
pub use treasury_planner::TreasurySwapPlan;
pub use treasury_planner::TreasurySwapPlanAccounts;
pub use validation::assert_bps;
pub use validation::assert_positive_amount;
pub use validation::assert_u16;
pub use validation::assert_u64_amount;
pub use constants::*;
pub use types::*;

Modules§

accounts
Account decoding, read-only fetching, and stored-order swap resolution.
client
Cluster-aware convenience API over the native, read-only SDK modules.
constants
Program addresses, PDA seeds, and account-layout constants shared with the npm SDK.
error
errors
IDL error metadata and invocation-scoped simulation diagnostics.
events
Swap event decoding and program-scoped transaction log parsing.
format
Exact integer-string amount conversion, without floating-point arithmetic.
generated
Native Solana clients generated from the npm SDK’s checked-in IDLs.
guides
Integration guides and runnable examples, published alongside the API reference.
liquidity
Unsigned add/remove liquidity workflows matching the checked-in npm SDK.
lp
Pair lifecycle builders and the LP liquidity namespace.
math
Integer swap and protocol-fee math matching the TypeScript SDK’s rounding order.
oracle
Oracle account resolution and nine-decimal NAV evaluation.
pda
Pure PDA derivation using the same seeds and signer domains as the npm SDK.
quote
RPC-backed local quotes and unsigned on-chain simulation quotes.
quote_core
Local swap quotes with the npm SDK’s fee conversion and rounding order.
registry
Bundled deployment metadata, API-backed registry, and read-only RPC discovery.
rpc
Read-only Solana RPC and unsigned transaction simulation.
swap
Swap assembly in the deployed pair’s stored quote/base orientation.
token
SPL Token and Token-2022 account helpers and transfer-hook resolution.
transaction
Unsigned version-0 transactions without compute-budget or submission policy.
treasury
Realloc-aware treasury user positions and read-only account fetchers.
treasury_planner
Read-only discovery of Treasury CPI accounts in protocol remaining-account order.
treasury_program_client
Treasury program facade with realloc-aware position decoding and fetching.
types
Native counterparts of the npm SDK’s public types.
validation
Checked input bounds for high-level builders.

Structs§

Account
An Account with data that is stored on chain
AccountMeta
Describes a single account read or written by a program during instruction execution.
CommitmentConfig
Hash
A hash; the 32-byte output of a hashing algorithm.
Instruction
A directive for a single invocation of a Solana program.
Signature
A 64-byte Ed25519 signature.
VersionedTransaction
An atomic transaction

Enums§

CommitmentLevel
An attribute of a slot. It describes how finalized a block is at some point in time. For example, a slot is said to be at the max level immediately after the cluster recognizes the block at that slot as finalized. When querying the ledger state, use lower levels of commitment to report progress and higher levels to ensure state changes will not be rolled back.
VersionedMessage
Either a legacy message, v0 or a v1 message.

Type Aliases§

Pubkey
A Solana account address.