From ad086ee05d4dea597cc5f77fc117344d588bc2fc Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Mon, 25 Nov 2024 16:01:54 -0500 Subject: [PATCH] create a deep copy of pools in v4 encodeRouteToPath --- sdks/v4-sdk/src/utils/encodeRouteToPath.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdks/v4-sdk/src/utils/encodeRouteToPath.ts b/sdks/v4-sdk/src/utils/encodeRouteToPath.ts index a9a626f1d..efb2ecfbb 100644 --- a/sdks/v4-sdk/src/utils/encodeRouteToPath.ts +++ b/sdks/v4-sdk/src/utils/encodeRouteToPath.ts @@ -11,8 +11,10 @@ export type PathKey = { } export const encodeRouteToPath = (route: Route, exactOutput?: boolean): PathKey[] => { + // 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 pools = exactOutput ? route.pools.reverse() : route.pools let pathKeys: PathKey[] = [] for (let pool of pools) {