Skip to content

Commit

Permalink
refactor: from allowNestedActions to disallowNestedActions (#346)
Browse files Browse the repository at this point in the history
* chore: add disallowNestedActions

* chore: clean disallowNestedActions setup

* chore: remove old phantom pool from disallowedNested
  • Loading branch information
agualis authored Jan 7, 2025
1 parent 3cde3a8 commit d1337ed
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packages/lib/config/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ContractsConfig {
}
export interface PoolsConfig {
issues: Partial<Record<PoolIssue, string[]>>
allowNestedActions?: string[] // pool ids
disallowNestedActions?: string[] // pool ids
}

export interface BlockExplorerConfig {
Expand Down
1 change: 0 additions & 1 deletion packages/lib/config/networks/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const networkConfig: NetworkConfig = {
},
pools: convertHexToLowerCase({
issues: { [PoolIssue.CspPoolVulnWarning]: CSP_ISSUE_POOL_IDS[GqlChain.Gnosis] },
allowNestedActions: ['0x66888e4f35063ad8bb11506a6fde5024fb4f1db0000100000000000000000053'],
}),
layerZeroChainId: 145,
supportsVeBalSync: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/config/networks/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ const networkConfig: NetworkConfig = {
'0xad0e5e0778cac28f1ff459602b31351871b5754a0002000000000000000003cD',
],
},
allowNestedActions: [
'0x08775ccb6674d6bdceb0797c364c2653ed84f3840002000000000000000004f0', // B-80BAL-20WETH
],
disallowNestedActions: ['0x3dd0843a028c86e0b760b1a76929d1c5ef93a2dd000200000000000000000249'],
}),
} as const satisfies NetworkConfig

Expand Down
6 changes: 1 addition & 5 deletions packages/lib/config/networks/sepolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ const networkConfig: NetworkConfig = {
},
pools: convertHexToLowerCase({
issues: {},
allowNestedActions: [
'0xc832a37c8252117604f1329b4a7fed7076880b27',
'0x693cc6a39bbf35464f53d6a5dbf7d6c2fa93741c',
'0xbfdbdb4d5b8e00bade87cf12ed58e6152f25ac3e',
],
disallowNestedActions: [],
}),
layerZeroChainId: 10161,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { HumanTokenAmountWithAddress } from '@repo/lib/modules/tokens/token.types'
import { GqlChain, GqlPoolElement } from '@repo/lib/shared/services/api/generated/graphql'
import { getPoolMock } from '../__mocks__/getPoolMock'
import { allPoolTokens } from '../pool.helpers'
import { allPoolTokens, getPoolActionableTokens } from '../pool.helpers'
import { LiquidityActionHelpers } from './LiquidityActionHelpers'
import { Pool } from '../PoolProvider'

Expand Down Expand Up @@ -678,3 +678,96 @@ describe('Liquidity helpers for GNOSIS V2 pool with isErc4626 tokens (v2 pools a
})
})
})

describe('Liquidity helpers for V2 B-auraBAL-STABLE pool with BPT token in the actionable tokens', async () => {
const poolId = '0x3dd0843a028c86e0b760b1a76929d1c5ef93a2dd000200000000000000000249' // Balancer 80 BAL 20 WETH auraBAL

const auraBalAddress = '0x616e8bfa43f920657b3497dbf40d6b1a02d4608d'
const balWeth8020BptAddress = '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56' // 80BAL-20WETH nested BPT that should be used for adds

const v2Pool = await getPoolMock(poolId, GqlChain.Mainnet)
const helpers = new LiquidityActionHelpers(v2Pool)

const humanAmountsIn: HumanTokenAmountWithAddress[] = [
{ humanAmount: '0.1', tokenAddress: balWeth8020BptAddress, symbol: '80BAL-20WETH' },
]

it('allPoolTokens includes 4 tokens: auraBAL, 80BAL-20WETH BTP and its nested tokens (BAL and WETH)', async () => {
// TODO: should nested tokens return all fields or just token core (I don't want balance balance USD)
expect(allPoolTokens(v2Pool)).toMatchObject([
{
address: '0x5c6ee304399dbdb9c8ef030ab642b10820db8f56',
decimals: 18,
index: 0,
name: 'Balancer 80 BAL 20 WETH',
symbol: 'B-80BAL-20WETH',
},
{
address: '0xba100000625a3754423978a60c9317c58a424e3d',
decimals: 18,
index: 0,
symbol: 'BAL',
weight: '0.8',
},
{
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
decimals: 18,
index: 1,
symbol: 'WETH',
weight: '0.2',
},
{
address: '0x616e8bfa43f920657b3497dbf40d6b1a02d4608d',
decimals: 18,
index: 1,
name: 'Aura BAL',
symbol: 'auraBAL',
},
])
})

it('toInputAmounts', async () => {
expect(helpers.toInputAmounts(humanAmountsIn)).toEqual([
{
address: bal80Weth20Address,
decimals: 18,
rawAmount: 100000000000000000n,
symbol: 'B-80BAL-20WETH',
},
])
})

it('poolActionable tokens are auraBal and nested BPT', async () => {
// TODO: merge pool helpers and LiquidityActionHelpers or split tests
const tokens = getPoolActionableTokens(v2Pool)
.map(t => t.address)
.sort()

expect(tokens).toEqual([bal80Weth20Address, auraBalAddress])
})

it('poolStateWithBalances', async () => {
const helpers = new LiquidityActionHelpers(v2Pool)
expect(helpers.poolStateWithBalances).toEqual({
id: poolId,
address: '0x3dd0843a028c86e0b760b1a76929d1c5ef93a2dd',
protocolVersion: 2,
tokens: [
{
address: bal80Weth20Address,
balance: expect.any(String),
decimals: 18,
index: 0,
},
{
address: auraBalAddress,
balance: expect.any(String),
decimals: 18,
index: 1,
},
],
totalShares: expect.any(String),
type: 'Stable',
})
})
})
8 changes: 5 additions & 3 deletions packages/lib/modules/pool/actions/LiquidityActionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
isV3Pool,
isV3NotSupportingWethIsEth,
getActionableTokenSymbol,
hasNestedPools,
} from '../pool.helpers'
import { TokenAmountIn } from '../../tokens/approvals/permit2/useSignPermit2'
import { ApiToken } from '../pool.types'
Expand Down Expand Up @@ -269,9 +270,10 @@ It looks that you tried to call useBuildCallData before the last query finished
}

