Skip to main content

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. Version 0.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

Install viem directly because your application creates and passes viem clients to the SDK. Node.js >=18 is required.

Client Initialization

Create a read-only client with a publicClient, or include a walletClient for swaps, approval changes, LP-admin writes, and yield accrual.
The client exposes eight modules: The selected deployment and underlying viem clients remain available as ml.deployment, ml.publicClient, and ml.walletClient.

Live Deployment Metadata

The static mainnet 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 by bytes32 IDs rather than token addresses:
Asset IDs are not derived from token addresses. Always use the IDs in the selected deployment config or the Deployments page.

Route Model

Every route uses the same SwapInputs structure:
The route ID selects the asset family and amount direction: 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 assetInID or assetOutID. The selected side determines which LP delegate executes the exchange.
  • Prefunded aliases use the same delegate rule as their base route family.
For stablecoin-to-stablecoin routes, input-delegate and output-delegate forms are distinct signed instructions because stablecoinDelegateID is included in SwapInputs. 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 assetOutAmt for exact-in swaps.
  • A maximum assetInAmt for exact-out swaps.
Using the quoted amount exactly provides zero tolerance and may cause a safe revert if state moves. The SDK never writes quote results back into execution bounds automatically.

Quoting

ml.quote.quoteSwap calls the single on-chain quoteSwap(user, input) view function for every route.

Prospective Exact-In Quote

The result also contains 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
It does not check:
  • 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
This means an unfunded address can request a prospective price. For yield-bearing inputs, use the address whose stored yield state you intend to model.

Quote Versus Simulation

Pass simulate: 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.
For delegated simulation, provide the operator, receiver, and permit so msg.sender and authorization match the intended submission:

Executing Swaps

All routes use ml.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:
Do not attach an EIP-712 swap permit to a direct user-submitted swap. The contract rejects a permit when the operator and user are the same address.

Multi-Leg Batch

A single transaction can execute an ordered array of requested legs:
The entire batch is atomic. A failure in any requested or internally derived leg reverts every transfer, approval spend, and permit nonce change.

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 exports erc20Abi, but does not automatically approve tokens or provide ERC-2612 helpers.
For exact-out swaps, approve at least the chosen maximum 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:
Omitted receivers resolve to the user and omitted permits resolve to an empty permit.

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 by user, operator, and assetInID:
adjustSwapInputAllowance applies a delta:
  • increase: true adds amount.
  • increase: false subtracts amount and reverts on underflow.
  • 2^256 - 1 behaves as an infinite allowance and is not decremented.
  • Exact-out routes consume the resolved input, not the submitted maximum.
The operator submits without a permit and must return output to the user:
Direct user swaps do not consume standing allowances.

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.
The permit can authorize a single requested leg or an ordered multi-leg batch because it binds the complete 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:
The signed message binds:
  • 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 MultiliquidSwap address
The EIP-712 domain is:
The domain version is the protocol’s EIP-712 version ("2"), independent of the npm package version. Read the nonce and domain separator directly when needed:
For ERC-1271 smart accounts or external signing infrastructure, build the typed data without invoking the connected wallet:
The contract accepts standard 65-byte ECDSA, compact EIP-2098 signatures, ERC-1271 contract signatures, and EIP-7702 delegated-account ECDSA signatures. 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

The ml.assets module provides read-only asset, price, fee, and eligibility information.

Asset Information and Prices

Prices and fee rates use WAD precision where 1e18 represents 1.0.

Fee Configuration

Individual reads are also available through 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

For individual reads:

LP Admin Operations

The ml.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.
Supported writes include:
  • addIssuerAdmin and removeIssuerAdmin
  • whitelistRWA and whitelistStablecoin
  • setRWADiscountRate and setRWARedemptionFee
  • setStablecoinAcceptanceFee and setStablecoinRedemptionFee
  • setAutoLiquidityStablecoinID
  • setRWACustodyAddress and setStablecoinCustodyAddress
  • setBlacklist
  • addRWAColdStorageAddress and removeRWAColdStorageAddress
  • addStablecoinColdStorageAddress and removeStablecoinColdStorageAddress
  • Delegate pause and unpause
For multisigs, smart accounts, or offline proposal construction:

Yield Operations

The yield module rejects stablecoins that are not configured as yield-bearing.
Calculate yield-adjusted amounts without changing state:
Accrue all currently available work by omitting limits, or bound both daily accrual and withheld-record merges for predictable gas:
Both explicit limits must be nonzero. The unlimited form passes uint256.max for both limits, matching the swap contract’s internal synchronization path.

Event Monitoring

Version 0.2.0 exposes the production contract’s unified Swap event.

Historical Events

Filters support user, rwaID, stablecoinID, eventTypes: ["Swap"], fromBlock, and toBlock.

Live Events

Parse an arbitrary raw log with:
Internal prefund and sweep executions also emit 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:
The SDK uses the deployment’s 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 Solidity Error(string) and Panic(uint256) payloads are also preserved.
When using simulate: true, execution errors are returned in quote.simulation.error rather than submitted on-chain.

Custom Deployments

Provide a ChainDeployment for another EVM deployment:
Addresses omitted from the optional maps are resolved on-chain where the corresponding module supports resolution.

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

  1. Build the exact bounded SwapInputs before signing or simulating.
  2. Re-quote unchanged signed inputs immediately before JIT funding and submission.
  3. Distinguish ERC-20 delegate allowance from Multiliquid operator authorization.
  4. Use simulate: true when current user funds and custody conditions should be tested.
  5. Use prospective view quotes when the user or LP is intentionally not funded yet.
  6. Keep EIP-712 deadlines short and serialize permits per user nonce.
  7. Use multicall and bulk asset methods for dashboards and discovery.
  8. Wait for receipts in your application; SDK write methods return transaction hashes.
  9. Test direct, standing-allowance, permit, exact-in, exact-out, and prefunded routes on Sepolia.

Support and Resources