Skip to content

Commit

Permalink
Fix remove liquidity tests for gyro
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Dec 10, 2024
1 parent d376457 commit 4075b93
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 59 deletions.
43 changes: 26 additions & 17 deletions test/v2/removeLiquidity/gyro2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Gyro2 remove liquidity test', () => {
let input: Omit<RemoveLiquidityUnbalancedInput, 'amountsOut'>;
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,
Expand All @@ -138,7 +138,10 @@ describe('Gyro2 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
removeLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down Expand Up @@ -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,
Expand All @@ -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,
),
);
});
});
Expand Down
37 changes: 23 additions & 14 deletions test/v2/removeLiquidity/gyro3.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Gyro3 remove liquidity test', () => {
let input: Omit<RemoveLiquidityUnbalancedInput, 'amountsOut'>;
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,
Expand All @@ -138,7 +138,10 @@ describe('Gyro3 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
removeLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down Expand Up @@ -166,7 +169,10 @@ describe('Gyro3 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
removeLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand All @@ -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 = {
Expand All @@ -192,7 +198,10 @@ describe('Gyro3 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput: input }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
input.kind,
poolState.type,
),
);
});
});
Expand Down
37 changes: 23 additions & 14 deletions test/v2/removeLiquidity/gyroE.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('GyroE V1 remove liquidity test', () => {
let input: Omit<RemoveLiquidityUnbalancedInput, 'amountsOut'>;
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,
Expand All @@ -138,7 +138,10 @@ describe('GyroE V1 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
removeLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand Down Expand Up @@ -166,7 +169,10 @@ describe('GyroE V1 remove liquidity test', () => {
await expect(() =>
doRemoveLiquidity({ ...txInput, removeLiquidityInput }),
).rejects.toThrowError(
InputValidatorGyro.removeLiquidityKindNotSupportedByGyro,
removeLiquidityProportionalOnlyError(
removeLiquidityInput.kind,
poolState.type,
),
);
});
});
Expand All @@ -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 = {
Expand All @@ -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,
),
);
});
});
Expand Down
Loading

0 comments on commit 4075b93

Please sign in to comment.