status-go/services/wallet/common/const.go

102 lines
2.4 KiB
Go
Raw Normal View History

2023-04-18 14:33:59 +00:00
package common
import (
"strconv"
"time"
ethCommon "github.com/ethereum/go-ethereum/common"
)
2023-09-04 10:18:46 +00:00
type MultiTransactionIDType int64
const (
NoMultiTransactionID = MultiTransactionIDType(0)
chore!: router code organization improvements It's a breaking change due to errors' changes, the list of mapped old error codes: - `"WR-001"` is now `"WRR-001"` - `"WR-002"` is now `"WRR-002"` - `"WR-003"` is now `"WRR-003"` - `"WR-004"` is now `"WRR-004"` - `"WR-005"` is now `"WRR-005"` - `"WR-006"` is now `"WRR-006"` - `"WR-007"` is now `"WRR-007"` - `"WR-008"` is now `"WRR-008"` - `"WR-009"` is now `"WRR-009"` - `"WR-010"` is now `"WRR-010"` - `"WR-011"` is now `"WRR-011"` - `"WR-012"` is now `"WRR-012"` - `"WR-013"` is now `"WRR-013"` - `"WR-014"` is now `"WRR-014"` - `"WR-015"` is now `"WRR-015"` - `"WR-019"` is now `"WRR-016"` - `"WR-020"` is now `"WRR-017"` - `"WR-021"` is now `"WRR-018"` - `"WR-025"` is now `"WRR-019"` - `"WR-016"` is now `"WR-001"` - `"WR-017"` is now `"WR-002"` - `"WR-018"` is now `"WR-003"` - `"WR-022"` is now `"WR-004"` - `"WR-023"` is now `"WR-005"` - `"WR-024"` is now `"WR-006"` - `"WR-026"` is now `"WR-007"` - `"WR-027"` is now `"WR-008"` Other changes: - `RouteInputParams` type moved to `requests` package and code updated accordingly - `SuggestedFees` type moved to a new `fees` package and code updated accordingly - `SendType` type moved to a new `sendtype` package and code updated accordingly - the following functions moved to `common` package - `ArrayContainsElement` - `ArraysWithSameElements` - `SameSingleChainTransfer` - `CopyMapGeneric` - `GweiToEth` - `WeiToGwei` - the following consts moved to `common` package - `HexAddressLength` - `SupportedNetworks` - `SupportedTestNetworks`
2024-08-28 11:17:59 +00:00
HexAddressLength = 42
)
2023-04-18 14:33:59 +00:00
type ChainID uint64
const (
UnknownChainID uint64 = 0
EthereumMainnet uint64 = 1
EthereumGoerli uint64 = 5
EthereumSepolia uint64 = 11155111
OptimismMainnet uint64 = 10
OptimismGoerli uint64 = 420
OptimismSepolia uint64 = 11155420
ArbitrumMainnet uint64 = 42161
ArbitrumGoerli uint64 = 421613
ArbitrumSepolia uint64 = 421614
BinanceChainID uint64 = 56 // obsolete?
BinanceTestChainID uint64 = 97 // obsolete?
2023-04-18 14:33:59 +00:00
)
2023-09-04 10:18:46 +00:00
var (
ZeroAddress = ethCommon.HexToAddress("0x0000000000000000000000000000000000000000")
chore!: router code organization improvements It's a breaking change due to errors' changes, the list of mapped old error codes: - `"WR-001"` is now `"WRR-001"` - `"WR-002"` is now `"WRR-002"` - `"WR-003"` is now `"WRR-003"` - `"WR-004"` is now `"WRR-004"` - `"WR-005"` is now `"WRR-005"` - `"WR-006"` is now `"WRR-006"` - `"WR-007"` is now `"WRR-007"` - `"WR-008"` is now `"WRR-008"` - `"WR-009"` is now `"WRR-009"` - `"WR-010"` is now `"WRR-010"` - `"WR-011"` is now `"WRR-011"` - `"WR-012"` is now `"WRR-012"` - `"WR-013"` is now `"WRR-013"` - `"WR-014"` is now `"WRR-014"` - `"WR-015"` is now `"WRR-015"` - `"WR-019"` is now `"WRR-016"` - `"WR-020"` is now `"WRR-017"` - `"WR-021"` is now `"WRR-018"` - `"WR-025"` is now `"WRR-019"` - `"WR-016"` is now `"WR-001"` - `"WR-017"` is now `"WR-002"` - `"WR-018"` is now `"WR-003"` - `"WR-022"` is now `"WR-004"` - `"WR-023"` is now `"WR-005"` - `"WR-024"` is now `"WR-006"` - `"WR-026"` is now `"WR-007"` - `"WR-027"` is now `"WR-008"` Other changes: - `RouteInputParams` type moved to `requests` package and code updated accordingly - `SuggestedFees` type moved to a new `fees` package and code updated accordingly - `SendType` type moved to a new `sendtype` package and code updated accordingly - the following functions moved to `common` package - `ArrayContainsElement` - `ArraysWithSameElements` - `SameSingleChainTransfer` - `CopyMapGeneric` - `GweiToEth` - `WeiToGwei` - the following consts moved to `common` package - `HexAddressLength` - `SupportedNetworks` - `SupportedTestNetworks`
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,
}
)
type ContractType byte
const (
ContractTypeUnknown ContractType = iota
ContractTypeERC20
ContractTypeERC721
ContractTypeERC1155
)
func (c ChainID) String() string {
return strconv.FormatUint(uint64(c), 10)
}
func (c ChainID) ToUint() uint64 {
return uint64(c)
}
func (c ChainID) IsMainnet() bool {
switch uint64(c) {
case EthereumMainnet, OptimismMainnet, ArbitrumMainnet:
return true
case EthereumGoerli, EthereumSepolia, OptimismGoerli, OptimismSepolia, ArbitrumGoerli, ArbitrumSepolia:
return false
case UnknownChainID:
return false
}
return false
}
func AllChainIDs() []ChainID {
return []ChainID{
ChainID(EthereumMainnet),
ChainID(EthereumGoerli),
ChainID(EthereumSepolia),
ChainID(OptimismMainnet),
ChainID(OptimismGoerli),
2023-11-16 20:46:01 +00:00
ChainID(OptimismSepolia),
ChainID(ArbitrumMainnet),
ChainID(ArbitrumGoerli),
2023-10-10 12:30:12 +00:00
ChainID(ArbitrumSepolia),
}
}
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(EthereumGoerli): time.Duration(12000) * time.Millisecond,
ChainID(OptimismMainnet): time.Duration(400) * time.Millisecond,
ChainID(OptimismGoerli): time.Duration(2000) * time.Millisecond,
ChainID(ArbitrumMainnet): time.Duration(300) * time.Millisecond,
ChainID(ArbitrumGoerli): time.Duration(1500) * time.Millisecond,
}