Skip to content

Commit

Permalink
Merge branch 'feat/sdk-syn-intents' into staging/syn-intents
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Jan 2, 2025
2 parents bc852b0 + 9384789 commit c66e5b4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 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
}
3 changes: 2 additions & 1 deletion packages/sdk-router/src/rfq/sir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -163,7 +164,7 @@ export class SynapseIntentRouter implements SynapseModule {
!decodedLastStep.minFinalAmount ||
!decodedLastStep.minFinalAmount.eq(originQuery.minAmountOut)
) {
console.error(
logger.error(
{
decodedLastStep,
originQuery,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-router/src/rfq/sirSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c66e5b4

Please sign in to comment.