diff --git a/packages/lib/modules/pool/actions/LiquidityActionHelpers.integration.spec.ts b/packages/lib/modules/pool/actions/LiquidityActionHelpers.integration.spec.ts index 7637a7804..d73e6928c 100644 --- a/packages/lib/modules/pool/actions/LiquidityActionHelpers.integration.spec.ts +++ b/packages/lib/modules/pool/actions/LiquidityActionHelpers.integration.spec.ts @@ -99,7 +99,7 @@ describe('Calculates toInputAmounts from allPoolTokens', () => { // Unskip when sepolia V3 pools are available in production api describe.skip('Liquidity helpers for V3 Boosted pools', async () => { - const poolId = '0x6dbdd7a36d900083a5b86a55583d90021e9f33e8' // Sepolia stataEthUSDC stataEthUSDT + // const poolId = '0x6dbdd7a36d900083a5b86a55583d90021e9f33e8' // Sepolia stataEthUSDC stataEthUSDT const usdcSepoliaAddress = '0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8' const usdtSepoliaAddress = '0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0' @@ -210,6 +210,31 @@ describe.skip('Liquidity helpers for V3 Boosted pools', async () => { type: 'Stable', }) }) + + it('poolStateWithBalances (that calls boostedPoolStateWithBalances underneath)', async () => { + const helpers = new LiquidityActionHelpers(v3Pool) + expect(helpers.poolStateWithBalances).toEqual({ + address: '0x6dbdd7a36d900083a5b86a55583d90021e9f33e8', + id: '0x6dbdd7a36d900083a5b86a55583d90021e9f33e8', + protocolVersion: 3, + tokens: [ + { + address: '0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8', + balance: expect.any(String), + decimals: 6, + index: 0, + }, + { + address: '0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0', + balance: expect.any(String), + decimals: 6, + index: 1, + }, + ], + totalShares: expect.any(String), + type: 'Stable', + }) + }) }) // Unskip when sepolia V3 pools are available in production api diff --git a/packages/lib/modules/pool/actions/LiquidityActionHelpers.ts b/packages/lib/modules/pool/actions/LiquidityActionHelpers.ts index 23f6ea395..fd9298d48 100644 --- a/packages/lib/modules/pool/actions/LiquidityActionHelpers.ts +++ b/packages/lib/modules/pool/actions/LiquidityActionHelpers.ts @@ -15,6 +15,7 @@ import { PoolState, PoolStateWithBalances, PoolStateWithUnderlyings, + PoolTokenWithBalance, PoolTokenWithUnderlying, Token, TokenAmount, @@ -35,6 +36,7 @@ import { Pool } from '../PoolProvider' import { allPoolTokens, isAffectedByCspIssue, + isBoosted, isComposableStableV1, isCowAmmPool, isGyro, @@ -83,6 +85,7 @@ export class LiquidityActionHelpers { (token, index) => ({ ...token, address: token.address as Address, + balance: token.balance as HumanAmount, underlyingToken: { ...token.underlyingToken, address: token.underlyingToken?.address as Address, @@ -103,7 +106,39 @@ export class LiquidityActionHelpers { } public get poolStateWithBalances(): PoolStateWithBalances { - return toPoolStateWithBalances(this.pool) + return isBoosted(this.pool) + ? this.boostedPoolStateWithBalances + : toPoolStateWithBalances(this.pool) + } + + /* Used by calculateProportionalAmounts for V3 boosted proportional adds */ + public get boostedPoolStateWithBalances(): PoolStateWithBalances { + const underlyingTokensWithBalance: PoolTokenWithBalance[] = this.pool.poolTokens.map( + (token, index) => + token.underlyingToken + ? { + address: token.underlyingToken?.address as Address, + decimals: token.underlyingToken?.decimals as number, + index, + // TODO: balance: token.underlyingToken?.balance * rate as HumanAmount, + balance: token.balance as HumanAmount, + } + : { + address: token.address as Address, + decimals: token.decimals as number, + balance: token.balance as HumanAmount, + index, + } + ) + const state: PoolStateWithBalances = { + id: this.pool.id as Hex, + address: this.pool.address as Address, + protocolVersion: 3, + type: mapPoolType(this.pool.type), + tokens: underlyingTokensWithBalance, + totalShares: this.pool.dynamicData.totalShares as HumanAmount, + } + return state } public get networkConfig() { diff --git a/packages/lib/modules/pool/actions/add-liquidity/form/AddLiquidityForm.tsx b/packages/lib/modules/pool/actions/add-liquidity/form/AddLiquidityForm.tsx index 75b5746ce..ef2b6ba5e 100644 --- a/packages/lib/modules/pool/actions/add-liquidity/form/AddLiquidityForm.tsx +++ b/packages/lib/modules/pool/actions/add-liquidity/form/AddLiquidityForm.tsx @@ -55,7 +55,6 @@ import { ConnectWallet } from '@repo/lib/modules/web3/ConnectWallet' import { BalAlert } from '@repo/lib/shared/components/alerts/BalAlert' import { SafeAppAlert } from '@repo/lib/shared/components/alerts/SafeAppAlert' import { useTokens } from '@repo/lib/modules/tokens/TokensProvider' -import { isBoosted } from '../../../pool.helpers' // small wrapper to prevent out of context error export function AddLiquidityForm() { @@ -189,11 +188,7 @@ function AddLiquidityMainForm() { )} - {/* //TODO: - Avoid proportional inputs to avoid error above until SDK calculateProportionalAmounts for boosted is implemented - https://github.com/balancer/b-sdk/issues/468 - */} - {!nestedAddLiquidityEnabled && !isBoosted(pool) ? ( + {!nestedAddLiquidityEnabled ? ( tokenSelectDisclosure.onOpen()}