Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
chore: add Proportional remove v3 integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
agualis committed Sep 19, 2024
1 parent 2bd69d4 commit bcd81d4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_APP_ENV=test
NEXT_PUBLIC_BALANCER_API_URL=https://api-v3.balancer.fi/graphql
NEXT_PUBLIC_BALANCER_API_URL=https://test-api-v3.balancer.fi/graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import networkConfig from '@/lib/config/networks/mainnet'
import { balAddress, wETHAddress } from '@/lib/debug-helpers'
import { balAddress, sepoliaRouter, wETHAddress } from '@/lib/debug-helpers'
import {
aBalWethPoolElementMock,
aPhantomStablePoolMock,
Expand All @@ -11,6 +11,8 @@ import { selectRemoveLiquidityHandler } from './selectRemoveLiquidityHandler'
import { ProportionalRemoveLiquidityHandler } from './ProportionalRemoveLiquidity.handler'
import { emptyAddress } from '@/lib/modules/web3/contracts/wagmi-helpers'
import { connectWithDefaultUser } from '@/test/utils/wagmi/wagmi-connections'
// import { GqlChain } from '@/lib/shared/services/api/generated/graphql'
// import { getPoolMock } from '../../../__mocks__/getPoolMock'

const poolMock = aBalWethPoolElementMock() // 80BAL-20WETH

Expand All @@ -30,7 +32,7 @@ const defaultBuildInput = { account: defaultTestUserAccount, slippagePercent: '0

await connectWithDefaultUser()

describe('When proportionally removing liquidity for a weighted pool', async () => {
describe('When proportionally removing liquidity for a weighted v2 pool', async () => {
test('returns ZERO price impact', async () => {
const handler = selectProportionalHandler(poolMock)

Expand Down Expand Up @@ -67,7 +69,7 @@ describe('When proportionally removing liquidity for a weighted pool', async ()
})
})

describe('When removing liquidity from a stable pool', () => {
describe('When removing liquidity from a V2 stable pool', () => {
test('queries remove liquidity', async () => {
const pool = aPhantomStablePoolMock() // wstETH-rETH-sfrxETH

Expand All @@ -79,3 +81,54 @@ describe('When removing liquidity from a stable pool', () => {
expect(result.account).toBe(defaultTestUserAccount)
})
})

// TODO: unskip this test when sepolia V3 pools are available in production api
describe.skip('When proportionally removing liquidity for a weighted v3 pool', async () => {
// Sepolia
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
const wethAddress = '0x7b79995e5f793a07bc00c21412e50ecae098e7f9'
// const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
// const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)

const v3Pool = {} as unknown as Pool

const defaultQueryInput: QueryRemoveLiquidityInput = {
humanBptIn: '0.01',
tokenOut: emptyAddress, // We don't use in this scenario it but it is required to simplify TS interfaces
}

test('returns ZERO price impact', async () => {
const handler = selectProportionalHandler(v3Pool)

const priceImpact = await handler.getPriceImpact()

expect(priceImpact).toBe(0)
})
test('queries amounts out', async () => {
const handler = selectProportionalHandler(v3Pool)

const result = await handler.simulate(defaultQueryInput)

const [wEthTokenAmountOut, balTokenAmountOut] = result.amountsOut

expect(balTokenAmountOut.token.address).toBe(balAddress)
expect(balTokenAmountOut.amount).toBeGreaterThan(200000000000000n)

expect(wEthTokenAmountOut.token.address).toBe(wethAddress)
expect(wEthTokenAmountOut.amount).toBeGreaterThan(100000000000000n)
})

test('builds Tx Config', async () => {
const handler = selectProportionalHandler(v3Pool)

const queryOutput = await handler.simulate(defaultQueryInput)

const result = await handler.buildCallData({
...defaultBuildInput,
queryOutput,
})

expect(result.to).toBe(sepoliaRouter)
expect(result.data).toBeDefined()
})
})

0 comments on commit bcd81d4

Please sign in to comment.