From 8ba9808f5275939125244a78021bc154825adde1 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Mon, 29 Sep 2025 14:56:20 +0200 Subject: [PATCH 01/17] refactor: split Token into BaseToken & Token --- src/entities/baseToken.ts | 45 +++++++++++++++++++++++++++++++++++++++ src/entities/token.ts | 39 ++++++++++----------------------- 2 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 src/entities/baseToken.ts diff --git a/src/entities/baseToken.ts b/src/entities/baseToken.ts new file mode 100644 index 000000000..b2aa77d12 --- /dev/null +++ b/src/entities/baseToken.ts @@ -0,0 +1,45 @@ +import { Address } from 'viem'; +import { InputToken } from '../types'; + +/** + * BaseToken contains the core functionality for all tokens + * This class handles the essential token properties and methods + * without any wrapped token logic + */ +export class BaseToken { + public readonly chainId: number; + public readonly address: Address; + public readonly decimals: number; + public readonly symbol?: string; + public readonly name?: string; + + public constructor( + chainId: number, + address: Address, + decimals: number, + symbol?: string, + name?: string, + ) { + this.chainId = chainId; + // Addresses are always lowercased for speed + this.address = address.toLowerCase() as Address; + this.decimals = decimals; + this.symbol = symbol; + this.name = name; + } + + public isEqual(token: BaseToken) { + return this.chainId === token.chainId && this.address === token.address; + } + + public isSameAddress(address: Address) { + return this.address === address.toLowerCase(); + } + + public toInputToken(): InputToken { + return { + address: this.address, + decimals: this.decimals, + }; + } +} diff --git a/src/entities/token.ts b/src/entities/token.ts index d306238cb..f32e4173c 100644 --- a/src/entities/token.ts +++ b/src/entities/token.ts @@ -1,11 +1,11 @@ import { Address } from 'viem'; -import { InputToken } from '../types'; -export class Token { - public readonly chainId: number; - public readonly address: Address; - public readonly decimals: number; - public readonly symbol?: string; - public readonly name?: string; +import { BaseToken } from './baseToken'; + +/** + * Token extends BaseToken and adds wrapped token functionality + * This maintains backward compatibility while providing a cleaner base class + */ +export class Token extends BaseToken { public readonly wrapped: Address; public constructor( @@ -16,33 +16,16 @@ export class Token { name?: string, wrapped?: Address, ) { - this.chainId = chainId; - // Addresses are always lowercased for speed - this.address = address.toLowerCase() as Address; - this.decimals = decimals; - this.symbol = symbol; - this.name = name; + // Call parent constructor with core properties + super(chainId, address, decimals, symbol, name); + + // Add wrapped functionality this.wrapped = ( wrapped ? wrapped.toLowerCase() : address.toLowerCase() ) as Address; } - public isEqual(token: Token) { - return this.chainId === token.chainId && this.address === token.address; - } - public isUnderlyingEqual(token: Token) { return this.chainId === token.chainId && this.wrapped === token.wrapped; } - - public isSameAddress(address: Address) { - return this.address === address.toLowerCase(); - } - - public toInputToken(): InputToken { - return { - address: this.address, - decimals: this.decimals, - }; - } } From bce6a97041c578a3b775ce0e472d98a19a999fd1 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Mon, 29 Sep 2025 14:56:44 +0200 Subject: [PATCH 02/17] chore: lint --- src/entities/token.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/token.ts b/src/entities/token.ts index f32e4173c..4d550a7ca 100644 --- a/src/entities/token.ts +++ b/src/entities/token.ts @@ -18,7 +18,7 @@ export class Token extends BaseToken { ) { // Call parent constructor with core properties super(chainId, address, decimals, symbol, name); - + // Add wrapped functionality this.wrapped = ( wrapped ? wrapped.toLowerCase() : address.toLowerCase() From 663629205bd4b2d45456da3a94ddadc978a7ac9f Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 7 Oct 2025 11:34:07 +0200 Subject: [PATCH 03/17] refactor: more Token -> BaseToken changes --- .../swap/swaps/v2/auraBalSwaps/exitPool.ts | 4 ++-- .../swap/swaps/v2/auraBalSwaps/joinPool.ts | 6 ++++-- .../swap/swaps/v2/auraBalSwaps/joinSwap.ts | 4 ++-- .../swap/swaps/v2/auraBalSwaps/swapExit.ts | 3 ++- src/entities/tokenAmount.ts | 14 +++++++------- src/entities/utils/getValue.ts | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts index 8ff64007a..ff3488fce 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts @@ -5,7 +5,7 @@ import { parseAbiParameters, Hex, } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { BALANCER_RELAYER, ChainId, inputValidationError } from '@/utils'; import { batchRelayerLibraryAbi } from '@/abi'; import { Relayer } from '@/entities/relayer'; @@ -13,7 +13,7 @@ import { balWethAssets, balWethId } from './constants'; import { replaceWrapped } from './replaceWrapped'; export function encodeExitData( - token: Token, + token: BaseToken, userAddress: Address, swapOpRef: bigint, limit: bigint, diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts index 6f79f3c34..46533468b 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts @@ -6,6 +6,7 @@ import { Hex, } from 'viem'; import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { BALANCER_RELAYER, ChainId, @@ -18,7 +19,7 @@ import { balWethAssets, balWethId } from './constants'; import { replaceWrapped } from './replaceWrapped'; export function encodeJoinData( - token: Token, + token: BaseToken, sender: Address, inputAmount: bigint, wethIsEth: boolean, @@ -31,7 +32,8 @@ export function encodeJoinData( ); const useNativeAsset = - wethIsEth && token.isUnderlyingEqual(NATIVE_ASSETS[ChainId.MAINNET]); + wethIsEth && + token.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped); const maxAmountsIn = Array(balWethAssets.length).fill(0n); maxAmountsIn[tokenInIndex] = inputAmount; diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts index c785a8a2b..b61f8b6af 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts @@ -14,7 +14,7 @@ import { auraBalToken, balWethAddress, auraBAL } from './constants'; import { encodeJoinData } from './joinPool'; import { encodeSwapData } from './swap'; import { AuraBalSwapQueryOutput, AuraBalSwapQueryInput } from './types'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; // token[join]8020BPT[swap]auraBAL export async function queryJoinSwap( @@ -81,7 +81,7 @@ export function buildJoinSwapCall( userAddress: Address, inputAmount: bigint, swapLimit: bigint, - joinToken: Token, + joinToken: BaseToken, wethIsEth: boolean, relayerApprovalSignature?: Hex, ): { callData: Hex; value: bigint } { diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts index ab5cd7d1d..4373d55f9 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts @@ -14,6 +14,7 @@ import { auraBalToken, balWethAddress, auraBAL } from './constants'; import { encodeSwapData } from './swap'; import { AuraBalSwapQueryOutput, AuraBalSwapQueryInput } from './types'; import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { encodeExitData } from './exitPool'; // auraBal[swap]8020Bpt[exit]token @@ -86,7 +87,7 @@ export function buildSwapExitCall( user: Address, inputAmount: bigint, exitLimit: bigint, - exitToken: Token, + exitToken: BaseToken, wethIsEth: boolean, relayerApprovalSignature?: Hex, ): Hex { diff --git a/src/entities/tokenAmount.ts b/src/entities/tokenAmount.ts index 863f3ea2d..7f1383a06 100644 --- a/src/entities/tokenAmount.ts +++ b/src/entities/tokenAmount.ts @@ -3,26 +3,26 @@ import { parseUnits } from 'viem'; import { InputAmount, BigintIsh } from '../types'; import { DECIMAL_SCALES } from '../utils/constants'; import { WAD } from '../utils/math'; -import { Token } from './token'; +import { BaseToken } from './baseToken'; export class TokenAmount { - public readonly token: Token; + public readonly token: BaseToken; public readonly scalar: bigint; public readonly decimalScale: bigint; public amount: bigint; public scale18: bigint; - public static fromRawAmount(token: Token, rawAmount: BigintIsh) { + public static fromRawAmount(token: BaseToken, rawAmount: BigintIsh) { return new TokenAmount(token, rawAmount); } - public static fromHumanAmount(token: Token, humanAmount: `${number}`) { + public static fromHumanAmount(token: BaseToken, humanAmount: `${number}`) { const rawAmount = parseUnits(humanAmount, token.decimals); return new TokenAmount(token, rawAmount); } public static fromScale18Amount( - token: Token, + token: BaseToken, scale18Amount: BigintIsh, divUp?: boolean, ) { @@ -37,11 +37,11 @@ export class TokenAmount { input: InputAmount, chainId: number, ): TokenAmount { - const token = new Token(chainId, input.address, input.decimals); + const token = new BaseToken(chainId, input.address, input.decimals); return new TokenAmount(token, input.rawAmount); } - protected constructor(token: Token, amount: BigintIsh) { + protected constructor(token: BaseToken, amount: BigintIsh) { this.decimalScale = DECIMAL_SCALES[token.decimals]; this.token = token; this.amount = BigInt(amount); diff --git a/src/entities/utils/getValue.ts b/src/entities/utils/getValue.ts index 5c3ea63bc..8955d932e 100644 --- a/src/entities/utils/getValue.ts +++ b/src/entities/utils/getValue.ts @@ -9,7 +9,7 @@ export const getValue = ( if (wethIsEth) { value = amountsIn.find((a) => - a.token.isUnderlyingEqual(NATIVE_ASSETS[a.token.chainId]), + a.token.isSameAddress(NATIVE_ASSETS[a.token.chainId].wrapped), )?.amount ?? 0n; } return value; From 0cd88f7eab8f64f18777bcff32e44632e8a645e8 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 7 Oct 2025 14:02:22 +0200 Subject: [PATCH 04/17] refactor: more type refactors Token -> BaseToken --- .../addLiquidityNestedV2/validateInputs.ts | 5 +++-- src/entities/priceImpact/addLiquidityUnbalanced.ts | 3 ++- .../priceImpact/addLiquidityUnbalancedBoosted.ts | 6 +++--- .../removeLiquidityNestedV2/getPeekCalls.ts | 4 ++-- .../removeLiquidityNestedV2/types.ts | 3 ++- src/entities/utils/parseAddLiquidityArgs.ts | 4 ++-- src/entities/utils/parseRemoveLiquidityArgs.ts | 4 ++-- src/entities/utils/replaceWrapped.ts | 10 +++++++--- test/lib/utils/addLiquidityBoostedHelper.ts | 12 ++++++++---- test/lib/utils/removeLiquidityNestedHelper.ts | 5 +++-- 10 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts index 38a9b4f64..5fb4a63c1 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts @@ -5,13 +5,14 @@ import { TokenAmount } from '../../tokenAmount'; import { NestedPoolState } from '../../types'; import { AddLiquidityNestedInput } from '../types'; import { AddLiquidityNestedCallInputV2 } from './types'; +import { BaseToken } from '@/entities/baseToken'; export const validateQueryInput = ( input: AddLiquidityNestedInput, nestedPoolState: NestedPoolState, ): TokenAmount[] => { const mainTokens = nestedPoolState.mainTokens.map( - (t) => new Token(input.chainId, t.address, t.decimals), + (t) => new BaseToken(input.chainId, t.address, t.decimals), ); const amountsIn = input.amountsIn.map((amountIn) => { const tokenIn = mainTokens.find((t) => @@ -35,7 +36,7 @@ export const validateBuildCallInput = ( if (input.wethIsEth) { if ( !input.amountsIn.some((a) => - a.token.isUnderlyingEqual(NATIVE_ASSETS[chainId]), + a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), ) ) { throw inputValidationError( diff --git a/src/entities/priceImpact/addLiquidityUnbalanced.ts b/src/entities/priceImpact/addLiquidityUnbalanced.ts index b467ab4b1..246474a82 100644 --- a/src/entities/priceImpact/addLiquidityUnbalanced.ts +++ b/src/entities/priceImpact/addLiquidityUnbalanced.ts @@ -14,6 +14,7 @@ import { TokenAmount } from '../tokenAmount'; import { PoolState } from '../types'; import { priceImpactABA } from './helper'; import { Swap, SwapInput } from '../swap'; +import { BaseToken } from '@/entities/baseToken'; export const addLiquidityUnbalanced = async ( input: AddLiquidityUnbalancedInput, @@ -25,7 +26,7 @@ export const addLiquidityUnbalanced = async ( const addLiquidity = new AddLiquidity(); let amountsIn: TokenAmount[]; let bptOut: TokenAmount; - let poolTokens: Token[]; + let poolTokens: BaseToken[]; try { const queryResult = await addLiquidity.query(input, poolState); amountsIn = queryResult.amountsIn; diff --git a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts index 57d90443a..dc4397bd8 100644 --- a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts +++ b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts @@ -11,7 +11,7 @@ import { AddLiquidityBoostedV3 } from '../addLiquidityBoosted'; import { RemoveLiquidityBoostedV3 } from '../removeLiquidityBoosted'; import { RemoveLiquidityBoostedProportionalInput } from '../removeLiquidityBoosted/types'; import { Address, BaseError, ContractFunctionRevertedError } from 'viem'; -import { Token } from '../token'; +import { BaseToken } from '@/entities/baseToken'; /** * Calculate price impact on add liquidity unbalanced operations @@ -131,7 +131,7 @@ async function queryAddLiquidityForTokenDelta( addLiquidity: AddLiquidityBoostedV3, input: AddLiquidityBoostedUnbalancedInput, poolState: PoolStateWithUnderlyings, - poolTokens: Token[], + poolTokens: BaseToken[], tokenIndex: number, delta: bigint, ): Promise { @@ -178,7 +178,7 @@ async function zeroOutDeltas( addLiquidity: AddLiquidityBoostedV3, input: AddLiquidityBoostedUnbalancedInput, poolState: PoolStateWithUnderlyings, - poolTokens: Token[], + poolTokens: BaseToken[], deltas: bigint[], deltaBPTs: bigint[], ) { diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts index 8b8cd1fc9..835e2abca 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts @@ -1,13 +1,13 @@ import { Hex } from 'viem'; import { RemoveLiquidityNestedCallAttributesV2 } from './types'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { Relayer } from '@/entities/relayer'; export const getPeekCalls = ( calls: RemoveLiquidityNestedCallAttributesV2[], isProportional: boolean, ) => { - const tokensOut: Token[] = []; + const tokensOut: BaseToken[] = []; const peekCalls: Hex[] = []; if (isProportional) { diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts index 7d65eaa43..79791ba2a 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts @@ -5,6 +5,7 @@ import { TokenAmount } from '@/entities/tokenAmount'; import { PoolKind } from '@/entities/types'; import { PoolType } from '@/types'; import { ChainId } from '@/utils'; +import { BaseToken } from '@/entities/baseToken'; export type RemoveLiquidityNestedProportionalInputV2 = { bptAmountIn: bigint; @@ -20,7 +21,7 @@ export type RemoveLiquidityNestedSingleTokenInputV2 = export type RemoveLiquidityNestedCallAttributesV2 = { chainId: ChainId; - sortedTokens: Token[]; + sortedTokens: BaseToken[]; poolId: Address; poolAddress: Address; poolType: PoolType; diff --git a/src/entities/utils/parseAddLiquidityArgs.ts b/src/entities/utils/parseAddLiquidityArgs.ts index 54572f1fa..e20466331 100644 --- a/src/entities/utils/parseAddLiquidityArgs.ts +++ b/src/entities/utils/parseAddLiquidityArgs.ts @@ -1,5 +1,5 @@ import { Address, Hex } from '../../types'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { replaceWrapped } from './replaceWrapped'; export function parseAddLiquidityArgs({ @@ -15,7 +15,7 @@ export function parseAddLiquidityArgs({ }: { chainId?: number; wethIsEth?: boolean; - sortedTokens: Token[]; + sortedTokens: BaseToken[]; poolId: Hex; sender: Address; recipient: Address; diff --git a/src/entities/utils/parseRemoveLiquidityArgs.ts b/src/entities/utils/parseRemoveLiquidityArgs.ts index 08ba1e083..486940567 100644 --- a/src/entities/utils/parseRemoveLiquidityArgs.ts +++ b/src/entities/utils/parseRemoveLiquidityArgs.ts @@ -1,5 +1,5 @@ import { Address } from '../../types'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { ExitPoolRequest } from '../removeLiquidity/types'; import { replaceWrapped } from './replaceWrapped'; @@ -16,7 +16,7 @@ export function parseRemoveLiquidityArgs({ }: { chainId?: number; wethIsEth?: boolean; - sortedTokens: Token[]; + sortedTokens: BaseToken[]; poolId: Address; sender: Address; recipient: Address; diff --git a/src/entities/utils/replaceWrapped.ts b/src/entities/utils/replaceWrapped.ts index ada8cc136..962a77f65 100644 --- a/src/entities/utils/replaceWrapped.ts +++ b/src/entities/utils/replaceWrapped.ts @@ -1,10 +1,14 @@ +import { BaseToken } from '../baseToken'; import { Token } from '../token'; import { NATIVE_ASSETS, ZERO_ADDRESS } from '../../utils'; -export function replaceWrapped(tokens: Token[], chainId: number): Token[] { +export function replaceWrapped( + tokens: BaseToken[], + chainId: number, +): BaseToken[] { return tokens.map((token) => { - if (token.isUnderlyingEqual(NATIVE_ASSETS[chainId])) { - return new Token(chainId, ZERO_ADDRESS, 18); + if (token.isSameAddress(NATIVE_ASSETS[chainId].wrapped)) { + return new BaseToken(chainId, ZERO_ADDRESS, 18); } return token; }); diff --git a/test/lib/utils/addLiquidityBoostedHelper.ts b/test/lib/utils/addLiquidityBoostedHelper.ts index 07344b3e5..556dd5d42 100644 --- a/test/lib/utils/addLiquidityBoostedHelper.ts +++ b/test/lib/utils/addLiquidityBoostedHelper.ts @@ -7,7 +7,6 @@ import { AddLiquidityKind, PoolStateWithUnderlyings, Slippage, - Token, TokenAmount, } from '@/entities'; import { ChainId, NATIVE_ASSETS, PERMIT2, PublicWalletClient } from '@/utils'; @@ -20,6 +19,7 @@ import { } from './helper'; import { areBigIntsWithinPercent } from './swapHelpers'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; +import { BaseToken } from '@/entities/baseToken'; export async function GetBoostedBpt( chainId: ChainId, @@ -117,8 +117,8 @@ export async function GetBoostedBpt( } export const assertTokenMatch = ( - tokenDefined: Token[], - tokenReturned: Token[], + tokenDefined: BaseToken[], + tokenReturned: BaseToken[], ) => { tokenDefined.map((tokenAmount) => { expect( @@ -188,7 +188,11 @@ export const doAddLiquidityBoosted = async ( addLiquidityBoostedQueryOutput.bptOut, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new Token(addLiquidityBoostedQueryOutput.chainId, zeroAddress, 18), + new BaseToken( + addLiquidityBoostedQueryOutput.chainId, + zeroAddress, + 18, + ), 0n, ), ]; diff --git a/test/lib/utils/removeLiquidityNestedHelper.ts b/test/lib/utils/removeLiquidityNestedHelper.ts index d02b94f84..143064575 100644 --- a/test/lib/utils/removeLiquidityNestedHelper.ts +++ b/test/lib/utils/removeLiquidityNestedHelper.ts @@ -26,6 +26,7 @@ import { sendTransactionGetBalances, setTokenBalances, } from './helper'; +import { BaseToken } from '@/entities/baseToken'; // AddLiquidityNestedInput @@ -123,7 +124,7 @@ export async function GetNestedBpt( return balanceDeltas[0]; } -const isSameToken = (token1: Token, token2: Token): boolean => { +const isSameToken = (token1: BaseToken, token2: BaseToken): boolean => { return ( token1.address.toLowerCase() === token2.address.toLowerCase() && token1.chainId === token2.chainId @@ -140,7 +141,7 @@ const isSameToken = (token1: Token, token2: Token): boolean => { */ export const validateTokenAmounts = ( amounts: TokenAmount[], - tokens: Token[], + tokens: BaseToken[], ): void => { // Check that we have the same number of amounts as main tokens expect(amounts.length).to.equal( From 655b6b19e0c408f96479b650a642a10120081b63 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 7 Oct 2025 16:28:15 +0200 Subject: [PATCH 05/17] refactor: more Token -> BaseToken refactors --- .../addLiquidity/addLiquidityCowAmm/index.ts | 6 +++--- .../addLiquidityComposableStable.ts | 4 ++-- .../addLiquidityV2/stable/addLiquidityStable.ts | 4 ++-- .../weighted/addLiquidityWeighted.ts | 4 ++-- src/entities/addLiquidity/addLiquidityV3/index.ts | 4 ++-- src/entities/addLiquidityBuffer/index.ts | 6 +++--- .../getQueryCallsAttributes.ts | 6 +++--- .../addLiquidityNestedV2/index.ts | 4 ++-- .../addLiquidityNestedV2/types.ts | 4 ++-- .../addLiquidityNestedV2/validateInputs.ts | 3 +-- .../composableStable/initPoolComposableStable.ts | 6 +++--- .../initPoolV2/weighted/initPoolWeighted.ts | 6 +++--- src/entities/initPool/initPoolV3.ts | 6 +++--- src/entities/removeLiquidity/helper.ts | 4 ++-- .../removeLiquidity/removeLiquidityCowAmm/index.ts | 6 +++--- .../removeLiquidityComposableStable.ts | 8 ++++---- .../stable/removeLiquidityStable.ts | 8 ++++---- .../weighted/removeLiquidityWeighted.ts | 7 ++++--- .../removeLiquidity/removeLiquidityV3/index.ts | 4 ++-- src/entities/removeLiquidityBoosted/index.ts | 6 +++--- .../getQueryCallsAttributes.ts | 10 +++++----- .../removeLiquidityNestedV2/types.ts | 3 +-- .../removeLiquidityNestedV3/index.ts | 6 +++--- .../swap/swaps/v2/auraBalSwaps/constants.ts | 4 ++-- .../swap/swaps/v2/auraBalSwaps/joinPool.ts | 1 - .../swap/swaps/v2/auraBalSwaps/parseInputs.ts | 12 ++++++------ .../swap/swaps/v2/auraBalSwaps/swapExit.ts | 1 - src/entities/swap/swaps/v2/auraBalSwaps/types.ts | 8 ++++---- src/entities/utils/getAmounts.ts | 5 +++-- src/entities/utils/getSortedTokens.ts | 6 +++--- src/entities/utils/parseInitializeArgs.ts | 4 ++-- src/entities/utils/replaceWrapped.ts | 1 - src/utils/helpers.ts | 6 +++--- .../v2/auraBalSwaps/auraBal.integration.test.ts | 14 +++++++------- .../swaps/v2/auraBalSwaps/parseInputs.test.ts | 7 ++++--- test/lib/utils/addLiquidityHelper.ts | 7 ++++--- test/lib/utils/removeLiquidityHelper.ts | 10 +++++----- test/lib/utils/removeLiquidityRecoveryHelper.ts | 4 ++-- ...moveLiquidityPartialBoosted.integration.test.ts | 7 ++++--- .../removeLiquidityNestedV3.integration.test.ts | 10 +++++----- 40 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts index b08a01a0a..67b1ed899 100644 --- a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts +++ b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts @@ -1,6 +1,6 @@ import { encodeFunctionData } from 'viem'; import { cowAmmPoolAbi } from '@/abi/cowAmmPool'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { poolTypeError, protocolVersionError } from '@/utils'; @@ -47,12 +47,12 @@ export class AddLiquidityCowAmm implements AddLiquidityBase { ); const bptOut = TokenAmount.fromRawAmount( - new Token(input.chainId, bptAmount.address, bptAmount.decimals), + new BaseToken(input.chainId, bptAmount.address, bptAmount.decimals), bptAmount.rawAmount, ); const amountsIn = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new Token(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index a6c1e30bf..54cc3252e 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; @@ -56,7 +56,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts b/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts index a4b241089..c0bd0c8b5 100644 --- a/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { StableEncoder } from '@/entities/encoders/stable'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; @@ -49,7 +49,7 @@ export class AddLiquidityStable implements AddLiquidityBase { args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index ea9c10990..619352fbf 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { WeightedEncoder } from '@/entities/encoders/weighted'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; @@ -51,7 +51,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index ee1fec5e0..6678926f1 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -1,7 +1,7 @@ import { encodeFunctionData, zeroAddress } from 'viem'; import { balancerRouterAbiExtended } from '@/abi'; import { Permit2 } from '@/entities/permit2Helper'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { @@ -33,7 +33,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { block?: bigint, ): Promise { const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); let bptOut: TokenAmount; let amountsIn: TokenAmount[]; diff --git a/src/entities/addLiquidityBuffer/index.ts b/src/entities/addLiquidityBuffer/index.ts index ad8b24bdb..c6dde7841 100644 --- a/src/entities/addLiquidityBuffer/index.ts +++ b/src/entities/addLiquidityBuffer/index.ts @@ -6,7 +6,7 @@ import { Permit2 } from '@/entities/permit2Helper'; import { BufferState } from '@/entities/types'; import { doAddLiquidityQuery } from './doAddLiquidityQuery'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { balancerBufferRouterAbiExtended, balancerRouterAbiExtended, @@ -35,7 +35,7 @@ export class AddLiquidityBufferV3 { input.exactSharesToIssue, block, ); - const underlyingToken = new Token( + const underlyingToken = new BaseToken( input.chainId, bufferState.underlyingToken.address, bufferState.underlyingToken.decimals, @@ -44,7 +44,7 @@ export class AddLiquidityBufferV3 { underlyingToken, amountUnderlyingIn, ); - const wrappedToken = new Token( + const wrappedToken = new BaseToken( input.chainId, bufferState.wrappedToken.address, bufferState.wrappedToken.decimals, diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts index 4aae69e11..90e279135 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts @@ -1,5 +1,5 @@ import { Address, PoolType } from '@/types'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { ZERO_ADDRESS, BALANCER_RELAYER, @@ -31,7 +31,7 @@ export const getQueryCallsAttributes = ( for (const pool of poolsSortedByLevel) { const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new Token(chainId, t.address, t.decimals)); + .map((t) => new BaseToken(chainId, t.address, t.decimals)); const maxAmountsIn = getMaxAmountsIn(sortedTokens, amountsIn, calls); if (maxAmountsIn.every((a) => a.amount === 0n && !a.isRef)) { continue; @@ -61,7 +61,7 @@ export const getQueryCallsAttributes = ( }; const getMaxAmountsIn = ( - sortedTokens: Token[], + sortedTokens: BaseToken[], amountsIn: { address: Address; rawAmount: bigint }[], calls: AddLiquidityNestedCallAttributes[], ): { amount: bigint; isRef: boolean }[] => { diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts index 3dcdc9536..fdb5ff02a 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '../../token'; +import { BaseToken } from '../../baseToken'; import { BALANCER_RELAYER, ZERO_ADDRESS } from '../../../utils'; import { Relayer } from '../../relayer'; import { encodeCalls } from './encodeCalls'; @@ -50,7 +50,7 @@ export class AddLiquidityNestedV2 { encodedMulticall, ); - const tokenOut = new Token( + const tokenOut = new BaseToken( input.chainId, callsAttributes[callsAttributes.length - 1].poolAddress, 18, diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts index 201cdca94..a4888caf9 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts @@ -1,7 +1,7 @@ import { Address, Hex } from 'viem'; import { PoolType } from '../../../types'; import { ChainId } from '../../../utils'; -import { Token } from '../../token'; +import { BaseToken } from '../../baseToken'; import { TokenAmount } from '../../tokenAmount'; import { PoolKind } from '../../types'; import { Slippage } from '@/entities/slippage'; @@ -14,7 +14,7 @@ export type AddLiquidityNestedInputV2 = AddLiquidityNestedBaseInput & { export type AddLiquidityNestedCallAttributes = { chainId: ChainId; wethIsEth?: boolean; - sortedTokens: Token[]; + sortedTokens: BaseToken[]; poolId: Hex; poolAddress: Address; poolType: PoolType; diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts index 5fb4a63c1..840219229 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts @@ -1,11 +1,10 @@ import { inputValidationError, NATIVE_ASSETS } from '@/utils'; -import { Token } from '../../token'; +import { BaseToken } from '../../baseToken'; import { TokenAmount } from '../../tokenAmount'; import { NestedPoolState } from '../../types'; import { AddLiquidityNestedInput } from '../types'; import { AddLiquidityNestedCallInputV2 } from './types'; -import { BaseToken } from '@/entities/baseToken'; export const validateQueryInput = ( input: AddLiquidityNestedInput, diff --git a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts index d66039ae7..496abb98f 100644 --- a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts +++ b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts @@ -13,7 +13,7 @@ import { } from '../../types'; import { vaultV2Abi } from '../../../../abi'; import { VAULT_V2, MAX_UINT256 } from '../../../../utils'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { getValue } from '@/entities/utils/getValue'; import { TokenAmount } from '@/entities/tokenAmount'; @@ -44,7 +44,7 @@ export class InitPoolComposableStable implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new Token(input.chainId, a.address, a.decimals); + const token = new BaseToken(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -58,7 +58,7 @@ export class InitPoolComposableStable implements InitPoolBase { private getAmounts( input: InitPoolInputV2, poolAddress: Address, - poolTokens: Token[], + poolTokens: BaseToken[], ): InitPoolAmountsComposableStable { const bptIndex = poolTokens.findIndex((t) => t.address === poolAddress); const maxAmountsIn = getAmounts(poolTokens, [ diff --git a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts index 720d98eb6..3285c4077 100644 --- a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts +++ b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts @@ -12,7 +12,7 @@ import { getSortedTokens, parseAddLiquidityArgs, } from '../../../utils'; -import { Token } from '../../../token'; +import { BaseToken } from '../../../baseToken'; import { WeightedEncoder } from '../../../encoders'; import { TokenAmount } from '@/entities/tokenAmount'; import { getValue } from '@/entities/utils/getValue'; @@ -41,7 +41,7 @@ export class InitPoolWeighted implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new Token(input.chainId, a.address, a.decimals); + const token = new BaseToken(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -54,7 +54,7 @@ export class InitPoolWeighted implements InitPoolBase { private getAmounts( input: InitPoolInputV2, - poolTokens: Token[], + poolTokens: BaseToken[], ): InitPoolAmounts { return { maxAmountsIn: getAmounts(poolTokens, input.amountsIn), diff --git a/src/entities/initPool/initPoolV3.ts b/src/entities/initPool/initPoolV3.ts index e509354e6..bac7f3b52 100644 --- a/src/entities/initPool/initPoolV3.ts +++ b/src/entities/initPool/initPoolV3.ts @@ -4,7 +4,7 @@ import { InitPoolBase, InitPoolBuildOutput, InitPoolInputV3 } from './types'; import { balancerV3Contracts } from '@/utils'; import { encodeFunctionData, Address } from 'viem'; import { getSortedTokens, parseInitializeArgs, getAmounts } from '../utils'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { TokenAmount } from '../tokenAmount'; import { getValue } from '../utils/getValue'; import { Permit2 } from '@/entities/permit2Helper'; @@ -30,7 +30,7 @@ export class InitPoolV3 implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new Token(input.chainId, a.address, a.decimals); + const token = new BaseToken(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -70,7 +70,7 @@ export class InitPoolV3 implements InitPoolBase { private getAmounts( input: InitPoolInputV3, - tokens: Token[], + tokens: BaseToken[], ): { exactAmountsIn: bigint[] } { return { exactAmountsIn: getAmounts(tokens, input.amountsIn), diff --git a/src/entities/removeLiquidity/helper.ts b/src/entities/removeLiquidity/helper.ts index 5ae59e277..46da5adc6 100644 --- a/src/entities/removeLiquidity/helper.ts +++ b/src/entities/removeLiquidity/helper.ts @@ -1,5 +1,5 @@ import { MAX_UINT256, missingParameterError } from '@/utils'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { RemoveLiquidityAmounts } from '../types'; import { getAmounts } from '../utils'; import { @@ -9,7 +9,7 @@ import { } from './types'; export const getAmountsQuery = ( - tokens: Token[], + tokens: BaseToken[], input: RemoveLiquidityInput, bptIndex = -1, ): RemoveLiquidityAmounts => { diff --git a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts index 256a6ba38..d45e3f316 100644 --- a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts @@ -1,4 +1,4 @@ -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { @@ -38,12 +38,12 @@ export class RemoveLiquidityCowAmm implements RemoveLiquidityBase { ); const bptIn = TokenAmount.fromRawAmount( - new Token(input.chainId, input.bptIn.address, input.bptIn.decimals), + new BaseToken(input.chainId, input.bptIn.address, input.bptIn.decimals), input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new Token(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index 4f52116ac..10d0ce37e 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '../../../token'; +import { BaseToken } from '../../../baseToken'; import { TokenAmount } from '../../../tokenAmount'; import { protocolVersionError, @@ -68,7 +68,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { input.chainId, args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -106,7 +106,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, @@ -116,7 +116,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { ); let amountsOut = tokenAmounts.map((amount) => TokenAmount.fromRawAmount( - new Token(input.chainId, amount.address, amount.decimals), + new BaseToken(input.chainId, amount.address, amount.decimals), amount.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts index 5a2febdac..36d6ddcad 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '../../../token'; +import { BaseToken } from '../../../baseToken'; import { TokenAmount } from '../../../tokenAmount'; import { StableEncoder } from '../../../encoders/stable'; import { @@ -60,7 +60,7 @@ export class RemoveLiquidityStable implements RemoveLiquidityBase { args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -97,14 +97,14 @@ export class RemoveLiquidityStable implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new Token(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index b222226d4..64eaa4eff 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -22,6 +22,7 @@ import { } from '../../../utils'; import { getAmountsCall, getAmountsQuery } from '../../helper'; import { RemoveLiquidityV2BaseBuildCallInput } from '../types'; +import { BaseToken } from '@/entities/baseToken'; export class RemoveLiquidityWeighted implements RemoveLiquidityBase { public async query( @@ -56,7 +57,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { args, ); - const bpt = new Token(input.chainId, poolState.address, 18); + const bpt = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -92,14 +93,14 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amount) => TokenAmount.fromRawAmount( - new Token(input.chainId, amount.address, amount.decimals), + new BaseToken(input.chainId, amount.address, amount.decimals), amount.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/index.ts b/src/entities/removeLiquidity/removeLiquidityV3/index.ts index 181925c90..a9b94d6e6 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/index.ts @@ -1,4 +1,4 @@ -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { getSortedTokens } from '@/entities/utils'; @@ -108,7 +108,7 @@ export class RemoveLiquidityV3 implements RemoveLiquidityBase { break; } - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const output: RemoveLiquidityBaseQueryOutput & { userData: Hex } = { to: AddressProvider.Router(input.chainId), diff --git a/src/entities/removeLiquidityBoosted/index.ts b/src/entities/removeLiquidityBoosted/index.ts index f4c82d87a..c590d9525 100644 --- a/src/entities/removeLiquidityBoosted/index.ts +++ b/src/entities/removeLiquidityBoosted/index.ts @@ -13,7 +13,7 @@ import { balancerCompositeLiquidityRouterBoostedAbiExtended } from '@/abi'; import { PoolStateWithUnderlyings } from '@/entities/types'; import { TokenAmount } from '@/entities/tokenAmount'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { getAmountsCall } from '../removeLiquidity/helper'; @@ -68,11 +68,11 @@ export class RemoveLiquidityBoostedV3 implements RemoveLiquidityBase { const { decimals } = poolStateTokenMap[tokenOut.toLowerCase() as Address]; - const token = new Token(input.chainId, tokenOut, decimals); + const token = new BaseToken(input.chainId, tokenOut, decimals); return TokenAmount.fromRawAmount(token, amount); }); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const output: RemoveLiquidityBoostedQueryOutput = { to: AddressProvider.CompositeLiquidityRouter(input.chainId), diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts index c1d41923a..160574a0c 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts @@ -2,7 +2,7 @@ import { Address } from 'viem'; import { TokenAmount } from '@/entities/tokenAmount'; import { BALANCER_RELAYER, ChainId, ZERO_ADDRESS } from '@/utils'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { NestedPoolV2, PoolKind } from '@/entities/types'; import { RemoveLiquidityNestedCallAttributesV2, @@ -51,7 +51,7 @@ export const getQueryCallsAttributes = ( ); } - const bptIn = new Token(chainId, poolsTopDown[0].address, 18); + const bptIn = new BaseToken(chainId, poolsTopDown[0].address, 18); const _bptAmountIn = TokenAmount.fromRawAmount(bptIn, bptAmountIn); return { callsAttributes, bptAmountIn: _bptAmountIn }; }; @@ -74,7 +74,7 @@ const getProportionalCallsAttributes = ( for (const pool of poolsSortedByLevel) { const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new Token(chainId, t.address, t.decimals)); + .map((t) => new BaseToken(chainId, t.address, t.decimals)); const sortedTokensWithoutBpt = sortedTokens.filter( (t) => !t.isSameAddress(pool.address), @@ -139,7 +139,7 @@ const getSingleTokenCallsAttributes = ( const pool = removeLiquidityPath[i]; const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new Token(chainId, t.address, t.decimals)); + .map((t) => new BaseToken(chainId, t.address, t.decimals)); const isLastCall = i === removeLiquidityPath.length - 1; const currenTokenOut = isLastCall ? tokenOut @@ -261,7 +261,7 @@ const getSenderProportional = ( // Recipient's logic: if there is at least one token that is an output of the // whole multicall, then the recipient is the user, otherwise it's the relayer. const getRecipientProportional = ( - sortedTokensWithoutBpt: Token[], + sortedTokensWithoutBpt: BaseToken[], poolsSortedByLevel: NestedPoolV2[], accountAddress: Address, chainId: ChainId, diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts index 79791ba2a..5fc136fb8 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts @@ -1,11 +1,10 @@ import { Address, Hex } from 'viem'; import { Slippage } from '@/entities/slippage'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolKind } from '@/entities/types'; import { PoolType } from '@/types'; import { ChainId } from '@/utils'; -import { BaseToken } from '@/entities/baseToken'; export type RemoveLiquidityNestedProportionalInputV2 = { bptAmountIn: bigint; diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts index 86da29ad2..777395ab9 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts @@ -20,7 +20,7 @@ import { SDKError, } from '@/utils'; import { balancerCompositeLiquidityRouterNestedAbiExtended } from '@/abi'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; export class RemoveLiquidityNestedV3 { @@ -43,10 +43,10 @@ export class RemoveLiquidityNestedV3 { // query function input, `tokensIn` array, must have all tokens from child pools // and all tokens that are not BPTs from the nested pool (parent pool). const mainTokens = nestedPoolState.mainTokens.map( - (t) => new Token(input.chainId, t.address, t.decimals), + (t) => new BaseToken(input.chainId, t.address, t.decimals), ); - const bptToken = new Token(input.chainId, parentPool.address, 18); + const bptToken = new BaseToken(input.chainId, parentPool.address, 18); const amountsOut = await this.doQueryRemoveLiquidityProportionalNestedPool( diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts b/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts index 1d510fa63..a1357d91c 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts @@ -1,11 +1,11 @@ import { Address } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { ChainId, NATIVE_ASSETS } from '@/utils'; export const BAL = '0xba100000625a3754423978a60c9317c58a424e3d'; export const auraBAL = '0x616e8BfA43F920657B3497DBf40D6b1A02D4608d'; export const supportedTokens = [BAL, NATIVE_ASSETS[ChainId.MAINNET].wrapped]; -export const auraBalToken = new Token(ChainId.MAINNET, auraBAL, 18); +export const auraBalToken = new BaseToken(ChainId.MAINNET, auraBAL, 18); export const balWethId = '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; export const balWethAddress = diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts index 46533468b..3d87dd25d 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts @@ -5,7 +5,6 @@ import { parseAbiParameters, Hex, } from 'viem'; -import { Token } from '@/entities/token'; import { BaseToken } from '@/entities/baseToken'; import { BALANCER_RELAYER, diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts b/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts index ceb2822cb..5dc399858 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts @@ -1,5 +1,5 @@ import { Address } from 'viem'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { AuraBalSwapKind, SwapQueryInput, @@ -21,8 +21,8 @@ export function isAuraBalSwap(input: SwapQueryInput): boolean { } function isMainnet( - tokenIn: Token, - tokenOut: Token, + tokenIn: BaseToken, + tokenOut: BaseToken, swapAmount: TokenAmount, ): boolean { if ( @@ -36,7 +36,7 @@ function isMainnet( return true; } -function isAddressEqual(token: Token, amount: TokenAmount): boolean { +function isAddressEqual(token: BaseToken, amount: TokenAmount): boolean { if (!token.isSameAddress(amount.token.address)) throw inputValidationError( 'auraBal Swap', @@ -51,7 +51,7 @@ function isGivenIn(kind: SwapKind): boolean { return true; } -function hasSupportedTokens(tokenIn: Token, tokenOut: Token): boolean { +function hasSupportedTokens(tokenIn: BaseToken, tokenOut: BaseToken): boolean { const tokenInIsAuraBal = auraBalToken.isSameAddress(tokenIn.address); const tokenOutIsAuraBal = auraBalToken.isSameAddress(tokenOut.address); if (tokenInIsAuraBal && tokenOutIsAuraBal) @@ -93,6 +93,6 @@ export function parseInputs(input: SwapQueryInput): AuraBalSwapQueryInput { }; } -function isSupportedToken(token: Token): boolean { +function isSupportedToken(token: BaseToken): boolean { return supportedTokens.some((t) => token.isSameAddress(t as Address)); } diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts index 4373d55f9..5b3283dce 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts @@ -13,7 +13,6 @@ import { Relayer } from '@/entities/relayer'; import { auraBalToken, balWethAddress, auraBAL } from './constants'; import { encodeSwapData } from './swap'; import { AuraBalSwapQueryOutput, AuraBalSwapQueryInput } from './types'; -import { Token } from '@/entities/token'; import { BaseToken } from '@/entities/baseToken'; import { encodeExitData } from './exitPool'; diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/types.ts b/src/entities/swap/swaps/v2/auraBalSwaps/types.ts index d9507f7a7..30af3a1e2 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/types.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/types.ts @@ -1,17 +1,17 @@ -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { TokenAmount } from '@/entities/tokenAmount'; import { SwapKind } from '@/types'; export type SwapQueryInput = { - tokenIn: Token; - tokenOut: Token; + tokenIn: BaseToken; + tokenOut: BaseToken; kind: SwapKind; swapAmount: TokenAmount; }; export interface AuraBalSwapQueryInput { kind: AuraBalSwapKind; - swapToken: Token; + swapToken: BaseToken; inputAmount: TokenAmount; } diff --git a/src/entities/utils/getAmounts.ts b/src/entities/utils/getAmounts.ts index 7fc1d3513..9f90d83f1 100644 --- a/src/entities/utils/getAmounts.ts +++ b/src/entities/utils/getAmounts.ts @@ -1,5 +1,6 @@ import { InputAmount } from '../../types'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; +import { Token } from '@/entities/token'; /** * Get amounts from array of TokenAmounts returning default if not a value for tokens. @@ -9,7 +10,7 @@ import { Token } from '../token'; * @returns */ export function getAmounts( - tokens: Token[], + tokens: BaseToken[], amounts: InputAmount[], defaultAmount = 0n, ): bigint[] { diff --git a/src/entities/utils/getSortedTokens.ts b/src/entities/utils/getSortedTokens.ts index 3d28df091..ab25384ab 100644 --- a/src/entities/utils/getSortedTokens.ts +++ b/src/entities/utils/getSortedTokens.ts @@ -1,11 +1,11 @@ import { MinimalToken } from '../../data/types'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; export function getSortedTokens( tokens: MinimalToken[], chainId: number, -): Token[] { +): BaseToken[] { return tokens .sort((a, b) => a.index - b.index) - .map((t) => new Token(chainId, t.address, t.decimals)); + .map((t) => new BaseToken(chainId, t.address, t.decimals)); } diff --git a/src/entities/utils/parseInitializeArgs.ts b/src/entities/utils/parseInitializeArgs.ts index 37c8c317c..4b9b0a39e 100644 --- a/src/entities/utils/parseInitializeArgs.ts +++ b/src/entities/utils/parseInitializeArgs.ts @@ -1,5 +1,5 @@ import { Address } from 'viem'; -import { Token } from '../token'; +import { BaseToken } from '../baseToken'; import { InitializeArgs } from '../initPool'; import { DEFAULT_USERDATA } from '@/utils'; @@ -15,7 +15,7 @@ export function parseInitializeArgs({ wethIsEth?: boolean; chainId: number; poolAddress: Address; - sortedTokens: Token[]; + sortedTokens: BaseToken[]; }): { args: InitializeArgs } { return { args: [ diff --git a/src/entities/utils/replaceWrapped.ts b/src/entities/utils/replaceWrapped.ts index 962a77f65..7032361cb 100644 --- a/src/entities/utils/replaceWrapped.ts +++ b/src/entities/utils/replaceWrapped.ts @@ -1,5 +1,4 @@ import { BaseToken } from '../baseToken'; -import { Token } from '../token'; import { NATIVE_ASSETS, ZERO_ADDRESS } from '../../utils'; export function replaceWrapped( diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index c16d17737..70059a8b2 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,11 +1,11 @@ import { inputValidationError } from './errors'; -import { Token } from '../entities/token'; +import { BaseToken } from '../entities/baseToken'; import { TokenAmount } from '../entities/tokenAmount'; import { Address, SwapKind, BigintIsh } from '@/types'; export function checkInputs( - tokenIn: Token, - tokenOut: Token, + tokenIn: BaseToken, + tokenOut: BaseToken, swapKind: SwapKind, swapAmount: BigintIsh | TokenAmount, ): TokenAmount { diff --git a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts index e769c2c4c..abf1bafc9 100644 --- a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts @@ -12,7 +12,6 @@ import { import { Relayer, Slippage, - Token, TokenAmount, AuraBalSwap, BALANCER_RELAYER, @@ -27,12 +26,13 @@ import { auraBalToken, BAL, } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; +import { BaseToken } from '@/entities/baseToken'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { forkSetup, sendTransactionGetBalances } from 'test/lib/utils'; const chainId = ChainId.MAINNET; -const bal = new Token(chainId, BAL, 18); -const weth = new Token(chainId, NATIVE_ASSETS[chainId].wrapped, 18); +const bal = new BaseToken(chainId, BAL, 18); +const weth = new BaseToken(chainId, NATIVE_ASSETS[chainId].wrapped, 18); describe('auraBalSwaps:Integration tests', () => { let rpcUrl: string; @@ -91,8 +91,8 @@ describe('auraBalSwaps:Integration tests', () => { async function testAuraBalSwap( client: PublicWalletClient & TestActions, - tokenIn: Token, - tokenOut: Token, + tokenIn: BaseToken, + tokenOut: BaseToken, tokenInSlot: number, rpcUrl: string, wethIsEth = false, @@ -144,7 +144,7 @@ async function testAuraBalSwap( if ( wethIsEth && - tokenIn.isUnderlyingEqual(NATIVE_ASSETS[ChainId.MAINNET]) + tokenIn.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped) ) { expect(queryOutput.inputAmount.amount).to.equal(balanceDeltas[2]); expect(queryOutput.expectedAmountOut.amount).to.equal(balanceDeltas[1]); @@ -152,7 +152,7 @@ async function testAuraBalSwap( expect(balanceDeltas[0]).to.eq(0n); } else if ( wethIsEth && - tokenOut.isUnderlyingEqual(NATIVE_ASSETS[ChainId.MAINNET]) + tokenOut.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped) ) { expect(queryOutput.inputAmount.amount).to.equal(balanceDeltas[0]); expect(queryOutput.expectedAmountOut.amount).to.equal(balanceDeltas[2]); diff --git a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts index d0dd1c052..dedd258d3 100644 --- a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts @@ -1,16 +1,17 @@ // pnpm test -- parseInputs.test.ts -import { AuraBalSwapKind, Token, TokenAmount } from '@/entities'; +import { AuraBalSwapKind, TokenAmount } from '@/entities'; +import { BaseToken } from '@/entities/baseToken'; import { auraBalToken } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; import { parseInputs } from '@/entities/swap/swaps/v2/auraBalSwaps/parseInputs'; import { SwapKind } from '@/types'; import { ChainId, inputValidationError } from '@/utils'; -const usdc = new Token( +const usdc = new BaseToken( ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, ); -const bal = new Token( +const bal = new BaseToken( ChainId.MAINNET, '0xba100000625a3754423978a60c9317c58a424e3D', 18, diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 8b1c2fe3e..9e45eda3b 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -15,7 +15,7 @@ import { NATIVE_ASSETS, PoolState, Slippage, - Token, + TokenAmount, VAULT_V2, Permit2Helper, @@ -24,6 +24,7 @@ import { PublicWalletClient, missingParameterError, } from 'src'; +import { BaseToken } from '@/entities/baseToken'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; @@ -208,7 +209,7 @@ export function assertAddLiquidityUnbalanced( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsIn = poolState.tokens.map((t) => { - const token = new Token( + const token = new BaseToken( addLiquidityInput.chainId, t.address, t.decimals, @@ -290,7 +291,7 @@ export function assertAddLiquiditySingleToken( protocolVersion, ); - const bptToken = new Token( + const bptToken = new BaseToken( addLiquidityInput.chainId, poolState.address, 18, diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 4ee7449e6..6b63d9d1b 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -17,10 +17,10 @@ import { RemoveLiquidityUnbalancedInput, RemoveLiquidityV3BuildCallInput, Slippage, - Token, TokenAmount, VAULT_V2, } from 'src'; +import { BaseToken } from '@/entities/baseToken'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances, TxOutput } from './helper'; import { RemoveLiquidityTxInput } from './types'; @@ -206,7 +206,7 @@ export function assertRemoveLiquidityUnbalanced( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsOut = poolState.tokens.map((t) => { - const token = new Token( + const token = new BaseToken( removeLiquidityInput.chainId, t.address, t.decimals, @@ -274,7 +274,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsOut = poolState.tokens.map((t) => { - const token = new Token( + const token = new BaseToken( removeLiquidityInput.chainId, t.address, t.decimals, @@ -361,7 +361,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( protocolVersion, ); - const bptToken = new Token( + const bptToken = new BaseToken( removeLiquidityInput.chainId, poolState.address, 18, @@ -451,7 +451,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new Token( + const bptToken = new BaseToken( removeLiquidityInput.chainId, poolState.address, 18, diff --git a/test/lib/utils/removeLiquidityRecoveryHelper.ts b/test/lib/utils/removeLiquidityRecoveryHelper.ts index 0f1ded47d..89de7db20 100644 --- a/test/lib/utils/removeLiquidityRecoveryHelper.ts +++ b/test/lib/utils/removeLiquidityRecoveryHelper.ts @@ -8,10 +8,10 @@ import { RemoveLiquidityRecoveryInput, RemoveLiquidityV3BuildCallInput, Slippage, - Token, TokenAmount, VAULT_V2, } from 'src'; +import { BaseToken } from '@/entities/baseToken'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances } from './helper'; import { RemoveLiquidityRecoveryTxInput } from './types'; @@ -145,7 +145,7 @@ export function assertRemoveLiquidityRecovery( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new Token( + const bptToken = new BaseToken( removeLiquidityRecoveryInput.chainId, poolState.address, 18, diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts index 3b22ac6e4..857b55841 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts @@ -39,19 +39,20 @@ import { import { validateTokenAmounts } from 'test/lib/utils/removeLiquidityNestedHelper'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; const WETH = TOKENS[chainId].WETH; -const parentBptToken = new Token( +const parentBptToken = new BaseToken( chainId, partialBoostedPool_WETH_stataUSDT.address, 18, ); // These are the underlying tokens -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); describe('V3 remove liquidity partial boosted', () => { let rpcUrl: string; diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts index b369e30df..f6b1fa510 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts @@ -17,7 +17,6 @@ import { ChainId, CHAINS, PublicWalletClient, - Token, RemoveLiquidityNestedInput, RemoveLiquidityNestedCallInput, RemoveLiquidityNested, @@ -42,18 +41,19 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; -const parentBptToken = new Token( +const parentBptToken = new BaseToken( chainId, NESTED_WITH_BOOSTED_POOL.address, NESTED_WITH_BOOSTED_POOL.decimals, ); // These are the underlying tokens -const usdcToken = new Token(chainId, USDC.address, USDC.decimals); -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 remove liquidity nested test, with Permit direct approval', () => { From 5a1bd5ced85444ec09b736aff0b5ecdff6c51463 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 7 Oct 2025 16:28:40 +0200 Subject: [PATCH 06/17] chore: lint --- .../addLiquidity/addLiquidityCowAmm/index.ts | 6 +++++- .../removeLiquidity/removeLiquidityCowAmm/index.ts | 12 ++++++++++-- .../stable/removeLiquidityStable.ts | 6 +++++- test/lib/utils/addLiquidityHelper.ts | 1 - 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts index 67b1ed899..748ff0510 100644 --- a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts +++ b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts @@ -52,7 +52,11 @@ export class AddLiquidityCowAmm implements AddLiquidityBase { ); const amountsIn = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken( + input.chainId, + amountIn.address, + amountIn.decimals, + ), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts index d45e3f316..9e14bc212 100644 --- a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts @@ -38,12 +38,20 @@ export class RemoveLiquidityCowAmm implements RemoveLiquidityBase { ); const bptIn = TokenAmount.fromRawAmount( - new BaseToken(input.chainId, input.bptIn.address, input.bptIn.decimals), + new BaseToken( + input.chainId, + input.bptIn.address, + input.bptIn.decimals, + ), input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken( + input.chainId, + amountIn.address, + amountIn.decimals, + ), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts index 36d6ddcad..e6e041c54 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts @@ -104,7 +104,11 @@ export class RemoveLiquidityStable implements RemoveLiquidityBase { ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken(input.chainId, amountIn.address, amountIn.decimals), + new BaseToken( + input.chainId, + amountIn.address, + amountIn.decimals, + ), amountIn.rawAmount, ), ); diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 9e45eda3b..7eab2ef5a 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -15,7 +15,6 @@ import { NATIVE_ASSETS, PoolState, Slippage, - TokenAmount, VAULT_V2, Permit2Helper, From e9bae09f0cc83df5f8089bca7f2f81bcaeb26624 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Wed, 8 Oct 2025 09:37:38 +0200 Subject: [PATCH 07/17] refactor: more Token -> BaseToken --- examples/swaps/auraBalSwap.ts | 6 +++--- examples/swaps/querySmartPath.ts | 6 +++--- examples/swaps/swapV2.ts | 9 +++++---- src/entities/addLiquidityBoosted/index.ts | 6 +++--- .../addLiquidityNestedV3/index.ts | 6 +++--- src/entities/priceImpact/addLiquidityUnbalanced.ts | 1 - .../weighted/removeLiquidityWeighted.ts | 1 - .../removeLiquidityNestedV2/validateInputs.ts | 6 +++--- src/entities/swap/paths/pathWithAmount.ts | 6 +++--- src/entities/utils/getAmounts.ts | 1 - test/api/sorSwapPaths.contract.test.ts | 7 ++++--- test/entities/swaps/swap.test.ts | 14 +++++++------- test/entities/swaps/v2/swapV2.test.ts | 11 ++++++----- test/lib/utils/removeLiquidityNestedHelper.ts | 3 +-- .../composableStable.integration.test.ts | 4 ++-- .../addLiquidityBoosted.integration.test.ts | 12 ++++++------ .../addLiquidityPartialBoosted.integration.test.ts | 6 +++--- .../addLiquidityNestedV3.integration.test.ts | 10 +++++----- ...dLiquidityNestedV3Signature.integration.test.ts | 8 ++++---- .../removeLiquidityBoosted.integration.test.ts | 14 +++++++------- ...moveLiquidityPartialBoosted.integration.test.ts | 3 +-- ...eLiquidityNestedV3Signature.integration.test.ts | 8 ++++---- 22 files changed, 73 insertions(+), 75 deletions(-) diff --git a/examples/swaps/auraBalSwap.ts b/examples/swaps/auraBalSwap.ts index 9bd06c000..f1d964f0f 100644 --- a/examples/swaps/auraBalSwap.ts +++ b/examples/swaps/auraBalSwap.ts @@ -14,7 +14,6 @@ import { Relayer, Slippage, AuraBalSwap, - Token, TokenAmount, SwapKind, isAuraBalSwap, @@ -24,15 +23,16 @@ import { ANVIL_NETWORKS, startFork } from '../../test/anvil/anvil-global-setup'; import { makeForkTx } from 'examples/lib/makeForkTx'; import { getSlot } from 'examples/lib/getSlot'; import { exit } from 'node:process'; +import { BaseToken } from '@/entities/baseToken'; const auraBalSwap = async ({ rpcUrl, client, userAccount, chainId }) => { - const tokenIn = new Token( + const tokenIn = new BaseToken( ChainId.MAINNET, '0xba100000625a3754423978a60c9317c58a424e3D', // BAL 18, ); - const tokenOut = new Token( + const tokenOut = new BaseToken( ChainId.MAINNET, '0x616e8BfA43F920657B3497DBf40D6b1A02D4608d', // auraBal 18, diff --git a/examples/swaps/querySmartPath.ts b/examples/swaps/querySmartPath.ts index 69ab54dcc..d4de9cbae 100644 --- a/examples/swaps/querySmartPath.ts +++ b/examples/swaps/querySmartPath.ts @@ -10,19 +10,19 @@ import { API_ENDPOINT, ChainId, SwapKind, - Token, TokenAmount, Swap, ExactInQueryOutput, ExactOutQueryOutput, } from '../../src'; +import { BaseToken } from '@/entities/baseToken'; interface QuerySmartPath { rpcUrl: string; chainId: ChainId; swapKind: SwapKind; - tokenIn: Token; - tokenOut: Token; + tokenIn: BaseToken; + tokenOut: BaseToken; swapAmount: TokenAmount; } diff --git a/examples/swaps/swapV2.ts b/examples/swaps/swapV2.ts index 8f7df6044..0e6c1d404 100644 --- a/examples/swaps/swapV2.ts +++ b/examples/swaps/swapV2.ts @@ -10,14 +10,15 @@ import { ChainId, Slippage, SwapKind, - Token, - TokenAmount, SwapBuildCallInput, VAULT_V2, } from '../../src'; +import { BaseToken } from '@/entities/baseToken'; import { querySmartPath } from './querySmartPath'; import { setupExampleFork } from '../lib/setupExampleFork'; import { TOKENS, approveSpenderOnToken } from 'test/lib/utils'; +import { TokenAmount } from '@/entities'; + const swapV2 = async () => { // Choose chain id to start fork const chainId = ChainId.MAINNET; @@ -25,13 +26,13 @@ const swapV2 = async () => { // User defines these params for querying swap with SOR const swapKind = SwapKind.GivenIn; - const tokenIn = new Token( + const tokenIn = new BaseToken( chainId, TOKENS[chainId].WETH.address, TOKENS[chainId].WETH.decimals, 'WETH', ); - const tokenOut = new Token( + const tokenOut = new BaseToken( chainId, TOKENS[chainId].BAL.address, TOKENS[chainId].BAL.decimals, diff --git a/src/entities/addLiquidityBoosted/index.ts b/src/entities/addLiquidityBoosted/index.ts index 11fd5e1c2..9102ec34b 100644 --- a/src/entities/addLiquidityBoosted/index.ts +++ b/src/entities/addLiquidityBoosted/index.ts @@ -19,7 +19,7 @@ import { } from '../addLiquidity/types'; import { doAddLiquidityUnbalancedQuery } from './doAddLiquidityUnbalancedQuery'; import { doAddLiquidityProportionalQuery } from './doAddLiquidityPropotionalQuery'; -import { Token } from '../token'; +import { BaseToken } from '@/entities/baseToken'; import { balancerV3Contracts, protocolVersionError } from '@/utils'; import { balancerCompositeLiquidityRouterBoostedAbiExtended, @@ -52,7 +52,7 @@ export class AddLiquidityBoostedV3 { type: 'Boosted', }); - const bptToken = new Token(input.chainId, poolState.address, 18); + const bptToken = new BaseToken(input.chainId, poolState.address, 18); const wrapUnderlying: boolean[] = new Array( poolState.tokens.length, ).fill(false); @@ -151,7 +151,7 @@ export class AddLiquidityBoostedV3 { amountsIn = tokensIn.map((t, i) => { const tokenInAddress = t.toLowerCase() as Address; const { decimals } = poolStateTokenMap[tokenInAddress]; - const token = new Token( + const token = new BaseToken( input.chainId, tokenInAddress, decimals, diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts b/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts index 432261c42..ea7b6f476 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts @@ -11,7 +11,7 @@ import { AddLiquidityNestedBuildCallOutput, AddLiquidityNestedInput, } from '../types'; -import { Token } from '@/entities/token'; +import { BaseToken } from '@/entities/baseToken'; import { getAmounts, getValue } from '@/entities/utils'; import { TokenAmount } from '@/entities/tokenAmount'; import { @@ -57,7 +57,7 @@ export class AddLiquidityNestedV3 { // query function input, `tokensIn` array, must have all tokens from child pools // and all tokens that are not BPTs from the nested pool (parent pool). const mainTokens = nestedPoolState.mainTokens.map( - (t) => new Token(input.chainId, t.address, t.decimals), + (t) => new BaseToken(input.chainId, t.address, t.decimals), ); // This will add 0 amount for any tokensIn the user hasn't included const maxAmountsIn = getAmounts(mainTokens, input.amountsIn, 0n); @@ -74,7 +74,7 @@ export class AddLiquidityNestedV3 { block, ); - const bptToken = new Token(input.chainId, parentPool.address, 18); + const bptToken = new BaseToken(input.chainId, parentPool.address, 18); return { to: BALANCER_COMPOSITE_LIQUIDITY_ROUTER_NESTED[input.chainId], diff --git a/src/entities/priceImpact/addLiquidityUnbalanced.ts b/src/entities/priceImpact/addLiquidityUnbalanced.ts index 246474a82..9e7e26961 100644 --- a/src/entities/priceImpact/addLiquidityUnbalanced.ts +++ b/src/entities/priceImpact/addLiquidityUnbalanced.ts @@ -9,7 +9,6 @@ import { RemoveLiquidityInput, RemoveLiquidityKind, } from '../removeLiquidity/types'; -import { Token } from '../token'; import { TokenAmount } from '../tokenAmount'; import { PoolState } from '../types'; import { priceImpactABA } from './helper'; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index 64eaa4eff..179cfd1b8 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -1,5 +1,4 @@ import { encodeFunctionData } from 'viem'; -import { Token } from '../../../token'; import { TokenAmount } from '../../../tokenAmount'; import { WeightedEncoder } from '../../../encoders/weighted'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts index c45ebd03a..126bf4fcc 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts @@ -1,5 +1,5 @@ import { inputValidationError, NATIVE_ASSETS } from '../../../utils'; -import { Token } from '../../token'; +import { BaseToken } from '../../baseToken'; import { NestedPoolState } from '../../types'; import { RemoveLiquidityNestedCallInputV2, @@ -16,7 +16,7 @@ export const validateQueryInput = ( const tokenOut = 'tokenOut' in input ? input.tokenOut : undefined; const isProportional = tokenOut === undefined; const mainTokens = nestedPoolState.mainTokens.map( - (token) => new Token(input.chainId, token.address, token.decimals), + (token) => new BaseToken(input.chainId, token.address, token.decimals), ); if (!isProportional) { validateInputsSingleToken( @@ -30,7 +30,7 @@ export const validateQueryInput = ( const validateInputsSingleToken = ( input: RemoveLiquidityNestedSingleTokenInputV2, - mainTokens: Token[], + mainTokens: BaseToken[], ) => { const tokenOut = mainTokens.find((t) => t.isSameAddress(input.tokenOut)); diff --git a/src/entities/swap/paths/pathWithAmount.ts b/src/entities/swap/paths/pathWithAmount.ts index c116aed61..9de00695c 100644 --- a/src/entities/swap/paths/pathWithAmount.ts +++ b/src/entities/swap/paths/pathWithAmount.ts @@ -1,6 +1,6 @@ import { TokenAmount } from '../../tokenAmount'; import { Address } from 'viem'; -import { Token } from '../../token'; +import { BaseToken } from '../../baseToken'; import { TokenApi } from './types'; export class PathWithAmount { @@ -18,12 +18,12 @@ export class PathWithAmount { outputAmountRaw: bigint, isBuffer: boolean[] | undefined, ) { - const tokenIn = new Token( + const tokenIn = new BaseToken( chainId, tokens[0].address, tokens[0].decimals, ); - const tokenOut = new Token( + const tokenOut = new BaseToken( chainId, tokens[tokens.length - 1].address, tokens[tokens.length - 1].decimals, diff --git a/src/entities/utils/getAmounts.ts b/src/entities/utils/getAmounts.ts index 9f90d83f1..5e15e40eb 100644 --- a/src/entities/utils/getAmounts.ts +++ b/src/entities/utils/getAmounts.ts @@ -1,6 +1,5 @@ import { InputAmount } from '../../types'; import { BaseToken } from '../baseToken'; -import { Token } from '@/entities/token'; /** * Get amounts from array of TokenAmounts returning default if not a value for tokens. diff --git a/test/api/sorSwapPaths.contract.test.ts b/test/api/sorSwapPaths.contract.test.ts index c8e85f736..607bdbe0b 100644 --- a/test/api/sorSwapPaths.contract.test.ts +++ b/test/api/sorSwapPaths.contract.test.ts @@ -2,7 +2,8 @@ import { describe, it, expect } from 'vitest'; import { BalancerApi } from '@/data/providers/balancer-api'; import { API_ENDPOINT, ChainId } from '@/utils'; import { Address } from 'viem'; -import { Token, TokenAmount } from '@/entities'; +import { TokenAmount } from '@/entities'; +import { BaseToken } from '@/entities/baseToken'; import { SwapKind } from '@/types'; // Inline minimal constants @@ -17,7 +18,7 @@ describe('contract: sor swap paths (live API)', () => { }); it('fetches SOR swap paths', async () => { - const token = new Token(CHAIN_ID, TOKEN_IN, 18); + const token = new BaseToken(CHAIN_ID, TOKEN_IN, 18); const oneUnit = TokenAmount.fromHumanAmount(token, '0.001'); const paths = await api.sorSwapPaths.fetchSorSwapPaths({ chainId: CHAIN_ID, @@ -30,7 +31,7 @@ describe('contract: sor swap paths (live API)', () => { }); it('fetches SOR swap paths with protocol version', async () => { - const token = new Token(CHAIN_ID, TOKEN_IN, 18); + const token = new BaseToken(CHAIN_ID, TOKEN_IN, 18); const oneUnit = TokenAmount.fromHumanAmount(token, '0.001'); const paths = await api.sorSwapPaths.fetchSorSwapPaths({ chainId: CHAIN_ID, diff --git a/test/entities/swaps/swap.test.ts b/test/entities/swaps/swap.test.ts index fb006e78b..6b351553e 100644 --- a/test/entities/swaps/swap.test.ts +++ b/test/entities/swaps/swap.test.ts @@ -3,7 +3,6 @@ import { ChainId, inputValidationError, Slippage } from '@/index'; import { SwapKind } from '@/types'; import { Swap, - Token, TokenAmount, SwapBuildOutputExactIn, SwapBuildOutputExactOut, @@ -11,6 +10,7 @@ import { import { Path, TokenApi } from '@/entities/swap/paths/types'; import { TOKENS } from 'test/lib/utils/addresses'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.MAINNET; const wethIsEth = false; @@ -212,7 +212,7 @@ describe('Swap', () => { describe('GivenIn', () => { const swapKind = SwapKind.GivenIn as const; - const tokenIn = new Token( + const tokenIn = new BaseToken( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -224,7 +224,7 @@ describe('Swap', () => { paths: [pathTo6Decimals], swapKind, }); - const tokenOut = new Token( + const tokenOut = new BaseToken( 1, pathTo6Decimals.tokens[pathTo6Decimals.tokens.length - 1] .address, @@ -260,7 +260,7 @@ describe('Swap', () => { paths: [pathFrom6Decimals], swapKind, }); - const tokenOut = new Token( + const tokenOut = new BaseToken( 1, pathFrom6Decimals.tokens[ pathFrom6Decimals.tokens.length - 1 @@ -295,7 +295,7 @@ describe('Swap', () => { }); describe('GivenOut', () => { const swapKind = SwapKind.GivenOut as const; - const tokenOut = new Token( + const tokenOut = new BaseToken( 1, pathTo6Decimals.tokens[pathTo6Decimals.tokens.length - 1] .address, @@ -310,7 +310,7 @@ describe('Swap', () => { swapKind, }); const slippage = Slippage.fromPercentage('0.1'); - const tokenIn = new Token( + const tokenIn = new BaseToken( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -346,7 +346,7 @@ describe('Swap', () => { swapKind: SwapKind.GivenOut, }); const slippage = Slippage.fromPercentage('0.1'); - const tokenIn = new Token( + const tokenIn = new BaseToken( 1, pathFrom6Decimals.tokens[0].address, pathFrom6Decimals.tokens[0].decimals, diff --git a/test/entities/swaps/v2/swapV2.test.ts b/test/entities/swaps/v2/swapV2.test.ts index 92c8764cd..f698eb61e 100644 --- a/test/entities/swaps/v2/swapV2.test.ts +++ b/test/entities/swaps/v2/swapV2.test.ts @@ -1,7 +1,8 @@ // pnpm test -- swapV2.test.ts import { ChainId } from '@/index'; import { SwapKind } from '@/types'; -import { Token, TokenAmount } from '@/entities'; +import { TokenAmount } from '@/entities'; +import { BaseToken } from '@/entities/baseToken'; import { SwapV2 } from '@/entities/swap/swaps/v2'; import { Path, TokenApi } from '@/entities/swap/paths/types'; @@ -55,7 +56,7 @@ describe('SwapV2', () => { paths: [pathTo6Decimals], swapKind: SwapKind.GivenIn, }); - const tokenOut = new Token( + const tokenOut = new BaseToken( 1, pathTo6Decimals.tokens[ pathTo6Decimals.tokens.length - 1 @@ -80,7 +81,7 @@ describe('SwapV2', () => { paths: [pathFrom6Decimals], swapKind: SwapKind.GivenIn, }); - const tokenOut = new Token( + const tokenOut = new BaseToken( 1, pathFrom6Decimals.tokens[ pathFrom6Decimals.tokens.length - 1 @@ -106,7 +107,7 @@ describe('SwapV2', () => { paths: [pathTo6Decimals], swapKind: SwapKind.GivenOut, }); - const tokenIn = new Token( + const tokenIn = new BaseToken( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -127,7 +128,7 @@ describe('SwapV2', () => { paths: [pathFrom6Decimals], swapKind: SwapKind.GivenOut, }); - const tokenIn = new Token( + const tokenIn = new BaseToken( 1, pathFrom6Decimals.tokens[0].address, pathFrom6Decimals.tokens[0].decimals, diff --git a/test/lib/utils/removeLiquidityNestedHelper.ts b/test/lib/utils/removeLiquidityNestedHelper.ts index 143064575..4a3935ecb 100644 --- a/test/lib/utils/removeLiquidityNestedHelper.ts +++ b/test/lib/utils/removeLiquidityNestedHelper.ts @@ -10,7 +10,6 @@ import { RemoveLiquidityNestedQueryOutput, RemoveLiquidityNestedQueryOutputV3, Slippage, - Token, TokenAmount, } from '@/entities'; import { @@ -232,7 +231,7 @@ export const doRemoveLiquidityNested = async ( removeLiquidityNestedQueryOutput.bptAmountIn, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new Token( + new BaseToken( removeLiquidityNestedQueryOutput.chainId, zeroAddress, 18, diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index a18ca8b65..12eeda10a 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -16,7 +16,6 @@ import { RemoveLiquidityUnbalancedInput, RemoveLiquidityKind, Slippage, - Token, PoolState, RemoveLiquidity, Address, @@ -40,6 +39,7 @@ import { } from '../../lib/utils/removeLiquidityHelper'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { TOKENS } from 'test/lib/utils/addresses'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); @@ -94,7 +94,7 @@ describe('composable stable remove liquidity test', () => { (t) => t.address === txInput.poolState.address, ); const poolTokensWithoutBpt = txInput.poolState.tokens - .map((t) => new Token(chainId, t.address, t.decimals)) + .map((t) => new BaseToken(chainId, t.address, t.decimals)) .filter((_, index) => index !== bptIndex); amountsOut = poolTokensWithoutBpt.map((t) => ({ diff --git a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts index 26bbbec9a..2eae37a03 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts @@ -22,7 +22,6 @@ import { AddLiquidityBoostedV3, Permit2Helper, PERMIT2, - Token, PublicWalletClient, AddLiquidityBoostedBuildCallInput, AddLiquidityBoostedInput, @@ -47,6 +46,7 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; @@ -54,9 +54,9 @@ const USDT = TOKENS[chainId].USDT_AAVE; const stataUSDT = TOKENS[chainId].stataUSDT; // These are the underlying tokens -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const usdcToken = new Token(chainId, USDC.address, USDC.decimals); -const stataUsdtToken = new Token( +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); +const stataUsdtToken = new BaseToken( chainId, stataUSDT.address, stataUSDT.decimals, @@ -618,8 +618,8 @@ describe('Boosted AddLiquidity', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new Token(111555111, USDC.address, USDC.decimals), - new Token(111555111, USDT.address, USDT.decimals), + new BaseToken(111555111, USDC.address, USDC.decimals), + new BaseToken(111555111, USDT.address, USDT.decimals), ], addLiquidityBuildCallOutput.maxAmountsIn.map( (a) => a.token, diff --git a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts index b55757f22..184dfe98b 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts @@ -19,7 +19,6 @@ import { PERMIT2, PublicWalletClient, Slippage, - Token, TokenAmount, AddLiquidityBoostedV3, AddLiquidityKind, @@ -39,14 +38,15 @@ import { } from 'test/lib/utils'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; const WETH = TOKENS[chainId].WETH; // These are the underlying tokens -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); describe('V3 add liquidity partial boosted', () => { let rpcUrl: string; diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts index 59dd4a80e..30d239e55 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts @@ -20,7 +20,6 @@ import { PERMIT2, PublicWalletClient, Slippage, - Token, TokenAmount, AddLiquidityNested, AddLiquidityNestedInput, @@ -28,6 +27,7 @@ import { AddLiquidityNestedCallInput, SDKError, } from '@/index'; +import { BaseToken } from '@/entities/baseToken'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { approveSpenderOnPermit2, @@ -46,15 +46,15 @@ import { const chainId = ChainId.SEPOLIA; -const parentBptToken = new Token( +const parentBptToken = new BaseToken( chainId, NESTED_WITH_BOOSTED_POOL.address, NESTED_WITH_BOOSTED_POOL.decimals, ); // These are the underlying tokens -const usdcToken = new Token(chainId, USDC.address, USDC.decimals); -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 add liquidity nested test, with Permit2 direct approval', () => { diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts index 67cc02e67..9fb2a2d81 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts @@ -17,7 +17,6 @@ import { PERMIT2, PublicWalletClient, Slippage, - Token, TokenAmount, AddLiquidityNested, AddLiquidityNestedInput, @@ -38,13 +37,14 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; // These are the underlying tokens -const usdcToken = new Token(chainId, USDC.address, USDC.decimals); -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 add liquidity nested test, with Permit2 signature', () => { diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts index 5313fec9c..aa06c9168 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts @@ -22,7 +22,6 @@ import { CHAINS, ChainId, PERMIT2, - Token, PublicWalletClient, AddLiquidityBoostedV3, RemoveLiquidityBoostedV3, @@ -45,6 +44,7 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; +import { BaseToken } from '@/entities/baseToken'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; @@ -243,12 +243,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new Token( + new BaseToken( 111555111, USDC.address as Address, USDC.decimals, ), - new Token( + new BaseToken( 111555111, USDT.address as Address, USDT.decimals, @@ -335,12 +335,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order assertTokenMatch( [ - new Token( + new BaseToken( 111555111, USDC.address as Address, USDC.decimals, ), - new Token( + new BaseToken( 111555111, stataUSDT.address as Address, stataUSDT.decimals, @@ -434,12 +434,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new Token( + new BaseToken( 111555111, USDC.address as Address, USDC.decimals, ), - new Token( + new BaseToken( 111555111, USDT.address as Address, USDT.decimals, diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts index 857b55841..d2f8482c2 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts @@ -18,7 +18,6 @@ import { ChainId, CHAINS, PublicWalletClient, - Token, balancerV3Contracts, Slippage, RemoveLiquidityBoostedV3, @@ -258,7 +257,7 @@ describe('V3 remove liquidity partial boosted', () => { queryOutput.bptIn, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new Token(queryOutput.chainId, zeroAddress, 18), + new BaseToken(queryOutput.chainId, zeroAddress, 18), 0n, ), ]; diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts index debf567e1..ad8907dcb 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts @@ -16,7 +16,6 @@ import { ChainId, CHAINS, PublicWalletClient, - Token, RemoveLiquidityNestedInput, RemoveLiquidityNested, BALANCER_COMPOSITE_LIQUIDITY_ROUTER_NESTED, @@ -24,6 +23,7 @@ import { PermitHelper, RemoveLiquidityNestedCallInputV3, } from 'src'; +import { BaseToken } from '@/entities/baseToken'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { @@ -41,9 +41,9 @@ import { const chainId = ChainId.SEPOLIA; // These are the underlying tokens -const usdtToken = new Token(chainId, USDT.address, USDT.decimals); -const usdcToken = new Token(chainId, USDC.address, USDC.decimals); -const wethToken = new Token(chainId, WETH.address, WETH.decimals); +const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); +const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); +const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 remove liquidity nested test, with Permit signature', () => { From fba4dd1e45158a0adb5bc2fa5967210d90fe5385 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Thu, 9 Oct 2025 10:21:47 +0200 Subject: [PATCH 08/17] refactor: add NativeToken --- src/entities/index.ts | 1 + src/entities/nativeToken.ts | 29 ++++++++++++++++ src/utils/constants.ts | 66 ++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 src/entities/nativeToken.ts diff --git a/src/entities/index.ts b/src/entities/index.ts index 3e696b4af..ddbbf64fb 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -30,6 +30,7 @@ export * from './removeLiquidityNested/removeLiquidityNestedV3'; export * from './removeLiquidityNested/removeLiquidityNestedV3/types'; export * from './slippage'; export * from './token'; +export * from './nativeToken'; export * from './tokenAmount'; export * from './types'; export * from './utils'; diff --git a/src/entities/nativeToken.ts b/src/entities/nativeToken.ts new file mode 100644 index 000000000..e6076e0df --- /dev/null +++ b/src/entities/nativeToken.ts @@ -0,0 +1,29 @@ +import { Address } from 'viem'; +import { BaseToken } from './baseToken'; + +/** + * NativeToken extends BaseToken and adds mandatory wrapped token functionality + * This class is specifically designed for native tokens that always have a wrapped version + */ +export class NativeToken extends BaseToken { + public readonly wrapped: Address; + + public constructor( + chainId: number, + address: Address, + decimals: number, + wrapped: Address, + symbol?: string, + name?: string, + ) { + // Call parent constructor with core properties + super(chainId, address, decimals, symbol, name); + + // Set wrapped address (always mandatory for native tokens) + this.wrapped = wrapped.toLowerCase() as Address; + } + + public isUnderlyingEqual(token: NativeToken) { + return this.chainId === token.chainId && this.wrapped === token.wrapped; + } +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index a26f0b4ba..303ff8c08 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,5 +1,5 @@ import { Address, Chain } from 'viem'; -import { Token } from '../entities/token'; +import { NativeToken } from '../entities/nativeToken'; import { arbitrum, avalanche, @@ -144,133 +144,133 @@ export const PERMIT2: Record = { }; export const NATIVE_ASSETS = { - [ChainId.ARBITRUM_ONE]: new Token( + [ChainId.ARBITRUM_ONE]: new NativeToken( ChainId.ARBITRUM_ONE, NATIVE_ADDRESS, 18, + '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 'ETH', 'Ether', - '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', ), - [ChainId.BASE]: new Token( + [ChainId.BASE]: new NativeToken( ChainId.BASE, NATIVE_ADDRESS, 18, + '0x4200000000000000000000000000000000000006', 'ETH', 'Ether', - '0x4200000000000000000000000000000000000006', ), - [ChainId.FANTOM]: new Token( + [ChainId.FANTOM]: new NativeToken( ChainId.FANTOM, NATIVE_ADDRESS, 18, + '0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83', 'FANTOM', 'Fantom', - '0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83', ), - [ChainId.FRAXTAL]: new Token( + [ChainId.FRAXTAL]: new NativeToken( ChainId.FRAXTAL, NATIVE_ADDRESS, 18, + '0xfc00000000000000000000000000000000000006', 'FRAXTAL', 'Fraxtal', - '0xfc00000000000000000000000000000000000006', ), - [ChainId.GNOSIS_CHAIN]: new Token( + [ChainId.GNOSIS_CHAIN]: new NativeToken( ChainId.GNOSIS_CHAIN, NATIVE_ADDRESS, 18, + '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', 'xDAI', 'xDAI', - '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', ), - [ChainId.GOERLI]: new Token( + [ChainId.GOERLI]: new NativeToken( ChainId.GOERLI, NATIVE_ADDRESS, 18, + '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 'ETH', 'Ether', - '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', ), - [ChainId.MAINNET]: new Token( + [ChainId.MAINNET]: new NativeToken( ChainId.MAINNET, NATIVE_ADDRESS, 18, + '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 'ETH', 'Ether', - '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', ), - [ChainId.MODE]: new Token( + [ChainId.MODE]: new NativeToken( ChainId.MODE, NATIVE_ADDRESS, 18, + '0x4200000000000000000000000000000000000006', 'ETH', 'Ether', - '0x4200000000000000000000000000000000000006', ), - [ChainId.OPTIMISM]: new Token( + [ChainId.OPTIMISM]: new NativeToken( ChainId.OPTIMISM, NATIVE_ADDRESS, 18, + '0x4200000000000000000000000000000000000006', 'ETH', 'Ether', - '0x4200000000000000000000000000000000000006', ), - [ChainId.POLYGON]: new Token( + [ChainId.POLYGON]: new NativeToken( ChainId.POLYGON, NATIVE_ADDRESS, 18, + '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', 'MATIC', 'Matic', - '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', ), - [ChainId.SEPOLIA]: new Token( + [ChainId.SEPOLIA]: new NativeToken( ChainId.SEPOLIA, NATIVE_ADDRESS, 18, + '0x7b79995e5f793a07bc00c21412e50ecae098e7f9', 'ETH', 'Ether', - '0x7b79995e5f793a07bc00c21412e50ecae098e7f9', ), - [ChainId.AVALANCHE]: new Token( + [ChainId.AVALANCHE]: new NativeToken( ChainId.AVALANCHE, NATIVE_ADDRESS, 18, + '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', 'AVAX', 'Avax', - '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', ), - [ChainId.ZKEVM]: new Token( + [ChainId.ZKEVM]: new NativeToken( ChainId.ZKEVM, NATIVE_ADDRESS, 18, + '0xa2036f0538221a77a3937f1379699f44945018d0', 'MATIC', 'Matic', - '0xa2036f0538221a77a3937f1379699f44945018d0', ), - [ChainId.SONIC]: new Token( + [ChainId.SONIC]: new NativeToken( ChainId.SONIC, NATIVE_ADDRESS, 18, + '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38', 'S', 'Sonic', - '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38', ), - [ChainId.HYPEREVM]: new Token( + [ChainId.HYPEREVM]: new NativeToken( ChainId.HYPEREVM, HYPEREVM_NATIVE_ADDRESS, 18, + '0x5555555555555555555555555555555555555555', 'HYPE', 'Hype', - '0x5555555555555555555555555555555555555555', ), - [ChainId.PLASMA]: new Token( + [ChainId.PLASMA]: new NativeToken( ChainId.PLASMA, NATIVE_ADDRESS, 18, + '0x6100E367285b01F48D07953803A2d8dCA5D19873', 'XPL', 'Xpl', - '0x6100E367285b01F48D07953803A2d8dCA5D19873', ), }; From e92471e498e6632840e4b51d8ebfd0bc35ffeaca Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Thu, 9 Oct 2025 10:27:47 +0200 Subject: [PATCH 09/17] refactor: complete Token removal --- src/entities/index.ts | 2 +- src/entities/token.ts | 31 ------------------------------- 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 src/entities/token.ts diff --git a/src/entities/index.ts b/src/entities/index.ts index ddbbf64fb..7bfad854c 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -29,8 +29,8 @@ export * from './removeLiquidityNested/removeLiquidityNestedV2/types'; export * from './removeLiquidityNested/removeLiquidityNestedV3'; export * from './removeLiquidityNested/removeLiquidityNestedV3/types'; export * from './slippage'; -export * from './token'; export * from './nativeToken'; +export * from './baseToken'; export * from './tokenAmount'; export * from './types'; export * from './utils'; diff --git a/src/entities/token.ts b/src/entities/token.ts deleted file mode 100644 index 4d550a7ca..000000000 --- a/src/entities/token.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Address } from 'viem'; -import { BaseToken } from './baseToken'; - -/** - * Token extends BaseToken and adds wrapped token functionality - * This maintains backward compatibility while providing a cleaner base class - */ -export class Token extends BaseToken { - public readonly wrapped: Address; - - public constructor( - chainId: number, - address: Address, - decimals: number, - symbol?: string, - name?: string, - wrapped?: Address, - ) { - // Call parent constructor with core properties - super(chainId, address, decimals, symbol, name); - - // Add wrapped functionality - this.wrapped = ( - wrapped ? wrapped.toLowerCase() : address.toLowerCase() - ) as Address; - } - - public isUnderlyingEqual(token: Token) { - return this.chainId === token.chainId && this.wrapped === token.wrapped; - } -} From 526959348dcf0840676862674f3feac137c6d110 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Fri, 10 Oct 2025 10:01:00 +0200 Subject: [PATCH 10/17] refactor: use Token & NativeToken (rename BaseToken back to Token) --- examples/swaps/auraBalSwap.ts | 6 +-- examples/swaps/querySmartPath.ts | 6 +-- examples/swaps/swapV2.ts | 6 +-- .../addLiquidity/addLiquidityCowAmm/index.ts | 10 ++--- .../addLiquidityComposableStable.ts | 4 +- .../stable/addLiquidityStable.ts | 4 +- .../weighted/addLiquidityWeighted.ts | 4 +- .../addLiquidity/addLiquidityV3/index.ts | 4 +- src/entities/addLiquidityBoosted/index.ts | 6 +-- src/entities/addLiquidityBuffer/index.ts | 6 +-- .../getQueryCallsAttributes.ts | 6 +-- .../addLiquidityNestedV2/index.ts | 4 +- .../addLiquidityNestedV2/types.ts | 4 +- .../addLiquidityNestedV2/validateInputs.ts | 4 +- .../addLiquidityNestedV3/index.ts | 6 +-- src/entities/baseToken.ts | 6 +-- src/entities/index.ts | 2 +- .../initPoolComposableStable.ts | 6 +-- .../initPoolV2/weighted/initPoolWeighted.ts | 6 +-- src/entities/initPool/initPoolV3.ts | 6 +-- src/entities/nativeToken.ts | 4 +- .../priceImpact/addLiquidityUnbalanced.ts | 4 +- .../addLiquidityUnbalancedBoosted.ts | 6 +-- src/entities/removeLiquidity/helper.ts | 4 +- .../removeLiquidityCowAmm/index.ts | 14 ++---- .../removeLiquidityComposableStable.ts | 8 ++-- .../stable/removeLiquidityStable.ts | 12 ++--- .../weighted/removeLiquidityWeighted.ts | 8 ++-- .../removeLiquidityV3/index.ts | 4 +- src/entities/removeLiquidityBoosted/index.ts | 6 +-- .../removeLiquidityNestedV2/getPeekCalls.ts | 4 +- .../getQueryCallsAttributes.ts | 10 ++--- .../removeLiquidityNestedV2/types.ts | 4 +- .../removeLiquidityNestedV2/validateInputs.ts | 6 +-- .../removeLiquidityNestedV3/index.ts | 6 +-- src/entities/swap/paths/pathWithAmount.ts | 6 +-- .../swap/swaps/v2/auraBalSwaps/constants.ts | 4 +- .../swap/swaps/v2/auraBalSwaps/exitPool.ts | 4 +- .../swap/swaps/v2/auraBalSwaps/joinPool.ts | 4 +- .../swap/swaps/v2/auraBalSwaps/joinSwap.ts | 4 +- .../swap/swaps/v2/auraBalSwaps/parseInputs.ts | 12 ++--- .../swap/swaps/v2/auraBalSwaps/swapExit.ts | 4 +- .../swap/swaps/v2/auraBalSwaps/types.ts | 8 ++-- src/entities/token.ts | 45 +++++++++++++++++++ src/entities/tokenAmount.ts | 14 +++--- src/entities/utils/getAmounts.ts | 4 +- src/entities/utils/getSortedTokens.ts | 6 +-- src/entities/utils/parseAddLiquidityArgs.ts | 4 +- src/entities/utils/parseInitializeArgs.ts | 4 +- .../utils/parseRemoveLiquidityArgs.ts | 4 +- src/entities/utils/replaceWrapped.ts | 9 ++-- src/utils/helpers.ts | 6 +-- test/api/sorSwapPaths.contract.test.ts | 6 +-- test/entities/swaps/swap.test.ts | 14 +++--- .../auraBalSwaps/auraBal.integration.test.ts | 10 ++--- .../swaps/v2/auraBalSwaps/parseInputs.test.ts | 6 +-- test/entities/swaps/v2/swapV2.test.ts | 10 ++--- test/lib/utils/addLiquidityBoostedHelper.ts | 12 ++--- test/lib/utils/addLiquidityHelper.ts | 6 +-- test/lib/utils/removeLiquidityHelper.ts | 10 ++--- test/lib/utils/removeLiquidityNestedHelper.ts | 8 ++-- .../utils/removeLiquidityRecoveryHelper.ts | 4 +- .../composableStable.integration.test.ts | 4 +- .../addLiquidityBoosted.integration.test.ts | 12 ++--- ...iquidityPartialBoosted.integration.test.ts | 6 +-- .../addLiquidityNestedV3.integration.test.ts | 10 ++--- ...idityNestedV3Signature.integration.test.ts | 8 ++-- ...removeLiquidityBoosted.integration.test.ts | 14 +++--- ...iquidityPartialBoosted.integration.test.ts | 10 ++--- ...emoveLiquidityNestedV3.integration.test.ts | 10 ++--- ...idityNestedV3Signature.integration.test.ts | 8 ++-- 71 files changed, 269 insertions(+), 247 deletions(-) create mode 100644 src/entities/token.ts diff --git a/examples/swaps/auraBalSwap.ts b/examples/swaps/auraBalSwap.ts index f1d964f0f..842a76c21 100644 --- a/examples/swaps/auraBalSwap.ts +++ b/examples/swaps/auraBalSwap.ts @@ -23,16 +23,16 @@ import { ANVIL_NETWORKS, startFork } from '../../test/anvil/anvil-global-setup'; import { makeForkTx } from 'examples/lib/makeForkTx'; import { getSlot } from 'examples/lib/getSlot'; import { exit } from 'node:process'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const auraBalSwap = async ({ rpcUrl, client, userAccount, chainId }) => { - const tokenIn = new BaseToken( + const tokenIn = new Token( ChainId.MAINNET, '0xba100000625a3754423978a60c9317c58a424e3D', // BAL 18, ); - const tokenOut = new BaseToken( + const tokenOut = new Token( ChainId.MAINNET, '0x616e8BfA43F920657B3497DBf40D6b1A02D4608d', // auraBal 18, diff --git a/examples/swaps/querySmartPath.ts b/examples/swaps/querySmartPath.ts index d4de9cbae..4635e03e1 100644 --- a/examples/swaps/querySmartPath.ts +++ b/examples/swaps/querySmartPath.ts @@ -15,14 +15,14 @@ import { ExactInQueryOutput, ExactOutQueryOutput, } from '../../src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; interface QuerySmartPath { rpcUrl: string; chainId: ChainId; swapKind: SwapKind; - tokenIn: BaseToken; - tokenOut: BaseToken; + tokenIn: Token; + tokenOut: Token; swapAmount: TokenAmount; } diff --git a/examples/swaps/swapV2.ts b/examples/swaps/swapV2.ts index 0e6c1d404..fc7017eea 100644 --- a/examples/swaps/swapV2.ts +++ b/examples/swaps/swapV2.ts @@ -13,7 +13,7 @@ import { SwapBuildCallInput, VAULT_V2, } from '../../src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { querySmartPath } from './querySmartPath'; import { setupExampleFork } from '../lib/setupExampleFork'; import { TOKENS, approveSpenderOnToken } from 'test/lib/utils'; @@ -26,13 +26,13 @@ const swapV2 = async () => { // User defines these params for querying swap with SOR const swapKind = SwapKind.GivenIn; - const tokenIn = new BaseToken( + const tokenIn = new Token( chainId, TOKENS[chainId].WETH.address, TOKENS[chainId].WETH.decimals, 'WETH', ); - const tokenOut = new BaseToken( + const tokenOut = new Token( chainId, TOKENS[chainId].BAL.address, TOKENS[chainId].BAL.decimals, diff --git a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts index 748ff0510..b08a01a0a 100644 --- a/src/entities/addLiquidity/addLiquidityCowAmm/index.ts +++ b/src/entities/addLiquidity/addLiquidityCowAmm/index.ts @@ -1,6 +1,6 @@ import { encodeFunctionData } from 'viem'; import { cowAmmPoolAbi } from '@/abi/cowAmmPool'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { poolTypeError, protocolVersionError } from '@/utils'; @@ -47,16 +47,12 @@ export class AddLiquidityCowAmm implements AddLiquidityBase { ); const bptOut = TokenAmount.fromRawAmount( - new BaseToken(input.chainId, bptAmount.address, bptAmount.decimals), + new Token(input.chainId, bptAmount.address, bptAmount.decimals), bptAmount.rawAmount, ); const amountsIn = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken( - input.chainId, - amountIn.address, - amountIn.decimals, - ), + new Token(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 54cc3252e..a6c1e30bf 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; @@ -56,7 +56,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts b/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts index c0bd0c8b5..a4b241089 100644 --- a/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/stable/addLiquidityStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { StableEncoder } from '@/entities/encoders/stable'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; @@ -49,7 +49,7 @@ export class AddLiquidityStable implements AddLiquidityBase { args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 619352fbf..ea9c10990 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { WeightedEncoder } from '@/entities/encoders/weighted'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; @@ -51,7 +51,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptOut = TokenAmount.fromRawAmount(bpt, queryOutput.bptOut); const amountsIn = queryOutput.amountsIn.map((a, i) => diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 6678926f1..ee1fec5e0 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -1,7 +1,7 @@ import { encodeFunctionData, zeroAddress } from 'viem'; import { balancerRouterAbiExtended } from '@/abi'; import { Permit2 } from '@/entities/permit2Helper'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { @@ -33,7 +33,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { block?: bigint, ): Promise { const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); let bptOut: TokenAmount; let amountsIn: TokenAmount[]; diff --git a/src/entities/addLiquidityBoosted/index.ts b/src/entities/addLiquidityBoosted/index.ts index 9102ec34b..b75fb0679 100644 --- a/src/entities/addLiquidityBoosted/index.ts +++ b/src/entities/addLiquidityBoosted/index.ts @@ -19,7 +19,7 @@ import { } from '../addLiquidity/types'; import { doAddLiquidityUnbalancedQuery } from './doAddLiquidityUnbalancedQuery'; import { doAddLiquidityProportionalQuery } from './doAddLiquidityPropotionalQuery'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { balancerV3Contracts, protocolVersionError } from '@/utils'; import { balancerCompositeLiquidityRouterBoostedAbiExtended, @@ -52,7 +52,7 @@ export class AddLiquidityBoostedV3 { type: 'Boosted', }); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const wrapUnderlying: boolean[] = new Array( poolState.tokens.length, ).fill(false); @@ -151,7 +151,7 @@ export class AddLiquidityBoostedV3 { amountsIn = tokensIn.map((t, i) => { const tokenInAddress = t.toLowerCase() as Address; const { decimals } = poolStateTokenMap[tokenInAddress]; - const token = new BaseToken( + const token = new Token( input.chainId, tokenInAddress, decimals, diff --git a/src/entities/addLiquidityBuffer/index.ts b/src/entities/addLiquidityBuffer/index.ts index c6dde7841..ad8b24bdb 100644 --- a/src/entities/addLiquidityBuffer/index.ts +++ b/src/entities/addLiquidityBuffer/index.ts @@ -6,7 +6,7 @@ import { Permit2 } from '@/entities/permit2Helper'; import { BufferState } from '@/entities/types'; import { doAddLiquidityQuery } from './doAddLiquidityQuery'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { balancerBufferRouterAbiExtended, balancerRouterAbiExtended, @@ -35,7 +35,7 @@ export class AddLiquidityBufferV3 { input.exactSharesToIssue, block, ); - const underlyingToken = new BaseToken( + const underlyingToken = new Token( input.chainId, bufferState.underlyingToken.address, bufferState.underlyingToken.decimals, @@ -44,7 +44,7 @@ export class AddLiquidityBufferV3 { underlyingToken, amountUnderlyingIn, ); - const wrappedToken = new BaseToken( + const wrappedToken = new Token( input.chainId, bufferState.wrappedToken.address, bufferState.wrappedToken.decimals, diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts index 90e279135..4aae69e11 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/getQueryCallsAttributes.ts @@ -1,5 +1,5 @@ import { Address, PoolType } from '@/types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { ZERO_ADDRESS, BALANCER_RELAYER, @@ -31,7 +31,7 @@ export const getQueryCallsAttributes = ( for (const pool of poolsSortedByLevel) { const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new BaseToken(chainId, t.address, t.decimals)); + .map((t) => new Token(chainId, t.address, t.decimals)); const maxAmountsIn = getMaxAmountsIn(sortedTokens, amountsIn, calls); if (maxAmountsIn.every((a) => a.amount === 0n && !a.isRef)) { continue; @@ -61,7 +61,7 @@ export const getQueryCallsAttributes = ( }; const getMaxAmountsIn = ( - sortedTokens: BaseToken[], + sortedTokens: Token[], amountsIn: { address: Address; rawAmount: bigint }[], calls: AddLiquidityNestedCallAttributes[], ): { amount: bigint; isRef: boolean }[] => { diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts index fdb5ff02a..3dcdc9536 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/index.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '../../baseToken'; +import { Token } from '../../token'; import { BALANCER_RELAYER, ZERO_ADDRESS } from '../../../utils'; import { Relayer } from '../../relayer'; import { encodeCalls } from './encodeCalls'; @@ -50,7 +50,7 @@ export class AddLiquidityNestedV2 { encodedMulticall, ); - const tokenOut = new BaseToken( + const tokenOut = new Token( input.chainId, callsAttributes[callsAttributes.length - 1].poolAddress, 18, diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts index a4888caf9..201cdca94 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/types.ts @@ -1,7 +1,7 @@ import { Address, Hex } from 'viem'; import { PoolType } from '../../../types'; import { ChainId } from '../../../utils'; -import { BaseToken } from '../../baseToken'; +import { Token } from '../../token'; import { TokenAmount } from '../../tokenAmount'; import { PoolKind } from '../../types'; import { Slippage } from '@/entities/slippage'; @@ -14,7 +14,7 @@ export type AddLiquidityNestedInputV2 = AddLiquidityNestedBaseInput & { export type AddLiquidityNestedCallAttributes = { chainId: ChainId; wethIsEth?: boolean; - sortedTokens: BaseToken[]; + sortedTokens: Token[]; poolId: Hex; poolAddress: Address; poolType: PoolType; diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts index 840219229..782b16fcc 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts @@ -1,6 +1,6 @@ import { inputValidationError, NATIVE_ASSETS } from '@/utils'; -import { BaseToken } from '../../baseToken'; +import { Token } from '../../token'; import { TokenAmount } from '../../tokenAmount'; import { NestedPoolState } from '../../types'; import { AddLiquidityNestedInput } from '../types'; @@ -11,7 +11,7 @@ export const validateQueryInput = ( nestedPoolState: NestedPoolState, ): TokenAmount[] => { const mainTokens = nestedPoolState.mainTokens.map( - (t) => new BaseToken(input.chainId, t.address, t.decimals), + (t) => new Token(input.chainId, t.address, t.decimals), ); const amountsIn = input.amountsIn.map((amountIn) => { const tokenIn = mainTokens.find((t) => diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts b/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts index ea7b6f476..432261c42 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV3/index.ts @@ -11,7 +11,7 @@ import { AddLiquidityNestedBuildCallOutput, AddLiquidityNestedInput, } from '../types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getAmounts, getValue } from '@/entities/utils'; import { TokenAmount } from '@/entities/tokenAmount'; import { @@ -57,7 +57,7 @@ export class AddLiquidityNestedV3 { // query function input, `tokensIn` array, must have all tokens from child pools // and all tokens that are not BPTs from the nested pool (parent pool). const mainTokens = nestedPoolState.mainTokens.map( - (t) => new BaseToken(input.chainId, t.address, t.decimals), + (t) => new Token(input.chainId, t.address, t.decimals), ); // This will add 0 amount for any tokensIn the user hasn't included const maxAmountsIn = getAmounts(mainTokens, input.amountsIn, 0n); @@ -74,7 +74,7 @@ export class AddLiquidityNestedV3 { block, ); - const bptToken = new BaseToken(input.chainId, parentPool.address, 18); + const bptToken = new Token(input.chainId, parentPool.address, 18); return { to: BALANCER_COMPOSITE_LIQUIDITY_ROUTER_NESTED[input.chainId], diff --git a/src/entities/baseToken.ts b/src/entities/baseToken.ts index b2aa77d12..3ab9eaf5f 100644 --- a/src/entities/baseToken.ts +++ b/src/entities/baseToken.ts @@ -2,11 +2,11 @@ import { Address } from 'viem'; import { InputToken } from '../types'; /** - * BaseToken contains the core functionality for all tokens + * Token contains the core functionality for all tokens * This class handles the essential token properties and methods * without any wrapped token logic */ -export class BaseToken { +export class Token { public readonly chainId: number; public readonly address: Address; public readonly decimals: number; @@ -28,7 +28,7 @@ export class BaseToken { this.name = name; } - public isEqual(token: BaseToken) { + public isEqual(token: Token) { return this.chainId === token.chainId && this.address === token.address; } diff --git a/src/entities/index.ts b/src/entities/index.ts index 7bfad854c..c93a24574 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -30,7 +30,7 @@ export * from './removeLiquidityNested/removeLiquidityNestedV3'; export * from './removeLiquidityNested/removeLiquidityNestedV3/types'; export * from './slippage'; export * from './nativeToken'; -export * from './baseToken'; +export * from './token'; export * from './tokenAmount'; export * from './types'; export * from './utils'; diff --git a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts index 496abb98f..d66039ae7 100644 --- a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts +++ b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts @@ -13,7 +13,7 @@ import { } from '../../types'; import { vaultV2Abi } from '../../../../abi'; import { VAULT_V2, MAX_UINT256 } from '../../../../utils'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getValue } from '@/entities/utils/getValue'; import { TokenAmount } from '@/entities/tokenAmount'; @@ -44,7 +44,7 @@ export class InitPoolComposableStable implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new BaseToken(input.chainId, a.address, a.decimals); + const token = new Token(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -58,7 +58,7 @@ export class InitPoolComposableStable implements InitPoolBase { private getAmounts( input: InitPoolInputV2, poolAddress: Address, - poolTokens: BaseToken[], + poolTokens: Token[], ): InitPoolAmountsComposableStable { const bptIndex = poolTokens.findIndex((t) => t.address === poolAddress); const maxAmountsIn = getAmounts(poolTokens, [ diff --git a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts index 3285c4077..720d98eb6 100644 --- a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts +++ b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts @@ -12,7 +12,7 @@ import { getSortedTokens, parseAddLiquidityArgs, } from '../../../utils'; -import { BaseToken } from '../../../baseToken'; +import { Token } from '../../../token'; import { WeightedEncoder } from '../../../encoders'; import { TokenAmount } from '@/entities/tokenAmount'; import { getValue } from '@/entities/utils/getValue'; @@ -41,7 +41,7 @@ export class InitPoolWeighted implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new BaseToken(input.chainId, a.address, a.decimals); + const token = new Token(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -54,7 +54,7 @@ export class InitPoolWeighted implements InitPoolBase { private getAmounts( input: InitPoolInputV2, - poolTokens: BaseToken[], + poolTokens: Token[], ): InitPoolAmounts { return { maxAmountsIn: getAmounts(poolTokens, input.amountsIn), diff --git a/src/entities/initPool/initPoolV3.ts b/src/entities/initPool/initPoolV3.ts index bac7f3b52..e509354e6 100644 --- a/src/entities/initPool/initPoolV3.ts +++ b/src/entities/initPool/initPoolV3.ts @@ -4,7 +4,7 @@ import { InitPoolBase, InitPoolBuildOutput, InitPoolInputV3 } from './types'; import { balancerV3Contracts } from '@/utils'; import { encodeFunctionData, Address } from 'viem'; import { getSortedTokens, parseInitializeArgs, getAmounts } from '../utils'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { TokenAmount } from '../tokenAmount'; import { getValue } from '../utils/getValue'; import { Permit2 } from '@/entities/permit2Helper'; @@ -30,7 +30,7 @@ export class InitPoolV3 implements InitPoolBase { }); const amountsIn = input.amountsIn.map((a) => { - const token = new BaseToken(input.chainId, a.address, a.decimals); + const token = new Token(input.chainId, a.address, a.decimals); return TokenAmount.fromRawAmount(token, a.rawAmount); }); @@ -70,7 +70,7 @@ export class InitPoolV3 implements InitPoolBase { private getAmounts( input: InitPoolInputV3, - tokens: BaseToken[], + tokens: Token[], ): { exactAmountsIn: bigint[] } { return { exactAmountsIn: getAmounts(tokens, input.amountsIn), diff --git a/src/entities/nativeToken.ts b/src/entities/nativeToken.ts index e6076e0df..e09d51cb3 100644 --- a/src/entities/nativeToken.ts +++ b/src/entities/nativeToken.ts @@ -1,11 +1,11 @@ import { Address } from 'viem'; -import { BaseToken } from './baseToken'; +import { Token } from './token'; /** * NativeToken extends BaseToken and adds mandatory wrapped token functionality * This class is specifically designed for native tokens that always have a wrapped version */ -export class NativeToken extends BaseToken { +export class NativeToken extends Token { public readonly wrapped: Address; public constructor( diff --git a/src/entities/priceImpact/addLiquidityUnbalanced.ts b/src/entities/priceImpact/addLiquidityUnbalanced.ts index 9e7e26961..00aa0d70a 100644 --- a/src/entities/priceImpact/addLiquidityUnbalanced.ts +++ b/src/entities/priceImpact/addLiquidityUnbalanced.ts @@ -13,7 +13,7 @@ import { TokenAmount } from '../tokenAmount'; import { PoolState } from '../types'; import { priceImpactABA } from './helper'; import { Swap, SwapInput } from '../swap'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; export const addLiquidityUnbalanced = async ( input: AddLiquidityUnbalancedInput, @@ -25,7 +25,7 @@ export const addLiquidityUnbalanced = async ( const addLiquidity = new AddLiquidity(); let amountsIn: TokenAmount[]; let bptOut: TokenAmount; - let poolTokens: BaseToken[]; + let poolTokens: Token[]; try { const queryResult = await addLiquidity.query(input, poolState); amountsIn = queryResult.amountsIn; diff --git a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts index dc4397bd8..0e5ee31a2 100644 --- a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts +++ b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts @@ -11,7 +11,7 @@ import { AddLiquidityBoostedV3 } from '../addLiquidityBoosted'; import { RemoveLiquidityBoostedV3 } from '../removeLiquidityBoosted'; import { RemoveLiquidityBoostedProportionalInput } from '../removeLiquidityBoosted/types'; import { Address, BaseError, ContractFunctionRevertedError } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; /** * Calculate price impact on add liquidity unbalanced operations @@ -131,7 +131,7 @@ async function queryAddLiquidityForTokenDelta( addLiquidity: AddLiquidityBoostedV3, input: AddLiquidityBoostedUnbalancedInput, poolState: PoolStateWithUnderlyings, - poolTokens: BaseToken[], + poolTokens: Token[], tokenIndex: number, delta: bigint, ): Promise { @@ -178,7 +178,7 @@ async function zeroOutDeltas( addLiquidity: AddLiquidityBoostedV3, input: AddLiquidityBoostedUnbalancedInput, poolState: PoolStateWithUnderlyings, - poolTokens: BaseToken[], + poolTokens: Token[], deltas: bigint[], deltaBPTs: bigint[], ) { diff --git a/src/entities/removeLiquidity/helper.ts b/src/entities/removeLiquidity/helper.ts index 46da5adc6..5ae59e277 100644 --- a/src/entities/removeLiquidity/helper.ts +++ b/src/entities/removeLiquidity/helper.ts @@ -1,5 +1,5 @@ import { MAX_UINT256, missingParameterError } from '@/utils'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { RemoveLiquidityAmounts } from '../types'; import { getAmounts } from '../utils'; import { @@ -9,7 +9,7 @@ import { } from './types'; export const getAmountsQuery = ( - tokens: BaseToken[], + tokens: Token[], input: RemoveLiquidityInput, bptIndex = -1, ): RemoveLiquidityAmounts => { diff --git a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts index 9e14bc212..256a6ba38 100644 --- a/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityCowAmm/index.ts @@ -1,4 +1,4 @@ -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { @@ -38,20 +38,12 @@ export class RemoveLiquidityCowAmm implements RemoveLiquidityBase { ); const bptIn = TokenAmount.fromRawAmount( - new BaseToken( - input.chainId, - input.bptIn.address, - input.bptIn.decimals, - ), + new Token(input.chainId, input.bptIn.address, input.bptIn.decimals), input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken( - input.chainId, - amountIn.address, - amountIn.decimals, - ), + new Token(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index 10d0ce37e..4f52116ac 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '../../../baseToken'; +import { Token } from '../../../token'; import { TokenAmount } from '../../../tokenAmount'; import { protocolVersionError, @@ -68,7 +68,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { input.chainId, args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -106,7 +106,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, @@ -116,7 +116,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { ); let amountsOut = tokenAmounts.map((amount) => TokenAmount.fromRawAmount( - new BaseToken(input.chainId, amount.address, amount.decimals), + new Token(input.chainId, amount.address, amount.decimals), amount.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts index e6e041c54..5a2febdac 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/stable/removeLiquidityStable.ts @@ -1,5 +1,5 @@ import { encodeFunctionData } from 'viem'; -import { BaseToken } from '../../../baseToken'; +import { Token } from '../../../token'; import { TokenAmount } from '../../../tokenAmount'; import { StableEncoder } from '../../../encoders/stable'; import { @@ -60,7 +60,7 @@ export class RemoveLiquidityStable implements RemoveLiquidityBase { args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -97,18 +97,14 @@ export class RemoveLiquidityStable implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amountIn) => TokenAmount.fromRawAmount( - new BaseToken( - input.chainId, - amountIn.address, - amountIn.decimals, - ), + new Token(input.chainId, amountIn.address, amountIn.decimals), amountIn.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index 179cfd1b8..cb0c6e855 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -21,7 +21,7 @@ import { } from '../../../utils'; import { getAmountsCall, getAmountsQuery } from '../../helper'; import { RemoveLiquidityV2BaseBuildCallInput } from '../types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; export class RemoveLiquidityWeighted implements RemoveLiquidityBase { public async query( @@ -56,7 +56,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { args, ); - const bpt = new BaseToken(input.chainId, poolState.address, 18); + const bpt = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount(bpt, queryOutput.bptIn); const amountsOut = queryOutput.amountsOut.map((a, i) => @@ -92,14 +92,14 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { input.bptIn, ); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const bptIn = TokenAmount.fromRawAmount( bptToken, input.bptIn.rawAmount, ); const amountsOut = tokenAmounts.map((amount) => TokenAmount.fromRawAmount( - new BaseToken(input.chainId, amount.address, amount.decimals), + new Token(input.chainId, amount.address, amount.decimals), amount.rawAmount, ), ); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/index.ts b/src/entities/removeLiquidity/removeLiquidityV3/index.ts index a9b94d6e6..181925c90 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/index.ts @@ -1,4 +1,4 @@ -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolState } from '@/entities/types'; import { getSortedTokens } from '@/entities/utils'; @@ -108,7 +108,7 @@ export class RemoveLiquidityV3 implements RemoveLiquidityBase { break; } - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const output: RemoveLiquidityBaseQueryOutput & { userData: Hex } = { to: AddressProvider.Router(input.chainId), diff --git a/src/entities/removeLiquidityBoosted/index.ts b/src/entities/removeLiquidityBoosted/index.ts index c590d9525..f4c82d87a 100644 --- a/src/entities/removeLiquidityBoosted/index.ts +++ b/src/entities/removeLiquidityBoosted/index.ts @@ -13,7 +13,7 @@ import { balancerCompositeLiquidityRouterBoostedAbiExtended } from '@/abi'; import { PoolStateWithUnderlyings } from '@/entities/types'; import { TokenAmount } from '@/entities/tokenAmount'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getAmountsCall } from '../removeLiquidity/helper'; @@ -68,11 +68,11 @@ export class RemoveLiquidityBoostedV3 implements RemoveLiquidityBase { const { decimals } = poolStateTokenMap[tokenOut.toLowerCase() as Address]; - const token = new BaseToken(input.chainId, tokenOut, decimals); + const token = new Token(input.chainId, tokenOut, decimals); return TokenAmount.fromRawAmount(token, amount); }); - const bptToken = new BaseToken(input.chainId, poolState.address, 18); + const bptToken = new Token(input.chainId, poolState.address, 18); const output: RemoveLiquidityBoostedQueryOutput = { to: AddressProvider.CompositeLiquidityRouter(input.chainId), diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts index 835e2abca..8b8cd1fc9 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getPeekCalls.ts @@ -1,13 +1,13 @@ import { Hex } from 'viem'; import { RemoveLiquidityNestedCallAttributesV2 } from './types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { Relayer } from '@/entities/relayer'; export const getPeekCalls = ( calls: RemoveLiquidityNestedCallAttributesV2[], isProportional: boolean, ) => { - const tokensOut: BaseToken[] = []; + const tokensOut: Token[] = []; const peekCalls: Hex[] = []; if (isProportional) { diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts index 160574a0c..c1d41923a 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/getQueryCallsAttributes.ts @@ -2,7 +2,7 @@ import { Address } from 'viem'; import { TokenAmount } from '@/entities/tokenAmount'; import { BALANCER_RELAYER, ChainId, ZERO_ADDRESS } from '@/utils'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { NestedPoolV2, PoolKind } from '@/entities/types'; import { RemoveLiquidityNestedCallAttributesV2, @@ -51,7 +51,7 @@ export const getQueryCallsAttributes = ( ); } - const bptIn = new BaseToken(chainId, poolsTopDown[0].address, 18); + const bptIn = new Token(chainId, poolsTopDown[0].address, 18); const _bptAmountIn = TokenAmount.fromRawAmount(bptIn, bptAmountIn); return { callsAttributes, bptAmountIn: _bptAmountIn }; }; @@ -74,7 +74,7 @@ const getProportionalCallsAttributes = ( for (const pool of poolsSortedByLevel) { const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new BaseToken(chainId, t.address, t.decimals)); + .map((t) => new Token(chainId, t.address, t.decimals)); const sortedTokensWithoutBpt = sortedTokens.filter( (t) => !t.isSameAddress(pool.address), @@ -139,7 +139,7 @@ const getSingleTokenCallsAttributes = ( const pool = removeLiquidityPath[i]; const sortedTokens = pool.tokens .sort((a, b) => a.index - b.index) - .map((t) => new BaseToken(chainId, t.address, t.decimals)); + .map((t) => new Token(chainId, t.address, t.decimals)); const isLastCall = i === removeLiquidityPath.length - 1; const currenTokenOut = isLastCall ? tokenOut @@ -261,7 +261,7 @@ const getSenderProportional = ( // Recipient's logic: if there is at least one token that is an output of the // whole multicall, then the recipient is the user, otherwise it's the relayer. const getRecipientProportional = ( - sortedTokensWithoutBpt: BaseToken[], + sortedTokensWithoutBpt: Token[], poolsSortedByLevel: NestedPoolV2[], accountAddress: Address, chainId: ChainId, diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts index 5fc136fb8..7d65eaa43 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/types.ts @@ -1,6 +1,6 @@ import { Address, Hex } from 'viem'; import { Slippage } from '@/entities/slippage'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { PoolKind } from '@/entities/types'; import { PoolType } from '@/types'; @@ -20,7 +20,7 @@ export type RemoveLiquidityNestedSingleTokenInputV2 = export type RemoveLiquidityNestedCallAttributesV2 = { chainId: ChainId; - sortedTokens: BaseToken[]; + sortedTokens: Token[]; poolId: Address; poolAddress: Address; poolType: PoolType; diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts index 126bf4fcc..c45ebd03a 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV2/validateInputs.ts @@ -1,5 +1,5 @@ import { inputValidationError, NATIVE_ASSETS } from '../../../utils'; -import { BaseToken } from '../../baseToken'; +import { Token } from '../../token'; import { NestedPoolState } from '../../types'; import { RemoveLiquidityNestedCallInputV2, @@ -16,7 +16,7 @@ export const validateQueryInput = ( const tokenOut = 'tokenOut' in input ? input.tokenOut : undefined; const isProportional = tokenOut === undefined; const mainTokens = nestedPoolState.mainTokens.map( - (token) => new BaseToken(input.chainId, token.address, token.decimals), + (token) => new Token(input.chainId, token.address, token.decimals), ); if (!isProportional) { validateInputsSingleToken( @@ -30,7 +30,7 @@ export const validateQueryInput = ( const validateInputsSingleToken = ( input: RemoveLiquidityNestedSingleTokenInputV2, - mainTokens: BaseToken[], + mainTokens: Token[], ) => { const tokenOut = mainTokens.find((t) => t.isSameAddress(input.tokenOut)); diff --git a/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts b/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts index 777395ab9..86da29ad2 100644 --- a/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts +++ b/src/entities/removeLiquidityNested/removeLiquidityNestedV3/index.ts @@ -20,7 +20,7 @@ import { SDKError, } from '@/utils'; import { balancerCompositeLiquidityRouterNestedAbiExtended } from '@/abi'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; export class RemoveLiquidityNestedV3 { @@ -43,10 +43,10 @@ export class RemoveLiquidityNestedV3 { // query function input, `tokensIn` array, must have all tokens from child pools // and all tokens that are not BPTs from the nested pool (parent pool). const mainTokens = nestedPoolState.mainTokens.map( - (t) => new BaseToken(input.chainId, t.address, t.decimals), + (t) => new Token(input.chainId, t.address, t.decimals), ); - const bptToken = new BaseToken(input.chainId, parentPool.address, 18); + const bptToken = new Token(input.chainId, parentPool.address, 18); const amountsOut = await this.doQueryRemoveLiquidityProportionalNestedPool( diff --git a/src/entities/swap/paths/pathWithAmount.ts b/src/entities/swap/paths/pathWithAmount.ts index 9de00695c..c116aed61 100644 --- a/src/entities/swap/paths/pathWithAmount.ts +++ b/src/entities/swap/paths/pathWithAmount.ts @@ -1,6 +1,6 @@ import { TokenAmount } from '../../tokenAmount'; import { Address } from 'viem'; -import { BaseToken } from '../../baseToken'; +import { Token } from '../../token'; import { TokenApi } from './types'; export class PathWithAmount { @@ -18,12 +18,12 @@ export class PathWithAmount { outputAmountRaw: bigint, isBuffer: boolean[] | undefined, ) { - const tokenIn = new BaseToken( + const tokenIn = new Token( chainId, tokens[0].address, tokens[0].decimals, ); - const tokenOut = new BaseToken( + const tokenOut = new Token( chainId, tokens[tokens.length - 1].address, tokens[tokens.length - 1].decimals, diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts b/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts index a1357d91c..1d510fa63 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/constants.ts @@ -1,11 +1,11 @@ import { Address } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { ChainId, NATIVE_ASSETS } from '@/utils'; export const BAL = '0xba100000625a3754423978a60c9317c58a424e3d'; export const auraBAL = '0x616e8BfA43F920657B3497DBf40D6b1A02D4608d'; export const supportedTokens = [BAL, NATIVE_ASSETS[ChainId.MAINNET].wrapped]; -export const auraBalToken = new BaseToken(ChainId.MAINNET, auraBAL, 18); +export const auraBalToken = new Token(ChainId.MAINNET, auraBAL, 18); export const balWethId = '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014'; export const balWethAddress = diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts index ff3488fce..8ff64007a 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/exitPool.ts @@ -5,7 +5,7 @@ import { parseAbiParameters, Hex, } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { BALANCER_RELAYER, ChainId, inputValidationError } from '@/utils'; import { batchRelayerLibraryAbi } from '@/abi'; import { Relayer } from '@/entities/relayer'; @@ -13,7 +13,7 @@ import { balWethAssets, balWethId } from './constants'; import { replaceWrapped } from './replaceWrapped'; export function encodeExitData( - token: BaseToken, + token: Token, userAddress: Address, swapOpRef: bigint, limit: bigint, diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts index 3d87dd25d..a270d304e 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts @@ -5,7 +5,7 @@ import { parseAbiParameters, Hex, } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { BALANCER_RELAYER, ChainId, @@ -18,7 +18,7 @@ import { balWethAssets, balWethId } from './constants'; import { replaceWrapped } from './replaceWrapped'; export function encodeJoinData( - token: BaseToken, + token: Token, sender: Address, inputAmount: bigint, wethIsEth: boolean, diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts index b61f8b6af..c785a8a2b 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinSwap.ts @@ -14,7 +14,7 @@ import { auraBalToken, balWethAddress, auraBAL } from './constants'; import { encodeJoinData } from './joinPool'; import { encodeSwapData } from './swap'; import { AuraBalSwapQueryOutput, AuraBalSwapQueryInput } from './types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; // token[join]8020BPT[swap]auraBAL export async function queryJoinSwap( @@ -81,7 +81,7 @@ export function buildJoinSwapCall( userAddress: Address, inputAmount: bigint, swapLimit: bigint, - joinToken: BaseToken, + joinToken: Token, wethIsEth: boolean, relayerApprovalSignature?: Hex, ): { callData: Hex; value: bigint } { diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts b/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts index 5dc399858..ceb2822cb 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/parseInputs.ts @@ -1,5 +1,5 @@ import { Address } from 'viem'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { AuraBalSwapKind, SwapQueryInput, @@ -21,8 +21,8 @@ export function isAuraBalSwap(input: SwapQueryInput): boolean { } function isMainnet( - tokenIn: BaseToken, - tokenOut: BaseToken, + tokenIn: Token, + tokenOut: Token, swapAmount: TokenAmount, ): boolean { if ( @@ -36,7 +36,7 @@ function isMainnet( return true; } -function isAddressEqual(token: BaseToken, amount: TokenAmount): boolean { +function isAddressEqual(token: Token, amount: TokenAmount): boolean { if (!token.isSameAddress(amount.token.address)) throw inputValidationError( 'auraBal Swap', @@ -51,7 +51,7 @@ function isGivenIn(kind: SwapKind): boolean { return true; } -function hasSupportedTokens(tokenIn: BaseToken, tokenOut: BaseToken): boolean { +function hasSupportedTokens(tokenIn: Token, tokenOut: Token): boolean { const tokenInIsAuraBal = auraBalToken.isSameAddress(tokenIn.address); const tokenOutIsAuraBal = auraBalToken.isSameAddress(tokenOut.address); if (tokenInIsAuraBal && tokenOutIsAuraBal) @@ -93,6 +93,6 @@ export function parseInputs(input: SwapQueryInput): AuraBalSwapQueryInput { }; } -function isSupportedToken(token: BaseToken): boolean { +function isSupportedToken(token: Token): boolean { return supportedTokens.some((t) => token.isSameAddress(t as Address)); } diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts index 5b3283dce..ab5cd7d1d 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/swapExit.ts @@ -13,7 +13,7 @@ import { Relayer } from '@/entities/relayer'; import { auraBalToken, balWethAddress, auraBAL } from './constants'; import { encodeSwapData } from './swap'; import { AuraBalSwapQueryOutput, AuraBalSwapQueryInput } from './types'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { encodeExitData } from './exitPool'; // auraBal[swap]8020Bpt[exit]token @@ -86,7 +86,7 @@ export function buildSwapExitCall( user: Address, inputAmount: bigint, exitLimit: bigint, - exitToken: BaseToken, + exitToken: Token, wethIsEth: boolean, relayerApprovalSignature?: Hex, ): Hex { diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/types.ts b/src/entities/swap/swaps/v2/auraBalSwaps/types.ts index 30af3a1e2..d9507f7a7 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/types.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/types.ts @@ -1,17 +1,17 @@ -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { TokenAmount } from '@/entities/tokenAmount'; import { SwapKind } from '@/types'; export type SwapQueryInput = { - tokenIn: BaseToken; - tokenOut: BaseToken; + tokenIn: Token; + tokenOut: Token; kind: SwapKind; swapAmount: TokenAmount; }; export interface AuraBalSwapQueryInput { kind: AuraBalSwapKind; - swapToken: BaseToken; + swapToken: Token; inputAmount: TokenAmount; } diff --git a/src/entities/token.ts b/src/entities/token.ts new file mode 100644 index 000000000..3ab9eaf5f --- /dev/null +++ b/src/entities/token.ts @@ -0,0 +1,45 @@ +import { Address } from 'viem'; +import { InputToken } from '../types'; + +/** + * Token contains the core functionality for all tokens + * This class handles the essential token properties and methods + * without any wrapped token logic + */ +export class Token { + public readonly chainId: number; + public readonly address: Address; + public readonly decimals: number; + public readonly symbol?: string; + public readonly name?: string; + + public constructor( + chainId: number, + address: Address, + decimals: number, + symbol?: string, + name?: string, + ) { + this.chainId = chainId; + // Addresses are always lowercased for speed + this.address = address.toLowerCase() as Address; + this.decimals = decimals; + this.symbol = symbol; + this.name = name; + } + + public isEqual(token: Token) { + return this.chainId === token.chainId && this.address === token.address; + } + + public isSameAddress(address: Address) { + return this.address === address.toLowerCase(); + } + + public toInputToken(): InputToken { + return { + address: this.address, + decimals: this.decimals, + }; + } +} diff --git a/src/entities/tokenAmount.ts b/src/entities/tokenAmount.ts index 7f1383a06..863f3ea2d 100644 --- a/src/entities/tokenAmount.ts +++ b/src/entities/tokenAmount.ts @@ -3,26 +3,26 @@ import { parseUnits } from 'viem'; import { InputAmount, BigintIsh } from '../types'; import { DECIMAL_SCALES } from '../utils/constants'; import { WAD } from '../utils/math'; -import { BaseToken } from './baseToken'; +import { Token } from './token'; export class TokenAmount { - public readonly token: BaseToken; + public readonly token: Token; public readonly scalar: bigint; public readonly decimalScale: bigint; public amount: bigint; public scale18: bigint; - public static fromRawAmount(token: BaseToken, rawAmount: BigintIsh) { + public static fromRawAmount(token: Token, rawAmount: BigintIsh) { return new TokenAmount(token, rawAmount); } - public static fromHumanAmount(token: BaseToken, humanAmount: `${number}`) { + public static fromHumanAmount(token: Token, humanAmount: `${number}`) { const rawAmount = parseUnits(humanAmount, token.decimals); return new TokenAmount(token, rawAmount); } public static fromScale18Amount( - token: BaseToken, + token: Token, scale18Amount: BigintIsh, divUp?: boolean, ) { @@ -37,11 +37,11 @@ export class TokenAmount { input: InputAmount, chainId: number, ): TokenAmount { - const token = new BaseToken(chainId, input.address, input.decimals); + const token = new Token(chainId, input.address, input.decimals); return new TokenAmount(token, input.rawAmount); } - protected constructor(token: BaseToken, amount: BigintIsh) { + protected constructor(token: Token, amount: BigintIsh) { this.decimalScale = DECIMAL_SCALES[token.decimals]; this.token = token; this.amount = BigInt(amount); diff --git a/src/entities/utils/getAmounts.ts b/src/entities/utils/getAmounts.ts index 5e15e40eb..7fc1d3513 100644 --- a/src/entities/utils/getAmounts.ts +++ b/src/entities/utils/getAmounts.ts @@ -1,5 +1,5 @@ import { InputAmount } from '../../types'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; /** * Get amounts from array of TokenAmounts returning default if not a value for tokens. @@ -9,7 +9,7 @@ import { BaseToken } from '../baseToken'; * @returns */ export function getAmounts( - tokens: BaseToken[], + tokens: Token[], amounts: InputAmount[], defaultAmount = 0n, ): bigint[] { diff --git a/src/entities/utils/getSortedTokens.ts b/src/entities/utils/getSortedTokens.ts index ab25384ab..3d28df091 100644 --- a/src/entities/utils/getSortedTokens.ts +++ b/src/entities/utils/getSortedTokens.ts @@ -1,11 +1,11 @@ import { MinimalToken } from '../../data/types'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; export function getSortedTokens( tokens: MinimalToken[], chainId: number, -): BaseToken[] { +): Token[] { return tokens .sort((a, b) => a.index - b.index) - .map((t) => new BaseToken(chainId, t.address, t.decimals)); + .map((t) => new Token(chainId, t.address, t.decimals)); } diff --git a/src/entities/utils/parseAddLiquidityArgs.ts b/src/entities/utils/parseAddLiquidityArgs.ts index e20466331..54572f1fa 100644 --- a/src/entities/utils/parseAddLiquidityArgs.ts +++ b/src/entities/utils/parseAddLiquidityArgs.ts @@ -1,5 +1,5 @@ import { Address, Hex } from '../../types'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { replaceWrapped } from './replaceWrapped'; export function parseAddLiquidityArgs({ @@ -15,7 +15,7 @@ export function parseAddLiquidityArgs({ }: { chainId?: number; wethIsEth?: boolean; - sortedTokens: BaseToken[]; + sortedTokens: Token[]; poolId: Hex; sender: Address; recipient: Address; diff --git a/src/entities/utils/parseInitializeArgs.ts b/src/entities/utils/parseInitializeArgs.ts index 4b9b0a39e..37c8c317c 100644 --- a/src/entities/utils/parseInitializeArgs.ts +++ b/src/entities/utils/parseInitializeArgs.ts @@ -1,5 +1,5 @@ import { Address } from 'viem'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { InitializeArgs } from '../initPool'; import { DEFAULT_USERDATA } from '@/utils'; @@ -15,7 +15,7 @@ export function parseInitializeArgs({ wethIsEth?: boolean; chainId: number; poolAddress: Address; - sortedTokens: BaseToken[]; + sortedTokens: Token[]; }): { args: InitializeArgs } { return { args: [ diff --git a/src/entities/utils/parseRemoveLiquidityArgs.ts b/src/entities/utils/parseRemoveLiquidityArgs.ts index 486940567..08ba1e083 100644 --- a/src/entities/utils/parseRemoveLiquidityArgs.ts +++ b/src/entities/utils/parseRemoveLiquidityArgs.ts @@ -1,5 +1,5 @@ import { Address } from '../../types'; -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { ExitPoolRequest } from '../removeLiquidity/types'; import { replaceWrapped } from './replaceWrapped'; @@ -16,7 +16,7 @@ export function parseRemoveLiquidityArgs({ }: { chainId?: number; wethIsEth?: boolean; - sortedTokens: BaseToken[]; + sortedTokens: Token[]; poolId: Address; sender: Address; recipient: Address; diff --git a/src/entities/utils/replaceWrapped.ts b/src/entities/utils/replaceWrapped.ts index 7032361cb..abebb4061 100644 --- a/src/entities/utils/replaceWrapped.ts +++ b/src/entities/utils/replaceWrapped.ts @@ -1,13 +1,10 @@ -import { BaseToken } from '../baseToken'; +import { Token } from '../token'; import { NATIVE_ASSETS, ZERO_ADDRESS } from '../../utils'; -export function replaceWrapped( - tokens: BaseToken[], - chainId: number, -): BaseToken[] { +export function replaceWrapped(tokens: Token[], chainId: number): Token[] { return tokens.map((token) => { if (token.isSameAddress(NATIVE_ASSETS[chainId].wrapped)) { - return new BaseToken(chainId, ZERO_ADDRESS, 18); + return new Token(chainId, ZERO_ADDRESS, 18); } return token; }); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 70059a8b2..c16d17737 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,11 +1,11 @@ import { inputValidationError } from './errors'; -import { BaseToken } from '../entities/baseToken'; +import { Token } from '../entities/token'; import { TokenAmount } from '../entities/tokenAmount'; import { Address, SwapKind, BigintIsh } from '@/types'; export function checkInputs( - tokenIn: BaseToken, - tokenOut: BaseToken, + tokenIn: Token, + tokenOut: Token, swapKind: SwapKind, swapAmount: BigintIsh | TokenAmount, ): TokenAmount { diff --git a/test/api/sorSwapPaths.contract.test.ts b/test/api/sorSwapPaths.contract.test.ts index 607bdbe0b..4169df361 100644 --- a/test/api/sorSwapPaths.contract.test.ts +++ b/test/api/sorSwapPaths.contract.test.ts @@ -3,7 +3,7 @@ import { BalancerApi } from '@/data/providers/balancer-api'; import { API_ENDPOINT, ChainId } from '@/utils'; import { Address } from 'viem'; import { TokenAmount } from '@/entities'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { SwapKind } from '@/types'; // Inline minimal constants @@ -18,7 +18,7 @@ describe('contract: sor swap paths (live API)', () => { }); it('fetches SOR swap paths', async () => { - const token = new BaseToken(CHAIN_ID, TOKEN_IN, 18); + const token = new Token(CHAIN_ID, TOKEN_IN, 18); const oneUnit = TokenAmount.fromHumanAmount(token, '0.001'); const paths = await api.sorSwapPaths.fetchSorSwapPaths({ chainId: CHAIN_ID, @@ -31,7 +31,7 @@ describe('contract: sor swap paths (live API)', () => { }); it('fetches SOR swap paths with protocol version', async () => { - const token = new BaseToken(CHAIN_ID, TOKEN_IN, 18); + const token = new Token(CHAIN_ID, TOKEN_IN, 18); const oneUnit = TokenAmount.fromHumanAmount(token, '0.001'); const paths = await api.sorSwapPaths.fetchSorSwapPaths({ chainId: CHAIN_ID, diff --git a/test/entities/swaps/swap.test.ts b/test/entities/swaps/swap.test.ts index 6b351553e..33a2757be 100644 --- a/test/entities/swaps/swap.test.ts +++ b/test/entities/swaps/swap.test.ts @@ -10,7 +10,7 @@ import { import { Path, TokenApi } from '@/entities/swap/paths/types'; import { TOKENS } from 'test/lib/utils/addresses'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.MAINNET; const wethIsEth = false; @@ -212,7 +212,7 @@ describe('Swap', () => { describe('GivenIn', () => { const swapKind = SwapKind.GivenIn as const; - const tokenIn = new BaseToken( + const tokenIn = new Token( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -224,7 +224,7 @@ describe('Swap', () => { paths: [pathTo6Decimals], swapKind, }); - const tokenOut = new BaseToken( + const tokenOut = new Token( 1, pathTo6Decimals.tokens[pathTo6Decimals.tokens.length - 1] .address, @@ -260,7 +260,7 @@ describe('Swap', () => { paths: [pathFrom6Decimals], swapKind, }); - const tokenOut = new BaseToken( + const tokenOut = new Token( 1, pathFrom6Decimals.tokens[ pathFrom6Decimals.tokens.length - 1 @@ -295,7 +295,7 @@ describe('Swap', () => { }); describe('GivenOut', () => { const swapKind = SwapKind.GivenOut as const; - const tokenOut = new BaseToken( + const tokenOut = new Token( 1, pathTo6Decimals.tokens[pathTo6Decimals.tokens.length - 1] .address, @@ -310,7 +310,7 @@ describe('Swap', () => { swapKind, }); const slippage = Slippage.fromPercentage('0.1'); - const tokenIn = new BaseToken( + const tokenIn = new Token( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -346,7 +346,7 @@ describe('Swap', () => { swapKind: SwapKind.GivenOut, }); const slippage = Slippage.fromPercentage('0.1'); - const tokenIn = new BaseToken( + const tokenIn = new Token( 1, pathFrom6Decimals.tokens[0].address, pathFrom6Decimals.tokens[0].decimals, diff --git a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts index abf1bafc9..fdb4b5372 100644 --- a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts @@ -26,13 +26,13 @@ import { auraBalToken, BAL, } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { forkSetup, sendTransactionGetBalances } from 'test/lib/utils'; const chainId = ChainId.MAINNET; -const bal = new BaseToken(chainId, BAL, 18); -const weth = new BaseToken(chainId, NATIVE_ASSETS[chainId].wrapped, 18); +const bal = new Token(chainId, BAL, 18); +const weth = new Token(chainId, NATIVE_ASSETS[chainId].wrapped, 18); describe('auraBalSwaps:Integration tests', () => { let rpcUrl: string; @@ -91,8 +91,8 @@ describe('auraBalSwaps:Integration tests', () => { async function testAuraBalSwap( client: PublicWalletClient & TestActions, - tokenIn: BaseToken, - tokenOut: BaseToken, + tokenIn: Token, + tokenOut: Token, tokenInSlot: number, rpcUrl: string, wethIsEth = false, diff --git a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts index dedd258d3..46abfca30 100644 --- a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts @@ -1,17 +1,17 @@ // pnpm test -- parseInputs.test.ts import { AuraBalSwapKind, TokenAmount } from '@/entities'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { auraBalToken } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; import { parseInputs } from '@/entities/swap/swaps/v2/auraBalSwaps/parseInputs'; import { SwapKind } from '@/types'; import { ChainId, inputValidationError } from '@/utils'; -const usdc = new BaseToken( +const usdc = new Token( ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, ); -const bal = new BaseToken( +const bal = new Token( ChainId.MAINNET, '0xba100000625a3754423978a60c9317c58a424e3D', 18, diff --git a/test/entities/swaps/v2/swapV2.test.ts b/test/entities/swaps/v2/swapV2.test.ts index f698eb61e..962f94234 100644 --- a/test/entities/swaps/v2/swapV2.test.ts +++ b/test/entities/swaps/v2/swapV2.test.ts @@ -2,7 +2,7 @@ import { ChainId } from '@/index'; import { SwapKind } from '@/types'; import { TokenAmount } from '@/entities'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { SwapV2 } from '@/entities/swap/swaps/v2'; import { Path, TokenApi } from '@/entities/swap/paths/types'; @@ -56,7 +56,7 @@ describe('SwapV2', () => { paths: [pathTo6Decimals], swapKind: SwapKind.GivenIn, }); - const tokenOut = new BaseToken( + const tokenOut = new Token( 1, pathTo6Decimals.tokens[ pathTo6Decimals.tokens.length - 1 @@ -81,7 +81,7 @@ describe('SwapV2', () => { paths: [pathFrom6Decimals], swapKind: SwapKind.GivenIn, }); - const tokenOut = new BaseToken( + const tokenOut = new Token( 1, pathFrom6Decimals.tokens[ pathFrom6Decimals.tokens.length - 1 @@ -107,7 +107,7 @@ describe('SwapV2', () => { paths: [pathTo6Decimals], swapKind: SwapKind.GivenOut, }); - const tokenIn = new BaseToken( + const tokenIn = new Token( 1, pathTo6Decimals.tokens[0].address, pathTo6Decimals.tokens[0].decimals, @@ -128,7 +128,7 @@ describe('SwapV2', () => { paths: [pathFrom6Decimals], swapKind: SwapKind.GivenOut, }); - const tokenIn = new BaseToken( + const tokenIn = new Token( 1, pathFrom6Decimals.tokens[0].address, pathFrom6Decimals.tokens[0].decimals, diff --git a/test/lib/utils/addLiquidityBoostedHelper.ts b/test/lib/utils/addLiquidityBoostedHelper.ts index 556dd5d42..1e4c4e5d4 100644 --- a/test/lib/utils/addLiquidityBoostedHelper.ts +++ b/test/lib/utils/addLiquidityBoostedHelper.ts @@ -19,7 +19,7 @@ import { } from './helper'; import { areBigIntsWithinPercent } from './swapHelpers'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; export async function GetBoostedBpt( chainId: ChainId, @@ -117,8 +117,8 @@ export async function GetBoostedBpt( } export const assertTokenMatch = ( - tokenDefined: BaseToken[], - tokenReturned: BaseToken[], + tokenDefined: Token[], + tokenReturned: Token[], ) => { tokenDefined.map((tokenAmount) => { expect( @@ -188,11 +188,7 @@ export const doAddLiquidityBoosted = async ( addLiquidityBoostedQueryOutput.bptOut, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new BaseToken( - addLiquidityBoostedQueryOutput.chainId, - zeroAddress, - 18, - ), + new Token(addLiquidityBoostedQueryOutput.chainId, zeroAddress, 18), 0n, ), ]; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 7eab2ef5a..6e3821eab 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -23,7 +23,7 @@ import { PublicWalletClient, missingParameterError, } from 'src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; @@ -208,7 +208,7 @@ export function assertAddLiquidityUnbalanced( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsIn = poolState.tokens.map((t) => { - const token = new BaseToken( + const token = new Token( addLiquidityInput.chainId, t.address, t.decimals, @@ -290,7 +290,7 @@ export function assertAddLiquiditySingleToken( protocolVersion, ); - const bptToken = new BaseToken( + const bptToken = new Token( addLiquidityInput.chainId, poolState.address, 18, diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 6b63d9d1b..94d4ea6d8 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -20,7 +20,7 @@ import { TokenAmount, VAULT_V2, } from 'src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances, TxOutput } from './helper'; import { RemoveLiquidityTxInput } from './types'; @@ -206,7 +206,7 @@ export function assertRemoveLiquidityUnbalanced( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsOut = poolState.tokens.map((t) => { - const token = new BaseToken( + const token = new Token( removeLiquidityInput.chainId, t.address, t.decimals, @@ -274,7 +274,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) const expectedAmountsOut = poolState.tokens.map((t) => { - const token = new BaseToken( + const token = new Token( removeLiquidityInput.chainId, t.address, t.decimals, @@ -361,7 +361,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( protocolVersion, ); - const bptToken = new BaseToken( + const bptToken = new Token( removeLiquidityInput.chainId, poolState.address, 18, @@ -451,7 +451,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new BaseToken( + const bptToken = new Token( removeLiquidityInput.chainId, poolState.address, 18, diff --git a/test/lib/utils/removeLiquidityNestedHelper.ts b/test/lib/utils/removeLiquidityNestedHelper.ts index 4a3935ecb..47ce42256 100644 --- a/test/lib/utils/removeLiquidityNestedHelper.ts +++ b/test/lib/utils/removeLiquidityNestedHelper.ts @@ -25,7 +25,7 @@ import { sendTransactionGetBalances, setTokenBalances, } from './helper'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; // AddLiquidityNestedInput @@ -123,7 +123,7 @@ export async function GetNestedBpt( return balanceDeltas[0]; } -const isSameToken = (token1: BaseToken, token2: BaseToken): boolean => { +const isSameToken = (token1: Token, token2: Token): boolean => { return ( token1.address.toLowerCase() === token2.address.toLowerCase() && token1.chainId === token2.chainId @@ -140,7 +140,7 @@ const isSameToken = (token1: BaseToken, token2: BaseToken): boolean => { */ export const validateTokenAmounts = ( amounts: TokenAmount[], - tokens: BaseToken[], + tokens: Token[], ): void => { // Check that we have the same number of amounts as main tokens expect(amounts.length).to.equal( @@ -231,7 +231,7 @@ export const doRemoveLiquidityNested = async ( removeLiquidityNestedQueryOutput.bptAmountIn, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new BaseToken( + new Token( removeLiquidityNestedQueryOutput.chainId, zeroAddress, 18, diff --git a/test/lib/utils/removeLiquidityRecoveryHelper.ts b/test/lib/utils/removeLiquidityRecoveryHelper.ts index 89de7db20..3c5f20ade 100644 --- a/test/lib/utils/removeLiquidityRecoveryHelper.ts +++ b/test/lib/utils/removeLiquidityRecoveryHelper.ts @@ -11,7 +11,7 @@ import { TokenAmount, VAULT_V2, } from 'src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances } from './helper'; import { RemoveLiquidityRecoveryTxInput } from './types'; @@ -145,7 +145,7 @@ export function assertRemoveLiquidityRecovery( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new BaseToken( + const bptToken = new Token( removeLiquidityRecoveryInput.chainId, poolState.address, 18, diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index 12eeda10a..f8cbf979a 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -39,7 +39,7 @@ import { } from '../../lib/utils/removeLiquidityHelper'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { TOKENS } from 'test/lib/utils/addresses'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); @@ -94,7 +94,7 @@ describe('composable stable remove liquidity test', () => { (t) => t.address === txInput.poolState.address, ); const poolTokensWithoutBpt = txInput.poolState.tokens - .map((t) => new BaseToken(chainId, t.address, t.decimals)) + .map((t) => new Token(chainId, t.address, t.decimals)) .filter((_, index) => index !== bptIndex); amountsOut = poolTokensWithoutBpt.map((t) => ({ diff --git a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts index 2eae37a03..bcd68e8ed 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts @@ -46,7 +46,7 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; @@ -54,9 +54,9 @@ const USDT = TOKENS[chainId].USDT_AAVE; const stataUSDT = TOKENS[chainId].stataUSDT; // These are the underlying tokens -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); -const stataUsdtToken = new BaseToken( +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const usdcToken = new Token(chainId, USDC.address, USDC.decimals); +const stataUsdtToken = new Token( chainId, stataUSDT.address, stataUSDT.decimals, @@ -618,8 +618,8 @@ describe('Boosted AddLiquidity', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new BaseToken(111555111, USDC.address, USDC.decimals), - new BaseToken(111555111, USDT.address, USDT.decimals), + new Token(111555111, USDC.address, USDC.decimals), + new Token(111555111, USDT.address, USDT.decimals), ], addLiquidityBuildCallOutput.maxAmountsIn.map( (a) => a.token, diff --git a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts index 184dfe98b..6f0d0ee08 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts @@ -38,15 +38,15 @@ import { } from 'test/lib/utils'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; const WETH = TOKENS[chainId].WETH; // These are the underlying tokens -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); describe('V3 add liquidity partial boosted', () => { let rpcUrl: string; diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts index 30d239e55..7f8d302e1 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts @@ -27,7 +27,7 @@ import { AddLiquidityNestedCallInput, SDKError, } from '@/index'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { approveSpenderOnPermit2, @@ -46,15 +46,15 @@ import { const chainId = ChainId.SEPOLIA; -const parentBptToken = new BaseToken( +const parentBptToken = new Token( chainId, NESTED_WITH_BOOSTED_POOL.address, NESTED_WITH_BOOSTED_POOL.decimals, ); // These are the underlying tokens -const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdcToken = new Token(chainId, USDC.address, USDC.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 add liquidity nested test, with Permit2 direct approval', () => { diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts index 9fb2a2d81..4c6b11bde 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts @@ -37,14 +37,14 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; // These are the underlying tokens -const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdcToken = new Token(chainId, USDC.address, USDC.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 add liquidity nested test, with Permit2 signature', () => { diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts index aa06c9168..71048b5ee 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts @@ -44,7 +44,7 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; @@ -243,12 +243,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new BaseToken( + new Token( 111555111, USDC.address as Address, USDC.decimals, ), - new BaseToken( + new Token( 111555111, USDT.address as Address, USDT.decimals, @@ -335,12 +335,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order assertTokenMatch( [ - new BaseToken( + new Token( 111555111, USDC.address as Address, USDC.decimals, ), - new BaseToken( + new Token( 111555111, stataUSDT.address as Address, stataUSDT.decimals, @@ -434,12 +434,12 @@ describe('remove liquidity boosted proportional', () => { // make sure to pass Tokens in correct order. Same as poolTokens but as underlyings instead assertTokenMatch( [ - new BaseToken( + new Token( 111555111, USDC.address as Address, USDC.decimals, ), - new BaseToken( + new Token( 111555111, USDT.address as Address, USDT.decimals, diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts index d2f8482c2..ecdd1781c 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts @@ -38,20 +38,20 @@ import { import { validateTokenAmounts } from 'test/lib/utils/removeLiquidityNestedHelper'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; const WETH = TOKENS[chainId].WETH; -const parentBptToken = new BaseToken( +const parentBptToken = new Token( chainId, partialBoostedPool_WETH_stataUSDT.address, 18, ); // These are the underlying tokens -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); describe('V3 remove liquidity partial boosted', () => { let rpcUrl: string; @@ -257,7 +257,7 @@ describe('V3 remove liquidity partial boosted', () => { queryOutput.bptIn, // add zero address so we can check for native token balance change TokenAmount.fromRawAmount( - new BaseToken(queryOutput.chainId, zeroAddress, 18), + new Token(queryOutput.chainId, zeroAddress, 18), 0n, ), ]; diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts index f6b1fa510..4a91bf4d5 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts @@ -41,19 +41,19 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; -const parentBptToken = new BaseToken( +const parentBptToken = new Token( chainId, NESTED_WITH_BOOSTED_POOL.address, NESTED_WITH_BOOSTED_POOL.decimals, ); // These are the underlying tokens -const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdcToken = new Token(chainId, USDC.address, USDC.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 remove liquidity nested test, with Permit direct approval', () => { diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts index ad8907dcb..57f140b82 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts @@ -23,7 +23,7 @@ import { PermitHelper, RemoveLiquidityNestedCallInputV3, } from 'src'; -import { BaseToken } from '@/entities/baseToken'; +import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { @@ -41,9 +41,9 @@ import { const chainId = ChainId.SEPOLIA; // These are the underlying tokens -const usdtToken = new BaseToken(chainId, USDT.address, USDT.decimals); -const usdcToken = new BaseToken(chainId, USDC.address, USDC.decimals); -const wethToken = new BaseToken(chainId, WETH.address, WETH.decimals); +const usdtToken = new Token(chainId, USDT.address, USDT.decimals); +const usdcToken = new Token(chainId, USDC.address, USDC.decimals); +const wethToken = new Token(chainId, WETH.address, WETH.decimals); const mainTokens = [wethToken, usdtToken, usdcToken]; describe('V3 remove liquidity nested test, with Permit signature', () => { From 466a34af0ff8833ecf42e33ab6629f7f065838b9 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Fri, 10 Oct 2025 10:19:27 +0200 Subject: [PATCH 11/17] refactor: Token imports --- examples/swaps/auraBalSwap.ts | 2 +- examples/swaps/querySmartPath.ts | 2 +- examples/swaps/swapV2.ts | 4 +- src/entities/addLiquidityBoosted/index.ts | 2 +- src/entities/baseToken.ts | 45 ------------------- .../priceImpact/addLiquidityUnbalanced.ts | 2 +- .../addLiquidityUnbalancedBoosted.ts | 2 +- .../weighted/removeLiquidityWeighted.ts | 2 +- 8 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 src/entities/baseToken.ts diff --git a/examples/swaps/auraBalSwap.ts b/examples/swaps/auraBalSwap.ts index 842a76c21..9bd06c000 100644 --- a/examples/swaps/auraBalSwap.ts +++ b/examples/swaps/auraBalSwap.ts @@ -14,6 +14,7 @@ import { Relayer, Slippage, AuraBalSwap, + Token, TokenAmount, SwapKind, isAuraBalSwap, @@ -23,7 +24,6 @@ import { ANVIL_NETWORKS, startFork } from '../../test/anvil/anvil-global-setup'; import { makeForkTx } from 'examples/lib/makeForkTx'; import { getSlot } from 'examples/lib/getSlot'; import { exit } from 'node:process'; -import { Token } from '@/entities/token'; const auraBalSwap = async ({ rpcUrl, client, userAccount, chainId }) => { const tokenIn = new Token( diff --git a/examples/swaps/querySmartPath.ts b/examples/swaps/querySmartPath.ts index 4635e03e1..69ab54dcc 100644 --- a/examples/swaps/querySmartPath.ts +++ b/examples/swaps/querySmartPath.ts @@ -10,12 +10,12 @@ import { API_ENDPOINT, ChainId, SwapKind, + Token, TokenAmount, Swap, ExactInQueryOutput, ExactOutQueryOutput, } from '../../src'; -import { Token } from '@/entities/token'; interface QuerySmartPath { rpcUrl: string; diff --git a/examples/swaps/swapV2.ts b/examples/swaps/swapV2.ts index fc7017eea..171c5ed54 100644 --- a/examples/swaps/swapV2.ts +++ b/examples/swaps/swapV2.ts @@ -10,14 +10,14 @@ import { ChainId, Slippage, SwapKind, + Token, + TokenAmount, SwapBuildCallInput, VAULT_V2, } from '../../src'; -import { Token } from '@/entities/token'; import { querySmartPath } from './querySmartPath'; import { setupExampleFork } from '../lib/setupExampleFork'; import { TOKENS, approveSpenderOnToken } from 'test/lib/utils'; -import { TokenAmount } from '@/entities'; const swapV2 = async () => { // Choose chain id to start fork diff --git a/src/entities/addLiquidityBoosted/index.ts b/src/entities/addLiquidityBoosted/index.ts index b75fb0679..11fd5e1c2 100644 --- a/src/entities/addLiquidityBoosted/index.ts +++ b/src/entities/addLiquidityBoosted/index.ts @@ -19,7 +19,7 @@ import { } from '../addLiquidity/types'; import { doAddLiquidityUnbalancedQuery } from './doAddLiquidityUnbalancedQuery'; import { doAddLiquidityProportionalQuery } from './doAddLiquidityPropotionalQuery'; -import { Token } from '@/entities/token'; +import { Token } from '../token'; import { balancerV3Contracts, protocolVersionError } from '@/utils'; import { balancerCompositeLiquidityRouterBoostedAbiExtended, diff --git a/src/entities/baseToken.ts b/src/entities/baseToken.ts deleted file mode 100644 index 3ab9eaf5f..000000000 --- a/src/entities/baseToken.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Address } from 'viem'; -import { InputToken } from '../types'; - -/** - * Token contains the core functionality for all tokens - * This class handles the essential token properties and methods - * without any wrapped token logic - */ -export class Token { - public readonly chainId: number; - public readonly address: Address; - public readonly decimals: number; - public readonly symbol?: string; - public readonly name?: string; - - public constructor( - chainId: number, - address: Address, - decimals: number, - symbol?: string, - name?: string, - ) { - this.chainId = chainId; - // Addresses are always lowercased for speed - this.address = address.toLowerCase() as Address; - this.decimals = decimals; - this.symbol = symbol; - this.name = name; - } - - public isEqual(token: Token) { - return this.chainId === token.chainId && this.address === token.address; - } - - public isSameAddress(address: Address) { - return this.address === address.toLowerCase(); - } - - public toInputToken(): InputToken { - return { - address: this.address, - decimals: this.decimals, - }; - } -} diff --git a/src/entities/priceImpact/addLiquidityUnbalanced.ts b/src/entities/priceImpact/addLiquidityUnbalanced.ts index 00aa0d70a..b467ab4b1 100644 --- a/src/entities/priceImpact/addLiquidityUnbalanced.ts +++ b/src/entities/priceImpact/addLiquidityUnbalanced.ts @@ -9,11 +9,11 @@ import { RemoveLiquidityInput, RemoveLiquidityKind, } from '../removeLiquidity/types'; +import { Token } from '../token'; import { TokenAmount } from '../tokenAmount'; import { PoolState } from '../types'; import { priceImpactABA } from './helper'; import { Swap, SwapInput } from '../swap'; -import { Token } from '@/entities/token'; export const addLiquidityUnbalanced = async ( input: AddLiquidityUnbalancedInput, diff --git a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts index 0e5ee31a2..57d90443a 100644 --- a/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts +++ b/src/entities/priceImpact/addLiquidityUnbalancedBoosted.ts @@ -11,7 +11,7 @@ import { AddLiquidityBoostedV3 } from '../addLiquidityBoosted'; import { RemoveLiquidityBoostedV3 } from '../removeLiquidityBoosted'; import { RemoveLiquidityBoostedProportionalInput } from '../removeLiquidityBoosted/types'; import { Address, BaseError, ContractFunctionRevertedError } from 'viem'; -import { Token } from '@/entities/token'; +import { Token } from '../token'; /** * Calculate price impact on add liquidity unbalanced operations diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index cb0c6e855..b222226d4 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -1,4 +1,5 @@ import { encodeFunctionData } from 'viem'; +import { Token } from '../../../token'; import { TokenAmount } from '../../../tokenAmount'; import { WeightedEncoder } from '../../../encoders/weighted'; import { protocolVersionError, VAULT_V2, ZERO_ADDRESS } from '@/utils'; @@ -21,7 +22,6 @@ import { } from '../../../utils'; import { getAmountsCall, getAmountsQuery } from '../../helper'; import { RemoveLiquidityV2BaseBuildCallInput } from '../types'; -import { Token } from '@/entities/token'; export class RemoveLiquidityWeighted implements RemoveLiquidityBase { public async query( From cbdc4faf7e029edf6a9165ec9783b2194493947f Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Fri, 10 Oct 2025 11:01:18 +0200 Subject: [PATCH 12/17] refactor: undo more changes --- examples/swaps/swapV2.ts | 1 - src/entities/index.ts | 1 - src/entities/token.ts | 5 ----- test/api/sorSwapPaths.contract.test.ts | 3 +-- test/entities/swaps/swap.test.ts | 2 +- .../swaps/v2/auraBalSwaps/auraBal.integration.test.ts | 2 +- test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts | 3 +-- test/entities/swaps/v2/swapV2.test.ts | 3 +-- test/lib/utils/addLiquidityBoostedHelper.ts | 2 +- test/lib/utils/removeLiquidityHelper.ts | 2 +- test/lib/utils/removeLiquidityNestedHelper.ts | 2 +- test/lib/utils/removeLiquidityRecoveryHelper.ts | 2 +- .../addLiquidityBoosted.integration.test.ts | 2 +- .../addLiquidityPartialBoosted.integration.test.ts | 2 +- .../addLiquidityNestedV3.integration.test.ts | 2 +- .../addLiquidityNestedV3Signature.integration.test.ts | 2 +- .../removeLiquidityBoosted.integration.test.ts | 2 +- .../removeLiquidityPartialBoosted.integration.test.ts | 2 +- .../removeLiquidityNestedV3.integration.test.ts | 2 +- .../removeLiquidityNestedV3Signature.integration.test.ts | 2 +- 20 files changed, 17 insertions(+), 27 deletions(-) diff --git a/examples/swaps/swapV2.ts b/examples/swaps/swapV2.ts index 171c5ed54..8f7df6044 100644 --- a/examples/swaps/swapV2.ts +++ b/examples/swaps/swapV2.ts @@ -18,7 +18,6 @@ import { import { querySmartPath } from './querySmartPath'; import { setupExampleFork } from '../lib/setupExampleFork'; import { TOKENS, approveSpenderOnToken } from 'test/lib/utils'; - const swapV2 = async () => { // Choose chain id to start fork const chainId = ChainId.MAINNET; diff --git a/src/entities/index.ts b/src/entities/index.ts index c93a24574..3e696b4af 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -29,7 +29,6 @@ export * from './removeLiquidityNested/removeLiquidityNestedV2/types'; export * from './removeLiquidityNested/removeLiquidityNestedV3'; export * from './removeLiquidityNested/removeLiquidityNestedV3/types'; export * from './slippage'; -export * from './nativeToken'; export * from './token'; export * from './tokenAmount'; export * from './types'; diff --git a/src/entities/token.ts b/src/entities/token.ts index 3ab9eaf5f..9f3c39a63 100644 --- a/src/entities/token.ts +++ b/src/entities/token.ts @@ -1,11 +1,6 @@ import { Address } from 'viem'; import { InputToken } from '../types'; -/** - * Token contains the core functionality for all tokens - * This class handles the essential token properties and methods - * without any wrapped token logic - */ export class Token { public readonly chainId: number; public readonly address: Address; diff --git a/test/api/sorSwapPaths.contract.test.ts b/test/api/sorSwapPaths.contract.test.ts index 4169df361..c8e85f736 100644 --- a/test/api/sorSwapPaths.contract.test.ts +++ b/test/api/sorSwapPaths.contract.test.ts @@ -2,8 +2,7 @@ import { describe, it, expect } from 'vitest'; import { BalancerApi } from '@/data/providers/balancer-api'; import { API_ENDPOINT, ChainId } from '@/utils'; import { Address } from 'viem'; -import { TokenAmount } from '@/entities'; -import { Token } from '@/entities/token'; +import { Token, TokenAmount } from '@/entities'; import { SwapKind } from '@/types'; // Inline minimal constants diff --git a/test/entities/swaps/swap.test.ts b/test/entities/swaps/swap.test.ts index 33a2757be..fb006e78b 100644 --- a/test/entities/swaps/swap.test.ts +++ b/test/entities/swaps/swap.test.ts @@ -3,6 +3,7 @@ import { ChainId, inputValidationError, Slippage } from '@/index'; import { SwapKind } from '@/types'; import { Swap, + Token, TokenAmount, SwapBuildOutputExactIn, SwapBuildOutputExactOut, @@ -10,7 +11,6 @@ import { import { Path, TokenApi } from '@/entities/swap/paths/types'; import { TOKENS } from 'test/lib/utils/addresses'; -import { Token } from '@/entities/token'; const chainId = ChainId.MAINNET; const wethIsEth = false; diff --git a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts index fdb4b5372..b6d6947a3 100644 --- a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts @@ -12,6 +12,7 @@ import { import { Relayer, Slippage, + Token, TokenAmount, AuraBalSwap, BALANCER_RELAYER, @@ -26,7 +27,6 @@ import { auraBalToken, BAL, } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; -import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { forkSetup, sendTransactionGetBalances } from 'test/lib/utils'; diff --git a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts index 46abfca30..d0dd1c052 100644 --- a/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/parseInputs.test.ts @@ -1,6 +1,5 @@ // pnpm test -- parseInputs.test.ts -import { AuraBalSwapKind, TokenAmount } from '@/entities'; -import { Token } from '@/entities/token'; +import { AuraBalSwapKind, Token, TokenAmount } from '@/entities'; import { auraBalToken } from '@/entities/swap/swaps/v2/auraBalSwaps/constants'; import { parseInputs } from '@/entities/swap/swaps/v2/auraBalSwaps/parseInputs'; import { SwapKind } from '@/types'; diff --git a/test/entities/swaps/v2/swapV2.test.ts b/test/entities/swaps/v2/swapV2.test.ts index 962f94234..92c8764cd 100644 --- a/test/entities/swaps/v2/swapV2.test.ts +++ b/test/entities/swaps/v2/swapV2.test.ts @@ -1,8 +1,7 @@ // pnpm test -- swapV2.test.ts import { ChainId } from '@/index'; import { SwapKind } from '@/types'; -import { TokenAmount } from '@/entities'; -import { Token } from '@/entities/token'; +import { Token, TokenAmount } from '@/entities'; import { SwapV2 } from '@/entities/swap/swaps/v2'; import { Path, TokenApi } from '@/entities/swap/paths/types'; diff --git a/test/lib/utils/addLiquidityBoostedHelper.ts b/test/lib/utils/addLiquidityBoostedHelper.ts index 1e4c4e5d4..07344b3e5 100644 --- a/test/lib/utils/addLiquidityBoostedHelper.ts +++ b/test/lib/utils/addLiquidityBoostedHelper.ts @@ -7,6 +7,7 @@ import { AddLiquidityKind, PoolStateWithUnderlyings, Slippage, + Token, TokenAmount, } from '@/entities'; import { ChainId, NATIVE_ASSETS, PERMIT2, PublicWalletClient } from '@/utils'; @@ -19,7 +20,6 @@ import { } from './helper'; import { areBigIntsWithinPercent } from './swapHelpers'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { Token } from '@/entities/token'; export async function GetBoostedBpt( chainId: ChainId, diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 94d4ea6d8..4ee7449e6 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -17,10 +17,10 @@ import { RemoveLiquidityUnbalancedInput, RemoveLiquidityV3BuildCallInput, Slippage, + Token, TokenAmount, VAULT_V2, } from 'src'; -import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances, TxOutput } from './helper'; import { RemoveLiquidityTxInput } from './types'; diff --git a/test/lib/utils/removeLiquidityNestedHelper.ts b/test/lib/utils/removeLiquidityNestedHelper.ts index 47ce42256..d02b94f84 100644 --- a/test/lib/utils/removeLiquidityNestedHelper.ts +++ b/test/lib/utils/removeLiquidityNestedHelper.ts @@ -10,6 +10,7 @@ import { RemoveLiquidityNestedQueryOutput, RemoveLiquidityNestedQueryOutputV3, Slippage, + Token, TokenAmount, } from '@/entities'; import { @@ -25,7 +26,6 @@ import { sendTransactionGetBalances, setTokenBalances, } from './helper'; -import { Token } from '@/entities/token'; // AddLiquidityNestedInput diff --git a/test/lib/utils/removeLiquidityRecoveryHelper.ts b/test/lib/utils/removeLiquidityRecoveryHelper.ts index 3c5f20ade..0f1ded47d 100644 --- a/test/lib/utils/removeLiquidityRecoveryHelper.ts +++ b/test/lib/utils/removeLiquidityRecoveryHelper.ts @@ -8,10 +8,10 @@ import { RemoveLiquidityRecoveryInput, RemoveLiquidityV3BuildCallInput, Slippage, + Token, TokenAmount, VAULT_V2, } from 'src'; -import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances } from './helper'; import { RemoveLiquidityRecoveryTxInput } from './types'; diff --git a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts index bcd68e8ed..26bbbec9a 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityBoosted.integration.test.ts @@ -22,6 +22,7 @@ import { AddLiquidityBoostedV3, Permit2Helper, PERMIT2, + Token, PublicWalletClient, AddLiquidityBoostedBuildCallInput, AddLiquidityBoostedInput, @@ -46,7 +47,6 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; diff --git a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts index 6f0d0ee08..b55757f22 100644 --- a/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/addLiquidityBoosted/addLiquidityPartialBoosted.integration.test.ts @@ -19,6 +19,7 @@ import { PERMIT2, PublicWalletClient, Slippage, + Token, TokenAmount, AddLiquidityBoostedV3, AddLiquidityKind, @@ -38,7 +39,6 @@ import { } from 'test/lib/utils'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts index 7f8d302e1..59dd4a80e 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3.integration.test.ts @@ -20,6 +20,7 @@ import { PERMIT2, PublicWalletClient, Slippage, + Token, TokenAmount, AddLiquidityNested, AddLiquidityNestedInput, @@ -27,7 +28,6 @@ import { AddLiquidityNestedCallInput, SDKError, } from '@/index'; -import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { approveSpenderOnPermit2, diff --git a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts index 4c6b11bde..67cc02e67 100644 --- a/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/addLiquidityNested/addLiquidityNestedV3Signature.integration.test.ts @@ -17,6 +17,7 @@ import { PERMIT2, PublicWalletClient, Slippage, + Token, TokenAmount, AddLiquidityNested, AddLiquidityNestedInput, @@ -37,7 +38,6 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts index 71048b5ee..5313fec9c 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityBoosted.integration.test.ts @@ -22,6 +22,7 @@ import { CHAINS, ChainId, PERMIT2, + Token, PublicWalletClient, AddLiquidityBoostedV3, RemoveLiquidityBoostedV3, @@ -44,7 +45,6 @@ import { import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { boostedPool_USDC_USDT } from 'test/mockData/boostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDC = TOKENS[chainId].USDC_AAVE; diff --git a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts index ecdd1781c..3b22ac6e4 100644 --- a/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts +++ b/test/v3/removeLiquidityBoosted/removeLiquidityPartialBoosted.integration.test.ts @@ -18,6 +18,7 @@ import { ChainId, CHAINS, PublicWalletClient, + Token, balancerV3Contracts, Slippage, RemoveLiquidityBoostedV3, @@ -38,7 +39,6 @@ import { import { validateTokenAmounts } from 'test/lib/utils/removeLiquidityNestedHelper'; import { partialBoostedPool_WETH_stataUSDT } from 'test/mockData/partialBoostedPool'; import { AddressProvider } from '@/entities/inputValidator/utils/addressProvider'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; const USDT = TOKENS[chainId].USDT_AAVE; diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts index 4a91bf4d5..b369e30df 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3.integration.test.ts @@ -17,6 +17,7 @@ import { ChainId, CHAINS, PublicWalletClient, + Token, RemoveLiquidityNestedInput, RemoveLiquidityNestedCallInput, RemoveLiquidityNested, @@ -41,7 +42,6 @@ import { USDT, WETH, } from 'test/mockData/nestedPool'; -import { Token } from '@/entities/token'; const chainId = ChainId.SEPOLIA; diff --git a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts index 57f140b82..debf567e1 100644 --- a/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts +++ b/test/v3/removeLiquidityNested/removeLiquidityNestedV3Signature.integration.test.ts @@ -16,6 +16,7 @@ import { ChainId, CHAINS, PublicWalletClient, + Token, RemoveLiquidityNestedInput, RemoveLiquidityNested, BALANCER_COMPOSITE_LIQUIDITY_ROUTER_NESTED, @@ -23,7 +24,6 @@ import { PermitHelper, RemoveLiquidityNestedCallInputV3, } from 'src'; -import { Token } from '@/entities/token'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; import { From f51af5f4923f0f92d0df8b1d92107d67b596ddc5 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 14 Oct 2025 11:06:24 +0200 Subject: [PATCH 13/17] chore: add changeset --- .changeset/hip-flowers-march.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/hip-flowers-march.md diff --git a/.changeset/hip-flowers-march.md b/.changeset/hip-flowers-march.md new file mode 100644 index 000000000..6cc944f51 --- /dev/null +++ b/.changeset/hip-flowers-march.md @@ -0,0 +1,13 @@ +--- +"@balancer/sdk": major +--- + +**WHAT**: Removed wrapped token functionality from the `Token` class and introduced a new `NativeToken` class to handle native tokens (like ETH) separately. + +**WHY**: This change improves type safety and separation of concerns by distinguishing between ERC-20 tokens and native tokens, making the API more explicit and preventing confusion about token types. + +**HOW**: Update your code by: +- Replace any usage of `Token` for native tokens with the new `NativeToken` class if using the wrapped functionality +- If not using any wrapped functionality, the `Token` can remain as is +- Import `NativeToken` from the SDK: `import { NativeToken } from '@balancer/sdk'` +- Use `NativeToken` for native token operations instead of `Token` with wrapped functionality From 202693bd4530207bdfc832926e34bb7245d4a963 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 14 Oct 2025 14:11:16 +0200 Subject: [PATCH 14/17] refactor: import from src --- src/entities/index.ts | 1 + src/utils/constants.ts | 2 +- test/lib/utils/addLiquidityHelper.ts | 2 +- test/v2/removeLiquidity/composableStable.integration.test.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/entities/index.ts b/src/entities/index.ts index 3e696b4af..ddbbf64fb 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -30,6 +30,7 @@ export * from './removeLiquidityNested/removeLiquidityNestedV3'; export * from './removeLiquidityNested/removeLiquidityNestedV3/types'; export * from './slippage'; export * from './token'; +export * from './nativeToken'; export * from './tokenAmount'; export * from './types'; export * from './utils'; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 303ff8c08..7f2ce4978 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,5 +1,5 @@ import { Address, Chain } from 'viem'; -import { NativeToken } from '../entities/nativeToken'; +import { NativeToken } from '../../src'; import { arbitrum, avalanche, diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 6e3821eab..100fb7db4 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -22,8 +22,8 @@ import { isSameAddress, PublicWalletClient, missingParameterError, + Token, } from 'src'; -import { Token } from '@/entities/token'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index f8cbf979a..885862074 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -27,6 +27,7 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + Token, } from '../../../src'; import { forkSetup } from '../../lib/utils/helper'; import { RemoveLiquidityTxInput } from '../../lib/utils/types'; @@ -39,7 +40,6 @@ import { } from '../../lib/utils/removeLiquidityHelper'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { TOKENS } from 'test/lib/utils/addresses'; -import { Token } from '@/entities/token'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); From 4e9a781823c226c9d1f75d0b8f19c59692c58672 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 14 Oct 2025 15:56:23 +0200 Subject: [PATCH 15/17] refactor: rename function --- src/entities/nativeToken.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/nativeToken.ts b/src/entities/nativeToken.ts index e09d51cb3..7988e3077 100644 --- a/src/entities/nativeToken.ts +++ b/src/entities/nativeToken.ts @@ -23,7 +23,7 @@ export class NativeToken extends Token { this.wrapped = wrapped.toLowerCase() as Address; } - public isUnderlyingEqual(token: NativeToken) { + public isWrappedEqual(token: NativeToken) { return this.chainId === token.chainId && this.wrapped === token.wrapped; } } From 3a7a56956a3c78c3d2783ca55c038ff4276f1957 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Tue, 14 Oct 2025 16:19:28 +0200 Subject: [PATCH 16/17] refactor: use isWrapped helper --- src/entities/nativeToken.ts | 4 ++++ src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts | 3 +-- src/entities/utils/getValue.ts | 2 +- src/entities/utils/replaceWrapped.ts | 2 +- src/utils/constants.ts | 2 +- .../swaps/v2/auraBalSwaps/auraBal.integration.test.ts | 7 ++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/entities/nativeToken.ts b/src/entities/nativeToken.ts index 7988e3077..2d8a7d12f 100644 --- a/src/entities/nativeToken.ts +++ b/src/entities/nativeToken.ts @@ -26,4 +26,8 @@ export class NativeToken extends Token { public isWrappedEqual(token: NativeToken) { return this.chainId === token.chainId && this.wrapped === token.wrapped; } + + public isWrapped(token: Token) { + return this.chainId === token.chainId && this.wrapped === token.address; + } } diff --git a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts index a270d304e..28d07b009 100644 --- a/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts +++ b/src/entities/swap/swaps/v2/auraBalSwaps/joinPool.ts @@ -31,8 +31,7 @@ export function encodeJoinData( ); const useNativeAsset = - wethIsEth && - token.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped); + wethIsEth && NATIVE_ASSETS[ChainId.MAINNET].isWrapped(token); const maxAmountsIn = Array(balWethAssets.length).fill(0n); maxAmountsIn[tokenInIndex] = inputAmount; diff --git a/src/entities/utils/getValue.ts b/src/entities/utils/getValue.ts index 8955d932e..1e8dac831 100644 --- a/src/entities/utils/getValue.ts +++ b/src/entities/utils/getValue.ts @@ -9,7 +9,7 @@ export const getValue = ( if (wethIsEth) { value = amountsIn.find((a) => - a.token.isSameAddress(NATIVE_ASSETS[a.token.chainId].wrapped), + NATIVE_ASSETS[a.token.chainId].isWrapped(a.token), )?.amount ?? 0n; } return value; diff --git a/src/entities/utils/replaceWrapped.ts b/src/entities/utils/replaceWrapped.ts index abebb4061..38433db58 100644 --- a/src/entities/utils/replaceWrapped.ts +++ b/src/entities/utils/replaceWrapped.ts @@ -3,7 +3,7 @@ import { NATIVE_ASSETS, ZERO_ADDRESS } from '../../utils'; export function replaceWrapped(tokens: Token[], chainId: number): Token[] { return tokens.map((token) => { - if (token.isSameAddress(NATIVE_ASSETS[chainId].wrapped)) { + if (NATIVE_ASSETS[chainId].isWrapped(token)) { return new Token(chainId, ZERO_ADDRESS, 18); } return token; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 7f2ce4978..303ff8c08 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,5 +1,5 @@ import { Address, Chain } from 'viem'; -import { NativeToken } from '../../src'; +import { NativeToken } from '../entities/nativeToken'; import { arbitrum, avalanche, diff --git a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts index b6d6947a3..02d405042 100644 --- a/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts +++ b/test/entities/swaps/v2/auraBalSwaps/auraBal.integration.test.ts @@ -142,17 +142,14 @@ async function testAuraBalSwap( expect(transactionReceipt.status).to.equal('success'); - if ( - wethIsEth && - tokenIn.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped) - ) { + if (wethIsEth && NATIVE_ASSETS[ChainId.MAINNET].isWrapped(tokenIn)) { expect(queryOutput.inputAmount.amount).to.equal(balanceDeltas[2]); expect(queryOutput.expectedAmountOut.amount).to.equal(balanceDeltas[1]); expect(call.value).to.eq(queryOutput.inputAmount.amount); expect(balanceDeltas[0]).to.eq(0n); } else if ( wethIsEth && - tokenOut.isSameAddress(NATIVE_ASSETS[ChainId.MAINNET].wrapped) + NATIVE_ASSETS[ChainId.MAINNET].isWrapped(tokenOut) ) { expect(queryOutput.inputAmount.amount).to.equal(balanceDeltas[0]); expect(queryOutput.expectedAmountOut.amount).to.equal(balanceDeltas[2]); From 8082f25a32bf1881b5026101abb49bb61d209e40 Mon Sep 17 00:00:00 2001 From: mkflow27 Date: Wed, 15 Oct 2025 10:10:25 +0200 Subject: [PATCH 17/17] refactor: use isWrapped helper --- .../addLiquidityNested/addLiquidityNestedV2/validateInputs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts index 782b16fcc..00775ced2 100644 --- a/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts +++ b/src/entities/addLiquidityNested/addLiquidityNestedV2/validateInputs.ts @@ -35,7 +35,7 @@ export const validateBuildCallInput = ( if (input.wethIsEth) { if ( !input.amountsIn.some((a) => - a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + NATIVE_ASSETS[chainId].isWrapped(a.token), ) ) { throw inputValidationError(