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 +} diff --git a/packages/sdk-router/src/rfq/sir.ts b/packages/sdk-router/src/rfq/sir.ts index af48fb0ccd..1ac6852621 100644 --- a/packages/sdk-router/src/rfq/sir.ts +++ b/packages/sdk-router/src/rfq/sir.ts @@ -24,6 +24,7 @@ import { decodeSavedBridgeParams } from './paramsV2' import { StepParams, decodeStepParams } from './steps' import { decodeZapData, encodeZapData } from './zapData' import { isSameAddress } from '../utils/addressUtils' +import { logger } from '../utils/logger' export class SynapseIntentRouter implements SynapseModule { static fastBridgeV2Interface = new Interface(fastBridgeV2Abi) @@ -163,7 +164,7 @@ export class SynapseIntentRouter implements SynapseModule { !decodedLastStep.minFinalAmount || !decodedLastStep.minFinalAmount.eq(originQuery.minAmountOut) ) { - console.error( + logger.error( { decodedLastStep, originQuery, diff --git a/packages/sdk-router/src/rfq/sirSet.ts b/packages/sdk-router/src/rfq/sirSet.ts index 3c09775932..581a0d2ea3 100644 --- a/packages/sdk-router/src/rfq/sirSet.ts +++ b/packages/sdk-router/src/rfq/sirSet.ts @@ -330,7 +330,7 @@ export class SynapseIntentRouterSet extends SynapseModuleSet { // Adjust the slippage in the last origin step. const originSteps = decodeStepParams(originQueryPrecise.rawParams) if (originSteps.length === 0) { - console.error({ originQueryPrecise }, 'No steps in originQueryPrecise') + logger.error({ originQueryPrecise }, 'No steps in originQueryPrecise') return originQuery } originSteps[originSteps.length - 1].zapData = modifyMinFinalAmount(