From 7678e907c1a99e0fb66ba9394e6b0e3983ba4e69 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 6 Jul 2023 12:36:43 -0300 Subject: [PATCH] Enforce join and exit swap to happen only with weighted pools --- .../src/modules/swaps/joinExit/joinAndExit.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/balancer-js/src/modules/swaps/joinExit/joinAndExit.ts b/balancer-js/src/modules/swaps/joinExit/joinAndExit.ts index ebc8cfcda..45c1ac6d1 100644 --- a/balancer-js/src/modules/swaps/joinExit/joinAndExit.ts +++ b/balancer-js/src/modules/swaps/joinExit/joinAndExit.ts @@ -74,7 +74,12 @@ export function hasJoinExit( * @param assets * @returns */ -export function isJoin(swap: SwapV2, assets: string[]): boolean { +export function isJoin( + swap: SwapV2, + assets: string[], + poolType: string | undefined +): boolean { + if (poolType !== 'Weighted') return false; // token[join]bpt const tokenOut = assets[swap.assetOutIndex]; const poolAddress = getPoolAddress(swap.poolId); @@ -87,7 +92,12 @@ export function isJoin(swap: SwapV2, assets: string[]): boolean { * @param assets * @returns */ -export function isExit(swap: SwapV2, assets: string[]): boolean { +export function isExit( + swap: SwapV2, + assets: string[], + poolType: string | undefined +): boolean { + if (poolType !== 'Weighted') return false; // bpt[exit]token const tokenIn = assets[swap.assetInIndex]; const poolAddress = getPoolAddress(swap.poolId); @@ -143,7 +153,8 @@ export function getActions( const actions: Actions[] = []; let opRefKey = 0; for (const swap of swaps) { - if (isJoin(swap, assets)) { + const poolType = pools.find((p) => p.id === swap.poolId)?.poolType; + if (isJoin(swap, assets, poolType)) { const newJoin = new Join( swap, tokenInIndex, @@ -157,7 +168,7 @@ export function getActions( opRefKey = newJoin.nextOpRefKey; actions.push(newJoin); continue; - } else if (isExit(swap, assets)) { + } else if (isExit(swap, assets, poolType)) { const newExit = new Exit( swap, tokenInIndex,