@obolnetwork/obol-sdk 2.11.3 → 2.11.5-rc.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 (143) hide show
  1. package/dist/cjs/src/index.js +17457 -382
  2. package/dist/cjs/src/index.js.map +1 -0
  3. package/dist/esm/src/index.js +17424 -361
  4. package/dist/esm/src/index.js.map +1 -0
  5. package/dist/types/src/abi/OVM.d.ts +103 -0
  6. package/dist/types/src/bytecodes.d.ts +3 -2
  7. package/dist/types/src/constants.d.ts +1 -2
  8. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  9. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  10. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  11. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  12. package/dist/types/src/utils.d.ts +2 -2
  13. package/dist/types/src/verification/common.d.ts +0 -2
  14. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  15. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  17. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  18. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  19. package/dist/types/test/client/methods.spec.d.ts +17 -0
  20. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  21. package/dist/types/tsup.config.d.ts +2 -0
  22. package/package.json +79 -54
  23. package/dist/cjs/package.json +0 -139
  24. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  25. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  26. package/dist/cjs/src/abi/Multicall3.js +0 -253
  27. package/dist/cjs/src/abi/OVMFactory.js +0 -620
  28. package/dist/cjs/src/abi/OWR.js +0 -304
  29. package/dist/cjs/src/abi/SplitMain.js +0 -929
  30. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  31. package/dist/cjs/src/ajv.js +0 -136
  32. package/dist/cjs/src/base.js +0 -42
  33. package/dist/cjs/src/bytecodes.js +0 -18
  34. package/dist/cjs/src/constants.js +0 -268
  35. package/dist/cjs/src/eoa/eoa.js +0 -132
  36. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  37. package/dist/cjs/src/errors.js +0 -11
  38. package/dist/cjs/src/exits/ethUtils.js +0 -57
  39. package/dist/cjs/src/exits/exit.js +0 -502
  40. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  41. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  42. package/dist/cjs/src/incentives/incentives.js +0 -119
  43. package/dist/cjs/src/schema.js +0 -352
  44. package/dist/cjs/src/services.js +0 -33
  45. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  46. package/dist/cjs/src/splits/splits.js +0 -366
  47. package/dist/cjs/src/types.js +0 -29
  48. package/dist/cjs/src/utils.js +0 -77
  49. package/dist/cjs/src/verification/common.js +0 -355
  50. package/dist/cjs/src/verification/signature-validator.js +0 -73
  51. package/dist/cjs/src/verification/sszTypes.js +0 -69
  52. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  53. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  54. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  55. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  56. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  57. package/dist/cjs/test/client/ajv.spec.js +0 -320
  58. package/dist/cjs/test/client/methods.spec.js +0 -418
  59. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  60. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  61. package/dist/cjs/test/exit/exit.spec.js +0 -399
  62. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  63. package/dist/cjs/test/fixtures.js +0 -896
  64. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  65. package/dist/cjs/test/splits/splits.spec.js +0 -402
  66. package/dist/esm/package.json +0 -139
  67. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  68. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  69. package/dist/esm/src/abi/Multicall3.js +0 -250
  70. package/dist/esm/src/abi/OVMFactory.js +0 -617
  71. package/dist/esm/src/abi/OWR.js +0 -301
  72. package/dist/esm/src/abi/SplitMain.js +0 -926
  73. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  74. package/dist/esm/src/ajv.js +0 -129
  75. package/dist/esm/src/base.js +0 -38
  76. package/dist/esm/src/bytecodes.js +0 -15
  77. package/dist/esm/src/constants.js +0 -234
  78. package/dist/esm/src/eoa/eoa.js +0 -128
  79. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  80. package/dist/esm/src/errors.js +0 -7
  81. package/dist/esm/src/exits/ethUtils.js +0 -52
  82. package/dist/esm/src/exits/exit.js +0 -475
  83. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  84. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  85. package/dist/esm/src/incentives/incentives.js +0 -115
  86. package/dist/esm/src/schema.js +0 -349
  87. package/dist/esm/src/services.js +0 -29
  88. package/dist/esm/src/splits/splitHelpers.js +0 -554
  89. package/dist/esm/src/splits/splits.js +0 -362
  90. package/dist/esm/src/types.js +0 -26
  91. package/dist/esm/src/utils.js +0 -68
  92. package/dist/esm/src/verification/common.js +0 -319
  93. package/dist/esm/src/verification/signature-validator.js +0 -64
  94. package/dist/esm/src/verification/sszTypes.js +0 -64
  95. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  96. package/dist/esm/src/verification/v1.10.0.js +0 -140
  97. package/dist/esm/src/verification/v1.6.0.js +0 -142
  98. package/dist/esm/src/verification/v1.7.0.js +0 -166
  99. package/dist/esm/src/verification/v1.8.0.js +0 -189
  100. package/dist/esm/test/client/ajv.spec.js +0 -318
  101. package/dist/esm/test/client/methods.spec.js +0 -393
  102. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  103. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  104. package/dist/esm/test/exit/exit.spec.js +0 -374
  105. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  106. package/dist/esm/test/fixtures.js +0 -893
  107. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  108. package/dist/esm/test/splits/splits.spec.js +0 -400
  109. package/dist/types/src/abi/OVMFactory.d.ts +0 -662
  110. package/src/abi/BatchDeposit.ts +0 -117
  111. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  112. package/src/abi/Multicall3.ts +0 -250
  113. package/src/abi/OVMFactory.ts +0 -617
  114. package/src/abi/OWR.ts +0 -302
  115. package/src/abi/SplitMain.ts +0 -927
  116. package/src/abi/splitV2FactoryAbi.ts +0 -417
  117. package/src/ajv.ts +0 -191
  118. package/src/base.ts +0 -54
  119. package/src/bytecodes.ts +0 -31
  120. package/src/constants.ts +0 -304
  121. package/src/eoa/eoa.ts +0 -153
  122. package/src/eoa/eoaHelpers.ts +0 -112
  123. package/src/errors.ts +0 -8
  124. package/src/exits/ethUtils.ts +0 -49
  125. package/src/exits/exit.ts +0 -661
  126. package/src/exits/verificationHelpers.ts +0 -110
  127. package/src/incentives/incentiveHelpers.ts +0 -55
  128. package/src/incentives/incentives.ts +0 -153
  129. package/src/index.ts +0 -614
  130. package/src/schema.ts +0 -376
  131. package/src/services.ts +0 -24
  132. package/src/splits/splitHelpers.ts +0 -1032
  133. package/src/splits/splits.ts +0 -504
  134. package/src/types.ts +0 -687
  135. package/src/utils.ts +0 -88
  136. package/src/verification/common.ts +0 -532
  137. package/src/verification/signature-validator.ts +0 -103
  138. package/src/verification/sszTypes.ts +0 -88
  139. package/src/verification/termsAndConditions.ts +0 -32
  140. package/src/verification/v1.10.0.ts +0 -245
  141. package/src/verification/v1.6.0.ts +0 -256
  142. package/src/verification/v1.7.0.ts +0 -309
  143. package/src/verification/v1.8.0.ts +0 -340
