@feelyourprotocol/common 8141.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +409 -0
  3. package/dist/cjs/chains.d.ts +6 -0
  4. package/dist/cjs/chains.d.ts.map +1 -0
  5. package/dist/cjs/chains.js +637 -0
  6. package/dist/cjs/chains.js.map +1 -0
  7. package/dist/cjs/common.d.ts +318 -0
  8. package/dist/cjs/common.d.ts.map +1 -0
  9. package/dist/cjs/common.js +789 -0
  10. package/dist/cjs/common.js.map +1 -0
  11. package/dist/cjs/constructors.d.ts +27 -0
  12. package/dist/cjs/constructors.d.ts.map +1 -0
  13. package/dist/cjs/constructors.js +53 -0
  14. package/dist/cjs/constructors.js.map +1 -0
  15. package/dist/cjs/crc.d.ts +8 -0
  16. package/dist/cjs/crc.d.ts.map +1 -0
  17. package/dist/cjs/crc.js +63 -0
  18. package/dist/cjs/crc.js.map +1 -0
  19. package/dist/cjs/eips.d.ts +3 -0
  20. package/dist/cjs/eips.d.ts.map +1 -0
  21. package/dist/cjs/eips.js +589 -0
  22. package/dist/cjs/eips.js.map +1 -0
  23. package/dist/cjs/enums.d.ts +65 -0
  24. package/dist/cjs/enums.d.ts.map +1 -0
  25. package/dist/cjs/enums.js +80 -0
  26. package/dist/cjs/enums.js.map +1 -0
  27. package/dist/cjs/gethGenesis.d.ts +145 -0
  28. package/dist/cjs/gethGenesis.d.ts.map +1 -0
  29. package/dist/cjs/gethGenesis.js +26 -0
  30. package/dist/cjs/gethGenesis.js.map +1 -0
  31. package/dist/cjs/hardforks.d.ts +3 -0
  32. package/dist/cjs/hardforks.d.ts.map +1 -0
  33. package/dist/cjs/hardforks.js +207 -0
  34. package/dist/cjs/hardforks.js.map +1 -0
  35. package/dist/cjs/index.d.ts +9 -0
  36. package/dist/cjs/index.d.ts.map +1 -0
  37. package/dist/cjs/index.js +25 -0
  38. package/dist/cjs/index.js.map +1 -0
  39. package/dist/cjs/interfaces.d.ts +132 -0
  40. package/dist/cjs/interfaces.d.ts.map +1 -0
  41. package/dist/cjs/interfaces.js +13 -0
  42. package/dist/cjs/interfaces.js.map +1 -0
  43. package/dist/cjs/package.json +3 -0
  44. package/dist/cjs/types.d.ts +167 -0
  45. package/dist/cjs/types.d.ts.map +1 -0
  46. package/dist/cjs/types.js +3 -0
  47. package/dist/cjs/types.js.map +1 -0
  48. package/dist/cjs/utils.d.ts +60 -0
  49. package/dist/cjs/utils.d.ts.map +1 -0
  50. package/dist/cjs/utils.js +263 -0
  51. package/dist/cjs/utils.js.map +1 -0
  52. package/dist/esm/chains.d.ts +6 -0
  53. package/dist/esm/chains.d.ts.map +1 -0
  54. package/dist/esm/chains.js +634 -0
  55. package/dist/esm/chains.js.map +1 -0
  56. package/dist/esm/common.d.ts +318 -0
  57. package/dist/esm/common.d.ts.map +1 -0
  58. package/dist/esm/common.js +785 -0
  59. package/dist/esm/common.js.map +1 -0
  60. package/dist/esm/constructors.d.ts +27 -0
  61. package/dist/esm/constructors.d.ts.map +1 -0
  62. package/dist/esm/constructors.js +49 -0
  63. package/dist/esm/constructors.js.map +1 -0
  64. package/dist/esm/crc.d.ts +8 -0
  65. package/dist/esm/crc.d.ts.map +1 -0
  66. package/dist/esm/crc.js +59 -0
  67. package/dist/esm/crc.js.map +1 -0
  68. package/dist/esm/eips.d.ts +3 -0
  69. package/dist/esm/eips.d.ts.map +1 -0
  70. package/dist/esm/eips.js +586 -0
  71. package/dist/esm/eips.js.map +1 -0
  72. package/dist/esm/enums.d.ts +65 -0
  73. package/dist/esm/enums.d.ts.map +1 -0
  74. package/dist/esm/enums.js +77 -0
  75. package/dist/esm/enums.js.map +1 -0
  76. package/dist/esm/gethGenesis.d.ts +145 -0
  77. package/dist/esm/gethGenesis.d.ts.map +1 -0
  78. package/dist/esm/gethGenesis.js +23 -0
  79. package/dist/esm/gethGenesis.js.map +1 -0
  80. package/dist/esm/hardforks.d.ts +3 -0
  81. package/dist/esm/hardforks.d.ts.map +1 -0
  82. package/dist/esm/hardforks.js +204 -0
  83. package/dist/esm/hardforks.js.map +1 -0
  84. package/dist/esm/index.d.ts +9 -0
  85. package/dist/esm/index.d.ts.map +1 -0
  86. package/dist/esm/index.js +9 -0
  87. package/dist/esm/index.js.map +1 -0
  88. package/dist/esm/interfaces.d.ts +132 -0
  89. package/dist/esm/interfaces.d.ts.map +1 -0
  90. package/dist/esm/interfaces.js +10 -0
  91. package/dist/esm/interfaces.js.map +1 -0
  92. package/dist/esm/package.json +3 -0
  93. package/dist/esm/types.d.ts +167 -0
  94. package/dist/esm/types.d.ts.map +1 -0
  95. package/dist/esm/types.js +2 -0
  96. package/dist/esm/types.js.map +1 -0
  97. package/dist/esm/utils.d.ts +60 -0
  98. package/dist/esm/utils.d.ts.map +1 -0
  99. package/dist/esm/utils.js +258 -0
  100. package/dist/esm/utils.js.map +1 -0
  101. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  102. package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
  103. package/package.json +77 -0
  104. package/src/chains.ts +638 -0
  105. package/src/common.ts +913 -0
  106. package/src/constructors.ts +60 -0
  107. package/src/crc.ts +63 -0
  108. package/src/eips.ts +588 -0
  109. package/src/enums.ts +104 -0
  110. package/src/gethGenesis.ts +175 -0
  111. package/src/hardforks.ts +205 -0
  112. package/src/index.ts +8 -0
  113. package/src/interfaces.ts +191 -0
  114. package/src/types.ts +193 -0
  115. package/src/utils.ts +324 -0
