@uniswap/v4-sdk
Version:
⚒️ An SDK for building applications on top of Uniswap V4
26 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeRouteToPath = void 0;
const internalConstants_1 = require("../internalConstants");
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 ? internalConstants_1.ADDRESS_ZERO : nextCurrency.address,
fee: pool.fee,
tickSpacing: pool.tickSpacing,
hooks: pool.hooks,
hookData: '0x',
});
startingCurrency = nextCurrency;
}
return exactOutput ? pathKeys.reverse() : pathKeys;
};
exports.encodeRouteToPath = encodeRouteToPath;
//# sourceMappingURL=encodeRouteToPath.js.map