Execute a Trade
Call multiswap(pool, payAssets, receiveAssets) on the Dispatcher. Direct execution uses msg.sender as payer and recipient.
Settlement types
type Amount = {
tokenAddress: Address;
amount: bigint; // token base units
};
type Allocation = {
tokenAddress: Address;
allocation: bigint; // six decimals: 1_000_000 = 100%
minAmount: bigint; // token base units
};
These settlement fields use ordinary integer encoding. Receive allocations must sum exactly to 1_000_000.
Example
The following example pays one USDC token when the selected USDC has six decimals. Token addresses, ABI, client, account, and minAmount must already be resolved for the selected pool.
const hash = await walletClient.writeContract({
account,
address: dispatcher,
abi: multiswapAbi,
functionName: "multiswap",
args: [
pool,
[{ tokenAddress: usdc, amount: 1_000_000n }],
[{ tokenAddress: usdt, allocation: 1_000_000n, minAmount }],
],
value: 0n,
});
Add entries to build a basket. Both sides must be nonempty and every token must have the required Reserve Asset role. Use each token exactly once across the complete order.
Approvals and native value
For external ERC-20 pay tokens, the payer approves the Dispatcher. Internal ledger tokens and native assets use their corresponding settlement paths.
The native-asset sentinel is:
0xE0092BfAe8c1A1d8CB953ed67bd42A4861E423F9
When a native asset is paid, use that address and attach the exact expected native pay amount as transaction value. Use the sentinel and the exact native pay value. Native currency used only for gas is separate.
Settlement
Execution reads current pool state, requests its execution quote through the Dispatcher, checks invariants and minimum receives, and applies the token/ledger movements. A failed constraint reverts the complete exchange.
Wait for the transaction receipt. Confirm successful execution through the receipt, realized transfers, and accounting events.
For delegated submission, see Signed Intents.