From 4075b93b6ee64701bf71403319ea49ff6b0b97cd Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Tue, 10 Dec 2024 12:45:36 -0300 Subject: [PATCH] Fix remove liquidity tests for gyro --- .../removeLiquidity/gyro2.integration.test.ts | 43 +++++++++++-------- .../removeLiquidity/gyro3.integration.test.ts | 37 ++++++++++------ .../removeLiquidity/gyroE.integration.test.ts | 37 ++++++++++------ .../gyroEV2.integration.test.ts | 37 ++++++++++------ 4 files changed, 95 insertions(+), 59 deletions(-) diff --git a/test/v2/removeLiquidity/gyro2.integration.test.ts b/test/v2/removeLiquidity/gyro2.integration.test.ts index a30d21ec..6847b5ca 100644 --- a/test/v2/removeLiquidity/gyro2.integration.test.ts +++ b/test/v2/removeLiquidity/gyro2.integration.test.ts @@ -27,16 +27,16 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + removeLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { assertRemoveLiquidityProportional, doRemoveLiquidity, -} from '../../lib/utils/removeLiquidityHelper'; -import { RemoveLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, + RemoveLiquidityTxInput, + TOKENS, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; -import { TOKENS } from 'test/lib/utils/addresses'; const chainId = ChainId.POLYGON; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); @@ -47,13 +47,13 @@ const USDC = TOKENS[chainId].USDC; describe('Gyro2 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(poolId); + poolState = await api.getPool(poolId); const client = createTestClient({ mode: 'anvil', @@ -67,7 +67,7 @@ describe('Gyro2 remove liquidity test', () => { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% - poolState: poolInput, + poolState, testAddress: '0xe84f75fc9caa49876d0ba18d309da4231d44e94d', // MATIC Holder Wallet, must hold amount of matic to approve tokens removeLiquidityInput: {} as RemoveLiquidityInput, }; @@ -89,7 +89,7 @@ describe('Gyro2 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('0.01'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; input = { bptIn, @@ -119,7 +119,7 @@ describe('Gyro2 remove liquidity test', () => { let input: Omit; let amountsOut: InputAmount[]; beforeAll(() => { - amountsOut = poolInput.tokens.map((t) => ({ + amountsOut = poolState.tokens.map((t) => ({ rawAmount: parseUnits('0.001', t.decimals), decimals: t.decimals, address: t.address, @@ -138,7 +138,10 @@ describe('Gyro2 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -166,21 +169,24 @@ describe('Gyro2 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); describe('single token exact in', () => { - let input: RemoveLiquiditySingleTokenExactInInput; + let removeLiquidityInput: RemoveLiquiditySingleTokenExactInInput; beforeAll(() => { const bptIn: InputAmount = { rawAmount: parseEther('1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH - input = { + removeLiquidityInput = { chainId, rpcUrl, bptIn, @@ -190,9 +196,12 @@ describe('Gyro2 remove liquidity test', () => { }); test('must throw remove liquidity kind not supported error', async () => { await expect(() => - doRemoveLiquidity({ ...txInput, removeLiquidityInput: input }), + doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/removeLiquidity/gyro3.integration.test.ts b/test/v2/removeLiquidity/gyro3.integration.test.ts index ef5be0d0..00e7df3a 100644 --- a/test/v2/removeLiquidity/gyro3.integration.test.ts +++ b/test/v2/removeLiquidity/gyro3.integration.test.ts @@ -27,16 +27,16 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + removeLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { assertRemoveLiquidityProportional, doRemoveLiquidity, -} from '../../lib/utils/removeLiquidityHelper'; -import { RemoveLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, + RemoveLiquidityTxInput, + TOKENS, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; -import { TOKENS } from 'test/lib/utils/addresses'; const chainId = ChainId.POLYGON; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); @@ -47,13 +47,13 @@ const USDC = TOKENS[chainId].USDC; describe('Gyro3 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(poolId); + poolState = await api.getPool(poolId); const client = createTestClient({ mode: 'anvil', @@ -67,7 +67,7 @@ describe('Gyro3 remove liquidity test', () => { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% - poolState: poolInput, + poolState: poolState, testAddress: '0xe84f75fc9caa49876d0ba18d309da4231d44e94d', // MATIC Holder Wallet, must hold amount of matic to approve tokens removeLiquidityInput: {} as RemoveLiquidityInput, }; @@ -89,7 +89,7 @@ describe('Gyro3 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('0.01'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; input = { bptIn, @@ -119,7 +119,7 @@ describe('Gyro3 remove liquidity test', () => { let input: Omit; let amountsOut: InputAmount[]; beforeAll(() => { - amountsOut = poolInput.tokens.map((t) => ({ + amountsOut = poolState.tokens.map((t) => ({ rawAmount: parseUnits('0.001', t.decimals), decimals: t.decimals, address: t.address, @@ -138,7 +138,10 @@ describe('Gyro3 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -166,7 +169,10 @@ describe('Gyro3 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -177,7 +183,7 @@ describe('Gyro3 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH input = { @@ -192,7 +198,10 @@ describe('Gyro3 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput: input }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + input.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/removeLiquidity/gyroE.integration.test.ts b/test/v2/removeLiquidity/gyroE.integration.test.ts index 93ac233a..f3ff3ad7 100644 --- a/test/v2/removeLiquidity/gyroE.integration.test.ts +++ b/test/v2/removeLiquidity/gyroE.integration.test.ts @@ -27,16 +27,16 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + removeLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { assertRemoveLiquidityProportional, doRemoveLiquidity, -} from '../../lib/utils/removeLiquidityHelper'; -import { RemoveLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, + RemoveLiquidityTxInput, + TOKENS, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; -import { TOKENS } from 'test/lib/utils/addresses'; const chainId = ChainId.POLYGON; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); @@ -47,13 +47,13 @@ const USDC = TOKENS[chainId].USDC; describe('GyroE V1 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(poolId); + poolState = await api.getPool(poolId); const client = createTestClient({ mode: 'anvil', @@ -67,7 +67,7 @@ describe('GyroE V1 remove liquidity test', () => { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% - poolState: poolInput, + poolState: poolState, testAddress: '0xe84f75fc9caa49876d0ba18d309da4231d44e94d', // MATIC Holder Wallet, must hold amount of matic to approve tokens removeLiquidityInput: {} as RemoveLiquidityInput, }; @@ -89,7 +89,7 @@ describe('GyroE V1 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; input = { bptIn, @@ -119,7 +119,7 @@ describe('GyroE V1 remove liquidity test', () => { let input: Omit; let amountsOut: InputAmount[]; beforeAll(() => { - amountsOut = poolInput.tokens.map((t) => ({ + amountsOut = poolState.tokens.map((t) => ({ rawAmount: parseUnits('1', t.decimals), decimals: t.decimals, address: t.address, @@ -138,7 +138,10 @@ describe('GyroE V1 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -166,7 +169,10 @@ describe('GyroE V1 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -177,7 +183,7 @@ describe('GyroE V1 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH input = { @@ -192,7 +198,10 @@ describe('GyroE V1 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput: input }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + input.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/removeLiquidity/gyroEV2.integration.test.ts b/test/v2/removeLiquidity/gyroEV2.integration.test.ts index 927e7974..01862a2d 100644 --- a/test/v2/removeLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/removeLiquidity/gyroEV2.integration.test.ts @@ -27,16 +27,16 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + removeLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { assertRemoveLiquidityProportional, doRemoveLiquidity, -} from '../../lib/utils/removeLiquidityHelper'; -import { RemoveLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, + RemoveLiquidityTxInput, + TOKENS, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; -import { TOKENS } from 'test/lib/utils/addresses'; const chainId = ChainId.MAINNET; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); @@ -47,13 +47,13 @@ const wETH = TOKENS[chainId].WETH; describe('GyroE V2 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(poolId); + poolState = await api.getPool(poolId); const client = createTestClient({ mode: 'anvil', @@ -67,7 +67,7 @@ describe('GyroE V2 remove liquidity test', () => { client, removeLiquidity: new RemoveLiquidity(), slippage: Slippage.fromPercentage('1'), // 1% - poolState: poolInput, + poolState: poolState, testAddress: '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f', // Balancer DAO Multisig removeLiquidityInput: {} as RemoveLiquidityInput, }; @@ -89,7 +89,7 @@ describe('GyroE V2 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('0.01'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; input = { bptIn, @@ -138,7 +138,7 @@ describe('GyroE V2 remove liquidity test', () => { let input: Omit; let amountsOut: InputAmount[]; beforeAll(() => { - amountsOut = poolInput.tokens.map((t) => ({ + amountsOut = poolState.tokens.map((t) => ({ rawAmount: parseUnits('0.001', t.decimals), decimals: t.decimals, address: t.address, @@ -157,7 +157,10 @@ describe('GyroE V2 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -185,7 +188,10 @@ describe('GyroE V2 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + removeLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -196,7 +202,7 @@ describe('GyroE V2 remove liquidity test', () => { const bptIn: InputAmount = { rawAmount: parseEther('1'), decimals: 18, - address: poolInput.address, + address: poolState.address, }; const tokenOut = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // WETH input = { @@ -211,7 +217,10 @@ describe('GyroE V2 remove liquidity test', () => { await expect(() => doRemoveLiquidity({ ...txInput, removeLiquidityInput: input }), ).rejects.toThrowError( - InputValidatorGyro.removeLiquidityKindNotSupportedByGyro, + removeLiquidityProportionalOnlyError( + input.kind, + poolState.type, + ), ); }); });