Skip to content

Commit

Permalink
feat: migrate to vault v3 deploy 8 (b-sdk 0.26.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
agualis committed Sep 18, 2024
1 parent 3a9acbc commit 29de0fa
Show file tree
Hide file tree
Showing 13 changed files with 3,154 additions and 1,040 deletions.
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_APP_ENV=test
NEXT_PUBLIC_BALANCER_API_URL=https://api-v3.balancer.fi/graphql
// TODO: change back to production api when v3 sepolia pools are available
NEXT_PUBLIC_BALANCER_API_URL=https://test-api-v3.balancer.fi/graphql
2 changes: 1 addition & 1 deletion lib/debug-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const vaultV3Address = sepoliaNetworkConfig.contracts.balancer.vaultV3 as

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

export const sepoliaRouter = '0x1c58cc548a23956469c7C528Bb3a846c842dfaF9'
export const sepoliaRouter = '0xB12FcB422aAe6720f882E22C340964a7723f2387'

/*
Used to pretty print objects when debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { aWjAuraWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.b
import { UnbalancedAddLiquidityHandler } from './UnbalancedAddLiquidity.handler'
import { selectAddLiquidityHandler } from './selectAddLiquidityHandler'
import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types'
import { GqlChain } from '@/lib/shared/services/api/generated/graphql'
import { getPoolMock } from '../../../__mocks__/getPoolMock'

function selectUnbalancedHandler() {
return selectAddLiquidityHandler(aWjAuraWethPoolElementMock()) as UnbalancedAddLiquidityHandler
}

describe('When adding unbalanced liquidity for a weighted pool', () => {
describe('When adding unbalanced liquidity for a weighted V2 pool', () => {
test('calculates price impact', async () => {
const handler = selectUnbalancedHandler()

Expand Down Expand Up @@ -72,3 +74,43 @@ describe('When adding unbalanced liquidity for a weighted pool', () => {
expect(result.data).toBeDefined()
})
})

describe('When adding unbalanced liquidity for a V3 pool', async () => {
// Sepolia
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)

const handler = selectAddLiquidityHandler(v3Pool) as UnbalancedAddLiquidityHandler

const humanAmountsIn: HumanTokenAmountWithAddress[] = [
{ humanAmount: '0.1', tokenAddress: balAddress },
]

it('calculates price impact', async () => {
const priceImpact = await handler.getPriceImpact(humanAmountsIn)
expect(priceImpact).toBeGreaterThan(0.002)
})

it('queries bptOut', async () => {
const result = await handler.simulate(humanAmountsIn)

expect(result.bptOut.amount).toBeGreaterThan(100000000000000n)
})

it('builds Tx Config', async () => {
// Store query response in handler instance
const queryOutput = await handler.simulate(humanAmountsIn)

const result = await handler.buildCallData({
humanAmountsIn,
account: defaultTestUserAccount,
slippagePercent: '0.2',
queryOutput,
})

const sepoliaRouter = '0xB12FcB422aAe6720f882E22C340964a7723f2387'
expect(result.to).toBe(sepoliaRouter)
expect(result.data).toBeDefined()
})
})
2 changes: 1 addition & 1 deletion lib/modules/pool/pool.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PoolIssue } from './alerts/pool-issues/PoolIssue.type'
import { getUserTotalBalanceInt } from './user-balance.helpers'
import { dateToUnixTimestamp } from '@/lib/shared/utils/time'
import { balancerV2VaultAbi } from '../web3/contracts/abi/generated'
import { balancerV3VaultAbi } from '../web3/contracts/abi/balancerV3Abi'
import { balancerV3VaultAbi } from '../web3/contracts/abi/balancerV3VaultAbi'

/**
* METHODS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function testPoolEnrichWithOnChainData(pool: Pool) {
return result
}

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

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

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

const pool = await getPoolMock(sepoliaPoolId, GqlChain.Sepolia)
const pool = await getPoolMock(cowPoolId, GqlChain.Mainnet)

// delete values to ensure that onchain data is used
pool.dynamicData.totalLiquidity = '0'
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/pool/queries/usePoolEnrichWithOnChainData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
import { Address, formatUnits } from 'viem'
import { useReadContracts } from 'wagmi'
import { useTokens } from '../../tokens/TokensProvider'
import { balancerV3VaultAbi } from '../../web3/contracts/abi/balancerV3Abi'
import { balancerV3ExtensionVaultAbi } from '../../web3/contracts/abi/balancerV3ExtensionVaultAbi'
import { weightedPoolV3Abi } from '../../web3/contracts/abi/weightedPoolV3Abi'
import { Pool } from '../PoolProvider'
import { BPT_DECIMALS } from '../pool.constants'
Expand Down Expand Up @@ -53,7 +53,7 @@ function useV3PoolOnchainData(pool: Pool) {
contracts: [
{
chainId,
abi: balancerV3VaultAbi,
abi: balancerV3ExtensionVaultAbi,
address: vaultAddress,
functionName: 'getPoolTokenInfo',
args: [pool.address as Address],
Expand Down
Loading

0 comments on commit 29de0fa

Please sign in to comment.