UNPKG

@uniswap/v4-sdk

Version:

⚒️ An SDK for building applications on top of Uniswap V4

22 lines 938 B
import { ADDRESS_ZERO } from '../internalConstants'; export const encodeRouteToPath = (route, exactOutput) => { // create a deep copy of pools so that we don't tamper with pool array on route let pools = route.pools.map((p) => p); if (exactOutput) pools = pools.reverse(); let startingCurrency = exactOutput ? route.pathOutput : route.pathInput; let pathKeys = []; for (let pool of pools) { const nextCurrency = startingCurrency.equals(pool.currency0) ? pool.currency1 : pool.currency0; pathKeys.push({ intermediateCurrency: nextCurrency.isNative ? ADDRESS_ZERO : nextCurrency.address, fee: pool.fee, tickSpacing: pool.tickSpacing, hooks: pool.hooks, hookData: '0x', }); startingCurrency = nextCurrency; } return exactOutput ? pathKeys.reverse() : pathKeys; }; //# sourceMappingURL=encodeRouteToPath.js.map