From 5c69dbed2b0b76d11f9f747836bd71fafa96a8c0 Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:16:17 -0700 Subject: [PATCH 1/3] feat: expose price impact in routing-api response --- lib/handlers/quote/quote.ts | 4 +++- lib/handlers/schema.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/handlers/quote/quote.ts b/lib/handlers/quote/quote.ts index 779ec175a..060d93d39 100644 --- a/lib/handlers/quote/quote.ts +++ b/lib/handlers/quote/quote.ts @@ -477,7 +477,8 @@ export class QuoteHandler extends APIGLambdaHandler< blockNumber, simulationStatus, hitsCachedRoute, - portionAmount: outputPortionAmount, // TODO: name it back to portionAmount + portionAmount: outputPortionAmount, // TODO: name it back to portionAmount, + trade, } = swapRoute const estimatedGasUsed = adhocCorrectGasUsed(preProcessedEstimatedGasUsed, chainId, requestSource) @@ -682,6 +683,7 @@ export class QuoteHandler extends APIGLambdaHandler< portionRecipient: outputPortionAmount && portionRecipient, portionAmount: outputPortionAmount?.quotient.toString(), portionAmountDecimals: outputPortionAmount?.toExact(), + priceImpact: trade?.priceImpact?.toFixed(), } this.logRouteMetrics( diff --git a/lib/handlers/schema.ts b/lib/handlers/schema.ts index 0906aaeaa..ed0621868 100644 --- a/lib/handlers/schema.ts +++ b/lib/handlers/schema.ts @@ -89,6 +89,7 @@ export const QuoteResponseSchemaJoi = Joi.object().keys({ portionRecipient: Joi.string().optional(), portionAmount: Joi.string().optional(), portionAmountDecimals: Joi.string().optional(), + priceImpact: Joi.string().optional(), }) export type QuoteResponse = { @@ -119,4 +120,5 @@ export type QuoteResponse = { portionRecipient?: string portionAmount?: string portionAmountDecimals?: string + priceImpact?: string } From 4e95a85b3c6dd0b3c369162b1c8e4a72998d0231 Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:25:49 -0700 Subject: [PATCH 2/3] add price impact e2e test assertion --- test/mocha/e2e/quote.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index 64c3b4351..d97523068 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -1,6 +1,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { AllowanceTransfer, PermitSingle } from '@uniswap/permit2-sdk' -import { ChainId, Currency, CurrencyAmount, Ether, Fraction, Rounding, Token, WETH9 } from '@uniswap/sdk-core' +import { ChainId, Currency, CurrencyAmount, Ether, Fraction, Percent, Rounding, Token, WETH9 } from '@uniswap/sdk-core' import { CEUR_CELO, CEUR_CELO_ALFAJORES, @@ -356,7 +356,7 @@ describe('quote', function () { const response: AxiosResponse = await axios.get(`${API}?${queryParams}`) const { - data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters }, + data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters, priceImpact }, status, } = response @@ -364,6 +364,8 @@ describe('quote', function () { expect(parseFloat(quoteDecimals)).to.be.greaterThan(90) expect(parseFloat(quoteDecimals)).to.be.lessThan(110) + expect(Number(priceImpact)).to.be.greaterThan(0) + if (type == 'exactIn') { expect(parseFloat(quoteGasAdjustedDecimals)).to.be.lessThanOrEqual(parseFloat(quoteDecimals)) } else { From 9b8879da60751df9d14fa94868225a26c991e1bb Mon Sep 17 00:00:00 2001 From: jsy1218 <91580504+jsy1218@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:30:17 -0700 Subject: [PATCH 3/3] remove unused import --- test/mocha/e2e/quote.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/e2e/quote.test.ts b/test/mocha/e2e/quote.test.ts index d97523068..f32e4bc60 100644 --- a/test/mocha/e2e/quote.test.ts +++ b/test/mocha/e2e/quote.test.ts @@ -1,6 +1,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { AllowanceTransfer, PermitSingle } from '@uniswap/permit2-sdk' -import { ChainId, Currency, CurrencyAmount, Ether, Fraction, Percent, Rounding, Token, WETH9 } from '@uniswap/sdk-core' +import { ChainId, Currency, CurrencyAmount, Ether, Fraction, Rounding, Token, WETH9 } from '@uniswap/sdk-core' import { CEUR_CELO, CEUR_CELO_ALFAJORES,