From 93847899128b6b9f7f39e1e6b7ff4b2961d3d780 Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Thu, 2 Jan 2025 18:47:16 +0000 Subject: [PATCH] fix: forwardTo extraction --- .../src/rfq/engine/defaultEngine.ts | 15 ++++-------- .../sdk-router/src/rfq/engine/odosEngine.ts | 2 +- .../sdk-router/src/rfq/engine/response.ts | 24 +++---------------- .../sdk-router/src/rfq/engine/swapEngine.ts | 8 ++++++- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/packages/sdk-router/src/rfq/engine/defaultEngine.ts b/packages/sdk-router/src/rfq/engine/defaultEngine.ts index afc67a2efa..9043197824 100644 --- a/packages/sdk-router/src/rfq/engine/defaultEngine.ts +++ b/packages/sdk-router/src/rfq/engine/defaultEngine.ts @@ -1,5 +1,5 @@ import { Interface } from '@ethersproject/abi' -import { AddressZero, Zero } from '@ethersproject/constants' +import { Zero } from '@ethersproject/constants' import { BigNumber, Contract } from 'ethers' import invariant from 'tiny-invariant' @@ -17,13 +17,12 @@ import { logger } from '../../utils/logger' import { SwapEngine, SwapEngineRoute, - Recipient, - RecipientEntity, EngineID, toWei, RouteInput, SlippageMax, getEmptyRoute, + getForwardTo, } from './swapEngine' export class DefaultEngine implements SwapEngine { @@ -81,11 +80,11 @@ export class DefaultEngine implements SwapEngine { return getEmptyRoute(this.id) } // Get the quote - const forwardTo = this.getForwardTo(finalRecipient) + const forwardTo = getForwardTo(finalRecipient) const { amountOut, steps: stepsOutput } = await previewer.previewIntent( swapQuoter, forwardTo, - // slippage settings are applied when generating the zap data as minFwdAmount + // slippage settings are applied when generating the zap data as minFinalAmount toWei(SlippageMax), tokenIn, tokenOut, @@ -116,10 +115,4 @@ export class DefaultEngine implements SwapEngine { } // TODO: getQuotes - - private getForwardTo(recipient: Recipient): string { - return recipient.entity === RecipientEntity.Self - ? AddressZero - : recipient.address - } } diff --git a/packages/sdk-router/src/rfq/engine/odosEngine.ts b/packages/sdk-router/src/rfq/engine/odosEngine.ts index 274cde4624..954941f670 100644 --- a/packages/sdk-router/src/rfq/engine/odosEngine.ts +++ b/packages/sdk-router/src/rfq/engine/odosEngine.ts @@ -109,7 +109,7 @@ export class OdosEngine implements SwapEngine { }, ], userAddr: tokenZap, - // slippage settings are applied when generating the zap data as minFwdAmount + // slippage settings are applied when generating the zap data as minFinalAmount slippageLimitPercent: toPercentFloat(SlippageMax), simple: true, } diff --git a/packages/sdk-router/src/rfq/engine/response.ts b/packages/sdk-router/src/rfq/engine/response.ts index b4d6a93439..3efbe68324 100644 --- a/packages/sdk-router/src/rfq/engine/response.ts +++ b/packages/sdk-router/src/rfq/engine/response.ts @@ -6,8 +6,7 @@ import { EngineID, RouteInput, SwapEngineRoute, - Recipient, - RecipientEntity, + getForwardTo, } from './swapEngine' import { isSameAddress } from '../../utils/addressUtils' import { AMOUNT_NOT_PRESENT, encodeZapData } from '../zapData' @@ -50,7 +49,8 @@ export const generateAPIRoute = ( payload: response.transaction.data, amountPosition: AMOUNT_NOT_PRESENT, finalToken: input.tokenOut, - ...getForwardParams(input.finalRecipient, response.amountOut), + forwardTo: getForwardTo(input.finalRecipient), + minFinalAmount: response.amountOut, }) return { @@ -66,21 +66,3 @@ export const generateAPIRoute = ( ], } } - -const getForwardParams = ( - finalRecipient: Recipient, - amountOut: BigNumber -): { - forwardTo: string - minFwdAmount: BigNumber -} => { - return finalRecipient.entity === RecipientEntity.Self - ? { - forwardTo: AddressZero, - minFwdAmount: Zero, - } - : { - forwardTo: finalRecipient.address, - minFwdAmount: amountOut, - } -} diff --git a/packages/sdk-router/src/rfq/engine/swapEngine.ts b/packages/sdk-router/src/rfq/engine/swapEngine.ts index f394fd717e..081fb5e212 100644 --- a/packages/sdk-router/src/rfq/engine/swapEngine.ts +++ b/packages/sdk-router/src/rfq/engine/swapEngine.ts @@ -1,5 +1,5 @@ import { BigNumber } from 'ethers' -import { Zero, WeiPerEther } from '@ethersproject/constants' +import { Zero, WeiPerEther, AddressZero } from '@ethersproject/constants' import { StepParams } from '../steps' import { BigintIsh } from '../../constants' @@ -130,3 +130,9 @@ export const sanitizeMultiStepRoute = ( steps: [], } } + +export const getForwardTo = (recipient: Recipient): string => { + return recipient.entity === RecipientEntity.Self + ? AddressZero + : recipient.address +}