2023-04-18 14:33:59 +00:00
|
|
|
package common
|
|
|
|
|
2023-09-22 13:18:42 +00:00
|
|
|
import (
|
2024-09-23 06:35:34 +00:00
|
|
|
"math/big"
|
2023-09-22 13:18:42 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
2024-07-18 20:14:42 +00:00
|
|
|
|
|
|
|
ethCommon "github.com/ethereum/go-ethereum/common"
|
2023-09-22 13:18:42 +00:00
|
|
|
)
|
2023-09-04 10:18:46 +00:00
|
|
|
|
2024-03-12 09:15:30 +00:00
|
|
|
type MultiTransactionIDType int64
|
|
|
|
|
|
|
|
const (
|
|
|
|
NoMultiTransactionID = MultiTransactionIDType(0)
|
2024-08-28 11:17:59 +00:00
|
|
|
HexAddressLength = 42
|
2024-11-05 11:05:23 +00:00
|
|
|
StatusDomain = "stateofus.eth"
|
2024-03-12 09:15:30 +00:00
|
|
|
)
|
|
|
|
|
2023-04-18 14:33:59 +00:00
|
|
|
type ChainID uint64
|
|
|
|
|
|
|
|
const (
|
2024-05-15 11:33:26 +00:00
|
|
|
UnknownChainID uint64 = 0
|
|
|
|
EthereumMainnet uint64 = 1
|
|
|
|
EthereumSepolia uint64 = 11155111
|
|
|
|
OptimismMainnet uint64 = 10
|
|
|
|
OptimismSepolia uint64 = 11155420
|
|
|
|
ArbitrumMainnet uint64 = 42161
|
|
|
|
ArbitrumSepolia uint64 = 421614
|
|
|
|
BinanceChainID uint64 = 56 // obsolete?
|
|
|
|
BinanceTestChainID uint64 = 97 // obsolete?
|
2024-09-25 12:27:04 +00:00
|
|
|
AnvilMainnet uint64 = 31337
|
2023-04-18 14:33:59 +00:00
|
|
|
)
|
2023-09-04 10:18:46 +00:00
|
|
|
|
2024-07-18 20:14:42 +00:00
|
|
|
var (
|
2024-08-28 11:17:59 +00:00
|
|
|
SupportedNetworks = map[uint64]bool{
|
|
|
|
EthereumMainnet: true,
|
|
|
|
OptimismMainnet: true,
|
|
|
|
ArbitrumMainnet: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
SupportedTestNetworks = map[uint64]bool{
|
|
|
|
EthereumSepolia: true,
|
|
|
|
OptimismSepolia: true,
|
|
|
|
ArbitrumSepolia: true,
|
|
|
|
}
|
2024-07-18 20:14:42 +00:00
|
|
|
)
|
|
|
|
|
2024-02-06 15:27:15 +00:00
|
|
|
type ContractType byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
ContractTypeUnknown ContractType = iota
|
|
|
|
ContractTypeERC20
|
|
|
|
ContractTypeERC721
|
|
|
|
ContractTypeERC1155
|
|
|
|
)
|
|
|
|
|
2024-09-23 06:35:34 +00:00
|
|
|
func ZeroAddress() ethCommon.Address {
|
|
|
|
return ethCommon.Address{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ZeroBigIntValue() *big.Int {
|
|
|
|
return big.NewInt(0)
|
|
|
|
}
|
|
|
|
|
2024-10-16 05:09:56 +00:00
|
|
|
func ZeroHash() ethCommon.Hash {
|
|
|
|
return ethCommon.Hash{}
|
|
|
|
}
|
|
|
|
|
2023-09-22 13:18:42 +00:00
|
|
|
func (c ChainID) String() string {
|
2024-07-26 18:56:48 +00:00
|
|
|
return strconv.FormatUint(uint64(c), 10)
|
2023-09-22 13:18:42 +00:00
|
|
|
}
|
|
|
|
|
2024-08-12 12:53:32 +00:00
|
|
|
func (c ChainID) ToUint() uint64 {
|
|
|
|
return uint64(c)
|
|
|
|
}
|
|
|
|
|
2023-11-23 21:11:18 +00:00
|
|
|
func (c ChainID) IsMainnet() bool {
|
|
|
|
switch uint64(c) {
|
|
|
|
case EthereumMainnet, OptimismMainnet, ArbitrumMainnet:
|
|
|
|
return true
|
2024-10-15 07:29:21 +00:00
|
|
|
case EthereumSepolia, OptimismSepolia, ArbitrumSepolia:
|
2023-11-23 21:11:18 +00:00
|
|
|
return false
|
|
|
|
case UnknownChainID:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-09-22 13:18:42 +00:00
|
|
|
func AllChainIDs() []ChainID {
|
|
|
|
return []ChainID{
|
|
|
|
ChainID(EthereumMainnet),
|
|
|
|
ChainID(EthereumSepolia),
|
|
|
|
ChainID(OptimismMainnet),
|
2023-11-16 20:46:01 +00:00
|
|
|
ChainID(OptimismSepolia),
|
2023-09-22 13:18:42 +00:00
|
|
|
ChainID(ArbitrumMainnet),
|
2023-10-10 12:30:12 +00:00
|
|
|
ChainID(ArbitrumSepolia),
|
2023-09-22 13:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-04 10:18:46 +00:00
|
|
|
var AverageBlockDurationForChain = map[ChainID]time.Duration{
|
|
|
|
ChainID(UnknownChainID): time.Duration(12000) * time.Millisecond,
|
|
|
|
ChainID(EthereumMainnet): time.Duration(12000) * time.Millisecond,
|
|
|
|
ChainID(OptimismMainnet): time.Duration(400) * time.Millisecond,
|
|
|
|
ChainID(ArbitrumMainnet): time.Duration(300) * time.Millisecond,
|
|
|
|
}
|