When using the smart-order-router (all latest, though also tried verisons previously working on cra) with Vite, I receive a Could not parse fraction
error each time I try to get a route from the smart order router. My exact same code worked on Create React App, though a full restart of the project but copying over the component files (but not any configuration files) yields this issue. Is this a bug on Uniswap’s side or an issue with my code or Vite setup?
Uniswap V3 SwapRouter.swapCallParameters Could not parse fraction did not solve the issue.
Versions:
- @uniswap/[email protected]
- @uniswap/[email protected]
- @uniswap/[email protected]
- [email protected] (though also tried installing 3.2.0, same issue)
The routing code thats throwing the error:
const options: SmartRouter.SwapOptionsSwapRouter02 = {
recipient: address,
slippageTolerance: new Core.Percent(1, 1),
deadline: Math.floor(Date.now() / 1000 + 1800),
type: SmartRouter.SwapType.SWAP_ROUTER_02
}
const route = await router.route(
Core.CurrencyAmount.fromRawAmount(inputToken, inputAmount.toString()),
outputToken,
Core.TradeType.EXACT_INPUT,
options
)
if (!route || !route.methodParameters) {
console.warn("Routing failed")
return
}
And the log for the error:
useUniswap.ts:353 Failed to route swap, error occured: Error: Could not parse fraction
at Function.tryParseFraction (chunk-YN4HSXAX.js?v=61b21d1c:1546:15)
at Percent2.lessThan (chunk-YN4HSXAX.js?v=61b21d1c:1567:37)
at Trade2.maximumAmountIn (chunk-4RU6S4JE.js?v=61b21d1c:5246:29)
at addV3Swap (@uniswap_smart-order-router.js?v=61b21d1c:50785:135)
at UniswapTrade2.encode3 [as encode] (@uniswap_smart-order-router.js?v=61b21d1c:50710:15)
at Function.swapERC20CallParameters (@uniswap_smart-order-router.js?v=61b21d1c:50985:15)
at buildSwapMethodParameters (@uniswap_smart-order-router.js?v=61b21d1c:110390:49)
at calculateArbitrumToL1SecurityFee (@uniswap_smart-order-router.js?v=61b21d1c:110712:18)
at calculateL1GasFeesHelper (@uniswap_smart-order-router.js?v=61b21d1c:110677:56)
at Object.calculateL1GasFees (@uniswap_smart-order-router.js?v=61b21d1c:112279:20)
Although the slippageTolerance is set to 100% in that example, I have tried using the example (50, 10_000) and (50, 100) values. Same problem occurs.
Note: Some chains don’t seem to have this issue. Polygon routes without (many) issues but Arbitrum, previously working on CRA, has this issue every time. Here’s a list of what does and doesn’t work:
- Ethereum – Works
- BNB Chain – Works
- Arbitrum One – Fraction Error
- Polygon – Works
- AVAX C-Chain – Fails, Provider Gas Error
Here is my vite.config.ts
:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import macrosPlugin from 'vite-plugin-babel-macros'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), macrosPlugin()],
define: {
'process.env': process.env
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
})