From 1757da088ef58a4fe1802569dbd91220e2ef7679 Mon Sep 17 00:00:00 2001 From: franz Date: Mon, 20 Nov 2023 18:31:47 +0100 Subject: [PATCH 1/9] add composable --- modules/pool/pool.gql | 1 + modules/pool/pool.prisma | 1 + .../20231120163312_add_composablestable_pooltype/migration.sql | 2 ++ prisma/schema.prisma | 1 + 4 files changed, 5 insertions(+) create mode 100644 prisma/migrations/20231120163312_add_composablestable_pooltype/migration.sql diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 219dea792..fc6aab4ca 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -82,6 +82,7 @@ enum GqlPoolMinimalType { STABLE META_STABLE PHANTOM_STABLE + COMPOSABLE_STABLE ELEMENT LINEAR UNKNOWN diff --git a/modules/pool/pool.prisma b/modules/pool/pool.prisma index 16767b4df..fa2c8bb8c 100644 --- a/modules/pool/pool.prisma +++ b/modules/pool/pool.prisma @@ -47,6 +47,7 @@ enum PrismaPoolType { STABLE META_STABLE PHANTOM_STABLE + COMPOSABLE_STABLE ELEMENT LINEAR UNKNOWN diff --git a/prisma/migrations/20231120163312_add_composablestable_pooltype/migration.sql b/prisma/migrations/20231120163312_add_composablestable_pooltype/migration.sql new file mode 100644 index 000000000..78f3ee0b4 --- /dev/null +++ b/prisma/migrations/20231120163312_add_composablestable_pooltype/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "PrismaPoolType" ADD VALUE 'COMPOSABLE_STABLE'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9ec3e38d1..2f56c2e23 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -93,6 +93,7 @@ enum PrismaPoolType { STABLE META_STABLE PHANTOM_STABLE + COMPOSABLE_STABLE ELEMENT LINEAR UNKNOWN From 4943f8736827a3147d7ab848d1cbbb49a748c52e Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 10:35:34 +0100 Subject: [PATCH 2/9] only exposing composable stable at query --- modules/pool/lib/pool-gql-loader.service.ts | 35 +++++++++++---------- modules/pool/pool.gql | 25 +++++++-------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 4d965269e..ec211a6d5 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -20,7 +20,7 @@ import { GqlPoolLinearNested, GqlPoolMinimal, GqlPoolNestingType, - GqlPoolPhantomStableNested, + GqlPoolComposableStableNested, GqlPoolStaking, GqlPoolToken, GqlPoolTokenDisplay, @@ -34,7 +34,7 @@ import { import { isSameAddress } from '@balancer-labs/sdk'; import _ from 'lodash'; import { prisma } from '../../../prisma/prisma-client'; -import { Chain, Prisma, PrismaPoolAprType } from '@prisma/client'; +import { Chain, Prisma, PrismaPoolAprType, PrismaPoolType } from '@prisma/client'; import { isWeightedPoolV2 } from './pool-utils'; import { oldBnum } from '../../big-number/old-big-number'; import { networkContext } from '../../network/network-context.service'; @@ -80,6 +80,7 @@ export class PoolGqlLoaderService { public mapToMinimalGqlPool(pool: PrismaPoolMinimal): GqlPoolMinimal { return { ...pool, + type: pool.type === 'PHANTOM_STABLE' ? PrismaPoolType.COMPOSABLE_STABLE : pool.type, decimals: 18, dynamicData: this.getPoolDynamicData(pool), allTokens: this.mapAllTokens(pool), @@ -380,9 +381,9 @@ export class PoolGqlLoaderService { amp: pool.stableDynamicData?.amp || '0', tokens: mappedData.tokens as GqlPoolToken[], }; - case 'PHANTOM_STABLE': + case 'COMPOSABLE_STABLE': return { - __typename: 'GqlPoolPhantomStable', + __typename: 'GqlPoolComposableStable', ...mappedData, amp: pool.stableDynamicData?.amp || '0', bptPriceRate: bpt?.dynamicData?.priceRate || '1.0', @@ -488,7 +489,7 @@ export class PoolGqlLoaderService { weight: poolToken?.dynamicData?.weight, }; } - } else if (allToken.nestedPool?.type === 'PHANTOM_STABLE') { + } else if (allToken.nestedPool?.type === 'COMPOSABLE_STABLE') { const mainTokens = allToken.nestedPool.allTokens.filter( (nestedToken) => @@ -806,7 +807,7 @@ export class PoolGqlLoaderService { private getPoolInvestConfig(pool: PrismaPoolWithExpandedNesting): GqlPoolInvestConfig { const poolTokens = pool.tokens.filter((token) => token.address !== pool.address); - const supportsNativeAssetDeposit = pool.type !== 'PHANTOM_STABLE'; + const supportsNativeAssetDeposit = pool.type !== 'COMPOSABLE_STABLE'; let options: GqlPoolInvestOption[] = []; for (const poolToken of poolTokens) { @@ -815,7 +816,7 @@ export class PoolGqlLoaderService { return { //TODO could flag these as disabled in sanity - proportionalEnabled: pool.type !== 'PHANTOM_STABLE' && pool.type !== 'META_STABLE', + proportionalEnabled: pool.type !== 'COMPOSABLE_STABLE' && pool.type !== 'META_STABLE', singleAssetEnabled: true, options, }; @@ -871,11 +872,11 @@ export class PoolGqlLoaderService { ] : [this.mapPoolTokenToGql(mainToken)], }); - } else if (nestedPool && nestedPool.type === 'PHANTOM_STABLE') { + } else if (nestedPool && nestedPool.type === 'COMPOSABLE_STABLE') { const nestedTokens = nestedPool.tokens.filter((token) => token.address !== nestedPool.address); - if (pool.type === 'PHANTOM_STABLE' || isWeightedPoolV2(pool)) { - //when nesting a phantom stable inside a phantom stable, all of the underlying tokens can be used when investing + if (pool.type === 'COMPOSABLE_STABLE' || isWeightedPoolV2(pool)) { + //when nesting a composable stable inside a composable stable, all of the underlying tokens can be used when investing //when withdrawing from a v2 weighted pool, we withdraw into all underlying assets. // ie: USDC/DAI/USDT for nested bbaUSD for (const nestedToken of nestedTokens) { @@ -895,7 +896,7 @@ export class PoolGqlLoaderService { }); } } else { - //if the parent pool does not have phantom bpt (ie: weighted), the user can only invest with 1 of the phantom stable tokens + //if the parent pool does not have phantom bpt (ie: weighted), the user can only invest with 1 of the composable stable tokens options.push({ poolTokenIndex: poolToken.index, poolTokenAddress: poolToken.address, @@ -956,7 +957,7 @@ export class PoolGqlLoaderService { ...this.getLinearPoolTokenData(token, nestedPool), pool: this.mapNestedPoolToGqlPoolLinearNested(nestedPool, percentOfSupplyNested), }; - } else if (nestedPool && nestedPool.type === 'PHANTOM_STABLE') { + } else if (nestedPool && nestedPool.type === 'COMPOSABLE_STABLE') { const totalShares = parseFloat(nestedPool.dynamicData?.totalShares || '0'); const percentOfSupplyNested = totalShares > 0 ? parseFloat(token.dynamicData?.balance || '0') / totalShares : 0; @@ -964,8 +965,8 @@ export class PoolGqlLoaderService { //50_000_000_000_000 return { ...this.mapPoolTokenToGql(token), - __typename: 'GqlPoolTokenPhantomStable', - pool: this.mapNestedPoolToGqlPoolPhantomStableNested(nestedPool, percentOfSupplyNested), + __typename: 'GqlPoolTokenComposableStable', + pool: this.mapNestedPoolToGqlPoolComposableStableNested(nestedPool, percentOfSupplyNested), }; } @@ -1019,14 +1020,14 @@ export class PoolGqlLoaderService { }; } - private mapNestedPoolToGqlPoolPhantomStableNested( + private mapNestedPoolToGqlPoolComposableStableNested( pool: PrismaNestedPoolWithSingleLayerNesting, percentOfSupplyNested: number, - ): GqlPoolPhantomStableNested { + ): GqlPoolComposableStableNested { const bpt = pool.tokens.find((token) => token.address === pool.address); return { - __typename: 'GqlPoolPhantomStableNested', + __typename: 'GqlPoolComposableStableNested', ...pool, nestingType: this.getPoolNestingType(pool), tokens: pool.tokens.map((token) => { diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index fc6aab4ca..87332397f 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -81,7 +81,6 @@ enum GqlPoolMinimalType { WEIGHTED STABLE META_STABLE - PHANTOM_STABLE COMPOSABLE_STABLE ELEMENT LINEAR @@ -177,7 +176,7 @@ type GqlPoolInvestOption { # we use an array here for invest options where there are more than one option, but only one can be selected # - FTM/wFTM or ETH/wETH - # - weighted boosted with nested phantom stable (bb-yv-USD) where you can only invest with DAI or USDC, not both at the same time + # - weighted boosted with nested composable stable (bb-yv-USD) where you can only invest with DAI or USDC, not both at the same time tokenOptions: [GqlPoolToken!]! } @@ -318,7 +317,7 @@ type GqlPoolMetaStable implements GqlPoolBase { version: Int! } -type GqlPoolPhantomStable implements GqlPoolBase { +type GqlPoolComposableStable implements GqlPoolBase { id: ID! chain: GqlChain! name: String! @@ -420,7 +419,7 @@ type GqlPoolLinearNested { version: Int! } -type GqlPoolPhantomStableNested { +type GqlPoolComposableStableNested { id: ID! name: String! symbol: String! @@ -428,7 +427,7 @@ type GqlPoolPhantomStableNested { owner: Bytes! factory: Bytes createTime: Int! - tokens: [GqlPoolTokenPhantomStableNestedUnion!]! + tokens: [GqlPoolTokenComposableStableNestedUnion!]! nestingType: GqlPoolNestingType! totalShares: BigDecimal! @@ -446,14 +445,14 @@ union GqlPoolUnion = | GqlPoolStable | GqlPoolMetaStable | GqlPoolLinear - | GqlPoolPhantomStable + | GqlPoolComposableStable | GqlPoolElement | GqlPoolLiquidityBootstrapping | GqlPoolGyro -union GqlPoolNestedUnion = GqlPoolLinearNested | GqlPoolPhantomStableNested +union GqlPoolNestedUnion = GqlPoolLinearNested | GqlPoolComposableStableNested -union GqlPoolTokenUnion = GqlPoolToken | GqlPoolTokenPhantomStable | GqlPoolTokenLinear -union GqlPoolTokenPhantomStableNestedUnion = GqlPoolToken | GqlPoolTokenLinear +union GqlPoolTokenUnion = GqlPoolToken | GqlPoolTokenComposableStable | GqlPoolTokenLinear +union GqlPoolTokenComposableStableNestedUnion = GqlPoolToken | GqlPoolTokenLinear interface GqlPoolTokenBase { id: ID! @@ -505,7 +504,7 @@ type GqlPoolTokenLinear implements GqlPoolTokenBase { totalBalance: BigDecimal! } -type GqlPoolTokenPhantomStable implements GqlPoolTokenBase { +type GqlPoolTokenComposableStable implements GqlPoolTokenBase { id: ID! address: String! balance: BigDecimal! @@ -518,7 +517,7 @@ type GqlPoolTokenPhantomStable implements GqlPoolTokenBase { #the total balance in the pool, regardless of nesting totalBalance: BigDecimal! - pool: GqlPoolPhantomStableNested! + pool: GqlPoolComposableStableNested! } type GqlPoolLinearPoolData { @@ -535,7 +534,7 @@ type GqlPoolLinearPoolData { mainTokenTotalBalance: String! } -type GqlPoolStablePhantomPoolData { +type GqlPoolStableComposablePoolData { id: ID! address: String! symbol: String! @@ -629,7 +628,7 @@ enum GqlPoolFilterType { WEIGHTED STABLE META_STABLE - PHANTOM_STABLE + COMPOSABLE_STABLE ELEMENT LINEAR UNKNOWN From 1b2d0e7db2a336d566bd18cd80467644e1e765e6 Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 10:50:24 +0100 Subject: [PATCH 3/9] pool creation phantom stable as composable stable v0 --- modules/pool/lib/pool-creator.service.ts | 31 +++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index fb22dc4fb..46c16d490 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -88,7 +88,9 @@ export class PoolCreatorService { const nestedPool = subgraphPools.find((nestedPool) => { const poolType = this.mapSubgraphPoolTypeToPoolType(nestedPool.poolType || ''); - return nestedPool.address === token.address && (poolType === 'LINEAR' || poolType === 'PHANTOM_STABLE'); + return ( + nestedPool.address === token.address && (poolType === 'LINEAR' || poolType === 'COMPOSABLE_STABLE') + ); }); if (nestedPool) { @@ -160,7 +162,7 @@ export class PoolCreatorService { const allNestedTypePools = await prisma.prismaPool.findMany({ where: { chain: networkContext.chain, - type: { in: [PrismaPoolType.LINEAR, PrismaPoolType.PHANTOM_STABLE] }, + type: { in: [PrismaPoolType.LINEAR, PrismaPoolType.COMPOSABLE_STABLE] }, }, select: { id: true, address: true }, }); @@ -185,6 +187,12 @@ export class PoolCreatorService { ], }); + // for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0 + let poolTypeVersion = pool.poolTypeVersion ? pool.poolTypeVersion : 1; + if (pool.poolType === 'PHANTOM_STABLE') { + poolTypeVersion = 0; + } + await prisma.prismaPool.create({ data: { id: pool.id, @@ -195,7 +203,7 @@ export class PoolCreatorService { name: pool.name || '', decimals: 18, type: poolType, - version: pool.poolTypeVersion ? pool.poolTypeVersion : 1, + version: poolTypeVersion, owner: pool.owner || ZERO_ADDRESS, factory: pool.factory, tokens: { @@ -256,7 +264,7 @@ export class PoolCreatorService { } : undefined, stableDynamicData: - poolType === 'STABLE' || poolType === 'PHANTOM_STABLE' || poolType === 'META_STABLE' + poolType === 'STABLE' || poolType === 'COMPOSABLE_STABLE' || poolType === 'META_STABLE' ? { create: { id: pool.id, @@ -364,9 +372,9 @@ export class PoolCreatorService { if (poolType === 'LINEAR') { return 0; - } else if (poolType === 'PHANTOM_STABLE') { - //if the phantom stable has a nested phantom stable, it needs to appear later in the list - const nestedPhantomStableToken = (pool.tokens || []).find((token) => { + } else if (poolType === 'COMPOSABLE_STABLE') { + //if the composable stable has a nested composable stable, it needs to appear later in the list + const nestedComposableStableToken = (pool.tokens || []).find((token) => { if (token.address === pool.address) { return false; } @@ -374,10 +382,10 @@ export class PoolCreatorService { const nestedPool = subgraphPools.find((nestedPool) => nestedPool.address === token.address); const nestedPoolType = this.mapSubgraphPoolTypeToPoolType(nestedPool?.poolType || ''); - return nestedPoolType === 'PHANTOM_STABLE'; + return nestedPoolType === 'COMPOSABLE_STABLE'; }); - return nestedPhantomStableToken ? 2 : 1; + return nestedComposableStableToken ? 2 : 1; } return 3; @@ -394,10 +402,11 @@ export class PoolCreatorService { return 'STABLE'; case 'MetaStable': return 'META_STABLE'; + // for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0 case 'StablePhantom': - return 'PHANTOM_STABLE'; + return 'COMPOSABLE_STABLE'; case 'ComposableStable': - return 'PHANTOM_STABLE'; + return 'COMPOSABLE_STABLE'; case 'Linear': return 'LINEAR'; case 'Element': From 991e36a2b9a5f5a17526bfb1b8df6e4f637c9e0f Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 10:51:50 +0100 Subject: [PATCH 4/9] add comment --- modules/pool/lib/pool-gql-loader.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index ec211a6d5..3440b4168 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -80,6 +80,7 @@ export class PoolGqlLoaderService { public mapToMinimalGqlPool(pool: PrismaPoolMinimal): GqlPoolMinimal { return { ...pool, + // we need this mapping because we migrated from PHANTOMSTABLE type to COMPOSABLESTABLE in the DB, but now only return COMPOSABLESTABLE type: pool.type === 'PHANTOM_STABLE' ? PrismaPoolType.COMPOSABLE_STABLE : pool.type, decimals: 18, dynamicData: this.getPoolDynamicData(pool), From 84c236e9dba81eb82eecb39dc4bf9c8159b7333b Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 11:03:12 +0100 Subject: [PATCH 5/9] add update mutation --- modules/pool/lib/pool-creator.service.ts | 36 ++++++++++++++++++++++++ modules/pool/pool.gql | 2 +- modules/pool/pool.resolvers.ts | 4 +-- modules/pool/pool.service.ts | 20 ++----------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index 46c16d490..e9c68111e 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -366,6 +366,42 @@ export class PoolCreatorService { } } + public async updatePoolTypesAndVersionForAllPools() { + const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false); + + for (const subgraphPool of subgraphPools) { + // for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0 + let poolTypeVersion = subgraphPool.poolTypeVersion ? subgraphPool.poolTypeVersion : 1; + if (subgraphPool.poolType === 'PHANTOM_STABLE') { + poolTypeVersion = 0; + } + + const poolType = this.mapSubgraphPoolTypeToPoolType(subgraphPool.poolType || ''); + + try { + await prisma.prismaPool.update({ + where: { id_chain: { chain: networkContext.chain, id: subgraphPool.id } }, + data: { + version: poolTypeVersion, + type: poolType, + }, + }); + } catch (e: any) { + // Some pools are filtered from the DB, like test pools, + // so we just ignore them without breaking the loop + const error = e.meta ? e.meta.cause : e; + console.error( + 'Error in updating pool versions: ', + error, + 'Network', + networkContext.chain, + 'Pool ID: ', + subgraphPool.id, + ); + } + } + } + private sortSubgraphPools(subgraphPools: BalancerPoolFragment[]) { return _.sortBy(subgraphPools, (pool) => { const poolType = this.mapSubgraphPoolTypeToPoolType(pool.poolType || ''); diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 87332397f..cc3ca9675 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -54,7 +54,7 @@ extend type Mutation { poolBlackListAddPool(poolId: String!): String! poolBlackListRemovePool(poolId: String!): String! poolDeletePool(poolId: String!): String! - poolSyncAllPoolVersions: String! + poolSyncAllPoolTypesVersions: String! poolInitOnChainDataForAllPools: String! } diff --git a/modules/pool/pool.resolvers.ts b/modules/pool/pool.resolvers.ts index e9fe7431b..9edbe1cfd 100644 --- a/modules/pool/pool.resolvers.ts +++ b/modules/pool/pool.resolvers.ts @@ -313,10 +313,10 @@ const balancerResolvers: Resolvers = { return 'success'; }, - poolSyncAllPoolVersions: async (parent, {}, context) => { + poolSyncAllPoolTypesVersions: async (parent, {}, context) => { isAdminRoute(context); - await poolService.syncPoolVersionForAllPools(); + await poolService.syncPoolTypeAndVersionForAllPools(); return 'success'; }, diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index ae54c3e2b..5555bdbc4 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -353,24 +353,8 @@ export class PoolService { await this.poolSyncService.setPoolsWithPreferredGaugesAsIncentivized(); } - public async syncPoolVersionForAllPools() { - const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false); - - for (const subgraphPool of subgraphPools) { - try { - await prisma.prismaPool.update({ - where: { id_chain: { chain: this.chain, id: subgraphPool.id } }, - data: { - version: subgraphPool.poolTypeVersion ? subgraphPool.poolTypeVersion : 1, - }, - }); - } catch (e: any) { - // Some pools are filtered from the DB, like test pools, - // so we just ignore them without breaking the loop - const error = e.meta ? e.meta.cause : e; - console.error(error, 'Network', networkContext.chain, 'Pool ID: ', subgraphPool.id); - } - } + public async syncPoolTypeAndVersionForAllPools() { + await this.poolCreatorService.updatePoolTypesAndVersionForAllPools(); } public async addToBlackList(poolId: string) { From 32f5898da7787a7d61125b6f32484b6d0879c82e Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 11:12:12 +0100 Subject: [PATCH 6/9] get rid of factory tracking --- modules/network/arbitrum.ts | 17 ++++--------- modules/network/avalanche.ts | 13 ++++------ modules/network/base.ts | 7 +++--- modules/network/fantom.ts | 24 ++++--------------- modules/network/gnosis.ts | 16 ++++--------- modules/network/mainnet.ts | 19 +-------------- modules/network/network-config-types.ts | 4 ---- modules/network/optimism.ts | 16 ++++--------- modules/network/polygon.ts | 17 ++++--------- modules/network/zkevm.ts | 11 ++++----- .../pool/lib/pool-on-chain-data.service.ts | 10 ++------ modules/pool/lib/pool-utils.ts | 17 ++----------- 12 files changed, 37 insertions(+), 134 deletions(-) diff --git a/modules/network/arbitrum.ts b/modules/network/arbitrum.ts index 20bb523f5..e4fedf51b 100644 --- a/modules/network/arbitrum.ts +++ b/modules/network/arbitrum.ts @@ -72,18 +72,6 @@ const arbitrumNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0xaeb406b0e430bf5ea2dc0b9fe62e4e53f74b3a33', - '0x85a80afee867adf27b50bdb7b76da70f1e853062', - '0x1c99324edc771c82a0dccb780cc7dda0045e50e7', - '0x2498a2b0d6462d2260eac50ae1c3e03f4829ba95', - '0xa8920455934da4d853faac1f94fe7bef72943ef1', - ], - weightedPoolV2Factories: [ - '0x8df6efec5547e31b0eb7d1291b511ff8a2bf987c', - '0xf1665e19bc105be4edd3739f88315cc699cc5b65', - '0xc7e5ed1054a24ef31d827e6f86caa58b3bc168d7', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -251,7 +239,10 @@ export const arbitrumNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(arbitrumNetworkData.subgraphs.balancer, arbitrumNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + arbitrumNetworkData.subgraphs.balancer, + arbitrumNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/avalanche.ts b/modules/network/avalanche.ts index f696e5005..b93ee348b 100644 --- a/modules/network/avalanche.ts +++ b/modules/network/avalanche.ts @@ -70,14 +70,6 @@ const avalancheNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0x3b1eb8eb7b43882b385ab30533d9a2bef9052a98', - '0xe42ffa682a26ef8f25891db4882932711d42e467', - ], - weightedPoolV2Factories: [ - '0x94f68b54191f62f781fe8298a8a5fa3ed772d227', - '0x230a59f4d9adc147480f03b0d3fffecd56c3289a', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -241,7 +233,10 @@ export const avalancheNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(avalancheNetworkData.subgraphs.balancer, avalancheNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + avalancheNetworkData.subgraphs.balancer, + avalancheNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/base.ts b/modules/network/base.ts index c25d9b91e..be69466e9 100644 --- a/modules/network/base.ts +++ b/modules/network/base.ts @@ -70,8 +70,6 @@ const baseNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: ['0x8df317a729fcaa260306d7de28888932cb579b88'], - weightedPoolV2Factories: ['0x4c32a8a8fda4e24139b51b456b42290f51d6a1c4'], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -139,7 +137,10 @@ export const baseNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(baseNetworkData.subgraphs.balancer, baseNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + baseNetworkData.subgraphs.balancer, + baseNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/fantom.ts b/modules/network/fantom.ts index a266d331c..0bd2f7bd5 100644 --- a/modules/network/fantom.ts +++ b/modules/network/fantom.ts @@ -116,27 +116,8 @@ const fantomNetworkData: NetworkData = { }, balancer: { vault: '0x20dd72ed959b6147912c2e529f0a0c651c33c9ce', - composableStablePoolFactories: [ - '0x5adaf6509bcec3219455348ac45d6d3261b1a990', - '0xb384a86f2fd7788720db42f9daa60fc07ecbea06', - '0x44814e3a603bb7f1198617995c5696c232f6e8ed', - '0x911566c808bf00acb200b418564440a2af177548', - '0x5c3094982cf3c97a06b7d62a6f7669f14a199b19', - '0x23f03a4fb344d8b98833d2ace093cc305e03474f', - ], - weightedPoolV2Factories: [ - '0xb2ed595afc445b47db7043bec25e772bf0fa1fbb', - '0x8ea1c497c16726e097f62c8c9fbd944143f27090', - '0xea87f3dffc679035653c0fba70e7bfe46e3fb733', - '0xd678b6acd834cc969bb19ce82727f2a541fb7941', - '0xb841df73861e65e6d61a80f503f095a91ce75e15', - ], swapProtocolFeePercentage: 0.25, yieldProtocolFeePercentage: 0.25, - factoriesWithpoolSpecificProtocolFeePercentagesProvider: [ - '0xb841df73861e65e6d61a80f503f095a91ce75e15', - '0x5c3094982cf3c97a06b7d62a6f7669f14a199b19', - ], }, multicall: '0x66335d7ad8011f6aa3f48aadcb523b62b38ed961', multicall3: '0xca11bde05977b3631167028862be2a173976ca11', @@ -347,7 +328,10 @@ export const fantomNetworkConfig: NetworkConfig = { new UserSyncReliquaryFarmBalanceService(fantomNetworkData.reliquary!.address), ], services: { - balancerSubgraphService: new BalancerSubgraphService(fantomNetworkData.subgraphs.balancer, fantomNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + fantomNetworkData.subgraphs.balancer, + fantomNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/gnosis.ts b/modules/network/gnosis.ts index d00aa09f0..57b91773d 100644 --- a/modules/network/gnosis.ts +++ b/modules/network/gnosis.ts @@ -68,17 +68,6 @@ const gnosisNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0x76578ecf9a141296ec657847fb45b0585bcda3a6', - '0xc128468b7ce63ea702c1f104d55a2566b13d3abd', - '0xd87f44df0159dc78029ab9ca7d7e57e7249f5acd', - '0x4bdcc2fb18aeb9e2d281b0278d946445070eada7', - ], - weightedPoolV2Factories: [ - '0x6cad2ea22bfa7f4c14aae92e47f510cd5c509bc7', - '0xf302f9f50958c5593770fdf4d4812309ff77414f', - '0xc128a9954e6c874ea3d62ce62b468ba073093f25', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -168,7 +157,10 @@ export const gnosisNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(gnosisNetworkData.subgraphs.balancer, gnosisNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + gnosisNetworkData.subgraphs.balancer, + gnosisNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/mainnet.ts b/modules/network/mainnet.ts index 8e77f13ff..2b1bbdfa7 100644 --- a/modules/network/mainnet.ts +++ b/modules/network/mainnet.ts @@ -83,22 +83,8 @@ const data: NetworkData = { balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', tokenAdmin: '0xf302f9f50958c5593770fdf4d4812309ff77414f', - composableStablePoolFactories: [ - '0xf9ac7b9df2b3454e841110cce5550bd5ac6f875f', - '0x85a80afee867adf27b50bdb7b76da70f1e853062', - '0xdba127fbc23fb20f5929c546af220a991b5c6e01', - '0xfada0f4547ab2de89d1304a668c39b3e09aa7c76', - '0xdb8d758bcb971e482b2c45f7f8a7740283a1bd3a', - '0xba1b4a90bad57470a2cba762a32955dc491f76e0', - ], - weightedPoolV2Factories: [ - '0xcc508a455f5b0073973107db6a878ddbdab957bc', - '0x5dd94da3644ddd055fcf6b3e1aa310bb7801eb8b', - '0x897888115ada5773e02aa29f775430bfb5f34c51', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, - excludedPoolDataQueryPoolIds: ['0xf71d0774b214c4cf51e33eb3d30ef98132e4dbaa00000000000000000000046e'], }, multicall: '0x5ba1e12693dc8f9c48aad8770482f4739beed696', multicall3: '0xca11bde05977b3631167028862be2a173976ca11', @@ -378,10 +364,7 @@ export const mainnetNetworkConfig: NetworkConfig = { data.balancer.yieldProtocolFeePercentage, data.balancer.swapProtocolFeePercentage, ), - new PhantomStableAprService( - data.chain.prismaId, - data.balancer.yieldProtocolFeePercentage, - ), + new PhantomStableAprService(data.chain.prismaId, data.balancer.yieldProtocolFeePercentage), new BoostedPoolAprService(), new SwapFeeAprService(data.balancer.swapProtocolFeePercentage), new GaugeAprService(tokenService, [data.bal!.address]), diff --git a/modules/network/network-config-types.ts b/modules/network/network-config-types.ts index 10c8e33dd..e921c65b3 100644 --- a/modules/network/network-config-types.ts +++ b/modules/network/network-config-types.ts @@ -104,12 +104,8 @@ export interface NetworkData { balancer: { vault: string; tokenAdmin?: string; - weightedPoolV2Factories: string[]; - composableStablePoolFactories: string[]; yieldProtocolFeePercentage: number; swapProtocolFeePercentage: number; - excludedPoolDataQueryPoolIds?: string[]; - factoriesWithpoolSpecificProtocolFeePercentagesProvider?: string[]; }; multicall: string; multicall3: string; diff --git a/modules/network/optimism.ts b/modules/network/optimism.ts index af9a1a00d..c16361a65 100644 --- a/modules/network/optimism.ts +++ b/modules/network/optimism.ts @@ -81,17 +81,6 @@ const optimismNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0xf145cafb67081895ee80eb7c04a30cf87f07b745', - '0xe2e901ab09f37884ba31622df3ca7fc19aa443be', - '0x1802953277fd955f9a254b80aa0582f193cf1d77', - '0x043a2dad730d585c44fb79d2614f295d2d625412', - ], - weightedPoolV2Factories: [ - '0xad901309d9e9dbc5df19c84f729f429f0189a633', - '0xa0dabebaad1b243bbb243f933013d560819eb66f', - '0x230a59f4d9adc147480f03b0d3fffecd56c3289a', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -296,7 +285,10 @@ export const optimismNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(optimismNetworkData.subgraphs.balancer, optimismNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + optimismNetworkData.subgraphs.balancer, + optimismNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/polygon.ts b/modules/network/polygon.ts index 8fd44b1fd..9407a51fa 100644 --- a/modules/network/polygon.ts +++ b/modules/network/polygon.ts @@ -72,18 +72,6 @@ const polygonNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0x136fd06fa01ecf624c7f2b3cb15742c1339dc2c4', - '0x85a80afee867adf27b50bdb7b76da70f1e853062', - '0x7bc6c0e73edaa66ef3f6e2f27b0ee8661834c6c9', - '0x6ab5549bbd766a43afb687776ad8466f8b42f777', - '0xe2fa4e1d17725e72dcdafe943ecf45df4b9e285b', - ], - weightedPoolV2Factories: [ - '0x0e39c3d9b2ec765efd9c5c70bb290b1fcd8536e3', - '0x82e4cfaef85b1b6299935340c964c942280327f4', - '0xfc8a407bba312ac761d8bfe04ce1201904842b76', - ], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -286,7 +274,10 @@ export const polygonNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(polygonNetworkData.subgraphs.balancer, polygonNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + polygonNetworkData.subgraphs.balancer, + polygonNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/network/zkevm.ts b/modules/network/zkevm.ts index 77ed05875..0a2f93c23 100644 --- a/modules/network/zkevm.ts +++ b/modules/network/zkevm.ts @@ -70,12 +70,6 @@ const zkevmNetworkData: NetworkData = { }, balancer: { vault: '0xba12222222228d8ba445958a75a0704d566bf2c8', - composableStablePoolFactories: [ - '0x8ea89804145c007e7d226001a96955ad53836087', - '0x956ccab09898c0af2aca5e6c229c3ad4e93d9288', - '0x577e5993b9cc480f07f98b5ebd055604bd9071c4' - ], - weightedPoolV2Factories: ['0x03f3fb107e74f2eac9358862e91ad3c692712054'], swapProtocolFeePercentage: 0.5, yieldProtocolFeePercentage: 0.5, }, @@ -187,7 +181,10 @@ export const zkevmNetworkConfig: NetworkConfig = { ], userStakedBalanceServices: [new UserSyncGaugeBalanceService()], services: { - balancerSubgraphService: new BalancerSubgraphService(zkevmNetworkData.subgraphs.balancer, zkevmNetworkData.chain.id), + balancerSubgraphService: new BalancerSubgraphService( + zkevmNetworkData.subgraphs.balancer, + zkevmNetworkData.chain.id, + ), }, /* For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3. diff --git a/modules/pool/lib/pool-on-chain-data.service.ts b/modules/pool/lib/pool-on-chain-data.service.ts index 72bef5972..c60c15d85 100644 --- a/modules/pool/lib/pool-on-chain-data.service.ts +++ b/modules/pool/lib/pool-on-chain-data.service.ts @@ -1,5 +1,5 @@ import { formatFixed } from '@ethersproject/bignumber'; -import { Chain, PrismaPoolType } from '@prisma/client'; +import { PrismaPoolType } from '@prisma/client'; import { isSameAddress } from '@balancer-labs/sdk'; import { prisma } from '../../../prisma/prisma-client'; import { isComposableStablePool, isStablePool } from './pool-utils'; @@ -33,7 +33,6 @@ export class PoolOnChainDataService { vaultAddress: networkContext.data.balancer.vault, yieldProtocolFeePercentage: networkContext.data.balancer.yieldProtocolFeePercentage, gyroConfig: networkContext.data.gyro?.config, - composableStableFactories: networkContext.data.balancer.composableStablePoolFactories, }; } @@ -95,12 +94,7 @@ export class PoolOnChainDataService { }); const gyroPools = filteredPools.filter((pool) => pool.type.includes('GYRO')); - const poolsWithComposableStableType = filteredPools.map((pool) => ({ - ...pool, - type: (isComposableStablePool(pool) ? 'COMPOSABLE_STABLE' : pool.type) as - | PrismaPoolType - | 'COMPOSABLE_STABLE', - })); + const poolsWithComposableStableType = filteredPools.filter((pool) => isComposableStablePool(pool)); const tokenPrices = await this.tokenService.getTokenPrices(); const onchainResults = await fetchOnChainPoolData( diff --git a/modules/pool/lib/pool-utils.ts b/modules/pool/lib/pool-utils.ts index d1cc25d06..321575fd9 100644 --- a/modules/pool/lib/pool-utils.ts +++ b/modules/pool/lib/pool-utils.ts @@ -1,7 +1,4 @@ import { PrismaPoolDynamicData, PrismaPoolType } from '@prisma/client'; -import { isSameAddress } from '@balancer-labs/sdk'; -import { networkContext } from '../../network/network-context.service'; -import { prisma } from '../../../prisma/prisma-client'; type PoolWithTypeAndFactory = { address: string; @@ -16,21 +13,11 @@ export function isStablePool(poolType: PrismaPoolType) { } export function isWeightedPoolV2(pool: PoolWithTypeAndFactory) { - return ( - pool.type === 'WEIGHTED' && - networkContext.data.balancer.weightedPoolV2Factories.find((factory) => - isSameAddress(pool.factory || '', factory), - ) !== undefined - ); + return pool.type === 'WEIGHTED' && pool.version >= 2; } export function isComposableStablePool(pool: PoolWithTypeAndFactory) { - return ( - pool.type === 'PHANTOM_STABLE' && - networkContext.data.balancer.composableStablePoolFactories.find((factory) => - isSameAddress(pool.factory || '', factory), - ) !== undefined - ); + return pool.type === 'COMPOSABLE_STABLE' && pool.version > 0; } export function collectsYieldFee(pool: PoolWithTypeAndFactory) { From c7e05bbbd25d2db28d29d316b47105e8acfc37a6 Mon Sep 17 00:00:00 2001 From: franz Date: Tue, 21 Nov 2023 11:24:31 +0100 Subject: [PATCH 7/9] add phantomstable to gql schema again --- modules/pool/lib/pool-creator.service.ts | 4 ++-- modules/pool/lib/pool-gql-loader.service.ts | 2 -- modules/pool/pool.gql | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index e9c68111e..0108cba5a 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -189,7 +189,7 @@ export class PoolCreatorService { // for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0 let poolTypeVersion = pool.poolTypeVersion ? pool.poolTypeVersion : 1; - if (pool.poolType === 'PHANTOM_STABLE') { + if (pool.poolType === 'StablePhantom') { poolTypeVersion = 0; } @@ -372,7 +372,7 @@ export class PoolCreatorService { for (const subgraphPool of subgraphPools) { // for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0 let poolTypeVersion = subgraphPool.poolTypeVersion ? subgraphPool.poolTypeVersion : 1; - if (subgraphPool.poolType === 'PHANTOM_STABLE') { + if (subgraphPool.poolType === 'StablePhantom') { poolTypeVersion = 0; } diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 3440b4168..0e5686456 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -80,8 +80,6 @@ export class PoolGqlLoaderService { public mapToMinimalGqlPool(pool: PrismaPoolMinimal): GqlPoolMinimal { return { ...pool, - // we need this mapping because we migrated from PHANTOMSTABLE type to COMPOSABLESTABLE in the DB, but now only return COMPOSABLESTABLE - type: pool.type === 'PHANTOM_STABLE' ? PrismaPoolType.COMPOSABLE_STABLE : pool.type, decimals: 18, dynamicData: this.getPoolDynamicData(pool), allTokens: this.mapAllTokens(pool), diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index cc3ca9675..17599275c 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -81,6 +81,7 @@ enum GqlPoolMinimalType { WEIGHTED STABLE META_STABLE + PHANTOM_STABLE COMPOSABLE_STABLE ELEMENT LINEAR From 0717c07bd75652d9913c578d66aa299d767ad271 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:36:53 +0100 Subject: [PATCH 8/9] Update pool-onchain-data.ts --- modules/pool/lib/pool-onchain-data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pool/lib/pool-onchain-data.ts b/modules/pool/lib/pool-onchain-data.ts index 189c5f62e..eee9af4ed 100644 --- a/modules/pool/lib/pool-onchain-data.ts +++ b/modules/pool/lib/pool-onchain-data.ts @@ -76,7 +76,7 @@ const getSwapFeeFn = (type: string) => { }; const getTotalSupplyFn = (type: PoolInput['type'], version: number) => { - if (['LINEAR', 'PHANTOM_STABLE'].includes(type)) { + if (['LINEAR'].includes(type) || (type === 'COMPOSABLE_STABLE' && version === 0)) { return 'getVirtualSupply'; } else if ( type === 'COMPOSABLE_STABLE' || From 034549f3c03c460be333e3ecdb500edb94b04c48 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:37:51 +0100 Subject: [PATCH 9/9] Update pool-on-chain-data.service.ts --- modules/pool/lib/pool-on-chain-data.service.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/pool/lib/pool-on-chain-data.service.ts b/modules/pool/lib/pool-on-chain-data.service.ts index c60c15d85..2a0e70d9d 100644 --- a/modules/pool/lib/pool-on-chain-data.service.ts +++ b/modules/pool/lib/pool-on-chain-data.service.ts @@ -94,14 +94,9 @@ export class PoolOnChainDataService { }); const gyroPools = filteredPools.filter((pool) => pool.type.includes('GYRO')); - const poolsWithComposableStableType = filteredPools.filter((pool) => isComposableStablePool(pool)); const tokenPrices = await this.tokenService.getTokenPrices(); - const onchainResults = await fetchOnChainPoolData( - poolsWithComposableStableType, - this.options.vaultAddress, - 1024, - ); + const onchainResults = await fetchOnChainPoolData(filteredPools, this.options.vaultAddress, 1024); const gyroFees = await (this.options.gyroConfig ? fetchOnChainGyroFees(gyroPools, this.options.gyroConfig, 1024) : Promise.resolve({} as { [address: string]: string }));