Skip to content

Commit

Permalink
actually retry with one more depth
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Feb 8, 2024
1 parent 3ff07c1 commit 084507f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modules/sor/sorV2/sorV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GqlSorGetSwapPaths, GqlSorSwap, GqlSorSwapType } from '../../../schema'
import { Chain } from '@prisma/client';
import { PrismaPoolWithDynamic, prismaPoolWithDynamic } from '../../../prisma/prisma-types';
import { prisma } from '../../../prisma/prisma-client';
import { GetSwapsInput, GetSwapsV2Input, SwapResult, SwapService } from '../types';
import { GetSwapsInput, GetSwapsV2Input as GetSwapPathsInput, SwapResult, SwapService } from '../types';
import { env } from '../../../app/env';
import { DeploymentEnv } from '../../network/network-config-types';
import { poolsToIgnore } from '../constants';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class SorV2Service implements SwapService {
}
}

public async getSorSwapPaths(input: GetSwapsV2Input, maxNonBoostedPathDepth = 4): Promise<GqlSorGetSwapPaths> {
public async getSorSwapPaths(input: GetSwapPathsInput, maxNonBoostedPathDepth = 4): Promise<GqlSorGetSwapPaths> {
const swap = await this.getSwap(input, maxNonBoostedPathDepth);
const emptyResponse = swapPathsZeroResponse(input.tokenIn, input.tokenOut);

Expand All @@ -75,7 +75,7 @@ export class SorV2Service implements SwapService {
}

try {
return this.mapToSorSwapPaths(swap!, input.chain, input.queryBatchSwap ? input.queryBatchSwap : true);
return this.mapToSorSwapPaths(swap!, input.chain, input.queryBatchSwap);
} catch (err: any) {
console.log(`Error Retrieving QuerySwap`, err);
Sentry.captureException(err.message, {
Expand All @@ -92,8 +92,8 @@ export class SorV2Service implements SwapService {
}
}

public async getSwap(
{ chain, tokenIn, tokenOut, swapType, swapAmount, graphTraversalConfig }: GetSwapsV2Input,
private async getSwap(
{ chain, tokenIn, tokenOut, swapType, swapAmount, graphTraversalConfig }: GetSwapPathsInput,
maxNonBoostedPathDepth = 4,
): Promise<Swap | null> {
try {
Expand All @@ -114,8 +114,9 @@ export class SorV2Service implements SwapService {
},
};
const swap = await sorGetSwapsWithPools(tIn, tOut, swapKind, swapAmount.amount, poolsFromDb, config);
// if we dont find a path with depth 4, we try one more level.
if (!swap && maxNonBoostedPathDepth < 5) {
return swap;
return this.getSwap(arguments[0], maxNonBoostedPathDepth + 1);
}
return swap;
} catch (err: any) {
Expand Down

0 comments on commit 084507f

Please sign in to comment.