From 321d109ad4b19cc94dceba8cf2a495737645aade Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 11 Dec 2024 10:45:30 -0300 Subject: [PATCH 1/5] Add support for InitBuffer --- src/entities/addLiquidityBuffer/index.ts | 9 - src/entities/index.ts | 2 + src/entities/initBuffer/doInitBufferQuery.ts | 35 +++ src/entities/initBuffer/index.ts | 94 +++++++ src/entities/initBuffer/types.ts | 31 +++ src/entities/permit2Helper/index.ts | 41 ++++ src/entities/tokenAmount.ts | 8 + test/anvil/anvil-global-setup.ts | 2 +- test/lib/utils/addresses.ts | 4 + .../addLiquidity/stable.integration.test.ts | 13 +- .../composableStable.integration.test.ts | 10 +- .../composableStable.integration.test.ts | 4 +- .../initBuffer/initBuffer.integration.test.ts | 230 ++++++++++++++++++ 13 files changed, 466 insertions(+), 17 deletions(-) create mode 100644 src/entities/initBuffer/doInitBufferQuery.ts create mode 100644 src/entities/initBuffer/index.ts create mode 100644 src/entities/initBuffer/types.ts create mode 100644 test/v3/initBuffer/initBuffer.integration.test.ts diff --git a/src/entities/addLiquidityBuffer/index.ts b/src/entities/addLiquidityBuffer/index.ts index d2b9058a..987a18a9 100644 --- a/src/entities/addLiquidityBuffer/index.ts +++ b/src/entities/addLiquidityBuffer/index.ts @@ -1,8 +1,3 @@ -// A user can add liquidity to a boosted pool in various forms. The following ways are -// available: -// 1. Unbalanced - addLiquidityUnbalancedToERC4626Pool -// 2. Proportional - addLiquidityProportionalToERC4626Pool - import { encodeFunctionData } from 'viem'; import { TokenAmount } from '@/entities/tokenAmount'; @@ -15,8 +10,6 @@ import { Token } from '../token'; import { BALANCER_BUFFER_ROUTER } from '@/utils'; import { balancerBufferRouterAbi, balancerRouterAbi } from '@/abi'; -import { InputValidator } from '../inputValidator/inputValidator'; - import { AddLiquidityBufferBuildCallInput, AddLiquidityBufferBuildCallOutput, @@ -25,8 +18,6 @@ import { } from './types'; export class AddLiquidityBufferV3 { - private readonly inputValidator: InputValidator = new InputValidator(); - async query( input: AddLiquidityBufferInput, bufferState: BufferState, diff --git a/src/entities/index.ts b/src/entities/index.ts index 216fbffc..4f8caaa4 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -10,6 +10,8 @@ export * from './addLiquidityNested/addLiquidityNestedV2/types'; export * from './addLiquidityNested/addLiquidityNestedV3/types'; export * from './createPool'; export * from './encoders'; +export * from './initBuffer'; +export * from './initBuffer/types'; export * from './initPool'; export * from './permitHelper'; export * from './permit2Helper'; diff --git a/src/entities/initBuffer/doInitBufferQuery.ts b/src/entities/initBuffer/doInitBufferQuery.ts new file mode 100644 index 00000000..fb7190cd --- /dev/null +++ b/src/entities/initBuffer/doInitBufferQuery.ts @@ -0,0 +1,35 @@ +import { createPublicClient, http } from 'viem'; +import { BALANCER_BUFFER_ROUTER, ChainId, CHAINS } from '@/utils'; +import { Address } from '@/types'; +import { + balancerBufferRouterAbi, + permit2Abi, + vaultExtensionAbi_V3, + vaultV3Abi, +} from '@/abi'; + +export const doInitBufferQuery = async ( + rpcUrl: string, + chainId: ChainId, + wrappedToken: Address, + exactAmountUnderlyingIn: bigint, + exactAmountWrappedIn: bigint, +): Promise<{ issuedShares: bigint }> => { + const client = createPublicClient({ + transport: http(rpcUrl), + chain: CHAINS[chainId], + }); + + const { result: issuedShares } = await client.simulateContract({ + address: BALANCER_BUFFER_ROUTER[chainId], + abi: [ + ...balancerBufferRouterAbi, + ...vaultV3Abi, + ...vaultExtensionAbi_V3, + ...permit2Abi, + ], + functionName: 'queryInitializeBuffer', + args: [wrappedToken, exactAmountUnderlyingIn, exactAmountWrappedIn], + }); + return { issuedShares }; +}; diff --git a/src/entities/initBuffer/index.ts b/src/entities/initBuffer/index.ts new file mode 100644 index 00000000..42106b1c --- /dev/null +++ b/src/entities/initBuffer/index.ts @@ -0,0 +1,94 @@ +import { encodeFunctionData } from 'viem'; +import { TokenAmount } from '@/entities/tokenAmount'; + +import { Permit2 } from '@/entities/permit2Helper'; + +import { doInitBufferQuery } from './doInitBufferQuery'; +import { BALANCER_BUFFER_ROUTER } from '@/utils'; +import { balancerBufferRouterAbi, balancerRouterAbi } from '@/abi'; + +import { + InitBufferBuildCallInput, + InitBufferBuildCallOutput, + InitBufferInput, + InitBufferQueryOutput, +} from './types'; + +export class InitBufferV3 { + async query(input: InitBufferInput): Promise { + const { issuedShares } = await doInitBufferQuery( + input.rpcUrl, + input.chainId, + input.wrappedAmountIn.address, + input.underlyingAmountIn.rawAmount, + input.wrappedAmountIn.rawAmount, + ); + const underlyingAmountIn = TokenAmount.fromInputAmount( + input.underlyingAmountIn, + input.chainId, + ); + const wrappedAmountIn = TokenAmount.fromInputAmount( + input.wrappedAmountIn, + input.chainId, + ); + + const output: InitBufferQueryOutput = { + issuedShares, + underlyingAmountIn, + wrappedAmountIn, + chainId: input.chainId, + protocolVersion: 3, + to: BALANCER_BUFFER_ROUTER[input.chainId], + }; + + return output; + } + + buildCall(input: InitBufferBuildCallInput): InitBufferBuildCallOutput { + const minIssuedShares = input.slippage.applyTo(input.issuedShares, -1); + + const callData = encodeFunctionData({ + abi: balancerBufferRouterAbi, + functionName: 'initializeBuffer', + args: [ + input.wrappedAmountIn.token.address, + input.underlyingAmountIn.amount, + input.wrappedAmountIn.amount, + minIssuedShares, + ] as const, + }); + return { + callData, + to: BALANCER_BUFFER_ROUTER[input.chainId], + value: 0n, // Default to 0 as native not supported + minIssuedShares, + }; + } + + public buildCallWithPermit2( + input: InitBufferBuildCallInput, + permit2: Permit2, + ): InitBufferBuildCallOutput { + // generate same calldata as buildCall + const buildCallOutput = this.buildCall(input); + + const args = [ + [], + [], + permit2.batch, + permit2.signature, + [buildCallOutput.callData], + ] as const; + + const callData = encodeFunctionData({ + abi: balancerRouterAbi, + functionName: 'permitBatchAndCall', + args, + }); + + return { + ...buildCallOutput, + callData, + }; + } +} diff --git a/src/entities/initBuffer/types.ts b/src/entities/initBuffer/types.ts new file mode 100644 index 00000000..f0dbb1bc --- /dev/null +++ b/src/entities/initBuffer/types.ts @@ -0,0 +1,31 @@ +import { Address, Hex } from 'viem'; +import { Slippage } from '../slippage'; +import { TokenAmount } from '../tokenAmount'; +import { InputAmount } from '@/types'; + +export type InitBufferInput = { + chainId: number; + rpcUrl: string; + wrappedAmountIn: InputAmount; + underlyingAmountIn: InputAmount; +}; + +export type InitBufferQueryOutput = { + issuedShares: bigint; + wrappedAmountIn: TokenAmount; + underlyingAmountIn: TokenAmount; + chainId: number; + protocolVersion: 3; + to: Address; +}; + +export type InitBufferBuildCallInput = { + slippage: Slippage; +} & InitBufferQueryOutput; + +export type InitBufferBuildCallOutput = { + callData: Hex; + to: Address; + value: bigint; + minIssuedShares: bigint; +}; diff --git a/src/entities/permit2Helper/index.ts b/src/entities/permit2Helper/index.ts index 9b14b4e7..006e21df 100644 --- a/src/entities/permit2Helper/index.ts +++ b/src/entities/permit2Helper/index.ts @@ -30,6 +30,7 @@ import { TokenAmount } from '../tokenAmount'; import { permit2Abi } from '@/abi'; import { getAmountsCall } from '../addLiquidity/helpers'; import { AddLiquidityBufferBuildCallInput } from '../addLiquidityBuffer/types'; +import { InitBufferBuildCallInput } from '../initBuffer/types'; export * from './allowanceTransfer'; export * from './constants'; @@ -195,6 +196,46 @@ export class Permit2Helper { return signPermit2(input.client, input.owner, spender, details); } + static async signInitBufferApproval( + input: InitBufferBuildCallInput & { + client: PublicWalletClient; + owner: Address; + nonces?: number[]; + expirations?: number[]; + }, + ): Promise { + if (input.nonces && input.nonces.length !== 2) { + throw new Error("Nonces length doesn't match amountsIn length"); + } + if (input.expirations && input.expirations.length !== 2) { + throw new Error( + "Expirations length doesn't match amountsIn length", + ); + } + const spender = BALANCER_BUFFER_ROUTER[input.chainId]; + const details: PermitDetails[] = [ + await getDetails( + input.client, + input.wrappedAmountIn.token.address, + input.owner, + spender, + input.wrappedAmountIn.amount, + input.expirations ? input.expirations[0] : undefined, + input.nonces ? input.nonces[0] : undefined, + ), + await getDetails( + input.client, + input.underlyingAmountIn.token.address, + input.owner, + spender, + input.underlyingAmountIn.amount, + input.expirations ? input.expirations[1] : undefined, + input.nonces ? input.nonces[1] : undefined, + ), + ]; + return signPermit2(input.client, input.owner, spender, details); + } + static async signSwapApproval( input: SwapBuildCallInputBase & { client: PublicWalletClient; diff --git a/src/entities/tokenAmount.ts b/src/entities/tokenAmount.ts index bcae4513..5a32d292 100644 --- a/src/entities/tokenAmount.ts +++ b/src/entities/tokenAmount.ts @@ -35,6 +35,14 @@ export class TokenAmount { return new TokenAmount(token, rawAmount); } + public static fromInputAmount( + input: InputAmount, + chainId: number, + ): TokenAmount { + const token = new Token(chainId, input.address, input.decimals); + return new TokenAmount(token, input.rawAmount); + } + protected constructor(token: Token, amount: BigintIsh) { this.decimalScale = DECIMAL_SCALES[token.decimals]; this.token = token; diff --git a/test/anvil/anvil-global-setup.ts b/test/anvil/anvil-global-setup.ts index f6be3c2a..2a1b2dbb 100644 --- a/test/anvil/anvil-global-setup.ts +++ b/test/anvil/anvil-global-setup.ts @@ -45,7 +45,7 @@ export const ANVIL_NETWORKS: Record = { rpcEnv: 'ETHEREUM_RPC_URL', fallBackRpc: 'https://mainnet.gateway.tenderly.co', port: ANVIL_PORTS.MAINNET, - forkBlockNumber: 18980070n, + forkBlockNumber: 21373640n, }, POLYGON: { rpcEnv: 'POLYGON_RPC_URL', diff --git a/test/lib/utils/addresses.ts b/test/lib/utils/addresses.ts index b1066341..b497a716 100644 --- a/test/lib/utils/addresses.ts +++ b/test/lib/utils/addresses.ts @@ -55,6 +55,10 @@ export const TOKENS: Record> = { address: '0xae78736cd615f374d3085123a210448e74fc6393', decimals: 18, }, + gearboxUSDC: { + address: '0xda00000035fef4082F78dEF6A8903bee419FbF8E', + decimals: 6, + }, }, [ChainId.OPTIMISM]: { FRAX: { diff --git a/test/v2/addLiquidity/stable.integration.test.ts b/test/v2/addLiquidity/stable.integration.test.ts index 28c84d95..ff104bce 100644 --- a/test/v2/addLiquidity/stable.integration.test.ts +++ b/test/v2/addLiquidity/stable.integration.test.ts @@ -41,13 +41,13 @@ import { } from 'test/lib/utils'; import { ANVIL_NETWORKS, startFork } from 'test/anvil/anvil-global-setup'; -const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); const chainId = ChainId.MAINNET; const poolId = POOLS[chainId].wstETH_wETH_MSP.id; // B-stETH-STABLE describe('add liquidity stable test', () => { let txInput: AddLiquidityTxInput; let poolState: PoolState; + let rpcUrl: string; beforeAll(async () => { // setup mock api @@ -56,6 +56,13 @@ describe('add liquidity stable test', () => { // get pool state from api poolState = await api.getPool(poolId); + // TODO: figure out why these tests fail when udpating blockNumber to 21373640n + ({ rpcUrl } = await startFork( + ANVIL_NETWORKS.MAINNET, + undefined, + 18980070n, + )); + const client = createTestClient({ mode: 'anvil', chain: CHAINS[chainId], @@ -137,7 +144,7 @@ describe('add liquidity stable test', () => { addLiquidityOutput, txInput.slippage, chainId, - poolState.protocolVersion, + poolState.protocolVersion as 2 | 3, wethIsEth, ); }); @@ -190,7 +197,7 @@ describe('add liquidity stable test', () => { addLiquidityOutput, txInput.slippage, chainId, - poolState.protocolVersion, + poolState.protocolVersion as 2 | 3, wethIsEth, ); }); diff --git a/test/v2/createPool/composableStable.integration.test.ts b/test/v2/createPool/composableStable.integration.test.ts index d3211303..b70dd3dd 100644 --- a/test/v2/createPool/composableStable.integration.test.ts +++ b/test/v2/createPool/composableStable.integration.test.ts @@ -18,14 +18,20 @@ import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; import { doCreatePool } from '../../lib/utils/createPoolHelper'; import { CreatePoolTxInput } from '../../lib/utils/types'; -const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); - describe('Create Composable Stable Pool tests', () => { const chainId = ChainId.MAINNET; let txInput: CreatePoolTxInput; let poolAddress: Address; let createPoolComposableStableInput: CreatePoolV2ComposableStableInput; + let rpcUrl: string; + beforeAll(async () => { + // TODO: find out why findEventInReceiptLogs doesn't find the event when blockNumber is updated to 21373640n (this causes test to fail) + ({ rpcUrl } = await startFork( + ANVIL_NETWORKS.MAINNET, + undefined, + 18980070n, + )); const client = createTestClient({ mode: 'anvil', chain: CHAINS[chainId], diff --git a/test/v2/removeLiquidity/composableStable.integration.test.ts b/test/v2/removeLiquidity/composableStable.integration.test.ts index 6891df99..a18ca8b6 100644 --- a/test/v2/removeLiquidity/composableStable.integration.test.ts +++ b/test/v2/removeLiquidity/composableStable.integration.test.ts @@ -98,7 +98,7 @@ describe('composable stable remove liquidity test', () => { .filter((_, index) => index !== bptIndex); amountsOut = poolTokensWithoutBpt.map((t) => ({ - rawAmount: parseUnits('20', t.decimals), + rawAmount: parseUnits('2', t.decimals), decimals: t.decimals, address: t.address, })); @@ -152,7 +152,7 @@ describe('composable stable remove liquidity test', () => { let amountOut: InputAmount; beforeAll(() => { amountOut = { - rawAmount: parseUnits('20', wETH.decimals), + rawAmount: parseUnits('2', wETH.decimals), decimals: wETH.decimals, address: wETH.address, }; diff --git a/test/v3/initBuffer/initBuffer.integration.test.ts b/test/v3/initBuffer/initBuffer.integration.test.ts new file mode 100644 index 00000000..6dc93576 --- /dev/null +++ b/test/v3/initBuffer/initBuffer.integration.test.ts @@ -0,0 +1,230 @@ +// pnpm test -- v3/initBuffer/initBuffer.integration.test.ts + +import { config } from 'dotenv'; +config(); + +import { + Address, + createTestClient, + http, + parseUnits, + publicActions, + TestActions, + walletActions, +} from 'viem'; + +import { + Slippage, + Hex, + CHAINS, + ChainId, + InitBufferInput, + InitBufferV3, + Permit2Helper, + PERMIT2, + PublicWalletClient, + BALANCER_BUFFER_ROUTER, +} from '../../../src'; +import { + TOKENS, + sendTransactionGetBalances, + setTokenBalance, + approveSpenderOnToken, + approveSpenderOnPermit2, +} from '../../lib/utils'; +import { ANVIL_NETWORKS, startFork } from '../../anvil/anvil-global-setup'; +import { InitBufferBuildCallInput } from '@/entities/initBuffer/types'; + +const chainId = ChainId.MAINNET; +const USDC = TOKENS[chainId].USDC; +const gearboxUSDC = TOKENS[chainId].gearboxUSDC; + +describe('Buffer Init', () => { + let client: PublicWalletClient & TestActions; + let rpcUrl: string; + let snapshot: Hex; + let testAddress: Address; + const initBuffer = new InitBufferV3(); + + beforeAll(async () => { + ({ rpcUrl } = await startFork(ANVIL_NETWORKS[ChainId[chainId]])); + + client = createTestClient({ + mode: 'anvil', + chain: CHAINS[chainId], + transport: http(rpcUrl), + }) + .extend(publicActions) + .extend(walletActions); + + const accounts = await client.getAddresses(); + + testAddress = accounts[0]; + + await setTokenBalance( + client, + testAddress, + USDC.address, + USDC.slot as number, + parseUnits('100000', USDC.decimals), + ); + + // Approve Permit2 to spend user tokens + await approveSpenderOnToken( + client, + testAddress, + USDC.address, + PERMIT2[chainId], + ); + + snapshot = await client.snapshot(); + }); + + beforeEach(async () => { + await client.revert({ + id: snapshot, + }); + snapshot = await client.snapshot(); + }); + + describe('permit 2 direct approval', () => { + beforeEach(async () => { + // Approve Buffer Router to spend tokens on the users behalf via Permit2 + await approveSpenderOnPermit2( + client, + testAddress, + USDC.address, + BALANCER_BUFFER_ROUTER[chainId], + ); + }); + + test('init', async () => { + const initBufferInput: InitBufferInput = { + chainId, + rpcUrl, + underlyingAmountIn: { + rawAmount: parseUnits('100', USDC.decimals), + decimals: USDC.decimals, + address: USDC.address, + }, + wrappedAmountIn: { + rawAmount: parseUnits('0', gearboxUSDC.decimals), + decimals: gearboxUSDC.decimals, + address: gearboxUSDC.address, + }, + }; + const initBufferQueryOutput = + await initBuffer.query(initBufferInput); + + expect(initBufferQueryOutput.wrappedAmountIn.amount).toEqual( + initBufferInput.wrappedAmountIn.rawAmount, + ); + expect(initBufferQueryOutput.underlyingAmountIn.amount).toEqual( + initBufferInput.underlyingAmountIn.rawAmount, + ); + expect(initBufferQueryOutput.issuedShares > 0n).to.be.true; + + const slippage = Slippage.fromPercentage('1'); + const initBufferBuildCallInput: InitBufferBuildCallInput = { + ...initBufferQueryOutput, + slippage, + }; + + const initBufferBuildCallOutput = initBuffer.buildCall( + initBufferBuildCallInput, + ); + + const tokensForBalanceCheck = [ + initBufferQueryOutput.wrappedAmountIn, + initBufferQueryOutput.underlyingAmountIn, + ]; + + const { transactionReceipt, balanceDeltas } = + await sendTransactionGetBalances( + tokensForBalanceCheck.map((t) => t.token.address), + client, + testAddress, + initBufferBuildCallOutput.to, + initBufferBuildCallOutput.callData, + ); + + expect(transactionReceipt.status).to.eq('success'); + + const expectedDeltas = tokensForBalanceCheck.map((t) => t.amount); + expect(balanceDeltas).to.deep.eq(expectedDeltas); + + expect(initBufferBuildCallOutput.minIssuedShares).to.deep.eq( + slippage.applyTo(initBufferQueryOutput.issuedShares, -1), + ); + }); + }); + + describe('permit 2 signatures', () => { + test('init', async () => { + const initBufferInput: InitBufferInput = { + chainId, + rpcUrl, + underlyingAmountIn: { + rawAmount: parseUnits('100', USDC.decimals), + decimals: USDC.decimals, + address: USDC.address, + }, + wrappedAmountIn: { + rawAmount: parseUnits('0', gearboxUSDC.decimals), + decimals: gearboxUSDC.decimals, + address: gearboxUSDC.address, + }, + }; + + const initBufferQueryOutput = + await initBuffer.query(initBufferInput); + const slippage = Slippage.fromPercentage('1'); + const initBufferBuildInput: InitBufferBuildCallInput = { + ...initBufferQueryOutput, + slippage, + }; + + const permit2 = await Permit2Helper.signInitBufferApproval({ + ...initBufferBuildInput, + client, + owner: testAddress, + }); + + const initBufferBuildCallOutput = initBuffer.buildCallWithPermit2( + initBufferBuildInput, + permit2, + ); + + const tokensForBalanceCheck = [ + initBufferQueryOutput.wrappedAmountIn, + initBufferQueryOutput.underlyingAmountIn, + ]; + + const { transactionReceipt, balanceDeltas } = + await sendTransactionGetBalances( + tokensForBalanceCheck.map((t) => t.token.address), + client, + testAddress, + initBufferBuildCallOutput.to, + initBufferBuildCallOutput.callData, + ); + + expect(transactionReceipt.status).to.eq('success'); + + expect(initBufferQueryOutput.wrappedAmountIn.amount).toEqual( + initBufferInput.wrappedAmountIn.rawAmount, + ); + expect(initBufferQueryOutput.underlyingAmountIn.amount).toEqual( + initBufferInput.underlyingAmountIn.rawAmount, + ); + expect(initBufferQueryOutput.issuedShares > 0n).to.be.true; + + const expectedDeltas = tokensForBalanceCheck.map((t) => t.amount); + expect(balanceDeltas).to.deep.eq(expectedDeltas); + + expect(initBufferBuildCallOutput.minIssuedShares).to.deep.eq( + slippage.applyTo(initBufferQueryOutput.issuedShares, -1), + ); + }); + }); +}); From a6ebf0d98b7ebe6f4cfce463823c72e4906cdf9b Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 11 Dec 2024 10:46:59 -0300 Subject: [PATCH 2/5] Add changeset --- .changeset/hungry-roses-sleep.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-roses-sleep.md diff --git a/.changeset/hungry-roses-sleep.md b/.changeset/hungry-roses-sleep.md new file mode 100644 index 00000000..c7680c7b --- /dev/null +++ b/.changeset/hungry-roses-sleep.md @@ -0,0 +1,5 @@ +--- +"@balancer/sdk": minor +--- + +Add support for InitBuffer From bff7ad5210a990425bafd24166320e716a2237ee Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 11 Dec 2024 11:14:46 -0300 Subject: [PATCH 3/5] Revert blocknumber change for init test --- test/v2/initPool/composableStable.integration.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/v2/initPool/composableStable.integration.test.ts b/test/v2/initPool/composableStable.integration.test.ts index 7388a2d2..03993e8b 100644 --- a/test/v2/initPool/composableStable.integration.test.ts +++ b/test/v2/initPool/composableStable.integration.test.ts @@ -26,7 +26,11 @@ import { doCreatePool } from '../../lib/utils/createPoolHelper'; import { forkSetup } from '../../lib/utils/helper'; import { assertInitPool, doInitPool } from '../../lib/utils/initPoolHelper'; -const { rpcUrl } = await startFork(ANVIL_NETWORKS.MAINNET); +const { rpcUrl } = await startFork( + ANVIL_NETWORKS.MAINNET, + undefined, + 18980070n, +); const chainId = ChainId.MAINNET; describe('Composable Stable Pool - Init Pool tests', async () => { From ca1348518398e72f2e61a015c03188e3a88a4efc Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Wed, 11 Dec 2024 11:46:36 -0300 Subject: [PATCH 4/5] Attempt to fix test with snapshots --- .../weighted.integration.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/v2/removeLiquidity/weighted.integration.test.ts b/test/v2/removeLiquidity/weighted.integration.test.ts index 21d23baf..75fde862 100644 --- a/test/v2/removeLiquidity/weighted.integration.test.ts +++ b/test/v2/removeLiquidity/weighted.integration.test.ts @@ -8,6 +8,7 @@ import { parseEther, parseUnits, publicActions, + TestActions, walletActions, } from 'viem'; import { @@ -27,6 +28,7 @@ import { InputAmount, PoolType, RemoveLiquiditySingleTokenExactOutInput, + PublicWalletClient, } from '../../../src'; import { forkSetup } from '../../lib/utils/helper'; import { @@ -50,6 +52,9 @@ const wETH = TOKENS[chainId].WETH; describe('weighted remove liquidity test', () => { let txInput: RemoveLiquidityTxInput; let poolInput: PoolState; + let client: PublicWalletClient & TestActions; + let snapshot: Hex; + beforeAll(async () => { // setup mock api const api = new MockApi(); @@ -57,7 +62,7 @@ describe('weighted remove liquidity test', () => { // get pool state from api poolInput = await api.getPool(poolId); - const client = createTestClient({ + client = createTestClient({ mode: 'anvil', chain: CHAINS[chainId], transport: http(rpcUrl), @@ -73,9 +78,7 @@ describe('weighted remove liquidity test', () => { testAddress: '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f', // Balancer DAO Multisig removeLiquidityInput: {} as RemoveLiquidityInput, }; - }); - beforeEach(async () => { await forkSetup( txInput.client, txInput.testAddress, @@ -83,6 +86,15 @@ describe('weighted remove liquidity test', () => { [0], [parseUnits('1000', 18)], ); + + snapshot = await client.snapshot(); + }); + + beforeEach(async () => { + await client.revert({ + id: snapshot, + }); + snapshot = await client.snapshot(); }); describe('remove liquidity unbalanced', async () => { From 6017e8c0794990aa40d99b93f8a9b05bdac3499d Mon Sep 17 00:00:00 2001 From: Bruno Eidam Guerios Date: Fri, 13 Dec 2024 12:15:04 -0300 Subject: [PATCH 5/5] Remove TODO --- test/v2/createPool/composableStable.integration.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/v2/createPool/composableStable.integration.test.ts b/test/v2/createPool/composableStable.integration.test.ts index b70dd3dd..085ae805 100644 --- a/test/v2/createPool/composableStable.integration.test.ts +++ b/test/v2/createPool/composableStable.integration.test.ts @@ -26,7 +26,6 @@ describe('Create Composable Stable Pool tests', () => { let rpcUrl: string; beforeAll(async () => { - // TODO: find out why findEventInReceiptLogs doesn't find the event when blockNumber is updated to 21373640n (this causes test to fail) ({ rpcUrl } = await startFork( ANVIL_NETWORKS.MAINNET, undefined,