Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose price impact in routing-api response #846

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/handlers/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lib/handlers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -119,4 +120,5 @@ export type QuoteResponse = {
portionRecipient?: string
portionAmount?: string
portionAmountDecimals?: string
priceImpact?: string
}
4 changes: 3 additions & 1 deletion test/mocha/e2e/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,16 @@ describe('quote', function () {

const response: AxiosResponse<QuoteResponse> = await axios.get<QuoteResponse>(`${API}?${queryParams}`)
const {
data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters },
data: { quote, quoteDecimals, quoteGasAdjustedDecimals, methodParameters, priceImpact },
status,
} = response

expect(status).to.equal(200)
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 {
Expand Down
Loading