Path

Functions for encoding and decoding multi-hop swap paths.

Source: contracts/periphery/libraries/Path.sol

Path Format

Paths encode token addresses and fee tiers as packed bytes:

[token0][fee0][token1][fee1][token2]...
  20       3     20      3     20    bytes

Functions

hasMultiplePools

function hasMultiplePools(bytes memory path) internal pure returns (bool)

Returns true if the path contains more than one pool (multi-hop).

numPools

function numPools(bytes memory path) internal pure returns (uint256)

Returns the number of pools in the path.

decodeFirstPool

Decodes the first pool's tokens and fee from the path.

getFirstPool

Returns the first pool's encoded bytes.

skipToken

Skips the first token in the path, returning the remaining path.

JavaScript Implementation

Usage Example

Last updated