export function supportsNestedActions(pool: Pool): boolean {
const allowNestedActions = getNetworkConfig(pool.chain).pools?.allowNestedActions ?? []
if (allowNestedActions.includes(pool.id)) return true
return false
if (!hasNestedPools(pool)) return false
const disallowNestedActions = getNetworkConfig(pool.chain).pools?.disallowNestedActions ?? []
if (disallowNestedActions.includes(pool.id)) return false
return true
}

export function shouldUseRecoveryRemoveLiquidity(pool: Pool): boolean {
Expand Down
82 changes: 34 additions & 48 deletions packages/lib/modules/pool/pool.helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable max-len */
import { Pool } from './PoolProvider'
import { supportsNestedActions } from './actions/LiquidityActionHelpers'
import { getPoolActionableTokens } from './pool.helpers'

describe('getPoolTokens', () => {
it('when pool supports nested actions', () => {
describe('getPoolActionableTokens', () => {
it('when nested pool supports nested actions (default behavior)', () => {
const pool = {
id: '0x66888e4f35063ad8bb11506a6fde5024fb4f1db0000100000000000000000053',
address: '0x2086f52651837600180de173b09470f54ef74910',
Expand Down Expand Up @@ -54,52 +55,37 @@ describe('getPoolTokens', () => {
const result = getPoolActionableTokens(pool)
expect(result.map(t => t.symbol)).toEqual(['USDT', 'USDC', 'WXDAI', 'WETH', 'WBTC']) // contains 'staBAL3' nested tokens (USDT, USDC, WXDAI)
})
})

it('when pool does not support nested actions', () => {
const pool = {
id: '0xdacf5fa19b1f720111609043ac67a9818262850c000000000000000000000635',
address: '0xdacf5fa19b1f720111609043ac67a9818262850c',
chain: 'MAINNET',
poolTokens: [
{
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
symbol: 'WETH',
hasNestedPool: false,
nestedPool: null,
},
{
address: '0xdacf5fa19b1f720111609043ac67a9818262850c',
symbol: 'osETH/wETH-BPT',
hasNestedPool: true,
nestedPool: {
address: '0xdacf5fa19b1f720111609043ac67a9818262850c',
symbol: 'osETH/wETH-BPT',
tokens: [
{
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
symbol: 'WETH',
},
{
address: '0xdacf5fa19b1f720111609043ac67a9818262850c',
symbol: 'osETH/wETH-BPT',
},
{
address: '0xf1c9acdc66974dfb6decb12aa385b9cd01190e38',
symbol: 'osETH',
},
],
},
},
{
address: '0xf1c9acdc66974dfb6decb12aa385b9cd01190e38',
symbol: 'osETH',
hasNestedPool: false,
nestedPool: null,
},
],
} as unknown as Pool
it('supportsNestedActions', () => {
const pool = {
id: '0x12345',
} as unknown as Pool

const result = getPoolActionableTokens(pool)
expect(result.map(t => t.symbol)).toEqual(['WETH', 'osETH']) // excludes 'osETH/wETH-BPT' bpt token
})
expect(supportsNestedActions(pool)).toBeFalsy()

expect(
supportsNestedActions(
// WETH / osETH Phantom composable stable
fakeNestedPool('0xdacf5fa19b1f720111609043ac67a9818262850c000000000000000000000635')
)
).toBeTruthy()

expect(
supportsNestedActions(
// Balancer 80 BAL 20 WETH auraBAL',
fakeNestedPool('0x3dd0843a028c86e0b760b1a76929d1c5ef93a2dd000200000000000000000249')
)
).toBeFalsy()
})

function fakeNestedPool(poolId: string): Pool {
return {
id: poolId, // Balancer 80 BAL 20 WETH auraBAL',
poolTokens: [
{
hasNestedPool: true,
},
],
} as unknown as Pool
}
1 change: 1 addition & 0 deletions packages/lib/modules/pool/pool.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export function getPoolHelpers(pool: Pool, chain: GqlChain) {
}

export function hasNestedPools(pool: Pool) {
if (!pool.poolTokens) return false
// The following discriminator is needed because not all pools in GqlPoolQuery do have nestingType property
// and the real TS discriminator is __typename which we don't want to use
return (
Expand Down

0 comments on commit d1337ed

Please sign in to comment.