Integration Overview
The official Multiliquid TypeScript SDK is built on viem and provides type-safe access to quoting, swap execution, delegated authorization, auto-liquidity previews, asset and delegate reads, LP administration, yield accounting, events, and multicall. Version0.2.0 follows the production MultiliquidSwap interface directly:
- One route-tagged
quoteSwap(user, input)view function quotes every route. - One
swap(user, receiver, inputs, permit)function executes one or more requested legs. - Standing input allowances and EIP-712 one-shot permits authorize delegated execution.
- Prefunded route IDs let the contract derive just-in-time LP liquidity legs internally.
Route Model
Understand route IDs, exact-in, exact-out, and delegate selection
Quotes and Simulation
Price hypothetical swaps or test complete settlement
Delegated Authorization
Use standing allowances or one-time EIP-712 permits
Auto-Sweep
LP prefund, sweep, and JIT liquidity configuration workflows
Asset Queries
Read assets, prices, fees, eligibility, and protocol status
LP Administration
Manage delegate configuration directly or through a multisig
Installation
>=18 is required.
Client Initialization
Create a read-only client with apublicClient, or include a walletClient for swaps, approval changes, LP-admin writes, and yield accrual.
The selected deployment and underlying viem clients remain available as
ml.deployment, ml.publicClient, and ml.walletClient.
Live Deployment Metadata
The staticmainnet and sepolia presets ship with the package. To load the latest EVM deployment metadata from the Multiliquid API:
loadEvmDeployment validates the response, merges current contract addresses and assets into the selected chain preset, and rejects mismatched chain IDs or malformed addresses.
Asset IDs
The protocol identifies assets bybytes32 IDs rather than token addresses:
Route Model
Every route uses the sameSwapInputs structure:
Even route IDs are exact-in and odd route IDs are exact-out.
Amount Semantics
The view quote ignores the execution-bound field. Settlement recalculates the quote from current state and enforces that signed or submitted bound.
Delegate Selection
stablecoinDelegateID selects the stablecoin LP domain that provides custody, compliance, and fee configuration:
- Stablecoin → RWA: use
assetInID. - RWA → stablecoin: use
assetOutID. - RWA → RWA: select the accepted stablecoin delegate used for the route.
- Stablecoin → stablecoin: select either
assetInIDorassetOutID. The selected side determines which LP delegate executes the exchange. - Prefunded aliases use the same delegate rule as their base route family.
stablecoinDelegateID is included in SwapInputs.
NAV-Based Pricing and Bounds
Multiliquid pricing is based on NAV, configured fee schedules, decimal normalization, and—where applicable—yield state. It does not use AMM reserves or apply price impact based on trade size. The quote can still change between signing and execution when an oracle price, fee, guardrail, protocol exemption, or yield state changes. Integrations must deliberately set:- A minimum
assetOutAmtfor exact-in swaps. - A maximum
assetInAmtfor exact-out swaps.
Quoting
ml.quote.quoteSwap calls the single on-chain quoteSwap(user, input) view function for every route.
Prospective Exact-In Quote
routeFamily, direction, timestamp, and the normalized input.
Prospective Exact-Out Quote
What a View Quote Validates
The view quote validates route configuration and current pricing state, including:- Route and delegate selection
- Asset acceptance
- Price adapters and nonzero RWA prices
- Stablecoin price guardrails
- Current fee configuration
- User-specific state needed to price yield-bearing inputs
- User token balances
- ERC-20 allowances
- Standing delegated swap allowances
- RWA recipient whitelisting
- LP or delegate custody inventory
- Whether all settlement transfers can currently complete
Quote Versus Simulation
Passsimulate: true to additionally run the real swap(user, receiver, [input], permit) path as an eth_call:
Simulation does not submit a transaction, but it does exercise current
settlement conditions. An unfunded user can receive a view quote while the
simulated swap correctly fails.
msg.sender and authorization match the intended submission:
Executing Swaps
All routes useml.swap.swap. It maps directly to swap(user, receiver, inputs, permit) and returns a transaction hash without waiting for a receipt.
Direct Swap
When the connected wallet is the user,user defaults to the wallet account and receiver defaults to the user:
Multi-Leg Batch
A single transaction can execute an ordered array of requested legs:ERC-20 Token Allowance
For each requested leg, the selected stablecoin delegate executes token movements and is the ERC-20 spender for the user’s input. The SDK exportserc20Abi, but does not automatically approve tokens or provide ERC-2612 helpers.
assetInAmt. Token allowance is separate from Multiliquid’s delegated swap authorization described below.
Build Calldata Without Sending
For smart-account batches, relayers, multisigs, or custom transaction submission:Delegated Authorization
Multiliquid supports two protocol-level mechanisms for an operator to submit swaps using another user’s assets:
Neither mechanism replaces the ERC-20 allowance granted to the selected stablecoin delegate.
Standing Input Allowances
The user adjusts an allowance keyed byuser, operator, and assetInID:
adjustSwapInputAllowance applies a delta:
increase: trueaddsamount.increase: falsesubtractsamountand reverts on underflow.2^256 - 1behaves as an infinite allowance and is not decremented.- Exact-out routes consume the resolved input, not the submitted maximum.
EIP-712 One-Shot Permits
The primary purpose of an EIP-712 one-shot permit is to separate the three execution identities for one authorized transaction:- The user owns the input assets and signs the permit.
- The operator submits the transaction and can be different from the user.
- The receiver receives the output and can be different from both the user and operator.
SwapInputs[] array. Batch support is available, but identity separation—not batching—is the reason to use the permit.
For one-time authorization, the user signs the code-defined SwapBatchApproval typed message:
signSwapApproval reads the current nonce automatically when nonce is omitted. The operator must submit the exact same user, receiver, ordered input array, and permit:
- User, operator, and receiver
- The complete ordered
SwapInputs[]array - Every route ID, asset ID, delegate ID, amount, and execution bound
- Current user nonce and deadline
- Chain ID and verifying
MultiliquidSwapaddress
"2"), independent of the npm package version.
Read the nonce and domain separator directly when needed:
signSwapApproval requires the connected signer to match user; use buildSwapApprovalTypedData for contract-account signing flows.
Successful permit execution increments the user’s nonce once for the signed transaction, whether it contains one requested leg or a multi-leg batch. A later settlement revert rolls the nonce change back, so the same permit can be retried before its deadline if no other permit consumed that nonce.
Auto-Sweep
Auto-Sweep lets an LP designate one stablecoin for working capital. Prefunded routes can convert that asset into required stablecoin inventory before a user swap, while eligible stablecoin-input routes can sweep the LP’s newly received balance back into the designated asset afterward.Auto-Sweep Configuration
Complete LP enablement, allowance, preview, JIT funding, and disablement
workflow
Querying Assets
Theml.assets module provides read-only asset, price, fee, and eligibility information.
Asset Information and Prices
1e18 represents 1.0.
Fee Configuration
isProtocolFeeExempt, getIssuerPaidProtocolFeeRate, and getSpreadProtocolTakeRate.
Eligibility and Protocol Status
isWhitelistedForRWA checks the configured RWA whitelist adapter. A route can still have additional delegate or token-level controls that are only fully exercised during simulation or execution.
Delegate Queries
LP Admin Operations
Theml.issuerAdmin module resolves the selected stablecoin delegate and executes LP-admin methods. The module retains its legacy code-facing name. Reads require a publicClient; writes require an authorized wallet account.
addIssuerAdminandremoveIssuerAdminwhitelistRWAandwhitelistStablecoinsetRWADiscountRateandsetRWARedemptionFeesetStablecoinAcceptanceFeeandsetStablecoinRedemptionFeesetAutoLiquidityStablecoinIDsetRWACustodyAddressandsetStablecoinCustodyAddresssetBlacklistaddRWAColdStorageAddressandremoveRWAColdStorageAddressaddStablecoinColdStorageAddressandremoveStablecoinColdStorageAddress- Delegate
pauseandunpause
Yield Operations
The yield module rejects stablecoins that are not configured as yield-bearing.uint256.max for both limits, matching the swap contract’s internal synchronization path.
Event Monitoring
Version0.2.0 exposes the production contract’s unified Swap event.
Historical Events
user, rwaID, stablecoinID, eventTypes: ["Swap"], fromBlock, and toBlock.
Live Events
Swap events with their actual LP user, operator, receiver, route, and amounts.
Multicall
ml.multicall.read batches arbitrary pure/view calls while preserving each return type:
multicall3 address when configured and otherwise falls back to the canonical Multicall3 address.
Error Handling
Contract calls are decoded into typed SDK errors when the revert ABI is known. Standard SolidityError(string) and Panic(uint256) payloads are also preserved.
simulate: true, execution errors are returned in quote.simulation.error rather than submitted on-chain.
Custom Deployments
Provide aChainDeployment for another EVM deployment:
Constants and ABIs
The package exports route IDs, role IDs, precision constants, Multicall3 defaults, and const-asserted ABIs for direct viem usage:Testing on Sepolia
Integration Best Practices
- Build the exact bounded
SwapInputsbefore signing or simulating. - Re-quote unchanged signed inputs immediately before JIT funding and submission.
- Distinguish ERC-20 delegate allowance from Multiliquid operator authorization.
- Use
simulate: truewhen current user funds and custody conditions should be tested. - Use prospective view quotes when the user or LP is intentionally not funded yet.
- Keep EIP-712 deadlines short and serialize permits per user nonce.
- Use multicall and bulk asset methods for dashboards and discovery.
- Wait for receipts in your application; SDK write methods return transaction hashes.
- Test direct, standing-allowance, permit, exact-in, exact-out, and prefunded routes on Sepolia.
Support and Resources
- Protocol Website: https://www.multiliquid.xyz/
- Deployment Addresses: Deployments
- Contract ABIs: Contract ABIs
- Security Guidance: Security