From fc774c598d7aaaea3e2737faca8277c20976e7f7 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Fri, 26 Sep 2025 14:04:14 +0200 Subject: [PATCH 1/3] refactor: replace wrapped with address --- modules/sor/lib/pathGraph/pathGraph.ts | 28 +++++++++---------- .../composableStable/composableStablePool.ts | 4 +-- modules/sor/lib/poolsV2/fx/fxPool.ts | 4 +-- modules/sor/lib/poolsV2/gyro2/gyro2Pool.ts | 4 +-- modules/sor/lib/poolsV2/gyro3/gyro3Pool.ts | 8 +++--- modules/sor/lib/poolsV2/gyroE/gyroEPool.ts | 4 +-- .../lib/poolsV2/metastable/metastablePool.ts | 4 +-- modules/sor/lib/poolsV2/stable/stablePool.ts | 4 +-- .../sor/lib/poolsV2/weighted/weightedPool.ts | 4 +-- modules/sor/lib/poolsV3/buffer/bufferPool.ts | 4 +-- .../sor/lib/poolsV3/gyro2CLP/gyro2CLPPool.ts | 4 +-- .../sor/lib/poolsV3/gyroECLP/gyroECLPPool.ts | 4 +-- .../liquidityBootstrapping.ts | 4 +-- .../sor/lib/poolsV3/quantAmm/quantAmmPool.ts | 4 +-- .../sor/lib/poolsV3/reClamm/reClammPool.ts | 4 +-- modules/sor/lib/poolsV3/stable/stablePool.ts | 4 +-- .../sor/lib/poolsV3/weighted/weightedPool.ts | 4 +-- 17 files changed, 48 insertions(+), 48 deletions(-) diff --git a/modules/sor/lib/pathGraph/pathGraph.ts b/modules/sor/lib/pathGraph/pathGraph.ts index 22cadf28e..027f7a501 100644 --- a/modules/sor/lib/pathGraph/pathGraph.ts +++ b/modules/sor/lib/pathGraph/pathGraph.ts @@ -88,11 +88,11 @@ export class PathGraph { const minLimitThreshold = (swapAmount.amount * BigInt(Math.floor(config.minSwapAmountRatio * 100))) / 100n; const tokenPaths = this.findAllValidTokenPaths({ - token: tokenIn.wrapped, - tokenIn: tokenIn.wrapped, - tokenOut: tokenOut.wrapped, + token: tokenIn.address, + tokenIn: tokenIn.address, + tokenOut: tokenOut.address, config, - tokenPath: [tokenIn.wrapped], + tokenPath: [tokenIn.address], }).sort((a, b) => (a.length < b.length ? -1 : 1)); const paths: PathGraphEdgeData[][] = []; @@ -186,7 +186,7 @@ export class PathGraph { tokens.push(new Token(pool.tokens[0].token.chainId, pool.address.toLowerCase() as Address, 18)); // Add BPT as token nodes } for (const token of tokens) { - if (!this.nodes.has(token.wrapped)) { + if (!this.nodes.has(token.address)) { this.addNode(token); } } @@ -226,12 +226,12 @@ export class PathGraph { } private addNode(token: Token): void { - this.nodes.set(token.wrapped, { - isPhantomBpt: !!this.poolAddressMap.get(token.wrapped), + this.nodes.set(token.address, { + isPhantomBpt: !!this.poolAddressMap.get(token.address), }); - if (!this.edges.has(token.wrapped)) { - this.edges.set(token.wrapped, new Map()); + if (!this.edges.has(token.address)) { + this.edges.set(token.address, new Map()); } } @@ -259,16 +259,16 @@ export class PathGraph { edgeProps: PathGraphEdgeData; maxPathsPerTokenPair: number; }): void { - const tokenInVertex = this.nodes.get(edgeProps.tokenIn.wrapped); - const tokenOutVertex = this.nodes.get(edgeProps.tokenOut.wrapped); - const tokenInNode = this.edges.get(edgeProps.tokenIn.wrapped); + const tokenInVertex = this.nodes.get(edgeProps.tokenIn.address); + const tokenOutVertex = this.nodes.get(edgeProps.tokenOut.address); + const tokenInNode = this.edges.get(edgeProps.tokenIn.address); if (!tokenInVertex || !tokenOutVertex || !tokenInNode) { throw new Error('Attempting to add invalid edge'); } const hasPhantomBpt = tokenInVertex.isPhantomBpt || tokenOutVertex.isPhantomBpt; - const existingEdges = tokenInNode.get(edgeProps.tokenOut.wrapped) || []; + const existingEdges = tokenInNode.get(edgeProps.tokenOut.address) || []; //TODO: ideally we don't call sort every time, this isn't performant const sorted = [...existingEdges, edgeProps].sort((a, b) => @@ -278,7 +278,7 @@ export class PathGraph { // TODO: double check if the hasPhantomBpt issue is not affecting v3 liquidity more frequently (considering all // pools have their BPT artificially added so we consider them for add/remove liquidity steps) tokenInNode.set( - edgeProps.tokenOut.wrapped, + edgeProps.tokenOut.address, sorted.length > maxPathsPerTokenPair && !hasPhantomBpt ? sorted.slice(0, maxPathsPerTokenPair) : sorted, ); } diff --git a/modules/sor/lib/poolsV2/composableStable/composableStablePool.ts b/modules/sor/lib/poolsV2/composableStable/composableStablePool.ts index 14118e1d5..369c2967e 100644 --- a/modules/sor/lib/poolsV2/composableStable/composableStablePool.ts +++ b/modules/sor/lib/poolsV2/composableStable/composableStablePool.ts @@ -299,8 +299,8 @@ export class ComposableStablePool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: PoolTokenWithRate; tOut: PoolTokenWithRate } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV2/fx/fxPool.ts b/modules/sor/lib/poolsV2/fx/fxPool.ts index d60d5d1d6..44b4c97b9 100644 --- a/modules/sor/lib/poolsV2/fx/fxPool.ts +++ b/modules/sor/lib/poolsV2/fx/fxPool.ts @@ -195,8 +195,8 @@ export class FxPool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: FxPoolToken; tOut: FxPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Token not found'); diff --git a/modules/sor/lib/poolsV2/gyro2/gyro2Pool.ts b/modules/sor/lib/poolsV2/gyro2/gyro2Pool.ts index 9eea74cc7..54cb86f5c 100644 --- a/modules/sor/lib/poolsV2/gyro2/gyro2Pool.ts +++ b/modules/sor/lib/poolsV2/gyro2/gyro2Pool.ts @@ -222,8 +222,8 @@ export class Gyro2Pool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: PoolTokenWithRate; tOut: PoolTokenWithRate } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV2/gyro3/gyro3Pool.ts b/modules/sor/lib/poolsV2/gyro3/gyro3Pool.ts index fd84a4c88..58dffb464 100644 --- a/modules/sor/lib/poolsV2/gyro3/gyro3Pool.ts +++ b/modules/sor/lib/poolsV2/gyro3/gyro3Pool.ts @@ -172,8 +172,8 @@ export class Gyro3Pool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); @@ -193,8 +193,8 @@ export class Gyro3Pool implements BasePool { const { tIn, tOut } = this.getPoolTokens(tokenIn, tokenOut); const tertiaryAddress = this.tokens - .map((t) => t.token.wrapped) - .find((a) => a !== tokenIn.wrapped && a !== tokenOut.wrapped); + .map((t) => t.token.address) + .find((a) => a !== tokenIn.address && a !== tokenOut.address); const tertiary = this.tokenMap.get(tertiaryAddress as string); if (!tertiary) { diff --git a/modules/sor/lib/poolsV2/gyroE/gyroEPool.ts b/modules/sor/lib/poolsV2/gyroE/gyroEPool.ts index 9b61b6a87..208ef0be7 100644 --- a/modules/sor/lib/poolsV2/gyroE/gyroEPool.ts +++ b/modules/sor/lib/poolsV2/gyroE/gyroEPool.ts @@ -255,8 +255,8 @@ export class GyroEPool implements BasePool { tIn: PoolTokenWithRate; tOut: PoolTokenWithRate; } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV2/metastable/metastablePool.ts b/modules/sor/lib/poolsV2/metastable/metastablePool.ts index 029249cc4..ac48966b1 100644 --- a/modules/sor/lib/poolsV2/metastable/metastablePool.ts +++ b/modules/sor/lib/poolsV2/metastable/metastablePool.ts @@ -195,8 +195,8 @@ export class MetaStablePool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: PoolTokenWithRate; tOut: PoolTokenWithRate } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV2/stable/stablePool.ts b/modules/sor/lib/poolsV2/stable/stablePool.ts index 101bc7c06..fd11e9faf 100644 --- a/modules/sor/lib/poolsV2/stable/stablePool.ts +++ b/modules/sor/lib/poolsV2/stable/stablePool.ts @@ -185,8 +185,8 @@ export class StablePool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV2/weighted/weightedPool.ts b/modules/sor/lib/poolsV2/weighted/weightedPool.ts index 233d68af3..9424a59f0 100644 --- a/modules/sor/lib/poolsV2/weighted/weightedPool.ts +++ b/modules/sor/lib/poolsV2/weighted/weightedPool.ts @@ -155,8 +155,8 @@ export class WeightedPool implements BasePool { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: WeightedPoolToken; tOut: WeightedPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/buffer/bufferPool.ts b/modules/sor/lib/poolsV3/buffer/bufferPool.ts index 3e89b477e..aad7e0234 100644 --- a/modules/sor/lib/poolsV3/buffer/bufferPool.ts +++ b/modules/sor/lib/poolsV3/buffer/bufferPool.ts @@ -190,8 +190,8 @@ export class BufferPool implements BasePoolMethodsV3 { // Helper methods public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/gyro2CLP/gyro2CLPPool.ts b/modules/sor/lib/poolsV3/gyro2CLP/gyro2CLPPool.ts index b03bea693..e1731c768 100644 --- a/modules/sor/lib/poolsV3/gyro2CLP/gyro2CLPPool.ts +++ b/modules/sor/lib/poolsV3/gyro2CLP/gyro2CLPPool.ts @@ -132,8 +132,8 @@ export class Gyro2CLPPool extends BasePoolV3 implements BasePoolMethodsV3 { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: GyroPoolToken; tOut: GyroPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/gyroECLP/gyroECLPPool.ts b/modules/sor/lib/poolsV3/gyroECLP/gyroECLPPool.ts index 47ad8f83e..399f59b29 100644 --- a/modules/sor/lib/poolsV3/gyroECLP/gyroECLPPool.ts +++ b/modules/sor/lib/poolsV3/gyroECLP/gyroECLPPool.ts @@ -169,8 +169,8 @@ export class GyroECLPPool extends BasePoolV3 implements BasePoolMethodsV3 { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: GyroPoolToken; tOut: GyroPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/liquidityBootstrapping/liquidityBootstrapping.ts b/modules/sor/lib/poolsV3/liquidityBootstrapping/liquidityBootstrapping.ts index 6f7c45e2f..a9ce2840c 100644 --- a/modules/sor/lib/poolsV3/liquidityBootstrapping/liquidityBootstrapping.ts +++ b/modules/sor/lib/poolsV3/liquidityBootstrapping/liquidityBootstrapping.ts @@ -219,8 +219,8 @@ export class LiquidityBootstrappingPoolV3 extends BasePoolV3 implements BasePool } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: WeightedPoolToken; tOut: WeightedPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/quantAmm/quantAmmPool.ts b/modules/sor/lib/poolsV3/quantAmm/quantAmmPool.ts index 57b0bb022..5edbb999c 100644 --- a/modules/sor/lib/poolsV3/quantAmm/quantAmmPool.ts +++ b/modules/sor/lib/poolsV3/quantAmm/quantAmmPool.ts @@ -158,8 +158,8 @@ export class QuantAmmPool extends BasePoolV3 implements BasePoolMethodsV3 { // Helper methods public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: QuantAmmPoolToken; tOut: QuantAmmPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/reClamm/reClammPool.ts b/modules/sor/lib/poolsV3/reClamm/reClammPool.ts index 2a178ea6a..7f23e9cac 100644 --- a/modules/sor/lib/poolsV3/reClamm/reClammPool.ts +++ b/modules/sor/lib/poolsV3/reClamm/reClammPool.ts @@ -149,8 +149,8 @@ export class ReClammPool extends BasePoolV3 implements BasePoolMethodsV3 { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: ReClammPoolToken; tOut: ReClammPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/stable/stablePool.ts b/modules/sor/lib/poolsV3/stable/stablePool.ts index 858244cd8..a407ec600 100644 --- a/modules/sor/lib/poolsV3/stable/stablePool.ts +++ b/modules/sor/lib/poolsV3/stable/stablePool.ts @@ -124,8 +124,8 @@ export class StablePoolV3 extends BasePoolV3 implements BasePoolMethodsV3 { } public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: StablePoolToken; tOut: StablePoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); diff --git a/modules/sor/lib/poolsV3/weighted/weightedPool.ts b/modules/sor/lib/poolsV3/weighted/weightedPool.ts index eef3346fd..ceb7bc957 100644 --- a/modules/sor/lib/poolsV3/weighted/weightedPool.ts +++ b/modules/sor/lib/poolsV3/weighted/weightedPool.ts @@ -130,8 +130,8 @@ export class WeightedPoolV3 extends BasePoolV3 implements BasePoolMethodsV3 { // Helper methods public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: WeightedPoolToken; tOut: WeightedPoolToken } { - const tIn = this.tokenMap.get(tokenIn.wrapped); - const tOut = this.tokenMap.get(tokenOut.wrapped); + const tIn = this.tokenMap.get(tokenIn.address); + const tOut = this.tokenMap.get(tokenOut.address); if (!tIn || !tOut) { throw new Error('Pool does not contain the tokens provided'); From b82ad2895fda646aa7cf9f827abb5473e032e7e7 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Wed, 1 Oct 2025 09:08:53 +0200 Subject: [PATCH 2/3] refactor: type changes --- modules/sor/lib/path.ts | 2 +- modules/sor/lib/poolsV2/basePool.ts | 12 ++++++------ modules/sor/lib/poolsV3/basePoolV3.ts | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/sor/lib/path.ts b/modules/sor/lib/path.ts index 4c992a30b..2363fe7ce 100644 --- a/modules/sor/lib/path.ts +++ b/modules/sor/lib/path.ts @@ -1,4 +1,4 @@ -import { TokenAmount, SwapKind, Token } from '@balancer/sdk'; +import { TokenAmount, SwapKind, BaseToken, Token } from '@balancer/sdk'; import { BasePool } from './poolsV2/basePool'; import { BufferPool } from './poolsV3/buffer/bufferPool'; diff --git a/modules/sor/lib/poolsV2/basePool.ts b/modules/sor/lib/poolsV2/basePool.ts index 9958e9672..d6eeebf80 100644 --- a/modules/sor/lib/poolsV2/basePool.ts +++ b/modules/sor/lib/poolsV2/basePool.ts @@ -1,4 +1,4 @@ -import { PoolType, SwapKind, Token, TokenAmount } from '@balancer/sdk'; +import { PoolType, SwapKind, BaseToken, TokenAmount } from '@balancer/sdk'; import { Hex } from 'viem'; import { BasePoolToken } from '../utils/basePoolToken'; @@ -9,13 +9,13 @@ export interface BasePool { readonly address: string; swapFee: bigint; tokens: BasePoolToken[]; - getNormalizedLiquidity(tokenIn: Token, tokenOut: Token): bigint; - swapGivenIn(tokenIn: Token, tokenOut: Token, swapAmount: TokenAmount, mutateBalances?: boolean): TokenAmount; - swapGivenOut(tokenIn: Token, tokenOut: Token, swapAmount: TokenAmount, mutateBalances?: boolean): TokenAmount; - getLimitAmountSwap(tokenIn: Token, tokenOut: Token, swapKind: SwapKind): bigint; + getNormalizedLiquidity(tokenIn: BaseToken, tokenOut: BaseToken): bigint; + swapGivenIn(tokenIn: BaseToken, tokenOut: BaseToken, swapAmount: TokenAmount, mutateBalances?: boolean): TokenAmount; + swapGivenOut(tokenIn: BaseToken, tokenOut: BaseToken, swapAmount: TokenAmount, mutateBalances?: boolean): TokenAmount; + getLimitAmountSwap(tokenIn: BaseToken, tokenOut: BaseToken, swapKind: SwapKind): bigint; /** * Validate that pool contains tokenIn and tokenOut provided and returns pool specific token data (e.g. balance, index, weight, rate, etc.) */ - getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken }; + getPoolTokens(tokenIn: BaseToken, tokenOut: BaseToken): { tIn: BasePoolToken; tOut: BasePoolToken }; copy(): BasePool; } diff --git a/modules/sor/lib/poolsV3/basePoolV3.ts b/modules/sor/lib/poolsV3/basePoolV3.ts index 37560295b..8c9f4f29d 100644 --- a/modules/sor/lib/poolsV3/basePoolV3.ts +++ b/modules/sor/lib/poolsV3/basePoolV3.ts @@ -1,6 +1,6 @@ import { Hex } from 'viem'; -import { MAX_UINT256, PoolType, SwapKind, Token, TokenAmount } from '@balancer/sdk'; +import { MAX_UINT256, PoolType, SwapKind, BaseToken, TokenAmount } from '@balancer/sdk'; import { AddKind, RemoveKind, Vault, HookState, PoolState } from '@balancer-labs/balancer-maths'; import { Chain } from '@prisma/client'; @@ -55,7 +55,7 @@ export class BasePoolV3 { this.vault = new Vault(); } - public getLimitAmountSwap(tokenIn: Token, tokenOut: Token, swapKind: SwapKind): bigint { + public getLimitAmountSwap(tokenIn: BaseToken, tokenOut: BaseToken, swapKind: SwapKind): bigint { const { tIn, tOut } = this.getPoolTokens(tokenIn, tokenOut); // remove liquidity @@ -90,8 +90,8 @@ export class BasePoolV3 { } public swapGivenIn( - tokenIn: Token, - tokenOut: Token, + tokenIn: BaseToken, + tokenOut: BaseToken, swapAmount: TokenAmount, mutateBalances?: boolean, ): TokenAmount { @@ -163,8 +163,8 @@ export class BasePoolV3 { } public swapGivenOut( - tokenIn: Token, - tokenOut: Token, + tokenIn: BaseToken, + tokenOut: BaseToken, swapAmount: TokenAmount, mutateBalances?: boolean, ): TokenAmount { @@ -235,7 +235,7 @@ export class BasePoolV3 { return TokenAmount.fromRawAmount(tIn.token, calculatedAmount); } - public getNormalizedLiquidity(tokenIn: Token, tokenOut: Token): bigint { + public getNormalizedLiquidity(tokenIn: BaseToken, tokenOut: BaseToken): bigint { const { tIn, tOut } = this.getPoolTokens(tokenIn, tokenOut); const tokenPair = this.tokenPairs.find( @@ -254,7 +254,7 @@ export class BasePoolV3 { throw new Error('Must be implemented by the subclass'); } - public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken } { + public getPoolTokens(tokenIn: BaseToken, tokenOut: BaseToken): { tIn: BasePoolToken; tOut: BasePoolToken } { throw new Error('Must be implemented by the subclass'); } From 4e1c4bad1f5e65dbbd727490d0209856a90a3ba7 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Wed, 1 Oct 2025 14:12:36 +0200 Subject: [PATCH 3/3] refactor: use more BaseToken --- modules/sor/lib/path.ts | 8 ++++---- modules/sor/lib/poolsV3/buffer/bufferPool.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/sor/lib/path.ts b/modules/sor/lib/path.ts index 2363fe7ce..bd7ac0e7a 100644 --- a/modules/sor/lib/path.ts +++ b/modules/sor/lib/path.ts @@ -4,10 +4,10 @@ import { BufferPool } from './poolsV3/buffer/bufferPool'; export class PathLocal { public readonly pools: BasePool[]; - public readonly tokens: Token[]; + public readonly tokens: BaseToken[]; public readonly isBuffer: boolean[]; - public constructor(tokens: Token[], pools: BasePool[], isBuffer: boolean[]) { + public constructor(tokens: BaseToken[], pools: BasePool[], isBuffer: boolean[]) { if (pools.length === 0 || tokens.length < 2) { throw new Error('Invalid path: must contain at least 1 pool and 2 tokens.'); } @@ -35,7 +35,7 @@ export class PathWithAmount extends PathLocal { public readonly swapStepsGreaterThanBufferLimit: number = 0; public constructor( - tokens: Token[], + tokens: BaseToken[], pools: BasePool[], isBuffer: boolean[], swapAmount: TokenAmount, @@ -46,7 +46,7 @@ export class PathWithAmount extends PathLocal { this.mutateBalances = Boolean(mutateBalances); //call to super ensures this array access is safe - if (tokens[0].isUnderlyingEqual(swapAmount.token)) { + if (tokens[0].isSameAddress(swapAmount.token.address)) { this.swapKind = SwapKind.GivenIn; } else { this.swapKind = SwapKind.GivenOut; diff --git a/modules/sor/lib/poolsV3/buffer/bufferPool.ts b/modules/sor/lib/poolsV3/buffer/bufferPool.ts index aad7e0234..8c31f599a 100644 --- a/modules/sor/lib/poolsV3/buffer/bufferPool.ts +++ b/modules/sor/lib/poolsV3/buffer/bufferPool.ts @@ -1,5 +1,5 @@ import { Address, Hex } from 'viem'; -import { MAX_UINT256, SwapKind, Token, TokenAmount } from '@balancer/sdk'; +import { MAX_UINT256, SwapKind, Token, TokenAmount, BaseToken } from '@balancer/sdk'; import { BufferState, Vault } from '@balancer-labs/balancer-maths'; import { BasePoolMethodsV3 } from '../basePoolMethodsV3'; @@ -189,7 +189,7 @@ export class BufferPool implements BasePoolMethodsV3 { // Helper methods - public getPoolTokens(tokenIn: Token, tokenOut: Token): { tIn: BasePoolToken; tOut: BasePoolToken } { + public getPoolTokens(tokenIn: BaseToken, tokenOut: BaseToken): { tIn: BasePoolToken; tOut: BasePoolToken } { const tIn = this.tokenMap.get(tokenIn.address); const tOut = this.tokenMap.get(tokenOut.address); @@ -213,7 +213,7 @@ export class BufferPool implements BasePoolMethodsV3 { ); } - public swapGivenInGreaterThanBufferLimit(tokenIn: Token, tokenOut: Token, swapAmount: TokenAmount): boolean { + public swapGivenInGreaterThanBufferLimit(tokenIn: BaseToken, tokenOut: BaseToken, swapAmount: TokenAmount): boolean { const { tIn, tOut } = this.getPoolTokens(tokenIn, tokenOut); const mainTokenAmount = this.tokens[0]; const underlyingTokenAmount = this.tokens[1]; @@ -227,7 +227,7 @@ export class BufferPool implements BasePoolMethodsV3 { } } - public swapGivenOutGreaterThanBufferLimit(tokenIn: Token, tokenOut: Token, swapAmount: TokenAmount): boolean { + public swapGivenOutGreaterThanBufferLimit(tokenIn: BaseToken, tokenOut: BaseToken, swapAmount: TokenAmount): boolean { const { tIn, tOut } = this.getPoolTokens(tokenIn, tokenOut); const mainTokenAmount = this.tokens[0]; const underlyingTokenAmount = this.tokens[1];