diff --git a/test/lib/utils/addLiquidityHelper.ts b/test/lib/utils/addLiquidityHelper.ts index 51116409..6f2df84a 100644 --- a/test/lib/utils/addLiquidityHelper.ts +++ b/test/lib/utils/addLiquidityHelper.ts @@ -414,7 +414,7 @@ export function assertAddLiquidityProportional( Number( a.amount - addLiquidityInput.referenceAmount.rawAmount, ), - ).closeTo(0, 1); + ).closeTo(0, 1000); // 1000 wei tolerance }); } diff --git a/test/v2/addLiquidity/gyro2.integration.test.ts b/test/v2/addLiquidity/gyro2.integration.test.ts index 4f2835c1..fd96f375 100644 --- a/test/v2/addLiquidity/gyro2.integration.test.ts +++ b/test/v2/addLiquidity/gyro2.integration.test.ts @@ -28,15 +28,15 @@ import { AddLiquidityUnbalancedInput, AddLiquiditySingleTokenInput, PoolType, + addLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { + AddLiquidityTxInput, assertAddLiquidityProportional, doAddLiquidity, -} from '../../lib/utils/addLiquidityHelper'; -import { AddLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); const chainId = ChainId.POLYGON; @@ -92,7 +92,7 @@ describe('Gyro2 add liquidity test', () => { describe('proportional', () => { let addLiquidityInput: AddLiquidityProportionalInput; - beforeAll(() => { + test('with bpt', async () => { const referenceAmount: InputAmount = { rawAmount: parseEther('1'), decimals: 18, @@ -104,8 +104,34 @@ describe('Gyro2 add liquidity test', () => { rpcUrl, kind: AddLiquidityKind.Proportional, }; + + const addLiquidityOutput = await doAddLiquidity({ + ...txInput, + addLiquidityInput, + }); + + assertAddLiquidityProportional( + txInput.poolState, + addLiquidityInput, + addLiquidityOutput, + txInput.slippage, + chainId, + ); }); - test('with tokens', async () => { + + test('with reference amount (non-bpt)', async () => { + const referenceAmount: InputAmount = { + rawAmount: 1000000n, + decimals: poolState.tokens[0].decimals, + address: poolState.tokens[0].address, + }; + addLiquidityInput = { + referenceAmount, + chainId, + rpcUrl, + kind: AddLiquidityKind.Proportional, + }; + const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, @@ -119,7 +145,6 @@ describe('Gyro2 add liquidity test', () => { chainId, ); }); - //Removed test with native, because there are no GyroE V1 pool with wrapped native asset in any network }); describe('unbalanced', () => { @@ -148,7 +173,10 @@ describe('Gyro2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -178,7 +206,10 @@ describe('Gyro2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/addLiquidity/gyro3.integration.test.ts b/test/v2/addLiquidity/gyro3.integration.test.ts index cea7b789..c6088225 100644 --- a/test/v2/addLiquidity/gyro3.integration.test.ts +++ b/test/v2/addLiquidity/gyro3.integration.test.ts @@ -28,15 +28,15 @@ import { AddLiquidityUnbalancedInput, AddLiquiditySingleTokenInput, PoolType, + addLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { + AddLiquidityTxInput, assertAddLiquidityProportional, doAddLiquidity, -} from '../../lib/utils/addLiquidityHelper'; -import { AddLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); const chainId = ChainId.POLYGON; @@ -92,7 +92,7 @@ describe('Gyro3 add liquidity test', () => { describe('proportional', () => { let addLiquidityInput: AddLiquidityProportionalInput; - beforeAll(() => { + test('with bpt', async () => { const referenceAmount: InputAmount = { rawAmount: parseEther('1'), decimals: 18, @@ -104,8 +104,32 @@ describe('Gyro3 add liquidity test', () => { rpcUrl, kind: AddLiquidityKind.Proportional, }; + const addLiquidityOutput = await doAddLiquidity({ + ...txInput, + addLiquidityInput, + }); + + assertAddLiquidityProportional( + txInput.poolState, + addLiquidityInput, + addLiquidityOutput, + txInput.slippage, + chainId, + ); }); - test('with tokens', async () => { + + test('with reference amount (non-bpt)', async () => { + const referenceAmount: InputAmount = { + rawAmount: parseUnits('1', poolState.tokens[0].decimals), + decimals: poolState.tokens[0].decimals, + address: poolState.tokens[0].address, + }; + addLiquidityInput = { + referenceAmount, + chainId, + rpcUrl, + kind: AddLiquidityKind.Proportional, + }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, @@ -148,7 +172,10 @@ describe('Gyro3 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -178,7 +205,10 @@ describe('Gyro3 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/addLiquidity/gyroE.integration.test.ts b/test/v2/addLiquidity/gyroE.integration.test.ts index 72828151..e5199db6 100644 --- a/test/v2/addLiquidity/gyroE.integration.test.ts +++ b/test/v2/addLiquidity/gyroE.integration.test.ts @@ -28,22 +28,22 @@ import { AddLiquidityUnbalancedInput, AddLiquiditySingleTokenInput, PoolType, + addLiquidityProportionalOnlyError, } from '../../../src'; -import { forkSetup } from '../../lib/utils/helper'; import { + AddLiquidityTxInput, assertAddLiquidityProportional, doAddLiquidity, -} from '../../lib/utils/addLiquidityHelper'; -import { AddLiquidityTxInput } from '../../lib/utils/types'; + forkSetup, +} from '../../lib/utils'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; const { rpcUrl } = await startFork(ANVIL_NETWORKS.POLYGON); const chainId = ChainId.POLYGON; const poolId = '0xa489c057de6c3177380ea264ebdf686b7f564f510002000000000000000008e2'; // ECLP-wstETH-wETH -describe('gyroE V2 add liquidity test', () => { +describe('GyroE add liquidity test', () => { let txInput: AddLiquidityTxInput; let poolState: PoolState; @@ -92,7 +92,7 @@ describe('gyroE V2 add liquidity test', () => { describe('proportional', () => { let addLiquidityInput: AddLiquidityProportionalInput; - beforeAll(() => { + test('with bpt', async () => { const referenceAmount: InputAmount = { rawAmount: parseEther('1'), decimals: 18, @@ -104,8 +104,32 @@ describe('gyroE V2 add liquidity test', () => { rpcUrl, kind: AddLiquidityKind.Proportional, }; + const addLiquidityOutput = await doAddLiquidity({ + ...txInput, + addLiquidityInput, + }); + + assertAddLiquidityProportional( + txInput.poolState, + addLiquidityInput, + addLiquidityOutput, + txInput.slippage, + chainId, + ); }); - test('with tokens', async () => { + + test('with reference amount (non-bpt)', async () => { + const referenceAmount: InputAmount = { + rawAmount: parseUnits('1', poolState.tokens[0].decimals), + decimals: poolState.tokens[0].decimals, + address: poolState.tokens[0].address, + }; + addLiquidityInput = { + referenceAmount, + chainId, + rpcUrl, + kind: AddLiquidityKind.Proportional, + }; const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, @@ -147,7 +171,10 @@ describe('gyroE V2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); //Removed test with native, because there are no GyroE V1 pool with wrapped native asset in any network @@ -178,7 +205,10 @@ describe('gyroE V2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); diff --git a/test/v2/addLiquidity/gyroEV2.integration.test.ts b/test/v2/addLiquidity/gyroEV2.integration.test.ts index 80fab395..69a07491 100644 --- a/test/v2/addLiquidity/gyroEV2.integration.test.ts +++ b/test/v2/addLiquidity/gyroEV2.integration.test.ts @@ -28,6 +28,7 @@ import { AddLiquidityUnbalancedInput, AddLiquiditySingleTokenInput, PoolType, + addLiquidityProportionalOnlyError, } from '../../../src'; import { forkSetup } from '../../lib/utils/helper'; import { @@ -36,7 +37,6 @@ import { } from '../../lib/utils/addLiquidityHelper'; import { AddLiquidityTxInput } from '../../lib/utils/types'; import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; -import { InputValidatorGyro } from '../../../src/entities/inputValidator/gyro/inputValidatorGyro'; const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); const chainId = ChainId.MAINNET; @@ -90,13 +90,59 @@ describe('GyroE V2 add liquidity test', () => { ); }); - describe('proportional', () => { + describe.only('proportional', () => { let addLiquidityInput: AddLiquidityProportionalInput; - beforeAll(() => { + describe('with bpt', () => { + beforeAll(() => { + const referenceAmount: InputAmount = { + rawAmount: parseEther('2'), + decimals: 18, + address: poolState.address, + }; + addLiquidityInput = { + referenceAmount, + chainId, + rpcUrl, + kind: AddLiquidityKind.Proportional, + }; + }); + test('with tokens', async () => { + const addLiquidityOutput = await doAddLiquidity({ + ...txInput, + addLiquidityInput, + }); + + assertAddLiquidityProportional( + txInput.poolState, + addLiquidityInput, + addLiquidityOutput, + txInput.slippage, + chainId, + ); + }); + test('with native', async () => { + const wethIsEth = true; + const addLiquidityOutput = await doAddLiquidity({ + ...txInput, + addLiquidityInput, + wethIsEth, + }); + assertAddLiquidityProportional( + txInput.poolState, + addLiquidityInput, + addLiquidityOutput, + txInput.slippage, + chainId, + 2, + wethIsEth, + ); + }); + }); + test('with reference amount (non-bpt)', async () => { const referenceAmount: InputAmount = { - rawAmount: parseEther('2'), - decimals: 18, - address: poolState.address, + rawAmount: parseUnits('1', poolState.tokens[0].decimals), + decimals: poolState.tokens[0].decimals, + address: poolState.tokens[0].address, }; addLiquidityInput = { referenceAmount, @@ -104,8 +150,6 @@ describe('GyroE V2 add liquidity test', () => { rpcUrl, kind: AddLiquidityKind.Proportional, }; - }); - test('with tokens', async () => { const addLiquidityOutput = await doAddLiquidity({ ...txInput, addLiquidityInput, @@ -119,23 +163,6 @@ describe('GyroE V2 add liquidity test', () => { chainId, ); }); - test('with native', async () => { - const wethIsEth = true; - const addLiquidityOutput = await doAddLiquidity({ - ...txInput, - addLiquidityInput, - wethIsEth, - }); - assertAddLiquidityProportional( - txInput.poolState, - addLiquidityInput, - addLiquidityOutput, - txInput.slippage, - chainId, - 2, - wethIsEth, - ); - }); }); describe('unbalanced', () => { @@ -164,7 +191,10 @@ describe('GyroE V2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); }); @@ -194,7 +224,10 @@ describe('GyroE V2 add liquidity test', () => { addLiquidityInput, }), ).rejects.toThrowError( - InputValidatorGyro.addLiquidityKindNotSupportedByGyro, + addLiquidityProportionalOnlyError( + addLiquidityInput.kind, + poolState.type, + ), ); }); });