Skip to content

Commit

Permalink
chore: bump sor to 4.17.17 - fix: add base mixed quoter v2 (#1002) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 authored Feb 12, 2025
1 parent d82e8c5 commit 8ad01f5
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
ChainId.MAINNET,
]

const mixedSupported = [ChainId.MAINNET, ChainId.SEPOLIA, ChainId.GOERLI, ChainId.UNICHAIN]
const mixedSupported = [ChainId.MAINNET, ChainId.SEPOLIA, ChainId.GOERLI, ChainId.UNICHAIN, ChainId.BASE]

const cachedRoutesCacheInvalidationFixRolloutPercentage = NEW_CACHED_ROUTES_ROLLOUT_PERCENT[chainId]

Expand Down
3 changes: 3 additions & 0 deletions lib/handlers/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
protocolVersionsToBeExcludedFromMixed,
URVersionsToProtocolVersions,
} from '../../util/supportedProtocolVersions'
import { enableMixedRouteEthWeth } from '../../util/enableMixedRouteEthWeth'

export class QuoteHandler extends APIGLambdaHandler<
ContainerInjected,
Expand Down Expand Up @@ -263,6 +264,7 @@ export class QuoteHandler extends APIGLambdaHandler<
params.event.headers?.['x-universal-router-version']
)
const excludedProtocolsFromMixed = protocolVersionsToBeExcludedFromMixed(universalRouterVersion)
const shouldEnableMixedRouteEthWeth = enableMixedRouteEthWeth(requestSourceHeader)

if (requestSourceHeader) {
metric.putMetric(`RequestSource.${requestSourceHeader}`, 1)
Expand Down Expand Up @@ -341,6 +343,7 @@ export class QuoteHandler extends APIGLambdaHandler<
...(enableFeeOnTransferFeeFetching ? FEE_ON_TRANSFER_SPECIFIC_CONFIG(enableFeeOnTransferFeeFetching) : {}),
...(gasToken ? { gasToken } : {}),
...(excludedProtocolsFromMixed ? { excludedProtocolsFromMixed } : {}),
shouldEnableMixedRouteEthWeth: shouldEnableMixedRouteEthWeth,
}

metric.putMetric(`${intent}Intent`, 1, MetricLoggerUnit.Count)
Expand Down
11 changes: 11 additions & 0 deletions lib/util/enableMixedRouteEthWeth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function enableMixedRouteEthWeth(requestSourceHeader?: string): boolean {
switch (requestSourceHeader) {
// only used for e2e-test purpose
case 'e2e-test':
return true
// TODO: enable once web, mobile, extension releases the FE bug fix for mixed route (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739296535359709?thread_ts=1739224900.129809&cid=C07AD3507SQ)
// TODO: for mobile, we need to ensure backward compatibility with the old version, using app version (https://uniswapteam.slack.com/archives/C07AD3507SQ/p1739309767819639?thread_ts=1739224900.129809&cid=C07AD3507SQ)
default:
return false
}
}
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@
"@types/stats-lite": "^2.2.0",
"@uniswap/default-token-list": "^11.13.0",
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.21.0",
"@uniswap/router-sdk": "^1.22.1",
"@uniswap/sdk-core": "^7.5.0",
"@uniswap/smart-order-router": "4.17.13",
"@uniswap/smart-order-router": "4.17.14",
"@uniswap/token-lists": "^1.0.0-beta.33",
"@uniswap/universal-router-sdk": "^4.14.0",
"@uniswap/universal-router-sdk": "^4.17.0",
"@uniswap/v2-sdk": "^4.13.0",
"@uniswap/v3-periphery": "^1.4.4",
"@uniswap/v3-sdk": "^3.24.0",
"@uniswap/v4-sdk": "^1.18.0",
"@uniswap/v4-sdk": "^1.18.1",
"async-retry": "^1.3.1",
"aws-cdk-lib": "^2.137.0",
"aws-embedded-metrics": "^2.0.6",
Expand Down
78 changes: 78 additions & 0 deletions test/mocha/e2e/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,84 @@ describe('quote', function () {
})
})

it('USDC -> mockA forceMixedRoutes true for mixed protocol on Base with request source', async () => {
if (type != 'exactIn') {
// mixed route only works for exactIn
return
}

const quoteReq: QuoteQueryParams = {
tokenInAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
tokenInChainId: 8453,
tokenOutAddress: '0x878784f7ebf6e57d17c81d82ddf53f117a5e2988',
tokenOutChainId: 8453,
amount: '1000000',
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
deadline: '360',
algorithm: 'alpha',
forceMixedRoutes: true,
protocols: 'mixed',
enableUniversalRouter: true,
}

const queryParams = qs.stringify(quoteReq)

const response: AxiosResponse<QuoteResponse> = await axios.get<QuoteResponse>(`${API}?${queryParams}`, {
headers: {
...HEADERS_2_0,
'x-request-source': 'e2e-test'
},
})
const {
data: { quoteDecimals, quoteGasAdjustedDecimals, methodParameters, routeString },
status,
} = response

expect(status).to.equal(200)
expect(parseFloat(quoteGasAdjustedDecimals)).to.be.lessThanOrEqual(parseFloat(quoteDecimals))
expect(methodParameters).to.not.be.undefined

/// since we only get the routeString back, we can check if there's V3 + V2
expect(routeString.includes('[V2 + V3 + V4]'))
})

it('USDC -> mockA forceMixedRoutes true for mixed protocol on Base no request source', async () => {
if (type != 'exactIn') {
// mixed route only works for exactIn
return
}

const quoteReq: QuoteQueryParams = {
tokenInAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
tokenInChainId: 8453,
tokenOutAddress: '0x878784f7ebf6e57d17c81d82ddf53f117a5e2988',
tokenOutChainId: 8453,
amount: '1000000',
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
deadline: '360',
algorithm: 'alpha',
forceMixedRoutes: true,
protocols: 'mixed',
enableUniversalRouter: true,
}

const queryParams = qs.stringify(quoteReq)

try {
await axios.get<QuoteResponse>(`${API}?${queryParams}`, {
headers: HEADERS_2_0,
})
} catch (err) {
if (err instanceof Error) {
expect(err.message).to.contains('404')
}
}
})

it.skip(`erc20 -> erc20 forceMixedRoutes true for all protocols specified`, async () => {
const quoteReq: QuoteQueryParams = {
tokenInAddress: 'BOND',
Expand Down

0 comments on commit 8ad01f5

Please sign in to comment.