Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra integration tests for gyro pools #528

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-paws-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@balancer/sdk": patch
---

Add extra integration tests for gyro pools
7 changes: 4 additions & 3 deletions test/lib/utils/addLiquidityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import {
AddLiquidityKind,
ChainId,
isSameAddress,
PublicWalletClient,
} from 'src';
import { getTokensForBalanceCheck } from './getTokensForBalanceCheck';
import { TxOutput, sendTransactionGetBalances } from './helper';
import { AddLiquidityTxInput } from './types';
import { AddLiquidityV2BaseBuildCallInput } from '@/entities/addLiquidity/addLiquidityV2/types';
import { AddLiquidityV2ComposableStableQueryOutput } from '@/entities/addLiquidity/addLiquidityV2/composableStable/types';
import { Client, Hex, PublicActions, WalletActions } from 'viem';
import { Hex, TestActions } from 'viem';

type AddLiquidityOutput = {
addLiquidityQueryOutput: AddLiquidityQueryOutput;
Expand All @@ -52,7 +53,7 @@ async function sdkAddLiquidity({
testAddress: Address;
wethIsEth?: boolean;
fromInternalBalance?: boolean;
client: Client & PublicActions & WalletActions;
client: PublicWalletClient & TestActions;
usePermit2Signatures?: boolean;
}): Promise<{
addLiquidityBuildCallOutput: AddLiquidityBuildCallOutput;
Expand Down Expand Up @@ -414,7 +415,7 @@ export function assertAddLiquidityProportional(
Number(
a.amount - addLiquidityInput.referenceAmount.rawAmount,
),
).closeTo(0, 1);
).closeTo(0, 1000); // 1000 wei tolerance
});
}

Expand Down
49 changes: 40 additions & 9 deletions test/v2/addLiquidity/gyro2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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', () => {
Expand Down Expand Up @@ -148,7 +173,10 @@ describe('Gyro2 add liquidity test', () => {
addLiquidityInput,
}),
).rejects.toThrowError(
InputValidatorGyro.addLiquidityKindNotSupportedByGyro,
addLiquidityProportionalOnlyError(
addLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down Expand Up @@ -178,7 +206,10 @@ describe('Gyro2 add liquidity test', () => {
addLiquidityInput,
}),
).rejects.toThrowError(
InputValidatorGyro.addLiquidityKindNotSupportedByGyro,
addLiquidityProportionalOnlyError(
addLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down
46 changes: 38 additions & 8 deletions test/v2/addLiquidity/gyro3.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -148,7 +172,10 @@ describe('Gyro3 add liquidity test', () => {
addLiquidityInput,
}),
).rejects.toThrowError(
InputValidatorGyro.addLiquidityKindNotSupportedByGyro,
addLiquidityProportionalOnlyError(
addLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down Expand Up @@ -178,7 +205,10 @@ describe('Gyro3 add liquidity test', () => {
addLiquidityInput,
}),
).rejects.toThrowError(
InputValidatorGyro.addLiquidityKindNotSupportedByGyro,
addLiquidityProportionalOnlyError(
addLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down
48 changes: 39 additions & 9 deletions test/v2/addLiquidity/gyroE.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,7 +205,10 @@ describe('gyroE V2 add liquidity test', () => {
addLiquidityInput,
}),
).rejects.toThrowError(
InputValidatorGyro.addLiquidityKindNotSupportedByGyro,
addLiquidityProportionalOnlyError(
addLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down
Loading
Loading