From abbc61ee355c411ee9406c3356b04803d678e7e7 Mon Sep 17 00:00:00 2001 From: johngrantuk Date: Thu, 7 Sep 2023 15:27:14 +0100 Subject: [PATCH] feat: Add Gyro pools for sorV2 service. --- modules/pool/pool.service.ts | 8 +++-- modules/sor/sorV2/sorV2.service.ts | 54 ++++++++++++++++++++++++++++-- prisma/prisma-types.ts | 1 + 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index eb1766bd0..05308a2e8 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -444,6 +444,10 @@ export class PoolService { where: { chain: networkContext.chain, poolId: poolId }, }); + await prisma.prismaPoolGyroData.deleteMany({ + where: { chain: networkContext.chain, poolId: poolId }, + }); + await prisma.prismaPoolExpandedTokens.deleteMany({ where: { chain: networkContext.chain, poolId: poolId }, }); @@ -482,9 +486,9 @@ export class PoolService { }, }); - if(gauge && gauge.votingGauge) + if (gauge && gauge.votingGauge) await prisma.prismaVotingGauge.deleteMany({ - where: { chain: networkContext.chain, id: gauge.votingGauge.id } + where: { chain: networkContext.chain, id: gauge.votingGauge.id }, }); await prisma.prismaPoolStakingGauge.deleteMany({ diff --git a/modules/sor/sorV2/sorV2.service.ts b/modules/sor/sorV2/sorV2.service.ts index 52ed8baaa..8e1463fb1 100644 --- a/modules/sor/sorV2/sorV2.service.ts +++ b/modules/sor/sorV2/sorV2.service.ts @@ -12,6 +12,9 @@ import { Swap as SwapSdk, RawPool, TokenAmount, + RawGyro2Pool, + RawGyro3Pool, + RawGyroEPool, } from '@balancer/sdk'; import cloneDeep from 'lodash/cloneDeep'; import { GqlSorSwapType, GqlSwap, GqlSorGetSwapsResponse, GqlPoolMinimal, GqlSorSwapRoute } from '../../../schema'; @@ -340,9 +343,12 @@ export class SorV2Service implements SwapService { }, NOT: { id: { - in: [...networkContext.data.sor[env.DEPLOYMENT_ENV as DeploymentEnv].poolIdsToExclude, ...poolsToIgnore], + in: [ + ...networkContext.data.sor[env.DEPLOYMENT_ENV as DeploymentEnv].poolIdsToExclude, + ...poolsToIgnore, + ], }, - type: 'LINEAR' // Linear pools are sunset so ignore to avoid issues related to lack of support + type: 'LINEAR', // Linear pools are sunset so ignore to avoid issues related to lack of support }, }, include: prismaPoolWithDynamic.include, @@ -381,7 +387,7 @@ export class SorV2Service implements SwapService { }), isPaused: !!prismaPool.dynamicData?.isPaused, inRecoveryMode: !!prismaPool.dynamicData?.isInRecoveryMode, - name: 'n/a' + name: 'n/a', }; if (['Weighted', 'Investment', 'LiquidityBootstrapping'].includes(rawPool.poolType)) { rawPool = { @@ -406,6 +412,41 @@ export class SorV2Service implements SwapService { }), } as RawMetaStablePool; } + if (rawPool.poolType === 'Gyro2') { + rawPool = { + ...rawPool, + alpha: prismaPool.gyroData?.alpha, + beta: prismaPool.gyroData?.beta, + sqrtAlpha: prismaPool.gyroData?.sqrtAlpha, + sqrtBeta: prismaPool.gyroData?.sqrtBeta, + } as RawGyro2Pool; + } + if (rawPool.poolType === 'Gyro3') { + rawPool = { + ...rawPool, + root3Alpha: prismaPool.gyroData?.root3Alpha, + } as RawGyro3Pool; + } + if (rawPool.poolType === 'GyroE') { + rawPool = { + ...rawPool, + alpha: prismaPool.gyroData?.alpha, + beta: prismaPool.gyroData?.beta, + c: prismaPool.gyroData?.c, + s: prismaPool.gyroData?.s, + lambda: prismaPool.gyroData?.lambda, + tauAlphaX: prismaPool.gyroData?.tauAlphaX, + tauAlphaY: prismaPool.gyroData?.tauAlphaY, + tauBetaX: prismaPool.gyroData?.tauBetaX, + tauBetaY: prismaPool.gyroData?.tauBetaY, + u: prismaPool.gyroData?.u, + v: prismaPool.gyroData?.v, + w: prismaPool.gyroData?.w, + z: prismaPool.gyroData?.z, + dSq: prismaPool.gyroData?.dSq, + tokenRates: prismaPool.tokens.map((t) => t.dynamicData?.priceRate), + } as RawGyroEPool; + } return rawPool; }); } @@ -443,6 +484,13 @@ export class SorV2Service implements SwapService { case PrismaPoolType.PHANTOM_STABLE: // Composablestables are PHANTOM_STABLE in Prisma. b-sdk treats Phantoms as ComposableStable. return 'ComposableStable'; + case PrismaPoolType.GYRO: + return 'Gyro2'; + // TODO - Needs a package update, see: https://github.com/balancer/b-sdk/pull/92 + // case PrismaPoolType.GYRO3: + // return 'Gyro3'; + case PrismaPoolType.GYROE: + return 'GyroE'; default: return type; } diff --git a/prisma/prisma-types.ts b/prisma/prisma-types.ts index a48347d04..7d70788b5 100644 --- a/prisma/prisma-types.ts +++ b/prisma/prisma-types.ts @@ -288,6 +288,7 @@ export const prismaPoolWithDynamic = Prisma.validator()({ dynamicData: true, linearDynamicData: true, linearData: true, + gyroData: true, tokens: { orderBy: { index: 'asc' }, include: {