From 054400e62e64fa26f793ff562073c41ee73d3002 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 5 Mar 2024 13:56:50 -0300 Subject: [PATCH 01/29] Rename wethIsEth to sendNativeAsset and receiveNativeAsset --- examples/addLiquidity.ts | 2 +- examples/addLiquidityNested.ts | 6 ++-- examples/removeLiquidity.ts | 1 - .../addLiquidityComposableStable.ts | 3 +- .../weighted/addLiquidityWeighted.ts | 3 +- .../addLiquidity/addLiquidityV3/index.ts | 16 +++++---- src/entities/addLiquidity/types.ts | 5 ++- .../addLiquidityNested/encodeCalls.ts | 4 +-- .../getQueryCallsAttributes.ts | 5 ++- src/entities/addLiquidityNested/types.ts | 4 +-- .../addLiquidityNested/validateInputs.ts | 2 +- src/entities/initPool/initPoolV3.ts | 2 +- src/entities/initPool/types.ts | 2 +- .../weighted/inputValidatorWeighted.ts | 33 +++++++++---------- src/entities/priceImpact/index.ts | 3 +- .../removeLiquidityComposableStable.ts | 2 +- .../weighted/removeLiquidityWeighted.ts | 2 +- .../encodeRemoveLiquidityProportional.ts | 2 +- ...encodeRemoveLiquiditySingleTokenExactIn.ts | 2 +- ...ncodeRemoveLiquiditySingleTokenExactOut.ts | 2 +- src/entities/removeLiquidity/types.ts | 3 +- src/entities/utils/parseAddLiquidityArgs.ts | 6 ++-- src/entities/utils/parseInitializeArgs.ts | 6 ++-- .../utils/parseRemoveLiquidityArgs.ts | 6 ++-- test/lib/utils/addLiquidityHelper.ts | 18 ++++++---- test/lib/utils/addLiquidityNestedHelper.ts | 10 +++--- test/lib/utils/removeLiquidityHelper.ts | 11 ++++--- test/lib/utils/types.ts | 3 +- .../composableStable.integration.test.ts | 6 ++-- .../addLiquidity/gyroEV2.integration.test.ts | 4 +-- .../addLiquidity/weighted.integration.test.ts | 10 +++--- .../addLiquidityNested.integration.test.ts | 10 +++--- .../composableStable.integration.test.ts | 8 ++--- .../gyroEV2.integration.test.ts | 2 +- .../weighted.integration.test.ts | 8 ++--- test/v3/addLiquidity.integration.test.ts | 4 +-- test/v3/removeLiquidity.integration.test.ts | 6 ++-- 37 files changed, 110 insertions(+), 112 deletions(-) diff --git a/examples/addLiquidity.ts b/examples/addLiquidity.ts index 38b9b009..e52c04da 100644 --- a/examples/addLiquidity.ts +++ b/examples/addLiquidity.ts @@ -80,7 +80,7 @@ const addLiquidity = async () => { sender: userAccount, recipient: userAccount, chainId, - wethIsEth: false, + sendNativeAsset: false, }); console.log('\nWith slippage applied:'); diff --git a/examples/addLiquidityNested.ts b/examples/addLiquidityNested.ts index e6b89177..c824f53c 100644 --- a/examples/addLiquidityNested.ts +++ b/examples/addLiquidityNested.ts @@ -62,14 +62,14 @@ const addLiquidityNested = async () => { }, ]; - const useNativeAssetAsWrappedAmountIn = false; + const sendNativeAsset = false; const addLiquidityInput: AddLiquidityNestedInput = { amountsIn, chainId, rpcUrl, accountAddress, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, }; // Calculate price impact to ensure it's acceptable @@ -109,7 +109,7 @@ const addLiquidityNested = async () => { }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); - if (useNativeAssetAsWrappedAmountIn) { + if (sendNativeAsset) { tokensIn = replaceWrapped(tokensIn, chainId); } diff --git a/examples/removeLiquidity.ts b/examples/removeLiquidity.ts index 1dacb079..b6679602 100644 --- a/examples/removeLiquidity.ts +++ b/examples/removeLiquidity.ts @@ -85,7 +85,6 @@ const removeLiquidity = async () => { sender: userAccount, recipient: userAccount, chainId, - wethIsEth: !!removeLiquidityInput.toNativeAsset, }); console.log('\nWith slippage applied:'); diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 49519f73..466532a9 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -44,8 +44,6 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { ); const { args, tokensIn } = parseAddLiquidityArgs({ - useNativeAssetAsWrappedAmountIn: - !!input.useNativeAssetAsWrappedAmountIn, chainId: input.chainId, sortedTokens, poolId: poolState.id, @@ -98,6 +96,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { maxAmountsIn: amounts.maxAmountsIn, userData, fromInternalBalance: input.fromInternalBalance, + sendNativeAsset: !!input.sendNativeAsset, }); const call = encodeFunctionData({ diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index fd3dbe2f..dacd2d06 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -35,8 +35,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { ); const { args, tokensIn } = parseAddLiquidityArgs({ - useNativeAssetAsWrappedAmountIn: - !!input.useNativeAssetAsWrappedAmountIn, + sendNativeAsset: !!input.sendNativeAsset, chainId: input.chainId, sortedTokens, poolId: poolState.id, diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 862e8e9a..2ea78214 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -102,7 +102,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { input.poolId, input.amountsIn.map((a) => a.amount), amounts.minimumBpt, - input.wethIsEth, + !!input.sendNativeAsset, '0x', ], }); @@ -122,7 +122,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { input.amountsIn[input.tokenInIndex].token.address, input.amountsIn[input.tokenInIndex].amount, input.bptOut.amount, - input.wethIsEth, + !!input.sendNativeAsset, '0x', ], }); @@ -131,14 +131,16 @@ export class AddLiquidityV3 implements AddLiquidityBase { } let value = 0n; - if (input.wethIsEth) { - const wethInput = input.amountsIn.find( + if (input.sendNativeAsset) { + const wrappedNativeAssetInput = input.amountsIn.find( (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, ); - if (wethInput === undefined) { - throw new Error('wethIsEth is true but no WETH input found'); + if (wrappedNativeAssetInput === undefined) { + throw new Error( + 'sendNativeAsset requires wrapped native asset as input', + ); } - value = wethInput.amount; + value = wrappedNativeAssetInput.amount; } return { diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index fdc3b3f5..9cb44997 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -13,7 +13,6 @@ export enum AddLiquidityKind { export type AddLiquidityBaseInput = { chainId: number; rpcUrl: string; - useNativeAssetAsWrappedAmountIn?: boolean; fromInternalBalance?: boolean; }; @@ -66,7 +65,7 @@ export type AddLiquidityBaseCall = { sender: Address; recipient: Address; chainId: number; - wethIsEth: boolean; + sendNativeAsset?: boolean; } & AddLiquidityBaseQueryOutput; export type AddLiquidityWeightedCall = AddLiquidityBaseCall; @@ -100,7 +99,7 @@ export type AddLiquidityConfig = { export type JoinPoolRequest = { assets: Address[]; - maxAmountsIn: bigint[]; + maxAmountsIn: readonly bigint[]; userData: Hex; fromInternalBalance: boolean; }; diff --git a/src/entities/addLiquidityNested/encodeCalls.ts b/src/entities/addLiquidityNested/encodeCalls.ts index bb9b3b2a..74c0c548 100644 --- a/src/entities/addLiquidityNested/encodeCalls.ts +++ b/src/entities/addLiquidityNested/encodeCalls.ts @@ -14,7 +14,7 @@ export const encodeCalls = ( const values: bigint[] = []; for (const callAttributes of callsAttributes) { const { - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, chainId, sortedTokens, poolId, @@ -33,7 +33,7 @@ export const encodeCalls = ( let tokensIn = [...sortedTokens]; let value = 0n; - if (useNativeAssetAsWrappedAmountIn) { + if (sendNativeAsset) { tokensIn = replaceWrapped([...sortedTokens], chainId); const nativeAssetIndex = tokensIn.findIndex((t) => t.isSameAddress(ZERO_ADDRESS), diff --git a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts index 0123e21f..78946834 100644 --- a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts +++ b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts @@ -13,7 +13,7 @@ export const getQueryCallsAttributes = ( amountsIn, chainId, accountAddress, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, fromInternalBalance, }: AddLiquidityNestedInput, pools: NestedPool[], @@ -38,8 +38,7 @@ export const getQueryCallsAttributes = ( } calls.push({ chainId: chainId, - useNativeAssetAsWrappedAmountIn: - useNativeAssetAsWrappedAmountIn ?? false, + sendNativeAsset: sendNativeAsset ?? false, sortedTokens, poolId: pool.id, poolAddress: pool.address, diff --git a/src/entities/addLiquidityNested/types.ts b/src/entities/addLiquidityNested/types.ts index 73c3197d..f2bd385b 100644 --- a/src/entities/addLiquidityNested/types.ts +++ b/src/entities/addLiquidityNested/types.ts @@ -10,13 +10,13 @@ export type AddLiquidityNestedInput = { chainId: ChainId; rpcUrl: string; accountAddress: Address; - useNativeAssetAsWrappedAmountIn?: boolean; + sendNativeAsset?: boolean; fromInternalBalance?: boolean; }; export type AddLiquidityNestedCallAttributes = { chainId: ChainId; - useNativeAssetAsWrappedAmountIn: boolean; + sendNativeAsset: boolean; sortedTokens: Token[]; poolId: Hex; poolAddress: Address; diff --git a/src/entities/addLiquidityNested/validateInputs.ts b/src/entities/addLiquidityNested/validateInputs.ts index 42bfbdbd..cb82dff8 100644 --- a/src/entities/addLiquidityNested/validateInputs.ts +++ b/src/entities/addLiquidityNested/validateInputs.ts @@ -26,7 +26,7 @@ export const validateInputs = ( return TokenAmount.fromRawAmount(tokenIn, amountIn.rawAmount); }); - if (input.useNativeAssetAsWrappedAmountIn) { + if (input.sendNativeAsset) { if ( !mainTokens.some((t) => t.isUnderlyingEqual(NATIVE_ASSETS[input.chainId]), diff --git a/src/entities/initPool/initPoolV3.ts b/src/entities/initPool/initPoolV3.ts index ba5c5f59..a1be6877 100644 --- a/src/entities/initPool/initPoolV3.ts +++ b/src/entities/initPool/initPoolV3.ts @@ -45,7 +45,7 @@ export class InitPoolV3 implements InitPoolBase { } private value(input: InitPoolInputV3) { - return input.wethIsEth + return input.sendNativeAsset ? (input.amountsIn.find((a) => isSameAddress( a.address, diff --git a/src/entities/initPool/types.ts b/src/entities/initPool/types.ts index 90397688..e7ee8222 100644 --- a/src/entities/initPool/types.ts +++ b/src/entities/initPool/types.ts @@ -27,7 +27,7 @@ export type InitPoolInputV2 = Omit & { export type InitPoolInputV3 = { amountsIn: InputAmount[]; minBptAmountOut: bigint; - wethIsEth?: boolean; + sendNativeAsset?: boolean; chainId: number; }; diff --git a/src/entities/inputValidator/weighted/inputValidatorWeighted.ts b/src/entities/inputValidator/weighted/inputValidatorWeighted.ts index 057b3988..34249fe2 100644 --- a/src/entities/inputValidator/weighted/inputValidatorWeighted.ts +++ b/src/entities/inputValidator/weighted/inputValidatorWeighted.ts @@ -24,7 +24,7 @@ export class InputValidatorWeighted implements InputValidatorBase { poolState.tokens.map((t) => t.address), ); if (poolState.vaultVersion === 3) { - this.validateWethIsEth(initPoolInput as InitPoolInputV3, poolState); + this.validateSendNativeAsset(initPoolInput as InitPoolInputV3); } } @@ -73,23 +73,20 @@ export class InputValidatorWeighted implements InputValidatorBase { validateTokensRemoveLiquidity(input, poolState); } - private validateWethIsEth( - initPoolInput: InitPoolInputV3, - poolState: PoolState, - ) { - if (!initPoolInput.wethIsEth) { - return; - } - const poolContainsWrappedNativeAsset = !!poolState.tokens.find((a) => - isSameAddress( - a.address, - NATIVE_ASSETS[initPoolInput.chainId].wrapped, - ), - ); - if (!poolContainsWrappedNativeAsset) { - throw new Error( - "Flag wethIsEth is active and pool doesn't contain the wrapped native asset", - ); + private validateSendNativeAsset(initPoolInput: InitPoolInputV3) { + if (initPoolInput.sendNativeAsset) { + const inputContainsWrappedNativeAsset = + initPoolInput.amountsIn.some((a) => + isSameAddress( + a.address, + NATIVE_ASSETS[initPoolInput.chainId].wrapped, + ), + ); + if (!inputContainsWrappedNativeAsset) { + throw new Error( + 'sendNativeAsset requires wrapped native asset as input', + ); + } } } } diff --git a/src/entities/priceImpact/index.ts b/src/entities/priceImpact/index.ts index 4eb96059..c20f9903 100644 --- a/src/entities/priceImpact/index.ts +++ b/src/entities/priceImpact/index.ts @@ -371,8 +371,7 @@ export class PriceImpact { accountAddress: input.accountAddress, chainId: input.chainId, rpcUrl: input.rpcUrl, - useNativeAssetAsWrappedAmountIn: - input.useNativeAssetAsWrappedAmountOut, + sendNativeAsset: input.useNativeAssetAsWrappedAmountOut, fromInternalBalance: input.toInternalBalance, amountsIn: amountsOut.map((a) => a.toInputAmount()), }; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index b6718686..ef3647ab 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -45,7 +45,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { // tokensOut will have zero address if removing liquidity to native asset const { args, tokensOut } = parseRemoveLiquidityArgs({ chainId: input.chainId, - toNativeAsset: !!input.toNativeAsset, + receiveNativeAsset: !!input.receiveNativeAsset, poolId: poolState.id, sortedTokens, sender: ZERO_ADDRESS, diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index d9fead03..8533056b 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -36,7 +36,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { // tokensOut will have zero address if removing liquidity to native asset const { args, tokensOut } = parseRemoveLiquidityArgs({ chainId: input.chainId, - toNativeAsset: !!input.toNativeAsset, + receiveNativeAsset: !!input.receiveNativeAsset, poolId: poolState.id, sortedTokens, sender: ZERO_ADDRESS, diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts index 7b7337a6..604d5338 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts @@ -13,7 +13,7 @@ export const encodeRemoveLiquidityProportional = ( input.poolId, input.bptIn.amount, minAmountsOut, - input.wethIsEth, + !!input.receiveNativeAsset, '0x', ], }); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts index 0866ffc8..7a27af53 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts @@ -20,7 +20,7 @@ export const encodeRemoveLiquiditySingleTokenExactIn = ( input.bptIn.amount, input.amountsOut[input.tokenOutIndex].token.address, minAmountsOut[input.tokenOutIndex], - input.wethIsEth, + !!input.receiveNativeAsset, '0x', ], }); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts index a266159c..268f233e 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts @@ -20,7 +20,7 @@ export const encodeRemoveLiquiditySingleTokenExactOut = ( maxBptAmountIn, input.amountsOut[input.tokenOutIndex].token.address, input.amountsOut[input.tokenOutIndex].amount, - input.wethIsEth, + !!input.receiveNativeAsset, '0x', ], }); diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index 3f53e25a..1dec1c7b 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -15,7 +15,6 @@ export enum RemoveLiquidityKind { export type RemoveLiquidityBaseInput = { chainId: number; rpcUrl: string; - toNativeAsset?: boolean; toInternalBalance?: boolean; }; @@ -80,7 +79,7 @@ export type RemoveLiquidityBaseCall = { sender: Address; recipient: Address; chainId: number; - wethIsEth: boolean; + receiveNativeAsset?: boolean; } & RemoveLiquidityBaseQueryOutput; export type RemoveLiquidityWeightedCall = RemoveLiquidityBaseCall; diff --git a/src/entities/utils/parseAddLiquidityArgs.ts b/src/entities/utils/parseAddLiquidityArgs.ts index 77051a08..cded013e 100644 --- a/src/entities/utils/parseAddLiquidityArgs.ts +++ b/src/entities/utils/parseAddLiquidityArgs.ts @@ -3,7 +3,7 @@ import { Token } from '../token'; import { replaceWrapped } from './replaceWrapped'; export function parseAddLiquidityArgs({ - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, chainId, sortedTokens, poolId, @@ -14,7 +14,7 @@ export function parseAddLiquidityArgs({ fromInternalBalance, }: { chainId?: number; - useNativeAssetAsWrappedAmountIn?: boolean; + sendNativeAsset?: boolean; sortedTokens: Token[]; poolId: Hex; sender: Address; @@ -25,7 +25,7 @@ export function parseAddLiquidityArgs({ }) { // replace wrapped token with native asset if needed const tokensIn = - chainId && useNativeAssetAsWrappedAmountIn + chainId && sendNativeAsset ? replaceWrapped([...sortedTokens], chainId) : [...sortedTokens]; diff --git a/src/entities/utils/parseInitializeArgs.ts b/src/entities/utils/parseInitializeArgs.ts index 48358d40..911fd549 100644 --- a/src/entities/utils/parseInitializeArgs.ts +++ b/src/entities/utils/parseInitializeArgs.ts @@ -6,13 +6,13 @@ import { DEFAULT_USERDATA } from '@/utils'; export function parseInitializeArgs({ exactAmountsIn, minBptAmountOut, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, poolAddress, sortedTokens, }: { exactAmountsIn: bigint[]; minBptAmountOut: bigint; - useNativeAssetAsWrappedAmountIn?: boolean; + sendNativeAsset?: boolean; chainId: number; poolAddress: Address; sortedTokens: Token[]; @@ -23,7 +23,7 @@ export function parseInitializeArgs({ sortedTokens.map(({ address }) => address), exactAmountsIn, minBptAmountOut, - useNativeAssetAsWrappedAmountIn ?? false, + sendNativeAsset ?? false, DEFAULT_USERDATA, ], }; diff --git a/src/entities/utils/parseRemoveLiquidityArgs.ts b/src/entities/utils/parseRemoveLiquidityArgs.ts index 6e54b5c9..bb623116 100644 --- a/src/entities/utils/parseRemoveLiquidityArgs.ts +++ b/src/entities/utils/parseRemoveLiquidityArgs.ts @@ -5,7 +5,7 @@ import { replaceWrapped } from './replaceWrapped'; export function parseRemoveLiquidityArgs({ chainId, - toNativeAsset, + receiveNativeAsset, sortedTokens, poolId, sender, @@ -15,7 +15,7 @@ export function parseRemoveLiquidityArgs({ toInternalBalance, }: { chainId?: number; - toNativeAsset?: boolean; + receiveNativeAsset?: boolean; sortedTokens: Token[]; poolId: Address; sender: Address; @@ -26,7 +26,7 @@ export function parseRemoveLiquidityArgs({ }) { // replace wrapped token with native asset if needed const tokensOut = - chainId && toNativeAsset + chainId && receiveNativeAsset ? replaceWrapped([...sortedTokens], chainId) : [...sortedTokens]; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 49186a0d..f9d95ae5 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -35,12 +35,14 @@ async function sdkAddLiquidity({ poolState, slippage, testAddress, + sendNativeAsset, }: { addLiquidity: AddLiquidity; addLiquidityInput: AddLiquidityInput; poolState: PoolState; slippage: Slippage; testAddress: Address; + sendNativeAsset?: boolean; }): Promise<{ addLiquidityBuildOutput: AddLiquidityBuildOutput; addLiquidityQueryOutput: AddLiquidityQueryOutput; @@ -55,7 +57,7 @@ async function sdkAddLiquidity({ sender: testAddress, recipient: testAddress, chainId: addLiquidityInput.chainId, - wethIsEth: addLiquidityInput.useNativeAssetAsWrappedAmountIn ?? false, + sendNativeAsset: !!sendNativeAsset, }); return { @@ -160,7 +162,7 @@ export function assertAddLiquidityUnbalanced( const expectedAmountsIn = poolState.tokens.map((t) => { let token: Token; if ( - addLiquidityInput.useNativeAssetAsWrappedAmountIn && + addLiquidityInput.sendNativeAsset && t.address === NATIVE_ASSETS[chainId].wrapped && vaultVersion === 2 ) @@ -263,7 +265,7 @@ export function assertAddLiquiditySingleToken( addLiquidityQueryOutput.amountsIn.forEach((a) => { if ( vaultVersion === 2 && - addLiquidityInput.useNativeAssetAsWrappedAmountIn && + addLiquidityInput.sendNativeAsset && a.token.address === zeroAddress ) { expect(a.amount > 0n).to.be.true; @@ -361,6 +363,7 @@ function assertTokenDeltas( addLiquidityBuildOutput: AddLiquidityBuildOutput, txOutput: TxOutput, vaultVersion: 2 | 3 = 2, + sendNativeAsset?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); @@ -380,9 +383,9 @@ function assertTokenDeltas( * Since native asset was moved to an extra index, we need to identify its * respective amount within the amounts array and move it to that index. * - Balancer V2: zero address represents the native asset - * - Balancer V3: WETH address represents the native asset (in combination with wethIsEth flag) + * - Balancer V3: WETH address represents the native asset (in combination with sendNativeAsset flag) */ - if (addLiquidityInput.useNativeAssetAsWrappedAmountIn) { + if (sendNativeAsset) { const respectiveNativeAddress = vaultVersion === 2 ? zeroAddress @@ -405,6 +408,7 @@ function assertAddLiquidityBuildOutput( isExactIn: boolean, slippage: Slippage, vaultVersion: 2 | 3 = 2, + sendNativeAsset?: boolean, ) { // if exactIn maxAmountsIn should use same amountsIn as input else slippage should be applied const maxAmountsIn = isExactIn @@ -428,8 +432,8 @@ function assertAddLiquidityBuildOutput( : BALANCER_ROUTER[addLiquidityInput.chainId]; let value = 0n; - if (addLiquidityInput.useNativeAssetAsWrappedAmountIn) { - // v2 uses zero address for native asset, while v3 uses wethIsEth flag only + if (sendNativeAsset) { + // v2 uses zero address for native asset, while v3 uses sendNativeAsset flag const nativeAsset = vaultVersion === 2 ? zeroAddress diff --git a/test/lib/utils/addLiquidityNestedHelper.ts b/test/lib/utils/addLiquidityNestedHelper.ts index 1303a714..e6b1a8a0 100644 --- a/test/lib/utils/addLiquidityNestedHelper.ts +++ b/test/lib/utils/addLiquidityNestedHelper.ts @@ -23,7 +23,7 @@ export const assertResults = ( minBptOut: bigint, chainId: number, value?: bigint, - useNativeAssetAsWrappedAmountIn = false, + sendNativeAsset = false, ) => { expect(transactionReceipt.status).to.eq('success'); expect(bptOut.amount > 0n).to.be.true; @@ -38,7 +38,7 @@ export const assertResults = ( const wrappedNativeAsset = amountsIn.find( (a) => a.address === NATIVE_ASSETS[chainId].wrapped, ); - if (wrappedNativeAsset && useNativeAssetAsWrappedAmountIn) { + if (wrappedNativeAsset && sendNativeAsset) { expect(value).to.eq(wrappedNativeAsset.rawAmount); } else { expect(value).to.eq(undefined || 0n); @@ -52,7 +52,7 @@ export const doAddLiquidityNested = async ({ rpcUrl, testAddress, client, - useNativeAssetAsWrappedAmountIn = false, + sendNativeAsset = false, }: AddLiquidityNestedTxInput) => { // setup add liquidity helper const addLiquidityNested = new AddLiquidityNested(); @@ -62,7 +62,7 @@ export const doAddLiquidityNested = async ({ chainId, rpcUrl, accountAddress: testAddress, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, }; const queryOutput = await addLiquidityNested.query( addLiquidityInput, @@ -87,7 +87,7 @@ export const doAddLiquidityNested = async ({ }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); - if (useNativeAssetAsWrappedAmountIn) { + if (sendNativeAsset) { tokensIn = replaceWrapped(tokensIn, chainId); } diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 4bb1a027..ef9648ed 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -35,6 +35,7 @@ export const sdkRemoveLiquidity = async ({ poolState, slippage, testAddress, + receiveNativeAsset, }: Omit): Promise<{ removeLiquidityBuildOutput: RemoveLiquidityBuildOutput; removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; @@ -49,7 +50,7 @@ export const sdkRemoveLiquidity = async ({ sender: testAddress, recipient: testAddress, chainId: removeLiquidityInput.chainId, - wethIsEth: !!removeLiquidityInput.toNativeAsset, + receiveNativeAsset: !!receiveNativeAsset, }); return { @@ -154,7 +155,7 @@ export function assertRemoveLiquidityUnbalanced( const expectedAmountsOut = poolState.tokens.map((t) => { let token: Token; if ( - removeLiquidityInput.toNativeAsset && + removeLiquidityInput.receiveNativeAsset && t.address === NATIVE_ASSETS[chainId].wrapped ) token = new Token(chainId, zeroAddress, t.decimals); @@ -219,7 +220,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( const expectedAmountsOut = poolState.tokens.map((t) => { let token: Token; if ( - removeLiquidityInput.toNativeAsset && + removeLiquidityInput.receiveNativeAsset && t.address === NATIVE_ASSETS[chainId].wrapped && vaultVersion === 2 ) { @@ -329,7 +330,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityQueryOutput.amountsOut.forEach((a) => { if ( vaultVersion === 2 && - removeLiquidityInput.toNativeAsset && + removeLiquidityInput.receiveNativeAsset && a.token.address === zeroAddress ) { expect(a.amount > 0n).to.be.true; @@ -497,7 +498,7 @@ function assertTokenDeltas( ]; // If removing liquidity to native asset we must replace it with 0 and update native value instead - if (removeLiquidityInput.toNativeAsset) { + if (removeLiquidityInput.receiveNativeAsset) { const respectiveNativeAddress = vaultVersion === 2 ? zeroAddress diff --git a/test/lib/utils/types.ts b/test/lib/utils/types.ts index 0273258b..d7453502 100644 --- a/test/lib/utils/types.ts +++ b/test/lib/utils/types.ts @@ -39,6 +39,7 @@ export type RemoveLiquidityTxInput = { slippage: Slippage; poolState: PoolState; testAddress: Address; + receiveNativeAsset?: boolean; }; export type CreatePoolTxInput = { @@ -58,5 +59,5 @@ export type AddLiquidityNestedTxInput = { rpcUrl: string; testAddress: Address; client: Client & PublicActions & TestActions & WalletActions; - useNativeAssetAsWrappedAmountIn?: boolean; + sendNativeAsset?: boolean; }; diff --git a/test/v2/addLiquidity/composableStable.integration.test.ts b/test/v2/addLiquidity/composableStable.integration.test.ts index 0baeefb8..4d177671 100644 --- a/test/v2/addLiquidity/composableStable.integration.test.ts +++ b/test/v2/addLiquidity/composableStable.integration.test.ts @@ -129,7 +129,7 @@ describe('add liquidity composable stable test', () => { const addLiquidityInput = { ...input, amountsIn, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, @@ -180,7 +180,7 @@ describe('add liquidity composable stable test', () => { test('with native', async () => { const addLiquidityInput = { ...input, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, @@ -229,7 +229,7 @@ describe('add liquidity composable stable test', () => { test('with native', async () => { const addLiquidityInput = { ...input, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, diff --git a/test/v2/addLiquidity/gyroEV2.integration.test.ts b/test/v2/addLiquidity/gyroEV2.integration.test.ts index 5a347b87..81488692 100644 --- a/test/v2/addLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/addLiquidity/gyroEV2.integration.test.ts @@ -124,7 +124,7 @@ describe('GyroE V2 add liquidity test', () => { ...txInput, addLiquidityInput: { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, }); assertAddLiquidityProportional( @@ -132,7 +132,7 @@ describe('GyroE V2 add liquidity test', () => { txInput.poolState, { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, addLiquidityOutput, txInput.slippage, diff --git a/test/v2/addLiquidity/weighted.integration.test.ts b/test/v2/addLiquidity/weighted.integration.test.ts index bd16037f..9eccaefd 100644 --- a/test/v2/addLiquidity/weighted.integration.test.ts +++ b/test/v2/addLiquidity/weighted.integration.test.ts @@ -129,7 +129,7 @@ describe('add liquidity weighted test', () => { const addLiquidityInput = { ...input, amountsIn, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, @@ -183,7 +183,7 @@ describe('add liquidity weighted test', () => { ...txInput, addLiquidityInput: { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, }); @@ -192,7 +192,7 @@ describe('add liquidity weighted test', () => { txInput.poolState, { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, addLiquidityOutput, txInput.slippage, @@ -234,7 +234,7 @@ describe('add liquidity weighted test', () => { ...txInput, addLiquidityInput: { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, }); @@ -243,7 +243,7 @@ describe('add liquidity weighted test', () => { txInput.poolState, { ...addLiquidityInput, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }, addLiquidityOutput, txInput.slippage, diff --git a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts index 158975f7..988f639b 100644 --- a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts +++ b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts @@ -162,12 +162,12 @@ describe('add liquidity nested test', () => { decimals: t.decimals, })); - const useNativeAssetAsWrappedAmountIn = true; + const sendNativeAsset = true; txInput = { ...txInput, amountsIn, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, }; const { @@ -188,7 +188,7 @@ describe('add liquidity nested test', () => { minBptOut, chainId, value, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, ); }); @@ -201,12 +201,12 @@ describe('add liquidity nested test', () => { }, ]; - const useNativeAssetAsWrappedAmountIn = true; + const sendNativeAsset = true; txInput = { ...txInput, amountsIn, - useNativeAssetAsWrappedAmountIn, + sendNativeAsset, }; await expect(() => doAddLiquidityNested(txInput)).rejects.toThrowError( diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index e92210e4..2d3b66e8 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -129,7 +129,7 @@ describe('composable stable remove liquidity test', () => { const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -181,7 +181,7 @@ describe('composable stable remove liquidity test', () => { const removeLiquidityInput = { ...input, amountOut, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -232,7 +232,7 @@ describe('composable stable remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -281,7 +281,7 @@ describe('composable stable remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, diff --git a/test/v2/removeLiquidity/gyroEV2.integration.test.ts b/test/v2/removeLiquidity/gyroEV2.integration.test.ts index 56972b8f..ebcd51f6 100644 --- a/test/v2/removeLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/removeLiquidity/gyroEV2.integration.test.ts @@ -115,7 +115,7 @@ describe('GyroE V2 remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index 451daae8..ac9efbea 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -121,7 +121,7 @@ describe('weighted remove liquidity test', () => { const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -173,7 +173,7 @@ describe('weighted remove liquidity test', () => { const removeLiquidityInput = { ...input, amountOut, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -224,7 +224,7 @@ describe('weighted remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -273,7 +273,7 @@ describe('weighted remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, diff --git a/test/v3/addLiquidity.integration.test.ts b/test/v3/addLiquidity.integration.test.ts index 9df3caa4..f5826adf 100644 --- a/test/v3/addLiquidity.integration.test.ts +++ b/test/v3/addLiquidity.integration.test.ts @@ -130,7 +130,7 @@ describe('add liquidity test', () => { const addLiquidityInput = { ...input, amountsIn, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, @@ -183,7 +183,7 @@ describe('add liquidity test', () => { test('with native', async () => { const addLiquidityInput = { ...input, - useNativeAssetAsWrappedAmountIn: true, + sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, diff --git a/test/v3/removeLiquidity.integration.test.ts b/test/v3/removeLiquidity.integration.test.ts index 044bc5ea..0f770932 100644 --- a/test/v3/removeLiquidity.integration.test.ts +++ b/test/v3/removeLiquidity.integration.test.ts @@ -185,7 +185,7 @@ describe('remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -239,7 +239,7 @@ describe('remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, @@ -290,7 +290,7 @@ describe('remove liquidity test', () => { test('with native', async () => { const removeLiquidityInput = { ...input, - toNativeAsset: true, + receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, From 4d2c083aff703bf52bb601225b07c6152613863c Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 5 Mar 2024 17:01:09 -0300 Subject: [PATCH 02/29] Move send/receiveNativeAsset from query to buildCall input --- examples/addLiquidityNested.ts | 6 +- .../addLiquidityComposableStable.ts | 7 +- .../weighted/addLiquidityWeighted.ts | 10 +-- src/entities/addLiquidity/helpers.ts | 12 +++ .../getQueryCallsAttributes.ts | 2 - src/entities/addLiquidityNested/index.ts | 15 +++- src/entities/addLiquidityNested/types.ts | 4 +- .../addLiquidityNested/validateInputs.ts | 30 +++----- src/entities/priceImpact/index.ts | 1 - .../removeLiquidityComposableStable.ts | 4 +- .../weighted/removeLiquidityWeighted.ts | 4 +- .../removeLiquidityV3/index.ts | 1 + src/entities/removeLiquidity/types.ts | 1 + src/entities/removeLiquidityNested/index.ts | 2 + .../removeLiquidityNested/validateInputs.ts | 2 - src/entities/utils/index.ts | 2 +- ...lidation.ts => validateNestedPoolState.ts} | 2 +- test/lib/utils/addLiquidityHelper.ts | 58 +++++++------- test/lib/utils/addLiquidityNestedHelper.ts | 2 +- test/lib/utils/removeLiquidityHelper.ts | 76 ++++++++++++------- test/lib/utils/types.ts | 2 + ...t.ts => nestedPoolStateValidation.test.ts} | 12 +-- .../composableStable.integration.test.ts | 15 +++- .../addLiquidity/gyroEV2.integration.test.ts | 14 ++-- .../addLiquidity/weighted.integration.test.ts | 33 ++++---- .../composableStable.integration.test.ts | 20 ++++- ...posableStable.recovery.integration.test.ts | 1 + .../gyroEV2.integration.test.ts | 5 +- .../weighted.integration.test.ts | 20 ++++- .../weighted.recovery.integration.test.ts | 1 + test/v3/addLiquidity.integration.test.ts | 10 ++- test/v3/removeLiquidity.integration.test.ts | 33 ++++---- 32 files changed, 239 insertions(+), 168 deletions(-) rename src/entities/utils/{constraintValidation.ts => validateNestedPoolState.ts} (97%) rename test/{constraintValidation.test.ts => nestedPoolStateValidation.test.ts} (95%) diff --git a/examples/addLiquidityNested.ts b/examples/addLiquidityNested.ts index c824f53c..91d0bc9d 100644 --- a/examples/addLiquidityNested.ts +++ b/examples/addLiquidityNested.ts @@ -62,14 +62,11 @@ const addLiquidityNested = async () => { }, ]; - const sendNativeAsset = false; - const addLiquidityInput: AddLiquidityNestedInput = { amountsIn, chainId, rpcUrl, accountAddress, - sendNativeAsset, }; // Calculate price impact to ensure it's acceptable @@ -100,12 +97,15 @@ const addLiquidityNested = async () => { client, ); + const sendNativeAsset = false; + const { call, to, value, minBptOut } = addLiquidityNested.buildCall({ ...queryOutput, slippage, sender: accountAddress, recipient: accountAddress, relayerApprovalSignature: signature, + sendNativeAsset, }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 466532a9..92286e90 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -22,6 +22,7 @@ import { parseAddLiquidityArgs, } from '@/entities/utils'; import { ComposableStableEncoder } from '@/entities/encoders/composableStable'; +import { getValue } from '../../helpers'; type AddLiquidityAmounts = AddLiquidityAmountsBase & { maxAmountsInWithoutBpt: bigint[]; @@ -105,14 +106,10 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { args, }); - const value = input.amountsIn.find( - (a) => a.token.address === ZERO_ADDRESS, - )?.amount; - return { call, to: VAULT[input.chainId], - value: value === undefined ? 0n : value, + value: getValue(input), minBptOut: TokenAmount.fromRawAmount( input.bptOut.token, amounts.minimumBpt, diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index dacd2d06..1426013f 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -19,7 +19,7 @@ import { getSortedTokens, parseAddLiquidityArgs, } from '@/entities/utils'; -import { getAmountsCall } from '../../helpers'; +import { getAmountsCall, getValue } from '../../helpers'; export class AddLiquidityWeighted implements AddLiquidityBase { public async query( @@ -35,7 +35,6 @@ export class AddLiquidityWeighted implements AddLiquidityBase { ); const { args, tokensIn } = parseAddLiquidityArgs({ - sendNativeAsset: !!input.sendNativeAsset, chainId: input.chainId, sortedTokens, poolId: poolState.id, @@ -85,6 +84,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { maxAmountsIn: amounts.maxAmountsIn, userData, fromInternalBalance: input.fromInternalBalance, + sendNativeAsset: !!input.sendNativeAsset, }); const call = encodeFunctionData({ @@ -93,14 +93,10 @@ export class AddLiquidityWeighted implements AddLiquidityBase { args, }); - const value = input.amountsIn.find( - (a) => a.token.address === ZERO_ADDRESS, - )?.amount; - return { call, to: VAULT[input.chainId], - value: value === undefined ? 0n : value, + value: getValue(input), minBptOut: TokenAmount.fromRawAmount( input.bptOut.token, amounts.minimumBpt, diff --git a/src/entities/addLiquidity/helpers.ts b/src/entities/addLiquidity/helpers.ts index e682ef54..17b04a17 100644 --- a/src/entities/addLiquidity/helpers.ts +++ b/src/entities/addLiquidity/helpers.ts @@ -1,3 +1,4 @@ +import { NATIVE_ASSETS } from '@/utils'; import { AddLiquidityAmounts } from '../types'; import { AddLiquidityBaseCall, AddLiquidityKind } from './types'; @@ -25,3 +26,14 @@ export const getAmountsCall = ( } } }; + +export const getValue = (input: AddLiquidityBaseCall): bigint => { + let value = 0n; + if (input.sendNativeAsset) { + value = + input.amountsIn.find( + (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, + )?.amount ?? 0n; + } + return value; +}; diff --git a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts index 78946834..938c383a 100644 --- a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts +++ b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts @@ -13,7 +13,6 @@ export const getQueryCallsAttributes = ( amountsIn, chainId, accountAddress, - sendNativeAsset, fromInternalBalance, }: AddLiquidityNestedInput, pools: NestedPool[], @@ -38,7 +37,6 @@ export const getQueryCallsAttributes = ( } calls.push({ chainId: chainId, - sendNativeAsset: sendNativeAsset ?? false, sortedTokens, poolId: pool.id, poolAddress: pool.address, diff --git a/src/entities/addLiquidityNested/index.ts b/src/entities/addLiquidityNested/index.ts index 496e854d..4c0f71e8 100644 --- a/src/entities/addLiquidityNested/index.ts +++ b/src/entities/addLiquidityNested/index.ts @@ -13,15 +13,17 @@ import { } from './types'; import { doAddLiquidityNestedQuery } from './doAddLiquidityNestedQuery'; import { getQueryCallsAttributes } from './getQueryCallsAttributes'; -import { validateInputs } from './validateInputs'; +import { validateBuildCallInput, validateQueryInput } from './validateInputs'; import { NestedPoolState } from '../types'; +import { validateNestedPoolState } from '../utils'; export class AddLiquidityNested { async query( input: AddLiquidityNestedInput, nestedPoolState: NestedPoolState, ): Promise { - const amountsIn = validateInputs(input, nestedPoolState); + const amountsIn = validateQueryInput(input, nestedPoolState); + validateNestedPoolState(nestedPoolState); const callsAttributes = getQueryCallsAttributes( input, @@ -65,6 +67,7 @@ export class AddLiquidityNested { value: bigint | undefined; minBptOut: bigint; } { + validateBuildCallInput(input); // apply slippage to bptOut const minBptOut = input.slippage.applyTo(input.bptOut.amount, -1); @@ -74,6 +77,14 @@ export class AddLiquidityNested { minBptOut, }; + // update sendNativeAsset flag + input.callsAttributes = input.callsAttributes.map((call) => { + return { + ...call, + sendNativeAsset: input.sendNativeAsset, + }; + }); + const { encodedCalls, values } = encodeCalls(input.callsAttributes); // prepend relayer approval if provided diff --git a/src/entities/addLiquidityNested/types.ts b/src/entities/addLiquidityNested/types.ts index f2bd385b..38e8f297 100644 --- a/src/entities/addLiquidityNested/types.ts +++ b/src/entities/addLiquidityNested/types.ts @@ -10,13 +10,12 @@ export type AddLiquidityNestedInput = { chainId: ChainId; rpcUrl: string; accountAddress: Address; - sendNativeAsset?: boolean; fromInternalBalance?: boolean; }; export type AddLiquidityNestedCallAttributes = { chainId: ChainId; - sendNativeAsset: boolean; + sendNativeAsset?: boolean; sortedTokens: Token[]; poolId: Hex; poolAddress: Address; @@ -44,4 +43,5 @@ export type AddLiquidityNestedCallInput = AddLiquidityNestedQueryOutput & { sender: Address; recipient: Address; relayerApprovalSignature?: Hex; + sendNativeAsset?: boolean; }; diff --git a/src/entities/addLiquidityNested/validateInputs.ts b/src/entities/addLiquidityNested/validateInputs.ts index cb82dff8..f543102a 100644 --- a/src/entities/addLiquidityNested/validateInputs.ts +++ b/src/entities/addLiquidityNested/validateInputs.ts @@ -2,43 +2,37 @@ import { NATIVE_ASSETS } from '../../utils'; import { Token } from '../token'; import { TokenAmount } from '../tokenAmount'; import { NestedPoolState } from '../types'; -import { constraintValidation } from '../utils'; -import { AddLiquidityNestedInput } from './types'; +import { AddLiquidityNestedCallInput, AddLiquidityNestedInput } from './types'; -export const validateInputs = ( +export const validateQueryInput = ( input: AddLiquidityNestedInput, nestedPoolState: NestedPoolState, ): TokenAmount[] => { - constraintValidation(nestedPoolState); const mainTokens = nestedPoolState.mainTokens.map( (t) => new Token(input.chainId, t.address, t.decimals), ); - const amountsIn = input.amountsIn.map((amountIn) => { const tokenIn = mainTokens.find((t) => t.isSameAddress(amountIn.address), ); if (tokenIn === undefined) { throw new Error( - `Adding liquidity with ${tokenIn} requires it to exist within mainTokens`, + `Adding liquidity with ${amountIn.address} requires it to exist within mainTokens`, ); } return TokenAmount.fromRawAmount(tokenIn, amountIn.rawAmount); }); + return amountsIn; +}; +export const validateBuildCallInput = ( + input: AddLiquidityNestedCallInput, +): void => { + const chainId = input.callsAttributes[0].chainId; if (input.sendNativeAsset) { if ( - !mainTokens.some((t) => - t.isUnderlyingEqual(NATIVE_ASSETS[input.chainId]), - ) - ) { - throw new Error( - 'Adding liquidity with native asset requires wrapped native asset to exist within mainTokens', - ); - } - if ( - !amountsIn.some((a) => - a.token.isUnderlyingEqual(NATIVE_ASSETS[input.chainId]), + !input.amountsIn.some((a) => + a.token.isUnderlyingEqual(NATIVE_ASSETS[chainId]), ) ) { throw new Error( @@ -46,6 +40,4 @@ export const validateInputs = ( ); } } - - return amountsIn; }; diff --git a/src/entities/priceImpact/index.ts b/src/entities/priceImpact/index.ts index c20f9903..734965d2 100644 --- a/src/entities/priceImpact/index.ts +++ b/src/entities/priceImpact/index.ts @@ -371,7 +371,6 @@ export class PriceImpact { accountAddress: input.accountAddress, chainId: input.chainId, rpcUrl: input.rpcUrl, - sendNativeAsset: input.useNativeAssetAsWrappedAmountOut, fromInternalBalance: input.toInternalBalance, amountsIn: amountsOut.map((a) => a.toInputAmount()), }; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index ef3647ab..ed5be05d 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -45,7 +45,6 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { // tokensOut will have zero address if removing liquidity to native asset const { args, tokensOut } = parseRemoveLiquidityArgs({ chainId: input.chainId, - receiveNativeAsset: !!input.receiveNativeAsset, poolId: poolState.id, sortedTokens, sender: ZERO_ADDRESS, @@ -76,6 +75,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { toInternalBalance: !!input.toInternalBalance, bptIndex, vaultVersion: poolState.vaultVersion, + chainId: input.chainId, }; } @@ -143,6 +143,8 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { minAmountsOut: amounts.minAmountsOut, userData, toInternalBalance: !!input.toInternalBalance, + receiveNativeAsset: !!input.receiveNativeAsset, + chainId: input.chainId, }); const call = encodeFunctionData({ abi: vaultV2Abi, diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index 8533056b..74c05e35 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -36,7 +36,6 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { // tokensOut will have zero address if removing liquidity to native asset const { args, tokensOut } = parseRemoveLiquidityArgs({ chainId: input.chainId, - receiveNativeAsset: !!input.receiveNativeAsset, poolId: poolState.id, sortedTokens, sender: ZERO_ADDRESS, @@ -68,6 +67,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { tokenOutIndex: amounts.tokenOutIndex, toInternalBalance: !!input.toInternalBalance, vaultVersion: poolState.vaultVersion, + chainId: input.chainId, }; } @@ -89,6 +89,8 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { minAmountsOut: amounts.minAmountsOut, userData, toInternalBalance: !!input.toInternalBalance, + receiveNativeAsset: !!input.receiveNativeAsset, + chainId: input.chainId, }); const call = encodeFunctionData({ diff --git a/src/entities/removeLiquidity/removeLiquidityV3/index.ts b/src/entities/removeLiquidity/removeLiquidityV3/index.ts index 75b7deea..a230890e 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/index.ts @@ -93,6 +93,7 @@ export class RemoveLiquidityV3 implements RemoveLiquidityBase { tokenOutIndex: amounts.tokenOutIndex, toInternalBalance: !!input.toInternalBalance, vaultVersion: poolState.vaultVersion, + chainId: input.chainId, }; return output; diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index 1dec1c7b..dc362748 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -67,6 +67,7 @@ export type RemoveLiquidityBaseQueryOutput = { tokenOutIndex?: number; toInternalBalance: boolean; vaultVersion: 2 | 3; + chainId: number; }; export type RemoveLiquidityComposableStableQueryOutput = diff --git a/src/entities/removeLiquidityNested/index.ts b/src/entities/removeLiquidityNested/index.ts index 6dd76e8d..cda73225 100644 --- a/src/entities/removeLiquidityNested/index.ts +++ b/src/entities/removeLiquidityNested/index.ts @@ -16,6 +16,7 @@ import { getQueryCallsAttributes } from './getQueryCallsAttributes'; import { encodeCalls } from './encodeCalls'; import { getPeekCalls } from './getPeekCalls'; import { validateInputs } from './validateInputs'; +import { validateNestedPoolState } from '../utils'; export class RemoveLiquidityNested { async query( @@ -25,6 +26,7 @@ export class RemoveLiquidityNested { nestedPoolState: NestedPoolState, ): Promise { const isProportional = validateInputs(input, nestedPoolState); + validateNestedPoolState(nestedPoolState); const { callsAttributes, bptAmountIn } = getQueryCallsAttributes( input, diff --git a/src/entities/removeLiquidityNested/validateInputs.ts b/src/entities/removeLiquidityNested/validateInputs.ts index 26e6f6a9..59bb6f6e 100644 --- a/src/entities/removeLiquidityNested/validateInputs.ts +++ b/src/entities/removeLiquidityNested/validateInputs.ts @@ -1,7 +1,6 @@ import { NATIVE_ASSETS } from '../../utils'; import { Token } from '../token'; import { NestedPoolState } from '../types'; -import { constraintValidation } from '../utils'; import { RemoveLiquidityNestedProportionalInput, RemoveLiquidityNestedSingleTokenInput, @@ -13,7 +12,6 @@ export const validateInputs = ( | RemoveLiquidityNestedSingleTokenInput, nestedPoolState: NestedPoolState, ) => { - constraintValidation(nestedPoolState); const tokenOut = 'tokenOut' in input ? input.tokenOut : undefined; const isProportional = tokenOut === undefined; const mainTokens = nestedPoolState.mainTokens.map( diff --git a/src/entities/utils/index.ts b/src/entities/utils/index.ts index caab02db..f5e53031 100644 --- a/src/entities/utils/index.ts +++ b/src/entities/utils/index.ts @@ -1,5 +1,5 @@ export * from './calculateProportionalAmounts'; -export * from './constraintValidation'; +export * from './validateNestedPoolState'; export * from './doAddLiquidityQuery'; export * from './doSingleSwapQuery'; export * from './getAmounts'; diff --git a/src/entities/utils/constraintValidation.ts b/src/entities/utils/validateNestedPoolState.ts similarity index 97% rename from src/entities/utils/constraintValidation.ts rename to src/entities/utils/validateNestedPoolState.ts index b314cc7f..1dbf74d6 100644 --- a/src/entities/utils/constraintValidation.ts +++ b/src/entities/utils/validateNestedPoolState.ts @@ -1,6 +1,6 @@ import { NestedPoolState } from '../types'; -export function constraintValidation( +export function validateNestedPoolState( nestedPoolState: NestedPoolState, ): boolean { /* diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index f9d95ae5..02bc6643 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -19,7 +19,6 @@ import { } from '../../../src'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; -import { zeroAddress } from 'viem'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { addLiquiditySingleTokenShouldHaveTokenInIndexError } from '../../../src/utils/errors'; @@ -117,6 +116,7 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { testAddress, client, slippage, + sendNativeAsset, } = txInput; const { addLiquidityQueryOutput, addLiquidityBuildOutput } = @@ -126,6 +126,7 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { poolState, slippage, testAddress, + sendNativeAsset, }); const tokens = getTokensForBalanceCheck(poolState); @@ -154,20 +155,14 @@ export function assertAddLiquidityUnbalanced( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + sendNativeAsset?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; // 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) => { - let token: Token; - if ( - addLiquidityInput.sendNativeAsset && - t.address === NATIVE_ASSETS[chainId].wrapped && - vaultVersion === 2 - ) - token = new Token(chainId, zeroAddress, t.decimals); - else token = new Token(chainId, t.address, t.decimals); + const token = new Token(chainId, t.address, t.decimals); const input = addLiquidityInput.amountsIn.find( (a) => a.address === t.address, ); @@ -204,6 +199,7 @@ export function assertAddLiquidityUnbalanced( true, slippage, vaultVersion, + sendNativeAsset, ); assertTokenDeltas( @@ -213,6 +209,7 @@ export function assertAddLiquidityUnbalanced( addLiquidityBuildOutput, txOutput, vaultVersion, + sendNativeAsset, ); } @@ -223,6 +220,7 @@ export function assertAddLiquiditySingleToken( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + sendNativeAsset?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; @@ -263,13 +261,7 @@ export function assertAddLiquiditySingleToken( // Expect only tokenIn to have amount > 0 // (Note addLiquidityQueryOutput also has value for bpt if pre-minted) addLiquidityQueryOutput.amountsIn.forEach((a) => { - if ( - vaultVersion === 2 && - addLiquidityInput.sendNativeAsset && - a.token.address === zeroAddress - ) { - expect(a.amount > 0n).to.be.true; - } else if (a.token.address === addLiquidityInput.tokenIn) { + if (a.token.address === addLiquidityInput.tokenIn) { expect(a.amount > 0n).to.be.true; } else { expect(a.amount).toEqual(0n); @@ -283,6 +275,7 @@ export function assertAddLiquiditySingleToken( false, slippage, vaultVersion, + sendNativeAsset, ); assertTokenDeltas( @@ -292,6 +285,7 @@ export function assertAddLiquiditySingleToken( addLiquidityBuildOutput, txOutput, vaultVersion, + sendNativeAsset, ); } @@ -302,6 +296,7 @@ export function assertAddLiquidityProportional( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + sendNativeAsset?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; @@ -344,8 +339,17 @@ export function assertAddLiquidityProportional( false, slippage, vaultVersion, + sendNativeAsset, ); + if (sendNativeAsset) { + expect( + addLiquidityOutput.addLiquidityQueryOutput.amountsIn.some((t) => + t.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + ), + ).to.be.true; + } + assertTokenDeltas( poolState, addLiquidityInput, @@ -353,6 +357,7 @@ export function assertAddLiquidityProportional( addLiquidityBuildOutput, txOutput, vaultVersion, + sendNativeAsset, ); } @@ -386,12 +391,10 @@ function assertTokenDeltas( * - Balancer V3: WETH address represents the native asset (in combination with sendNativeAsset flag) */ if (sendNativeAsset) { - const respectiveNativeAddress = - vaultVersion === 2 - ? zeroAddress - : NATIVE_ASSETS[addLiquidityInput.chainId].wrapped; - const nativeAssetIndex = amountsWithoutBpt.findIndex( - (a) => a.token.address === respectiveNativeAddress, + const nativeAssetIndex = amountsWithoutBpt.findIndex((a) => + a.token.isSameAddress( + NATIVE_ASSETS[addLiquidityInput.chainId].wrapped, + ), ); expectedDeltas[nativeAssetIndex] = 0n; expectedDeltas[expectedDeltas.length - 1] = @@ -433,14 +436,11 @@ function assertAddLiquidityBuildOutput( let value = 0n; if (sendNativeAsset) { - // v2 uses zero address for native asset, while v3 uses sendNativeAsset flag - const nativeAsset = - vaultVersion === 2 - ? zeroAddress - : NATIVE_ASSETS[addLiquidityInput.chainId].wrapped; value = - addLiquidityQueryOutput.amountsIn.find( - (a) => a.token.address === nativeAsset, + addLiquidityQueryOutput.amountsIn.find((a) => + a.token.isSameAddress( + NATIVE_ASSETS[addLiquidityInput.chainId].wrapped, + ), )?.amount ?? 0n; } diff --git a/test/lib/utils/addLiquidityNestedHelper.ts b/test/lib/utils/addLiquidityNestedHelper.ts index e6b1a8a0..c9c0cda2 100644 --- a/test/lib/utils/addLiquidityNestedHelper.ts +++ b/test/lib/utils/addLiquidityNestedHelper.ts @@ -62,7 +62,6 @@ export const doAddLiquidityNested = async ({ chainId, rpcUrl, accountAddress: testAddress, - sendNativeAsset, }; const queryOutput = await addLiquidityNested.query( addLiquidityInput, @@ -84,6 +83,7 @@ export const doAddLiquidityNested = async ({ sender: testAddress, recipient: testAddress, relayerApprovalSignature: signature, + sendNativeAsset, }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index ef9648ed..1015762c 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -110,6 +110,7 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { testAddress, client, slippage, + receiveNativeAsset, } = txInput; const { removeLiquidityQueryOutput, removeLiquidityBuildOutput } = @@ -119,6 +120,7 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { poolState, slippage, testAddress, + receiveNativeAsset, }); // get tokens for balance change - pool tokens, BPT, native @@ -147,19 +149,15 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput: RemoveLiquidityUnbalancedInput, removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, + vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; // 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) => { - let token: Token; - if ( - removeLiquidityInput.receiveNativeAsset && - t.address === NATIVE_ASSETS[chainId].wrapped - ) - token = new Token(chainId, zeroAddress, t.decimals); - else token = new Token(chainId, t.address, t.decimals); + const token = new Token(chainId, t.address, t.decimals); const input = removeLiquidityInput.amountsOut.find( (a) => a.address === t.address, ); @@ -180,6 +178,7 @@ export function assertRemoveLiquidityUnbalanced( toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, false); @@ -202,6 +201,8 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, + vaultVersion, + receiveNativeAsset, ); } @@ -212,22 +213,14 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; // 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) => { - let token: Token; - if ( - removeLiquidityInput.receiveNativeAsset && - t.address === NATIVE_ASSETS[chainId].wrapped && - vaultVersion === 2 - ) { - token = new Token(chainId, zeroAddress, t.decimals); - } else { - token = new Token(chainId, t.address, t.decimals); - } + const token = new Token(chainId, t.address, t.decimals); const input = removeLiquidityInput.amountOut; if (input.address !== t.address) { return TokenAmount.fromRawAmount(token, 0n); @@ -254,6 +247,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, false); @@ -278,6 +272,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityQueryOutput, txOutput, vaultVersion, + receiveNativeAsset, ); } @@ -288,6 +283,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -319,6 +315,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -330,7 +327,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityQueryOutput.amountsOut.forEach((a) => { if ( vaultVersion === 2 && - removeLiquidityInput.receiveNativeAsset && + receiveNativeAsset && a.token.address === zeroAddress ) { expect(a.amount > 0n).to.be.true; @@ -356,6 +353,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityQueryOutput, txOutput, vaultVersion, + receiveNativeAsset, ); } @@ -366,6 +364,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -389,6 +388,7 @@ export function assertRemoveLiquidityProportional( toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -401,6 +401,14 @@ export function assertRemoveLiquidityProportional( else expect(a.amount > 0n).to.be.true; }); + if (receiveNativeAsset) { + expect( + removeLiquidityQueryOutput.amountsOut.some((a) => + a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + ), + ).to.be.true; + } + assertRemoveLiquidityBuildOutput( removeLiquidityQueryOutput, removeLiquidityBuildOutput, @@ -416,6 +424,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityQueryOutput, txOutput, vaultVersion, + receiveNativeAsset, ); } @@ -425,6 +434,8 @@ export function assertRemoveLiquidityRecovery( removeLiquidityInput: RemoveLiquidityRecoveryInput, removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, + vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -448,6 +459,7 @@ export function assertRemoveLiquidityRecovery( toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -460,12 +472,21 @@ export function assertRemoveLiquidityRecovery( else expect(a.amount > 0n).to.be.true; }); + if (receiveNativeAsset) { + expect( + removeLiquidityQueryOutput.amountsOut.some((a) => + a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + ), + ).to.be.true; + } + assertRemoveLiquidityBuildOutput( removeLiquidityQueryOutput, removeLiquidityBuildOutput, true, slippage, chainId, + vaultVersion, ); assertTokenDeltas( @@ -473,6 +494,8 @@ export function assertRemoveLiquidityRecovery( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, + vaultVersion, + receiveNativeAsset, ); } @@ -482,6 +505,7 @@ function assertTokenDeltas( removeLiquidityQueryOutput: RemoveLiquidityQueryOutput, txOutput: TxOutput, vaultVersion: 2 | 3 = 2, + receiveNativeAsset?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); @@ -498,13 +522,11 @@ function assertTokenDeltas( ]; // If removing liquidity to native asset we must replace it with 0 and update native value instead - if (removeLiquidityInput.receiveNativeAsset) { - const respectiveNativeAddress = - vaultVersion === 2 - ? zeroAddress - : NATIVE_ASSETS[removeLiquidityInput.chainId].wrapped; - const nativeAssetIndex = amountsWithoutBpt.findIndex( - (a) => a.token.address === respectiveNativeAddress, + if (receiveNativeAsset) { + const nativeAssetIndex = amountsWithoutBpt.findIndex((a) => + a.token.isSameAddress( + NATIVE_ASSETS[removeLiquidityInput.chainId].wrapped, + ), ); expectedDeltas[expectedDeltas.length - 1] = expectedDeltas[nativeAssetIndex]; @@ -517,8 +539,8 @@ function assertTokenDeltas( }, ); //The Balance Delta for Recovery Exits has rounding errors, since the query is done for proportional exits - balanceVsExpectedDeltas.forEach((value) => { - expect(value).to.be.lessThanOrEqual(1); + balanceVsExpectedDeltas.forEach((diff) => { + expect(diff).to.be.lessThanOrEqual(1); }); } diff --git a/test/lib/utils/types.ts b/test/lib/utils/types.ts index d7453502..cf2efd75 100644 --- a/test/lib/utils/types.ts +++ b/test/lib/utils/types.ts @@ -22,6 +22,7 @@ export type AddLiquidityTxInput = { slippage: Slippage; poolState: PoolState; testAddress: Address; + sendNativeAsset?: boolean; }; export type InitPoolTxInput = Omit< @@ -54,6 +55,7 @@ export type AddLiquidityNestedTxInput = { amountsIn: { address: Address; // DAI rawAmount: bigint; + decimals: number; }[]; chainId: ChainId; rpcUrl: string; diff --git a/test/constraintValidation.test.ts b/test/nestedPoolStateValidation.test.ts similarity index 95% rename from test/constraintValidation.test.ts rename to test/nestedPoolStateValidation.test.ts index e45ec966..9837921c 100644 --- a/test/constraintValidation.test.ts +++ b/test/nestedPoolStateValidation.test.ts @@ -3,20 +3,20 @@ import { describe, expect, test } from 'vitest'; import { NestedPoolState, NestedPool, - constraintValidation, + validateNestedPoolState, } from '../src/entities'; import { PoolType } from '@/types'; -describe('constraint validations', () => { +describe('nested pool state validations', () => { describe('happy case', () => { test('should be valid', () => { - expect(constraintValidation(happyPoolState)).to.be.true; + expect(validateNestedPoolState(happyPoolState)).to.be.true; }); }); describe('A main token must exist as a token of a pool', () => { test('should throw', () => { // Test the exact error message - expect(() => constraintValidation(missingMain)).toThrowError( + expect(() => validateNestedPoolState(missingMain)).toThrowError( /^NestedPoolState, main token must exist as a token of a pool$/, ); }); @@ -25,7 +25,7 @@ describe('constraint validations', () => { test('should throw', () => { // Test the exact error message expect(() => - constraintValidation(multiTokenPoolState), + validateNestedPoolState(multiTokenPoolState), ).toThrowError( /^NestedPoolState, main token can't be token of more than 1 pool$/, ); @@ -34,7 +34,7 @@ describe('constraint validations', () => { describe('A main token only supported to a max of 1 level of nesting', () => { test('should throw', () => { // Test the exact error message - expect(() => constraintValidation(deepPoolState)).toThrowError( + expect(() => validateNestedPoolState(deepPoolState)).toThrowError( /^NestedPoolState, main token only supported to a max of 1 level of nesting$/, ); }); diff --git a/test/v2/addLiquidity/composableStable.integration.test.ts b/test/v2/addLiquidity/composableStable.integration.test.ts index 4d177671..f945c5ea 100644 --- a/test/v2/addLiquidity/composableStable.integration.test.ts +++ b/test/v2/addLiquidity/composableStable.integration.test.ts @@ -126,14 +126,15 @@ describe('add liquidity composable stable test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, amountsIn, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -141,6 +142,8 @@ describe('add liquidity composable stable test', () => { addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); @@ -178,13 +181,14 @@ describe('add liquidity composable stable test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquiditySingleToken( @@ -193,6 +197,8 @@ describe('add liquidity composable stable test', () => { addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); @@ -227,13 +233,14 @@ describe('add liquidity composable stable test', () => { ); }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityProportional( txInput.client.chain?.id as number, @@ -241,6 +248,8 @@ describe('add liquidity composable stable test', () => { addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); diff --git a/test/v2/addLiquidity/gyroEV2.integration.test.ts b/test/v2/addLiquidity/gyroEV2.integration.test.ts index 81488692..c22e581b 100644 --- a/test/v2/addLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/addLiquidity/gyroEV2.integration.test.ts @@ -120,22 +120,20 @@ describe('GyroE V2 add liquidity test', () => { ); }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, - addLiquidityInput: { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityProportional( txInput.client.chain?.id as number, txInput.poolState, - { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); diff --git a/test/v2/addLiquidity/weighted.integration.test.ts b/test/v2/addLiquidity/weighted.integration.test.ts index 9eccaefd..fbc5e1d7 100644 --- a/test/v2/addLiquidity/weighted.integration.test.ts +++ b/test/v2/addLiquidity/weighted.integration.test.ts @@ -126,14 +126,15 @@ describe('add liquidity weighted test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, amountsIn, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -141,6 +142,8 @@ describe('add liquidity weighted test', () => { addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); @@ -179,23 +182,21 @@ describe('add liquidity weighted test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, - addLiquidityInput: { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, + sendNativeAsset, }); assertAddLiquiditySingleToken( txInput.client.chain?.id as number, txInput.poolState, - { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); @@ -230,23 +231,21 @@ describe('add liquidity weighted test', () => { ); }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, - addLiquidityInput: { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityProportional( txInput.client.chain?.id as number, txInput.poolState, - { - ...addLiquidityInput, - sendNativeAsset: true, - }, + addLiquidityInput, addLiquidityOutput, txInput.slippage, + 2, + sendNativeAsset, ); }); }); diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index 2d3b66e8..2361b7ff 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -126,14 +126,15 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -141,6 +142,8 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -178,14 +181,15 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, amountOut, - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactOut( txInput.client.chain?.id as number, @@ -193,6 +197,8 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -230,13 +236,14 @@ describe('composable stable remove liquidity test', () => { }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactIn( @@ -245,6 +252,8 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -279,13 +288,14 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, - sendNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -293,6 +303,8 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); diff --git a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts index 832a1d79..e9bc900f 100644 --- a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts @@ -98,6 +98,7 @@ describe('composable stable remove liquidity test', () => { txInput.slippage, ); }); + // TODO: with native asset }); }); diff --git a/test/v2/removeLiquidity/gyroEV2.integration.test.ts b/test/v2/removeLiquidity/gyroEV2.integration.test.ts index ebcd51f6..f91e4cc0 100644 --- a/test/v2/removeLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/removeLiquidity/gyroEV2.integration.test.ts @@ -113,13 +113,14 @@ describe('GyroE V2 remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, - sendNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -127,6 +128,8 @@ describe('GyroE V2 remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index ac9efbea..5ea7926b 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -118,14 +118,15 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -133,6 +134,8 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -170,14 +173,15 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, amountOut, - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactOut( txInput.client.chain?.id as number, @@ -185,6 +189,8 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -222,13 +228,14 @@ describe('weighted remove liquidity test', () => { }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactIn( @@ -237,6 +244,8 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); @@ -271,13 +280,14 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { + const receiveNativeAsset = true; const removeLiquidityInput = { ...input, - receiveNativeAsset: true, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, + receiveNativeAsset, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -285,6 +295,8 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, + 2, + receiveNativeAsset, ); }); }); diff --git a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts index bbbacc2c..4f28617a 100644 --- a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts @@ -103,6 +103,7 @@ describe('weighted remove liquidity recovery test', () => { txInput.slippage, ); }); + // TODO: with native asset }); }); diff --git a/test/v3/addLiquidity.integration.test.ts b/test/v3/addLiquidity.integration.test.ts index f5826adf..70ac2705 100644 --- a/test/v3/addLiquidity.integration.test.ts +++ b/test/v3/addLiquidity.integration.test.ts @@ -81,7 +81,7 @@ describe('add liquidity test', () => { txInput.client, txInput.testAddress, [...txInput.poolState.tokens.map((t) => t.address)], - [WETH.slot, BAL.slot], + [WETH.slot, BAL.slot] as number[], [ ...txInput.poolState.tokens.map((t) => parseUnits('100', t.decimals), @@ -127,14 +127,15 @@ describe('add liquidity test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, amountsIn, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -143,6 +144,7 @@ describe('add liquidity test', () => { addLiquidityOutput, txInput.slippage, vaultVersion, + sendNativeAsset, ); }); }); @@ -181,13 +183,14 @@ describe('add liquidity test', () => { }); test('with native', async () => { + const sendNativeAsset = true; const addLiquidityInput = { ...input, - sendNativeAsset: true, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, + sendNativeAsset, }); assertAddLiquiditySingleToken( @@ -197,6 +200,7 @@ describe('add liquidity test', () => { addLiquidityOutput, txInput.slippage, vaultVersion, + sendNativeAsset, ); }); }); diff --git a/test/v3/removeLiquidity.integration.test.ts b/test/v3/removeLiquidity.integration.test.ts index 0f770932..846cb919 100644 --- a/test/v3/removeLiquidity.integration.test.ts +++ b/test/v3/removeLiquidity.integration.test.ts @@ -183,22 +183,21 @@ describe('remove liquidity test', () => { }); test('with native', async () => { - const removeLiquidityInput = { - ...input, - receiveNativeAsset: true, - }; + const receiveNativeAsset = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, - removeLiquidityInput, + removeLiquidityInput: input, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactOut( txInput.client.chain?.id as number, txInput.poolState, - removeLiquidityInput, + input, removeLiquidityOutput, txInput.slippage, vaultVersion, + receiveNativeAsset, ); }); }); @@ -237,22 +236,21 @@ describe('remove liquidity test', () => { }); test('with native', async () => { - const removeLiquidityInput = { - ...input, - receiveNativeAsset: true, - }; + const receiveNativeAsset = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, - removeLiquidityInput, + removeLiquidityInput: input, + receiveNativeAsset, }); assertRemoveLiquiditySingleTokenExactIn( txInput.client.chain?.id as number, txInput.poolState, - removeLiquidityInput, + input, removeLiquidityOutput, txInput.slippage, vaultVersion, + receiveNativeAsset, ); }); }); @@ -288,21 +286,20 @@ describe('remove liquidity test', () => { ); }); test('with native', async () => { - const removeLiquidityInput = { - ...input, - receiveNativeAsset: true, - }; + const receiveNativeAsset = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, - removeLiquidityInput, + removeLiquidityInput: input, + receiveNativeAsset, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, txInput.poolState, - removeLiquidityInput, + input, removeLiquidityOutput, txInput.slippage, vaultVersion, + receiveNativeAsset, ); }); }); From b92b77d6248fd260df34b5fbeeda2858f4e9f2a4 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 09:21:59 -0300 Subject: [PATCH 03/29] Fix lint issues --- test/lib/utils/addLiquidityHelper.ts | 4 ---- test/lib/utils/removeLiquidityHelper.ts | 7 ------- .../removeLiquidity/composableStable.integration.test.ts | 1 - test/v2/removeLiquidity/weighted.integration.test.ts | 1 - 4 files changed, 13 deletions(-) diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 02bc6643..9470fb0a 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -208,7 +208,6 @@ export function assertAddLiquidityUnbalanced( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - vaultVersion, sendNativeAsset, ); } @@ -284,7 +283,6 @@ export function assertAddLiquiditySingleToken( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - vaultVersion, sendNativeAsset, ); } @@ -356,7 +354,6 @@ export function assertAddLiquidityProportional( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - vaultVersion, sendNativeAsset, ); } @@ -367,7 +364,6 @@ function assertTokenDeltas( addLiquidityQueryOutput: AddLiquidityQueryOutput, addLiquidityBuildOutput: AddLiquidityBuildOutput, txOutput: TxOutput, - vaultVersion: 2 | 3 = 2, sendNativeAsset?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 1015762c..65460079 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -149,7 +149,6 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput: RemoveLiquidityUnbalancedInput, removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, - vaultVersion: 2 | 3 = 2, receiveNativeAsset?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = @@ -201,7 +200,6 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - vaultVersion, receiveNativeAsset, ); } @@ -271,7 +269,6 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - vaultVersion, receiveNativeAsset, ); } @@ -352,7 +349,6 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - vaultVersion, receiveNativeAsset, ); } @@ -423,7 +419,6 @@ export function assertRemoveLiquidityProportional( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - vaultVersion, receiveNativeAsset, ); } @@ -494,7 +489,6 @@ export function assertRemoveLiquidityRecovery( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - vaultVersion, receiveNativeAsset, ); } @@ -504,7 +498,6 @@ function assertTokenDeltas( removeLiquidityInput: RemoveLiquidityInput, removeLiquidityQueryOutput: RemoveLiquidityQueryOutput, txOutput: TxOutput, - vaultVersion: 2 | 3 = 2, receiveNativeAsset?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index 2361b7ff..bb2abb41 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -142,7 +142,6 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, - 2, receiveNativeAsset, ); }); diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index 5ea7926b..880004f9 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -134,7 +134,6 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, - 2, receiveNativeAsset, ); }); From c0718500fa6ec4e28c789adbe9616041b08802d5 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 09:40:55 -0300 Subject: [PATCH 04/29] Add changeset --- .changeset/hungry-seahorses-rest.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-seahorses-rest.md diff --git a/.changeset/hungry-seahorses-rest.md b/.changeset/hungry-seahorses-rest.md new file mode 100644 index 00000000..41f1f262 --- /dev/null +++ b/.changeset/hungry-seahorses-rest.md @@ -0,0 +1,5 @@ +--- +"@balancer/sdk": minor +--- + +Refactor wethIsEth into sendNativeAsset and receiveNativeAsset From 071fa2b3d7d0a02bc3d95fb42483ab522a4299b5 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 10:35:01 -0300 Subject: [PATCH 05/29] Update useNativeAssetAsWrappedAmountOut to receiveNativeAsset --- .../removeLiquidityNested/encodeCalls.ts | 4 +- .../getQueryCallsAttributes.ts | 7 ---- src/entities/removeLiquidityNested/index.ts | 18 ++++++--- src/entities/removeLiquidityNested/types.ts | 5 ++- .../removeLiquidityNested/validateInputs.ts | 38 ++++++------------- .../removeLiquidityNested.integration.test.ts | 22 +++++------ 6 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/entities/removeLiquidityNested/encodeCalls.ts b/src/entities/removeLiquidityNested/encodeCalls.ts index 857036aa..fd898a19 100644 --- a/src/entities/removeLiquidityNested/encodeCalls.ts +++ b/src/entities/removeLiquidityNested/encodeCalls.ts @@ -14,7 +14,7 @@ export const encodeCalls = ( const encodedCalls: Hex[] = []; for (const callAttributes of callsAttributes) { const { - useNativeAssetAsWrappedAmountOut, + receiveNativeAsset, chainId, sortedTokens, poolId, @@ -31,7 +31,7 @@ export const encodeCalls = ( // replace wrapped token with native asset if needed let tokensOut = [...sortedTokens]; - if (useNativeAssetAsWrappedAmountOut) { + if (receiveNativeAsset) { tokensOut = replaceWrapped([...sortedTokens], chainId); } diff --git a/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts b/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts index 265ed547..f85db79d 100644 --- a/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts +++ b/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts @@ -24,7 +24,6 @@ export const getQueryCallsAttributes = ( bptAmountIn, chainId, accountAddress, - useNativeAssetAsWrappedAmountOut = false, toInternalBalance = false, } = input; let callsAttributes: RemoveLiquidityNestedCallAttributes[]; @@ -36,7 +35,6 @@ export const getQueryCallsAttributes = ( callsAttributes = getProportionalCallsAttributes( poolsTopDown, chainId, - useNativeAssetAsWrappedAmountOut, accountAddress, bptAmountIn, toInternalBalance, @@ -47,7 +45,6 @@ export const getQueryCallsAttributes = ( callsAttributes = getSingleTokenCallsAttributes( poolsTopDown, chainId, - useNativeAssetAsWrappedAmountOut, accountAddress, bptAmountIn, toInternalBalance, @@ -63,7 +60,6 @@ export const getQueryCallsAttributes = ( const getProportionalCallsAttributes = ( poolsSortedByLevel: NestedPool[], chainId: ChainId, - useNativeAssetAsWrappedAmountOut: boolean, accountAddress: Address, bptAmountIn: bigint, toInternalBalance: boolean, @@ -86,7 +82,6 @@ const getProportionalCallsAttributes = ( ); calls.push({ chainId: chainId, - useNativeAssetAsWrappedAmountOut, sortedTokens, poolId: pool.id, poolAddress: pool.address, @@ -122,7 +117,6 @@ const getProportionalCallsAttributes = ( const getSingleTokenCallsAttributes = ( poolsTopDown: NestedPool[], chainId: ChainId, - useNativeAssetAsWrappedAmountOut: boolean, accountAddress: Address, bptAmountIn: bigint, toInternalBalance: boolean, @@ -156,7 +150,6 @@ const getSingleTokenCallsAttributes = ( ); calls.push({ chainId: chainId, - useNativeAssetAsWrappedAmountOut, sortedTokens, poolId: pool.id, poolAddress: pool.address, diff --git a/src/entities/removeLiquidityNested/index.ts b/src/entities/removeLiquidityNested/index.ts index cda73225..f31f16c2 100644 --- a/src/entities/removeLiquidityNested/index.ts +++ b/src/entities/removeLiquidityNested/index.ts @@ -15,7 +15,7 @@ import { doRemoveLiquidityNestedQuery } from './doRemoveLiquidityNestedQuery'; import { getQueryCallsAttributes } from './getQueryCallsAttributes'; import { encodeCalls } from './encodeCalls'; import { getPeekCalls } from './getPeekCalls'; -import { validateInputs } from './validateInputs'; +import { validateQueryInput, validateBuildCallInput } from './validateInputs'; import { validateNestedPoolState } from '../utils'; export class RemoveLiquidityNested { @@ -25,7 +25,7 @@ export class RemoveLiquidityNested { | RemoveLiquidityNestedSingleTokenInput, nestedPoolState: NestedPoolState, ): Promise { - const isProportional = validateInputs(input, nestedPoolState); + const isProportional = validateQueryInput(input, nestedPoolState); validateNestedPoolState(nestedPoolState); const { callsAttributes, bptAmountIn } = getQueryCallsAttributes( @@ -58,13 +58,17 @@ export class RemoveLiquidityNested { tokensOut.length, ); - console.log('peekedValues ', peekedValues); - const amountsOut = tokensOut.map((tokenOut, i) => TokenAmount.fromRawAmount(tokenOut, peekedValues[i]), ); - return { callsAttributes, bptAmountIn, amountsOut, isProportional }; + return { + callsAttributes, + bptAmountIn, + amountsOut, + isProportional, + chainId: input.chainId, + }; } buildCall(input: RemoveLiquidityNestedCallInput): { @@ -72,6 +76,8 @@ export class RemoveLiquidityNested { to: Address; minAmountsOut: TokenAmount[]; } { + validateBuildCallInput(input); + // apply slippage to amountsOut const minAmountsOut = input.amountsOut.map((amountOut) => TokenAmount.fromRawAmount( @@ -91,6 +97,8 @@ export class RemoveLiquidityNested { minAmountsOut[j].amount; } }); + // update receiveNativeAsset flag + call.receiveNativeAsset = !!input.receiveNativeAsset; }); const encodedCalls = encodeCalls( diff --git a/src/entities/removeLiquidityNested/types.ts b/src/entities/removeLiquidityNested/types.ts index 59c7f791..97b38934 100644 --- a/src/entities/removeLiquidityNested/types.ts +++ b/src/entities/removeLiquidityNested/types.ts @@ -10,7 +10,6 @@ export type RemoveLiquidityNestedProportionalInput = { chainId: ChainId; rpcUrl: string; accountAddress: Address; - useNativeAssetAsWrappedAmountOut?: boolean; toInternalBalance?: boolean; }; @@ -21,7 +20,6 @@ export type RemoveLiquidityNestedSingleTokenInput = export type RemoveLiquidityNestedCallAttributes = { chainId: ChainId; - useNativeAssetAsWrappedAmountOut: boolean; sortedTokens: Token[]; poolId: Address; poolAddress: Address; @@ -40,6 +38,7 @@ export type RemoveLiquidityNestedCallAttributes = { index: bigint; }[]; tokenOutIndex?: number; + receiveNativeAsset?: boolean; }; export type RemoveLiquidityNestedQueryOutput = { @@ -47,6 +46,7 @@ export type RemoveLiquidityNestedQueryOutput = { bptAmountIn: TokenAmount; amountsOut: TokenAmount[]; isProportional: boolean; + chainId: ChainId; }; export type RemoveLiquidityNestedCallInput = @@ -55,4 +55,5 @@ export type RemoveLiquidityNestedCallInput = sender: Address; recipient: Address; relayerApprovalSignature?: Hex; + receiveNativeAsset?: boolean; }; diff --git a/src/entities/removeLiquidityNested/validateInputs.ts b/src/entities/removeLiquidityNested/validateInputs.ts index 59bb6f6e..5e2c640c 100644 --- a/src/entities/removeLiquidityNested/validateInputs.ts +++ b/src/entities/removeLiquidityNested/validateInputs.ts @@ -2,11 +2,12 @@ import { NATIVE_ASSETS } from '../../utils'; import { Token } from '../token'; import { NestedPoolState } from '../types'; import { + RemoveLiquidityNestedCallInput, RemoveLiquidityNestedProportionalInput, RemoveLiquidityNestedSingleTokenInput, } from './types'; -export const validateInputs = ( +export const validateQueryInput = ( input: | RemoveLiquidityNestedProportionalInput | RemoveLiquidityNestedSingleTokenInput, @@ -17,12 +18,7 @@ export const validateInputs = ( const mainTokens = nestedPoolState.mainTokens.map( (token) => new Token(input.chainId, token.address, token.decimals), ); - if (isProportional) { - validateInputsProportional( - input as RemoveLiquidityNestedProportionalInput, - mainTokens, - ); - } else { + if (!isProportional) { validateInputsSingleToken( input as RemoveLiquidityNestedSingleTokenInput, mainTokens, @@ -32,22 +28,6 @@ export const validateInputs = ( return isProportional; }; -const validateInputsProportional = ( - input: RemoveLiquidityNestedProportionalInput, - mainTokens: Token[], -) => { - if ( - input.useNativeAssetAsWrappedAmountOut && - !mainTokens.some((t) => - t.isUnderlyingEqual(NATIVE_ASSETS[input.chainId]), - ) - ) { - throw new Error( - 'Removing liquidity to native asset requires wrapped native asset to exist within main tokens', - ); - } -}; - const validateInputsSingleToken = ( input: RemoveLiquidityNestedSingleTokenInput, mainTokens: Token[], @@ -59,13 +39,19 @@ const validateInputsSingleToken = ( `Removing liquidity to ${input.tokenOut} requires it to exist within main tokens`, ); } +}; +export const validateBuildCallInput = ( + input: RemoveLiquidityNestedCallInput, +) => { if ( - input.useNativeAssetAsWrappedAmountOut && - !tokenOut.isUnderlyingEqual(NATIVE_ASSETS[input.chainId]) + input.receiveNativeAsset && + !input.amountsOut.some((a) => + a.token.isSameAddress(NATIVE_ASSETS[input.chainId].wrapped), + ) ) { throw new Error( - 'Removing liquidity to native asset requires wrapped native asset to be the tokenOut', + 'Removing liquidity to native asset requires wrapped native asset to exist within amounts out', ); } }; diff --git a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts index 66c11b86..2ac7a2ce 100644 --- a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts +++ b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts @@ -43,7 +43,7 @@ type TxInput = { testAddress: Address; client: Client & PublicActions & TestActions & WalletActions; tokenOut?: Address; - useNativeAssetAsWrappedAmountOut?: boolean; + receiveNativeAsset?: boolean; }; describe('remove liquidity nested test', () => { @@ -113,7 +113,7 @@ describe('remove liquidity nested test', () => { test('proportional - native asset', async () => { const amountIn = parseUnits('1', 18); - const useNativeAssetAsWrappedAmountOut = true; + const receiveNativeAsset = true; const { transactionReceipt, @@ -129,7 +129,7 @@ describe('remove liquidity nested test', () => { rpcUrl, testAddress, client, - useNativeAssetAsWrappedAmountOut, + receiveNativeAsset, }); assertResults( @@ -176,7 +176,7 @@ describe('remove liquidity nested test', () => { test('single token - native asset', async () => { const amountIn = parseUnits('1', 18); const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH - const useNativeAssetAsWrappedAmountOut = true; + const receiveNativeAsset = true; const { transactionReceipt, @@ -193,7 +193,7 @@ describe('remove liquidity nested test', () => { testAddress, client, tokenOut, - useNativeAssetAsWrappedAmountOut, + receiveNativeAsset, }); assertResults( @@ -209,7 +209,7 @@ describe('remove liquidity nested test', () => { test('single token - native asset - invalid input', async () => { const amountIn = parseUnits('1', 18); const tokenOut = '0x6b175474e89094c44da98b954eedeac495271d0f'; // DAI - const useNativeAssetAsWrappedAmountOut = true; + const receiveNativeAsset = true; await expect( doTransaction({ @@ -220,10 +220,10 @@ describe('remove liquidity nested test', () => { testAddress, client, tokenOut, - useNativeAssetAsWrappedAmountOut, + receiveNativeAsset, }), ).rejects.toThrow( - 'Removing liquidity to native asset requires wrapped native asset to be the tokenOut', + 'Removing liquidity to native asset requires wrapped native asset to exist within amounts out', ); }); }); @@ -236,7 +236,7 @@ export const doTransaction = async ({ testAddress, client, tokenOut, - useNativeAssetAsWrappedAmountOut = false, + receiveNativeAsset = false, }: TxInput) => { // setup mock api const api = new MockApi(); @@ -252,7 +252,6 @@ export const doTransaction = async ({ chainId, rpcUrl, accountAddress: testAddress, - useNativeAssetAsWrappedAmountOut, tokenOut, }; const queryOutput = await removeLiquidityNested.query( @@ -275,10 +274,11 @@ export const doTransaction = async ({ sender: testAddress, recipient: testAddress, relayerApprovalSignature: signature, + receiveNativeAsset, }); let tokensOut = minAmountsOut.map((a) => a.token); - if (useNativeAssetAsWrappedAmountOut) { + if (receiveNativeAsset) { tokensOut = replaceWrapped(tokensOut, chainId); } From 4ec3fe055e925314c02829922e633f5316ecca1e Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 11:34:23 -0300 Subject: [PATCH 06/29] Add tests to remove liquidity recovery to native asset --- test/lib/utils/addresses.ts | 18 +++-- test/lib/utils/index.ts | 12 +++ ...posableStable.recovery.integration.test.ts | 73 +++++++++++++------ .../weighted.recovery.integration.test.ts | 58 ++++++++++----- 4 files changed, 113 insertions(+), 48 deletions(-) create mode 100644 test/lib/utils/index.ts diff --git a/test/lib/utils/addresses.ts b/test/lib/utils/addresses.ts index b229a735..6c09d3a0 100644 --- a/test/lib/utils/addresses.ts +++ b/test/lib/utils/addresses.ts @@ -56,6 +56,10 @@ export const TOKENS: Record> = { }, }, [ChainId.POLYGON]: { + DAI: { + address: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063', + decimals: 18, + }, USDC: { address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', decimals: 6, @@ -105,13 +109,6 @@ export const POOLS: Record> = { decimals: 18, slot: 0, }, - '50bb_sDAI_50bb_a_USDC': { - id: '0x0da692ac0611397027c91e559cfd482c4197e4030002000000000000000005c9', - address: '0x0da692ac0611397027c91e559cfd482c4197e403', - type: PoolType.Weighted, - decimals: 18, - slot: 0, - }, wstETH_rETH_sfrxETH: { id: '0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b', address: '0x42ed016f826165c2e5976fe5bc3df540c5ad0af7', @@ -128,6 +125,13 @@ export const POOLS: Record> = { decimals: 18, slot: 0, }, + DAI_WMATIC: { + id: '0x9d75cc71555ddabcb89b52c818c2c689e2191401000200000000000000000762', + address: '0x9d75cc71555ddabcb89b52c818c2c689e2191401', + type: PoolType.Weighted, + decimals: 18, + slot: 0, + }, }, [ChainId.SEPOLIA]: { MOCK_WEIGHTED_POOL: { diff --git a/test/lib/utils/index.ts b/test/lib/utils/index.ts new file mode 100644 index 00000000..1e57c79d --- /dev/null +++ b/test/lib/utils/index.ts @@ -0,0 +1,12 @@ +export * from './addLiquidityHelper'; +export * from './addLiquidityNestedHelper'; +export * from './addresses'; +export * from './createPoolHelper'; +export * from './findEventInReceiptLogs'; +export * from './getTokensForBalanceCheck'; +export * from './helper'; +export * from './initPoolHelper'; +export * from './promises'; +export * from './relayerHelper'; +export * from './removeLiquidityHelper'; +export * from './swapHelpers'; diff --git a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts index e9bc900f..b4631f62 100644 --- a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts @@ -1,14 +1,5 @@ -import { - PoolState, - RemoveLiquidity, - RemoveLiquidityInput, - RemoveLiquidityKind, - RemoveLiquidityRecoveryInput, - Slippage, -} from '@/entities'; -import { CHAINS, ChainId } from '@/utils'; -import { forkSetup } from 'test/lib/utils/helper'; -import { RemoveLiquidityTxInput } from 'test/lib/utils/types'; +// pnpm test -- composableStable.recovery.integration.test.ts + import { Hex, createTestClient, @@ -18,14 +9,28 @@ import { publicActions, walletActions, } from 'viem'; + +import { + CHAINS, + ChainId, + InputAmount, + PoolState, + RemoveLiquidity, + RemoveLiquidityInput, + RemoveLiquidityKind, + RemoveLiquidityRecoveryInput, + Slippage, +} from 'src'; + import { startFork, ANVIL_NETWORKS } from 'test/anvil/anvil-global-setup'; -import { InputAmount } from '@/types'; import { - doRemoveLiquidity, assertRemoveLiquidityRecovery, -} from 'test/lib/utils/removeLiquidityHelper'; -import { test } from 'vitest'; -import { POOLS, TOKENS } from 'test/lib/utils/addresses'; + doRemoveLiquidity, + forkSetup, + POOLS, + TOKENS, +} from 'test/lib/utils'; +import { RemoveLiquidityTxInput } from 'test/lib/utils/types'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); @@ -34,13 +39,13 @@ const testPool = POOLS[chainId].vETH_WETH; describe('composable stable remove liquidity test', () => { let txInput: RemoveLiquidityTxInput; - let poolInput: PoolState; + let poolState: PoolState; beforeAll(async () => { // setup mock api const api = new MockApi(); // get pool state from api - poolInput = await api.getPool(testPool.id); + poolState = await api.getPool(testPool.id); const client = createTestClient({ mode: 'anvil', @@ -50,12 +55,14 @@ describe('composable stable remove liquidity test', () => { .extend(publicActions) .extend(walletActions); + const testAddress = (await client.getAddresses())[0]; + txInput = { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% - poolState: poolInput, - testAddress: '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f', // Balancer DAO Multisig + poolState, + testAddress, removeLiquidityInput: {} as RemoveLiquidityInput, }; }); @@ -64,18 +71,19 @@ describe('composable stable remove liquidity test', () => { await forkSetup( txInput.client, txInput.testAddress, - [txInput.poolState.address], + [testPool.address], [testPool.slot as number], [parseUnits('1000', 18)], ); }); + describe('remove liquidity recovery', () => { let input: RemoveLiquidityRecoveryInput; beforeAll(() => { const bptIn: InputAmount = { - rawAmount: parseEther('1'), + rawAmount: parseEther('0.1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; input = { bptIn, @@ -98,7 +106,24 @@ describe('composable stable remove liquidity test', () => { txInput.slippage, ); }); - // TODO: with native asset + test('with native', async () => { + const receiveNativeAsset = true; + const removeLiquidityOutput = await doRemoveLiquidity({ + ...txInput, + removeLiquidityInput: input, + receiveNativeAsset, + }); + + assertRemoveLiquidityRecovery( + txInput.client.chain?.id as number, + txInput.poolState, + input, + removeLiquidityOutput, + txInput.slippage, + 2, + receiveNativeAsset, + ); + }); }); }); diff --git a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts index 4f28617a..d8679ea2 100644 --- a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts @@ -1,4 +1,4 @@ -// pnpm test -- removeLiquidity/weighted.integration.test.ts +// pnpm test -- removeLiquidity/weighted.recovery.integration.test.ts import dotenv from 'dotenv'; dotenv.config(); @@ -10,6 +10,7 @@ import { publicActions, walletActions, } from 'viem'; + import { RemoveLiquidityKind, Slippage, @@ -21,21 +22,25 @@ import { RemoveLiquidityInput, InputAmount, RemoveLiquidityRecoveryInput, -} from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; +} from 'src'; + import { assertRemoveLiquidityRecovery, doRemoveLiquidity, -} from '../../lib/utils/removeLiquidityHelper'; -import { RemoveLiquidityTxInput } from '../../lib/utils/types'; -import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { POOLS, TOKENS } from 'test/lib/utils/addresses'; + forkSetup, + POOLS, + TOKENS, +} from 'test/lib/utils'; +import { RemoveLiquidityTxInput } from 'test/lib/utils/types'; +import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; + +const chainId = ChainId.POLYGON; +const { rpcUrl } = await startFork(ANVIL_NETWORKS[ChainId[chainId]]); -const chainId = ChainId.MAINNET; -const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); +const testPool = POOLS[chainId].DAI_WMATIC; +const DAI = TOKENS[chainId].DAI; +const WMATIC = TOKENS[chainId].WMATIC; -const testPool = POOLS[chainId]['50bb_sDAI_50bb_a_USDC']; -const TOKENS_MAINNET = TOKENS[chainId]; describe('weighted remove liquidity recovery test', () => { let txInput: RemoveLiquidityTxInput; let poolInput: PoolState; @@ -54,12 +59,14 @@ describe('weighted remove liquidity recovery test', () => { .extend(publicActions) .extend(walletActions); + const testAddress = (await client.getAddresses())[0]; + txInput = { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% poolState: poolInput, - testAddress: '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f', // Balancer DAO Multisig + testAddress, removeLiquidityInput: {} as RemoveLiquidityInput, }; }); @@ -103,7 +110,24 @@ describe('weighted remove liquidity recovery test', () => { txInput.slippage, ); }); - // TODO: with native asset + test('with native', async () => { + const receiveNativeAsset = true; + const removeLiquidityOutput = await doRemoveLiquidity({ + ...txInput, + removeLiquidityInput: input, + receiveNativeAsset, + }); + + assertRemoveLiquidityRecovery( + txInput.client.chain?.id as number, + txInput.poolState, + input, + removeLiquidityOutput, + txInput.slippage, + 2, + receiveNativeAsset, + ); + }); }); }); @@ -113,13 +137,13 @@ class MockApi { public async getPool(id: Hex): Promise { const tokens = [ { - address: TOKENS_MAINNET.bb_s_DAI.address, - decimals: TOKENS_MAINNET.bb_s_DAI.decimals, + address: WMATIC.address, + decimals: WMATIC.decimals, index: 0, }, { - address: TOKENS_MAINNET.bb_a_USDC.address, - decimals: TOKENS_MAINNET.bb_a_USDC.decimals, + address: DAI.address, + decimals: DAI.decimals, index: 1, }, ]; From 8d76cac37ff430dda3f6c1e009f644916d549ba7 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 14:39:28 -0300 Subject: [PATCH 07/29] Move accountAddress from query to buildCall input --- .../doAddLiquidityNestedQuery.ts | 7 ++-- .../getQueryCallsAttributes.ts | 19 +++++------ src/entities/addLiquidityNested/index.ts | 13 ++++++-- src/entities/addLiquidityNested/types.ts | 4 +-- .../doRemoveLiquidityNestedQuery.ts | 7 ++-- .../getQueryCallsAttributes.ts | 15 ++++----- src/entities/removeLiquidityNested/index.ts | 12 +++++-- src/entities/removeLiquidityNested/types.ts | 4 +-- test/lib/utils/addLiquidityNestedHelper.ts | 4 +-- test/lib/utils/index.ts | 1 + .../addLiquidityNested.integration.test.ts | 10 +++--- ...LiquidityNestedPolygon.integration.test.ts | 15 +++++---- ...posableStable.recovery.integration.test.ts | 2 +- .../weighted.recovery.integration.test.ts | 2 +- .../removeLiquidityNested.integration.test.ts | 32 +++++++++---------- 15 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts b/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts index 994fe55e..9a3ace79 100644 --- a/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts +++ b/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts @@ -4,14 +4,13 @@ import { decodeFunctionResult, http, } from 'viem'; -import { Address, Hex } from '../../types'; -import { BALANCER_RELAYER, CHAINS, ChainId } from '../../utils'; +import { Hex } from '../../types'; +import { BALANCER_RELAYER, CHAINS, ChainId, ZERO_ADDRESS } from '../../utils'; import { balancerRelayerAbi } from '../../abi'; export const doAddLiquidityNestedQuery = async ( chainId: ChainId, rpcUrl: string, - accountAddress: Address, encodedMulticall: Hex, ): Promise => { const client = createPublicClient({ @@ -20,7 +19,7 @@ export const doAddLiquidityNestedQuery = async ( }); const { data } = await client.call({ - account: accountAddress, + account: ZERO_ADDRESS, to: BALANCER_RELAYER[chainId], data: encodedMulticall, }); diff --git a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts index 938c383a..08949d4c 100644 --- a/src/entities/addLiquidityNested/getQueryCallsAttributes.ts +++ b/src/entities/addLiquidityNested/getQueryCallsAttributes.ts @@ -1,5 +1,10 @@ import { Token } from '../token'; -import { BALANCER_RELAYER, ChainId, getPoolAddress } from '../../utils'; +import { + BALANCER_RELAYER, + ChainId, + ZERO_ADDRESS, + getPoolAddress, +} from '../../utils'; import { AddLiquidityNestedInput, AddLiquidityNestedCallAttributes, @@ -9,12 +14,7 @@ import { Address, PoolType } from '../../types'; import { Relayer } from '../relayer'; export const getQueryCallsAttributes = ( - { - amountsIn, - chainId, - accountAddress, - fromInternalBalance, - }: AddLiquidityNestedInput, + { amountsIn, chainId, fromInternalBalance }: AddLiquidityNestedInput, pools: NestedPool[], ): AddLiquidityNestedCallAttributes[] => { /** @@ -25,6 +25,7 @@ export const getQueryCallsAttributes = ( */ const poolsSortedByLevel = pools.sort((a, b) => a.level - b.level); + const accountAddressPlaceholder = ZERO_ADDRESS; const calls: AddLiquidityNestedCallAttributes[] = []; for (const pool of poolsSortedByLevel) { @@ -45,7 +46,7 @@ export const getQueryCallsAttributes = ( pool.type === PoolType.ComposableStable ? PoolKind.COMPOSABLE_STABLE_V2 : PoolKind.WEIGHTED, - sender: getSender(maxAmountsIn, accountAddress, chainId), + sender: getSender(maxAmountsIn, accountAddressPlaceholder, chainId), recipient: '0x', // set as placeholder - will be updated after all calls are created maxAmountsIn, minBptOut: 0n, // limits set to zero for query calls @@ -55,7 +56,7 @@ export const getQueryCallsAttributes = ( ), }); } - updateRecipients(calls, accountAddress); + updateRecipients(calls, accountAddressPlaceholder); return calls; }; diff --git a/src/entities/addLiquidityNested/index.ts b/src/entities/addLiquidityNested/index.ts index 4c0f71e8..d6107f38 100644 --- a/src/entities/addLiquidityNested/index.ts +++ b/src/entities/addLiquidityNested/index.ts @@ -1,7 +1,7 @@ import { encodeFunctionData } from 'viem'; import { Address, Hex } from '../../types'; import { Token } from '../token'; -import { BALANCER_RELAYER } from '../../utils'; +import { BALANCER_RELAYER, ZERO_ADDRESS } from '../../utils'; import { Relayer } from '../relayer'; import { encodeCalls } from './encodeCalls'; import { TokenAmount } from '../tokenAmount'; @@ -47,7 +47,6 @@ export class AddLiquidityNested { const peekedValue = await doAddLiquidityNestedQuery( input.chainId, input.rpcUrl, - input.accountAddress, encodedMulticall, ); @@ -77,10 +76,18 @@ export class AddLiquidityNested { minBptOut, }; - // update sendNativeAsset flag + // update sendNativeAsset flag + sender and recipient placeholders input.callsAttributes = input.callsAttributes.map((call) => { return { ...call, + sender: + call.sender === ZERO_ADDRESS + ? input.accountAddress + : call.sender, + recipient: + call.recipient === ZERO_ADDRESS + ? input.accountAddress + : call.recipient, sendNativeAsset: input.sendNativeAsset, }; }); diff --git a/src/entities/addLiquidityNested/types.ts b/src/entities/addLiquidityNested/types.ts index 38e8f297..ad5b551e 100644 --- a/src/entities/addLiquidityNested/types.ts +++ b/src/entities/addLiquidityNested/types.ts @@ -9,7 +9,6 @@ export type AddLiquidityNestedInput = { amountsIn: InputAmount[]; chainId: ChainId; rpcUrl: string; - accountAddress: Address; fromInternalBalance?: boolean; }; @@ -40,8 +39,7 @@ export type AddLiquidityNestedQueryOutput = { export type AddLiquidityNestedCallInput = AddLiquidityNestedQueryOutput & { slippage: Slippage; - sender: Address; - recipient: Address; + accountAddress: Address; relayerApprovalSignature?: Hex; sendNativeAsset?: boolean; }; diff --git a/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts b/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts index 8b91cdc1..423dabcb 100644 --- a/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts +++ b/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts @@ -4,14 +4,13 @@ import { decodeFunctionResult, http, } from 'viem'; -import { Address, Hex } from '../../types'; -import { BALANCER_RELAYER, CHAINS, ChainId } from '../../utils'; +import { Hex } from '../../types'; +import { BALANCER_RELAYER, CHAINS, ChainId, ZERO_ADDRESS } from '../../utils'; import { balancerRelayerAbi } from '../../abi'; export const doRemoveLiquidityNestedQuery = async ( chainId: ChainId, rpcUrl: string, - accountAddress: Address, encodedMulticall: Hex, tokensOutLength: number, ): Promise => { @@ -21,7 +20,7 @@ export const doRemoveLiquidityNestedQuery = async ( }); const { data } = await client.call({ - account: accountAddress, + account: ZERO_ADDRESS, to: BALANCER_RELAYER[chainId], data: encodedMulticall, }); diff --git a/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts b/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts index f85db79d..23d06a69 100644 --- a/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts +++ b/src/entities/removeLiquidityNested/getQueryCallsAttributes.ts @@ -7,7 +7,7 @@ import { import { NestedPool, PoolKind } from '../types'; import { TokenAmount } from '../tokenAmount'; import { Address, PoolType } from '../../types'; -import { BALANCER_RELAYER, ChainId } from '../../utils'; +import { BALANCER_RELAYER, ChainId, ZERO_ADDRESS } from '../../utils'; import { Relayer } from '../relayer'; export const getQueryCallsAttributes = ( @@ -20,22 +20,19 @@ export const getQueryCallsAttributes = ( bptAmountIn: TokenAmount; callsAttributes: RemoveLiquidityNestedCallAttributes[]; } => { - const { - bptAmountIn, - chainId, - accountAddress, - toInternalBalance = false, - } = input; + const { bptAmountIn, chainId, toInternalBalance = false } = input; let callsAttributes: RemoveLiquidityNestedCallAttributes[]; // sort pools by descending level const poolsTopDown = pools.sort((a, b) => b.level - a.level); + const accountAddressPlaceholder = ZERO_ADDRESS; + if (isProportional) { callsAttributes = getProportionalCallsAttributes( poolsTopDown, chainId, - accountAddress, + accountAddressPlaceholder, bptAmountIn, toInternalBalance, ); @@ -45,7 +42,7 @@ export const getQueryCallsAttributes = ( callsAttributes = getSingleTokenCallsAttributes( poolsTopDown, chainId, - accountAddress, + accountAddressPlaceholder, bptAmountIn, toInternalBalance, tokenOut, diff --git a/src/entities/removeLiquidityNested/index.ts b/src/entities/removeLiquidityNested/index.ts index f31f16c2..e1599fe9 100644 --- a/src/entities/removeLiquidityNested/index.ts +++ b/src/entities/removeLiquidityNested/index.ts @@ -1,6 +1,6 @@ import { encodeFunctionData } from 'viem'; import { Address, Hex } from '../../types'; -import { BALANCER_RELAYER } from '../../utils'; +import { BALANCER_RELAYER, ZERO_ADDRESS } from '../../utils'; import { Relayer } from '../relayer'; import { TokenAmount } from '../tokenAmount'; import { balancerRelayerAbi } from '../../abi'; @@ -53,7 +53,6 @@ export class RemoveLiquidityNested { const peekedValues = await doRemoveLiquidityNestedQuery( input.chainId, input.rpcUrl, - input.accountAddress, encodedMulticall, tokensOut.length, ); @@ -99,6 +98,15 @@ export class RemoveLiquidityNested { }); // update receiveNativeAsset flag call.receiveNativeAsset = !!input.receiveNativeAsset; + // update sender and recipient placeholders + call.sender = + call.sender === ZERO_ADDRESS + ? input.accountAddress + : call.sender; + call.recipient = + call.recipient === ZERO_ADDRESS + ? input.accountAddress + : call.recipient; }); const encodedCalls = encodeCalls( diff --git a/src/entities/removeLiquidityNested/types.ts b/src/entities/removeLiquidityNested/types.ts index 97b38934..80b4e831 100644 --- a/src/entities/removeLiquidityNested/types.ts +++ b/src/entities/removeLiquidityNested/types.ts @@ -9,7 +9,6 @@ export type RemoveLiquidityNestedProportionalInput = { bptAmountIn: bigint; chainId: ChainId; rpcUrl: string; - accountAddress: Address; toInternalBalance?: boolean; }; @@ -52,8 +51,7 @@ export type RemoveLiquidityNestedQueryOutput = { export type RemoveLiquidityNestedCallInput = RemoveLiquidityNestedQueryOutput & { slippage: Slippage; - sender: Address; - recipient: Address; + accountAddress: Address; relayerApprovalSignature?: Hex; receiveNativeAsset?: boolean; }; diff --git a/test/lib/utils/addLiquidityNestedHelper.ts b/test/lib/utils/addLiquidityNestedHelper.ts index c9c0cda2..185205da 100644 --- a/test/lib/utils/addLiquidityNestedHelper.ts +++ b/test/lib/utils/addLiquidityNestedHelper.ts @@ -61,7 +61,6 @@ export const doAddLiquidityNested = async ({ amountsIn, chainId, rpcUrl, - accountAddress: testAddress, }; const queryOutput = await addLiquidityNested.query( addLiquidityInput, @@ -80,8 +79,7 @@ export const doAddLiquidityNested = async ({ const { call, to, value, minBptOut } = addLiquidityNested.buildCall({ ...queryOutput, slippage, - sender: testAddress, - recipient: testAddress, + accountAddress: testAddress, relayerApprovalSignature: signature, sendNativeAsset, }); diff --git a/test/lib/utils/index.ts b/test/lib/utils/index.ts index 1e57c79d..3fa86ea3 100644 --- a/test/lib/utils/index.ts +++ b/test/lib/utils/index.ts @@ -10,3 +10,4 @@ export * from './promises'; export * from './relayerHelper'; export * from './removeLiquidityHelper'; export * from './swapHelpers'; +export * from './types'; diff --git a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts index 988f639b..1e3b66ce 100644 --- a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts +++ b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts @@ -17,13 +17,15 @@ import { import { Address, CHAINS, ChainId, Hex, NestedPoolState } from 'src'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; -import { POOLS, TestToken, TOKENS } from 'test/lib/utils/addresses'; import { + AddLiquidityNestedTxInput, assertResults, doAddLiquidityNested, -} from 'test/lib/utils/addLiquidityNestedHelper'; -import { forkSetup } from 'test/lib/utils/helper'; -import { AddLiquidityNestedTxInput } from 'test/lib/utils/types'; + forkSetup, + POOLS, + TestToken, + TOKENS, +} from 'test/lib/utils'; const chainId = ChainId.MAINNET; const DAI = TOKENS[chainId].DAI; diff --git a/test/v2/addLiquidityNested/addLiquidityNestedPolygon.integration.test.ts b/test/v2/addLiquidityNested/addLiquidityNestedPolygon.integration.test.ts index e5bccb39..1c9e8a69 100644 --- a/test/v2/addLiquidityNested/addLiquidityNestedPolygon.integration.test.ts +++ b/test/v2/addLiquidityNested/addLiquidityNestedPolygon.integration.test.ts @@ -15,18 +15,18 @@ import { walletActions, } from 'viem'; -import { NestedPoolState } from '@/entities'; -import { Address, Hex, PoolType } from '@/types'; -import { CHAINS, ChainId } from '@/utils'; +import { Address, CHAINS, ChainId, Hex, PoolType, NestedPoolState } from 'src'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; -import { POOLS, TestToken, TOKENS } from 'test/lib/utils/addresses'; import { + AddLiquidityNestedTxInput, assertResults, doAddLiquidityNested, -} from 'test/lib/utils/addLiquidityNestedHelper'; -import { forkSetup } from 'test/lib/utils/helper'; -import { AddLiquidityNestedTxInput } from 'test/lib/utils/types'; + forkSetup, + POOLS, + TestToken, + TOKENS, +} from 'test/lib/utils'; const chainId = ChainId.POLYGON; const WMATIC = TOKENS[chainId].WMATIC; @@ -92,6 +92,7 @@ describe('add liquidity nested test', () => { { address: WMATIC.address, rawAmount: parseUnits('1', WMATIC.decimals), + decimals: WMATIC.decimals, }, ]; diff --git a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts index b4631f62..4c49ca88 100644 --- a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts @@ -28,9 +28,9 @@ import { doRemoveLiquidity, forkSetup, POOLS, + RemoveLiquidityTxInput, TOKENS, } from 'test/lib/utils'; -import { RemoveLiquidityTxInput } from 'test/lib/utils/types'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); diff --git a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts index d8679ea2..f21cef28 100644 --- a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts @@ -29,9 +29,9 @@ import { doRemoveLiquidity, forkSetup, POOLS, + RemoveLiquidityTxInput, TOKENS, } from 'test/lib/utils'; -import { RemoveLiquidityTxInput } from 'test/lib/utils/types'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; const chainId = ChainId.POLYGON; diff --git a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts index 2ac7a2ce..042076f0 100644 --- a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts +++ b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts @@ -1,5 +1,4 @@ // pnpm test -- removeLiquidityNested.integration.test.ts -import { describe, expect, test, beforeAll } from 'vitest'; import dotenv from 'dotenv'; dotenv.config(); @@ -17,23 +16,24 @@ import { } from 'viem'; import { - Slippage, + Address, + BALANCER_RELAYER, + ChainId, + CHAINS, + Hex, + NestedPoolState, + PoolType, + Relayer, RemoveLiquidityNested, + RemoveLiquidityNestedProportionalInput, + RemoveLiquidityNestedSingleTokenInput, replaceWrapped, - NestedPoolState, + Slippage, TokenAmount, -} from '../../../src/entities'; -import { Address, Hex, PoolType } from '../../../src/types'; +} from 'src'; -import { BALANCER_RELAYER, CHAINS, ChainId } from '../../../src/utils'; - -import { forkSetup, sendTransactionGetBalances } from '../../lib/utils/helper'; -import { Relayer } from '../../../src/entities/relayer'; -import { - RemoveLiquidityNestedProportionalInput, - RemoveLiquidityNestedSingleTokenInput, -} from '../../../src/entities/removeLiquidityNested/types'; -import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; +import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; +import { forkSetup, sendTransactionGetBalances } from 'test/lib/utils'; type TxInput = { poolId: Hex; @@ -251,7 +251,6 @@ export const doTransaction = async ({ bptAmountIn: amountIn, chainId, rpcUrl, - accountAddress: testAddress, tokenOut, }; const queryOutput = await removeLiquidityNested.query( @@ -271,8 +270,7 @@ export const doTransaction = async ({ const { call, to, minAmountsOut } = removeLiquidityNested.buildCall({ ...queryOutput, slippage, - sender: testAddress, - recipient: testAddress, + accountAddress: testAddress, relayerApprovalSignature: signature, receiveNativeAsset, }); From 7bc308ac736e6869caf199ad874d8f08fd0a400b Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 14:40:57 -0300 Subject: [PATCH 08/29] Add changeset --- .changeset/mean-numbers-change.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/mean-numbers-change.md diff --git a/.changeset/mean-numbers-change.md b/.changeset/mean-numbers-change.md new file mode 100644 index 00000000..16075f1d --- /dev/null +++ b/.changeset/mean-numbers-change.md @@ -0,0 +1,5 @@ +--- +"@balancer/sdk": minor +--- + +Move accountAddress from query to buildCall input From 972610e67dcfa6fb269a936594260dfef622edc7 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 15:09:51 -0300 Subject: [PATCH 09/29] Add removeLiquidityNested example --- examples/addLiquidityNested.ts | 4 +- examples/removeLiquidityNested.ts | 183 ++++++++++++++++++++ src/entities/removeLiquidityNested/index.ts | 24 +-- src/entities/removeLiquidityNested/types.ts | 4 + 4 files changed, 200 insertions(+), 15 deletions(-) create mode 100644 examples/removeLiquidityNested.ts diff --git a/examples/addLiquidityNested.ts b/examples/addLiquidityNested.ts index 91d0bc9d..54a34406 100644 --- a/examples/addLiquidityNested.ts +++ b/examples/addLiquidityNested.ts @@ -66,7 +66,6 @@ const addLiquidityNested = async () => { amountsIn, chainId, rpcUrl, - accountAddress, }; // Calculate price impact to ensure it's acceptable @@ -102,8 +101,7 @@ const addLiquidityNested = async () => { const { call, to, value, minBptOut } = addLiquidityNested.buildCall({ ...queryOutput, slippage, - sender: accountAddress, - recipient: accountAddress, + accountAddress, relayerApprovalSignature: signature, sendNativeAsset, }); diff --git a/examples/removeLiquidityNested.ts b/examples/removeLiquidityNested.ts new file mode 100644 index 00000000..207ad9c4 --- /dev/null +++ b/examples/removeLiquidityNested.ts @@ -0,0 +1,183 @@ +/** + * Example showing how to remove liquidity to a pool. + * (Runs against a local Anvil fork) + * + * Run with: + * pnpm example ./examples/removeLiquidityNested.ts + */ + +import { config } from 'dotenv'; +config(); + +import { + Client, + createTestClient, + http, + parseUnits, + PublicActions, + publicActions, + TestActions, + WalletActions, + walletActions, +} from 'viem'; + +import { + Address, + BALANCER_RELAYER, + BalancerApi, + ChainId, + CHAINS, + NestedPoolState, + PriceImpact, + Relayer, + replaceWrapped, + Slippage, + RemoveLiquidityNested, + RemoveLiquidityNestedSingleTokenInput, +} from '../src'; +import { forkSetup, sendTransactionGetBalances } from '../test/lib/utils'; +import { ANVIL_NETWORKS, startFork } from '../test/anvil/anvil-global-setup'; + +const balancerApiUrl = 'https://backend-v3-canary.beets-ftm-node.com/graphql'; +const poolId = + '0x08775ccb6674d6bdceb0797c364c2653ed84f3840002000000000000000004f0'; // WETH-3POOL +const chainId = ChainId.MAINNET; + +const removeLiquidityNested = async () => { + // User approve vault to spend their tokens and update user balance + const { client, accountAddress, nestedPoolState, rpcUrl } = + await exampleSetup(); + + // setup remove liquidity helper + const removeLiquidityNested = new RemoveLiquidityNested(); + + const bptAmountIn = parseUnits('1', 18); + const tokenOut = '0x6b175474e89094c44da98b954eedeac495271d0f' as Address; // DAI + + const removeLiquidityInput: RemoveLiquidityNestedSingleTokenInput = { + bptAmountIn, + chainId, + rpcUrl, + tokenOut, + }; + + // Calculate price impact to ensure it's acceptable + const priceImpact = await PriceImpact.removeLiquidityNested( + removeLiquidityInput, + nestedPoolState, + ); + console.log(`\nPrice Impact: ${priceImpact.percentage.toFixed(2)}%`); + + const queryOutput = await removeLiquidityNested.query( + removeLiquidityInput, + nestedPoolState, + ); + + console.log('\nRemove Liquidity Query Output:'); + console.table({ + tokensOut: queryOutput.amountsOut.map((a) => a.token.address), + amountsOut: queryOutput.amountsOut.map((a) => a.amount), + }); + console.log(`BPT In: ${queryOutput.bptAmountIn.amount.toString()}`); + + // build remove liquidity nested call with expected minAmountsOut based on slippage + const slippage = Slippage.fromPercentage('1'); // 1% + + const signature = await Relayer.signRelayerApproval( + BALANCER_RELAYER[chainId], + accountAddress, + client, + ); + + const receiveNativeAsset = false; + + const { call, to, minAmountsOut } = removeLiquidityNested.buildCall({ + ...queryOutput, + slippage, + accountAddress, + relayerApprovalSignature: signature, + receiveNativeAsset, + }); + + let tokensOut = queryOutput.amountsOut.map((a) => a.token); + if (receiveNativeAsset) { + tokensOut = replaceWrapped(tokensOut, chainId); + } + + console.log('\nWith slippage applied:'); + console.table({ + tokensOut: minAmountsOut.map((a) => a.token.address), + minAmountsOut: minAmountsOut.map((a) => a.amount), + }); + + const tokens = [ + ...tokensOut.map((t) => t.address), + queryOutput.bptAmountIn.token.address, + ]; + + // send remove liquidity nested transaction and check balance changes + const { transactionReceipt, balanceDeltas } = + await sendTransactionGetBalances( + tokens, + client, + accountAddress, + to, + call, + ); + console.log(`\nTransaction status: ${transactionReceipt.status}`); + console.log('Token balance deltas:'); + console.table({ + tokens, + balanceDeltas, + }); +}; + +const exampleSetup = async (): Promise<{ + client: Client & PublicActions & TestActions & WalletActions; + accountAddress: Address; + nestedPoolState: NestedPoolState; + rpcUrl: string; +}> => { + const { rpcUrl } = await startFork(ANVIL_NETWORKS[ChainId[chainId]]); + const balancerApi = new BalancerApi(balancerApiUrl, chainId); + const nestedPoolState = + await balancerApi.nestedPools.fetchNestedPoolState(poolId); + + const client: Client & PublicActions & TestActions & WalletActions = + createTestClient({ + mode: 'anvil', + chain: CHAINS[chainId], + transport: http(rpcUrl), + }) + .extend(publicActions) + .extend(walletActions); + + const accountAddress = (await client.getAddresses())[0]; + + const rootPool = nestedPoolState.pools.sort((a, b) => b.level - a.level)[0]; + + const testTokens = [ + { + address: rootPool.address, + balance: parseUnits('1000', 18), + slot: 0, + }, + ]; + + await forkSetup( + client, + accountAddress, + testTokens.map((t) => t.address), + testTokens.map((t) => t.slot), + testTokens.map((t) => t.balance), + ); + + return { + client, + accountAddress, + nestedPoolState, + rpcUrl, + }; +}; + +export default removeLiquidityNested; diff --git a/src/entities/removeLiquidityNested/index.ts b/src/entities/removeLiquidityNested/index.ts index e1599fe9..50710747 100644 --- a/src/entities/removeLiquidityNested/index.ts +++ b/src/entities/removeLiquidityNested/index.ts @@ -1,28 +1,28 @@ import { encodeFunctionData } from 'viem'; + +import { balancerRelayerAbi } from '../../abi'; import { Address, Hex } from '../../types'; import { BALANCER_RELAYER, ZERO_ADDRESS } from '../../utils'; + import { Relayer } from '../relayer'; import { TokenAmount } from '../tokenAmount'; -import { balancerRelayerAbi } from '../../abi'; +import { NestedPoolState } from '../types'; +import { validateNestedPoolState } from '../utils'; + +import { encodeCalls } from './encodeCalls'; +import { doRemoveLiquidityNestedQuery } from './doRemoveLiquidityNestedQuery'; +import { getPeekCalls } from './getPeekCalls'; +import { getQueryCallsAttributes } from './getQueryCallsAttributes'; import { - RemoveLiquidityNestedProportionalInput, - RemoveLiquidityNestedSingleTokenInput, RemoveLiquidityNestedQueryOutput, RemoveLiquidityNestedCallInput, + RemoveLiquidityNestedInput, } from './types'; -import { NestedPoolState } from '../types'; -import { doRemoveLiquidityNestedQuery } from './doRemoveLiquidityNestedQuery'; -import { getQueryCallsAttributes } from './getQueryCallsAttributes'; -import { encodeCalls } from './encodeCalls'; -import { getPeekCalls } from './getPeekCalls'; import { validateQueryInput, validateBuildCallInput } from './validateInputs'; -import { validateNestedPoolState } from '../utils'; export class RemoveLiquidityNested { async query( - input: - | RemoveLiquidityNestedProportionalInput - | RemoveLiquidityNestedSingleTokenInput, + input: RemoveLiquidityNestedInput, nestedPoolState: NestedPoolState, ): Promise { const isProportional = validateQueryInput(input, nestedPoolState); diff --git a/src/entities/removeLiquidityNested/types.ts b/src/entities/removeLiquidityNested/types.ts index 80b4e831..f01f3b45 100644 --- a/src/entities/removeLiquidityNested/types.ts +++ b/src/entities/removeLiquidityNested/types.ts @@ -17,6 +17,10 @@ export type RemoveLiquidityNestedSingleTokenInput = tokenOut: Address; }; +export type RemoveLiquidityNestedInput = + | RemoveLiquidityNestedProportionalInput + | RemoveLiquidityNestedSingleTokenInput; + export type RemoveLiquidityNestedCallAttributes = { chainId: ChainId; sortedTokens: Token[]; From cfafa3c54402ef1e7fb0f0fee5cd23e241b2a6da Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 16:53:36 -0300 Subject: [PATCH 10/29] Refactor sender and recipient to exist on v2 only --- src/entities/addLiquidity/index.ts | 7 +++++++ src/entities/addLiquidity/types.ts | 20 ++++++++++++-------- src/entities/removeLiquidity/index.ts | 7 +++++++ src/entities/removeLiquidity/types.ts | 21 +++++++++++++-------- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/entities/addLiquidity/index.ts b/src/entities/addLiquidity/index.ts index 43592d06..c970201e 100644 --- a/src/entities/addLiquidity/index.ts +++ b/src/entities/addLiquidity/index.ts @@ -33,6 +33,13 @@ export class AddLiquidity implements AddLiquidityBase { } buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput { + // TODO: refactor validators to take v3 into account + const isV2Input = 'sender' in input; + if (input.vaultVersion === 3 && isV2Input) + throw Error('Cannot define sender/recipient in V3'); + if (input.vaultVersion === 2 && !isV2Input) + throw Error('Sender/recipient must be defined in V2'); + switch (input.vaultVersion) { case 2: { const addLiquidity = new AddLiquidityV2(this.config); diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 9cb44997..1e7d8bb1 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -48,28 +48,32 @@ export type AddLiquidityBaseQueryOutput = { vaultVersion: 2 | 3; }; -export type AddLiquidityWeightedQueryOutput = AddLiquidityBaseQueryOutput; - export type AddLiquidityComposableStableQueryOutput = AddLiquidityBaseQueryOutput & { bptIndex: number; }; +export type AddLiquidityWeightedQueryOutput = AddLiquidityBaseQueryOutput; + export type AddLiquidityQueryOutput = | AddLiquidityBaseQueryOutput - | AddLiquidityWeightedQueryOutput - | AddLiquidityComposableStableQueryOutput; + | AddLiquidityComposableStableQueryOutput + | AddLiquidityWeightedQueryOutput; export type AddLiquidityBaseCall = { slippage: Slippage; - sender: Address; - recipient: Address; chainId: number; sendNativeAsset?: boolean; } & AddLiquidityBaseQueryOutput; -export type AddLiquidityWeightedCall = AddLiquidityBaseCall; -export type AddLiquidityComposableStableCall = AddLiquidityBaseCall & +export type AddLiquidityBaseCallV2 = AddLiquidityBaseCall & { + sender: Address; + recipient: Address; +}; + +export type AddLiquidityWeightedCall = AddLiquidityBaseCallV2 & + AddLiquidityWeightedQueryOutput; +export type AddLiquidityComposableStableCall = AddLiquidityBaseCallV2 & AddLiquidityComposableStableQueryOutput; export type AddLiquidityCall = diff --git a/src/entities/removeLiquidity/index.ts b/src/entities/removeLiquidity/index.ts index 3efe99e6..eafc5400 100644 --- a/src/entities/removeLiquidity/index.ts +++ b/src/entities/removeLiquidity/index.ts @@ -34,6 +34,13 @@ export class RemoveLiquidity implements RemoveLiquidityBase { } public buildCall(input: RemoveLiquidityCall): RemoveLiquidityBuildOutput { + // TODO: refactor validators to take v3 into account + const isV2Input = 'sender' in input; + if (input.vaultVersion === 3 && isV2Input) + throw Error('Cannot define sender/recipient in V3'); + if (input.vaultVersion === 2 && !isV2Input) + throw Error('Sender/recipient must be defined in V2'); + switch (input.vaultVersion) { case 2: { const removeLiquidity = new RemoveLiquidityV2(this.config); diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index dc362748..93076046 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -53,10 +53,6 @@ export type RemoveLiquidityInput = | RemoveLiquidityProportionalInput | RemoveLiquidityRecoveryInput; -export type RemoveLiquidityQueryOutput = - | RemoveLiquidityBaseQueryOutput - | RemoveLiquidityComposableStableQueryOutput; - // Returned from a remove liquidity query export type RemoveLiquidityBaseQueryOutput = { poolType: string; @@ -74,18 +70,27 @@ export type RemoveLiquidityComposableStableQueryOutput = RemoveLiquidityBaseQueryOutput & { bptIndex: number; }; +export type RemoveLiquidityWeightedQueryOutput = RemoveLiquidityBaseQueryOutput; + +export type RemoveLiquidityQueryOutput = + | RemoveLiquidityBaseQueryOutput + | RemoveLiquidityComposableStableQueryOutput + | RemoveLiquidityWeightedQueryOutput; export type RemoveLiquidityBaseCall = { slippage: Slippage; - sender: Address; - recipient: Address; chainId: number; receiveNativeAsset?: boolean; } & RemoveLiquidityBaseQueryOutput; -export type RemoveLiquidityWeightedCall = RemoveLiquidityBaseCall; -export type RemoveLiquidityComposableStableCall = RemoveLiquidityBaseCall & +export type RemoveLiquidityBaseCallV2 = RemoveLiquidityBaseCall & { + sender: Address; + recipient: Address; +}; + +export type RemoveLiquidityComposableStableCall = RemoveLiquidityBaseCallV2 & RemoveLiquidityComposableStableQueryOutput; +export type RemoveLiquidityWeightedCall = RemoveLiquidityBaseCallV2; export type RemoveLiquidityCall = | RemoveLiquidityBaseCall From 8825f0a7eae7398d6b5917a31402e81ad423ae32 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 6 Mar 2024 16:54:18 -0300 Subject: [PATCH 11/29] Add changeset --- .changeset/few-planets-rush.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/few-planets-rush.md diff --git a/.changeset/few-planets-rush.md b/.changeset/few-planets-rush.md new file mode 100644 index 00000000..4400c507 --- /dev/null +++ b/.changeset/few-planets-rush.md @@ -0,0 +1,5 @@ +--- +"@balancer/sdk": patch +--- + +Refactor sender and recipient to exist on v2 only From 8f0a11881b9222ca097504adf2c1f0f716ccc717 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 7 Mar 2024 13:16:31 -0300 Subject: [PATCH 12/29] Remove accountAddress from add/remove nested query --- src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts | 3 +-- src/entities/priceImpact/index.ts | 1 - .../removeLiquidityNested/doRemoveLiquidityNestedQuery.ts | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts b/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts index 9a3ace79..063a1e70 100644 --- a/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts +++ b/src/entities/addLiquidityNested/doAddLiquidityNestedQuery.ts @@ -5,7 +5,7 @@ import { http, } from 'viem'; import { Hex } from '../../types'; -import { BALANCER_RELAYER, CHAINS, ChainId, ZERO_ADDRESS } from '../../utils'; +import { BALANCER_RELAYER, CHAINS, ChainId } from '../../utils'; import { balancerRelayerAbi } from '../../abi'; export const doAddLiquidityNestedQuery = async ( @@ -19,7 +19,6 @@ export const doAddLiquidityNestedQuery = async ( }); const { data } = await client.call({ - account: ZERO_ADDRESS, to: BALANCER_RELAYER[chainId], data: encodedMulticall, }); diff --git a/src/entities/priceImpact/index.ts b/src/entities/priceImpact/index.ts index 734965d2..edfa1988 100644 --- a/src/entities/priceImpact/index.ts +++ b/src/entities/priceImpact/index.ts @@ -368,7 +368,6 @@ export class PriceImpact { // simulate adding liquidity to get amounts in const addLiquidityNested = new AddLiquidityNested(); const addLiquidityNestedInput: AddLiquidityNestedInput = { - accountAddress: input.accountAddress, chainId: input.chainId, rpcUrl: input.rpcUrl, fromInternalBalance: input.toInternalBalance, diff --git a/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts b/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts index 423dabcb..ef054a4d 100644 --- a/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts +++ b/src/entities/removeLiquidityNested/doRemoveLiquidityNestedQuery.ts @@ -5,7 +5,7 @@ import { http, } from 'viem'; import { Hex } from '../../types'; -import { BALANCER_RELAYER, CHAINS, ChainId, ZERO_ADDRESS } from '../../utils'; +import { BALANCER_RELAYER, CHAINS, ChainId } from '../../utils'; import { balancerRelayerAbi } from '../../abi'; export const doRemoveLiquidityNestedQuery = async ( @@ -20,7 +20,6 @@ export const doRemoveLiquidityNestedQuery = async ( }); const { data } = await client.call({ - account: ZERO_ADDRESS, to: BALANCER_RELAYER[chainId], data: encodedMulticall, }); From 8772e5ff793e34ff506369111f6b7a1fbd36f84c Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Thu, 7 Mar 2024 14:36:46 -0300 Subject: [PATCH 13/29] Fix add/remove liquidity helper for v3 tests --- test/lib/utils/addLiquidityHelper.ts | 48 +++++++++++++++--------- test/lib/utils/removeLiquidityHelper.ts | 50 +++++++++++++++---------- 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 9470fb0a..1a08b50a 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -1,26 +1,28 @@ import { AddLiquidity, - AddLiquidityInput, - PoolState, - Slippage, - Address, + AddLiquidityBaseCallV2, AddLiquidityBuildOutput, + AddLiquidityCall, + AddLiquidityComposableStableQueryOutput, + AddLiquidityInput, + AddLiquidityProportionalInput, AddLiquidityQueryOutput, - AddLiquidityUnbalancedInput, - VAULT, AddLiquiditySingleTokenInput, - AddLiquidityProportionalInput, - Token, + addLiquiditySingleTokenShouldHaveTokenInIndexError, + AddLiquidityUnbalancedInput, + Address, + BALANCER_ROUTER, ChainId, - TokenAmount, - AddLiquidityComposableStableQueryOutput, NATIVE_ASSETS, - BALANCER_ROUTER, -} from '../../../src'; + PoolState, + Slippage, + Token, + TokenAmount, + VAULT, +} from 'src'; +import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; -import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; -import { addLiquiditySingleTokenShouldHaveTokenInIndexError } from '../../../src/utils/errors'; type AddLiquidityOutput = { addLiquidityQueryOutput: AddLiquidityQueryOutput; @@ -50,14 +52,24 @@ async function sdkAddLiquidity({ addLiquidityInput, poolState, ); - const addLiquidityBuildOutput = addLiquidity.buildCall({ + + let addLiquidityBuildInput: AddLiquidityCall = { ...addLiquidityQueryOutput, slippage, - sender: testAddress, - recipient: testAddress, chainId: addLiquidityInput.chainId, sendNativeAsset: !!sendNativeAsset, - }); + }; + if (poolState.vaultVersion === 2) { + (addLiquidityBuildInput as AddLiquidityBaseCallV2) = { + ...addLiquidityBuildInput, + sender: testAddress, + recipient: testAddress, + }; + } + + const addLiquidityBuildOutput = addLiquidity.buildCall( + addLiquidityBuildInput, + ); return { addLiquidityBuildOutput, diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 65460079..d7059b59 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -1,27 +1,29 @@ -import { RemoveLiquidityTxInput } from './types'; +import { zeroAddress } from 'viem'; import { + BALANCER_ROUTER, ChainId, - RemoveLiquidityComposableStableQueryOutput, - RemoveLiquidityBuildOutput, - RemoveLiquidityQueryOutput, NATIVE_ASSETS, PoolState, - TokenAmount, - Slippage, - Token, - RemoveLiquidityUnbalancedInput, - RemoveLiquiditySingleTokenExactInInput, - VAULT, + RemoveLiquidityBaseCallV2, + RemoveLiquidityCall, + RemoveLiquidityBuildOutput, + RemoveLiquidityComposableStableQueryOutput, RemoveLiquidityInput, RemoveLiquidityProportionalInput, + RemoveLiquidityQueryOutput, + RemoveLiquidityRecoveryInput, + RemoveLiquiditySingleTokenExactInInput, removeLiquiditySingleTokenExactInShouldHaveTokenOutIndexError, - BALANCER_ROUTER, RemoveLiquiditySingleTokenExactOutInput, - RemoveLiquidityRecoveryInput, -} from '../../../src'; -import { sendTransactionGetBalances, TxOutput } from './helper'; -import { zeroAddress } from 'viem'; + RemoveLiquidityUnbalancedInput, + Slippage, + Token, + TokenAmount, + VAULT, +} from 'src'; import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; +import { sendTransactionGetBalances, TxOutput } from './helper'; +import { RemoveLiquidityTxInput } from './types'; type RemoveLiquidityOutput = { removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; @@ -44,14 +46,24 @@ export const sdkRemoveLiquidity = async ({ removeLiquidityInput, poolState, ); - const removeLiquidityBuildOutput = removeLiquidity.buildCall({ + + let removeLiquidityBuildInput: RemoveLiquidityCall = { ...removeLiquidityQueryOutput, slippage, - sender: testAddress, - recipient: testAddress, chainId: removeLiquidityInput.chainId, receiveNativeAsset: !!receiveNativeAsset, - }); + }; + if (poolState.vaultVersion === 2) { + (removeLiquidityBuildInput as RemoveLiquidityBaseCallV2) = { + ...removeLiquidityBuildInput, + sender: testAddress, + recipient: testAddress, + }; + } + + const removeLiquidityBuildOutput = removeLiquidity.buildCall( + removeLiquidityBuildInput, + ); return { removeLiquidityBuildOutput, From 13101371d5f285850e0242d26f7b0bc2e45cc15e Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Fri, 8 Mar 2024 11:57:47 +0000 Subject: [PATCH 14/29] refactor: Split types to versions. --- .../addLiquidityComposableStable.ts | 4 +-- .../addLiquidityV2/composableStable/types.ts | 10 ++++++ .../addLiquidity/addLiquidityV2/index.ts | 7 ++-- .../addLiquidity/addLiquidityV2/types.ts | 19 ++++++++++ .../weighted/addLiquidityWeighted.ts | 4 +-- src/entities/addLiquidity/index.ts | 24 +++++-------- src/entities/addLiquidity/types.ts | 36 ++++--------------- src/entities/utils/doAddLiquidityQuery.ts | 10 ++++-- 8 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts create mode 100644 src/entities/addLiquidity/addLiquidityV2/types.ts diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 92286e90..164e710d 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -8,7 +8,6 @@ import { AddLiquidityBuildOutput, AddLiquidityInput, AddLiquidityKind, - AddLiquidityComposableStableQueryOutput, AddLiquidityComposableStableCall, } from '@/entities/addLiquidity/types'; import { @@ -23,6 +22,7 @@ import { } from '@/entities/utils'; import { ComposableStableEncoder } from '@/entities/encoders/composableStable'; import { getValue } from '../../helpers'; +import { AddLiquidityV2ComposableStableQueryOutput } from './types'; type AddLiquidityAmounts = AddLiquidityAmountsBase & { maxAmountsInWithoutBpt: bigint[]; @@ -32,7 +32,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { public async query( input: AddLiquidityInput, poolState: PoolState, - ): Promise { + ): Promise { const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); const bptIndex = sortedTokens.findIndex( (t) => t.address === poolState.address, diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts new file mode 100644 index 00000000..d48338e5 --- /dev/null +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts @@ -0,0 +1,10 @@ +import { AddLiquidityBaseQueryOutput } from '../../types'; +import { AddLiquidityV2BaseCall } from '../types'; + +export type AddLiquidityV2ComposableStableQueryOutput = + AddLiquidityBaseQueryOutput & { + bptIndex: number; + }; + +export type AddLiquidityV2ComposableStableCall = AddLiquidityV2BaseCall & + AddLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/addLiquidity/addLiquidityV2/index.ts b/src/entities/addLiquidity/addLiquidityV2/index.ts index 14911090..e964c996 100644 --- a/src/entities/addLiquidity/addLiquidityV2/index.ts +++ b/src/entities/addLiquidity/addLiquidityV2/index.ts @@ -1,14 +1,13 @@ import { AddLiquidityBase, AddLiquidityBuildOutput, - AddLiquidityCall, AddLiquidityConfig, AddLiquidityInput, - AddLiquidityQueryOutput, PoolState, } from '../..'; import { PoolType } from '../../../types'; import { AddLiquidityComposableStable } from './composableStable/addLiquidityComposableStable'; +import { AddLiquidityV2Call, AddLiqudityV2QueryOutput } from './types'; import { AddLiquidityWeighted } from './weighted/addLiquidityWeighted'; export class AddLiquidityV2 implements AddLiquidityBase { @@ -38,11 +37,11 @@ export class AddLiquidityV2 implements AddLiquidityBase { public async query( input: AddLiquidityInput, poolState: PoolState, - ): Promise { + ): Promise { return this.getAddLiquidity(poolState.type).query(input, poolState); } - public buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput { + public buildCall(input: AddLiquidityV2Call): AddLiquidityBuildOutput { return this.getAddLiquidity(input.poolType).buildCall(input); } } diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts new file mode 100644 index 00000000..e62a7924 --- /dev/null +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -0,0 +1,19 @@ +import { Address } from 'viem'; +import { AddLiquidityBaseCall, AddLiquidityBaseQueryOutput } from '../types'; +import { + AddLiquidityV2ComposableStableCall, + AddLiquidityV2ComposableStableQueryOutput, +} from './composableStable/types'; + +export type AddLiquidityV2BaseCall = AddLiquidityBaseCall & { + sender: Address; + recipient: Address; +}; + +export type AddLiquidityV2Call = + | AddLiquidityV2BaseCall + | AddLiquidityV2ComposableStableCall; + +export type AddLiqudityV2QueryOutput = + | AddLiquidityBaseQueryOutput + | AddLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 1426013f..7cbd148c 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -6,10 +6,10 @@ import { VAULT, MAX_UINT256, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; import { AddLiquidityBase, + AddLiquidityBaseQueryOutput, AddLiquidityBuildOutput, AddLiquidityInput, AddLiquidityKind, - AddLiquidityWeightedQueryOutput, AddLiquidityWeightedCall, } from '@/entities/addLiquidity/types'; import { AddLiquidityAmounts, PoolState } from '@/entities/types'; @@ -25,7 +25,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { public async query( input: AddLiquidityInput, poolState: PoolState, - ): Promise { + ): Promise { const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); const amounts = this.getAmountsQuery(sortedTokens, input); diff --git a/src/entities/addLiquidity/index.ts b/src/entities/addLiquidity/index.ts index c970201e..df7e6c61 100644 --- a/src/entities/addLiquidity/index.ts +++ b/src/entities/addLiquidity/index.ts @@ -33,22 +33,16 @@ export class AddLiquidity implements AddLiquidityBase { } buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput { - // TODO: refactor validators to take v3 into account - const isV2Input = 'sender' in input; - if (input.vaultVersion === 3 && isV2Input) - throw Error('Cannot define sender/recipient in V3'); - if (input.vaultVersion === 2 && !isV2Input) - throw Error('Sender/recipient must be defined in V2'); + if (input.vaultVersion === 2 && 'sender' in input) { + const addLiquidity = new AddLiquidityV2(this.config); + return addLiquidity.buildCall(input); + } - switch (input.vaultVersion) { - case 2: { - const addLiquidity = new AddLiquidityV2(this.config); - return addLiquidity.buildCall(input); - } - case 3: { - const addLiquidity = new AddLiquidityV3(); - return addLiquidity.buildCall(input); - } + if (input.vaultVersion === 3 && !('sender' in input)) { + const addLiquidity = new AddLiquidityV3(); + return addLiquidity.buildCall(input); } + + throw Error('buildCall input/version mis-match'); } } diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 1e7d8bb1..1e1fdcef 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -2,6 +2,10 @@ import { TokenAmount } from '../tokenAmount'; import { Slippage } from '../slippage'; import { PoolState } from '../types'; import { Address, Hex, InputAmount } from '../../types'; +import { + AddLiquidityV2Call, + AddLiqudityV2QueryOutput, +} from './addLiquidityV2/types'; export enum AddLiquidityKind { Unbalanced = 'Unbalanced', @@ -48,17 +52,9 @@ export type AddLiquidityBaseQueryOutput = { vaultVersion: 2 | 3; }; -export type AddLiquidityComposableStableQueryOutput = - AddLiquidityBaseQueryOutput & { - bptIndex: number; - }; - -export type AddLiquidityWeightedQueryOutput = AddLiquidityBaseQueryOutput; - export type AddLiquidityQueryOutput = | AddLiquidityBaseQueryOutput - | AddLiquidityComposableStableQueryOutput - | AddLiquidityWeightedQueryOutput; + | AddLiqudityV2QueryOutput; export type AddLiquidityBaseCall = { slippage: Slippage; @@ -66,20 +62,7 @@ export type AddLiquidityBaseCall = { sendNativeAsset?: boolean; } & AddLiquidityBaseQueryOutput; -export type AddLiquidityBaseCallV2 = AddLiquidityBaseCall & { - sender: Address; - recipient: Address; -}; - -export type AddLiquidityWeightedCall = AddLiquidityBaseCallV2 & - AddLiquidityWeightedQueryOutput; -export type AddLiquidityComposableStableCall = AddLiquidityBaseCallV2 & - AddLiquidityComposableStableQueryOutput; - -export type AddLiquidityCall = - | AddLiquidityBaseCall - | AddLiquidityWeightedCall - | AddLiquidityComposableStableCall; +export type AddLiquidityCall = AddLiquidityBaseCall | AddLiquidityV2Call; export interface AddLiquidityBase { query( @@ -100,10 +83,3 @@ export type AddLiquidityBuildOutput = { export type AddLiquidityConfig = { customAddLiquidityTypes: Record; }; - -export type JoinPoolRequest = { - assets: Address[]; - maxAmountsIn: readonly bigint[]; - userData: Hex; - fromInternalBalance: boolean; -}; diff --git a/src/entities/utils/doAddLiquidityQuery.ts b/src/entities/utils/doAddLiquidityQuery.ts index b8aeae56..d6acbbf6 100644 --- a/src/entities/utils/doAddLiquidityQuery.ts +++ b/src/entities/utils/doAddLiquidityQuery.ts @@ -1,8 +1,14 @@ -import { createPublicClient, http } from 'viem'; +import { createPublicClient, http, Hex } from 'viem'; import { Address } from '../../types'; import { BALANCER_QUERIES, CHAINS } from '../../utils'; import { balancerQueriesAbi } from '../../abi'; -import { JoinPoolRequest } from '../addLiquidity/types'; + +type JoinPoolRequest = { + assets: Address[]; + maxAmountsIn: readonly bigint[]; + userData: Hex; + fromInternalBalance: boolean; +}; export async function doAddLiquidityQuery( rpcUrl: string, From 2897201b0b57cdc76b41ff15a6a58c256bfd60c7 Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Fri, 8 Mar 2024 12:08:14 +0000 Subject: [PATCH 15/29] fix: Move fromInternalBalance to V2 only. --- src/entities/addLiquidity/addLiquidityV2/types.ts | 7 ++++++- src/entities/addLiquidity/types.ts | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts index e62a7924..4798cd84 100644 --- a/src/entities/addLiquidity/addLiquidityV2/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -14,6 +14,11 @@ export type AddLiquidityV2Call = | AddLiquidityV2BaseCall | AddLiquidityV2ComposableStableCall; +type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { + fromInternalBalance: boolean; + vaultVersion: 2; +}; + export type AddLiqudityV2QueryOutput = - | AddLiquidityBaseQueryOutput + | AddLiquidityV2BaseQueryOutput | AddLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 1e1fdcef..f44c5352 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -47,7 +47,6 @@ export type AddLiquidityBaseQueryOutput = { addLiquidityKind: AddLiquidityKind; bptOut: TokenAmount; amountsIn: TokenAmount[]; - fromInternalBalance: boolean; tokenInIndex?: number; vaultVersion: 2 | 3; }; From bc4452957c6d22a4683be5c83bd69b32dacf00fd Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Fri, 8 Mar 2024 13:22:35 +0000 Subject: [PATCH 16/29] fix: fromInternal balance for V2 only. --- .../addLiquidityComposableStable.ts | 10 +-- .../addLiquidityV2/composableStable/types.ts | 8 ++- .../addLiquidity/addLiquidityV2/types.ts | 3 +- .../weighted/addLiquidityWeighted.ts | 10 +-- .../addLiquidity/addLiquidityV3/index.ts | 1 - test/lib/utils/addLiquidityHelper.ts | 65 ++++++++++++------- 6 files changed, 60 insertions(+), 37 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 164e710d..cf31fed9 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -8,7 +8,6 @@ import { AddLiquidityBuildOutput, AddLiquidityInput, AddLiquidityKind, - AddLiquidityComposableStableCall, } from '@/entities/addLiquidity/types'; import { AddLiquidityAmounts as AddLiquidityAmountsBase, @@ -22,7 +21,10 @@ import { } from '@/entities/utils'; import { ComposableStableEncoder } from '@/entities/encoders/composableStable'; import { getValue } from '../../helpers'; -import { AddLiquidityV2ComposableStableQueryOutput } from './types'; +import { + AddLiquidityV2ComposableStableCall, + AddLiquidityV2ComposableStableQueryOutput, +} from './types'; type AddLiquidityAmounts = AddLiquidityAmountsBase & { maxAmountsInWithoutBpt: bigint[]; @@ -82,7 +84,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { } public buildCall( - input: AddLiquidityComposableStableCall, + input: AddLiquidityV2ComposableStableCall, ): AddLiquidityBuildOutput { const amounts = this.getAmountsCall(input); @@ -174,7 +176,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { } private getAmountsCall( - input: AddLiquidityComposableStableCall, + input: AddLiquidityV2ComposableStableCall, ): AddLiquidityAmounts { let addLiquidityAmounts: AddLiquidityAmountsBase; switch (input.addLiquidityKind) { diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts index d48338e5..19a95dc1 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts @@ -1,8 +1,10 @@ -import { AddLiquidityBaseQueryOutput } from '../../types'; -import { AddLiquidityV2BaseCall } from '../types'; +import { + AddLiquidityV2BaseCall, + AddLiquidityV2BaseQueryOutput, +} from '../types'; export type AddLiquidityV2ComposableStableQueryOutput = - AddLiquidityBaseQueryOutput & { + AddLiquidityV2BaseQueryOutput & { bptIndex: number; }; diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts index 4798cd84..bf3ee0e7 100644 --- a/src/entities/addLiquidity/addLiquidityV2/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -6,6 +6,7 @@ import { } from './composableStable/types'; export type AddLiquidityV2BaseCall = AddLiquidityBaseCall & { + fromInternalBalance: boolean; sender: Address; recipient: Address; }; @@ -14,7 +15,7 @@ export type AddLiquidityV2Call = | AddLiquidityV2BaseCall | AddLiquidityV2ComposableStableCall; -type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { +export type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { fromInternalBalance: boolean; vaultVersion: 2; }; diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 7cbd148c..817feaeb 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -6,11 +6,9 @@ import { VAULT, MAX_UINT256, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; import { AddLiquidityBase, - AddLiquidityBaseQueryOutput, AddLiquidityBuildOutput, AddLiquidityInput, AddLiquidityKind, - AddLiquidityWeightedCall, } from '@/entities/addLiquidity/types'; import { AddLiquidityAmounts, PoolState } from '@/entities/types'; import { @@ -20,12 +18,16 @@ import { parseAddLiquidityArgs, } from '@/entities/utils'; import { getAmountsCall, getValue } from '../../helpers'; +import { + AddLiquidityV2BaseCall, + AddLiquidityV2BaseQueryOutput, +} from '../types'; export class AddLiquidityWeighted implements AddLiquidityBase { public async query( input: AddLiquidityInput, poolState: PoolState, - ): Promise { + ): Promise { const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); const amounts = this.getAmountsQuery(sortedTokens, input); @@ -70,7 +72,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { }; } - public buildCall(input: AddLiquidityWeightedCall): AddLiquidityBuildOutput { + public buildCall(input: AddLiquidityV2BaseCall): AddLiquidityBuildOutput { const amounts = getAmountsCall(input); const userData = WeightedEncoder.encodeAddLiquidityUserData( diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 2ea78214..e701f5ac 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -79,7 +79,6 @@ export class AddLiquidityV3 implements AddLiquidityBase { addLiquidityKind: input.kind, bptOut, amountsIn, - fromInternalBalance: input.fromInternalBalance ?? false, vaultVersion: 3, tokenInIndex, }; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 1a08b50a..ea4004e6 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -1,9 +1,7 @@ import { AddLiquidity, - AddLiquidityBaseCallV2, AddLiquidityBuildOutput, AddLiquidityCall, - AddLiquidityComposableStableQueryOutput, AddLiquidityInput, AddLiquidityProportionalInput, AddLiquidityQueryOutput, @@ -23,6 +21,11 @@ import { import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; +import { + AddLiquidityV2BaseCall, + AddLiquidityV2BaseQueryOutput, +} from '@/entities/addLiquidity/addLiquidityV2/types'; +import { AddLiquidityV2ComposableStableQueryOutput } from '@/entities/addLiquidity/addLiquidityV2/composableStable/types'; type AddLiquidityOutput = { addLiquidityQueryOutput: AddLiquidityQueryOutput; @@ -60,10 +63,11 @@ async function sdkAddLiquidity({ sendNativeAsset: !!sendNativeAsset, }; if (poolState.vaultVersion === 2) { - (addLiquidityBuildInput as AddLiquidityBaseCallV2) = { + (addLiquidityBuildInput as AddLiquidityV2BaseCall) = { ...addLiquidityBuildInput, sender: testAddress, recipient: testAddress, + fromInternalBalance: false, }; } @@ -80,10 +84,8 @@ async function sdkAddLiquidity({ function isAddLiquidityComposableStableQueryOutput( output: AddLiquidityQueryOutput, ): boolean { - return ( - (output as AddLiquidityComposableStableQueryOutput).bptIndex !== - undefined - ); + if ('bptIndex' in output) return true; + return false; } function getCheck(output: AddLiquidityQueryOutput, isExactIn: boolean) { @@ -92,12 +94,12 @@ function getCheck(output: AddLiquidityQueryOutput, isExactIn: boolean) { // Using this destructuring to return only the fields of interest // biome-ignore lint/correctness/noUnusedVariables: const { bptOut, bptIndex, ...check } = - output as AddLiquidityComposableStableQueryOutput; + output as AddLiquidityV2ComposableStableQueryOutput; return check; } // biome-ignore lint/correctness/noUnusedVariables: const { amountsIn, bptIndex, ...check } = - output as AddLiquidityComposableStableQueryOutput; + output as AddLiquidityV2ComposableStableQueryOutput; return check; } if (isExactIn) { @@ -182,21 +184,26 @@ export function assertAddLiquidityUnbalanced( return TokenAmount.fromRawAmount(token, input.rawAmount); }); - const expectedQueryOutput: Omit< - AddLiquidityQueryOutput, - 'bptOut' | 'bptIndex' - > = { + let expectedQueryOutput: + | Omit + | Omit = { // Query should use same amountsIn as input amountsIn: expectedAmountsIn, tokenInIndex: undefined, // Should match inputs poolId: poolState.id, poolType: poolState.type, - fromInternalBalance: !!addLiquidityInput.fromInternalBalance, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, }; + if (vaultVersion === 2) + expectedQueryOutput = { + ...expectedQueryOutput, + fromInternalBalance: false, + vaultVersion: 2, + }; + const queryCheck = getCheck(addLiquidityQueryOutput, true); expect(queryCheck).to.deep.eq(expectedQueryOutput); @@ -245,10 +252,9 @@ export function assertAddLiquiditySingleToken( (t) => t.address !== poolState.address, ); - const expectedQueryOutput: Omit< - AddLiquidityQueryOutput, - 'amountsIn' | 'bptIndex' - > = { + let expectedQueryOutput: + | Omit + | Omit = { // Query should use same bpt out as user sets bptOut: TokenAmount.fromRawAmount( bptToken, @@ -260,11 +266,17 @@ export function assertAddLiquiditySingleToken( // Should match inputs poolId: poolState.id, poolType: poolState.type, - fromInternalBalance: !!addLiquidityInput.fromInternalBalance, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, }; + if (vaultVersion === 2) + expectedQueryOutput = { + ...expectedQueryOutput, + fromInternalBalance: false, + vaultVersion: 2, + }; + const queryCheck = getCheck(addLiquidityQueryOutput, false); expect(queryCheck).to.deep.eq(expectedQueryOutput); @@ -313,10 +325,9 @@ export function assertAddLiquidityProportional( const bptToken = new Token(chainId, poolState.address, 18); - const expectedQueryOutput: Omit< - AddLiquidityQueryOutput, - 'amountsIn' | 'bptIndex' - > = { + let expectedQueryOutput: + | Omit + | Omit = { // Query should use same bpt out as user sets bptOut: TokenAmount.fromRawAmount( bptToken, @@ -327,11 +338,17 @@ export function assertAddLiquidityProportional( // Should match inputs poolId: poolState.id, poolType: poolState.type, - fromInternalBalance: !!addLiquidityInput.fromInternalBalance, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, }; + if (vaultVersion === 2) + expectedQueryOutput = { + ...expectedQueryOutput, + fromInternalBalance: false, + vaultVersion: 2, + }; + const queryCheck = getCheck(addLiquidityQueryOutput, false); expect(queryCheck).to.deep.eq(expectedQueryOutput); From 71b2f6ddaed4dbe4f8e277ef357c2096c4c2f237 Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Fri, 8 Mar 2024 13:22:59 +0000 Subject: [PATCH 17/29] fix: Validate fromInternal for vault version. --- src/entities/inputValidator/inputValidator.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/entities/inputValidator/inputValidator.ts b/src/entities/inputValidator/inputValidator.ts index 84134658..208b8056 100644 --- a/src/entities/inputValidator/inputValidator.ts +++ b/src/entities/inputValidator/inputValidator.ts @@ -38,6 +38,11 @@ export class InputValidator { addLiquidityInput: AddLiquidityInput, poolState: PoolState, ): void { + if ( + addLiquidityInput.fromInternalBalance && + poolState.vaultVersion === 3 + ) + throw new Error('Cannot use internal balances in V3'); this.getValidator(poolState.type).validateAddLiquidity( addLiquidityInput, poolState, From b5b75dbb2822c8f060b22fbac79d034ca1ca39dd Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Fri, 8 Mar 2024 13:49:17 +0000 Subject: [PATCH 18/29] refactor: Move fromInternal to build. --- .../addLiquidityComposableStable.ts | 5 +- .../addLiquidity/addLiquidityV2/index.ts | 5 +- .../addLiquidity/addLiquidityV2/types.ts | 3 +- .../weighted/addLiquidityWeighted.ts | 5 +- src/entities/addLiquidity/types.ts | 1 - src/entities/initPool/types.ts | 1 + src/entities/inputValidator/inputValidator.ts | 5 -- test/lib/utils/addLiquidityHelper.ts | 48 ++++++------------- 8 files changed, 23 insertions(+), 50 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index cf31fed9..1d1acf1c 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -54,7 +54,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { recipient: ZERO_ADDRESS, maxAmountsIn: amounts.maxAmountsIn, userData, - fromInternalBalance: input.fromInternalBalance ?? false, + fromInternalBalance: false, // This isn't required for the query }); const queryOutput = await doAddLiquidityQuery( @@ -77,7 +77,6 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { bptOut, amountsIn, tokenInIndex: amounts.tokenInIndex, - fromInternalBalance: !!input.fromInternalBalance, bptIndex, vaultVersion: 2, }; @@ -98,7 +97,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { sortedTokens: input.amountsIn.map((a) => a.token), maxAmountsIn: amounts.maxAmountsIn, userData, - fromInternalBalance: input.fromInternalBalance, + fromInternalBalance: !!input.fromInternalBalance, sendNativeAsset: !!input.sendNativeAsset, }); diff --git a/src/entities/addLiquidity/addLiquidityV2/index.ts b/src/entities/addLiquidity/addLiquidityV2/index.ts index e964c996..dd392ff5 100644 --- a/src/entities/addLiquidity/addLiquidityV2/index.ts +++ b/src/entities/addLiquidity/addLiquidityV2/index.ts @@ -3,11 +3,12 @@ import { AddLiquidityBuildOutput, AddLiquidityConfig, AddLiquidityInput, + AddLiquidityQueryOutput, PoolState, } from '../..'; import { PoolType } from '../../../types'; import { AddLiquidityComposableStable } from './composableStable/addLiquidityComposableStable'; -import { AddLiquidityV2Call, AddLiqudityV2QueryOutput } from './types'; +import { AddLiquidityV2Call } from './types'; import { AddLiquidityWeighted } from './weighted/addLiquidityWeighted'; export class AddLiquidityV2 implements AddLiquidityBase { @@ -37,7 +38,7 @@ export class AddLiquidityV2 implements AddLiquidityBase { public async query( input: AddLiquidityInput, poolState: PoolState, - ): Promise { + ): Promise { return this.getAddLiquidity(poolState.type).query(input, poolState); } diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts index bf3ee0e7..55bd53bb 100644 --- a/src/entities/addLiquidity/addLiquidityV2/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -6,7 +6,7 @@ import { } from './composableStable/types'; export type AddLiquidityV2BaseCall = AddLiquidityBaseCall & { - fromInternalBalance: boolean; + fromInternalBalance?: boolean; sender: Address; recipient: Address; }; @@ -16,7 +16,6 @@ export type AddLiquidityV2Call = | AddLiquidityV2ComposableStableCall; export type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { - fromInternalBalance: boolean; vaultVersion: 2; }; diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 817feaeb..21799c11 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -44,7 +44,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { recipient: ZERO_ADDRESS, maxAmountsIn: amounts.maxAmountsIn, userData, - fromInternalBalance: input.fromInternalBalance ?? false, + fromInternalBalance: false, // This isn't required for the query }); const queryOutput = await doAddLiquidityQuery( @@ -67,7 +67,6 @@ export class AddLiquidityWeighted implements AddLiquidityBase { bptOut, amountsIn, tokenInIndex: amounts.tokenInIndex, - fromInternalBalance: !!input.fromInternalBalance, vaultVersion: 2, }; } @@ -85,7 +84,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { sortedTokens: input.amountsIn.map((a) => a.token), maxAmountsIn: amounts.maxAmountsIn, userData, - fromInternalBalance: input.fromInternalBalance, + fromInternalBalance: !!input.fromInternalBalance, sendNativeAsset: !!input.sendNativeAsset, }); diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index f44c5352..b81ac817 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -17,7 +17,6 @@ export enum AddLiquidityKind { export type AddLiquidityBaseInput = { chainId: number; rpcUrl: string; - fromInternalBalance?: boolean; }; export type AddLiquidityUnbalancedInput = AddLiquidityBaseInput & { diff --git a/src/entities/initPool/types.ts b/src/entities/initPool/types.ts index e7ee8222..953c4408 100644 --- a/src/entities/initPool/types.ts +++ b/src/entities/initPool/types.ts @@ -22,6 +22,7 @@ export type InitPoolInputV2 = Omit & { recipient: Address; amountsIn: InputAmount[]; chainId: number; + fromInternalBalance?: boolean; }; export type InitPoolInputV3 = { diff --git a/src/entities/inputValidator/inputValidator.ts b/src/entities/inputValidator/inputValidator.ts index 208b8056..84134658 100644 --- a/src/entities/inputValidator/inputValidator.ts +++ b/src/entities/inputValidator/inputValidator.ts @@ -38,11 +38,6 @@ export class InputValidator { addLiquidityInput: AddLiquidityInput, poolState: PoolState, ): void { - if ( - addLiquidityInput.fromInternalBalance && - poolState.vaultVersion === 3 - ) - throw new Error('Cannot use internal balances in V3'); this.getValidator(poolState.type).validateAddLiquidity( addLiquidityInput, poolState, diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index ea4004e6..db48e89d 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -21,10 +21,7 @@ import { import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; -import { - AddLiquidityV2BaseCall, - AddLiquidityV2BaseQueryOutput, -} from '@/entities/addLiquidity/addLiquidityV2/types'; +import { AddLiquidityV2BaseCall } from '@/entities/addLiquidity/addLiquidityV2/types'; import { AddLiquidityV2ComposableStableQueryOutput } from '@/entities/addLiquidity/addLiquidityV2/composableStable/types'; type AddLiquidityOutput = { @@ -184,9 +181,11 @@ export function assertAddLiquidityUnbalanced( return TokenAmount.fromRawAmount(token, input.rawAmount); }); - let expectedQueryOutput: - | Omit - | Omit = { + const expectedQueryOutput: Omit< + AddLiquidityQueryOutput, + 'bptOut' | 'bptIndex' + > = { + // | Omit = { // Query should use same amountsIn as input amountsIn: expectedAmountsIn, tokenInIndex: undefined, @@ -197,13 +196,6 @@ export function assertAddLiquidityUnbalanced( vaultVersion: poolState.vaultVersion, }; - if (vaultVersion === 2) - expectedQueryOutput = { - ...expectedQueryOutput, - fromInternalBalance: false, - vaultVersion: 2, - }; - const queryCheck = getCheck(addLiquidityQueryOutput, true); expect(queryCheck).to.deep.eq(expectedQueryOutput); @@ -252,9 +244,10 @@ export function assertAddLiquiditySingleToken( (t) => t.address !== poolState.address, ); - let expectedQueryOutput: - | Omit - | Omit = { + const expectedQueryOutput: Omit< + AddLiquidityQueryOutput, + 'amountsIn' | 'bptIndex' + > = { // Query should use same bpt out as user sets bptOut: TokenAmount.fromRawAmount( bptToken, @@ -270,13 +263,6 @@ export function assertAddLiquiditySingleToken( vaultVersion: poolState.vaultVersion, }; - if (vaultVersion === 2) - expectedQueryOutput = { - ...expectedQueryOutput, - fromInternalBalance: false, - vaultVersion: 2, - }; - const queryCheck = getCheck(addLiquidityQueryOutput, false); expect(queryCheck).to.deep.eq(expectedQueryOutput); @@ -325,9 +311,10 @@ export function assertAddLiquidityProportional( const bptToken = new Token(chainId, poolState.address, 18); - let expectedQueryOutput: - | Omit - | Omit = { + const expectedQueryOutput: Omit< + AddLiquidityQueryOutput, + 'amountsIn' | 'bptIndex' + > = { // Query should use same bpt out as user sets bptOut: TokenAmount.fromRawAmount( bptToken, @@ -342,13 +329,6 @@ export function assertAddLiquidityProportional( vaultVersion: poolState.vaultVersion, }; - if (vaultVersion === 2) - expectedQueryOutput = { - ...expectedQueryOutput, - fromInternalBalance: false, - vaultVersion: 2, - }; - const queryCheck = getCheck(addLiquidityQueryOutput, false); expect(queryCheck).to.deep.eq(expectedQueryOutput); From 3c2053bc76e8eea0711c1883a65dfb01b23bd0f3 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 8 Mar 2024 13:20:53 -0300 Subject: [PATCH 19/29] Export JoinPoolRequest type --- src/entities/addLiquidity/types.ts | 8 ++++++++ src/entities/utils/doAddLiquidityQuery.ts | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index b81ac817..bb07fbeb 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -81,3 +81,11 @@ export type AddLiquidityBuildOutput = { export type AddLiquidityConfig = { customAddLiquidityTypes: Record; }; + +// type consumed by FE team, so should be exported here +export type JoinPoolRequest = { + assets: Address[]; + maxAmountsIn: readonly bigint[]; + userData: Hex; + fromInternalBalance: boolean; +}; diff --git a/src/entities/utils/doAddLiquidityQuery.ts b/src/entities/utils/doAddLiquidityQuery.ts index d6acbbf6..b8aeae56 100644 --- a/src/entities/utils/doAddLiquidityQuery.ts +++ b/src/entities/utils/doAddLiquidityQuery.ts @@ -1,14 +1,8 @@ -import { createPublicClient, http, Hex } from 'viem'; +import { createPublicClient, http } from 'viem'; import { Address } from '../../types'; import { BALANCER_QUERIES, CHAINS } from '../../utils'; import { balancerQueriesAbi } from '../../abi'; - -type JoinPoolRequest = { - assets: Address[]; - maxAmountsIn: readonly bigint[]; - userData: Hex; - fromInternalBalance: boolean; -}; +import { JoinPoolRequest } from '../addLiquidity/types'; export async function doAddLiquidityQuery( rpcUrl: string, From 8e6f972c09efc57909fc99ed519e2a7ca19efac4 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Mon, 11 Mar 2024 14:36:01 -0300 Subject: [PATCH 20/29] Refactor sendNativeAsset and receiveNativeAsset into wethIsEth --- .changeset/hungry-seahorses-rest.md | 2 +- examples/addLiquidity.ts | 2 +- examples/addLiquidityNested.ts | 6 +-- .../addLiquidityComposableStable.ts | 2 +- .../weighted/addLiquidityWeighted.ts | 2 +- .../addLiquidity/addLiquidityV3/index.ts | 8 ++-- src/entities/addLiquidity/helpers.ts | 2 +- src/entities/addLiquidity/types.ts | 2 +- .../addLiquidityNested/encodeCalls.ts | 4 +- src/entities/addLiquidityNested/index.ts | 4 +- src/entities/addLiquidityNested/types.ts | 4 +- .../addLiquidityNested/validateInputs.ts | 2 +- src/entities/initPool/initPoolV3.ts | 2 +- src/entities/initPool/types.ts | 2 +- .../weighted/inputValidatorWeighted.ts | 8 ++-- .../removeLiquidityComposableStable.ts | 2 +- .../weighted/removeLiquidityWeighted.ts | 2 +- .../encodeRemoveLiquidityProportional.ts | 2 +- ...encodeRemoveLiquiditySingleTokenExactIn.ts | 2 +- ...ncodeRemoveLiquiditySingleTokenExactOut.ts | 2 +- src/entities/removeLiquidity/types.ts | 2 +- .../removeLiquidityNested/encodeCalls.ts | 4 +- src/entities/removeLiquidityNested/index.ts | 4 +- src/entities/removeLiquidityNested/types.ts | 4 +- .../removeLiquidityNested/validateInputs.ts | 2 +- src/entities/utils/parseAddLiquidityArgs.ts | 6 +-- src/entities/utils/parseInitializeArgs.ts | 6 +-- .../utils/parseRemoveLiquidityArgs.ts | 6 +-- test/lib/utils/addLiquidityHelper.ts | 40 +++++++++---------- test/lib/utils/addLiquidityNestedHelper.ts | 10 ++--- test/lib/utils/removeLiquidityHelper.ts | 38 +++++++++--------- test/lib/utils/types.ts | 6 +-- .../composableStable.integration.test.ts | 18 ++++----- .../addLiquidity/gyroEV2.integration.test.ts | 6 +-- .../addLiquidity/weighted.integration.test.ts | 18 ++++----- .../addLiquidityNested.integration.test.ts | 10 ++--- .../composableStable.integration.test.ts | 24 +++++------ ...posableStable.recovery.integration.test.ts | 6 +-- .../gyroEV2.integration.test.ts | 6 +-- .../weighted.integration.test.ts | 24 +++++------ .../weighted.recovery.integration.test.ts | 6 +-- .../removeLiquidityNested.integration.test.ts | 20 +++++----- test/v3/addLiquidity.integration.test.ts | 12 +++--- test/v3/removeLiquidity.integration.test.ts | 18 ++++----- 44 files changed, 179 insertions(+), 179 deletions(-) diff --git a/.changeset/hungry-seahorses-rest.md b/.changeset/hungry-seahorses-rest.md index 41f1f262..27efe496 100644 --- a/.changeset/hungry-seahorses-rest.md +++ b/.changeset/hungry-seahorses-rest.md @@ -2,4 +2,4 @@ "@balancer/sdk": minor --- -Refactor wethIsEth into sendNativeAsset and receiveNativeAsset +Refactor useNativeAssetAsWrappedAmountIn adn toNativeAsset into wethIsEth diff --git a/examples/addLiquidity.ts b/examples/addLiquidity.ts index e52c04da..38b9b009 100644 --- a/examples/addLiquidity.ts +++ b/examples/addLiquidity.ts @@ -80,7 +80,7 @@ const addLiquidity = async () => { sender: userAccount, recipient: userAccount, chainId, - sendNativeAsset: false, + wethIsEth: false, }); console.log('\nWith slippage applied:'); diff --git a/examples/addLiquidityNested.ts b/examples/addLiquidityNested.ts index 91d0bc9d..96036c84 100644 --- a/examples/addLiquidityNested.ts +++ b/examples/addLiquidityNested.ts @@ -97,7 +97,7 @@ const addLiquidityNested = async () => { client, ); - const sendNativeAsset = false; + const wethIsEth = false; const { call, to, value, minBptOut } = addLiquidityNested.buildCall({ ...queryOutput, @@ -105,11 +105,11 @@ const addLiquidityNested = async () => { sender: accountAddress, recipient: accountAddress, relayerApprovalSignature: signature, - sendNativeAsset, + wethIsEth, }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); - if (sendNativeAsset) { + if (wethIsEth) { tokensIn = replaceWrapped(tokensIn, chainId); } diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 92286e90..38478b19 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -97,7 +97,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { maxAmountsIn: amounts.maxAmountsIn, userData, fromInternalBalance: input.fromInternalBalance, - sendNativeAsset: !!input.sendNativeAsset, + wethIsEth: !!input.wethIsEth, }); const call = encodeFunctionData({ diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 1426013f..ca876ce8 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -84,7 +84,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { maxAmountsIn: amounts.maxAmountsIn, userData, fromInternalBalance: input.fromInternalBalance, - sendNativeAsset: !!input.sendNativeAsset, + wethIsEth: !!input.wethIsEth, }); const call = encodeFunctionData({ diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 2ea78214..3634649a 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -102,7 +102,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { input.poolId, input.amountsIn.map((a) => a.amount), amounts.minimumBpt, - !!input.sendNativeAsset, + !!input.wethIsEth, '0x', ], }); @@ -122,7 +122,7 @@ export class AddLiquidityV3 implements AddLiquidityBase { input.amountsIn[input.tokenInIndex].token.address, input.amountsIn[input.tokenInIndex].amount, input.bptOut.amount, - !!input.sendNativeAsset, + !!input.wethIsEth, '0x', ], }); @@ -131,13 +131,13 @@ export class AddLiquidityV3 implements AddLiquidityBase { } let value = 0n; - if (input.sendNativeAsset) { + if (input.wethIsEth) { const wrappedNativeAssetInput = input.amountsIn.find( (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, ); if (wrappedNativeAssetInput === undefined) { throw new Error( - 'sendNativeAsset requires wrapped native asset as input', + 'wethIsEth requires wrapped native asset as input', ); } value = wrappedNativeAssetInput.amount; diff --git a/src/entities/addLiquidity/helpers.ts b/src/entities/addLiquidity/helpers.ts index 17b04a17..326c33b2 100644 --- a/src/entities/addLiquidity/helpers.ts +++ b/src/entities/addLiquidity/helpers.ts @@ -29,7 +29,7 @@ export const getAmountsCall = ( export const getValue = (input: AddLiquidityBaseCall): bigint => { let value = 0n; - if (input.sendNativeAsset) { + if (input.wethIsEth) { value = input.amountsIn.find( (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 9cb44997..025fa797 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -65,7 +65,7 @@ export type AddLiquidityBaseCall = { sender: Address; recipient: Address; chainId: number; - sendNativeAsset?: boolean; + wethIsEth?: boolean; } & AddLiquidityBaseQueryOutput; export type AddLiquidityWeightedCall = AddLiquidityBaseCall; diff --git a/src/entities/addLiquidityNested/encodeCalls.ts b/src/entities/addLiquidityNested/encodeCalls.ts index 74c0c548..9c5e8186 100644 --- a/src/entities/addLiquidityNested/encodeCalls.ts +++ b/src/entities/addLiquidityNested/encodeCalls.ts @@ -14,7 +14,7 @@ export const encodeCalls = ( const values: bigint[] = []; for (const callAttributes of callsAttributes) { const { - sendNativeAsset, + wethIsEth, chainId, sortedTokens, poolId, @@ -33,7 +33,7 @@ export const encodeCalls = ( let tokensIn = [...sortedTokens]; let value = 0n; - if (sendNativeAsset) { + if (wethIsEth) { tokensIn = replaceWrapped([...sortedTokens], chainId); const nativeAssetIndex = tokensIn.findIndex((t) => t.isSameAddress(ZERO_ADDRESS), diff --git a/src/entities/addLiquidityNested/index.ts b/src/entities/addLiquidityNested/index.ts index 4c0f71e8..2dc06faf 100644 --- a/src/entities/addLiquidityNested/index.ts +++ b/src/entities/addLiquidityNested/index.ts @@ -77,11 +77,11 @@ export class AddLiquidityNested { minBptOut, }; - // update sendNativeAsset flag + // update wethIsEth flag input.callsAttributes = input.callsAttributes.map((call) => { return { ...call, - sendNativeAsset: input.sendNativeAsset, + wethIsEth: input.wethIsEth, }; }); diff --git a/src/entities/addLiquidityNested/types.ts b/src/entities/addLiquidityNested/types.ts index 38e8f297..f7821818 100644 --- a/src/entities/addLiquidityNested/types.ts +++ b/src/entities/addLiquidityNested/types.ts @@ -15,7 +15,7 @@ export type AddLiquidityNestedInput = { export type AddLiquidityNestedCallAttributes = { chainId: ChainId; - sendNativeAsset?: boolean; + wethIsEth?: boolean; sortedTokens: Token[]; poolId: Hex; poolAddress: Address; @@ -43,5 +43,5 @@ export type AddLiquidityNestedCallInput = AddLiquidityNestedQueryOutput & { sender: Address; recipient: Address; relayerApprovalSignature?: Hex; - sendNativeAsset?: boolean; + wethIsEth?: boolean; }; diff --git a/src/entities/addLiquidityNested/validateInputs.ts b/src/entities/addLiquidityNested/validateInputs.ts index f543102a..acb31a18 100644 --- a/src/entities/addLiquidityNested/validateInputs.ts +++ b/src/entities/addLiquidityNested/validateInputs.ts @@ -29,7 +29,7 @@ export const validateBuildCallInput = ( input: AddLiquidityNestedCallInput, ): void => { const chainId = input.callsAttributes[0].chainId; - if (input.sendNativeAsset) { + if (input.wethIsEth) { if ( !input.amountsIn.some((a) => a.token.isUnderlyingEqual(NATIVE_ASSETS[chainId]), diff --git a/src/entities/initPool/initPoolV3.ts b/src/entities/initPool/initPoolV3.ts index a1be6877..ba5c5f59 100644 --- a/src/entities/initPool/initPoolV3.ts +++ b/src/entities/initPool/initPoolV3.ts @@ -45,7 +45,7 @@ export class InitPoolV3 implements InitPoolBase { } private value(input: InitPoolInputV3) { - return input.sendNativeAsset + return input.wethIsEth ? (input.amountsIn.find((a) => isSameAddress( a.address, diff --git a/src/entities/initPool/types.ts b/src/entities/initPool/types.ts index e7ee8222..90397688 100644 --- a/src/entities/initPool/types.ts +++ b/src/entities/initPool/types.ts @@ -27,7 +27,7 @@ export type InitPoolInputV2 = Omit & { export type InitPoolInputV3 = { amountsIn: InputAmount[]; minBptAmountOut: bigint; - sendNativeAsset?: boolean; + wethIsEth?: boolean; chainId: number; }; diff --git a/src/entities/inputValidator/weighted/inputValidatorWeighted.ts b/src/entities/inputValidator/weighted/inputValidatorWeighted.ts index 34249fe2..35dc4e50 100644 --- a/src/entities/inputValidator/weighted/inputValidatorWeighted.ts +++ b/src/entities/inputValidator/weighted/inputValidatorWeighted.ts @@ -24,7 +24,7 @@ export class InputValidatorWeighted implements InputValidatorBase { poolState.tokens.map((t) => t.address), ); if (poolState.vaultVersion === 3) { - this.validateSendNativeAsset(initPoolInput as InitPoolInputV3); + this.validateWethIsEth(initPoolInput as InitPoolInputV3); } } @@ -73,8 +73,8 @@ export class InputValidatorWeighted implements InputValidatorBase { validateTokensRemoveLiquidity(input, poolState); } - private validateSendNativeAsset(initPoolInput: InitPoolInputV3) { - if (initPoolInput.sendNativeAsset) { + private validateWethIsEth(initPoolInput: InitPoolInputV3) { + if (initPoolInput.wethIsEth) { const inputContainsWrappedNativeAsset = initPoolInput.amountsIn.some((a) => isSameAddress( @@ -84,7 +84,7 @@ export class InputValidatorWeighted implements InputValidatorBase { ); if (!inputContainsWrappedNativeAsset) { throw new Error( - 'sendNativeAsset requires wrapped native asset as input', + 'wethIsEth requires wrapped native asset as input', ); } } diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index ed5be05d..740bdaba 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -143,7 +143,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { minAmountsOut: amounts.minAmountsOut, userData, toInternalBalance: !!input.toInternalBalance, - receiveNativeAsset: !!input.receiveNativeAsset, + wethIsEth: !!input.wethIsEth, chainId: input.chainId, }); const call = encodeFunctionData({ diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index 74c05e35..c2938d67 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -89,7 +89,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { minAmountsOut: amounts.minAmountsOut, userData, toInternalBalance: !!input.toInternalBalance, - receiveNativeAsset: !!input.receiveNativeAsset, + wethIsEth: !!input.wethIsEth, chainId: input.chainId, }); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts index 604d5338..f2164919 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts @@ -13,7 +13,7 @@ export const encodeRemoveLiquidityProportional = ( input.poolId, input.bptIn.amount, minAmountsOut, - !!input.receiveNativeAsset, + !!input.wethIsEth, '0x', ], }); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts index 7a27af53..df0d06f8 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts @@ -20,7 +20,7 @@ export const encodeRemoveLiquiditySingleTokenExactIn = ( input.bptIn.amount, input.amountsOut[input.tokenOutIndex].token.address, minAmountsOut[input.tokenOutIndex], - !!input.receiveNativeAsset, + !!input.wethIsEth, '0x', ], }); diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts index 268f233e..62380994 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts @@ -20,7 +20,7 @@ export const encodeRemoveLiquiditySingleTokenExactOut = ( maxBptAmountIn, input.amountsOut[input.tokenOutIndex].token.address, input.amountsOut[input.tokenOutIndex].amount, - !!input.receiveNativeAsset, + !!input.wethIsEth, '0x', ], }); diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index dc362748..ed4a8659 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -80,7 +80,7 @@ export type RemoveLiquidityBaseCall = { sender: Address; recipient: Address; chainId: number; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; } & RemoveLiquidityBaseQueryOutput; export type RemoveLiquidityWeightedCall = RemoveLiquidityBaseCall; diff --git a/src/entities/removeLiquidityNested/encodeCalls.ts b/src/entities/removeLiquidityNested/encodeCalls.ts index fd898a19..94e0d4f2 100644 --- a/src/entities/removeLiquidityNested/encodeCalls.ts +++ b/src/entities/removeLiquidityNested/encodeCalls.ts @@ -14,7 +14,7 @@ export const encodeCalls = ( const encodedCalls: Hex[] = []; for (const callAttributes of callsAttributes) { const { - receiveNativeAsset, + wethIsEth, chainId, sortedTokens, poolId, @@ -31,7 +31,7 @@ export const encodeCalls = ( // replace wrapped token with native asset if needed let tokensOut = [...sortedTokens]; - if (receiveNativeAsset) { + if (wethIsEth) { tokensOut = replaceWrapped([...sortedTokens], chainId); } diff --git a/src/entities/removeLiquidityNested/index.ts b/src/entities/removeLiquidityNested/index.ts index f31f16c2..b9d368b2 100644 --- a/src/entities/removeLiquidityNested/index.ts +++ b/src/entities/removeLiquidityNested/index.ts @@ -97,8 +97,8 @@ export class RemoveLiquidityNested { minAmountsOut[j].amount; } }); - // update receiveNativeAsset flag - call.receiveNativeAsset = !!input.receiveNativeAsset; + // update wethIsEth flag + call.wethIsEth = !!input.wethIsEth; }); const encodedCalls = encodeCalls( diff --git a/src/entities/removeLiquidityNested/types.ts b/src/entities/removeLiquidityNested/types.ts index 97b38934..06c9dcb9 100644 --- a/src/entities/removeLiquidityNested/types.ts +++ b/src/entities/removeLiquidityNested/types.ts @@ -38,7 +38,7 @@ export type RemoveLiquidityNestedCallAttributes = { index: bigint; }[]; tokenOutIndex?: number; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; }; export type RemoveLiquidityNestedQueryOutput = { @@ -55,5 +55,5 @@ export type RemoveLiquidityNestedCallInput = sender: Address; recipient: Address; relayerApprovalSignature?: Hex; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; }; diff --git a/src/entities/removeLiquidityNested/validateInputs.ts b/src/entities/removeLiquidityNested/validateInputs.ts index 5e2c640c..71d1c8ab 100644 --- a/src/entities/removeLiquidityNested/validateInputs.ts +++ b/src/entities/removeLiquidityNested/validateInputs.ts @@ -45,7 +45,7 @@ export const validateBuildCallInput = ( input: RemoveLiquidityNestedCallInput, ) => { if ( - input.receiveNativeAsset && + input.wethIsEth && !input.amountsOut.some((a) => a.token.isSameAddress(NATIVE_ASSETS[input.chainId].wrapped), ) diff --git a/src/entities/utils/parseAddLiquidityArgs.ts b/src/entities/utils/parseAddLiquidityArgs.ts index cded013e..3429c184 100644 --- a/src/entities/utils/parseAddLiquidityArgs.ts +++ b/src/entities/utils/parseAddLiquidityArgs.ts @@ -3,7 +3,7 @@ import { Token } from '../token'; import { replaceWrapped } from './replaceWrapped'; export function parseAddLiquidityArgs({ - sendNativeAsset, + wethIsEth, chainId, sortedTokens, poolId, @@ -14,7 +14,7 @@ export function parseAddLiquidityArgs({ fromInternalBalance, }: { chainId?: number; - sendNativeAsset?: boolean; + wethIsEth?: boolean; sortedTokens: Token[]; poolId: Hex; sender: Address; @@ -25,7 +25,7 @@ export function parseAddLiquidityArgs({ }) { // replace wrapped token with native asset if needed const tokensIn = - chainId && sendNativeAsset + chainId && wethIsEth ? replaceWrapped([...sortedTokens], chainId) : [...sortedTokens]; diff --git a/src/entities/utils/parseInitializeArgs.ts b/src/entities/utils/parseInitializeArgs.ts index 911fd549..37c8c317 100644 --- a/src/entities/utils/parseInitializeArgs.ts +++ b/src/entities/utils/parseInitializeArgs.ts @@ -6,13 +6,13 @@ import { DEFAULT_USERDATA } from '@/utils'; export function parseInitializeArgs({ exactAmountsIn, minBptAmountOut, - sendNativeAsset, + wethIsEth, poolAddress, sortedTokens, }: { exactAmountsIn: bigint[]; minBptAmountOut: bigint; - sendNativeAsset?: boolean; + wethIsEth?: boolean; chainId: number; poolAddress: Address; sortedTokens: Token[]; @@ -23,7 +23,7 @@ export function parseInitializeArgs({ sortedTokens.map(({ address }) => address), exactAmountsIn, minBptAmountOut, - sendNativeAsset ?? false, + wethIsEth ?? false, DEFAULT_USERDATA, ], }; diff --git a/src/entities/utils/parseRemoveLiquidityArgs.ts b/src/entities/utils/parseRemoveLiquidityArgs.ts index bb623116..a73e05e4 100644 --- a/src/entities/utils/parseRemoveLiquidityArgs.ts +++ b/src/entities/utils/parseRemoveLiquidityArgs.ts @@ -5,7 +5,7 @@ import { replaceWrapped } from './replaceWrapped'; export function parseRemoveLiquidityArgs({ chainId, - receiveNativeAsset, + wethIsEth, sortedTokens, poolId, sender, @@ -15,7 +15,7 @@ export function parseRemoveLiquidityArgs({ toInternalBalance, }: { chainId?: number; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; sortedTokens: Token[]; poolId: Address; sender: Address; @@ -26,7 +26,7 @@ export function parseRemoveLiquidityArgs({ }) { // replace wrapped token with native asset if needed const tokensOut = - chainId && receiveNativeAsset + chainId && wethIsEth ? replaceWrapped([...sortedTokens], chainId) : [...sortedTokens]; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 9470fb0a..ed1be0e7 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -34,14 +34,14 @@ async function sdkAddLiquidity({ poolState, slippage, testAddress, - sendNativeAsset, + wethIsEth, }: { addLiquidity: AddLiquidity; addLiquidityInput: AddLiquidityInput; poolState: PoolState; slippage: Slippage; testAddress: Address; - sendNativeAsset?: boolean; + wethIsEth?: boolean; }): Promise<{ addLiquidityBuildOutput: AddLiquidityBuildOutput; addLiquidityQueryOutput: AddLiquidityQueryOutput; @@ -56,7 +56,7 @@ async function sdkAddLiquidity({ sender: testAddress, recipient: testAddress, chainId: addLiquidityInput.chainId, - sendNativeAsset: !!sendNativeAsset, + wethIsEth: !!wethIsEth, }); return { @@ -116,7 +116,7 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { testAddress, client, slippage, - sendNativeAsset, + wethIsEth, } = txInput; const { addLiquidityQueryOutput, addLiquidityBuildOutput } = @@ -126,7 +126,7 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { poolState, slippage, testAddress, - sendNativeAsset, + wethIsEth, }); const tokens = getTokensForBalanceCheck(poolState); @@ -155,7 +155,7 @@ export function assertAddLiquidityUnbalanced( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - sendNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; @@ -199,7 +199,7 @@ export function assertAddLiquidityUnbalanced( true, slippage, vaultVersion, - sendNativeAsset, + wethIsEth, ); assertTokenDeltas( @@ -208,7 +208,7 @@ export function assertAddLiquidityUnbalanced( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - sendNativeAsset, + wethIsEth, ); } @@ -219,7 +219,7 @@ export function assertAddLiquiditySingleToken( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - sendNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; @@ -274,7 +274,7 @@ export function assertAddLiquiditySingleToken( false, slippage, vaultVersion, - sendNativeAsset, + wethIsEth, ); assertTokenDeltas( @@ -283,7 +283,7 @@ export function assertAddLiquiditySingleToken( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - sendNativeAsset, + wethIsEth, ); } @@ -294,7 +294,7 @@ export function assertAddLiquidityProportional( addLiquidityOutput: AddLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - sendNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = addLiquidityOutput; @@ -337,10 +337,10 @@ export function assertAddLiquidityProportional( false, slippage, vaultVersion, - sendNativeAsset, + wethIsEth, ); - if (sendNativeAsset) { + if (wethIsEth) { expect( addLiquidityOutput.addLiquidityQueryOutput.amountsIn.some((t) => t.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), @@ -354,7 +354,7 @@ export function assertAddLiquidityProportional( addLiquidityQueryOutput, addLiquidityBuildOutput, txOutput, - sendNativeAsset, + wethIsEth, ); } @@ -364,7 +364,7 @@ function assertTokenDeltas( addLiquidityQueryOutput: AddLiquidityQueryOutput, addLiquidityBuildOutput: AddLiquidityBuildOutput, txOutput: TxOutput, - sendNativeAsset?: boolean, + wethIsEth?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); @@ -384,9 +384,9 @@ function assertTokenDeltas( * Since native asset was moved to an extra index, we need to identify its * respective amount within the amounts array and move it to that index. * - Balancer V2: zero address represents the native asset - * - Balancer V3: WETH address represents the native asset (in combination with sendNativeAsset flag) + * - Balancer V3: WETH address represents the native asset (in combination with wethIsEth flag) */ - if (sendNativeAsset) { + if (wethIsEth) { const nativeAssetIndex = amountsWithoutBpt.findIndex((a) => a.token.isSameAddress( NATIVE_ASSETS[addLiquidityInput.chainId].wrapped, @@ -407,7 +407,7 @@ function assertAddLiquidityBuildOutput( isExactIn: boolean, slippage: Slippage, vaultVersion: 2 | 3 = 2, - sendNativeAsset?: boolean, + wethIsEth?: boolean, ) { // if exactIn maxAmountsIn should use same amountsIn as input else slippage should be applied const maxAmountsIn = isExactIn @@ -431,7 +431,7 @@ function assertAddLiquidityBuildOutput( : BALANCER_ROUTER[addLiquidityInput.chainId]; let value = 0n; - if (sendNativeAsset) { + if (wethIsEth) { value = addLiquidityQueryOutput.amountsIn.find((a) => a.token.isSameAddress( diff --git a/test/lib/utils/addLiquidityNestedHelper.ts b/test/lib/utils/addLiquidityNestedHelper.ts index c9c0cda2..50e30871 100644 --- a/test/lib/utils/addLiquidityNestedHelper.ts +++ b/test/lib/utils/addLiquidityNestedHelper.ts @@ -23,7 +23,7 @@ export const assertResults = ( minBptOut: bigint, chainId: number, value?: bigint, - sendNativeAsset = false, + wethIsEth = false, ) => { expect(transactionReceipt.status).to.eq('success'); expect(bptOut.amount > 0n).to.be.true; @@ -38,7 +38,7 @@ export const assertResults = ( const wrappedNativeAsset = amountsIn.find( (a) => a.address === NATIVE_ASSETS[chainId].wrapped, ); - if (wrappedNativeAsset && sendNativeAsset) { + if (wrappedNativeAsset && wethIsEth) { expect(value).to.eq(wrappedNativeAsset.rawAmount); } else { expect(value).to.eq(undefined || 0n); @@ -52,7 +52,7 @@ export const doAddLiquidityNested = async ({ rpcUrl, testAddress, client, - sendNativeAsset = false, + wethIsEth = false, }: AddLiquidityNestedTxInput) => { // setup add liquidity helper const addLiquidityNested = new AddLiquidityNested(); @@ -83,11 +83,11 @@ export const doAddLiquidityNested = async ({ sender: testAddress, recipient: testAddress, relayerApprovalSignature: signature, - sendNativeAsset, + wethIsEth, }); let tokensIn = queryOutput.amountsIn.map((a) => a.token); - if (sendNativeAsset) { + if (wethIsEth) { tokensIn = replaceWrapped(tokensIn, chainId); } diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 65460079..2c8f58ff 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -35,7 +35,7 @@ export const sdkRemoveLiquidity = async ({ poolState, slippage, testAddress, - receiveNativeAsset, + wethIsEth, }: Omit): Promise<{ removeLiquidityBuildOutput: RemoveLiquidityBuildOutput; removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; @@ -50,7 +50,7 @@ export const sdkRemoveLiquidity = async ({ sender: testAddress, recipient: testAddress, chainId: removeLiquidityInput.chainId, - receiveNativeAsset: !!receiveNativeAsset, + wethIsEth: !!wethIsEth, }); return { @@ -110,7 +110,7 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { testAddress, client, slippage, - receiveNativeAsset, + wethIsEth, } = txInput; const { removeLiquidityQueryOutput, removeLiquidityBuildOutput } = @@ -120,7 +120,7 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { poolState, slippage, testAddress, - receiveNativeAsset, + wethIsEth, }); // get tokens for balance change - pool tokens, BPT, native @@ -149,7 +149,7 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput: RemoveLiquidityUnbalancedInput, removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -200,7 +200,7 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - receiveNativeAsset, + wethIsEth, ); } @@ -211,7 +211,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -269,7 +269,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - receiveNativeAsset, + wethIsEth, ); } @@ -280,7 +280,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -324,7 +324,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityQueryOutput.amountsOut.forEach((a) => { if ( vaultVersion === 2 && - receiveNativeAsset && + wethIsEth && a.token.address === zeroAddress ) { expect(a.amount > 0n).to.be.true; @@ -349,7 +349,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - receiveNativeAsset, + wethIsEth, ); } @@ -360,7 +360,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -397,7 +397,7 @@ export function assertRemoveLiquidityProportional( else expect(a.amount > 0n).to.be.true; }); - if (receiveNativeAsset) { + if (wethIsEth) { expect( removeLiquidityQueryOutput.amountsOut.some((a) => a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), @@ -419,7 +419,7 @@ export function assertRemoveLiquidityProportional( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - receiveNativeAsset, + wethIsEth, ); } @@ -430,7 +430,7 @@ export function assertRemoveLiquidityRecovery( removeLiquidityOutput: RemoveLiquidityOutput, slippage: Slippage, vaultVersion: 2 | 3 = 2, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = removeLiquidityOutput; @@ -467,7 +467,7 @@ export function assertRemoveLiquidityRecovery( else expect(a.amount > 0n).to.be.true; }); - if (receiveNativeAsset) { + if (wethIsEth) { expect( removeLiquidityQueryOutput.amountsOut.some((a) => a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), @@ -489,7 +489,7 @@ export function assertRemoveLiquidityRecovery( removeLiquidityInput, removeLiquidityQueryOutput, txOutput, - receiveNativeAsset, + wethIsEth, ); } @@ -498,7 +498,7 @@ function assertTokenDeltas( removeLiquidityInput: RemoveLiquidityInput, removeLiquidityQueryOutput: RemoveLiquidityQueryOutput, txOutput: TxOutput, - receiveNativeAsset?: boolean, + wethIsEth?: boolean, ) { expect(txOutput.transactionReceipt.status).to.eq('success'); @@ -515,7 +515,7 @@ function assertTokenDeltas( ]; // If removing liquidity to native asset we must replace it with 0 and update native value instead - if (receiveNativeAsset) { + if (wethIsEth) { const nativeAssetIndex = amountsWithoutBpt.findIndex((a) => a.token.isSameAddress( NATIVE_ASSETS[removeLiquidityInput.chainId].wrapped, diff --git a/test/lib/utils/types.ts b/test/lib/utils/types.ts index cf2efd75..7866bdb7 100644 --- a/test/lib/utils/types.ts +++ b/test/lib/utils/types.ts @@ -22,7 +22,7 @@ export type AddLiquidityTxInput = { slippage: Slippage; poolState: PoolState; testAddress: Address; - sendNativeAsset?: boolean; + wethIsEth?: boolean; }; export type InitPoolTxInput = Omit< @@ -40,7 +40,7 @@ export type RemoveLiquidityTxInput = { slippage: Slippage; poolState: PoolState; testAddress: Address; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; }; export type CreatePoolTxInput = { @@ -61,5 +61,5 @@ export type AddLiquidityNestedTxInput = { rpcUrl: string; testAddress: Address; client: Client & PublicActions & TestActions & WalletActions; - sendNativeAsset?: boolean; + wethIsEth?: boolean; }; diff --git a/test/v2/addLiquidity/composableStable.integration.test.ts b/test/v2/addLiquidity/composableStable.integration.test.ts index f945c5ea..58a1633d 100644 --- a/test/v2/addLiquidity/composableStable.integration.test.ts +++ b/test/v2/addLiquidity/composableStable.integration.test.ts @@ -126,7 +126,7 @@ describe('add liquidity composable stable test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, amountsIn, @@ -134,7 +134,7 @@ describe('add liquidity composable stable test', () => { const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -143,7 +143,7 @@ describe('add liquidity composable stable test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); @@ -181,14 +181,14 @@ describe('add liquidity composable stable test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquiditySingleToken( @@ -198,7 +198,7 @@ describe('add liquidity composable stable test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); @@ -233,14 +233,14 @@ describe('add liquidity composable stable test', () => { ); }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityProportional( txInput.client.chain?.id as number, @@ -249,7 +249,7 @@ describe('add liquidity composable stable test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/addLiquidity/gyroEV2.integration.test.ts b/test/v2/addLiquidity/gyroEV2.integration.test.ts index c22e581b..85ac1b28 100644 --- a/test/v2/addLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/addLiquidity/gyroEV2.integration.test.ts @@ -120,11 +120,11 @@ describe('GyroE V2 add liquidity test', () => { ); }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityProportional( txInput.client.chain?.id as number, @@ -133,7 +133,7 @@ describe('GyroE V2 add liquidity test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/addLiquidity/weighted.integration.test.ts b/test/v2/addLiquidity/weighted.integration.test.ts index fbc5e1d7..6726b5cf 100644 --- a/test/v2/addLiquidity/weighted.integration.test.ts +++ b/test/v2/addLiquidity/weighted.integration.test.ts @@ -126,7 +126,7 @@ describe('add liquidity weighted test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, amountsIn, @@ -134,7 +134,7 @@ describe('add liquidity weighted test', () => { const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -143,7 +143,7 @@ describe('add liquidity weighted test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); @@ -182,11 +182,11 @@ describe('add liquidity weighted test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquiditySingleToken( @@ -196,7 +196,7 @@ describe('add liquidity weighted test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); @@ -231,11 +231,11 @@ describe('add liquidity weighted test', () => { ); }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityProportional( @@ -245,7 +245,7 @@ describe('add liquidity weighted test', () => { addLiquidityOutput, txInput.slippage, 2, - sendNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts index 988f639b..29131a65 100644 --- a/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts +++ b/test/v2/addLiquidityNested/addLiquidityNested.integration.test.ts @@ -162,12 +162,12 @@ describe('add liquidity nested test', () => { decimals: t.decimals, })); - const sendNativeAsset = true; + const wethIsEth = true; txInput = { ...txInput, amountsIn, - sendNativeAsset, + wethIsEth, }; const { @@ -188,7 +188,7 @@ describe('add liquidity nested test', () => { minBptOut, chainId, value, - sendNativeAsset, + wethIsEth, ); }); @@ -201,12 +201,12 @@ describe('add liquidity nested test', () => { }, ]; - const sendNativeAsset = true; + const wethIsEth = true; txInput = { ...txInput, amountsIn, - sendNativeAsset, + wethIsEth, }; await expect(() => doAddLiquidityNested(txInput)).rejects.toThrowError( diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index bb2abb41..32d54c1a 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -126,7 +126,7 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), @@ -134,7 +134,7 @@ describe('composable stable remove liquidity test', () => { const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -142,7 +142,7 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -180,7 +180,7 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, amountOut, @@ -188,7 +188,7 @@ describe('composable stable remove liquidity test', () => { const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactOut( txInput.client.chain?.id as number, @@ -197,7 +197,7 @@ describe('composable stable remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -235,14 +235,14 @@ describe('composable stable remove liquidity test', () => { }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactIn( @@ -252,7 +252,7 @@ describe('composable stable remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -287,14 +287,14 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -303,7 +303,7 @@ describe('composable stable remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts index b4631f62..72cd7c5d 100644 --- a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts @@ -107,11 +107,11 @@ describe('composable stable remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput: input, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityRecovery( @@ -121,7 +121,7 @@ describe('composable stable remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/removeLiquidity/gyroEV2.integration.test.ts b/test/v2/removeLiquidity/gyroEV2.integration.test.ts index f91e4cc0..90a30334 100644 --- a/test/v2/removeLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/removeLiquidity/gyroEV2.integration.test.ts @@ -113,14 +113,14 @@ describe('GyroE V2 remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -129,7 +129,7 @@ describe('GyroE V2 remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index 880004f9..e8f72a6b 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -118,7 +118,7 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, amountsOut: amountsOut.slice(0, 1), @@ -126,7 +126,7 @@ describe('weighted remove liquidity test', () => { const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -134,7 +134,7 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, removeLiquidityOutput, txInput.slippage, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -172,7 +172,7 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, amountOut, @@ -180,7 +180,7 @@ describe('weighted remove liquidity test', () => { const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactOut( txInput.client.chain?.id as number, @@ -189,7 +189,7 @@ describe('weighted remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -227,14 +227,14 @@ describe('weighted remove liquidity test', () => { }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactIn( @@ -244,7 +244,7 @@ describe('weighted remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -279,14 +279,14 @@ describe('weighted remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityInput = { ...input, }; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -295,7 +295,7 @@ describe('weighted remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts index d8679ea2..08cbce23 100644 --- a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts @@ -111,11 +111,11 @@ describe('weighted remove liquidity recovery test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput: input, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityRecovery( @@ -125,7 +125,7 @@ describe('weighted remove liquidity recovery test', () => { removeLiquidityOutput, txInput.slippage, 2, - receiveNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts index 2ac7a2ce..07dfd634 100644 --- a/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts +++ b/test/v2/removeLiquidityNested/removeLiquidityNested.integration.test.ts @@ -43,7 +43,7 @@ type TxInput = { testAddress: Address; client: Client & PublicActions & TestActions & WalletActions; tokenOut?: Address; - receiveNativeAsset?: boolean; + wethIsEth?: boolean; }; describe('remove liquidity nested test', () => { @@ -113,7 +113,7 @@ describe('remove liquidity nested test', () => { test('proportional - native asset', async () => { const amountIn = parseUnits('1', 18); - const receiveNativeAsset = true; + const wethIsEth = true; const { transactionReceipt, @@ -129,7 +129,7 @@ describe('remove liquidity nested test', () => { rpcUrl, testAddress, client, - receiveNativeAsset, + wethIsEth, }); assertResults( @@ -176,7 +176,7 @@ describe('remove liquidity nested test', () => { test('single token - native asset', async () => { const amountIn = parseUnits('1', 18); const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH - const receiveNativeAsset = true; + const wethIsEth = true; const { transactionReceipt, @@ -193,7 +193,7 @@ describe('remove liquidity nested test', () => { testAddress, client, tokenOut, - receiveNativeAsset, + wethIsEth, }); assertResults( @@ -209,7 +209,7 @@ describe('remove liquidity nested test', () => { test('single token - native asset - invalid input', async () => { const amountIn = parseUnits('1', 18); const tokenOut = '0x6b175474e89094c44da98b954eedeac495271d0f'; // DAI - const receiveNativeAsset = true; + const wethIsEth = true; await expect( doTransaction({ @@ -220,7 +220,7 @@ describe('remove liquidity nested test', () => { testAddress, client, tokenOut, - receiveNativeAsset, + wethIsEth, }), ).rejects.toThrow( 'Removing liquidity to native asset requires wrapped native asset to exist within amounts out', @@ -236,7 +236,7 @@ export const doTransaction = async ({ testAddress, client, tokenOut, - receiveNativeAsset = false, + wethIsEth = false, }: TxInput) => { // setup mock api const api = new MockApi(); @@ -274,11 +274,11 @@ export const doTransaction = async ({ sender: testAddress, recipient: testAddress, relayerApprovalSignature: signature, - receiveNativeAsset, + wethIsEth, }); let tokensOut = minAmountsOut.map((a) => a.token); - if (receiveNativeAsset) { + if (wethIsEth) { tokensOut = replaceWrapped(tokensOut, chainId); } diff --git a/test/v3/addLiquidity.integration.test.ts b/test/v3/addLiquidity.integration.test.ts index 70ac2705..970c888f 100644 --- a/test/v3/addLiquidity.integration.test.ts +++ b/test/v3/addLiquidity.integration.test.ts @@ -127,7 +127,7 @@ describe('add liquidity test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, amountsIn, @@ -135,7 +135,7 @@ describe('add liquidity test', () => { const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquidityUnbalanced( txInput.client.chain?.id as number, @@ -144,7 +144,7 @@ describe('add liquidity test', () => { addLiquidityOutput, txInput.slippage, vaultVersion, - sendNativeAsset, + wethIsEth, ); }); }); @@ -183,14 +183,14 @@ describe('add liquidity test', () => { }); test('with native', async () => { - const sendNativeAsset = true; + const wethIsEth = true; const addLiquidityInput = { ...input, }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, - sendNativeAsset, + wethIsEth, }); assertAddLiquiditySingleToken( @@ -200,7 +200,7 @@ describe('add liquidity test', () => { addLiquidityOutput, txInput.slippage, vaultVersion, - sendNativeAsset, + wethIsEth, ); }); }); diff --git a/test/v3/removeLiquidity.integration.test.ts b/test/v3/removeLiquidity.integration.test.ts index 846cb919..bf306cd8 100644 --- a/test/v3/removeLiquidity.integration.test.ts +++ b/test/v3/removeLiquidity.integration.test.ts @@ -183,11 +183,11 @@ describe('remove liquidity test', () => { }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput: input, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactOut( @@ -197,7 +197,7 @@ describe('remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, vaultVersion, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -236,11 +236,11 @@ describe('remove liquidity test', () => { }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput: input, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquiditySingleTokenExactIn( @@ -250,7 +250,7 @@ describe('remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, vaultVersion, - receiveNativeAsset, + wethIsEth, ); }); }); @@ -286,11 +286,11 @@ describe('remove liquidity test', () => { ); }); test('with native', async () => { - const receiveNativeAsset = true; + const wethIsEth = true; const removeLiquidityOutput = await doRemoveLiquidity({ ...txInput, removeLiquidityInput: input, - receiveNativeAsset, + wethIsEth, }); assertRemoveLiquidityProportional( txInput.client.chain?.id as number, @@ -299,7 +299,7 @@ describe('remove liquidity test', () => { removeLiquidityOutput, txInput.slippage, vaultVersion, - receiveNativeAsset, + wethIsEth, ); }); }); From af5a6a08df770e81a17168a03d5cb2d70d03a8c0 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 8 Mar 2024 13:09:53 -0300 Subject: [PATCH 21/29] Rename add liquidity build call interface --- .../addLiquidityComposableStable.ts | 10 +-- .../addLiquidityV2/composableStable/types.ts | 7 +- .../addLiquidity/addLiquidityV2/index.ts | 8 ++- .../addLiquidity/addLiquidityV2/types.ts | 24 ++++--- .../weighted/addLiquidityWeighted.ts | 8 ++- .../addLiquidity/addLiquidityV3/index.ts | 8 ++- src/entities/addLiquidity/helpers.ts | 6 +- src/entities/addLiquidity/index.ts | 6 +- src/entities/addLiquidity/types.ts | 12 ++-- src/entities/initPool/types.ts | 4 +- test/lib/utils/addLiquidityHelper.ts | 64 +++++++++---------- 11 files changed, 85 insertions(+), 72 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 8eda77f9..cd4cf4f2 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -5,7 +5,7 @@ import { VAULT, MAX_UINT256, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; import { AddLiquidityBase, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, AddLiquidityInput, AddLiquidityKind, } from '@/entities/addLiquidity/types'; @@ -22,7 +22,7 @@ import { import { ComposableStableEncoder } from '@/entities/encoders/composableStable'; import { getValue } from '../../helpers'; import { - AddLiquidityV2ComposableStableCall, + AddLiquidityV2ComposableStableBuildCallInput, AddLiquidityV2ComposableStableQueryOutput, } from './types'; @@ -83,8 +83,8 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { } public buildCall( - input: AddLiquidityV2ComposableStableCall, - ): AddLiquidityBuildOutput { + input: AddLiquidityV2ComposableStableBuildCallInput, + ): AddLiquidityBuildCallOutput { const amounts = this.getAmountsCall(input); const userData = ComposableStableEncoder.encodeAddLiquidityUserData( @@ -175,7 +175,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { } private getAmountsCall( - input: AddLiquidityV2ComposableStableCall, + input: AddLiquidityV2ComposableStableBuildCallInput, ): AddLiquidityAmounts { let addLiquidityAmounts: AddLiquidityAmountsBase; switch (input.addLiquidityKind) { diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts index 19a95dc1..a0dc5155 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/types.ts @@ -1,5 +1,5 @@ import { - AddLiquidityV2BaseCall, + AddLiquidityV2BaseBuildCallInput, AddLiquidityV2BaseQueryOutput, } from '../types'; @@ -8,5 +8,6 @@ export type AddLiquidityV2ComposableStableQueryOutput = bptIndex: number; }; -export type AddLiquidityV2ComposableStableCall = AddLiquidityV2BaseCall & - AddLiquidityV2ComposableStableQueryOutput; +export type AddLiquidityV2ComposableStableBuildCallInput = + AddLiquidityV2BaseBuildCallInput & + AddLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/addLiquidity/addLiquidityV2/index.ts b/src/entities/addLiquidity/addLiquidityV2/index.ts index dd392ff5..b4963b65 100644 --- a/src/entities/addLiquidity/addLiquidityV2/index.ts +++ b/src/entities/addLiquidity/addLiquidityV2/index.ts @@ -1,6 +1,6 @@ import { AddLiquidityBase, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, AddLiquidityConfig, AddLiquidityInput, AddLiquidityQueryOutput, @@ -8,7 +8,7 @@ import { } from '../..'; import { PoolType } from '../../../types'; import { AddLiquidityComposableStable } from './composableStable/addLiquidityComposableStable'; -import { AddLiquidityV2Call } from './types'; +import { AddLiquidityV2BuildCallInput } from './types'; import { AddLiquidityWeighted } from './weighted/addLiquidityWeighted'; export class AddLiquidityV2 implements AddLiquidityBase { @@ -42,7 +42,9 @@ export class AddLiquidityV2 implements AddLiquidityBase { return this.getAddLiquidity(poolState.type).query(input, poolState); } - public buildCall(input: AddLiquidityV2Call): AddLiquidityBuildOutput { + public buildCall( + input: AddLiquidityV2BuildCallInput, + ): AddLiquidityBuildCallOutput { return this.getAddLiquidity(input.poolType).buildCall(input); } } diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts index 55bd53bb..85763391 100644 --- a/src/entities/addLiquidity/addLiquidityV2/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -1,19 +1,23 @@ import { Address } from 'viem'; -import { AddLiquidityBaseCall, AddLiquidityBaseQueryOutput } from '../types'; import { - AddLiquidityV2ComposableStableCall, + AddLiquidityBaseBuildCallInput, + AddLiquidityBaseQueryOutput, +} from '../types'; +import { + AddLiquidityV2ComposableStableBuildCallInput, AddLiquidityV2ComposableStableQueryOutput, } from './composableStable/types'; -export type AddLiquidityV2BaseCall = AddLiquidityBaseCall & { - fromInternalBalance?: boolean; - sender: Address; - recipient: Address; -}; +export type AddLiquidityV2BaseBuildCallInput = + AddLiquidityBaseBuildCallInput & { + fromInternalBalance?: boolean; + sender: Address; + recipient: Address; + }; -export type AddLiquidityV2Call = - | AddLiquidityV2BaseCall - | AddLiquidityV2ComposableStableCall; +export type AddLiquidityV2BuildCallInput = + | AddLiquidityV2BaseBuildCallInput + | AddLiquidityV2ComposableStableBuildCallInput; export type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { vaultVersion: 2; diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 9f57a908..2e8dc6e1 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -6,7 +6,7 @@ import { VAULT, MAX_UINT256, ZERO_ADDRESS } from '@/utils'; import { vaultV2Abi } from '@/abi'; import { AddLiquidityBase, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, AddLiquidityInput, AddLiquidityKind, } from '@/entities/addLiquidity/types'; @@ -19,7 +19,7 @@ import { } from '@/entities/utils'; import { getAmountsCall, getValue } from '../../helpers'; import { - AddLiquidityV2BaseCall, + AddLiquidityV2BaseBuildCallInput, AddLiquidityV2BaseQueryOutput, } from '../types'; @@ -71,7 +71,9 @@ export class AddLiquidityWeighted implements AddLiquidityBase { }; } - public buildCall(input: AddLiquidityV2BaseCall): AddLiquidityBuildOutput { + public buildCall( + input: AddLiquidityV2BaseBuildCallInput, + ): AddLiquidityBuildCallOutput { const amounts = getAmountsCall(input); const userData = WeightedEncoder.encodeAddLiquidityUserData( diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 43a43d94..90259fb8 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -15,9 +15,9 @@ import { import { getAmountsCall } from '../helpers'; import { AddLiquidityBase, - AddLiquidityBaseCall, + AddLiquidityBaseBuildCallInput, AddLiquidityBaseQueryOutput, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, AddLiquidityInput, AddLiquidityKind, } from '../types'; @@ -86,7 +86,9 @@ export class AddLiquidityV3 implements AddLiquidityBase { return output; } - buildCall(input: AddLiquidityBaseCall): AddLiquidityBuildOutput { + buildCall( + input: AddLiquidityBaseBuildCallInput, + ): AddLiquidityBuildCallOutput { const amounts = getAmountsCall(input); let call: Hex; switch (input.addLiquidityKind) { diff --git a/src/entities/addLiquidity/helpers.ts b/src/entities/addLiquidity/helpers.ts index 326c33b2..0635c44f 100644 --- a/src/entities/addLiquidity/helpers.ts +++ b/src/entities/addLiquidity/helpers.ts @@ -1,9 +1,9 @@ import { NATIVE_ASSETS } from '@/utils'; import { AddLiquidityAmounts } from '../types'; -import { AddLiquidityBaseCall, AddLiquidityKind } from './types'; +import { AddLiquidityBaseBuildCallInput, AddLiquidityKind } from './types'; export const getAmountsCall = ( - input: AddLiquidityBaseCall, + input: AddLiquidityBaseBuildCallInput, ): AddLiquidityAmounts => { switch (input.addLiquidityKind) { case AddLiquidityKind.Unbalanced: { @@ -27,7 +27,7 @@ export const getAmountsCall = ( } }; -export const getValue = (input: AddLiquidityBaseCall): bigint => { +export const getValue = (input: AddLiquidityBaseBuildCallInput): bigint => { let value = 0n; if (input.wethIsEth) { value = diff --git a/src/entities/addLiquidity/index.ts b/src/entities/addLiquidity/index.ts index df7e6c61..926fe217 100644 --- a/src/entities/addLiquidity/index.ts +++ b/src/entities/addLiquidity/index.ts @@ -1,9 +1,9 @@ import { AddLiquidityBase, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, AddLiquidityInput, AddLiquidityQueryOutput, - AddLiquidityCall, + AddLiquidityBuildCallInput, AddLiquidityConfig, } from './types'; import { PoolState } from '../types'; @@ -32,7 +32,7 @@ export class AddLiquidity implements AddLiquidityBase { } } - buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput { + buildCall(input: AddLiquidityBuildCallInput): AddLiquidityBuildCallOutput { if (input.vaultVersion === 2 && 'sender' in input) { const addLiquidity = new AddLiquidityV2(this.config); return addLiquidity.buildCall(input); diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 7f4ad934..aa627423 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -3,7 +3,7 @@ import { Slippage } from '../slippage'; import { PoolState } from '../types'; import { Address, Hex, InputAmount } from '../../types'; import { - AddLiquidityV2Call, + AddLiquidityV2BuildCallInput, AddLiqudityV2QueryOutput, } from './addLiquidityV2/types'; @@ -54,23 +54,25 @@ export type AddLiquidityQueryOutput = | AddLiquidityBaseQueryOutput | AddLiqudityV2QueryOutput; -export type AddLiquidityBaseCall = { +export type AddLiquidityBaseBuildCallInput = { slippage: Slippage; chainId: number; wethIsEth?: boolean; } & AddLiquidityBaseQueryOutput; -export type AddLiquidityCall = AddLiquidityBaseCall | AddLiquidityV2Call; +export type AddLiquidityBuildCallInput = + | AddLiquidityBaseBuildCallInput + | AddLiquidityV2BuildCallInput; export interface AddLiquidityBase { query( input: AddLiquidityInput, poolState: PoolState, ): Promise; - buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput; + buildCall(input: AddLiquidityBuildCallInput): AddLiquidityBuildCallOutput; } -export type AddLiquidityBuildOutput = { +export type AddLiquidityBuildCallOutput = { call: Hex; to: Address; value: bigint; diff --git a/src/entities/initPool/types.ts b/src/entities/initPool/types.ts index f5cee237..cdb61598 100644 --- a/src/entities/initPool/types.ts +++ b/src/entities/initPool/types.ts @@ -1,7 +1,7 @@ import { Address, Hex } from 'viem'; import { AddLiquidityBaseInput, - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, } from '../addLiquidity/types'; import { InputAmount } from '../../types'; import { PoolState } from '../types'; @@ -11,7 +11,7 @@ export interface InitPoolBase { } export type InitPoolBuildOutput = Omit< - AddLiquidityBuildOutput, + AddLiquidityBuildCallOutput, 'minBptOut' | 'maxAmountsIn' >; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 4c660fc7..2649e5c3 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -1,7 +1,7 @@ import { AddLiquidity, - AddLiquidityBuildOutput, - AddLiquidityCall, + AddLiquidityBuildCallOutput, + AddLiquidityBuildCallInput, AddLiquidityInput, AddLiquidityProportionalInput, AddLiquidityQueryOutput, @@ -21,12 +21,12 @@ import { import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { TxOutput, sendTransactionGetBalances } from './helper'; import { AddLiquidityTxInput } from './types'; -import { AddLiquidityV2BaseCall } from '@/entities/addLiquidity/addLiquidityV2/types'; +import { AddLiquidityV2BaseBuildCallInput } from '@/entities/addLiquidity/addLiquidityV2/types'; import { AddLiquidityV2ComposableStableQueryOutput } from '@/entities/addLiquidity/addLiquidityV2/composableStable/types'; type AddLiquidityOutput = { addLiquidityQueryOutput: AddLiquidityQueryOutput; - addLiquidityBuildOutput: AddLiquidityBuildOutput; + addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput; txOutput: TxOutput; }; @@ -45,7 +45,7 @@ async function sdkAddLiquidity({ testAddress: Address; wethIsEth?: boolean; }): Promise<{ - addLiquidityBuildOutput: AddLiquidityBuildOutput; + addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput; addLiquidityQueryOutput: AddLiquidityQueryOutput; }> { const addLiquidityQueryOutput = await addLiquidity.query( @@ -53,14 +53,14 @@ async function sdkAddLiquidity({ poolState, ); - let addLiquidityBuildInput: AddLiquidityCall = { + let addLiquidityBuildInput: AddLiquidityBuildCallInput = { ...addLiquidityQueryOutput, slippage, chainId: addLiquidityInput.chainId, wethIsEth: !!wethIsEth, }; if (poolState.vaultVersion === 2) { - (addLiquidityBuildInput as AddLiquidityV2BaseCall) = { + (addLiquidityBuildInput as AddLiquidityV2BaseBuildCallInput) = { ...addLiquidityBuildInput, sender: testAddress, recipient: testAddress, @@ -68,12 +68,12 @@ async function sdkAddLiquidity({ }; } - const addLiquidityBuildOutput = addLiquidity.buildCall( + const addLiquidityBuildCallOutput = addLiquidity.buildCall( addLiquidityBuildInput, ); return { - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, addLiquidityQueryOutput, }; } @@ -130,7 +130,7 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { wethIsEth, } = txInput; - const { addLiquidityQueryOutput, addLiquidityBuildOutput } = + const { addLiquidityQueryOutput, addLiquidityBuildCallOutput } = await sdkAddLiquidity({ addLiquidity, addLiquidityInput, @@ -147,14 +147,14 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { tokens, client, testAddress, - addLiquidityBuildOutput.to, - addLiquidityBuildOutput.call, - addLiquidityBuildOutput.value, + addLiquidityBuildCallOutput.to, + addLiquidityBuildCallOutput.call, + addLiquidityBuildCallOutput.value, ); return { addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, txOutput, }; } @@ -168,7 +168,7 @@ export function assertAddLiquidityUnbalanced( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = + const { txOutput, addLiquidityQueryOutput, addLiquidityBuildCallOutput } = addLiquidityOutput; // Get an amount for each pool token defaulting to 0 if not provided as input (this will include BPT token if in tokenList) @@ -203,10 +203,10 @@ export function assertAddLiquidityUnbalanced( // Expect some bpt amount expect(addLiquidityQueryOutput.bptOut.amount > 0n).to.be.true; - assertAddLiquidityBuildOutput( + assertAddLiquidityBuildCallOutput( addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, true, slippage, vaultVersion, @@ -217,7 +217,7 @@ export function assertAddLiquidityUnbalanced( poolState, addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, txOutput, wethIsEth, ); @@ -232,7 +232,7 @@ export function assertAddLiquiditySingleToken( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = + const { txOutput, addLiquidityQueryOutput, addLiquidityBuildCallOutput } = addLiquidityOutput; if (addLiquidityQueryOutput.tokenInIndex === undefined) @@ -277,10 +277,10 @@ export function assertAddLiquiditySingleToken( } }); - assertAddLiquidityBuildOutput( + assertAddLiquidityBuildCallOutput( addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, false, slippage, vaultVersion, @@ -291,7 +291,7 @@ export function assertAddLiquiditySingleToken( poolState, addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, txOutput, wethIsEth, ); @@ -306,7 +306,7 @@ export function assertAddLiquidityProportional( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, addLiquidityQueryOutput, addLiquidityBuildOutput } = + const { txOutput, addLiquidityQueryOutput, addLiquidityBuildCallOutput } = addLiquidityOutput; const bptToken = new Token(chainId, poolState.address, 18); @@ -339,10 +339,10 @@ export function assertAddLiquidityProportional( else expect(a.amount > 0n).to.be.true; }); - assertAddLiquidityBuildOutput( + assertAddLiquidityBuildCallOutput( addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, false, slippage, vaultVersion, @@ -361,7 +361,7 @@ export function assertAddLiquidityProportional( poolState, addLiquidityInput, addLiquidityQueryOutput, - addLiquidityBuildOutput, + addLiquidityBuildCallOutput, txOutput, wethIsEth, ); @@ -371,7 +371,7 @@ function assertTokenDeltas( poolState: PoolState, addLiquidityInput: AddLiquidityInput, addLiquidityQueryOutput: AddLiquidityQueryOutput, - addLiquidityBuildOutput: AddLiquidityBuildOutput, + addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput, txOutput: TxOutput, wethIsEth?: boolean, ) { @@ -403,16 +403,16 @@ function assertTokenDeltas( ); expectedDeltas[nativeAssetIndex] = 0n; expectedDeltas[expectedDeltas.length - 1] = - addLiquidityBuildOutput.value; + addLiquidityBuildCallOutput.value; } expect(txOutput.balanceDeltas).to.deep.eq(expectedDeltas); } -function assertAddLiquidityBuildOutput( +function assertAddLiquidityBuildCallOutput( addLiquidityInput: AddLiquidityInput, addLiquidityQueryOutput: AddLiquidityQueryOutput, - addLiquidityBuildOutput: AddLiquidityBuildOutput, + addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput, isExactIn: boolean, slippage: Slippage, vaultVersion: 2 | 3 = 2, @@ -449,7 +449,7 @@ function assertAddLiquidityBuildOutput( )?.amount ?? 0n; } - const expectedBuildOutput: Omit = { + const expectedBuildOutput: Omit = { maxAmountsIn, minBptOut, to, @@ -457,6 +457,6 @@ function assertAddLiquidityBuildOutput( }; // biome-ignore lint/correctness/noUnusedVariables: - const { call, ...buildCheck } = addLiquidityBuildOutput; + const { call, ...buildCheck } = addLiquidityBuildCallOutput; expect(buildCheck).to.deep.eq(expectedBuildOutput); } From 71395378f3824455b39a98cb4998e33229ea24c7 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 8 Mar 2024 13:39:05 -0300 Subject: [PATCH 22/29] Rename remove liquidity build call interface --- src/entities/removeLiquidity/helper.ts | 4 +- src/entities/removeLiquidity/index.ts | 8 +- .../removeLiquidityComposableStable.ts | 10 +- .../removeLiquidityV2/index.ts | 8 +- .../weighted/removeLiquidityWeighted.ts | 8 +- .../encodeRemoveLiquidityProportional.ts | 4 +- ...encodeRemoveLiquiditySingleTokenExactIn.ts | 4 +- ...ncodeRemoveLiquiditySingleTokenExactOut.ts | 4 +- .../removeLiquidityV3/index.ts | 8 +- src/entities/removeLiquidity/types.ts | 33 ++++--- test/lib/utils/removeLiquidityHelper.ts | 91 +++++++++++-------- 11 files changed, 103 insertions(+), 79 deletions(-) diff --git a/src/entities/removeLiquidity/helper.ts b/src/entities/removeLiquidity/helper.ts index b898ecd1..43deea20 100644 --- a/src/entities/removeLiquidity/helper.ts +++ b/src/entities/removeLiquidity/helper.ts @@ -6,7 +6,7 @@ import { Token } from '../token'; import { RemoveLiquidityAmounts } from '../types'; import { getAmounts } from '../utils'; import { - RemoveLiquidityCall, + RemoveLiquidityBuildCallInput, RemoveLiquidityInput, RemoveLiquidityKind, } from './types'; @@ -49,7 +49,7 @@ export const getAmountsQuery = ( }; export const getAmountsCall = ( - input: RemoveLiquidityCall, + input: RemoveLiquidityBuildCallInput, ): RemoveLiquidityAmounts => { switch (input.removeLiquidityKind) { case RemoveLiquidityKind.Unbalanced: diff --git a/src/entities/removeLiquidity/index.ts b/src/entities/removeLiquidity/index.ts index eafc5400..f84788a8 100644 --- a/src/entities/removeLiquidity/index.ts +++ b/src/entities/removeLiquidity/index.ts @@ -1,7 +1,7 @@ import { RemoveLiquidityBase, - RemoveLiquidityBuildOutput, - RemoveLiquidityCall, + RemoveLiquidityBuildCallOutput, + RemoveLiquidityBuildCallInput, RemoveLiquidityConfig, RemoveLiquidityInput, RemoveLiquidityQueryOutput, @@ -33,7 +33,9 @@ export class RemoveLiquidity implements RemoveLiquidityBase { } } - public buildCall(input: RemoveLiquidityCall): RemoveLiquidityBuildOutput { + public buildCall( + input: RemoveLiquidityBuildCallInput, + ): RemoveLiquidityBuildCallOutput { // TODO: refactor validators to take v3 into account const isV2Input = 'sender' in input; if (input.vaultVersion === 3 && isV2Input) diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index 740bdaba..a00495d6 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -6,8 +6,8 @@ import { vaultV2Abi } from '../../../../abi'; import { parseRemoveLiquidityArgs } from '../../../utils/parseRemoveLiquidityArgs'; import { RemoveLiquidityBase, - RemoveLiquidityComposableStableCall, - RemoveLiquidityBuildOutput, + RemoveLiquidityComposableStableBuildCallInput, + RemoveLiquidityBuildCallOutput, RemoveLiquidityInput, RemoveLiquidityKind, RemoveLiquidityQueryOutput, @@ -120,8 +120,8 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { } public buildCall( - input: RemoveLiquidityComposableStableCall, - ): RemoveLiquidityBuildOutput { + input: RemoveLiquidityComposableStableBuildCallInput, + ): RemoveLiquidityBuildCallOutput { const amounts = this.getAmountsCall(input); const amountsWithoutBpt = { ...amounts, @@ -167,7 +167,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { } private getAmountsCall( - input: RemoveLiquidityComposableStableCall, + input: RemoveLiquidityComposableStableBuildCallInput, ): RemoveLiquidityAmounts { switch (input.removeLiquidityKind) { case RemoveLiquidityKind.Unbalanced: diff --git a/src/entities/removeLiquidity/removeLiquidityV2/index.ts b/src/entities/removeLiquidity/removeLiquidityV2/index.ts index 6099a806..373f906f 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/index.ts @@ -1,8 +1,8 @@ import { PoolState, RemoveLiquidityBase, - RemoveLiquidityBuildOutput, - RemoveLiquidityCall, + RemoveLiquidityBuildCallOutput, + RemoveLiquidityBuildCallInput, RemoveLiquidityConfig, RemoveLiquidityInput, RemoveLiquidityQueryOutput, @@ -44,7 +44,9 @@ export class RemoveLiquidityV2 implements RemoveLiquidityBase { return this.getRemoveLiquidity(poolState.type).query(input, poolState); } - public buildCall(input: RemoveLiquidityCall): RemoveLiquidityBuildOutput { + public buildCall( + input: RemoveLiquidityBuildCallInput, + ): RemoveLiquidityBuildCallOutput { return this.getRemoveLiquidity(input.poolType).buildCall(input); } } diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index c2938d67..bee7559e 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -7,11 +7,11 @@ import { vaultV2Abi } from '../../../../abi'; import { parseRemoveLiquidityArgs } from '../../../utils/parseRemoveLiquidityArgs'; import { RemoveLiquidityBase, - RemoveLiquidityBuildOutput, + RemoveLiquidityBuildCallOutput, RemoveLiquidityInput, RemoveLiquidityKind, RemoveLiquidityQueryOutput, - RemoveLiquidityWeightedCall, + RemoveLiquidityWeightedBuildCallInput, } from '../../types'; import { PoolState } from '../../../types'; import { doRemoveLiquidityQuery } from '../../../utils/doRemoveLiquidityQuery'; @@ -72,8 +72,8 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { } public buildCall( - input: RemoveLiquidityWeightedCall, - ): RemoveLiquidityBuildOutput { + input: RemoveLiquidityWeightedBuildCallInput, + ): RemoveLiquidityBuildCallOutput { const amounts = getAmountsCall(input); const userData = WeightedEncoder.encodeRemoveLiquidityUserData( diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts index f2164919..1afb4b66 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquidityProportional.ts @@ -1,9 +1,9 @@ import { encodeFunctionData } from 'viem'; -import { RemoveLiquidityBaseCall } from '../types'; +import { RemoveLiquidityBaseBuildCallInput } from '../types'; import { balancerRouterAbi } from '@/abi'; export const encodeRemoveLiquidityProportional = ( - input: RemoveLiquidityBaseCall, + input: RemoveLiquidityBaseBuildCallInput, minAmountsOut: bigint[], ) => { return encodeFunctionData({ diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts index df0d06f8..dcedf575 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactIn.ts @@ -1,9 +1,9 @@ import { encodeFunctionData } from 'viem'; -import { RemoveLiquidityBaseCall } from '../types'; +import { RemoveLiquidityBaseBuildCallInput } from '../types'; import { balancerRouterAbi } from '@/abi'; export const encodeRemoveLiquiditySingleTokenExactIn = ( - input: RemoveLiquidityBaseCall, + input: RemoveLiquidityBaseBuildCallInput, minAmountsOut: bigint[], ) => { // just a sanity check as this is already checked in InputValidator diff --git a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts index 62380994..e8e845ec 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/encodeRemoveLiquiditySingleTokenExactOut.ts @@ -1,11 +1,11 @@ import { removeLiquiditySingleTokenExactInShouldHaveTokenOutIndexError } from '@/utils'; -import { RemoveLiquidityBaseCall } from '../types'; +import { RemoveLiquidityBaseBuildCallInput } from '../types'; import { encodeFunctionData } from 'viem'; import { balancerRouterAbi } from '@/abi'; import { Hex } from '@/types'; export const encodeRemoveLiquiditySingleTokenExactOut = ( - input: RemoveLiquidityBaseCall, + input: RemoveLiquidityBaseBuildCallInput, maxBptAmountIn: bigint, ): Hex => { // just a sanity check as this is already checked in InputValidator diff --git a/src/entities/removeLiquidity/removeLiquidityV3/index.ts b/src/entities/removeLiquidity/removeLiquidityV3/index.ts index a230890e..75b18c56 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/index.ts @@ -11,9 +11,9 @@ import { import { getAmountsCall, getAmountsQuery } from '../helper'; import { RemoveLiquidityBase, - RemoveLiquidityBaseCall, + RemoveLiquidityBaseBuildCallInput, RemoveLiquidityBaseQueryOutput, - RemoveLiquidityBuildOutput, + RemoveLiquidityBuildCallOutput, RemoveLiquidityInput, RemoveLiquidityKind, } from '../types'; @@ -100,8 +100,8 @@ export class RemoveLiquidityV3 implements RemoveLiquidityBase { } public buildCall( - input: RemoveLiquidityBaseCall, - ): RemoveLiquidityBuildOutput { + input: RemoveLiquidityBaseBuildCallInput, + ): RemoveLiquidityBuildCallOutput { const amounts = getAmountsCall(input); let call: Hex; diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index 29feac3f..be217dd3 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -77,27 +77,30 @@ export type RemoveLiquidityQueryOutput = | RemoveLiquidityComposableStableQueryOutput | RemoveLiquidityWeightedQueryOutput; -export type RemoveLiquidityBaseCall = { +export type RemoveLiquidityBaseBuildCallInput = { slippage: Slippage; chainId: number; wethIsEth?: boolean; } & RemoveLiquidityBaseQueryOutput; -export type RemoveLiquidityBaseCallV2 = RemoveLiquidityBaseCall & { - sender: Address; - recipient: Address; -}; +export type RemoveLiquidityBaseBuildCallInputV2 = + RemoveLiquidityBaseBuildCallInput & { + sender: Address; + recipient: Address; + }; -export type RemoveLiquidityComposableStableCall = RemoveLiquidityBaseCallV2 & - RemoveLiquidityComposableStableQueryOutput; -export type RemoveLiquidityWeightedCall = RemoveLiquidityBaseCallV2; +export type RemoveLiquidityComposableStableBuildCallInput = + RemoveLiquidityBaseBuildCallInputV2 & + RemoveLiquidityComposableStableQueryOutput; +export type RemoveLiquidityWeightedBuildCallInput = + RemoveLiquidityBaseBuildCallInputV2; -export type RemoveLiquidityCall = - | RemoveLiquidityBaseCall - | RemoveLiquidityComposableStableCall - | RemoveLiquidityWeightedCall; +export type RemoveLiquidityBuildCallInput = + | RemoveLiquidityBaseBuildCallInput + | RemoveLiquidityComposableStableBuildCallInput + | RemoveLiquidityWeightedBuildCallInput; -export type RemoveLiquidityBuildOutput = { +export type RemoveLiquidityBuildCallOutput = { call: Address; to: Address; value: bigint; @@ -110,7 +113,9 @@ export interface RemoveLiquidityBase { input: RemoveLiquidityInput, poolState: PoolState, ): Promise; - buildCall(input: RemoveLiquidityCall): RemoveLiquidityBuildOutput; + buildCall( + input: RemoveLiquidityBuildCallInput, + ): RemoveLiquidityBuildCallOutput; } export type RemoveLiquidityConfig = { diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 73c9bd71..1fed1f74 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -4,9 +4,9 @@ import { ChainId, NATIVE_ASSETS, PoolState, - RemoveLiquidityBaseCallV2, - RemoveLiquidityCall, - RemoveLiquidityBuildOutput, + RemoveLiquidityBaseBuildCallInputV2, + RemoveLiquidityBuildCallInput, + RemoveLiquidityBuildCallOutput, RemoveLiquidityComposableStableQueryOutput, RemoveLiquidityInput, RemoveLiquidityProportionalInput, @@ -27,7 +27,7 @@ import { RemoveLiquidityTxInput } from './types'; type RemoveLiquidityOutput = { removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; - removeLiquidityBuildOutput: RemoveLiquidityBuildOutput; + removeLiquidityBuildCallOutput: RemoveLiquidityBuildCallOutput; txOutput: TxOutput; }; @@ -39,7 +39,7 @@ export const sdkRemoveLiquidity = async ({ testAddress, wethIsEth, }: Omit): Promise<{ - removeLiquidityBuildOutput: RemoveLiquidityBuildOutput; + removeLiquidityBuildCallOutput: RemoveLiquidityBuildCallOutput; removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; }> => { const removeLiquidityQueryOutput = await removeLiquidity.query( @@ -47,26 +47,26 @@ export const sdkRemoveLiquidity = async ({ poolState, ); - let removeLiquidityBuildInput: RemoveLiquidityCall = { + let removeLiquidityBuildInput: RemoveLiquidityBuildCallInput = { ...removeLiquidityQueryOutput, slippage, chainId: removeLiquidityInput.chainId, wethIsEth: !!wethIsEth, }; if (poolState.vaultVersion === 2) { - (removeLiquidityBuildInput as RemoveLiquidityBaseCallV2) = { + (removeLiquidityBuildInput as RemoveLiquidityBaseBuildCallInputV2) = { ...removeLiquidityBuildInput, sender: testAddress, recipient: testAddress, }; } - const removeLiquidityBuildOutput = removeLiquidity.buildCall( + const removeLiquidityBuildCallOutput = removeLiquidity.buildCall( removeLiquidityBuildInput, ); return { - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, removeLiquidityQueryOutput, }; }; @@ -125,7 +125,7 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { wethIsEth, } = txInput; - const { removeLiquidityQueryOutput, removeLiquidityBuildOutput } = + const { removeLiquidityQueryOutput, removeLiquidityBuildCallOutput } = await sdkRemoveLiquidity({ removeLiquidity, removeLiquidityInput, @@ -143,14 +143,14 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { tokens, client, testAddress, - removeLiquidityBuildOutput.to, - removeLiquidityBuildOutput.call, - removeLiquidityBuildOutput.value, + removeLiquidityBuildCallOutput.to, + removeLiquidityBuildCallOutput.call, + removeLiquidityBuildCallOutput.value, ); return { removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, txOutput, }; } @@ -163,8 +163,11 @@ export function assertRemoveLiquidityUnbalanced( slippage: Slippage, wethIsEth?: boolean, ) { - const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = - removeLiquidityOutput; + const { + txOutput, + removeLiquidityQueryOutput, + removeLiquidityBuildCallOutput, + } = removeLiquidityOutput; // 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) => { @@ -199,9 +202,9 @@ export function assertRemoveLiquidityUnbalanced( // Expect some bpt amount expect(removeLiquidityQueryOutput.bptIn.amount > 0n).to.be.true; - assertRemoveLiquidityBuildOutput( + assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, false, slippage, chainId, @@ -225,8 +228,11 @@ export function assertRemoveLiquiditySingleTokenExactOut( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = - removeLiquidityOutput; + const { + txOutput, + removeLiquidityQueryOutput, + removeLiquidityBuildCallOutput, + } = removeLiquidityOutput; // 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) => { @@ -267,9 +273,9 @@ export function assertRemoveLiquiditySingleTokenExactOut( // Expect some bpt amount expect(removeLiquidityQueryOutput.bptIn.amount > 0n).to.be.true; - assertRemoveLiquidityBuildOutput( + assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, false, slippage, chainId, @@ -294,8 +300,11 @@ export function assertRemoveLiquiditySingleTokenExactIn( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = - removeLiquidityOutput; + const { + txOutput, + removeLiquidityQueryOutput, + removeLiquidityBuildCallOutput, + } = removeLiquidityOutput; if (removeLiquidityQueryOutput.tokenOutIndex === undefined) throw removeLiquiditySingleTokenExactInShouldHaveTokenOutIndexError; @@ -347,9 +356,9 @@ export function assertRemoveLiquiditySingleTokenExactIn( } }); - assertRemoveLiquidityBuildOutput( + assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, true, slippage, chainId, @@ -374,8 +383,11 @@ export function assertRemoveLiquidityProportional( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = - removeLiquidityOutput; + const { + txOutput, + removeLiquidityQueryOutput, + removeLiquidityBuildCallOutput, + } = removeLiquidityOutput; const bptToken = new Token(chainId, poolState.address, 18); @@ -417,9 +429,9 @@ export function assertRemoveLiquidityProportional( ).to.be.true; } - assertRemoveLiquidityBuildOutput( + assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, true, slippage, chainId, @@ -444,8 +456,11 @@ export function assertRemoveLiquidityRecovery( vaultVersion: 2 | 3 = 2, wethIsEth?: boolean, ) { - const { txOutput, removeLiquidityQueryOutput, removeLiquidityBuildOutput } = - removeLiquidityOutput; + const { + txOutput, + removeLiquidityQueryOutput, + removeLiquidityBuildCallOutput, + } = removeLiquidityOutput; const bptToken = new Token(chainId, poolState.address, 18); @@ -487,9 +502,9 @@ export function assertRemoveLiquidityRecovery( ).to.be.true; } - assertRemoveLiquidityBuildOutput( + assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput, - removeLiquidityBuildOutput, + removeLiquidityBuildCallOutput, true, slippage, chainId, @@ -549,9 +564,9 @@ function assertTokenDeltas( }); } -function assertRemoveLiquidityBuildOutput( +function assertRemoveLiquidityBuildCallOutput( removeLiquidityQueryOutput: RemoveLiquidityQueryOutput, - RemoveLiquidityBuildOutput: RemoveLiquidityBuildOutput, + RemoveLiquidityBuildCallOutput: RemoveLiquidityBuildCallOutput, isExactIn: boolean, slippage: Slippage, chainId: number, @@ -578,7 +593,7 @@ function assertRemoveLiquidityBuildOutput( const to = vaultVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId]; - const expectedBuildOutput: Omit = { + const expectedBuildOutput: Omit = { minAmountsOut, maxBptIn, to, @@ -586,6 +601,6 @@ function assertRemoveLiquidityBuildOutput( }; // biome-ignore lint/correctness/noUnusedVariables: - const { call, ...buildCheck } = RemoveLiquidityBuildOutput; + const { call, ...buildCheck } = RemoveLiquidityBuildCallOutput; expect(buildCheck).to.deep.eq(expectedBuildOutput); } From e0cf7b47d93bfc9b8a04f8e97b24b0706f4f359b Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 8 Mar 2024 14:02:26 -0300 Subject: [PATCH 23/29] Split remove liquidity types into versions --- .../addLiquidity/addLiquidityV2/types.ts | 4 +-- src/entities/addLiquidity/types.ts | 4 +-- .../removeLiquidityComposableStable.ts | 6 ++-- .../composableStable/types.ts | 11 ++++++++ .../removeLiquidityV2/types.ts | 28 +++++++++++++++++++ .../weighted/removeLiquidityWeighted.ts | 4 +-- src/entities/removeLiquidity/types.ts | 28 ++++--------------- test/lib/utils/removeLiquidityHelper.ts | 16 +++++------ 8 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 src/entities/removeLiquidity/removeLiquidityV2/composableStable/types.ts create mode 100644 src/entities/removeLiquidity/removeLiquidityV2/types.ts diff --git a/src/entities/addLiquidity/addLiquidityV2/types.ts b/src/entities/addLiquidity/addLiquidityV2/types.ts index 85763391..4d79c5d5 100644 --- a/src/entities/addLiquidity/addLiquidityV2/types.ts +++ b/src/entities/addLiquidity/addLiquidityV2/types.ts @@ -1,4 +1,4 @@ -import { Address } from 'viem'; +import { Address } from '@/types'; import { AddLiquidityBaseBuildCallInput, AddLiquidityBaseQueryOutput, @@ -23,6 +23,6 @@ export type AddLiquidityV2BaseQueryOutput = AddLiquidityBaseQueryOutput & { vaultVersion: 2; }; -export type AddLiqudityV2QueryOutput = +export type AddLiquidityV2QueryOutput = | AddLiquidityV2BaseQueryOutput | AddLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index aa627423..39f97a18 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -4,7 +4,7 @@ import { PoolState } from '../types'; import { Address, Hex, InputAmount } from '../../types'; import { AddLiquidityV2BuildCallInput, - AddLiqudityV2QueryOutput, + AddLiquidityV2QueryOutput, } from './addLiquidityV2/types'; export enum AddLiquidityKind { @@ -52,7 +52,7 @@ export type AddLiquidityBaseQueryOutput = { export type AddLiquidityQueryOutput = | AddLiquidityBaseQueryOutput - | AddLiqudityV2QueryOutput; + | AddLiquidityV2QueryOutput; export type AddLiquidityBaseBuildCallInput = { slippage: Slippage; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index a00495d6..d7172451 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -6,12 +6,12 @@ import { vaultV2Abi } from '../../../../abi'; import { parseRemoveLiquidityArgs } from '../../../utils/parseRemoveLiquidityArgs'; import { RemoveLiquidityBase, - RemoveLiquidityComposableStableBuildCallInput, RemoveLiquidityBuildCallOutput, RemoveLiquidityInput, RemoveLiquidityKind, RemoveLiquidityQueryOutput, } from '../../types'; +import { RemoveLiquidityV2ComposableStableBuildCallInput } from './types'; import { RemoveLiquidityAmounts, PoolState } from '../../../types'; import { doRemoveLiquidityQuery } from '../../../utils/doRemoveLiquidityQuery'; import { ComposableStableEncoder } from '../../../encoders/composableStable'; @@ -120,7 +120,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { } public buildCall( - input: RemoveLiquidityComposableStableBuildCallInput, + input: RemoveLiquidityV2ComposableStableBuildCallInput, ): RemoveLiquidityBuildCallOutput { const amounts = this.getAmountsCall(input); const amountsWithoutBpt = { @@ -167,7 +167,7 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { } private getAmountsCall( - input: RemoveLiquidityComposableStableBuildCallInput, + input: RemoveLiquidityV2ComposableStableBuildCallInput, ): RemoveLiquidityAmounts { switch (input.removeLiquidityKind) { case RemoveLiquidityKind.Unbalanced: diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/types.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/types.ts new file mode 100644 index 00000000..0bbb1bb6 --- /dev/null +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/types.ts @@ -0,0 +1,11 @@ +import { RemoveLiquidityBaseQueryOutput } from '../../types'; +import { RemoveLiquidityV2BaseBuildCallInput } from '../types'; + +export type RemoveLiquidityV2ComposableStableQueryOutput = + RemoveLiquidityBaseQueryOutput & { + bptIndex: number; + }; + +export type RemoveLiquidityV2ComposableStableBuildCallInput = + RemoveLiquidityV2BaseBuildCallInput & + RemoveLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/types.ts b/src/entities/removeLiquidity/removeLiquidityV2/types.ts new file mode 100644 index 00000000..3328af62 --- /dev/null +++ b/src/entities/removeLiquidity/removeLiquidityV2/types.ts @@ -0,0 +1,28 @@ +import { Address } from '@/types'; +import { + RemoveLiquidityBaseBuildCallInput, + RemoveLiquidityBaseQueryOutput, +} from '../types'; +import { + RemoveLiquidityV2ComposableStableBuildCallInput, + RemoveLiquidityV2ComposableStableQueryOutput, +} from './composableStable/types'; + +export type RemoveLiquidityV2BaseBuildCallInput = + RemoveLiquidityBaseBuildCallInput & { + sender: Address; + recipient: Address; + }; + +export type RemoveLiquidityV2BuildCallInput = + | RemoveLiquidityV2BaseBuildCallInput + | RemoveLiquidityV2ComposableStableBuildCallInput; + +export type RemoveLiquidityV2BaseQueryOutput = + RemoveLiquidityBaseQueryOutput & { + vaultVersion: 2; + }; + +export type RemoveLiquidityV2QueryOutput = + | RemoveLiquidityV2BaseQueryOutput + | RemoveLiquidityV2ComposableStableQueryOutput; diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index bee7559e..f6a3a803 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -11,12 +11,12 @@ import { RemoveLiquidityInput, RemoveLiquidityKind, RemoveLiquidityQueryOutput, - RemoveLiquidityWeightedBuildCallInput, } from '../../types'; import { PoolState } from '../../../types'; import { doRemoveLiquidityQuery } from '../../../utils/doRemoveLiquidityQuery'; import { getSortedTokens } from '../../../utils'; import { getAmountsCall, getAmountsQuery } from '../../helper'; +import { RemoveLiquidityV2BaseBuildCallInput } from '../types'; export class RemoveLiquidityWeighted implements RemoveLiquidityBase { public async query( @@ -72,7 +72,7 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { } public buildCall( - input: RemoveLiquidityWeightedBuildCallInput, + input: RemoveLiquidityV2BaseBuildCallInput, ): RemoveLiquidityBuildCallOutput { const amounts = getAmountsCall(input); diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index be217dd3..a7024e7b 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -2,6 +2,10 @@ import { TokenAmount } from '../tokenAmount'; import { Slippage } from '../slippage'; import { Address, InputAmount } from '../../types'; import { PoolState } from '../types'; +import { + RemoveLiquidityV2BuildCallInput, + RemoveLiquidityV2QueryOutput, +} from './removeLiquidityV2/types'; export enum RemoveLiquidityKind { Unbalanced = 'Unbalanced', // exact out @@ -66,16 +70,9 @@ export type RemoveLiquidityBaseQueryOutput = { chainId: number; }; -export type RemoveLiquidityComposableStableQueryOutput = - RemoveLiquidityBaseQueryOutput & { - bptIndex: number; - }; -export type RemoveLiquidityWeightedQueryOutput = RemoveLiquidityBaseQueryOutput; - export type RemoveLiquidityQueryOutput = | RemoveLiquidityBaseQueryOutput - | RemoveLiquidityComposableStableQueryOutput - | RemoveLiquidityWeightedQueryOutput; + | RemoveLiquidityV2QueryOutput; export type RemoveLiquidityBaseBuildCallInput = { slippage: Slippage; @@ -83,22 +80,9 @@ export type RemoveLiquidityBaseBuildCallInput = { wethIsEth?: boolean; } & RemoveLiquidityBaseQueryOutput; -export type RemoveLiquidityBaseBuildCallInputV2 = - RemoveLiquidityBaseBuildCallInput & { - sender: Address; - recipient: Address; - }; - -export type RemoveLiquidityComposableStableBuildCallInput = - RemoveLiquidityBaseBuildCallInputV2 & - RemoveLiquidityComposableStableQueryOutput; -export type RemoveLiquidityWeightedBuildCallInput = - RemoveLiquidityBaseBuildCallInputV2; - export type RemoveLiquidityBuildCallInput = | RemoveLiquidityBaseBuildCallInput - | RemoveLiquidityComposableStableBuildCallInput - | RemoveLiquidityWeightedBuildCallInput; + | RemoveLiquidityV2BuildCallInput; export type RemoveLiquidityBuildCallOutput = { call: Address; diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 1fed1f74..389d0afc 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -4,10 +4,10 @@ import { ChainId, NATIVE_ASSETS, PoolState, - RemoveLiquidityBaseBuildCallInputV2, + RemoveLiquidityV2BaseBuildCallInput, RemoveLiquidityBuildCallInput, RemoveLiquidityBuildCallOutput, - RemoveLiquidityComposableStableQueryOutput, + RemoveLiquidityV2ComposableStableQueryOutput, RemoveLiquidityInput, RemoveLiquidityProportionalInput, RemoveLiquidityQueryOutput, @@ -54,7 +54,7 @@ export const sdkRemoveLiquidity = async ({ wethIsEth: !!wethIsEth, }; if (poolState.vaultVersion === 2) { - (removeLiquidityBuildInput as RemoveLiquidityBaseBuildCallInputV2) = { + (removeLiquidityBuildInput as RemoveLiquidityV2BaseBuildCallInput) = { ...removeLiquidityBuildInput, sender: testAddress, recipient: testAddress, @@ -71,27 +71,27 @@ export const sdkRemoveLiquidity = async ({ }; }; -function isRemoveLiquidityComposableStableQueryOutput( +function isRemoveLiquidityV2ComposableStableQueryOutput( output: RemoveLiquidityQueryOutput, ): boolean { return ( - (output as RemoveLiquidityComposableStableQueryOutput).bptIndex !== + (output as RemoveLiquidityV2ComposableStableQueryOutput).bptIndex !== undefined ); } function getCheck(output: RemoveLiquidityQueryOutput, isExactIn: boolean) { - if (isRemoveLiquidityComposableStableQueryOutput(output)) { + if (isRemoveLiquidityV2ComposableStableQueryOutput(output)) { if (isExactIn) { // Using this destructuring to return only the fields of interest // biome-ignore lint/correctness/noUnusedVariables: const { amountsOut, bptIndex, ...check } = - output as RemoveLiquidityComposableStableQueryOutput; + output as RemoveLiquidityV2ComposableStableQueryOutput; return check; } // biome-ignore lint/correctness/noUnusedVariables: const { bptIn, bptIndex, ...check } = - output as RemoveLiquidityComposableStableQueryOutput; + output as RemoveLiquidityV2ComposableStableQueryOutput; return check; } if (isExactIn) { From 36f2388990c39f2fe55f3c10f70131f761c5084c Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 8 Mar 2024 14:26:07 -0300 Subject: [PATCH 24/29] Move toInternalBalance to remove liquidity buildCall interface --- .../addLiquidityV2/weighted/addLiquidityWeighted.ts | 1 - .../removeLiquidityComposableStable.ts | 2 -- .../removeLiquidity/removeLiquidityV2/types.ts | 1 + .../weighted/removeLiquidityWeighted.ts | 2 -- .../removeLiquidity/removeLiquidityV3/index.ts | 1 - src/entities/removeLiquidity/types.ts | 2 -- src/entities/utils/parseAddLiquidityArgs.ts | 4 ++-- src/entities/utils/parseRemoveLiquidityArgs.ts | 4 ++-- test/lib/utils/addLiquidityHelper.ts | 4 +++- test/lib/utils/removeLiquidityHelper.ts | 11 ++++------- test/lib/utils/types.ts | 2 ++ 11 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 2e8dc6e1..6e1650ba 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -44,7 +44,6 @@ export class AddLiquidityWeighted implements AddLiquidityBase { recipient: ZERO_ADDRESS, maxAmountsIn: amounts.maxAmountsIn, userData, - fromInternalBalance: false, // This isn't required for the query }); const queryOutput = await doAddLiquidityQuery( diff --git a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts index d7172451..f59bd00b 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/composableStable/removeLiquidityComposableStable.ts @@ -51,7 +51,6 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { recipient: ZERO_ADDRESS, minAmountsOut: amounts.minAmountsOut, userData, - toInternalBalance: !!input.toInternalBalance, }); const queryOutput = await doRemoveLiquidityQuery( input.rpcUrl, @@ -72,7 +71,6 @@ export class RemoveLiquidityComposableStable implements RemoveLiquidityBase { bptIn, amountsOut, tokenOutIndex: amounts.tokenOutIndex, - toInternalBalance: !!input.toInternalBalance, bptIndex, vaultVersion: poolState.vaultVersion, chainId: input.chainId, diff --git a/src/entities/removeLiquidity/removeLiquidityV2/types.ts b/src/entities/removeLiquidity/removeLiquidityV2/types.ts index 3328af62..c36f4f73 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/types.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/types.ts @@ -12,6 +12,7 @@ export type RemoveLiquidityV2BaseBuildCallInput = RemoveLiquidityBaseBuildCallInput & { sender: Address; recipient: Address; + toInternalBalance?: boolean; }; export type RemoveLiquidityV2BuildCallInput = diff --git a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts index f6a3a803..fad52fb2 100644 --- a/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts +++ b/src/entities/removeLiquidity/removeLiquidityV2/weighted/removeLiquidityWeighted.ts @@ -42,7 +42,6 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { recipient: ZERO_ADDRESS, minAmountsOut: amounts.minAmountsOut, userData, - toInternalBalance: !!input.toInternalBalance, }); const queryOutput = await doRemoveLiquidityQuery( @@ -65,7 +64,6 @@ export class RemoveLiquidityWeighted implements RemoveLiquidityBase { bptIn, amountsOut, tokenOutIndex: amounts.tokenOutIndex, - toInternalBalance: !!input.toInternalBalance, vaultVersion: poolState.vaultVersion, chainId: input.chainId, }; diff --git a/src/entities/removeLiquidity/removeLiquidityV3/index.ts b/src/entities/removeLiquidity/removeLiquidityV3/index.ts index 75b18c56..a2fa9151 100644 --- a/src/entities/removeLiquidity/removeLiquidityV3/index.ts +++ b/src/entities/removeLiquidity/removeLiquidityV3/index.ts @@ -91,7 +91,6 @@ export class RemoveLiquidityV3 implements RemoveLiquidityBase { TokenAmount.fromRawAmount(t, minAmountsOut[i]), ), tokenOutIndex: amounts.tokenOutIndex, - toInternalBalance: !!input.toInternalBalance, vaultVersion: poolState.vaultVersion, chainId: input.chainId, }; diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index a7024e7b..1297a9ff 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -19,7 +19,6 @@ export enum RemoveLiquidityKind { export type RemoveLiquidityBaseInput = { chainId: number; rpcUrl: string; - toInternalBalance?: boolean; }; export type RemoveLiquidityUnbalancedInput = RemoveLiquidityBaseInput & { @@ -65,7 +64,6 @@ export type RemoveLiquidityBaseQueryOutput = { bptIn: TokenAmount; amountsOut: TokenAmount[]; tokenOutIndex?: number; - toInternalBalance: boolean; vaultVersion: 2 | 3; chainId: number; }; diff --git a/src/entities/utils/parseAddLiquidityArgs.ts b/src/entities/utils/parseAddLiquidityArgs.ts index 3429c184..54572f1f 100644 --- a/src/entities/utils/parseAddLiquidityArgs.ts +++ b/src/entities/utils/parseAddLiquidityArgs.ts @@ -21,7 +21,7 @@ export function parseAddLiquidityArgs({ recipient: Address; maxAmountsIn: readonly bigint[]; userData: Hex; - fromInternalBalance: boolean; + fromInternalBalance?: boolean; }) { // replace wrapped token with native asset if needed const tokensIn = @@ -33,7 +33,7 @@ export function parseAddLiquidityArgs({ assets: tokensIn.map((t) => t.address), // with BPT maxAmountsIn, // with BPT userData, // wihtout BPT - fromInternalBalance, + fromInternalBalance: !!fromInternalBalance, }; return { diff --git a/src/entities/utils/parseRemoveLiquidityArgs.ts b/src/entities/utils/parseRemoveLiquidityArgs.ts index a73e05e4..08ba1e08 100644 --- a/src/entities/utils/parseRemoveLiquidityArgs.ts +++ b/src/entities/utils/parseRemoveLiquidityArgs.ts @@ -22,7 +22,7 @@ export function parseRemoveLiquidityArgs({ recipient: Address; minAmountsOut: bigint[]; userData: Address; - toInternalBalance: boolean; + toInternalBalance?: boolean; }) { // replace wrapped token with native asset if needed const tokensOut = @@ -34,7 +34,7 @@ export function parseRemoveLiquidityArgs({ assets: tokensOut.map((t) => t.address), // with BPT minAmountsOut, // with BPT userData, // wihtout BPT - toInternalBalance, + toInternalBalance: !!toInternalBalance, }; return { diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 2649e5c3..876d738e 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -37,6 +37,7 @@ async function sdkAddLiquidity({ slippage, testAddress, wethIsEth, + fromInternalBalance, }: { addLiquidity: AddLiquidity; addLiquidityInput: AddLiquidityInput; @@ -44,6 +45,7 @@ async function sdkAddLiquidity({ slippage: Slippage; testAddress: Address; wethIsEth?: boolean; + fromInternalBalance?: boolean; }): Promise<{ addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput; addLiquidityQueryOutput: AddLiquidityQueryOutput; @@ -64,7 +66,7 @@ async function sdkAddLiquidity({ ...addLiquidityBuildInput, sender: testAddress, recipient: testAddress, - fromInternalBalance: false, + fromInternalBalance: !!fromInternalBalance, }; } diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 389d0afc..1fae6151 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -4,10 +4,8 @@ import { ChainId, NATIVE_ASSETS, PoolState, - RemoveLiquidityV2BaseBuildCallInput, RemoveLiquidityBuildCallInput, RemoveLiquidityBuildCallOutput, - RemoveLiquidityV2ComposableStableQueryOutput, RemoveLiquidityInput, RemoveLiquidityProportionalInput, RemoveLiquidityQueryOutput, @@ -24,6 +22,8 @@ import { import { getTokensForBalanceCheck } from './getTokensForBalanceCheck'; import { sendTransactionGetBalances, TxOutput } from './helper'; import { RemoveLiquidityTxInput } from './types'; +import { RemoveLiquidityV2BaseBuildCallInput } from '@/entities/removeLiquidity/removeLiquidityV2/types'; +import { RemoveLiquidityV2ComposableStableQueryOutput } from '@/entities/removeLiquidity/removeLiquidityV2/composableStable/types'; type RemoveLiquidityOutput = { removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; @@ -38,6 +38,7 @@ export const sdkRemoveLiquidity = async ({ slippage, testAddress, wethIsEth, + toInternalBalance, }: Omit): Promise<{ removeLiquidityBuildCallOutput: RemoveLiquidityBuildCallOutput; removeLiquidityQueryOutput: RemoveLiquidityQueryOutput; @@ -58,6 +59,7 @@ export const sdkRemoveLiquidity = async ({ ...removeLiquidityBuildInput, sender: testAddress, recipient: testAddress, + toInternalBalance: !!toInternalBalance, }; } @@ -189,7 +191,6 @@ export function assertRemoveLiquidityUnbalanced( // Should match inputs poolId: poolState.id, poolType: poolState.type, - toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, chainId, @@ -260,7 +261,6 @@ export function assertRemoveLiquiditySingleTokenExactOut( // Should match inputs poolId: poolState.id, poolType: poolState.type, - toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, chainId, @@ -330,7 +330,6 @@ export function assertRemoveLiquiditySingleTokenExactIn( // Should match inputs poolId: poolState.id, poolType: poolState.type, - toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, chainId, @@ -405,7 +404,6 @@ export function assertRemoveLiquidityProportional( // Should match inputs poolId: poolState.id, poolType: poolState.type, - toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, chainId, @@ -478,7 +476,6 @@ export function assertRemoveLiquidityRecovery( // Should match inputs poolId: poolState.id, poolType: poolState.type, - toInternalBalance: !!removeLiquidityInput.toInternalBalance, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, chainId, diff --git a/test/lib/utils/types.ts b/test/lib/utils/types.ts index 7866bdb7..0dfd0d8a 100644 --- a/test/lib/utils/types.ts +++ b/test/lib/utils/types.ts @@ -23,6 +23,7 @@ export type AddLiquidityTxInput = { poolState: PoolState; testAddress: Address; wethIsEth?: boolean; + fromInternalBalance?: boolean; }; export type InitPoolTxInput = Omit< @@ -41,6 +42,7 @@ export type RemoveLiquidityTxInput = { poolState: PoolState; testAddress: Address; wethIsEth?: boolean; + toInternalBalance?: boolean; }; export type CreatePoolTxInput = { From 787b16c8150c90dfcc0243aacb74d86b94787676 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Mon, 11 Mar 2024 15:25:29 -0300 Subject: [PATCH 25/29] Remove AddLiquidity reference from InitPool interface --- src/entities/initPool/types.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/entities/initPool/types.ts b/src/entities/initPool/types.ts index cdb61598..ab1d0be3 100644 --- a/src/entities/initPool/types.ts +++ b/src/entities/initPool/types.ts @@ -1,8 +1,4 @@ import { Address, Hex } from 'viem'; -import { - AddLiquidityBaseInput, - AddLiquidityBuildCallOutput, -} from '../addLiquidity/types'; import { InputAmount } from '../../types'; import { PoolState } from '../types'; @@ -10,26 +6,28 @@ export interface InitPoolBase { buildCall(input: InitPoolInput, poolState: PoolState): InitPoolBuildOutput; } -export type InitPoolBuildOutput = Omit< - AddLiquidityBuildCallOutput, - 'minBptOut' | 'maxAmountsIn' ->; +export type InitPoolBuildOutput = { + call: Hex; + to: Address; + value: bigint; +}; export type InitPoolInput = InitPoolInputV2 | InitPoolInputV3; -export type InitPoolInputV2 = Omit & { - sender: Address; - recipient: Address; +type InitBaseInput = { amountsIn: InputAmount[]; chainId: number; + wethIsEth?: boolean; +}; + +export type InitPoolInputV2 = InitBaseInput & { + sender: Address; + recipient: Address; fromInternalBalance?: boolean; }; -export type InitPoolInputV3 = { - amountsIn: InputAmount[]; +export type InitPoolInputV3 = InitBaseInput & { minBptAmountOut: bigint; - wethIsEth?: boolean; - chainId: number; }; export type InitPoolConfig = { From 8c980eefd60116004ad1ce9c6b5cb0d38e3c4e5b Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Mon, 11 Mar 2024 15:32:16 -0300 Subject: [PATCH 26/29] Extract value calculation to helper file --- examples/removeLiquidityNested.ts | 6 ++--- .../addLiquidityComposableStable.ts | 4 ++-- .../weighted/addLiquidityWeighted.ts | 5 +++-- .../addLiquidity/addLiquidityV3/index.ts | 17 ++------------ src/entities/addLiquidity/helpers.ts | 12 ---------- .../addLiquidityNested/encodeCalls.ts | 21 ++++++++---------- src/entities/addLiquidityNested/index.ts | 2 +- .../initPoolComposableStable.ts | 14 +++++++----- .../initPoolV2/weighted/initPoolWeighted.ts | 13 ++++++----- src/entities/initPool/initPoolV3.ts | 22 +++++++------------ src/entities/utils/getValue.ts | 16 ++++++++++++++ 11 files changed, 61 insertions(+), 71 deletions(-) create mode 100644 src/entities/utils/getValue.ts diff --git a/examples/removeLiquidityNested.ts b/examples/removeLiquidityNested.ts index 207ad9c4..7c3bea7a 100644 --- a/examples/removeLiquidityNested.ts +++ b/examples/removeLiquidityNested.ts @@ -89,18 +89,18 @@ const removeLiquidityNested = async () => { client, ); - const receiveNativeAsset = false; + const wethIsEth = false; const { call, to, minAmountsOut } = removeLiquidityNested.buildCall({ ...queryOutput, slippage, accountAddress, relayerApprovalSignature: signature, - receiveNativeAsset, + wethIsEth, }); let tokensOut = queryOutput.amountsOut.map((a) => a.token); - if (receiveNativeAsset) { + if (wethIsEth) { tokensOut = replaceWrapped(tokensOut, chainId); } diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index cd4cf4f2..660b2ab7 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -20,7 +20,7 @@ import { parseAddLiquidityArgs, } from '@/entities/utils'; import { ComposableStableEncoder } from '@/entities/encoders/composableStable'; -import { getValue } from '../../helpers'; +import { getValue } from '../../../utils/getValue'; import { AddLiquidityV2ComposableStableBuildCallInput, AddLiquidityV2ComposableStableQueryOutput, @@ -110,7 +110,7 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { return { call, to: VAULT[input.chainId], - value: getValue(input), + value: getValue(input.amountsIn, !!input.wethIsEth), minBptOut: TokenAmount.fromRawAmount( input.bptOut.token, amounts.minimumBpt, diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 6e1650ba..9f87f7c5 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -17,7 +17,8 @@ import { getSortedTokens, parseAddLiquidityArgs, } from '@/entities/utils'; -import { getAmountsCall, getValue } from '../../helpers'; +import { getAmountsCall } from '../../helpers'; +import { getValue } from '../../../utils/getValue'; import { AddLiquidityV2BaseBuildCallInput, AddLiquidityV2BaseQueryOutput, @@ -98,7 +99,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { return { call, to: VAULT[input.chainId], - value: getValue(input), + value: getValue(input.amountsIn, !!input.wethIsEth), minBptOut: TokenAmount.fromRawAmount( input.bptOut.token, amounts.minimumBpt, diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index 90259fb8..c1d08276 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -7,7 +7,6 @@ import { getAmounts, getSortedTokens } from '@/entities/utils'; import { Hex } from '@/types'; import { BALANCER_ROUTER, - NATIVE_ASSETS, addLiquidityProportionalUnavailableError, addLiquiditySingleTokenShouldHaveTokenInIndexError, } from '@/utils'; @@ -23,6 +22,7 @@ import { } from '../types'; import { doAddLiquidityUnbalancedQuery } from './doAddLiquidityUnbalancedQuery'; import { doAddLiquiditySingleTokenQuery } from './doAddLiquiditySingleTokenQuery'; +import { getValue } from '@/entities/utils/getValue'; export class AddLiquidityV3 implements AddLiquidityBase { async query( @@ -131,23 +131,10 @@ export class AddLiquidityV3 implements AddLiquidityBase { break; } - let value = 0n; - if (input.wethIsEth) { - const wrappedNativeAssetInput = input.amountsIn.find( - (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, - ); - if (wrappedNativeAssetInput === undefined) { - throw new Error( - 'wethIsEth requires wrapped native asset as input', - ); - } - value = wrappedNativeAssetInput.amount; - } - return { call, to: BALANCER_ROUTER[input.chainId], - value, + value: getValue(input.amountsIn, !!input.wethIsEth), minBptOut: TokenAmount.fromRawAmount( input.bptOut.token, amounts.minimumBpt, diff --git a/src/entities/addLiquidity/helpers.ts b/src/entities/addLiquidity/helpers.ts index 0635c44f..f40319f5 100644 --- a/src/entities/addLiquidity/helpers.ts +++ b/src/entities/addLiquidity/helpers.ts @@ -1,4 +1,3 @@ -import { NATIVE_ASSETS } from '@/utils'; import { AddLiquidityAmounts } from '../types'; import { AddLiquidityBaseBuildCallInput, AddLiquidityKind } from './types'; @@ -26,14 +25,3 @@ export const getAmountsCall = ( } } }; - -export const getValue = (input: AddLiquidityBaseBuildCallInput): bigint => { - let value = 0n; - if (input.wethIsEth) { - value = - input.amountsIn.find( - (a) => a.token.address === NATIVE_ASSETS[input.chainId].wrapped, - )?.amount ?? 0n; - } - return value; -}; diff --git a/src/entities/addLiquidityNested/encodeCalls.ts b/src/entities/addLiquidityNested/encodeCalls.ts index 9c5e8186..f20af1de 100644 --- a/src/entities/addLiquidityNested/encodeCalls.ts +++ b/src/entities/addLiquidityNested/encodeCalls.ts @@ -1,11 +1,12 @@ import { Hex, PoolType } from '../../types'; -import { ZERO_ADDRESS } from '../../utils'; import { WeightedEncoder } from '../encoders'; import { ComposableStableEncoder } from '../encoders/composableStable'; import { AddLiquidityNestedCallAttributes } from './types'; import { replaceWrapped } from '../utils/replaceWrapped'; import { batchRelayerLibraryAbi } from '../../abi'; import { encodeFunctionData } from 'viem'; +import { TokenAmount } from '../tokenAmount'; +import { getValue } from '../utils/getValue'; export const encodeCalls = ( callsAttributes: AddLiquidityNestedCallAttributes[], @@ -30,18 +31,14 @@ export const encodeCalls = ( } = callAttributes; // replace wrapped token with native asset if needed - let tokensIn = [...sortedTokens]; + const tokensIn = wethIsEth + ? replaceWrapped([...sortedTokens], chainId) + : [...sortedTokens]; - let value = 0n; - if (wethIsEth) { - tokensIn = replaceWrapped([...sortedTokens], chainId); - const nativeAssetIndex = tokensIn.findIndex((t) => - t.isSameAddress(ZERO_ADDRESS), - ); - if (nativeAssetIndex > -1) { - value = maxAmountsIn[nativeAssetIndex].amount; - } - } + const amountsIn = [...sortedTokens].map((t, i) => { + return TokenAmount.fromRawAmount(t, maxAmountsIn[i].amount); + }); + const value = getValue(amountsIn, !!wethIsEth); const _maxAmountsIn = maxAmountsIn.map((a) => a.amount); const amountsInWithoutBpt = _maxAmountsIn.filter( diff --git a/src/entities/addLiquidityNested/index.ts b/src/entities/addLiquidityNested/index.ts index fb7c9fe2..0a595481 100644 --- a/src/entities/addLiquidityNested/index.ts +++ b/src/entities/addLiquidityNested/index.ts @@ -76,7 +76,7 @@ export class AddLiquidityNested { minBptOut, }; - // update sendNativeAsset flag + sender and recipient placeholders + // update wethIsEth flag + sender and recipient placeholders input.callsAttributes = input.callsAttributes.map((call) => { return { ...call, diff --git a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts index 63916a2b..b3b87228 100644 --- a/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts +++ b/src/entities/initPool/initPoolV2/composableStable/initPoolComposableStable.ts @@ -12,8 +12,10 @@ import { InitPoolInputV2, } from '../../types'; import { vaultV2Abi } from '../../../../abi'; -import { VAULT, MAX_UINT256, ZERO_ADDRESS } from '../../../../utils'; +import { VAULT, MAX_UINT256 } from '../../../../utils'; import { Token } from '@/entities/token'; +import { getValue } from '@/entities/utils/getValue'; +import { TokenAmount } from '@/entities/tokenAmount'; export class InitPoolComposableStable implements InitPoolBase { buildCall( @@ -33,6 +35,7 @@ export class InitPoolComposableStable implements InitPoolBase { maxAmountsIn: amounts.maxAmountsIn, userData, fromInternalBalance: input.fromInternalBalance ?? false, + wethIsEth: !!input.wethIsEth, }); const call = encodeFunctionData({ abi: vaultV2Abi, @@ -40,14 +43,15 @@ export class InitPoolComposableStable implements InitPoolBase { args, }); - const value = input.amountsIn.find( - (a) => a.address === ZERO_ADDRESS, - )?.rawAmount; + const amountsIn = input.amountsIn.map((a) => { + const token = new Token(input.chainId, a.address, a.decimals); + return TokenAmount.fromRawAmount(token, a.rawAmount); + }); return { call, to: VAULT[input.chainId] as Address, - value: value === undefined ? 0n : value, + value: getValue(amountsIn, !!input.wethIsEth), }; } diff --git a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts index 1ce10760..44f014d0 100644 --- a/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts +++ b/src/entities/initPool/initPoolV2/weighted/initPoolWeighted.ts @@ -5,7 +5,7 @@ import { InitPoolBuildOutput, InitPoolInputV2, } from '../../types'; -import { VAULT, ZERO_ADDRESS } from '../../../../utils'; +import { VAULT } from '../../../../utils'; import { vaultV2Abi } from '../../../../abi'; import { getAmounts, @@ -14,6 +14,8 @@ import { } from '../../../utils'; import { Token } from '../../../token'; import { WeightedEncoder } from '../../../encoders'; +import { TokenAmount } from '@/entities/tokenAmount'; +import { getValue } from '@/entities/utils/getValue'; export class InitPoolWeighted implements InitPoolBase { buildCall( @@ -38,14 +40,15 @@ export class InitPoolWeighted implements InitPoolBase { args, }); - const value = input.amountsIn.find( - (a) => a.address === ZERO_ADDRESS, - )?.rawAmount; + const amountsIn = input.amountsIn.map((a) => { + const token = new Token(input.chainId, a.address, a.decimals); + return TokenAmount.fromRawAmount(token, a.rawAmount); + }); return { call, to: VAULT[input.chainId] as Address, - value: value === undefined ? 0n : value, + value: getValue(amountsIn, !!input.wethIsEth), }; } diff --git a/src/entities/initPool/initPoolV3.ts b/src/entities/initPool/initPoolV3.ts index ba5c5f59..cf4f2d04 100644 --- a/src/entities/initPool/initPoolV3.ts +++ b/src/entities/initPool/initPoolV3.ts @@ -1,10 +1,12 @@ import { balancerRouterAbi } from '@/abi'; import { PoolState } from '../types'; import { InitPoolBase, InitPoolBuildOutput, InitPoolInputV3 } from './types'; -import { BALANCER_ROUTER, NATIVE_ASSETS, isSameAddress } from '@/utils'; +import { BALANCER_ROUTER } from '@/utils'; import { encodeFunctionData, Address } from 'viem'; import { getSortedTokens, parseInitializeArgs, getAmounts } from '../utils'; import { Token } from '../token'; +import { TokenAmount } from '../tokenAmount'; +import { getValue } from '../utils/getValue'; export class InitPoolV3 implements InitPoolBase { buildCall( @@ -26,12 +28,15 @@ export class InitPoolV3 implements InitPoolBase { args, }); - const value = this.value(input); + const amountsIn = input.amountsIn.map((a) => { + const token = new Token(input.chainId, a.address, a.decimals); + return TokenAmount.fromRawAmount(token, a.rawAmount); + }); return { call, to: BALANCER_ROUTER[input.chainId] as Address, - value, + value: getValue(amountsIn, !!input.wethIsEth), }; } @@ -43,15 +48,4 @@ export class InitPoolV3 implements InitPoolBase { exactAmountsIn: getAmounts(tokens, input.amountsIn), }; } - - private value(input: InitPoolInputV3) { - return input.wethIsEth - ? (input.amountsIn.find((a) => - isSameAddress( - a.address, - NATIVE_ASSETS[input.chainId].wrapped, - ), - )?.rawAmount as bigint) - : 0n; - } } diff --git a/src/entities/utils/getValue.ts b/src/entities/utils/getValue.ts new file mode 100644 index 00000000..5c3ea63b --- /dev/null +++ b/src/entities/utils/getValue.ts @@ -0,0 +1,16 @@ +import { NATIVE_ASSETS } from '@/utils'; +import { TokenAmount } from '../tokenAmount'; + +export const getValue = ( + amountsIn: TokenAmount[], + wethIsEth: boolean, +): bigint => { + let value = 0n; + if (wethIsEth) { + value = + amountsIn.find((a) => + a.token.isUnderlyingEqual(NATIVE_ASSETS[a.token.chainId]), + )?.amount ?? 0n; + } + return value; +}; From dfacb047de85b3bb92cc1112139a41bb1d03d54e Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Mon, 11 Mar 2024 15:37:08 -0300 Subject: [PATCH 27/29] Add changeset --- .changeset/curly-shrimps-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curly-shrimps-jog.md diff --git a/.changeset/curly-shrimps-jog.md b/.changeset/curly-shrimps-jog.md new file mode 100644 index 00000000..651d9530 --- /dev/null +++ b/.changeset/curly-shrimps-jog.md @@ -0,0 +1,5 @@ +--- +"@balancer/sdk": minor +--- + +Rename buildCall interface for consistency and clarity From a973005aef47ce2a9371701d14cc97270870b749 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 12 Mar 2024 11:30:53 -0300 Subject: [PATCH 28/29] Explain why some types are being exported --- src/entities/addLiquidity/types.ts | 2 +- src/entities/removeLiquidity/types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 39f97a18..24c752ae 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -84,7 +84,7 @@ export type AddLiquidityConfig = { customAddLiquidityTypes: Record; }; -// type consumed by FE team, so should be exported here +// type exposed because FE team uses it for batching add liquidity and stake operations export type JoinPoolRequest = { assets: Address[]; maxAmountsIn: readonly bigint[]; diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index 1297a9ff..195b75e8 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -104,6 +104,7 @@ export type RemoveLiquidityConfig = { customRemoveLiquidityTypes: Record; }; +// type exposed because FE team uses it for batching unstake and remove liquidity operations export type ExitPoolRequest = { assets: Address[]; minAmountsOut: bigint[]; From ed69b5f5a3fd30772390bbd8ab63c46cad4a83c3 Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 12 Mar 2024 15:59:12 -0300 Subject: [PATCH 29/29] Add chainId to add/remove liquidity query outputs --- .../addLiquidityComposableStable.ts | 3 +- .../weighted/addLiquidityWeighted.ts | 1 + .../addLiquidity/addLiquidityV3/index.ts | 3 +- src/entities/addLiquidity/types.ts | 2 +- src/entities/removeLiquidity/types.ts | 1 - test/lib/utils/addLiquidityHelper.ts | 30 ++++++--- test/lib/utils/removeLiquidityHelper.ts | 66 +++++++++++-------- .../composableStable.integration.test.ts | 6 -- .../v2/addLiquidity/gyro2.integration.test.ts | 1 - .../v2/addLiquidity/gyro3.integration.test.ts | 1 - .../v2/addLiquidity/gyroE.integration.test.ts | 1 - .../addLiquidity/gyroEV2.integration.test.ts | 2 - .../addLiquidity/weighted.integration.test.ts | 6 -- .../composableStable.integration.test.ts | 8 --- ...posableStable.recovery.integration.test.ts | 2 - .../removeLiquidity/gyro2.integration.test.ts | 1 - .../removeLiquidity/gyro3.integration.test.ts | 1 - .../removeLiquidity/gyroE.integration.test.ts | 1 - .../gyroEV2.integration.test.ts | 2 - .../weighted.integration.test.ts | 8 --- .../weighted.recovery.integration.test.ts | 2 - test/v3/addLiquidity.integration.test.ts | 4 -- test/v3/removeLiquidity.integration.test.ts | 6 -- 23 files changed, 67 insertions(+), 91 deletions(-) diff --git a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts index 660b2ab7..8bfb7db1 100644 --- a/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts +++ b/src/entities/addLiquidity/addLiquidityV2/composableStable/addLiquidityComposableStable.ts @@ -77,8 +77,9 @@ export class AddLiquidityComposableStable implements AddLiquidityBase { bptOut, amountsIn, tokenInIndex: amounts.tokenInIndex, - bptIndex, + chainId: input.chainId, vaultVersion: 2, + bptIndex, }; } diff --git a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts index 9f87f7c5..e09fff27 100644 --- a/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts +++ b/src/entities/addLiquidity/addLiquidityV2/weighted/addLiquidityWeighted.ts @@ -66,6 +66,7 @@ export class AddLiquidityWeighted implements AddLiquidityBase { poolId: poolState.id, bptOut, amountsIn, + chainId: input.chainId, tokenInIndex: amounts.tokenInIndex, vaultVersion: 2, }; diff --git a/src/entities/addLiquidity/addLiquidityV3/index.ts b/src/entities/addLiquidity/addLiquidityV3/index.ts index c1d08276..3a3ea399 100644 --- a/src/entities/addLiquidity/addLiquidityV3/index.ts +++ b/src/entities/addLiquidity/addLiquidityV3/index.ts @@ -79,8 +79,9 @@ export class AddLiquidityV3 implements AddLiquidityBase { addLiquidityKind: input.kind, bptOut, amountsIn, - vaultVersion: 3, tokenInIndex, + chainId: input.chainId, + vaultVersion: 3, }; return output; diff --git a/src/entities/addLiquidity/types.ts b/src/entities/addLiquidity/types.ts index 24c752ae..d89e9d11 100644 --- a/src/entities/addLiquidity/types.ts +++ b/src/entities/addLiquidity/types.ts @@ -46,6 +46,7 @@ export type AddLiquidityBaseQueryOutput = { addLiquidityKind: AddLiquidityKind; bptOut: TokenAmount; amountsIn: TokenAmount[]; + chainId: number; tokenInIndex?: number; vaultVersion: 2 | 3; }; @@ -56,7 +57,6 @@ export type AddLiquidityQueryOutput = export type AddLiquidityBaseBuildCallInput = { slippage: Slippage; - chainId: number; wethIsEth?: boolean; } & AddLiquidityBaseQueryOutput; diff --git a/src/entities/removeLiquidity/types.ts b/src/entities/removeLiquidity/types.ts index 195b75e8..ce2f4607 100644 --- a/src/entities/removeLiquidity/types.ts +++ b/src/entities/removeLiquidity/types.ts @@ -74,7 +74,6 @@ export type RemoveLiquidityQueryOutput = export type RemoveLiquidityBaseBuildCallInput = { slippage: Slippage; - chainId: number; wethIsEth?: boolean; } & RemoveLiquidityBaseQueryOutput; diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 876d738e..0078d6a6 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -10,7 +10,6 @@ import { AddLiquidityUnbalancedInput, Address, BALANCER_ROUTER, - ChainId, NATIVE_ASSETS, PoolState, Slippage, @@ -58,7 +57,6 @@ async function sdkAddLiquidity({ let addLiquidityBuildInput: AddLiquidityBuildCallInput = { ...addLiquidityQueryOutput, slippage, - chainId: addLiquidityInput.chainId, wethIsEth: !!wethIsEth, }; if (poolState.vaultVersion === 2) { @@ -162,7 +160,6 @@ export async function doAddLiquidity(txInput: AddLiquidityTxInput) { } export function assertAddLiquidityUnbalanced( - chainId: ChainId, poolState: PoolState, addLiquidityInput: AddLiquidityUnbalancedInput, addLiquidityOutput: AddLiquidityOutput, @@ -175,7 +172,11 @@ 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(chainId, t.address, t.decimals); + const token = new Token( + addLiquidityInput.chainId, + t.address, + t.decimals, + ); const input = addLiquidityInput.amountsIn.find( (a) => a.address === t.address, ); @@ -196,6 +197,7 @@ export function assertAddLiquidityUnbalanced( poolType: poolState.type, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId: addLiquidityInput.chainId, }; const queryCheck = getCheck(addLiquidityQueryOutput, true); @@ -226,7 +228,6 @@ export function assertAddLiquidityUnbalanced( } export function assertAddLiquiditySingleToken( - chainId: ChainId, poolState: PoolState, addLiquidityInput: AddLiquiditySingleTokenInput, addLiquidityOutput: AddLiquidityOutput, @@ -240,7 +241,11 @@ export function assertAddLiquiditySingleToken( if (addLiquidityQueryOutput.tokenInIndex === undefined) throw addLiquiditySingleTokenShouldHaveTokenInIndexError; - const bptToken = new Token(chainId, poolState.address, 18); + const bptToken = new Token( + addLiquidityInput.chainId, + poolState.address, + 18, + ); const tokensWithoutBpt = poolState.tokens.filter( (t) => t.address !== poolState.address, @@ -263,6 +268,7 @@ export function assertAddLiquiditySingleToken( poolType: poolState.type, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId: addLiquidityInput.chainId, }; const queryCheck = getCheck(addLiquidityQueryOutput, false); @@ -300,7 +306,6 @@ export function assertAddLiquiditySingleToken( } export function assertAddLiquidityProportional( - chainId: ChainId, poolState: PoolState, addLiquidityInput: AddLiquidityProportionalInput, addLiquidityOutput: AddLiquidityOutput, @@ -311,7 +316,11 @@ export function assertAddLiquidityProportional( const { txOutput, addLiquidityQueryOutput, addLiquidityBuildCallOutput } = addLiquidityOutput; - const bptToken = new Token(chainId, poolState.address, 18); + const bptToken = new Token( + addLiquidityInput.chainId, + poolState.address, + 18, + ); const expectedQueryOutput: Omit< AddLiquidityQueryOutput, @@ -329,6 +338,7 @@ export function assertAddLiquidityProportional( poolType: poolState.type, addLiquidityKind: addLiquidityInput.kind, vaultVersion: poolState.vaultVersion, + chainId: addLiquidityInput.chainId, }; const queryCheck = getCheck(addLiquidityQueryOutput, false); @@ -354,7 +364,9 @@ export function assertAddLiquidityProportional( if (wethIsEth) { expect( addLiquidityOutput.addLiquidityQueryOutput.amountsIn.some((t) => - t.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + t.token.isSameAddress( + NATIVE_ASSETS[addLiquidityInput.chainId].wrapped, + ), ), ).to.be.true; } diff --git a/test/lib/utils/removeLiquidityHelper.ts b/test/lib/utils/removeLiquidityHelper.ts index 1fae6151..82259c49 100644 --- a/test/lib/utils/removeLiquidityHelper.ts +++ b/test/lib/utils/removeLiquidityHelper.ts @@ -1,7 +1,6 @@ import { zeroAddress } from 'viem'; import { BALANCER_ROUTER, - ChainId, NATIVE_ASSETS, PoolState, RemoveLiquidityBuildCallInput, @@ -51,7 +50,6 @@ export const sdkRemoveLiquidity = async ({ let removeLiquidityBuildInput: RemoveLiquidityBuildCallInput = { ...removeLiquidityQueryOutput, slippage, - chainId: removeLiquidityInput.chainId, wethIsEth: !!wethIsEth, }; if (poolState.vaultVersion === 2) { @@ -158,7 +156,6 @@ export async function doRemoveLiquidity(txInput: RemoveLiquidityTxInput) { } export function assertRemoveLiquidityUnbalanced( - chainId: ChainId, poolState: PoolState, removeLiquidityInput: RemoveLiquidityUnbalancedInput, removeLiquidityOutput: RemoveLiquidityOutput, @@ -173,7 +170,11 @@ 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(chainId, t.address, t.decimals); + const token = new Token( + removeLiquidityInput.chainId, + t.address, + t.decimals, + ); const input = removeLiquidityInput.amountsOut.find( (a) => a.address === t.address, ); @@ -193,7 +194,7 @@ export function assertRemoveLiquidityUnbalanced( poolType: poolState.type, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, - chainId, + chainId: removeLiquidityInput.chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, false); @@ -208,7 +209,6 @@ export function assertRemoveLiquidityUnbalanced( removeLiquidityBuildCallOutput, false, slippage, - chainId, ); assertTokenDeltas( @@ -221,7 +221,6 @@ export function assertRemoveLiquidityUnbalanced( } export function assertRemoveLiquiditySingleTokenExactOut( - chainId: ChainId, poolState: PoolState, removeLiquidityInput: RemoveLiquiditySingleTokenExactOutInput, removeLiquidityOutput: RemoveLiquidityOutput, @@ -237,7 +236,11 @@ 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(chainId, t.address, t.decimals); + const token = new Token( + removeLiquidityInput.chainId, + t.address, + t.decimals, + ); const input = removeLiquidityInput.amountOut; if (input.address !== t.address) { return TokenAmount.fromRawAmount(token, 0n); @@ -263,7 +266,7 @@ export function assertRemoveLiquiditySingleTokenExactOut( poolType: poolState.type, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, - chainId, + chainId: removeLiquidityInput.chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, false); @@ -278,7 +281,6 @@ export function assertRemoveLiquiditySingleTokenExactOut( removeLiquidityBuildCallOutput, false, slippage, - chainId, vaultVersion, ); @@ -292,7 +294,6 @@ export function assertRemoveLiquiditySingleTokenExactOut( } export function assertRemoveLiquiditySingleTokenExactIn( - chainId: ChainId, poolState: PoolState, removeLiquidityInput: RemoveLiquiditySingleTokenExactInInput, removeLiquidityOutput: RemoveLiquidityOutput, @@ -309,7 +310,11 @@ export function assertRemoveLiquiditySingleTokenExactIn( if (removeLiquidityQueryOutput.tokenOutIndex === undefined) throw removeLiquiditySingleTokenExactInShouldHaveTokenOutIndexError; - const bptToken = new Token(chainId, poolState.address, 18); + const bptToken = new Token( + removeLiquidityInput.chainId, + poolState.address, + 18, + ); const tokensWithoutBpt = poolState.tokens.filter( (t) => t.address !== poolState.address, @@ -332,7 +337,7 @@ export function assertRemoveLiquiditySingleTokenExactIn( poolType: poolState.type, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, - chainId, + chainId: removeLiquidityInput.chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -360,7 +365,6 @@ export function assertRemoveLiquiditySingleTokenExactIn( removeLiquidityBuildCallOutput, true, slippage, - chainId, vaultVersion, ); @@ -374,7 +378,6 @@ export function assertRemoveLiquiditySingleTokenExactIn( } export function assertRemoveLiquidityProportional( - chainId: ChainId, poolState: PoolState, removeLiquidityInput: RemoveLiquidityProportionalInput, removeLiquidityOutput: RemoveLiquidityOutput, @@ -388,7 +391,11 @@ export function assertRemoveLiquidityProportional( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new Token(chainId, poolState.address, 18); + const bptToken = new Token( + removeLiquidityInput.chainId, + poolState.address, + 18, + ); const expectedQueryOutput: Omit< RemoveLiquidityQueryOutput, @@ -406,7 +413,7 @@ export function assertRemoveLiquidityProportional( poolType: poolState.type, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, - chainId, + chainId: removeLiquidityInput.chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -422,7 +429,9 @@ export function assertRemoveLiquidityProportional( if (wethIsEth) { expect( removeLiquidityQueryOutput.amountsOut.some((a) => - a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + a.token.isSameAddress( + NATIVE_ASSETS[removeLiquidityQueryOutput.chainId].wrapped, + ), ), ).to.be.true; } @@ -432,7 +441,6 @@ export function assertRemoveLiquidityProportional( removeLiquidityBuildCallOutput, true, slippage, - chainId, vaultVersion, ); @@ -446,7 +454,6 @@ export function assertRemoveLiquidityProportional( } export function assertRemoveLiquidityRecovery( - chainId: ChainId, poolState: PoolState, removeLiquidityInput: RemoveLiquidityRecoveryInput, removeLiquidityOutput: RemoveLiquidityOutput, @@ -460,7 +467,11 @@ export function assertRemoveLiquidityRecovery( removeLiquidityBuildCallOutput, } = removeLiquidityOutput; - const bptToken = new Token(chainId, poolState.address, 18); + const bptToken = new Token( + removeLiquidityInput.chainId, + poolState.address, + 18, + ); const expectedQueryOutput: Omit< RemoveLiquidityQueryOutput, @@ -478,7 +489,7 @@ export function assertRemoveLiquidityRecovery( poolType: poolState.type, removeLiquidityKind: removeLiquidityInput.kind, vaultVersion: poolState.vaultVersion, - chainId, + chainId: removeLiquidityInput.chainId, }; const queryCheck = getCheck(removeLiquidityQueryOutput, true); @@ -494,7 +505,9 @@ export function assertRemoveLiquidityRecovery( if (wethIsEth) { expect( removeLiquidityQueryOutput.amountsOut.some((a) => - a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped), + a.token.isSameAddress( + NATIVE_ASSETS[removeLiquidityQueryOutput.chainId].wrapped, + ), ), ).to.be.true; } @@ -504,7 +517,6 @@ export function assertRemoveLiquidityRecovery( removeLiquidityBuildCallOutput, true, slippage, - chainId, vaultVersion, ); @@ -566,7 +578,6 @@ function assertRemoveLiquidityBuildCallOutput( RemoveLiquidityBuildCallOutput: RemoveLiquidityBuildCallOutput, isExactIn: boolean, slippage: Slippage, - chainId: number, vaultVersion: 2 | 3 = 2, ) { // if exactIn minAmountsOut should use amountsOut with slippage applied, else should use same amountsOut as input @@ -588,7 +599,10 @@ function assertRemoveLiquidityBuildCallOutput( slippage.applyTo(removeLiquidityQueryOutput.bptIn.amount), ); - const to = vaultVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId]; + const to = + vaultVersion === 2 + ? VAULT[removeLiquidityQueryOutput.chainId] + : BALANCER_ROUTER[removeLiquidityQueryOutput.chainId]; const expectedBuildOutput: Omit = { minAmountsOut, diff --git a/test/v2/addLiquidity/composableStable.integration.test.ts b/test/v2/addLiquidity/composableStable.integration.test.ts index 58a1633d..24499daf 100644 --- a/test/v2/addLiquidity/composableStable.integration.test.ts +++ b/test/v2/addLiquidity/composableStable.integration.test.ts @@ -117,7 +117,6 @@ describe('add liquidity composable stable test', () => { addLiquidityInput, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -137,7 +136,6 @@ describe('add liquidity composable stable test', () => { wethIsEth, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -172,7 +170,6 @@ describe('add liquidity composable stable test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, input, addLiquidityOutput, @@ -192,7 +189,6 @@ describe('add liquidity composable stable test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -225,7 +221,6 @@ describe('add liquidity composable stable test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, addLiquidityOutput, @@ -243,7 +238,6 @@ describe('add liquidity composable stable test', () => { wethIsEth, }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/addLiquidity/gyro2.integration.test.ts b/test/v2/addLiquidity/gyro2.integration.test.ts index e6ec84e0..8d99a6d8 100644 --- a/test/v2/addLiquidity/gyro2.integration.test.ts +++ b/test/v2/addLiquidity/gyro2.integration.test.ts @@ -112,7 +112,6 @@ describe('Gyro2 add liquidity test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/addLiquidity/gyro3.integration.test.ts b/test/v2/addLiquidity/gyro3.integration.test.ts index 20978b28..738436c9 100644 --- a/test/v2/addLiquidity/gyro3.integration.test.ts +++ b/test/v2/addLiquidity/gyro3.integration.test.ts @@ -112,7 +112,6 @@ describe('Gyro3 add liquidity test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/addLiquidity/gyroE.integration.test.ts b/test/v2/addLiquidity/gyroE.integration.test.ts index 7b00b622..1ff676f3 100644 --- a/test/v2/addLiquidity/gyroE.integration.test.ts +++ b/test/v2/addLiquidity/gyroE.integration.test.ts @@ -112,7 +112,6 @@ describe('gyroE V2 add liquidity test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/addLiquidity/gyroEV2.integration.test.ts b/test/v2/addLiquidity/gyroEV2.integration.test.ts index 85ac1b28..6f3944ae 100644 --- a/test/v2/addLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/addLiquidity/gyroEV2.integration.test.ts @@ -112,7 +112,6 @@ describe('GyroE V2 add liquidity test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -127,7 +126,6 @@ describe('GyroE V2 add liquidity test', () => { wethIsEth, }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/addLiquidity/weighted.integration.test.ts b/test/v2/addLiquidity/weighted.integration.test.ts index 6726b5cf..03442995 100644 --- a/test/v2/addLiquidity/weighted.integration.test.ts +++ b/test/v2/addLiquidity/weighted.integration.test.ts @@ -117,7 +117,6 @@ describe('add liquidity weighted test', () => { addLiquidityInput, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -137,7 +136,6 @@ describe('add liquidity weighted test', () => { wethIsEth, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -173,7 +171,6 @@ describe('add liquidity weighted test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -190,7 +187,6 @@ describe('add liquidity weighted test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -223,7 +219,6 @@ describe('add liquidity weighted test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -239,7 +234,6 @@ describe('add liquidity weighted test', () => { }); assertAddLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index 32d54c1a..3acd6450 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -118,7 +118,6 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, }); assertRemoveLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -137,7 +136,6 @@ describe('composable stable remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -172,7 +170,6 @@ describe('composable stable remove liquidity test', () => { removeLiquidityInput, }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -191,7 +188,6 @@ describe('composable stable remove liquidity test', () => { wethIsEth, }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -226,7 +222,6 @@ describe('composable stable remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -246,7 +241,6 @@ describe('composable stable remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -279,7 +273,6 @@ describe('composable stable remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -297,7 +290,6 @@ describe('composable stable remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts index 9b2d0713..032bf2c0 100644 --- a/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.recovery.integration.test.ts @@ -99,7 +99,6 @@ describe('composable stable remove liquidity test', () => { }); assertRemoveLiquidityRecovery( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -115,7 +114,6 @@ describe('composable stable remove liquidity test', () => { }); assertRemoveLiquidityRecovery( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/gyro2.integration.test.ts b/test/v2/removeLiquidity/gyro2.integration.test.ts index 97ebf066..0a04ad5b 100644 --- a/test/v2/removeLiquidity/gyro2.integration.test.ts +++ b/test/v2/removeLiquidity/gyro2.integration.test.ts @@ -105,7 +105,6 @@ describe('Gyro2 remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/gyro3.integration.test.ts b/test/v2/removeLiquidity/gyro3.integration.test.ts index 2750fe21..173e1f45 100644 --- a/test/v2/removeLiquidity/gyro3.integration.test.ts +++ b/test/v2/removeLiquidity/gyro3.integration.test.ts @@ -105,7 +105,6 @@ describe('Gyro3 remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/gyroE.integration.test.ts b/test/v2/removeLiquidity/gyroE.integration.test.ts index bcb3d1d5..0d882372 100644 --- a/test/v2/removeLiquidity/gyroE.integration.test.ts +++ b/test/v2/removeLiquidity/gyroE.integration.test.ts @@ -105,7 +105,6 @@ describe('GyroE V1 remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/gyroEV2.integration.test.ts b/test/v2/removeLiquidity/gyroEV2.integration.test.ts index 90a30334..5a008093 100644 --- a/test/v2/removeLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/removeLiquidity/gyroEV2.integration.test.ts @@ -105,7 +105,6 @@ describe('GyroE V2 remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -123,7 +122,6 @@ describe('GyroE V2 remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index e8f72a6b..22d05d28 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -110,7 +110,6 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, }); assertRemoveLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -129,7 +128,6 @@ describe('weighted remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -164,7 +162,6 @@ describe('weighted remove liquidity test', () => { removeLiquidityInput, }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -183,7 +180,6 @@ describe('weighted remove liquidity test', () => { wethIsEth, }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -218,7 +214,6 @@ describe('weighted remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -238,7 +233,6 @@ describe('weighted remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, @@ -271,7 +265,6 @@ describe('weighted remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -289,7 +282,6 @@ describe('weighted remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, removeLiquidityInput, removeLiquidityOutput, diff --git a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts index d0ee2971..3ed7265a 100644 --- a/test/v2/removeLiquidity/weighted.recovery.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.recovery.integration.test.ts @@ -103,7 +103,6 @@ describe('weighted remove liquidity recovery test', () => { }); assertRemoveLiquidityRecovery( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -119,7 +118,6 @@ describe('weighted remove liquidity recovery test', () => { }); assertRemoveLiquidityRecovery( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, diff --git a/test/v3/addLiquidity.integration.test.ts b/test/v3/addLiquidity.integration.test.ts index 970c888f..330a1a29 100644 --- a/test/v3/addLiquidity.integration.test.ts +++ b/test/v3/addLiquidity.integration.test.ts @@ -117,7 +117,6 @@ describe('add liquidity test', () => { addLiquidityInput, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -138,7 +137,6 @@ describe('add liquidity test', () => { wethIsEth, }); assertAddLiquidityUnbalanced( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, @@ -173,7 +171,6 @@ describe('add liquidity test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, input, addLiquidityOutput, @@ -194,7 +191,6 @@ describe('add liquidity test', () => { }); assertAddLiquiditySingleToken( - txInput.client.chain?.id as number, txInput.poolState, addLiquidityInput, addLiquidityOutput, diff --git a/test/v3/removeLiquidity.integration.test.ts b/test/v3/removeLiquidity.integration.test.ts index bf306cd8..abe60ea5 100644 --- a/test/v3/removeLiquidity.integration.test.ts +++ b/test/v3/removeLiquidity.integration.test.ts @@ -173,7 +173,6 @@ describe('remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -191,7 +190,6 @@ describe('remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactOut( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -226,7 +224,6 @@ describe('remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -244,7 +241,6 @@ describe('remove liquidity test', () => { }); assertRemoveLiquiditySingleTokenExactIn( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -277,7 +273,6 @@ describe('remove liquidity test', () => { }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput, @@ -293,7 +288,6 @@ describe('remove liquidity test', () => { wethIsEth, }); assertRemoveLiquidityProportional( - txInput.client.chain?.id as number, txInput.poolState, input, removeLiquidityOutput,