Uniswap / smart-order-router

GNU General Public License v3.0
419 stars 426 forks source link

Package does not work in browser due to Brotli dependency (Arbitrum one/goerli) #662

Open ethanrushh opened 3 months ago

ethanrushh commented 3 months ago

When using Arbitrum One / Arbitrum Goerli, Brotli is used to help estimate the gas within the getL2ToL1GasUsed function of gas-factory-helpers.js. Brotli.js is abandoned and has no browser support. From looking around, it seems like the most appropriate replacement would be brotli-wasm.

I would like to know the thoughts of the project maintainers regarding migrating from brotli.js to brotli-wasm. I would like to work on that myself if possible and submit a PR when complete.

namedotget commented 2 months ago

I was able to get past this issue by adding this script to index.html

          <script
            dangerouslySetInnerHTML={{
              __html: `globalThis.Browser = { T: () => {} };`,
            }}
          />

I'm now running into this error when I try to create a route on Arbitrum One :

TypeError: brotli._malloc is not a function
    at module.exports [as compress] (compress.js:24:1)
    at getArbitrumBytes (gas-factory-helpers.js:119:24)
    at getL2ToL1GasUsed (gas-factory-helpers.js:154:1)
    at calculateArbitrumToL1FeeFromCalldata (gas-factory-helpers.js:134:1)
    at calculateArbitrumToL1SecurityFee (gas-factory-helpers.js:384:1)
    at calculateL1GasFeesHelper (gas-factory-helpers.js:326:1)
    at Object.calculateL1GasFees (v3-heuristic-gas-model.js:39:50)
    at getBestSwapRouteBy (best-swap-route.js:320:1)
    at getBestSwapRoute (best-swap-route.js:40:1)
    at AlphaRouter.getSwapRouteFromChain (alpha-router.js:800:53)
    at async Promise.all (index 1)
    at async AlphaRouter.route (alpha-router.js:497:1)
    at async generateRoute (useUniversalRouter.tsx:42:21)

I'm using version ^3.19.2