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

Commit 2d2d189

Browse files
authoredSep 19, 2024··
feat: migrate to b-sdk 0.26.0 (#1107)
* feat: migrate to vault v3 deploy 8 (b-sdk 0.26.0) * chore: skip integration test * chore: avoid undefined pool mock fetch * chore: add Proportional remove v3 integration test * chore: add Single token remove v3 integration test * chore: skip test
1 parent 9e2da6d commit 2d2d189

14 files changed

+3257
-1048
lines changed
 

‎lib/debug-helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const vaultV3Address = sepoliaNetworkConfig.contracts.balancer.vaultV3 as
3636

3737
export const poolId = '0x68e3266c9c8bbd44ad9dca5afbfe629022aee9fe000200000000000000000512' as const // Balancer Weighted wjAura and WETH
3838

39-
export const sepoliaRouter = '0x1c58cc548a23956469c7C528Bb3a846c842dfaF9'
39+
export const sepoliaRouter = '0xB12FcB422aAe6720f882E22C340964a7723f2387'
4040

4141
/*
4242
Used to pretty print objects when debugging

‎lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.integration.spec.ts

+44-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { aWjAuraWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.b
66
import { UnbalancedAddLiquidityHandler } from './UnbalancedAddLiquidity.handler'
77
import { selectAddLiquidityHandler } from './selectAddLiquidityHandler'
88
import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types'
9+
import { Pool } from '../../../PoolProvider'
910

1011
function selectUnbalancedHandler() {
1112
return selectAddLiquidityHandler(aWjAuraWethPoolElementMock()) as UnbalancedAddLiquidityHandler
1213
}
1314

14-
describe('When adding unbalanced liquidity for a weighted pool', () => {
15+
describe('When adding unbalanced liquidity for a weighted V2 pool', () => {
1516
test('calculates price impact', async () => {
1617
const handler = selectUnbalancedHandler()
1718

@@ -72,3 +73,45 @@ describe('When adding unbalanced liquidity for a weighted pool', () => {
7273
expect(result.data).toBeDefined()
7374
})
7475
})
76+
77+
// TODO: unskip this test when sepolia V3 pools are available in production api
78+
describe.skip('When adding unbalanced liquidity for a V3 pool', async () => {
79+
// Sepolia
80+
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
81+
// const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
82+
// const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)
83+
const v3Pool = {} as unknown as Pool
84+
85+
const handler = selectAddLiquidityHandler(v3Pool) as UnbalancedAddLiquidityHandler
86+
87+
const humanAmountsIn: HumanTokenAmountWithAddress[] = [
88+
{ humanAmount: '0.1', tokenAddress: balAddress },
89+
]
90+
91+
it('calculates price impact', async () => {
92+
const priceImpact = await handler.getPriceImpact(humanAmountsIn)
93+
expect(priceImpact).toBeGreaterThan(0.002)
94+
})
95+
96+
it('queries bptOut', async () => {
97+
const result = await handler.simulate(humanAmountsIn)
98+
99+
expect(result.bptOut.amount).toBeGreaterThan(100000000000000n)
100+
})
101+
102+
it('builds Tx Config', async () => {
103+
// Store query response in handler instance
104+
const queryOutput = await handler.simulate(humanAmountsIn)
105+
106+
const result = await handler.buildCallData({
107+
humanAmountsIn,
108+
account: defaultTestUserAccount,
109+
slippagePercent: '0.2',
110+
queryOutput,
111+
})
112+
113+
const sepoliaRouter = '0xB12FcB422aAe6720f882E22C340964a7723f2387'
114+
expect(result.to).toBe(sepoliaRouter)
115+
expect(result.data).toBeDefined()
116+
})
117+
})

‎lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.integration.spec.ts

+56-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import networkConfig from '@/lib/config/networks/mainnet'
2-
import { balAddress, wETHAddress } from '@/lib/debug-helpers'
2+
import { balAddress, sepoliaRouter, wETHAddress } from '@/lib/debug-helpers'
33
import {
44
aBalWethPoolElementMock,
55
aPhantomStablePoolMock,
@@ -11,6 +11,8 @@ import { selectRemoveLiquidityHandler } from './selectRemoveLiquidityHandler'
1111
import { ProportionalRemoveLiquidityHandler } from './ProportionalRemoveLiquidity.handler'
1212
import { emptyAddress } from '@/lib/modules/web3/contracts/wagmi-helpers'
1313
import { connectWithDefaultUser } from '@/test/utils/wagmi/wagmi-connections'
14+
// import { GqlChain } from '@/lib/shared/services/api/generated/graphql'
15+
// import { getPoolMock } from '../../../__mocks__/getPoolMock'
1416

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

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

3133
await connectWithDefaultUser()
3234

33-
describe('When proportionally removing liquidity for a weighted pool', async () => {
35+
describe('When proportionally removing liquidity for a weighted v2 pool', async () => {
3436
test('returns ZERO price impact', async () => {
3537
const handler = selectProportionalHandler(poolMock)
3638

@@ -67,7 +69,7 @@ describe('When proportionally removing liquidity for a weighted pool', async ()
6769
})
6870
})
6971

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

@@ -79,3 +81,54 @@ describe('When removing liquidity from a stable pool', () => {
7981
expect(result.account).toBe(defaultTestUserAccount)
8082
})
8183
})
84+
85+
// TODO: unskip this test when sepolia V3 pools are available in production api
86+
describe.skip('When proportionally removing liquidity for a weighted v3 pool', async () => {
87+
// Sepolia
88+
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
89+
const wethAddress = '0x7b79995e5f793a07bc00c21412e50ecae098e7f9'
90+
// const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
91+
// const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)
92+
93+
const v3Pool = {} as unknown as Pool
94+
95+
const defaultQueryInput: QueryRemoveLiquidityInput = {
96+
humanBptIn: '0.01',
97+
tokenOut: emptyAddress, // We don't use in this scenario it but it is required to simplify TS interfaces
98+
}
99+
100+
test('returns ZERO price impact', async () => {
101+
const handler = selectProportionalHandler(v3Pool)
102+
103+
const priceImpact = await handler.getPriceImpact()
104+
105+
expect(priceImpact).toBe(0)
106+
})
107+
test('queries amounts out', async () => {
108+
const handler = selectProportionalHandler(v3Pool)
109+
110+
const result = await handler.simulate(defaultQueryInput)
111+
112+
const [wEthTokenAmountOut, balTokenAmountOut] = result.amountsOut
113+
114+
expect(balTokenAmountOut.token.address).toBe(balAddress)
115+
expect(balTokenAmountOut.amount).toBeGreaterThan(200000000000000n)
116+
117+
expect(wEthTokenAmountOut.token.address).toBe(wethAddress)
118+
expect(wEthTokenAmountOut.amount).toBeGreaterThan(100000000000000n)
119+
})
120+
121+
test('builds Tx Config', async () => {
122+
const handler = selectProportionalHandler(v3Pool)
123+
124+
const queryOutput = await handler.simulate(defaultQueryInput)
125+
126+
const result = await handler.buildCallData({
127+
...defaultBuildInput,
128+
queryOutput,
129+
})
130+
131+
expect(result.to).toBe(sepoliaRouter)
132+
expect(result.data).toBeDefined()
133+
})
134+
})

‎lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.integration.spec.ts

+48-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import networkConfig from '@/lib/config/networks/mainnet'
2-
import { balAddress, wETHAddress } from '@/lib/debug-helpers'
2+
import { balAddress, sepoliaRouter, wETHAddress } from '@/lib/debug-helpers'
33
import { aBalWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.builders'
44
import { defaultTestUserAccount } from '@/test/anvil/anvil-setup'
55
import { Pool } from '../../../PoolProvider'
66
import { QueryRemoveLiquidityInput, RemoveLiquidityType } from '../remove-liquidity.types'
77
import { SingleTokenRemoveLiquidityHandler } from './SingleTokenRemoveLiquidity.handler'
88
import { selectRemoveLiquidityHandler } from './selectRemoveLiquidityHandler'
9-
10-
const poolMock = aBalWethPoolElementMock() // 80BAL-20WETH
9+
// import { getPoolMock } from '../../../__mocks__/getPoolMock'
10+
// import { GqlChain } from '@/lib/shared/services/api/generated/graphql'
1111

1212
function selectSingleTokenHandler(pool: Pool): SingleTokenRemoveLiquidityHandler {
1313
return selectRemoveLiquidityHandler(
@@ -23,9 +23,11 @@ const defaultQueryInput: QueryRemoveLiquidityInput = {
2323

2424
const defaultBuildInput = { account: defaultTestUserAccount, slippagePercent: '0.2' }
2525

26-
describe('When removing unbalanced liquidity for a weighted pool', () => {
26+
describe('When removing unbalanced liquidity for a weighted V2 pool', () => {
27+
const v2poolMock = aBalWethPoolElementMock() // 80BAL-20WETH
28+
2729
test('queries amounts out', async () => {
28-
const handler = selectSingleTokenHandler(poolMock)
30+
const handler = selectSingleTokenHandler(v2poolMock)
2931

3032
const result = await handler.simulate(defaultQueryInput)
3133

@@ -39,7 +41,7 @@ describe('When removing unbalanced liquidity for a weighted pool', () => {
3941
})
4042

4143
test('builds Tx Config', async () => {
42-
const handler = selectSingleTokenHandler(poolMock)
44+
const handler = selectSingleTokenHandler(v2poolMock)
4345

4446
const inputs: QueryRemoveLiquidityInput = {
4547
humanBptIn: '1',
@@ -54,3 +56,43 @@ describe('When removing unbalanced liquidity for a weighted pool', () => {
5456
expect(result.data).toBeDefined()
5557
})
5658
})
59+
60+
// TODO: unskip this test when sepolia V3 pools are available in production api
61+
describe.skip('When removing unbalanced liquidity for a weighted V3 pool', async () => {
62+
// Sepolia
63+
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
64+
const wethAddress = '0x7b79995e5f793a07bc00c21412e50ecae098e7f9'
65+
// const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
66+
// const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)
67+
const v3Pool = {} as unknown as Pool
68+
69+
const defaultQueryInput: QueryRemoveLiquidityInput = {
70+
humanBptIn: '0.001',
71+
tokenOut: balAddress,
72+
}
73+
74+
test('queries amounts out', async () => {
75+
const handler = selectSingleTokenHandler(v3Pool)
76+
77+
const result = await handler.simulate(defaultQueryInput)
78+
79+
const [wEthTokenAmountOut, balTokenAmountOut] = result.amountsOut
80+
81+
expect(wEthTokenAmountOut.token.address).toBe(wethAddress)
82+
expect(wEthTokenAmountOut.amount).toBe(0n)
83+
84+
expect(balTokenAmountOut.token.address).toBe(balAddress)
85+
expect(balTokenAmountOut.amount).toBeGreaterThan(50000000000000000n)
86+
})
87+
88+
test('builds Tx Config', async () => {
89+
const handler = selectSingleTokenHandler(v3Pool)
90+
91+
const queryOutput = await handler.simulate(defaultQueryInput)
92+
93+
const result = await handler.buildCallData({ ...defaultBuildInput, queryOutput })
94+
95+
expect(result.to).toBe(sepoliaRouter)
96+
expect(result.data).toBeDefined()
97+
})
98+
})

‎lib/modules/pool/pool.helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { PoolIssue } from './alerts/pool-issues/PoolIssue.type'
2222
import { getUserTotalBalanceInt } from './user-balance.helpers'
2323
import { dateToUnixTimestamp } from '@/lib/shared/utils/time'
2424
import { balancerV2VaultAbi } from '../web3/contracts/abi/generated'
25-
import { balancerV3VaultAbi } from '../web3/contracts/abi/balancerV3Abi'
25+
import { balancerV3VaultAbi } from '../web3/contracts/abi/balancerV3VaultAbi'
2626

2727
/**
2828
* METHODS

‎lib/modules/pool/queries/usePoolEnrichWithOnChainData.integration.spec.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ function testPoolEnrichWithOnChainData(pool: Pool) {
1111
return result
1212
}
1313

14-
// TODO: un-skip when pool 0x7cf221fa36584f59a4f7fd7b946b8571c78e3692 is available in production api
14+
// TODO: un-skip when pool 0xec1b5ca86c83c7a85392063399e7d2170d502e00 is available in production api
1515
test.skip('enriches V3 pool with on-chain data', async () => {
16-
const poolId = '0x7cf221fa36584f59a4f7fd7b946b8571c78e3692' // V3 Balancer 50 BAL 50 WETH (sepolia experimental)
16+
const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // V3 Balancer 50 BAL 50 WETH (sepolia)
1717
const pool = await getPoolMock(poolId, GqlChain.Sepolia, defaultTestUserAccount)
1818

1919
// delete values to ensure that onchain data is used
@@ -45,12 +45,10 @@ test('enriches V2 pool with on-chain data', async () => {
4545
expect(Number(result.current.pool.dynamicData.totalShares)).toBeGreaterThan(0)
4646
})
4747

48-
// TODO: un-skip when pool 0x232a18645c4e33dd64e6925e03da0f0dd77ad003 is available in production api
49-
test.skip('enriches V1 Cow AMM pool with on-chain data', async () => {
50-
// const poolId = '0x232a18645c4e33dd64e6925e03da0f0dd77ad003' // V1 test Cow AMM pool
51-
const sepoliaPoolId = '0xd1bdc51decb61ee0c98e47fe17217c58be525180' // V1 test Cow AMM pool
48+
test('enriches V1 Cow AMM pool with on-chain data', async () => {
49+
const cowPoolId = '0xf706c50513446d709f08d3e5126cd74fb6bfda19'
5250

53-
const pool = await getPoolMock(sepoliaPoolId, GqlChain.Sepolia)
51+
const pool = await getPoolMock(cowPoolId, GqlChain.Mainnet)
5452

5553
// delete values to ensure that onchain data is used
5654
pool.dynamicData.totalLiquidity = '0'

‎lib/modules/pool/queries/usePoolEnrichWithOnChainData.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
22
import { Address, formatUnits } from 'viem'
33
import { useReadContracts } from 'wagmi'
44
import { useTokens } from '../../tokens/TokensProvider'
5-
import { balancerV3VaultAbi } from '../../web3/contracts/abi/balancerV3Abi'
5+
import { balancerV3ExtensionVaultAbi } from '../../web3/contracts/abi/balancerV3ExtensionVaultAbi'
66
import { weightedPoolV3Abi } from '../../web3/contracts/abi/weightedPoolV3Abi'
77
import { Pool } from '../PoolProvider'
88
import { BPT_DECIMALS } from '../pool.constants'
@@ -53,7 +53,7 @@ function useV3PoolOnchainData(pool: Pool) {
5353
contracts: [
5454
{
5555
chainId,
56-
abi: balancerV3VaultAbi,
56+
abi: balancerV3ExtensionVaultAbi,
5757
address: vaultAddress,
5858
functionName: 'getPoolTokenInfo',
5959
args: [pool.address as Address],

‎lib/modules/web3/contracts/abi/balancerV3Abi.ts

-994
This file was deleted.

‎lib/modules/web3/contracts/abi/balancerV3ExtensionVaultAbi.ts

+1,781
Large diffs are not rendered by default.

‎lib/modules/web3/contracts/abi/balancerV3VaultAbi.ts

+1,293
Large diffs are not rendered by default.

‎lib/modules/web3/contracts/useMulticall.integration.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Performs multicall in multiple chains', () => {
3535
expect(result.current.results[mainnet.id].data).toMatchInlineSnapshot(`
3636
{
3737
"ethBalance": {
38-
"result": 0n,
38+
"result": 1n,
3939
"status": "success",
4040
},
4141
}

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"dependencies": {
3636
"@apollo/client": "^3.11.8",
37-
"@balancer/sdk": "^0.25.0",
37+
"@balancer/sdk": "^0.26.0",
3838
"@chakra-ui/anatomy": "^2.2.2",
3939
"@chakra-ui/hooks": "^2.2.1",
4040
"@chakra-ui/icons": "^2.1.1",

‎pnpm-lock.yaml

+21-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/anvil/anvil-setup.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ export const ANVIL_NETWORKS: Record<NetworksWithFork, NetworkSetup> = {
5050
port: ANVIL_PORTS.Ethereum,
5151
// From time to time this block gets outdated having this kind of error in integration tests:
5252
// ContractFunctionExecutionError: The contract function "queryJoin" returned no data ("0x").
53-
// forkBlockNumber: 19769489n,
54-
// forkBlockNumber: 20061849n,
55-
forkBlockNumber: 20474895n,
53+
// forkBlockNumber: 20474895n,
54+
forkBlockNumber: 20777062n,
5655
},
5756
Polygon: {
5857
networkName: 'Polygon',
@@ -66,7 +65,7 @@ export const ANVIL_NETWORKS: Record<NetworksWithFork, NetworkSetup> = {
6665
fallBackRpc: 'https://gateway.tenderly.co/public/sepolia',
6766
port: ANVIL_PORTS.Sepolia,
6867
// For now we will use the last block until v3 deployments are final
69-
// forkBlockNumber: ,
68+
// forkBlockNumber: 6679621n,
7069
},
7170
}
7271

0 commit comments

Comments
 (0)
This repository has been archived.