package/src/constants.ts DELETED
@@ -1,304 +0,0 @@
1
- import { type TypedMessage } from '@metamask/eth-sig-util';
2
- import { type TypedDataDomain } from 'ethers';
3
- import pjson from '../package.json';
4
- import { type ChainConfig, FORK_MAPPING } from './types';
5
- import {
6
- HOLESKY_MULTICALL3_BYTECODE,
7
- HOLESKY_OWR_FACTORY_BYTECODE,
8
- HOLESKY_SPLITMAIN_BYTECODE,
9
- HOODI_MULTICALL3_BYTECODE,
10
- HOODI_OVM_FACTORY_BYTECODE,
11
- HOODI_OWR_FACTORY_BYTECODE,
12
- HOODI_SPLIT_V2_FACTORY_BYTECODE,
13
- HOODI_SPLITMAIN_BYTECODE,
14
- HOODI_WAREHOUSE_BYTECODE,
15
- MAINNET_MULTICALL3_BYTECODE,
16
- MAINNET_OVM_FACTORY_BYTECODE,
17
- MAINNET_OWR_FACTORY_BYTECODE,
18
- MAINNET_SPLIT_V2_FACTORY_BYTECODE,
19
- MAINNET_SPLITMAIN_BYTECODE,
20
- MAINNET_WAREHOUSE_BYTECODE,
21
- } from './bytecodes';
22
-
23
- import * as dotenv from 'dotenv';
24
- dotenv.config();
25
-
26
- export const CONFLICT_ERROR_MSG = 'Conflict';
27
-
28
- export const EIP712_DOMAIN_NAME = 'Obol';
29
- export const EIP712_DOMAIN_VERSION = '1';
30
- export const CreatorConfigHashSigningTypes = {
31
- CreatorConfigHash: [{ name: 'creator_config_hash', type: 'string' }],
32
- };
33
- export const TermsAndConditionsSigningTypes = {
34
- TermsAndConditions: [
35
- { name: 'terms_and_conditions_hash', type: 'string' },
36
- { name: 'version', type: 'uint256' },
37
- ],
38
- };
39
-
40
- const EIP712Domain = [
41
- { name: 'name', type: 'string' },
42
- { name: 'version', type: 'string' },
43
- { name: 'chainId', type: 'uint256' },
44
- ];
45
-
46
- export const Domain = (chainId?: number): TypedDataDomain => {
47
- const typeDataDomain: any = {
48
- name: EIP712_DOMAIN_NAME,
49
- version: EIP712_DOMAIN_VERSION,
50
- };
51
- if (chainId) {
52
- typeDataDomain.chainId = chainId;
53
- }
54
- return typeDataDomain;
55
- };
56
-
57
- export const CreatorTypedMessage = {
58
- EIP712Domain,
59
- ...CreatorConfigHashSigningTypes,
60
- };
61
-
62
- // A conflict once updateDefinition is merged
63
- export const EnrSigningTypes = {
64
- ENR: [{ name: 'enr', type: 'string' }],
65
- };
66
-
67
- export const OperatorConfigHashSigningTypes = {
68
- OperatorConfigHash: [{ name: 'operator_config_hash', type: 'string' }],
69
- };
70
-
71
- export const OperatorTypedMessage = {
72
- EIP712Domain,
73
- ...OperatorConfigHashSigningTypes,
74
- };
75
-
76
- export const ENRTypedMessage = {
77
- EIP712Domain,
78
- ...EnrSigningTypes,
79
- };
80
-
81
- export const signCreatorConfigHashPayload = (
82
- payload: { creator_config_hash: string },
83
- chainId: number,
84
- ): TypedMessage<typeof CreatorTypedMessage> => {
85
- return {
86
- types: CreatorTypedMessage,
87
- primaryType: 'CreatorConfigHash',
88
- domain: {
89
- name: EIP712_DOMAIN_NAME,
90
- version: EIP712_DOMAIN_VERSION,
91
- chainId,
92
- },
93
- message: payload,
94
- };
95
- };
96
-
97
- export const signOperatorConfigHashPayload = (
98
- payload: { operator_config_hash: string },
99
- chainId: number,
100
- ): TypedMessage<typeof OperatorTypedMessage> => {
101
- return {
102
- types: OperatorTypedMessage,
103
- primaryType: 'OperatorConfigHash',
104
- domain: {
105
- name: EIP712_DOMAIN_NAME,
106
- version: EIP712_DOMAIN_VERSION,
107
- chainId,
108
- },
109
- message: payload,
110
- };
111
- };
112
-
113
- export const signEnrPayload = (
114
- payload: { enr: string },
115
- chainId: number,
116
- ): TypedMessage<typeof ENRTypedMessage> => {
117
- return {
118
- types: ENRTypedMessage,
119
- primaryType: 'ENR',
120
- domain: {
121
- name: EIP712_DOMAIN_NAME,
122
- version: EIP712_DOMAIN_VERSION,
123
- chainId,
124
- },
125
- message: payload,
126
- };
127
- };
128
-
129
- export const DKG_ALGORITHM = 'default';
130
-
131
- export const CONFIG_VERSION = 'v1.10.0';
132
-
133
- export const SDK_VERSION = pjson.version;
134
-
135
- export const DOMAIN_APPLICATION_BUILDER = '00000001';
136
- export const DOMAIN_DEPOSIT = '03000000';
137
- export const GENESIS_VALIDATOR_ROOT =
138
- '0000000000000000000000000000000000000000000000000000000000000000';
139
-
140
- // Flow used to create definition
141
- export enum DefinitionFlow {
142
- Group = 'LP-Group',
143
- Solo = 'LP-Solo',
144
- Charon = 'Charon-Command',
145
- }
146
-
147
- export const DEFAULT_BASE_URL = 'https://api.obol.tech';
148
- export const DEFAULT_BASE_VERSION = 'v1';
149
- export const DEFAULT_CHAIN_ID = 17000;
150
-
151
- export const ETHER_TO_GWEI = 10 ** 9;
152
-
153
- export const TERMS_AND_CONDITIONS_VERSION = 1;
154
- export const TERMS_AND_CONDITIONS_URL =
155
- TERMS_AND_CONDITIONS_VERSION === 1
156
- ? 'https://obol.org/terms.pdf'
157
- : `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf`;
158
- export const TERMS_AND_CONDITIONS_HASH =
159
- '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';
160
-
161
- export const AVAILABLE_SPLITTER_CHAINS = {
162
- [FORK_MAPPING['0x00000000']]: true, // Mainnet
163
- [FORK_MAPPING['0x01017000']]: true, // Holesky
164
- [FORK_MAPPING['0x10000910']]: true, // Hoodi
165
- } as const;
166
-
167
- export const isChainSupportedForSplitters = (chainId: number): boolean => {
168
- return chainId in AVAILABLE_SPLITTER_CHAINS;
169
- };
170
-
171
- export const CHAIN_CONFIGURATION: Record<number, ChainConfig> = {
172
- [FORK_MAPPING['0x00000000']]: {
173
- SPLITMAIN_CONTRACT: {
174
- address: '0x2ed6c4B5dA6378c7897AC67Ba9e43102Feb694EE',
175
- bytecode: MAINNET_SPLITMAIN_BYTECODE,
176
- },
177
- MULTICALL3_CONTRACT: {
178
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
179
- bytecode: MAINNET_MULTICALL3_BYTECODE,
180
- },
181
- OWR_FACTORY_CONTRACT: {
182
- address: '0x119acd7844cbdd5fc09b1c6a4408f490c8f7f522',
183
- bytecode: MAINNET_OWR_FACTORY_BYTECODE,
184
- },
185
- RETROACTIVE_FUNDING_CONTRACT: {
186
- address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
187
- bytecode: '',
188
- },
189
- // OVM and SplitV2 Contract Addresses
190
- OVM_FACTORY_CONTRACT: {
191
- address: '0xdfe2d8b26806583cf03b3cb623b0752f8670e93e',
192
- bytecode: MAINNET_OVM_FACTORY_BYTECODE,
193
- },
194
- WAREHOUSE_CONTRACT: {
195
- address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
196
- bytecode: MAINNET_WAREHOUSE_BYTECODE,
197
- },
198
- SPLIT_V2_FACTORY_CONTRACT: {
199
- address: '0x5cbA88D55Cec83caD5A105Ad40C8c9aF20bE21d1',
200
- bytecode: MAINNET_SPLIT_V2_FACTORY_BYTECODE,
201
- },
202
- EOA_WITHDRAWAL_CONTRACT: {
203
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
204
- },
205
- BATCH_DEPOSIT_CONTRACT: {
206
- address: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
207
- },
208
- },
209
- [FORK_MAPPING['0x01017000']]: {
210
- SPLITMAIN_CONTRACT: {
211
- address: '0xfC8a305728051367797DADE6Aa0344E0987f5286',
212
- bytecode: HOLESKY_SPLITMAIN_BYTECODE,
213
- },
214
- MULTICALL3_CONTRACT: {
215
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
216
- bytecode: HOLESKY_MULTICALL3_BYTECODE,
217
- },
218
- OWR_FACTORY_CONTRACT: {
219
- address: '0xc0961353fcc43a99e3041db07ac646720e116256',
220
- bytecode: HOLESKY_OWR_FACTORY_BYTECODE,
221
- },
222
- RETROACTIVE_FUNDING_CONTRACT: {
223
- address: '0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5',
224
- bytecode: '',
225
- },
226
- EOA_WITHDRAWAL_CONTRACT: {
227
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
228
- },
229
- },
230
- [FORK_MAPPING['0x10000910']]: {
231
- SPLITMAIN_CONTRACT: {
232
- address: '0xc05ae267291705ac16F75283572294ed2a91CBc7',
233
- bytecode: HOODI_SPLITMAIN_BYTECODE,
234
- },
235
- MULTICALL3_CONTRACT: {
236
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
237
- bytecode: HOODI_MULTICALL3_BYTECODE,
238
- },
239
- OWR_FACTORY_CONTRACT: {
240
- address: '0x9ff0c649d0bf5fe7efa4d72e94bed7302ed5c8d7',
241
- bytecode: HOODI_OWR_FACTORY_BYTECODE,
242
- },
243
- RETROACTIVE_FUNDING_CONTRACT: {
244
- address: '0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5',
245
- bytecode: '',
246
- },
247
- // OVM and SplitV2 Contract Addresses
248
- OVM_FACTORY_CONTRACT: {
249
- address: '0x6F13d929C783a420AE4DC71C1dcc27A02038Ed09',
250
- bytecode: HOODI_OVM_FACTORY_BYTECODE,
251
- },
252
- WAREHOUSE_CONTRACT: {
253
- address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
254
- bytecode: HOODI_WAREHOUSE_BYTECODE,
255
- },
256
- SPLIT_V2_FACTORY_CONTRACT: {
257
- address: '0x5cbA88D55Cec83caD5A105Ad40C8c9aF20bE21d1',
258
- bytecode: HOODI_SPLIT_V2_FACTORY_BYTECODE,
259
- },
260
- EOA_WITHDRAWAL_CONTRACT: {
261
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
262
- },
263
- BATCH_DEPOSIT_CONTRACT: {
264
- address: '0x4c9506eE2fCd962f03022D9d8ebf6f7828abEfaf',
265
- },
266
- },
267
- };
268
-
269
- export const DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = 1;
270
-
271
- export const DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = 0.1;
272
-
273
- // OVM and SplitV2 Default Constants
274
- export const SPLITS_V2_SALT =
275
- '0x2fa740d39f3b04b2c7ef4e9f9e1a6e38f4c72c1a91d8595d5d31a3adf17c6b12';
276
- export const PRINCIPAL_THRESHOLD = 16;
277
-
278
- export const OBOL_SDK_EMAIL = 'sdk@dvlabs.tech';
279
-
280
- export const PROVIDER_MAP: Record<number, string> = {
281
- 1: `${process.env.RPC_MAINNET}`, // Mainnet
282
- 17000: `${process.env.RPC_HOLESKY}`, // Holesky
283
- 11155111: `${process.env.RPC_SEPOLIA}`, // Sepolia
284
- 100: `${process.env.RPC_GNOSIS}`, // Gnosis
285
- 560048: `${process.env.RPC_HOODI}`, // Hoodi
286
- };
287
-
288
- /**
289
- * Maps base fork versions to their corresponding Capella fork versions.
290
- * Example: Mainnet Capella fork version.
291
- */
292
- export const CAPELLA_FORK_MAPPING: Record<string, string> = {
293
- '0x00000000': '0x03000000', // Mainnet
294
- '0x00001020': '0x03001020', // Goerli
295
- '0x00000064': '0x03000064', // Gnosis
296
- '0x90000069': '0x90000072', // Sepolia
297
- '0x01017000': '0x04017000', // Holesky
298
- '0x10000910': '0x40000910', // Hoodi
299
- };
300
-
301
- export const CHAIN_PUBLIC_RPC_URL: Record<number, string> = {
302
- 1: 'https://ethereum-rpc.publicnode.com', // Mainnet
303
- 560048: 'https://ethereum-hoodi-rpc.publicnode.com', // Hoodi
304
- };
package/src/eoa/eoa.ts DELETED
@@ -1,153 +0,0 @@
1
- import {
2
- submitEOAWithdrawalRequest,
3
- submitEOABatchDeposit,
4
- } from './eoaHelpers';
5
- import { validatePayload } from '../ajv';
6
- import { eoaWithdrawalPayloadSchema, eoaDepositPayloadSchema } from '../schema';
7
- import { CHAIN_CONFIGURATION } from '../constants';
8
- import {
9
- type ProviderType,
10
- type SignerType,
11
- type EOAWithdrawalPayload,
12
- type EOADepositPayload,
13
- } from '../types';
14
-
15
- /**
16
- * EOA can be used for managing EOA (Externally Owned Account) operations like withdrawals.
17
- * @class
18
- * @internal Access it through Client.eoa.
19
- * @example
20
- * const obolClient = new Client(config);
21
- * await obolClient.eoa.requestWithdrawal(EOAWithdrawalPayload);
22
- */
23
- export class EOA {
24
- private readonly signer: SignerType | undefined;
25
- public readonly chainId: number;
26
- public readonly provider: ProviderType | undefined | null;
27
-
28
- constructor(
29
- signer: SignerType | undefined,
30
- chainId: number,
31
- provider: ProviderType | undefined | null,
32
- ) {
33
- this.signer = signer;
34
- this.chainId = chainId;
35
- this.provider = provider;
36
- }
37
-
38
- /**
39
- * Requests withdrawal from an EOA contract.
40
- *
41
- * This method allows requesting withdrawal of validator funds.
42
- * The withdrawal request includes validator public key and corresponding withdrawal amount.
43
- *
44
- * @remarks
45
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
46
- * and not pushed to version control.
47
- *
48
- * @param {EOAWithdrawalPayload} payload - Data needed to request withdrawal
49
- * @returns {Promise<{txHash: string}>} Transaction hash of the withdrawal request
50
- * @throws Will throw an error if the signer is not provided or the request fails
51
- *
52
- * An example of how to use requestWithdrawal:
53
- * ```typescript
54
- * const result = await client.eoa.requestWithdrawal({
55
- * pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
56
- * allocation: 32, // 32 ETH
57
- * requiredFee: '1' // in wei
58
- * });
59
- * console.log('Withdrawal requested:', result.txHash);
60
- * ```
61
- */
62
- async requestWithdrawal(
63
- payload: EOAWithdrawalPayload,
64
- ): Promise<{ txHash: string | null }> {
65
- if (!this.signer) {
66
- throw new Error('Signer is required in requestWithdrawal');
67
- }
68
-
69
- if (!this.provider) {
70
- throw new Error('Provider is required in requestWithdrawal');
71
- }
72
-
73
- const chainConfig = CHAIN_CONFIGURATION[this.chainId];
74
- if (!chainConfig?.EOA_WITHDRAWAL_CONTRACT?.address) {
75
- throw new Error(
76
- `EOA withdrawal contract is not configured for chain ${this.chainId}`,
77
- );
78
- }
79
-
80
- const validatedPayload = validatePayload<EOAWithdrawalPayload>(
81
- payload,
82
- eoaWithdrawalPayloadSchema,
83
- );
84
-
85
- const withdrawalAddress = await this.signer.getAddress();
86
-
87
- return await submitEOAWithdrawalRequest({
88
- pubkey: validatedPayload.pubkey,
89
- allocation: validatedPayload.allocation,
90
- withdrawalAddress,
91
- withdrawalContractAddress: chainConfig.EOA_WITHDRAWAL_CONTRACT.address,
92
- requiredFee: validatedPayload.requiredFee,
93
- chainId: this.chainId,
94
- signer: this.signer,
95
- provider: this.provider,
96
- });
97
- }
98
-
99
- /**
100
- * Deposits to batch deposit contract.
101
- *
102
- * This method allows depositing multiple validators to the Ethereum beacon chain
103
- * using the Pier Two batch deposit contract for gas efficiency.
104
- * Each deposit includes validator public key, withdrawal credentials, signature, and amount.
105
- *
106
- * @remarks
107
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
108
- * and not pushed to version control.
109
- *
110
- * **⚠️ Gas Limit:** Due to EVM constraints, it is recommended to deposit in batches of up to 500 at a time.
111
- *
112
- * @param {EOADepositPayload} payload - Data needed to deposit to batch contract
113
- * @returns {Promise<{txHashes: string[]}>} Array of transaction hashes for all batches
114
- * @throws Will throw an error if the signer is not provided, contract is not configured, or the deposit fails
115
- *
116
- * An example of how to use deposit:
117
- * ```typescript
118
- * const result = await client.eoa.deposit({
119
- * deposits: [{
120
- * pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
121
- * withdrawal_credentials: '0x1234567890123456789012345678901234567890',
122
- * deposit_data_root: '0x1234567890123456789012345678901234567890123456789012345678901234',
123
- * signature: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
124
- * amount: '32000000000000000000' // 32 ETH in wei
125
- * }]
126
- * });
127
- * console.log('Deposits completed:', result.txHashes);
128
- * ```
129
- */
130
- async deposit(payload: EOADepositPayload): Promise<{ txHashes: string[] }> {
131
- if (!this.signer) {
132
- throw new Error('Signer is required in deposit');
133
- }
134
-
135
- const chainConfig = CHAIN_CONFIGURATION[this.chainId];
136
- if (!chainConfig?.BATCH_DEPOSIT_CONTRACT?.address) {
137
- throw new Error(
138
- `Batch deposit contract is not configured for chain ${this.chainId}`,
139
- );
140
- }
141
-
142
- const validatedPayload = validatePayload<EOADepositPayload>(
143
- payload,
144
- eoaDepositPayloadSchema,
145
- );
146
-
147
- return await submitEOABatchDeposit({
148
- deposits: validatedPayload.deposits,
149
- batchDepositContractAddress: chainConfig.BATCH_DEPOSIT_CONTRACT.address,
150
- signer: this.signer,
151
- });
152
- }
153
- }
@@ -1,112 +0,0 @@
1
- import { ETHER_TO_GWEI } from '../constants';
2
- import { type SignerType, type ProviderType } from '../types';
3
- import { Contract } from 'ethers';
4
- import { BatchDepositContract } from '../abi/BatchDeposit';
5
-
6
- /**
7
- * Helper function to submit withdrawal request for EOA
8
- */
9
- export async function submitEOAWithdrawalRequest({
10
- pubkey,
11
- allocation,
12
- withdrawalAddress,
13
- withdrawalContractAddress,
14
- requiredFee,
15
- chainId,
16
- signer,
17
- provider,
18
- }: {
19
- pubkey: string;
20
- allocation: number;
21
- withdrawalAddress: string;
22
- withdrawalContractAddress: string;
23
- requiredFee: string;
24
- chainId: number;
25
- signer: SignerType;
26
- provider: ProviderType;
27
- }): Promise<{ txHash: string | null }> {
28
- if (!withdrawalAddress) throw new Error('No withdrawal address provided');
29
- if (!allocation) throw new Error('No allocation provided');
30
-
31
- const amountInGwei = BigInt(Math.floor(Number(allocation) * ETHER_TO_GWEI));
32
- const data = `0x${pubkey.slice(2)}${amountInGwei.toString(16).padStart(16, '0')}`;
33
-
34
- const tx = await signer.sendTransaction({
35
- to: withdrawalContractAddress,
36
- chainId,
37
- value: BigInt(requiredFee),
38
- data: data as `0x${string}`,
39
- });
40
-
41
- const receipt = await tx.wait();
42
- if (!receipt) return { txHash: null };
43
- return { txHash: receipt.hash };
44
- }
45
-
46
- /**
47
- * Helper function to submit batch deposit request for EOA
48
- */
49
- export async function submitEOABatchDeposit({
50
- deposits,
51
- batchDepositContractAddress,
52
- signer,
53
- }: {
54
- deposits: Array<{
55
- pubkey: string;
56
- withdrawal_credentials: string;
57
- signature: string;
58
- deposit_data_root: string;
59
- amount: string;
60
- }>;
61
- batchDepositContractAddress: string;
62
- signer: SignerType;
63
- }): Promise<{ txHashes: string[] }> {
64
- if (!deposits || deposits.length === 0) {
65
- throw new Error('No deposits provided');
66
- }
67
-
68
- // Create contract instance
69
- const batchDepositContract = new Contract(
70
- batchDepositContractAddress,
71
- BatchDepositContract.abi,
72
- signer,
73
- );
74
-
75
- const BATCH_SIZE = 500;
76
- const txHashes: string[] = [];
77
-
78
- try {
79
- // Process deposits in batches of 500
80
- for (let i = 0; i < deposits.length; i += BATCH_SIZE) {
81
- const batchDeposits = deposits.slice(i, i + BATCH_SIZE);
82
-
83
- // Calculate total value needed for this batch
84
- const totalValue = batchDeposits.reduce(
85
- (sum, deposit) => sum + BigInt(deposit.amount),
86
- BigInt(0),
87
- );
88
-
89
- // Prepare deposit data for this batch
90
- const depositData = batchDeposits.map(deposit => ({
91
- pubKey: deposit.pubkey,
92
- withdrawalCredentials: deposit.withdrawal_credentials,
93
- signature: deposit.signature,
94
- depositDataRoot: deposit.deposit_data_root,
95
- amount: BigInt(deposit.amount),
96
- }));
97
-
98
- // Execute batch deposit for this batch
99
- const tx = await batchDepositContract.batchDeposit(depositData, {
100
- value: totalValue,
101
- });
102
-
103
- const receipt = await tx.wait();
104
- if (receipt?.hash) {
105
- txHashes.push(receipt.hash);
106
- }
107
- }
108
- return { txHashes };
109
- } catch (error: any) {
110
- throw new Error("Failed to submit batch deposit'}");
111
- }
112
- }
package/src/errors.ts DELETED
@@ -1,8 +0,0 @@
1
- export class ConflictError extends Error {
2
- name = 'ConflictError';
3
-
4
- constructor() {
5
- super('This Cluster has been already posted.');
6
- Object.setPrototypeOf(this, ConflictError.prototype);
7
- }
8
- }
@@ -1,49 +0,0 @@
1
- import { CAPELLA_FORK_MAPPING } from '../constants';
2
-
3
- /**
4
- * Retrieves the Capella fork version for a given base fork version.
5
- * @param fork_version - The base fork version string (e.g., '0x00000000' for mainnet).
6
- * @returns A promise that resolves to the Capella fork version string, or null if not found.
7
- */
8
- export async function getCapellaFork(
9
- fork_version: string,
10
- ): Promise<string | null> {
11
- // Ensure the CAPELLA_FORK_MAPPING uses the base fork_version as key
12
- if (CAPELLA_FORK_MAPPING[fork_version]) {
13
- return CAPELLA_FORK_MAPPING[fork_version];
14
- }
15
- return null;
16
- }
17
-
18
- /**
19
- * Fetches the genesis validators root from a beacon node.
20
- * @param beaconNodeApiUrl - The base URL of the beacon node API (e.g., http://localhost:5052).
21
- * @returns A promise that resolves to the genesis_validators_root string, or null on error.
22
- * @throws Will throw an error if the network corresponding to the fork_version is not supported or if the HTTP request fails.
23
- */
24
- export async function getGenesisValidatorsRoot(
25
- beaconNodeApiUrl: string,
26
- ): Promise<string | null> {
27
- const genesisEndpoint = `${beaconNodeApiUrl}/eth/v1/beacon/genesis`;
28
-
29
- try {
30
- const response = await fetch(genesisEndpoint, {
31
- method: 'GET',
32
- });
33
-
34
- const json = await response.json();
35
-
36
- if (json.data?.genesis_validators_root) {
37
- return json.data.genesis_validators_root;
38
- }
39
- console.error('Invalid response structure from genesis endpoint', json);
40
- return null;
41
- } catch (e: any) {
42
- console.error(
43
- `Error fetching genesis validators root from ${genesisEndpoint}:`,
44
- e,
45
- );
46
- const errorMessage = e instanceof Error ? e.message : String(e);
47
- throw new Error(`Failed to fetch genesis validators root: ${errorMessage}`);
48
- }
49
- }