decred.org/dcrdex@v1.0.5/dex/networks/polygon/genesis_config.go (about)

     1  package polygon
     2  
     3  import (
     4  	"embed"
     5  	"encoding/json"
     6  	"fmt"
     7  	"math/big"
     8  
     9  	"decred.org/dcrdex/dex"
    10  	"github.com/ethereum/go-ethereum/common"
    11  	"github.com/ethereum/go-ethereum/core"
    12  	"github.com/ethereum/go-ethereum/params"
    13  )
    14  
    15  // The allocs directory contains the genesis allocations for the various polygon
    16  // networks. See: https://github.com/maticnetwork/bor/tree/develop/core/allocs.
    17  
    18  //go:embed allocs
    19  var allocs embed.FS
    20  
    21  // These are the chain IDs of the various polygon network.
    22  const (
    23  	MainnetChainID = 137
    24  	TestnetChainID = 80001 // Mumbai
    25  	SimnetChainID  = 90001
    26  )
    27  
    28  var (
    29  	// ChainIDs is a map of the network name to it's chain ID.
    30  	ChainIDs = map[dex.Network]int64{
    31  		dex.Mainnet: MainnetChainID,
    32  		dex.Testnet: TestnetChainID,
    33  		dex.Simnet:  SimnetChainID,
    34  	}
    35  
    36  	// mumbaiChainConfig contains the chain parameters to run a node on the
    37  	// Mumbai test network. This is a copy of
    38  	// https://github.com/maticnetwork/bor/blob/891ec7fef619cac0a796e3e29d5b2d4c095bdd9b/params/config.go#L336.
    39  	mumbaiChainConfig = &params.ChainConfig{
    40  		ChainID:             big.NewInt(80001),
    41  		HomesteadBlock:      big.NewInt(0),
    42  		DAOForkBlock:        nil,
    43  		DAOForkSupport:      true,
    44  		EIP150Block:         big.NewInt(0),
    45  		EIP155Block:         big.NewInt(0),
    46  		EIP158Block:         big.NewInt(0),
    47  		ByzantiumBlock:      big.NewInt(0),
    48  		ConstantinopleBlock: big.NewInt(0),
    49  		PetersburgBlock:     big.NewInt(0),
    50  		IstanbulBlock:       big.NewInt(2722000),
    51  		MuirGlacierBlock:    big.NewInt(2722000),
    52  		BerlinBlock:         big.NewInt(13996000),
    53  		LondonBlock:         big.NewInt(22640000),
    54  	}
    55  
    56  	// Called BorTestChainConfig in maticnetwork/bor/params/config.go
    57  	AmoyChainConfig = &params.ChainConfig{
    58  		ChainID:             big.NewInt(80002),
    59  		HomesteadBlock:      big.NewInt(0),
    60  		DAOForkBlock:        nil,
    61  		DAOForkSupport:      true,
    62  		EIP150Block:         big.NewInt(0),
    63  		EIP155Block:         big.NewInt(0),
    64  		EIP158Block:         big.NewInt(0),
    65  		ByzantiumBlock:      big.NewInt(0),
    66  		ConstantinopleBlock: big.NewInt(0),
    67  		PetersburgBlock:     big.NewInt(0),
    68  		IstanbulBlock:       big.NewInt(0),
    69  		MuirGlacierBlock:    big.NewInt(0),
    70  		BerlinBlock:         big.NewInt(0),
    71  		LondonBlock:         big.NewInt(73100),
    72  		// ShanghaiBlock:       big.NewInt(73100),
    73  		// CancunBlock:         big.NewInt(5423600),
    74  	}
    75  
    76  	// BorMainnetChainConfig is the genesis block of the Bor Mainnet network.
    77  	// This is a copy of the genesis block from
    78  	// https://github.com/maticnetwork/bor/blob/891ec7fef619cac0a796e3e29d5b2d4c095bdd9b/params/config.go#L395.
    79  	BorMainnetChainConfig = &params.ChainConfig{
    80  		ChainID:             big.NewInt(137),
    81  		HomesteadBlock:      big.NewInt(0),
    82  		DAOForkBlock:        nil,
    83  		DAOForkSupport:      true,
    84  		EIP150Block:         big.NewInt(0),
    85  		EIP155Block:         big.NewInt(0),
    86  		EIP158Block:         big.NewInt(0),
    87  		ByzantiumBlock:      big.NewInt(0),
    88  		ConstantinopleBlock: big.NewInt(0),
    89  		PetersburgBlock:     big.NewInt(0),
    90  		IstanbulBlock:       big.NewInt(3395000),
    91  		MuirGlacierBlock:    big.NewInt(3395000),
    92  		BerlinBlock:         big.NewInt(14750000),
    93  		LondonBlock:         big.NewInt(23850000),
    94  	}
    95  )
    96  
    97  // DefaultAmoyGenesisBlock returns the Mumbai network genesis block. See:
    98  // https://github.com/maticnetwork/bor/blob/46f93b1f9415c8778d6e5ea2f3fad440f4572ba5/core/genesis.go#L616
    99  func DefaultAmoyGenesisBlock() *core.Genesis {
   100  	return &core.Genesis{
   101  		Config:     AmoyChainConfig,
   102  		Nonce:      0,
   103  		Timestamp:  1700225065,
   104  		GasLimit:   10000000,
   105  		Difficulty: big.NewInt(1),
   106  		Mixhash:    common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
   107  		Coinbase:   common.HexToAddress("0x0000000000000000000000000000000000000000"),
   108  		Alloc:      readPrealloc("allocs/amoy.json"),
   109  	}
   110  }
   111  
   112  // defaultMumbaiGenesisBlock returns the Mumbai network genesis block. See:
   113  // https://github.com/maticnetwork/bor/blob/891ec7fef619cac0a796e3e29d5b2d4c095bdd9b/core/genesis.go#L495
   114  func defaultMumbaiGenesisBlock() *core.Genesis {
   115  	return &core.Genesis{
   116  		Config:     mumbaiChainConfig,
   117  		Nonce:      0,
   118  		Timestamp:  1558348305,
   119  		GasLimit:   10000000,
   120  		Difficulty: big.NewInt(1),
   121  		Mixhash:    common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
   122  		Coinbase:   common.HexToAddress("0x0000000000000000000000000000000000000000"),
   123  		Alloc:      readPrealloc("allocs/mumbai.json"),
   124  	}
   125  }
   126  
   127  // DefaultBorMainnet returns the Bor Mainnet network gensis block. See:
   128  // https://github.com/maticnetwork/bor/blob/891ec7fef619cac0a796e3e29d5b2d4c095bdd9b/core/genesis.go#L509
   129  func DefaultBorMainnetGenesisBlock() *core.Genesis {
   130  	return &core.Genesis{
   131  		Config:     BorMainnetChainConfig,
   132  		Nonce:      0,
   133  		Timestamp:  1590824836,
   134  		GasLimit:   10000000,
   135  		Difficulty: big.NewInt(1),
   136  		Mixhash:    common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
   137  		Coinbase:   common.HexToAddress("0x0000000000000000000000000000000000000000"),
   138  		Alloc:      readPrealloc("allocs/bor_mainnet.json"),
   139  	}
   140  }
   141  
   142  func readPrealloc(filename string) core.GenesisAlloc {
   143  	f, err := allocs.Open(filename)
   144  	if err != nil {
   145  		panic(fmt.Sprintf("Could not open genesis preallocation for %s: %v", filename, err))
   146  	}
   147  	defer f.Close()
   148  	decoder := json.NewDecoder(f)
   149  	ga := make(core.GenesisAlloc)
   150  	err = decoder.Decode(&ga)
   151  	if err != nil {
   152  		panic(fmt.Sprintf("Could not parse genesis preallocation for %s: %v", filename, err))
   153  	}
   154  	return ga
   155  }