chore(wallet)_: use proxy instead of OVM_GasPriceOracle contract for estimating l1 fee

- A new contract is used for estimating L1 fee.
- New contract's addresses are known only for Optimims and Sepolia Optimimsm.
- Old contract and addresses per chain are kept so far, but not in use anymore.

Comparing to other wallets, seems L1 fee is added to the total fee only for the Optimims chain.
So we're doing the same in this commit, disabling L1 fees for other than the Optimism.
This commit is contained in:
Sale Djenic 2025-01-31 12:57:24 +01:00 committed by saledjenic
parent 9957dd330c
commit c4dca62c4b
7 changed files with 1654 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import (
var ErrorNotAvailableOnChainID = errors.New("not available for chainID")
// Addresses of the gas price oracle contract `OVM_GasPriceOracle` on different chains.
var contractAddressByChainID = map[uint64]common.Address{
wallet_common.OptimismMainnet: common.HexToAddress("0x8527c030424728cF93E72bDbf7663281A44Eeb22"),
wallet_common.OptimismSepolia: common.HexToAddress("0x5230210c2b4995FD5084b0F5FD0D7457aebb5010"),
@ -19,6 +20,8 @@ var contractAddressByChainID = map[uint64]common.Address{
wallet_common.BaseSepolia: common.HexToAddress("0x5230210c2b4995FD5084b0F5FD0D7457aebb5010"),
}
// We stopped uisng `OVM_GasPriceOracle` contract, cause it returns significantly higher gas prices than the actual ones.
// But we don't remove this code for now.
func ContractAddress(chainID uint64) (common.Address, error) {
addr, exists := contractAddressByChainID[chainID]
if !exists {

View File

@ -0,0 +1,25 @@
package gaspriceproxy
import (
"errors"
"github.com/ethereum/go-ethereum/common"
wallet_common "github.com/status-im/status-go/services/wallet/common"
)
var ErrorNotAvailableOnChainID = errors.New("not available for chainID")
// Addresses of the proxy contract `Proxy` on different chains.
var contractAddressByChainID = map[uint64]common.Address{
wallet_common.OptimismMainnet: common.HexToAddress("0x420000000000000000000000000000000000000F"),
wallet_common.OptimismSepolia: common.HexToAddress("0x420000000000000000000000000000000000000F"),
}
func ContractAddress(chainID uint64) (common.Address, error) {
addr, exists := contractAddressByChainID[chainID]
if !exists {
return common.Address{}, ErrorNotAvailableOnChainID
}
return addr, nil
}

View File

@ -0,0 +1,3 @@
package gaspriceproxy
//go:generate abigen -abi gaspriceproxy.abi -pkg gaspriceproxy -out gaspriceproxy.go

View File

@ -0,0 +1,316 @@
[
{
"inputs": [],
"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": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "ScalarUpdated",
"type": "event"
},
{
"inputs": [],
"name": "admin",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "adminCall",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"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": [],
"name": "getAdmin",
"outputs": [
{
"internalType": "address",
"name": "adminAddress",
"type": "address"
}
],
"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": [
{
"internalType": "bytes",
"name": "initPayload",
"type": "bytes"
}
],
"name": "init",
"outputs": [
{
"internalType": "bytes4",
"name": "",
"type": "bytes4"
}
],
"stateMutability": "nonpayable",
"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": [
{
"internalType": "address",
"name": "adminAddress",
"type": "address"
}
],
"name": "setAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"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"
}
]

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ import (
"context"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gaspriceoracle "github.com/status-im/status-go/contracts/gas-price-oracle"
gaspriceproxy "github.com/status-im/status-go/contracts/gas-price-proxy"
"github.com/status-im/status-go/services/wallet/common"
)
@ -50,12 +50,12 @@ func (f *FeeManager) GetL1Fee(ctx context.Context, chainID uint64, input []byte)
return 0, err
}
contractAddress, err := gaspriceoracle.ContractAddress(chainID)
contractAddress, err := gaspriceproxy.ContractAddress(chainID)
if err != nil {
return 0, err
}
contract, err := gaspriceoracle.NewGaspriceoracleCaller(contractAddress, ethClient)
contract, err := gaspriceproxy.NewGaspriceproxy(contractAddress, ethClient)
if err != nil {
return 0, err
}

View File

@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/contracts"
gaspriceoracle "github.com/status-im/status-go/contracts/gas-price-oracle"
gaspriceproxy "github.com/status-im/status-go/contracts/gas-price-proxy"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc/chain"
@ -94,19 +94,19 @@ func (r *Router) calculateL1Fee(chainID uint64, data []byte) (*big.Int, error) {
}
func CalculateL1Fee(chainID uint64, data []byte, ethClient chain.ClientInterface) (*big.Int, error) {
oracleContractAddress, err := gaspriceoracle.ContractAddress(chainID)
oracleContractAddress, err := gaspriceproxy.ContractAddress(chainID)
if err != nil {
return nil, err
}
oracleContract, err := gaspriceoracle.NewGaspriceoracleCaller(oracleContractAddress, ethClient)
proxyContract, err := gaspriceproxy.NewGaspriceproxy(oracleContractAddress, ethClient)
if err != nil {
return nil, err
}
callOpt := &bind.CallOpts{}
return oracleContract.GetL1Fee(callOpt, data)
return proxyContract.GetL1Fee(callOpt, data)
}
func (r *Router) getERC1155Balance(ctx context.Context, network *params.Network, token *token.Token, account common.Address) (*big.Int, error) {
@ -256,9 +256,8 @@ func (r *Router) evaluateAndUpdatePathDetails(ctx context.Context, path *routes.
l1TxFeeWei := big.NewInt(0)
l1ApprovalFeeWei := big.NewInt(0)
needL1Fee := path.FromChain.ChainID != walletCommon.EthereumMainnet &&
path.FromChain.ChainID != walletCommon.EthereumSepolia &&
path.FromChain.ChainID != walletCommon.AnvilMainnet
needL1Fee := path.FromChain.ChainID == walletCommon.OptimismMainnet ||
path.FromChain.ChainID == walletCommon.OptimismSepolia
if testsMode {
usedNonces[path.FromChain.ChainID] = usedNonces[path.FromChain.ChainID] + 1