Skip to content

Commit

Permalink
feat: Add Gyro pools for sorV2 service.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Sep 7, 2023
1 parent 6390fe4 commit abbc61e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
8 changes: 6 additions & 2 deletions modules/pool/pool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
Expand Down Expand Up @@ -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({
Expand Down
54 changes: 51 additions & 3 deletions modules/sor/sorV2/sorV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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;
});
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions prisma/prisma-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const prismaPoolWithDynamic = Prisma.validator<Prisma.PrismaPoolArgs>()({
dynamicData: true,
linearDynamicData: true,
linearData: true,
gyroData: true,
tokens: {
orderBy: { index: 'asc' },
include: {
Expand Down

0 comments on commit abbc61e

Please sign in to comment.