Skip to main content

Execute a Trade

Direct settlement calls multiswap on the Dispatcher.

function multiswap(
address pool,
Amount[] payAssets,
Allocation[] receiveAssets
) external payable;

For direct execution, msg.sender is the payer, recipient, and native-value source.

Settlement structs

type Amount = {
tokenAddress: Address;
amount: bigint; // token base units
};

type Allocation = {
tokenAddress: Address;
allocation: bigint; // 1_000_000 = 100%
minAmount: bigint; // token base units
};

Unlike the quote ABI, these fields do not use packed Float encoding.

Viem example

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,
});

ERC-20 approvals

For an external ERC-20 pay asset, the payer must approve the Dispatcher to transfer at least the submitted amount. Approve the exact trade amount when practical and do not approve a module implementation address.

Native assets

Multiswap represents the native asset internally with:

0xE0092BfAe8c1A1d8CB953ed67bd42A4861E423F9

When paying the native asset:

  • use that sentinel as tokenAddress,
  • set transaction value to the sum of native pay amounts,
  • do not use the zero address,
  • do not include extra native value.

Settlement enforces the expected native value exactly.

Before submission

Verify:

  1. chain ID and Dispatcher,
  2. pool identity,
  3. token addresses and decimals,
  4. receive allocations sum to 1_000_000,
  5. every minAmount is derived from a fresh settlement quote,
  6. ERC-20 allowance or native value is sufficient.

Wait for the transaction receipt and compare realized transfers with the signed minimums and quoted accounting output.