diff --git a/modules/beethoven/balancer-sdk.gql b/modules/beethoven/balancer-sdk.gql index 161c685a..6c90201e 100644 --- a/modules/beethoven/balancer-sdk.gql +++ b/modules/beethoven/balancer-sdk.gql @@ -26,10 +26,33 @@ input GqlSorSwapOptionsInput { forceRefresh: Boolean #don't use any cached responses } +""" +Configuration options for SOR V2 +""" input GqlGraphTraversalConfigInput { - maxDepth: Int # default 6 - maxNonBoostedPathDepth: Int # default 3 - maxNonBoostedHopTokensInBoostedPath: Int # default 2 + """ + The max hops in a path. + + Default: 6 + """ + maxDepth: Int + """ + Limit of "non-boosted" pools for efficiency. + + Default: 6 + """ + maxNonBoostedPathDepth: Int + """ + Limit non boosted hop tokens in a boosted path. + + Default: 2 + """ + maxNonBoostedHopTokensInBoostedPath: Int + """ + Max number of paths to return (can be less) + + Default: 5 + """ approxPathsToReturn: Int # default 5 poolIdsToInclude: [String] } diff --git a/modules/beethoven/balancer-sdk.resolvers.ts b/modules/beethoven/balancer-sdk.resolvers.ts index cab3456c..792d06e2 100644 --- a/modules/beethoven/balancer-sdk.resolvers.ts +++ b/modules/beethoven/balancer-sdk.resolvers.ts @@ -13,7 +13,7 @@ const balancerSdkResolvers: Resolvers = { if (!args.chain && currentChain) { args.chain = currentChain; } else if (!args.chain) { - throw new Error('poolGetPool error: Provide "chain" param'); + throw new Error('sorGetSwaps error: Provide "chain" param'); } const chain = args.chain; const tokenIn = args.tokenIn.toLowerCase(); @@ -22,7 +22,13 @@ const balancerSdkResolvers: Resolvers = { // Use TokenAmount to help follow scaling requirements in later logic // args.swapAmount is HumanScale const amount = await getTokenAmountHuman(amountToken, args.swapAmount, args.chain); - const graphTraversalConfig = args.graphTraversalConfig as GraphTraversalConfig; + const graphTraversalConfig = ( + args.graphTraversalConfig + ? args.graphTraversalConfig + : { + maxNonBoostedPathDepth: 6, + } + ) as GraphTraversalConfig; const swaps = await sorService.getBeetsSwaps({ ...args, diff --git a/modules/metrics/sor.metric.ts b/modules/metrics/sor.metric.ts index bac38295..fb4b6f42 100644 --- a/modules/metrics/sor.metric.ts +++ b/modules/metrics/sor.metric.ts @@ -3,7 +3,13 @@ import { CloudwatchMetricsPublisher } from './metrics.client'; const publishers: Record = {}; -export function getSorMetricsPublisher(chain: Chain): CloudwatchMetricsPublisher { +export const publishMetric = (chain: Chain, metricName: string, value: number) => { + if (process.env.NODE_ENV !== 'production') return Promise.resolve(); + + return getSorMetricsPublisher(chain).publish(metricName, value); +}; + +function getSorMetricsPublisher(chain: Chain): CloudwatchMetricsPublisher { if (!publishers[chain]) { console.log(`Creating new SOR publisher for ${chain}`); publishers[chain] = new CloudwatchMetricsPublisher(`Backend-${chain}/Sor`); diff --git a/modules/sor/sor.service.ts b/modules/sor/sor.service.ts index 1602e1d3..98e93fea 100644 --- a/modules/sor/sor.service.ts +++ b/modules/sor/sor.service.ts @@ -4,7 +4,7 @@ import { sorV1BeetsService } from './sorV1Beets/sorV1Beets.service'; import { sorV2Service } from './sorV2/sorV2.service'; import { GetSwapsInput, SwapResult, SwapService } from './types'; import { EMPTY_COWSWAP_RESPONSE } from './constants'; -import { getSorMetricsPublisher } from '../metrics/sor.metric'; +import { publishMetric } from '../metrics/sor.metric'; import { Chain } from '@prisma/client'; import { parseUnits, formatUnits } from '@ethersproject/units'; import { tokenService } from '../token/token.service'; @@ -121,9 +121,8 @@ export class SorService { v1Time: number, v2Time: number, ) { - const sorMetricsPublisher = getSorMetricsPublisher(chain); - await sorMetricsPublisher.publish(`SOR_VALID_V1`, v1.isValid ? 1 : 0); - await sorMetricsPublisher.publish(`SOR_VALID_V2`, v2.isValid ? 1 : 0); + await publishMetric(chain, `SOR_VALID_V1`, v1.isValid ? 1 : 0); + await publishMetric(chain, `SOR_VALID_V2`, v2.isValid ? 1 : 0); if (!version) return; @@ -154,9 +153,9 @@ export class SorService { let diff = bn(diffN.toFixed(decimals), decimals); let bestResultAmount = version === 'V1' ? v1ResultAmount : v2ResultAmount; - await sorMetricsPublisher.publish(`SOR_TIME_V1`, v1Time); - await sorMetricsPublisher.publish(`SOR_TIME_V2`, v2Time); - await sorMetricsPublisher.publish(`SOR_V2_PERFORMACE`, v2Perf); + await publishMetric(chain, `SOR_TIME_V1`, v1Time); + await publishMetric(chain, `SOR_TIME_V2`, v2Time); + await publishMetric(chain, `SOR_V2_PERFORMACE`, v2Perf); console.log( [