Uniswap / smart-order-router

GNU General Public License v3.0
413 stars 420 forks source link

"Failed to get gas constants data from the optimism gas oracle" when quoting swaps on Base and Optimism #518

Closed pedroyan closed 7 months ago

pedroyan commented 8 months ago

I'm submitting a ...

[x] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

Summary

Hi there! I work for Endaoment and we are currently unable to process donations on L2's due to an error we are getting with the AutoRouter.

Every time we try to compute swaps on Optimism or Base on their respective Mainnets, the AutoRouter throws the following error: "Error: Failed to get gas constants data from the optimism gas oracle"

The problem seems to have started alongside the Dencun Update, so may be related?

Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Stack trace:

Error: Failed to get gas constants data from the optimism gas oracle
    at OptimismGasDataProvider.getGasData (/app/node_modules/@uniswap/smart-order-router/build/main/providers/v3/gas-data-provider.js:35:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async V3HeuristicGasModelFactory.buildGasModel (/app/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js:41:15)
    at async Promise.all (index 0)
    at async AlphaRouter.getGasModels (/app/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/alpha-router.js:651:50)
    at async AlphaRouter.route (/app/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/alpha-router.js:346:50)
    at async UniswapRoutingService.buildRoute (/app/main.js:52684:23)
    at async UniswapRoutingService.getBestV3SwapRoute (/app/main.js:52619:46)
    at async TokenPricingService.getSwapPrice (/app/main.js:52232:27)
    at async TokenPricingService.getSwapPriceWithFallback (/app/main.js:52272:20)

Arguments for failed WETH/USDbC Swap Quote on Base

"alphaRouterArguments": {
      "swapConfig": {
        "deadline": 1710869949,
        "type": 1,
        "recipient": "0x0000000000000000000000000000000000000000",
        "slippageTolerance": {
          "numerator": [
            100
          ],
          "isPercent": true,
          "denominator": [
            10000
          ]
        }
      },
      "partialRoutingConfig": {},
      "inputAmount": {
        "denominator": [
          1
        ],
        "decimalScale": [
          660865024,
          931322574
        ],
        "numerator": [
          166199296,
          723291154,
          8
        ],
        "currency": {
          "chainId": 8453,
          "isToken": true,
          "address": "0x4200000000000000000000000000000000000006",
          "symbol": "WETH",
          "decimals": 18,
          "isNative": false
        }
      },
      "outputToken": {
        "chainId": 8453,
        "isToken": true,
        "address": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
        "decimals": 6,
        "symbol": "USDbC",
        "isNative": false
      },
      "tradeType": 0
    }

Arguments for failed WETH/USDC Swap Quote on Optimism

{
"alphaRouterArguments": {
      "swapConfig": {
        "slippageTolerance": {
          "numerator": [
            100
          ],
          "isPercent": true,
          "denominator": [
            10000
          ]
        },
        "type": 1,
        "recipient": "0x0000000000000000000000000000000000000000",
        "deadline": 1710876077
      },
      "outputToken": {
        "decimals": 6,
        "address": "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
        "isNative": false,
        "isToken": true,
        "symbol": "USDC",
        "chainId": 10
      },
      "tradeType": 0,
      "inputAmount": {
        "currency": {
          "decimals": 18,
          "chainId": 10,
          "isToken": true,
          "address": "0x4200000000000000000000000000000000000006",
          "symbol": "WETH",
          "isNative": false
        },
        "denominator": [
          1
        ],
        "decimalScale": [
          660865024,
          931322574
        ],
        "numerator": [
          166199296,
          723291154,
          8
        ]
      },
      "partialRoutingConfig": {}
    }
}
pedroyan commented 8 months ago

Let me know if we can provide any more information that can be useful in the investigation here!

ghost commented 8 months ago

I'm getting the same symptom. Using version @uniswap/smart-order-router@3.17.4 in a browser. (tried to upgrade to latest but couldn't get it to work in the browser, but that's a different issue)

The point of failure for me is in OptimismGasDataProvider.getGasData, where it's making making these calls:

'l1BaseFee', 'scalar', 'decimals', 'overhead'

The tx.results show failures for 'scalar' and 'overhead'

[
    {
        "success": true,
        "result": [
            {
                "type": "BigNumber",
                "hex": "0x05b619715f"
            }
        ]
    },
    {
        "success": false,
        "returnData": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002647617350726963654f7261636c653a207363616c6172282920697320646570726563617465640000000000000000000000000000000000000000000000000000"
    },
    {
        "success": true,
        "result": [
            {
                "type": "BigNumber",
                "hex": "0x06"
            }
        ]
    },
    {
        "success": false,
        "returnData": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002847617350726963654f7261636c653a206f7665726865616428292069732064657072656361746564000000000000000000000000000000000000000000000000"
    }
]
nirtusbro commented 7 months ago

I'm seeing this same thing, is there a way around this?

julien51 commented 7 months ago

Confirmed for us as well!

ccarfi commented 7 months ago

also confirming seeing this too

nirtusbro commented 7 months ago

I solved this by using the v2 version of swap router: 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 Found here: https://docs.uniswap.org/contracts/v3/reference/deployments under SwapRouter02

stephancill commented 7 months ago

i believe the error is related to the deprecation of L1 calldata fees and transition to blob fees. the data returned by the errors decoded are revert messages: "GasPriceOracle: scalar() is deprecated" and "GasPriceOracle: overhead() is deprecated"

i'm not sure what the equivalent of overhead is in blobspace, but the patch below fixes the issue. it replaces the L1 fee variables with blob equivalents where available (everything except overhead) and updates the gas oracle ABI with the one from the latest deployment https://optimistic.etherscan.io/address/0xb528d11cc114e026f138fe568744c6d45ce6da7a#code

diff --git a/node_modules/@uniswap/smart-order-router/build/module/providers/v3/gas-data-provider.js b/node_modules/@uniswap/smart-order-router/build/module/providers/v3/gas-data-provider.js
index 700e514..939c775 100644
--- a/node_modules/@uniswap/smart-order-router/build/module/providers/v3/gas-data-provider.js
+++ b/node_modules/@uniswap/smart-order-router/build/module/providers/v3/gas-data-provider.js
@@ -2,6 +2,7 @@ import { ChainId } from '@uniswap/sdk-core';
 import { GasDataArbitrum__factory } from '../../types/other/factories/GasDataArbitrum__factory';
 import { GasPriceOracle__factory } from '../../types/other/factories/GasPriceOracle__factory';
 import { ARB_GASINFO_ADDRESS, log, OVM_GASPRICE_ADDRESS } from '../../util';
+import { BigNumber } from 'ethers';
 export class OptimismGasDataProvider {
     constructor(chainId, multicall2Provider, gasPriceAddress) {
         this.chainId = chainId;
@@ -18,23 +19,25 @@ export class OptimismGasDataProvider {
      */
     async getGasData() {
         var _a, _b, _c, _d;
-        const funcNames = ['l1BaseFee', 'scalar', 'decimals', 'overhead'];
+        const funcNames = ['blobBaseFee', 'blobBaseFeeScalar', 'decimals', 'overhead'];
         const tx = await this.multicall2Provider.callMultipleFunctionsOnSameContract({
             address: this.gasOracleAddress,
             contractInterface: GasPriceOracle__factory.createInterface(),
             functionNames: funcNames,
         });
+
         if (!((_a = tx.results[0]) === null || _a === void 0 ? void 0 : _a.success) ||
             !((_b = tx.results[1]) === null || _b === void 0 ? void 0 : _b.success) ||
-            !((_c = tx.results[2]) === null || _c === void 0 ? void 0 : _c.success) ||
-            !((_d = tx.results[3]) === null || _d === void 0 ? void 0 : _d.success)) {
+            !((_c = tx.results[2]) === null || _c === void 0 ? void 0 : _c.success) 
+            // || !((_d = tx.results[3]) === null || _d === void 0 ? void 0 : _d.success)
+            ) {
             log.info({ results: tx.results }, 'Failed to get gas constants data from the optimism gas oracle');
             throw new Error('Failed to get gas constants data from the optimism gas oracle');
         }
         const { result: l1BaseFee } = tx.results[0];
         const { result: scalar } = tx.results[1];
         const { result: decimals } = tx.results[2];
-        const { result: overhead } = tx.results[3];
+        const { result: overhead } = tx.results[3].success ? tx.results[3] : {result: [BigNumber.from(0)]};
         return {
             l1BaseFee: l1BaseFee[0],
             scalar: scalar[0],
diff --git a/node_modules/@uniswap/smart-order-router/build/module/types/other/factories/GasPriceOracle__factory.js b/node_modules/@uniswap/smart-order-router/build/module/types/other/factories/GasPriceOracle__factory.js
index a893e46..c41f77e 100644
--- a/node_modules/@uniswap/smart-order-router/build/module/types/other/factories/GasPriceOracle__factory.js
+++ b/node_modules/@uniswap/smart-order-router/build/module/types/other/factories/GasPriceOracle__factory.js
@@ -4,302 +4,207 @@
 import { Contract, utils } from "ethers";
 const _abi = [
     {
-        inputs: [
-            {
-                internalType: "address",
-                name: "_owner",
-                type: "address",
-            },
-        ],
-        stateMutability: "nonpayable",
-        type: "constructor",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: false,
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        name: "DecimalsUpdated",
-        type: "event",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: false,
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        name: "GasPriceUpdated",
-        type: "event",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: false,
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        name: "L1BaseFeeUpdated",
-        type: "event",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: false,
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        name: "OverheadUpdated",
-        type: "event",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: true,
-                internalType: "address",
-                name: "previousOwner",
-                type: "address",
-            },
-            {
-                indexed: true,
-                internalType: "address",
-                name: "newOwner",
-                type: "address",
-            },
-        ],
-        name: "OwnershipTransferred",
-        type: "event",
-    },
-    {
-        anonymous: false,
-        inputs: [
-            {
-                indexed: false,
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        name: "ScalarUpdated",
-        type: "event",
-    },
-    {
-        inputs: [],
-        name: "decimals",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "gasPrice",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "bytes",
-                name: "_data",
-                type: "bytes",
-            },
-        ],
-        name: "getL1Fee",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "bytes",
-                name: "_data",
-                type: "bytes",
-            },
-        ],
-        name: "getL1GasUsed",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "l1BaseFee",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "overhead",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "owner",
-        outputs: [
-            {
-                internalType: "address",
-                name: "",
-                type: "address",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "renounceOwnership",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [],
-        name: "scalar",
-        outputs: [
-            {
-                internalType: "uint256",
-                name: "",
-                type: "uint256",
-            },
-        ],
-        stateMutability: "view",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "uint256",
-                name: "_decimals",
-                type: "uint256",
-            },
-        ],
-        name: "setDecimals",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "uint256",
-                name: "_gasPrice",
-                type: "uint256",
-            },
-        ],
-        name: "setGasPrice",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "uint256",
-                name: "_baseFee",
-                type: "uint256",
-            },
-        ],
-        name: "setL1BaseFee",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "uint256",
-                name: "_overhead",
-                type: "uint256",
-            },
-        ],
-        name: "setOverhead",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "uint256",
-                name: "_scalar",
-                type: "uint256",
-            },
-        ],
-        name: "setScalar",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-    {
-        inputs: [
-            {
-                internalType: "address",
-                name: "newOwner",
-                type: "address",
-            },
-        ],
-        name: "transferOwnership",
-        outputs: [],
-        stateMutability: "nonpayable",
-        type: "function",
-    },
-];
+        "inputs": [],
+        "name": "DECIMALS",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "baseFee",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "baseFeeScalar",
+        "outputs": [
+        {
+            "internalType": "uint32",
+            "name": "",
+            "type": "uint32"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "blobBaseFee",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "blobBaseFeeScalar",
+        "outputs": [
+        {
+            "internalType": "uint32",
+            "name": "",
+            "type": "uint32"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "decimals",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "pure",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "gasPrice",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+        {
+            "internalType": "bytes",
+            "name": "_data",
+            "type": "bytes"
+        }
+        ],
+        "name": "getL1Fee",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+        {
+            "internalType": "bytes",
+            "name": "_data",
+            "type": "bytes"
+        }
+        ],
+        "name": "getL1GasUsed",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "isEcotone",
+        "outputs": [
+        {
+            "internalType": "bool",
+            "name": "",
+            "type": "bool"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "l1BaseFee",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "overhead",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "scalar",
+        "outputs": [
+        {
+            "internalType": "uint256",
+            "name": "",
+            "type": "uint256"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "setEcotone",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "version",
+        "outputs": [
+        {
+            "internalType": "string",
+            "name": "",
+            "type": "string"
+        }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    }
+    ];
 export class GasPriceOracle__factory {
     static createInterface() {
         return new utils.Interface(_abi);
Aiden0801 commented 7 months ago

Same here. Can anyone please help me?

pietro-bertarini commented 7 months ago

I was facing the same problem and it was resolved after I update to 3.26.1!! Screenshot 2024-04-02 at 18 02 47

Akhilesh-solutelabs commented 7 months ago

we were able to get rid of the error of Failed to get gas constants data from the optimism gas oracle by upgrading to :

    "@uniswap/sdk-core": "^4.2.0",
    "@uniswap/smart-order-router": "^3.26.0",
    "@uniswap/v3-periphery": "^1.4.4",
    "@uniswap/v3-sdk": "^3.11.0",

which caused Browser is not defined - solution : Adding fallback script as mentioned in comments in #484

after which we ran into - image so we moved the L:6 variables - _SEPOLIA of github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/get-candidate-pools.ts i.e. USDC_ARBITRUM_SEPOLIA, DAI_OPTIMISM_SEPOLIA, USDC_OPTIMISM_SEPOLIA, USDT_OPTIMISM_SEPOLIA, WBTC_OPTIMISM_SEPOLIA to already existing import on L:16 import { USDC_ARBITRUM_SEPOLIA, DAI_OPTIMISM_SEPOLIA, USDC_OPTIMISM_SEPOLIA, USDT_OPTIMISM_SEPOLIA, WBTC_OPTIMISM_SEPOLIA, CELO, CELO_ALFAJORES, ...} from '../../../providers/token-provider';

It seems to have worked for me. I was able to get a quote for ETH/ other tokens .. on Optimism chain using Alpha router & do a successful swap. So I would request uniswap team @jsy1218 to update the imports perhaps? not sure why there are two different imports when they use the same token-provider file.

jsy1218 commented 7 months ago

Sorry for the trouble. The original issue happened after OP Ecotone upgrade, same day as Dencun. Proper fix was in since 3.26.0.

For the minor import issue in https://github.com/Uniswap/smart-order-router/issues/518#issuecomment-2034291988, will find a time to fix.

dglowinski commented 2 months ago

@jsy1218 It seems the import fix to https://github.com/Uniswap/smart-order-router/issues/518#issuecomment-2034291988 was never merged upstream