Settlement
TypeScript settlement module API for encoding trades, interactions, and clearing prices
Last modified on March 4, 2026
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
TypeScript settlement module API for encoding trades, interactions, and clearing prices
const encoder = new SettlementEncoder(domain: TypedDataDomain);
encoder.encodeTrade(
order: Order,
signature: Signature,
execution?: TradeExecution
): void;
await encoder.signEncodeTrade(
order: Order,
signer: Signer,
scheme: SigningScheme,
execution?: TradeExecution
): Promise<void>;
encoder.encodeInteraction(
interaction: InteractionLike,
stage?: InteractionStage
): void;
encoder.encodedSettlement(
prices: Record<string, BigNumberish>
): EncodedSettlement;
encoder.clearingPrices(
prices: Record<string, BigNumberish>
): BigNumberish[];
const registry = new TokenRegistry();
const index = registry.index(tokenAddress);
enum InteractionStage {
PRE = 0, // Before trading (e.g., permit approvals)
INTRA = 1, // During token swaps (e.g., AMM operations)
POST = 2, // After settlement completion
}
interface TradeExecution {
executedAmount: BigNumberish;
}
type EncodedSettlement = [
string[], // tokens
BigNumberish[], // clearingPrices
Trade[], // trades
Interaction[][], // [pre, intra, post] interactions
];
import {
domain,
SettlementEncoder,
SigningScheme,
InteractionStage,
Order,
OrderKind,
} from "@cowprotocol/contracts";
import { ethers } from "ethers";
const settlementDomain = domain(1, "0x9008D19f58AAbD9eD0D60971565AA8510560ab41");
const encoder = new SettlementEncoder(settlementDomain);
const order: Order = {
sellToken: WETH,
buyToken: DAI,
sellAmount: ethers.utils.parseEther("1"),
buyAmount: ethers.utils.parseEther("2000"),
validTo: Math.floor(Date.now() / 1000) + 3600,
appData: ethers.constants.HashZero,
feeAmount: ethers.utils.parseEther("0.01"),
kind: OrderKind.SELL,
partiallyFillable: false,
receiver: ethers.constants.AddressZero,
};
await encoder.signEncodeTrade(order, wallet, SigningScheme.EIP712);
const settlement = encoder.encodedSettlement({
[WETH]: ethers.utils.parseEther("2000"),
[DAI]: ethers.utils.parseEther("1"),
});
Was this page helpful?