package/src/enums.ts ADDED
@@ -0,0 +1,104 @@
1
+ import { BIGINT_0, hexToBytes } from '@feelyourprotocol/util'
2
+
3
+ export type Chain = (typeof Chain)[keyof typeof Chain]
4
+
5
+ export const Chain = {
6
+ Mainnet: 1,
7
+ Sepolia: 11155111,
8
+ Holesky: 17000,
9
+ Hoodi: 560048,
10
+ } as const
11
+
12
+ // Reverse mapping: from numeric value back to the key name
13
+ export const ChainNameFromNumber: { [key in Chain]: string } = Object.entries(Chain).reduce(
14
+ (acc, [key, value]) => {
15
+ acc[value as Chain] = key
16
+ return acc
17
+ },
18
+ {} as { [key in Chain]: string },
19
+ )
20
+
21
+ /**
22
+ * Genesis state meta info which is decoupled from common's genesis params
23
+ */
24
+ type GenesisState = {
25
+ name: string
26
+ /* blockNumber that can be used to update and track the regenesis marker */
27
+ blockNumber: bigint
28
+ /* stateRoot of the chain at the blockNumber */
29
+ stateRoot: Uint8Array
30
+ }
31
+
32
+ // Having this info as record will force typescript to make sure no chain is missed
33
+ /**
34
+ * GenesisState info about well known ethereum chains
35
+ */
36
+ export const ChainGenesis: Record<Chain, GenesisState> = {
37
+ [Chain.Mainnet]: {
38
+ name: 'mainnet',
39
+ blockNumber: BIGINT_0,
40
+ stateRoot: hexToBytes('0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544'),
41
+ },
42
+ [Chain.Sepolia]: {
43
+ name: 'sepolia',
44
+ blockNumber: BIGINT_0,
45
+ stateRoot: hexToBytes('0x5eb6e371a698b8d68f665192350ffcecbbbf322916f4b51bd79bb6887da3f494'),
46
+ },
47
+ [Chain.Holesky]: {
48
+ name: 'holesky',
49
+ blockNumber: BIGINT_0,
50
+ stateRoot: hexToBytes('0x69d8c9d72f6fa4ad42d4702b433707212f90db395eb54dc20bc85de253788783'),
51
+ },
52
+ [Chain.Hoodi]: {
53
+ name: 'hoodi',
54
+ blockNumber: BIGINT_0,
55
+ stateRoot: hexToBytes('0xda87d7f5f91c51508791bbcbd4aa5baf04917830b86985eeb9ad3d5bfb657576'),
56
+ },
57
+ }
58
+
59
+ export type Hardfork = (typeof Hardfork)[keyof typeof Hardfork]
60
+
61
+ export const Hardfork = {
62
+ Chainstart: 'chainstart',
63
+ Homestead: 'homestead',
64
+ Dao: 'dao',
65
+ TangerineWhistle: 'tangerineWhistle',
66
+ SpuriousDragon: 'spuriousDragon',
67
+ Byzantium: 'byzantium',
68
+ Constantinople: 'constantinople',
69
+ Petersburg: 'petersburg',
70
+ Istanbul: 'istanbul',
71
+ MuirGlacier: 'muirGlacier',
72
+ Berlin: 'berlin',
73
+ London: 'london',
74
+ ArrowGlacier: 'arrowGlacier',
75
+ GrayGlacier: 'grayGlacier',
76
+ MergeNetsplitBlock: 'mergeNetsplitBlock',
77
+ Paris: 'paris',
78
+ Shanghai: 'shanghai',
79
+ Cancun: 'cancun',
80
+ Prague: 'prague',
81
+ Osaka: 'osaka',
82
+ Bpo1: 'bpo1',
83
+ Bpo2: 'bpo2',
84
+ Bpo3: 'bpo3',
85
+ Bpo4: 'bpo4',
86
+ Bpo5: 'bpo5',
87
+ Amsterdam: 'amsterdam',
88
+ } as const
89
+
90
+ export type ConsensusType = (typeof ConsensusType)[keyof typeof ConsensusType]
91
+
92
+ export const ConsensusType = {
93
+ ProofOfStake: 'pos',
94
+ ProofOfWork: 'pow',
95
+ ProofOfAuthority: 'poa',
96
+ } as const
97
+
98
+ export type ConsensusAlgorithm = (typeof ConsensusAlgorithm)[keyof typeof ConsensusAlgorithm]
99
+
100
+ export const ConsensusAlgorithm = {
101
+ Ethash: 'ethash',
102
+ Clique: 'clique',
103
+ Casper: 'casper',
104
+ } as const
@@ -0,0 +1,175 @@
1
+ import { type PrefixedHexString, addHexPrefix, bigIntToHex, isHexString } from '@feelyourprotocol/util'
2
+
3
+ /**
4
+ * Interface for Geth Genesis Config
5
+ */
6
+ export interface GethGenesisConfig {
7
+ chainId: number
8
+ depositContractAddress?: string
9
+ homesteadBlock?: number
10
+ daoForkBlock?: number
11
+ daoForkSupport?: boolean
12
+ eip150Block?: number
13
+ eip150Hash?: string
14
+ eip155Block?: number
15
+ eip158Block?: number
16
+ byzantiumBlock?: number
17
+ constantinopleBlock?: number
18
+ petersburgBlock?: number
19
+ istanbulBlock?: number
20
+ muirGlacierBlock?: number
21
+ berlinBlock?: number
22
+ londonBlock?: number
23
+ mergeForkBlock?: number
24
+ cancunBlock?: number
25
+ arrowGlacierBlock?: number
26
+ grayGlacierBlock?: number
27
+ mergeNetsplitBlock?: number
28
+ shanghaiTime?: number
29
+ cancunTime?: number
30
+ pragueTime?: number
31
+ terminalTotalDifficulty?: number
32
+ terminalTotalDifficultyPassed?: boolean
33
+ ethash?: {}
34
+ clique?: {
35
+ period?: number
36
+ epoch?: number
37
+ blockperiodseconds?: number
38
+ epochlength?: number
39
+ }
40
+ trustedCheckpoint?: {
41
+ sectionIndex: number
42
+ sectionHead: string
43
+ chtRoot: string
44
+ bloomRoot: string
45
+ }
46
+ trustedCheckpointOracle?: {
47
+ address: string
48
+ signers: string[]
49
+ threshold: number
50
+ }
51
+ blobSchedule?: GethGenesisBlobSchedule
52
+ proofInBlocks?: boolean
53
+ }
54
+
55
+ /**
56
+ * Interface for account allocation in Geth Genesis
57
+ */
58
+ export interface GethGenesisAlloc {
59
+ [address: string]: {
60
+ balance: string
61
+ code?: string
62
+ storage?: { [key: string]: string }
63
+ nonce?: string
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Interface for blob schedule in Geth Genesis (EIP-7840)
69
+ */
70
+ export interface GethGenesisBlobSchedule {
71
+ [fork: string]: {
72
+ target?: number
73
+ max?: number
74
+ baseFeeUpdateFraction?: number
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Interface for Geth Genesis object
80
+ */
81
+ export interface GethGenesis {
82
+ config: GethGenesisConfig
83
+ name?: string
84
+ excessBlobGas?: string
85
+ requestsHash?: string
86
+ nonce: string
87
+ timestamp: string
88
+ extraData?: string
89
+ gasLimit: PrefixedHexString
90
+ difficulty?: PrefixedHexString
91
+ mixHash?: PrefixedHexString
92
+ coinbase?: PrefixedHexString
93
+ alloc: GethGenesisAlloc
94
+ number?: PrefixedHexString
95
+ gasUsed?: PrefixedHexString
96
+ parentHash?: PrefixedHexString
97
+ baseFeePerGas?: PrefixedHexString | number | null
98
+ }
99
+
100
+ /**
101
+ * Type for the options passed to createCommonFromGethGenesis
102
+ */
103
+ export interface CreateCommonFromGethGenesisOpts {
104
+ chain?: string
105
+ genesisHash?: string
106
+ mergeForkIdPostMerge?: boolean
107
+ }
108
+
109
+ export type StoragePair = [key: PrefixedHexString, value: PrefixedHexString]
110
+
111
+ export type AccountState = [
112
+ balance: PrefixedHexString,
113
+ code?: PrefixedHexString,
114
+ storage?: Array<StoragePair>,
115
+ nonce?: PrefixedHexString,
116
+ ]
117
+
118
+ /**
119
+ * If you are using a custom chain {@link Common}, pass the genesis state.
120
+ *
121
+ * Pattern 1 (with genesis state see {@link GenesisState} for format):
122
+ *
123
+ * ```javascript
124
+ * {
125
+ * '0x0...01': '0x100', // For EoA
126
+ * }
127
+ * ```
128
+ *
129
+ * Pattern 2 (with complex genesis state, containing contract accounts and storage).
130
+ * Note that in {@link AccountState} there are two
131
+ * accepted types. This allows to easily insert accounts in the genesis state:
132
+ *
133
+ * A complex genesis state with Contract and EoA states would have the following format:
134
+ *
135
+ * ```javascript
136
+ * {
137
+ * '0x0...01': '0x100', // For EoA
138
+ * '0x0...02': ['0x1', '0xRUNTIME_BYTECODE', [[storageKey1, storageValue1], [storageKey2, storageValue2]]] // For contracts
139
+ * }
140
+ * ```
141
+ */
142
+ export interface GenesisState {
143
+ [key: PrefixedHexString]: PrefixedHexString | AccountState
144
+ }
145
+
146
+ /**
147
+ * Parses the geth genesis state into Blockchain {@link GenesisState}
148
+ * @param gethGenesis GethGenesis object
149
+ * @returns Parsed {@link GenesisState}
150
+ */
151
+ export function parseGethGenesisState(gethGenesis: GethGenesis): GenesisState {
152
+ const state: GenesisState = {}
153
+
154
+ for (const address of Object.keys(gethGenesis.alloc)) {
155
+ const {
156
+ balance: rawBalance,
157
+ code: rawCode,
158
+ nonce: rawNonce,
159
+ storage: rawStorage,
160
+ } = gethGenesis.alloc[address]
161
+ // create a map with lowercase for easy lookups
162
+ const prefixedAddress = addHexPrefix(address.toLowerCase())
163
+ const balance = isHexString(rawBalance) ? rawBalance : bigIntToHex(BigInt(rawBalance))
164
+ const code = rawCode !== undefined ? addHexPrefix(rawCode) : undefined
165
+ const storage =
166
+ rawStorage !== undefined
167
+ ? (Object.entries(rawStorage).map((storagePair) =>
168
+ storagePair.map(addHexPrefix),
169
+ ) as StoragePair[])
170
+ : undefined
171
+ const nonce = rawNonce !== undefined ? addHexPrefix(rawNonce) : undefined
172
+ state[prefixedAddress] = [balance, code, storage, nonce]
173
+ }
174
+ return state
175
+ }
@@ -0,0 +1,205 @@
1
+ import type { HardforksDict } from './types.ts'
2
+
3
+ export const hardforksDict: HardforksDict = {
4
+ /**
5
+ * Description: Start of the Ethereum main chain
6
+ * URL : -
7
+ * Status : Final
8
+ */
9
+ chainstart: {
10
+ eips: [1],
11
+ },
12
+ /**
13
+ * Description: Homestead hardfork with protocol and network changes
14
+ * URL : https://eips.ethereum.org/EIPS/eip-606
15
+ * Status : Final
16
+ */
17
+ homestead: {
18
+ eips: [606],
19
+ },
20
+ /**
21
+ * Description: DAO rescue hardfork
22
+ * URL : https://eips.ethereum.org/EIPS/eip-779
23
+ * Status : Final
24
+ */
25
+ dao: {
26
+ eips: [],
27
+ },
28
+ /**
29
+ * Description: Hardfork with gas cost changes for IO-heavy operations
30
+ * URL : https://eips.ethereum.org/EIPS/eip-608
31
+ * Status : Final
32
+ */
33
+ tangerineWhistle: {
34
+ eips: [608],
35
+ },
36
+ /**
37
+ * Description: HF with EIPs for simple replay attack protection, EXP cost increase, state trie clearing, contract code size limit
38
+ * URL : https://eips.ethereum.org/EIPS/eip-607
39
+ * Status : Final
40
+ */
41
+ spuriousDragon: {
42
+ eips: [607],
43
+ },
44
+ /**
45
+ * Description: Hardfork with new precompiles, instructions and other protocol changes
46
+ * URL : https://eips.ethereum.org/EIPS/eip-609
47
+ * Status : Final
48
+ */
49
+ byzantium: {
50
+ eips: [609],
51
+ },
52
+ /**
53
+ * Description: Postponed hardfork including EIP-1283 (SSTORE gas metering changes)
54
+ * URL : https://eips.ethereum.org/EIPS/eip-1013
55
+ * Status : Final
56
+ */
57
+ constantinople: {
58
+ eips: [1013],
59
+ },
60
+ /**
61
+ * Description: Aka constantinopleFix, removes EIP-1283, activate together with or after constantinople
62
+ * URL : https://eips.ethereum.org/EIPS/eip-1716
63
+ * Status : Final
64
+ */
65
+ petersburg: {
66
+ eips: [1716],
67
+ },
68
+ /**
69
+ * Description: HF targeted for December 2019 following the Constantinople/Petersburg HF
70
+ * URL : https://eips.ethereum.org/EIPS/eip-1679
71
+ * Status : Final
72
+ */
73
+ istanbul: {
74
+ eips: [1679],
75
+ },
76
+ /**
77
+ * Description: HF to delay the difficulty bomb
78
+ * URL : https://eips.ethereum.org/EIPS/eip-2384
79
+ * Status : Final
80
+ */
81
+ muirGlacier: {
82
+ eips: [2384],
83
+ },
84
+ /**
85
+ * Description: HF targeted for July 2020 following the Muir Glacier HF
86
+ * URL : https://eips.ethereum.org/EIPS/eip-2070
87
+ * Status : Final
88
+ */
89
+ berlin: {
90
+ eips: [2565, 2929, 2718, 2930],
91
+ },
92
+ /**
93
+ * Description: HF targeted for July 2021 following the Berlin fork
94
+ * URL : https://github.com/ethereum/eth1.0-specs/blob/master/network-upgrades/mainnet-upgrades/london.md
95
+ * Status : Final
96
+ */
97
+ london: {
98
+ eips: [1559, 3198, 3529, 3541],
99
+ },
100
+ /**
101
+ * Description: HF to delay the difficulty bomb
102
+ * URL : https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md
103
+ * Status : Final
104
+ */
105
+ arrowGlacier: {
106
+ eips: [4345],
107
+ },
108
+ /**
109
+ * Description: Delaying the difficulty bomb to Mid September 2022
110
+ * URL : https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md
111
+ * Status : Final
112
+ */
113
+ grayGlacier: {
114
+ eips: [5133],
115
+ },
116
+ /**
117
+ * Description: Hardfork to upgrade the consensus mechanism to Proof-of-Stake
118
+ * URL : https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/merge.md
119
+ * Status : Final
120
+ */
121
+ paris: {
122
+ consensus: {
123
+ type: 'pos',
124
+ algorithm: 'casper',
125
+ casper: {},
126
+ },
127
+ eips: [3675, 4399],
128
+ },
129
+ /**
130
+ * Description: Pre-merge hardfork to fork off non-upgraded clients
131
+ * URL : https://eips.ethereum.org/EIPS/eip-3675
132
+ * Status : Final
133
+ */
134
+ mergeNetsplitBlock: {
135
+ eips: [],
136
+ },
137
+ /**
138
+ * Description: Next feature hardfork after the merge hardfork having withdrawals, warm coinbase, push0, limit/meter initcode
139
+ * URL : https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
140
+ * Status : Final
141
+ */
142
+ shanghai: {
143
+ eips: [3651, 3855, 3860, 4895],
144
+ },
145
+ /**
146
+ * Description: Next feature hardfork after shanghai, includes proto-danksharding EIP 4844 blobs,
147
+ * transient storage opcodes, parent beacon block root availability in EVM, selfdestruct only in
148
+ * same transaction, and blob base fee opcode
149
+ * URL : https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/cancun.md
150
+ * Status : Final
151
+ */
152
+ cancun: {
153
+ eips: [1153, 4844, 4788, 5656, 6780, 7516],
154
+ },
155
+ /**
156
+ * Description: Next feature hardfork after cancun including EIP-7702 account abstraction + other EIPs
157
+ * URL : https://eips.ethereum.org/EIPS/eip-7600
158
+ * Status : Final
159
+ */
160
+ prague: {
161
+ eips: [2537, 2935, 6110, 7002, 7251, 7623, 7685, 7691, 7702],
162
+ },
163
+ /**
164
+ * Description: Next feature hardfork after prague (headliner: PeerDAS)
165
+ * URL : https://eips.ethereum.org/EIPS/eip-7607
166
+ * Status : Final
167
+ */
168
+ osaka: {
169
+ eips: [7594, 7823, 7825, 7883, 7892, 7939, 7951, 7918],
170
+ },
171
+ /**
172
+ * Description: HF to update the blob target, max and updateFraction (see also EIP-7892)
173
+ * URL : TBD
174
+ * Status : Final
175
+ */
176
+ bpo1: {
177
+ eips: [],
178
+ params: {
179
+ target: 10,
180
+ max: 15,
181
+ blobGasPriceUpdateFraction: 8346193,
182
+ },
183
+ },
184
+ /**
185
+ * Description: HF to update the blob target, max and updateFraction (see also EIP-7892)
186
+ * URL : TBD
187
+ * Status : Final
188
+ */
189
+ bpo2: {
190
+ eips: [],
191
+ params: {
192
+ target: 14,
193
+ max: 21,
194
+ blobGasPriceUpdateFraction: 11684671,
195
+ },
196
+ },
197
+ /**
198
+ * Description: Feature hardfork after osaka (headliner: EIP-7928 Block Level Access Lists (BAL))
199
+ * URL : https://eips.ethereum.org/EIPS/eip-7773
200
+ * Status : Draft (implementation incomplete + spec still moving!)
201
+ */
202
+ amsterdam: {
203
+ eips: [7708, 7843, 7778, 7928, 8024],
204
+ },
205
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './chains.ts'
2
+ export * from './common.ts'
3
+ export * from './constructors.ts'
4
+ export * from './enums.ts'
5
+ export * from './gethGenesis.ts'
6
+ export * from './interfaces.ts'
7
+ export * from './types.ts'
8
+ export * from './utils.ts'
@@ -0,0 +1,191 @@
1
+ /**
2
+ * External Interfaces for other EthereumJS libraries
3
+ */
4
+
5
+ import type {
6
+ Account,
7
+ Address,
8
+ BinaryTreeExecutionWitness,
9
+ PrefixedHexString,
10
+ } from '@feelyourprotocol/util'
11
+
12
+ export interface StorageDump {
13
+ [key: string]: string
14
+ }
15
+
16
+ /**
17
+ * Object that can contain a set of storage keys associated with an account.
18
+ */
19
+ export interface StorageRange {
20
+ /**
21
+ * A dictionary where the keys are hashed storage keys, and the values are
22
+ * objects containing the preimage of the hashed key (in `key`) and the
23
+ * storage key (in `value`). Currently, there is no way to retrieve preimages,
24
+ * so they are always `null`.
25
+ */
26
+ storage: {
27
+ [key: string]: {
28
+ key: string | null
29
+ value: string
30
+ }
31
+ }
32
+ /**
33
+ * The next (hashed) storage key after the greatest storage key
34
+ * contained in `storage`.
35
+ */
36
+ nextKey: string | null
37
+ }
38
+
39
+ export type AccountFields = Partial<
40
+ Pick<Account, 'nonce' | 'balance' | 'storageRoot' | 'codeHash' | 'codeSize'>
41
+ >
42
+
43
+ export type StorageProof = {
44
+ key: PrefixedHexString
45
+ proof: PrefixedHexString[]
46
+ value: PrefixedHexString
47
+ }
48
+
49
+ export type Proof = {
50
+ address: PrefixedHexString
51
+ balance: PrefixedHexString
52
+ codeHash: PrefixedHexString
53
+ nonce: PrefixedHexString
54
+ storageHash: PrefixedHexString
55
+ accountProof: PrefixedHexString[]
56
+ storageProof: StorageProof[]
57
+ }
58
+
59
+ /**
60
+ * Binary tree related
61
+ *
62
+ * Experimental (do not implement)
63
+ */
64
+ export type AccessEventFlags = {
65
+ stemRead: boolean
66
+ stemWrite: boolean
67
+ chunkRead: boolean
68
+ chunkWrite: boolean
69
+ chunkFill: boolean
70
+ }
71
+
72
+ export type BinaryTreeAccessedStateType =
73
+ (typeof BinaryTreeAccessedStateType)[keyof typeof BinaryTreeAccessedStateType]
74
+
75
+ export const BinaryTreeAccessedStateType = {
76
+ BasicData: 'basicData',
77
+ CodeHash: 'codeHash',
78
+ Code: 'code',
79
+ Storage: 'storage',
80
+ } as const
81
+
82
+ export type RawBinaryTreeAccessedState = {
83
+ address: Address
84
+ treeIndex: number | bigint
85
+ chunkIndex: number
86
+ chunkKey: PrefixedHexString
87
+ }
88
+
89
+ export type BinaryTreeAccessedState =
90
+ | {
91
+ type: Exclude<
92
+ BinaryTreeAccessedStateType,
93
+ typeof BinaryTreeAccessedStateType.Code | typeof BinaryTreeAccessedStateType.Storage
94
+ >
95
+ }
96
+ | { type: typeof BinaryTreeAccessedStateType.Code; codeOffset: number }
97
+ | { type: typeof BinaryTreeAccessedStateType.Storage; slot: bigint }
98
+
99
+ export type BinaryTreeAccessedStateWithAddress = BinaryTreeAccessedState & {
100
+ address: Address
101
+ chunkKey: PrefixedHexString
102
+ }
103
+ export interface BinaryTreeAccessWitnessInterface {
104
+ accesses(): Generator<BinaryTreeAccessedStateWithAddress>
105
+ rawAccesses(): Generator<RawBinaryTreeAccessedState>
106
+ debugWitnessCost(): void
107
+ readAccountBasicData(address: Address): bigint
108
+ writeAccountBasicData(address: Address): bigint
109
+ readAccountCodeHash(address: Address): bigint
110
+ writeAccountCodeHash(address: Address): bigint
111
+ readAccountHeader(address: Address): bigint
112
+ writeAccountHeader(address: Address): bigint
113
+ readAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint
114
+ writeAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint
115
+ readAccountStorage(contract: Address, storageSlot: bigint): bigint
116
+ writeAccountStorage(contract: Address, storageSlot: bigint): bigint
117
+ merge(accessWitness: BinaryTreeAccessWitnessInterface): void
118
+ commit(): void
119
+ revert(): void
120
+ }
121
+
122
+ /*
123
+ * Generic StateManager interface corresponding with the @feelyourprotocol/statemanager package
124
+ *
125
+ */
126
+ export interface StateManagerInterface {
127
+ /*
128
+ * Core Access Functionality
129
+ */
130
+ // Account methods
131
+ getAccount(address: Address): Promise<Account | undefined>
132
+ putAccount(address: Address, account?: Account): Promise<void>
133
+ deleteAccount(address: Address): Promise<void>
134
+ modifyAccountFields(address: Address, accountFields: AccountFields): Promise<void>
135
+
136
+ // Code methods
137
+ putCode(address: Address, value: Uint8Array): Promise<void>
138
+ getCode(address: Address): Promise<Uint8Array>
139
+ getCodeSize(address: Address): Promise<number>
140
+
141
+ // Storage methods
142
+ getStorage(address: Address, key: Uint8Array): Promise<Uint8Array>
143
+ putStorage(address: Address, key: Uint8Array, value: Uint8Array): Promise<void>
144
+ clearStorage(address: Address): Promise<void>
145
+
146
+ /*
147
+ * Checkpointing Functionality
148
+ */
149
+ checkpoint(): Promise<void>
150
+ commit(): Promise<void>
151
+ revert(): Promise<void>
152
+
153
+ /*
154
+ * State Root Functionality
155
+ */
156
+ getStateRoot(): Promise<Uint8Array>
157
+ setStateRoot(stateRoot: Uint8Array, clearCache?: boolean): Promise<void>
158
+ hasStateRoot(root: Uint8Array): Promise<boolean> // only used in client
159
+
160
+ /*
161
+ * Extra Functionality
162
+ *
163
+ * Optional non-essential methods, these methods should always be guarded
164
+ * on usage (check for existence)
165
+ */
166
+ // Client RPC
167
+ dumpStorage?(address: Address): Promise<StorageDump>
168
+ dumpStorageRange?(address: Address, startKey: bigint, limit: number): Promise<StorageRange>
169
+
170
+ /*
171
+ * EVM/VM Specific Functionality
172
+ */
173
+ originalStorageCache: {
174
+ get(address: Address, key: Uint8Array): Promise<Uint8Array>
175
+ clear(): void
176
+ }
177
+ generateCanonicalGenesis?(initState: any): Promise<void> // TODO make input more typesafe
178
+ initBinaryTreeExecutionWitness?(
179
+ blockNum: bigint,
180
+ executionWitness?: BinaryTreeExecutionWitness | null,
181
+ ): void
182
+ verifyBinaryTreePostState?(accessWitness: BinaryTreeAccessWitnessInterface): Promise<boolean>
183
+ checkChunkWitnessPresent?(contract: Address, programCounter: number): Promise<boolean>
184
+ getAppliedKey?(address: Uint8Array): Uint8Array // only for preimages
185
+
186
+ /*
187
+ * Utility
188
+ */
189
+ clearCaches(): void
190
+ shallowCopy(downlevelCaches?: boolean): StateManagerInterface
191
+ }