From c142e65941c3182b711eda49d8249bfaab3f83ec Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Thu, 21 Sep 2023 17:29:42 +1000 Subject: [PATCH 1/9] Add price rate providers to tokens --- modules/pool/lib/pool-creator.service.ts | 7 +++++++ modules/pool/lib/pool-gql-loader.service.ts | 17 +++++++++++++++++ modules/pool/pool.gql | 11 +++++++++++ .../balancer-subgraph-queries.graphql | 6 ++++++ .../migration.sql | 2 ++ prisma/schema.prisma | 2 ++ 6 files changed, 45 insertions(+) create mode 100644 prisma/migrations/20230921072643_add_price_rate_providers/migration.sql diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index e9f296e58..8dd1696c3 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -202,9 +202,16 @@ export class PoolCreatorService { return nestedPool.address === token.address; }); + let priceRateProvider; + if (pool.priceRateProviders) { + const data = pool.priceRateProviders.find((provider) => provider.token.address === token.address) + priceRateProvider = data?.address; + } + return { id: token.id, address: token.address, + priceRateProvider, nestedPoolId: nestedPool?.id, index: token.index || pool.tokensList.findIndex((address) => address === token.address), }; diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 9a888f599..1cb6f5fd1 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -28,6 +28,7 @@ import { GqlPoolUnion, GqlPoolWithdrawConfig, GqlPoolWithdrawOption, + GqlPoolPriceRateProvider, QueryPoolGetPoolsArgs, } from '../../../schema'; import { isSameAddress } from '@balancer-labs/sdk'; @@ -322,6 +323,7 @@ export class PoolGqlLoaderService { .map((token) => this.mapPoolTokenToGqlUnion(token)), allTokens: this.mapAllTokens(pool), displayTokens: this.mapDisplayTokens(pool), + priceRateProviders: this.mapPriceRateProviders(pool), }; //TODO: may need to build out the types here still @@ -770,6 +772,21 @@ export class PoolGqlLoaderService { }; } + private mapPriceRateProviders(pool: PrismaPoolWithExpandedNesting): GqlPoolPriceRateProvider[] { + const providers: GqlPoolPriceRateProvider[] = []; + pool.tokens.forEach((token) => { + if (token.priceRateProvider) { + providers.push({ + address: token.priceRateProvider, + token: { + address: token.address + } + }) + } + }) + return providers; + } + private getPoolInvestConfig(pool: PrismaPoolWithExpandedNesting): GqlPoolInvestConfig { const poolTokens = pool.tokens.filter((token) => token.address !== pool.address); const supportsNativeAssetDeposit = pool.type !== 'PHANTOM_STABLE'; diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 6f898b54f..46950cb17 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -111,6 +111,8 @@ interface GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider] + dynamicData: GqlPoolDynamicData! staking: GqlPoolStaking } @@ -541,6 +543,15 @@ type GqlPoolLinearPoolWrappedToken { decimals: Int! } +type GqlPoolPriceRateProvider { + address: String! + token: GqlPoolPriceRateProviderToken! +} + +type GqlPoolPriceRateProviderToken { + address: String! +} + type GqlPoolApr { apr: GqlPoolAprValue! swapApr: BigDecimal! # we make the assumption swap apr will never have a range diff --git a/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql b/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql index 8c37e682f..de9e2ddd2 100644 --- a/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql +++ b/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql @@ -182,6 +182,12 @@ fragment BalancerPool on Pool { amp alpha beta + priceRateProviders { + address + token { + address + } + } tokens { ...BalancerPoolToken diff --git a/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql b/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql new file mode 100644 index 000000000..53f998344 --- /dev/null +++ b/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "PrismaPoolToken" ADD COLUMN "priceRateProvider" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4ba50cda4..f1a99707c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -242,6 +242,8 @@ model PrismaPoolToken { nestedPoolId String? nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) + priceRateProvider String? + dynamicData PrismaPoolTokenDynamicData? } From a6d256207dbec16a2a113cfa1864eea330b1e236 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Thu, 21 Sep 2023 18:26:46 +1000 Subject: [PATCH 2/9] Make price rate providers required --- modules/pool/pool.gql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 46950cb17..4a4683339 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -111,7 +111,7 @@ interface GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider] + priceRateProviders: [GqlPoolPriceRateProvider!]! dynamicData: GqlPoolDynamicData! staking: GqlPoolStaking @@ -214,6 +214,7 @@ type GqlPoolWeighted implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolTokenUnion!]! nestingType: GqlPoolNestingType! @@ -236,6 +237,7 @@ type GqlPoolGyro implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! alpha: String! beta: String! @@ -260,6 +262,7 @@ type GqlPoolLiquidityBootstrapping implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolTokenUnion!]! nestingType: GqlPoolNestingType! @@ -281,6 +284,7 @@ type GqlPoolStable implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolToken!]! amp: BigInt! @@ -302,6 +306,7 @@ type GqlPoolMetaStable implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolToken!]! amp: BigInt! @@ -324,6 +329,7 @@ type GqlPoolPhantomStable implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolTokenUnion!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! nestingType: GqlPoolNestingType! amp: BigInt! staking: GqlPoolStaking @@ -346,6 +352,7 @@ type GqlPoolElement implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolToken!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! #element specific fields unitSeconds: BigInt! @@ -370,6 +377,7 @@ type GqlPoolLinear implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolToken!]! + priceRateProviders: [GqlPoolPriceRateProvider!]! #linear specific fields mainIndex: Int! From 1282b03b05abddf31cd5a2e1f34c33ee28ab2dcb Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 22 Sep 2023 16:09:47 +1000 Subject: [PATCH 3/9] Add mutation method to update token price rate providers --- modules/pool/pool.gql | 1 + modules/pool/pool.resolvers.ts | 7 +++++++ modules/pool/pool.service.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 4a4683339..b7ad21d39 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -57,6 +57,7 @@ extend type Mutation { poolBlackListRemovePool(poolId: String!): String! poolDeletePool(poolId: String!): String! poolSyncAllPoolVersions: String! + poolSyncPriceRateProviders: String! poolInitOnChainDataForAllPools: String! } diff --git a/modules/pool/pool.resolvers.ts b/modules/pool/pool.resolvers.ts index d958ca087..e8db56e01 100644 --- a/modules/pool/pool.resolvers.ts +++ b/modules/pool/pool.resolvers.ts @@ -281,6 +281,13 @@ const balancerResolvers: Resolvers = { await poolService.syncPoolVersionForAllPools(); + return 'success'; + }, + poolSyncPriceRateProviders: async (parent, {}, context) => { + isAdminRoute(context); + + await poolService.syncPriceRateProvidersForAllPools(); + return 'success'; }, }, diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index 852a03bc0..7b1053435 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -362,6 +362,38 @@ export class PoolService { } } + public async syncPriceRateProvidersForAllPools() { + const subgraphPools = await balancerSubgraphService.getAllPools({}, false); + for (const subgraphPool of subgraphPools) { + console.log("Pool ", subgraphPool.id, " price rate providers: ", subgraphPool.priceRateProviders); + if (!subgraphPool.priceRateProviders || !subgraphPool.priceRateProviders.length) continue; + console.log("Updating providers"); + + const poolTokens = subgraphPool.tokens || []; + for (let i = 0; i < poolTokens.length; i++) { + const token = poolTokens[i]; + + let priceRateProvider; + const data = subgraphPool.priceRateProviders.find((provider) => provider.token.address === token.address) + priceRateProvider = data?.address; + if (!priceRateProvider) continue; + + console.log("Updating token ", token.id, " to provider: ", priceRateProvider); + + try { + await prisma.prismaPoolToken.update({ + where: { id_chain: { id: token.id, chain: networkContext.chain } }, + data: { + priceRateProvider, + }, + }); + } catch (e) { + console.error('Failed to update token ', token.id, ' error is: ', e); + } + } + } + } + public async addToBlackList(poolId: string) { const category = await prisma.prismaPoolCategory.findFirst({ where: { poolId, chain: networkContext.chain, category: 'BLACK_LISTED' }, From cb8b3e154bc6b6713b3e73b79d054caa85cbb1c0 Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 1 Nov 2023 16:29:39 +0100 Subject: [PATCH 4/9] adding exempt flag --- modules/pool/lib/pool-creator.service.ts | 6 ++++-- modules/pool/pool.prisma | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index 8dd1696c3..8c82bcac6 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -204,7 +204,9 @@ export class PoolCreatorService { let priceRateProvider; if (pool.priceRateProviders) { - const data = pool.priceRateProviders.find((provider) => provider.token.address === token.address) + const data = pool.priceRateProviders.find( + (provider) => provider.token.address === token.address, + ); priceRateProvider = data?.address; } @@ -250,7 +252,7 @@ export class PoolCreatorService { }, } : undefined, - gyroData: ['GYRO', 'GYRO3', 'GYROE'].includes(poolType) + gyroData: ['GYRO2', 'GYRO3', 'GYROE'].includes(poolType) ? { create: { id: pool.id, diff --git a/modules/pool/pool.prisma b/modules/pool/pool.prisma index 16767b4df..14ea66456 100644 --- a/modules/pool/pool.prisma +++ b/modules/pool/pool.prisma @@ -196,6 +196,9 @@ model PrismaPoolToken { nestedPoolId String? nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) + priceRateProvider String? + exemptFromYield Boolean @default(false) + dynamicData PrismaPoolTokenDynamicData? } From c457e4fea34f99211fe40322b37e367bb3a7617e Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 20 Dec 2023 16:30:15 +0100 Subject: [PATCH 5/9] fix gyro type --- modules/pool/lib/pool-creator.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index 9ecf8dae0..391cec644 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -300,7 +300,7 @@ export class PoolCreatorService { }, } : undefined, - gyroData: ['GYRO2', 'GYRO3', 'GYROE'].includes(poolType) + gyroData: ['GYRO', 'GYRO3', 'GYROE'].includes(poolType) ? { create: { id: pool.id, From 5a434f1c864f2456e2ed24b07f9b3c59fa968e21 Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 20 Dec 2023 16:44:52 +0100 Subject: [PATCH 6/9] move rateprovider to token --- modules/pool/lib/pool-gql-loader.service.ts | 18 +--------- modules/pool/pool.gql | 38 +++------------------ 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 99b730f5a..2d5c1d2ce 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -30,7 +30,6 @@ import { GqlPoolUserBalance, GqlPoolWithdrawConfig, GqlPoolWithdrawOption, - GqlPoolPriceRateProvider, QueryPoolGetPoolsArgs, } from '../../../schema'; import { isSameAddress } from '@balancer-labs/sdk'; @@ -428,7 +427,6 @@ export class PoolGqlLoaderService { allTokens: this.mapAllTokens(pool), displayTokens: this.mapDisplayTokens(pool), userBalance: this.getUserBalance(pool, userWalletbalances, userStakedBalances), - priceRateProviders: this.mapPriceRateProviders(pool), }; //TODO: may need to build out the types here still @@ -941,21 +939,6 @@ export class PoolGqlLoaderService { }; } - private mapPriceRateProviders(pool: PrismaPoolWithExpandedNesting): GqlPoolPriceRateProvider[] { - const providers: GqlPoolPriceRateProvider[] = []; - pool.tokens.forEach((token) => { - if (token.priceRateProvider) { - providers.push({ - address: token.priceRateProvider, - token: { - address: token.address, - }, - }); - } - }); - return providers; - } - private getPoolInvestConfig(pool: PrismaPoolWithExpandedNesting): GqlPoolInvestConfig { const poolTokens = pool.tokens.filter((token) => token.address !== pool.address); const supportsNativeAssetDeposit = pool.type !== 'COMPOSABLE_STABLE'; @@ -1130,6 +1113,7 @@ export class PoolGqlLoaderService { ...poolToken.token, __typename: 'GqlPoolToken', priceRate: poolToken.dynamicData?.priceRate || '1.0', + priceRateProvider: poolToken.priceRateProvider, balance: poolToken.dynamicData?.balance || '0', index: poolToken.index, weight: poolToken.dynamicData?.weight, diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 21922c460..403e9734f 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -125,8 +125,6 @@ interface GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! - dynamicData: GqlPoolDynamicData! staking: GqlPoolStaking @@ -230,7 +228,6 @@ type GqlPoolWeighted implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolTokenUnion!]! nestingType: GqlPoolNestingType! @@ -257,7 +254,6 @@ type GqlPoolGyro implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! alpha: String! beta: String! @@ -300,7 +296,6 @@ type GqlPoolLiquidityBootstrapping implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolTokenUnion!]! nestingType: GqlPoolNestingType! @@ -326,7 +321,6 @@ type GqlPoolStable implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolToken!]! amp: BigInt! @@ -352,7 +346,6 @@ type GqlPoolMetaStable implements GqlPoolBase { dynamicData: GqlPoolDynamicData! displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! tokens: [GqlPoolToken!]! amp: BigInt! @@ -379,7 +372,6 @@ type GqlPoolComposableStable implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolTokenUnion!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! nestingType: GqlPoolNestingType! amp: BigInt! staking: GqlPoolStaking @@ -406,7 +398,6 @@ type GqlPoolElement implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolToken!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! #element specific fields unitSeconds: BigInt! @@ -435,7 +426,6 @@ type GqlPoolLinear implements GqlPoolBase { displayTokens: [GqlPoolTokenDisplay!]! allTokens: [GqlPoolTokenExpanded!]! tokens: [GqlPoolToken!]! - priceRateProviders: [GqlPoolPriceRateProvider!]! #linear specific fields mainIndex: Int! @@ -518,6 +508,7 @@ interface GqlPoolTokenBase { symbol: String! index: Int! priceRate: BigDecimal! + priceRateProvider: String weight: BigDecimal #the total balance in the pool, regardless of nesting totalBalance: BigDecimal! @@ -534,6 +525,7 @@ type GqlPoolToken implements GqlPoolTokenBase { #dynamic data balance: BigDecimal! priceRate: BigDecimal! + priceRateProvider: String weight: BigDecimal #the total balance in the pool, regardless of nesting totalBalance: BigDecimal! @@ -548,6 +540,7 @@ type GqlPoolTokenLinear implements GqlPoolTokenBase { symbol: String! index: Int! priceRate: BigDecimal! + priceRateProvider: String weight: BigDecimal pool: GqlPoolLinearNested! @@ -568,6 +561,7 @@ type GqlPoolTokenComposableStable implements GqlPoolTokenBase { symbol: String! index: Int! priceRate: BigDecimal! + priceRateProvider: String weight: BigDecimal #the total balance in the pool, regardless of nesting totalBalance: BigDecimal! @@ -619,15 +613,6 @@ type GqlPoolLinearPoolWrappedToken { decimals: Int! } -type GqlPoolPriceRateProvider { - address: String! - token: GqlPoolPriceRateProviderToken! -} - -type GqlPoolPriceRateProviderToken { - address: String! -} - type GqlPoolApr { apr: GqlPoolAprValue! swapApr: BigDecimal! # we make the assumption swap apr will never have a range @@ -689,21 +674,6 @@ enum GqlPoolFilterCategory { BLACK_LISTED } -# enum GqlPoolFilterType { -# WEIGHTED -# STABLE -# META_STABLE -# PHANTOM_STABLE -# ELEMENT -# LINEAR -# UNKNOWN -# LIQUIDITY_BOOTSTRAPPING -# INVESTMENT -# GYRO -# GYRO3 -# GYROE -# } - type GqlPoolTokenExpanded { id: ID! address: String! From 6d7b829be37c69f05a0f5daf9980215dcf88ee91 Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 20 Dec 2023 16:50:45 +0100 Subject: [PATCH 7/9] start yield fee exemption flag --- modules/pool/lib/pool-creator.service.ts | 3 +++ modules/pool/pool.service.ts | 12 ++++++----- .../balancer-subgraph-queries.graphql | 1 + prisma/schema.prisma | 21 ++++++++++--------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/modules/pool/lib/pool-creator.service.ts b/modules/pool/lib/pool-creator.service.ts index 391cec644..b138ea03b 100644 --- a/modules/pool/lib/pool-creator.service.ts +++ b/modules/pool/lib/pool-creator.service.ts @@ -262,6 +262,9 @@ export class PoolCreatorService { id: token.id, address: token.address, priceRateProvider, + exemptFromProtocolYieldFee: token.isExemptFromYieldProtocolFee + ? token.isExemptFromYieldProtocolFee + : false, nestedPoolId: nestedPool?.id, index: token.index || pool.tokensList.findIndex((address) => address === token.address), }; diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index 0ae65e996..ddb706c81 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -362,22 +362,24 @@ export class PoolService { } public async syncPriceRateProvidersForAllPools() { - const subgraphPools = await balancerSubgraphService.getAllPools({}, false); + const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false); for (const subgraphPool of subgraphPools) { - console.log("Pool ", subgraphPool.id, " price rate providers: ", subgraphPool.priceRateProviders); + console.log('Pool ', subgraphPool.id, ' price rate providers: ', subgraphPool.priceRateProviders); if (!subgraphPool.priceRateProviders || !subgraphPool.priceRateProviders.length) continue; - console.log("Updating providers"); + console.log('Updating providers'); const poolTokens = subgraphPool.tokens || []; for (let i = 0; i < poolTokens.length; i++) { const token = poolTokens[i]; let priceRateProvider; - const data = subgraphPool.priceRateProviders.find((provider) => provider.token.address === token.address) + const data = subgraphPool.priceRateProviders.find( + (provider) => provider.token.address === token.address, + ); priceRateProvider = data?.address; if (!priceRateProvider) continue; - console.log("Updating token ", token.id, " to provider: ", priceRateProvider); + console.log('Updating token ', token.id, ' to provider: ', priceRateProvider); try { await prisma.prismaPoolToken.update({ diff --git a/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql b/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql index 7eabc2900..5469dc094 100644 --- a/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql +++ b/modules/subgraphs/balancer-subgraph/balancer-subgraph-queries.graphql @@ -219,6 +219,7 @@ fragment BalancerPoolToken on PoolToken { balance weight priceRate + isExemptFromYieldProtocolFee index token { latestFXPrice diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 98ccb0e44..e3b5c5387 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -246,19 +246,20 @@ model PrismaPoolLinearDynamicData { model PrismaPoolToken { @@id([id, chain]) - id String - poolId String - pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain]) - chain Chain + id String + poolId String + pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain]) + chain Chain - address String - token PrismaToken @relation(fields:[address, chain], references: [address, chain]) - index Int + address String + token PrismaToken @relation(fields:[address, chain], references: [address, chain]) + index Int - nestedPoolId String? - nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) + nestedPoolId String? + nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) - priceRateProvider String? + priceRateProvider String? + exemptFromProtocolYieldFee Boolean @default(false) dynamicData PrismaPoolTokenDynamicData? } From 1c3a3a43743eb31d104fc54ac6dcd61838eee07f Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 20 Dec 2023 17:13:10 +0100 Subject: [PATCH 8/9] add sync for exemption --- modules/pool/pool.gql | 1 + modules/pool/pool.resolvers.ts | 7 +++++++ modules/pool/pool.service.ts | 26 ++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index 403e9734f..83fa0b919 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -57,6 +57,7 @@ extend type Mutation { poolDeletePool(poolId: String!): String! poolSyncAllPoolTypesVersions: String! poolSyncPriceRateProviders: String! + poolSyncProtocolYieldFeeExemptions: String! poolInitOnChainDataForAllPools: String! } diff --git a/modules/pool/pool.resolvers.ts b/modules/pool/pool.resolvers.ts index 5d4f7ea25..90fcebff2 100644 --- a/modules/pool/pool.resolvers.ts +++ b/modules/pool/pool.resolvers.ts @@ -328,6 +328,13 @@ const balancerResolvers: Resolvers = { await poolService.syncPriceRateProvidersForAllPools(); + return 'success'; + }, + poolSyncProtocolYieldFeeExemptions: async (parent, {}, context) => { + isAdminRoute(context); + + await poolService.syncProtocolYieldFeeExemptionsForAllPools(); + return 'success'; }, }, diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index ddb706c81..0dd490d9f 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -361,12 +361,32 @@ export class PoolService { await this.poolCreatorService.updatePoolTypesAndVersionForAllPools(); } + public async syncProtocolYieldFeeExemptionsForAllPools() { + const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false); + for (const subgraphPool of subgraphPools) { + const poolTokens = subgraphPool.tokens || []; + for (let i = 0; i < poolTokens.length; i++) { + const token = poolTokens[i]; + try { + await prisma.prismaPoolToken.update({ + where: { id_chain: { id: token.id, chain: networkContext.chain } }, + data: { + exemptFromYield: token.isExemptFromYieldProtocolFee + ? token.isExemptFromYieldProtocolFee + : false, + }, + }); + } catch (e) { + console.error('Failed to update token ', token.id, ' error is: ', e); + } + } + } + } + public async syncPriceRateProvidersForAllPools() { const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false); for (const subgraphPool of subgraphPools) { - console.log('Pool ', subgraphPool.id, ' price rate providers: ', subgraphPool.priceRateProviders); if (!subgraphPool.priceRateProviders || !subgraphPool.priceRateProviders.length) continue; - console.log('Updating providers'); const poolTokens = subgraphPool.tokens || []; for (let i = 0; i < poolTokens.length; i++) { @@ -379,8 +399,6 @@ export class PoolService { priceRateProvider = data?.address; if (!priceRateProvider) continue; - console.log('Updating token ', token.id, ' to provider: ', priceRateProvider); - try { await prisma.prismaPoolToken.update({ where: { id_chain: { id: token.id, chain: networkContext.chain } }, From a123edf6dac52a20d1d62809aad28aef84c8d741 Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 20 Dec 2023 17:29:06 +0100 Subject: [PATCH 9/9] fix prisma --- modules/pool/pool.prisma | 22 +++++++++---------- modules/pool/pool.service.ts | 2 +- .../migration.sql | 2 -- .../migration.sql | 3 +++ 4 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 prisma/migrations/20230921072643_add_price_rate_providers/migration.sql create mode 100644 prisma/migrations/20231220162356_add_price_rate_and_exempt/migration.sql diff --git a/modules/pool/pool.prisma b/modules/pool/pool.prisma index 97dcf78d2..9b16b15c2 100644 --- a/modules/pool/pool.prisma +++ b/modules/pool/pool.prisma @@ -200,20 +200,20 @@ model PrismaPoolLinearDynamicData { model PrismaPoolToken { @@id([id, chain]) - id String - poolId String - pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain]) - chain Chain + id String + poolId String + pool PrismaPool @relation(fields:[poolId, chain], references: [id, chain]) + chain Chain - address String - token PrismaToken @relation(fields:[address, chain], references: [address, chain]) - index Int + address String + token PrismaToken @relation(fields:[address, chain], references: [address, chain]) + index Int - nestedPoolId String? - nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) + nestedPoolId String? + nestedPool PrismaPool? @relation(name: "PoolNestedInToken", fields:[nestedPoolId, chain], references: [id, chain]) - priceRateProvider String? - exemptFromYield Boolean @default(false) + priceRateProvider String? + exemptFromProtocolYieldFee Boolean @default(false) dynamicData PrismaPoolTokenDynamicData? } diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index 0dd490d9f..a19068e6c 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -371,7 +371,7 @@ export class PoolService { await prisma.prismaPoolToken.update({ where: { id_chain: { id: token.id, chain: networkContext.chain } }, data: { - exemptFromYield: token.isExemptFromYieldProtocolFee + exemptFromProtocolYieldFee: token.isExemptFromYieldProtocolFee ? token.isExemptFromYieldProtocolFee : false, }, diff --git a/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql b/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql deleted file mode 100644 index 53f998344..000000000 --- a/prisma/migrations/20230921072643_add_price_rate_providers/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "PrismaPoolToken" ADD COLUMN "priceRateProvider" TEXT; diff --git a/prisma/migrations/20231220162356_add_price_rate_and_exempt/migration.sql b/prisma/migrations/20231220162356_add_price_rate_and_exempt/migration.sql new file mode 100644 index 000000000..aa4f9a5a5 --- /dev/null +++ b/prisma/migrations/20231220162356_add_price_rate_and_exempt/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "PrismaPoolToken" ADD COLUMN "exemptFromProtocolYieldFee" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "priceRateProvider" TEXT;