Skip to content

Commit

Permalink
fix: bump SOR to 4.18.0 - fix: properly use global cache + mixed rout…
Browse files Browse the repository at this point in the history
…es fix (#1014)

* fix: bump SOR to 4.18.0 - fix: properly use global cache + mixed routes fix

* add mixed only e2e test

* swaprouter02 test use ura1.2 header

* sor 4.18.0

* sor 4.18.0 fix

* force mixed routes test skip cache
  • Loading branch information
xrsv authored Feb 13, 2025
1 parent ba4b969 commit d991f6b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
6 changes: 6 additions & 0 deletions lib/handlers/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ export class QuoteHandler extends APIGLambdaHandler<
errorCode: 'INVALID_PROTOCOL',
detail: `Invalid protocol specified. Supported protocols: ${JSON.stringify(Object.values(Protocol))}`,
}
} else if (protocols.length === 1 && protocols[0] === Protocol.MIXED) {
return {
statusCode: 400,
errorCode: 'INVALID_PROTOCOL',
detail: `Mixed protocol cannot be specified explicitly`,
}
}

// Parse user provided token address/symbol to Currency object.
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.22.1",
"@uniswap/sdk-core": "^7.5.0",
"@uniswap/smart-order-router": "4.17.14",
"@uniswap/smart-order-router": "4.18.0",
"@uniswap/token-lists": "^1.0.0-beta.33",
"@uniswap/universal-router-sdk": "^4.17.0",
"@uniswap/v2-sdk": "^4.13.0",
Expand Down
51 changes: 40 additions & 11 deletions test/mocha/e2e/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ describe('quote', function () {
slippageTolerance: SLIPPAGE,
deadline: '360',
algorithm,
protocols: ALL_PROTOCOLS,
protocols: 'v2,v3,mixed',
}

const queryParams = qs.stringify(quoteReq)

const response: AxiosResponse<QuoteResponse> = await axios.get<QuoteResponse>(`${API}?${queryParams}`, {
headers: HEADERS_2_0,
headers: HEADERS_1_2,
})
const {
data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters },
Expand Down Expand Up @@ -869,7 +869,7 @@ describe('quote', function () {

const queryParams = qs.stringify(quoteReq)

const response = await axios.get<QuoteResponse>(`${API}?${queryParams}`, { headers: HEADERS_2_0 })
const response = await axios.get<QuoteResponse>(`${API}?${queryParams}`, { headers: HEADERS_1_2 })
const { data, status } = response

expect(status).to.equal(200)
Expand Down Expand Up @@ -1376,10 +1376,14 @@ describe('quote', function () {

expect(methodParameters).to.not.be.undefined

let hasV4Pool = false
let hasV3Pool = false
let hasV2Pool = false
for (const r of route) {
for (const pool of r) {
if (pool.type == 'v4-pool') {
hasV4Pool = true
}
if (pool.type == 'v3-pool') {
hasV3Pool = true
}
Expand All @@ -1389,7 +1393,7 @@ describe('quote', function () {
}
}

expect(hasV3Pool && hasV2Pool).to.be.true
expect((hasV3Pool && hasV2Pool) || (hasV4Pool && hasV2Pool) || (hasV4Pool && hasV3Pool)).to.be.true

const { tokenInBefore, tokenInAfter, tokenOutBefore, tokenOutAfter } = await executeSwap(
response.data.methodParameters!,
Expand Down Expand Up @@ -1447,6 +1451,31 @@ describe('quote', function () {
expect(!routeString.includes('[V2 + V3]'))
})

it(`erc20 -> erc20 only mixed is not allowed`, async () => {
const quoteReq: QuoteQueryParams = {
tokenInAddress: 'BOND',
tokenInChainId: 1,
tokenOutAddress: 'APE',
tokenOutChainId: 1,
amount: await getAmount(1, type, 'BOND', 'APE', '10000'),
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
deadline: '360',
algorithm: 'alpha',
protocols: 'mixed',
enableUniversalRouter: true,
}

await callAndExpectFail(quoteReq, {
status: 400,
data: {
detail: 'Mixed protocol cannot be specified explicitly',
errorCode: 'INVALID_PROTOCOL',
},
})
})

it(`erc20 -> erc20 forceMixedRoutes true for v2,v3`, async () => {
const quoteReq: QuoteQueryParams = {
tokenInAddress: 'BOND',
Expand Down Expand Up @@ -1491,7 +1520,7 @@ describe('quote', function () {
deadline: '360',
algorithm: 'alpha',
forceMixedRoutes: true,
protocols: 'mixed',
protocols: 'v3,v4,mixed',
enableUniversalRouter: true,
}

Expand Down Expand Up @@ -1534,7 +1563,7 @@ describe('quote', function () {
deadline: '360',
algorithm: 'alpha',
forceMixedRoutes: true,
protocols: 'mixed',
protocols: ALL_PROTOCOLS,
enableUniversalRouter: true,
}

Expand Down Expand Up @@ -1630,7 +1659,7 @@ describe('quote', function () {
tokenOutChainId: tokenOut.chainId,
amount: amount,
type: type,
protocols: 'v2,v3,mixed',
protocols: ALL_PROTOCOLS,
// TODO: ROUTE-86 remove enableFeeOnTransferFeeFetching once we are ready to enable this by default
enableFeeOnTransferFeeFetching: enableFeeOnTransferFeeFetching,
recipient: alice.address,
Expand Down Expand Up @@ -1883,13 +1912,13 @@ describe('quote', function () {
deadline: '360',
algorithm,
simulateFromAddress: '0xf584f8728b874a6a5c7a8d4d387c9aae9172d621',
protocols: ALL_PROTOCOLS,
protocols: 'v2,v3,mixed',
}

const queryParams = qs.stringify(quoteReq)

const response: AxiosResponse<QuoteResponse> = await axios.get<QuoteResponse>(`${API}?${queryParams}`, {
headers: HEADERS_2_0,
headers: HEADERS_1_2,
})
const {
data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters, simulationError },
Expand Down Expand Up @@ -2224,7 +2253,7 @@ describe('quote', function () {

const queryParams = qs.stringify(quoteReq)

const response = await axios.get<QuoteResponse>(`${API}?${queryParams}`, { headers: HEADERS_2_0 })
const response = await axios.get<QuoteResponse>(`${API}?${queryParams}`, { headers: HEADERS_1_2 })
const { data, status } = response
expect(status).to.equal(200)
expect(data.methodParameters).to.not.be.undefined
Expand Down Expand Up @@ -2393,7 +2422,7 @@ describe('quote', function () {
tokenOutChainId: tokenOut.chainId,
amount: amount,
type: type,
protocols: 'v2,v3,mixed',
protocols: ALL_PROTOCOLS,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
deadline: '360',
Expand Down

0 comments on commit d991f6b

Please sign in to comment.