swap() function on the GPv2Settlement contract.
Interfaces
Swap
Represents a Balancer swap used for settling a single order against Balancer pools.The ID of the Balancer pool to swap against
Address of the input token
Address of the output token
The amount to swap. For sell orders, this is the input amount. For buy orders, this is the output amount.
Optional pool-specific user data required for certain pool types
BatchSwapStep
An encoded Balancer swap step that can be passed to the settlement contract.The ID of the Balancer pool
Index of the input token in the tokens array
Index of the output token in the tokens array
The swap amount
Pool-specific user data (empty if not needed)
SwapExecution
Parameters for swap execution that allow tighter slippage control.The limit amount for the swap. This allows solvers to specify tighter slippage than the order’s limit to reduce MEV.
EncodedSwap
A tuple representing a fully encoded swap ready for the settlement contract.SwapEncoder Class
A builder class for encoding swap calldata step-by-step.Constructor
The EIP-712 domain for signing orders
Properties
Array of token addresses used in the encoded swaps (read-only)
Array of encoded swap steps (read-only)
The encoded trade (throws if not yet encoded)
Methods
encodeSwapStep
Encodes swap steps and appends them to the encoder.One or more swaps to encode
encodeTrade
Encodes a trade from a signed order.The order to encode
The signature for the order
Optional execution parameters for tighter limits
signEncodeTrade
Signs an order and encodes a trade in one step.The order to sign and encode
The signer for the order
The signing scheme to use (EIP712 or ETHSIGN)
Optional execution parameters
encodedSwap
Returns the complete encoded swap data.Tuple of [swaps, tokens, trade] ready for the settlement contract
encodeSwap (static)
Utility method for encoding a swap in one call. Has multiple overloads:Usage Examples
Encode a Direct Balancer Swap
Multi-Hop Swap Through Multiple Pools
Tighter Slippage Control
Functions
encodeSwapStep
Standalone function to encode a single swap step.Token registry for mapping addresses to indices
The swap to encode
Encoded swap step with token indices
Notes
The swap module is specifically for direct settlement against Balancer pools using the
swap() function. For settlements with multiple orders and interactions, use the SettlementEncoder class instead.The
userData field in swaps is pool-implementation specific. Most standard Balancer pools don’t require it, but specialized pools might use it for additional parameters.Related
Settlement Encoding
Full settlement encoding with multiple trades
Vault Module
Balancer Vault integration utilities
