Skip to content

Commit

Permalink
fix: Fail to adjust gas cost (#11078)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on fixing error handling when adjusting token output by
gas cost in the `offChainQuoteProvider.ts` file of the `smart-router`
package.

### Detailed summary
- Updated the destructuring of `route` to include `output` and `input`.
- Introduced `quoteCurrency` to determine the correct currency based on
the wrapped amounts.
- Changed the `quote` assignment to use `finalQuote` created from
`CurrencyAmount.fromRawAmount`.
- Adjusted the `quote` and `quoteAdjustedForGas` properties in the
`routesWithQuote` push to use `finalQuote`.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
chefjackson authored Dec 20, 2024
1 parent 5cc3be4 commit 8578d8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-bananas-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pancakeswap/smart-router': patch
---

Fix error throws when adjusting token output by gas cost
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function createOffChainQuoteProvider(): QuoteProvider {
const routesWithQuote: RouteWithQuote[] = []
for (const route of routes) {
try {
const { pools, amount } = route
const { pools, amount, output, input } = route
const quoteCurrency = amount.currency.wrapped.equals(input.wrapped) ? output : input
let quote = amount
const initializedTickCrossedList = Array(pools.length).fill(0)
let quoteSuccess = true
Expand Down Expand Up @@ -75,17 +76,18 @@ export function createOffChainQuoteProvider(): QuoteProvider {
continue
}

const finalQuote = CurrencyAmount.fromRawAmount(quoteCurrency, quote.quotient)
const { gasEstimate, gasCostInUSD, gasCostInToken } = gasModel.estimateGasCost(
{
...route,
quote,
quote: finalQuote,
},
{ initializedTickCrossedList },
)
routesWithQuote.push({
...route,
quote,
quoteAdjustedForGas: adjustQuoteForGas(quote, gasCostInToken),
quote: finalQuote,
quoteAdjustedForGas: adjustQuoteForGas(finalQuote, gasCostInToken),
gasEstimate,
gasCostInUSD,
gasCostInToken,
Expand Down

0 comments on commit 8578d8f

Please sign in to comment.