Skip to content

Commit

Permalink
fix: forwardTo extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Jan 2, 2025
1 parent 4236442 commit 9384789
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
15 changes: 4 additions & 11 deletions packages/sdk-router/src/rfq/engine/defaultEngine.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -116,10 +115,4 @@ export class DefaultEngine implements SwapEngine {
}

// TODO: getQuotes

private getForwardTo(recipient: Recipient): string {
return recipient.entity === RecipientEntity.Self
? AddressZero
: recipient.address
}
}
2 changes: 1 addition & 1 deletion packages/sdk-router/src/rfq/engine/odosEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
24 changes: 3 additions & 21 deletions packages/sdk-router/src/rfq/engine/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
8 changes: 7 additions & 1 deletion packages/sdk-router/src/rfq/engine/swapEngine.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -130,3 +130,9 @@ export const sanitizeMultiStepRoute = (
steps: [],
}
}

export const getForwardTo = (recipient: Recipient): string => {
return recipient.entity === RecipientEntity.Self
? AddressZero
: recipient.address
}

0 comments on commit 9384789

Please sign in to comment.