@obolnetwork/obol-sdk 2.11.4 → 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 (140) 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/constants.d.ts +1 -2
  6. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  7. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  8. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  9. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  10. package/dist/types/src/utils.d.ts +2 -2
  11. package/dist/types/src/verification/common.d.ts +0 -2
  12. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  13. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  14. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  15. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  17. package/dist/types/test/client/methods.spec.d.ts +17 -0
  18. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  19. package/dist/types/tsup.config.d.ts +2 -0
  20. package/package.json +79 -54
  21. package/dist/cjs/package.json +0 -139
  22. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  23. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  24. package/dist/cjs/src/abi/Multicall3.js +0 -253
  25. package/dist/cjs/src/abi/OVM.js +0 -627
  26. package/dist/cjs/src/abi/OWR.js +0 -304
  27. package/dist/cjs/src/abi/SplitMain.js +0 -929
  28. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  29. package/dist/cjs/src/ajv.js +0 -136
  30. package/dist/cjs/src/base.js +0 -42
  31. package/dist/cjs/src/bytecodes.js +0 -19
  32. package/dist/cjs/src/constants.js +0 -272
  33. package/dist/cjs/src/eoa/eoa.js +0 -132
  34. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  35. package/dist/cjs/src/errors.js +0 -11
  36. package/dist/cjs/src/exits/ethUtils.js +0 -57
  37. package/dist/cjs/src/exits/exit.js +0 -502
  38. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  39. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  40. package/dist/cjs/src/incentives/incentives.js +0 -119
  41. package/dist/cjs/src/schema.js +0 -352
  42. package/dist/cjs/src/services.js +0 -33
  43. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  44. package/dist/cjs/src/splits/splits.js +0 -366
  45. package/dist/cjs/src/types.js +0 -29
  46. package/dist/cjs/src/utils.js +0 -77
  47. package/dist/cjs/src/verification/common.js +0 -355
  48. package/dist/cjs/src/verification/signature-validator.js +0 -73
  49. package/dist/cjs/src/verification/sszTypes.js +0 -69
  50. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  51. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  52. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  53. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  54. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  55. package/dist/cjs/test/client/ajv.spec.js +0 -320
  56. package/dist/cjs/test/client/methods.spec.js +0 -418
  57. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  58. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  59. package/dist/cjs/test/exit/exit.spec.js +0 -399
  60. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  61. package/dist/cjs/test/fixtures.js +0 -896
  62. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  63. package/dist/cjs/test/splits/splits.spec.js +0 -402
  64. package/dist/esm/package.json +0 -139
  65. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  66. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  67. package/dist/esm/src/abi/Multicall3.js +0 -250
  68. package/dist/esm/src/abi/OVM.js +0 -624
  69. package/dist/esm/src/abi/OWR.js +0 -301
  70. package/dist/esm/src/abi/SplitMain.js +0 -926
  71. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  72. package/dist/esm/src/ajv.js +0 -129
  73. package/dist/esm/src/base.js +0 -38
  74. package/dist/esm/src/bytecodes.js +0 -16
  75. package/dist/esm/src/constants.js +0 -238
  76. package/dist/esm/src/eoa/eoa.js +0 -128
  77. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  78. package/dist/esm/src/errors.js +0 -7
  79. package/dist/esm/src/exits/ethUtils.js +0 -52
  80. package/dist/esm/src/exits/exit.js +0 -475
  81. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  82. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  83. package/dist/esm/src/incentives/incentives.js +0 -115
  84. package/dist/esm/src/schema.js +0 -349
  85. package/dist/esm/src/services.js +0 -29
  86. package/dist/esm/src/splits/splitHelpers.js +0 -554
  87. package/dist/esm/src/splits/splits.js +0 -362
  88. package/dist/esm/src/types.js +0 -26
  89. package/dist/esm/src/utils.js +0 -68
  90. package/dist/esm/src/verification/common.js +0 -319
  91. package/dist/esm/src/verification/signature-validator.js +0 -64
  92. package/dist/esm/src/verification/sszTypes.js +0 -64
  93. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  94. package/dist/esm/src/verification/v1.10.0.js +0 -140
  95. package/dist/esm/src/verification/v1.6.0.js +0 -142
  96. package/dist/esm/src/verification/v1.7.0.js +0 -166
  97. package/dist/esm/src/verification/v1.8.0.js +0 -189
  98. package/dist/esm/test/client/ajv.spec.js +0 -318
  99. package/dist/esm/test/client/methods.spec.js +0 -393
  100. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  101. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  102. package/dist/esm/test/exit/exit.spec.js +0 -374
  103. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  104. package/dist/esm/test/fixtures.js +0 -893
  105. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  106. package/dist/esm/test/splits/splits.spec.js +0 -400
  107. package/src/abi/BatchDeposit.ts +0 -117
  108. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  109. package/src/abi/Multicall3.ts +0 -250
  110. package/src/abi/OVM.ts +0 -624
  111. package/src/abi/OWR.ts +0 -302
  112. package/src/abi/SplitMain.ts +0 -927
  113. package/src/abi/splitV2FactoryAbi.ts +0 -417
  114. package/src/ajv.ts +0 -191
  115. package/src/base.ts +0 -54
  116. package/src/bytecodes.ts +0 -32
  117. package/src/constants.ts +0 -309
  118. package/src/eoa/eoa.ts +0 -153
  119. package/src/eoa/eoaHelpers.ts +0 -112
  120. package/src/errors.ts +0 -8
  121. package/src/exits/ethUtils.ts +0 -49
  122. package/src/exits/exit.ts +0 -661
  123. package/src/exits/verificationHelpers.ts +0 -110
  124. package/src/incentives/incentiveHelpers.ts +0 -55
  125. package/src/incentives/incentives.ts +0 -153
  126. package/src/index.ts +0 -614
  127. package/src/schema.ts +0 -376
  128. package/src/services.ts +0 -24
  129. package/src/splits/splitHelpers.ts +0 -1032
  130. package/src/splits/splits.ts +0 -504
  131. package/src/types.ts +0 -687
  132. package/src/utils.ts +0 -88
  133. package/src/verification/common.ts +0 -532
  134. package/src/verification/signature-validator.ts +0 -103
  135. package/src/verification/sszTypes.ts +0 -88
  136. package/src/verification/termsAndConditions.ts +0 -32
  137. package/src/verification/v1.10.0.ts +0 -245
  138. package/src/verification/v1.6.0.ts +0 -256
  139. package/src/verification/v1.7.0.ts +0 -309
  140. package/src/verification/v1.8.0.ts +0 -340
package/src/constants.ts DELETED
@@ -1,309 +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_OVM_FACTORY_BYTECODE,
8
- HOLESKY_OWR_FACTORY_BYTECODE,
9
- HOLESKY_SPLITMAIN_BYTECODE,
10
- HOODI_MULTICALL3_BYTECODE,
11
- HOODI_OVM_FACTORY_BYTECODE,
12
- HOODI_OWR_FACTORY_BYTECODE,
13
- HOODI_SPLIT_V2_FACTORY_BYTECODE,
14
- HOODI_SPLITMAIN_BYTECODE,
15
- HOODI_WAREHOUSE_BYTECODE,
16
- MAINNET_MULTICALL3_BYTECODE,
17
- MAINNET_OVM_FACTORY_BYTECODE,
18
- MAINNET_OWR_FACTORY_BYTECODE,
19
- MAINNET_SPLIT_V2_FACTORY_BYTECODE,
20
- MAINNET_SPLITMAIN_BYTECODE,
21
- MAINNET_WAREHOUSE_BYTECODE,
22
- } from './bytecodes';
23
-
24
- import * as dotenv from 'dotenv';
25
- dotenv.config();
26
-
27
- export const CONFLICT_ERROR_MSG = 'Conflict';
28
-
29
- export const EIP712_DOMAIN_NAME = 'Obol';
30
- export const EIP712_DOMAIN_VERSION = '1';
31
- export const CreatorConfigHashSigningTypes = {
32
- CreatorConfigHash: [{ name: 'creator_config_hash', type: 'string' }],
33
- };
34
- export const TermsAndConditionsSigningTypes = {
35
- TermsAndConditions: [
36
- { name: 'terms_and_conditions_hash', type: 'string' },
37
- { name: 'version', type: 'uint256' },
38
- ],
39
- };
40
-
41
- const EIP712Domain = [
42
- { name: 'name', type: 'string' },
43
- { name: 'version', type: 'string' },
44
- { name: 'chainId', type: 'uint256' },
45
- ];
46
-
47
- export const Domain = (chainId?: number): TypedDataDomain => {
48
- const typeDataDomain: any = {
49
- name: EIP712_DOMAIN_NAME,
50
- version: EIP712_DOMAIN_VERSION,
51
- };
52
- if (chainId) {
53
- typeDataDomain.chainId = chainId;
54
- }
55
- return typeDataDomain;
56
- };
57
-
58
- export const CreatorTypedMessage = {
59
- EIP712Domain,
60
- ...CreatorConfigHashSigningTypes,
61
- };
62
-
63
- // A conflict once updateDefinition is merged
64
- export const EnrSigningTypes = {
65
- ENR: [{ name: 'enr', type: 'string' }],
66
- };
67
-
68
- export const OperatorConfigHashSigningTypes = {
69
- OperatorConfigHash: [{ name: 'operator_config_hash', type: 'string' }],
70
- };
71
-
72
- export const OperatorTypedMessage = {
73
- EIP712Domain,
74
- ...OperatorConfigHashSigningTypes,
75
- };
76
-
77
- export const ENRTypedMessage = {
78
- EIP712Domain,
79
- ...EnrSigningTypes,
80
- };
81
-
82
- export const signCreatorConfigHashPayload = (
83
- payload: { creator_config_hash: string },
84
- chainId: number,
85
- ): TypedMessage<typeof CreatorTypedMessage> => {
86
- return {
87
- types: CreatorTypedMessage,
88
- primaryType: 'CreatorConfigHash',
89
- domain: {
90
- name: EIP712_DOMAIN_NAME,
91
- version: EIP712_DOMAIN_VERSION,
92
- chainId,
93
- },
94
- message: payload,
95
- };
96
- };
97
-
98
- export const signOperatorConfigHashPayload = (
99
- payload: { operator_config_hash: string },
100
- chainId: number,
101
- ): TypedMessage<typeof OperatorTypedMessage> => {
102
- return {
103
- types: OperatorTypedMessage,
104
- primaryType: 'OperatorConfigHash',
105
- domain: {
106
- name: EIP712_DOMAIN_NAME,
107
- version: EIP712_DOMAIN_VERSION,
108
- chainId,
109
- },
110
- message: payload,
111
- };
112
- };
113
-
114
- export const signEnrPayload = (
115
- payload: { enr: string },
116
- chainId: number,
117
- ): TypedMessage<typeof ENRTypedMessage> => {
118
- return {
119
- types: ENRTypedMessage,
120
- primaryType: 'ENR',
121
- domain: {
122
- name: EIP712_DOMAIN_NAME,
123
- version: EIP712_DOMAIN_VERSION,
124
- chainId,
125
- },
126
- message: payload,
127
- };
128
- };
129
-
130
- export const DKG_ALGORITHM = 'default';
131
-
132
- export const CONFIG_VERSION = 'v1.10.0';
133
-
134
- export const SDK_VERSION = pjson.version;
135
-
136
- export const DOMAIN_APPLICATION_BUILDER = '00000001';
137
- export const DOMAIN_DEPOSIT = '03000000';
138
- export const GENESIS_VALIDATOR_ROOT =
139
- '0000000000000000000000000000000000000000000000000000000000000000';
140
-
141
- // Flow used to create definition
142
- export enum DefinitionFlow {
143
- Group = 'LP-Group',
144
- Solo = 'LP-Solo',
145
- Charon = 'Charon-Command',
146
- }
147
-
148
- export const DEFAULT_BASE_URL = 'https://api.obol.tech';
149
- export const DEFAULT_BASE_VERSION = 'v1';
150
- export const DEFAULT_CHAIN_ID = 17000;
151
-
152
- export const ETHER_TO_GWEI = 10 ** 9;
153
-
154
- export const TERMS_AND_CONDITIONS_VERSION = 1;
155
- export const TERMS_AND_CONDITIONS_URL =
156
- TERMS_AND_CONDITIONS_VERSION === 1
157
- ? 'https://obol.org/terms.pdf'
158
- : `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf`;
159
- export const TERMS_AND_CONDITIONS_HASH =
160
- '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';
161
-
162
- export const AVAILABLE_SPLITTER_CHAINS = {
163
- [FORK_MAPPING['0x00000000']]: true, // Mainnet
164
- [FORK_MAPPING['0x01017000']]: true, // Holesky
165
- [FORK_MAPPING['0x10000910']]: true, // Hoodi
166
- } as const;
167
-
168
- export const isChainSupportedForSplitters = (chainId: number): boolean => {
169
- return chainId in AVAILABLE_SPLITTER_CHAINS;
170
- };
171
-
172
- export const CHAIN_CONFIGURATION: Record<number, ChainConfig> = {
173
- [FORK_MAPPING['0x00000000']]: {
174
- SPLITMAIN_CONTRACT: {
175
- address: '0x2ed6c4B5dA6378c7897AC67Ba9e43102Feb694EE',
176
- bytecode: MAINNET_SPLITMAIN_BYTECODE,
177
- },
178
- MULTICALL3_CONTRACT: {
179
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
180
- bytecode: MAINNET_MULTICALL3_BYTECODE,
181
- },
182
- OWR_FACTORY_CONTRACT: {
183
- address: '0x119acd7844cbdd5fc09b1c6a4408f490c8f7f522',
184
- bytecode: MAINNET_OWR_FACTORY_BYTECODE,
185
- },
186
- RETROACTIVE_FUNDING_CONTRACT: {
187
- address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
188
- bytecode: '',
189
- },
190
- // OVM and SplitV2 Contract Addresses
191
- OVM_FACTORY_CONTRACT: {
192
- address: '0xA755669f314022ED2158e93867af5183E88370fe',
193
- bytecode: MAINNET_OVM_FACTORY_BYTECODE,
194
- },
195
- WAREHOUSE_CONTRACT: {
196
- address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
197
- bytecode: MAINNET_WAREHOUSE_BYTECODE,
198
- },
199
- SPLIT_V2_FACTORY_CONTRACT: {
200
- address: '0x5cbA88D55Cec83caD5A105Ad40C8c9aF20bE21d1',
201
- bytecode: MAINNET_SPLIT_V2_FACTORY_BYTECODE,
202
- },
203
- EOA_WITHDRAWAL_CONTRACT: {
204
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
205
- },
206
- BATCH_DEPOSIT_CONTRACT: {
207
- address: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
208
- },
209
- },
210
- [FORK_MAPPING['0x01017000']]: {
211
- SPLITMAIN_CONTRACT: {
212
- address: '0xfC8a305728051367797DADE6Aa0344E0987f5286',
213
- bytecode: HOLESKY_SPLITMAIN_BYTECODE,
214
- },
215
- MULTICALL3_CONTRACT: {
216
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
217
- bytecode: HOLESKY_MULTICALL3_BYTECODE,
218
- },
219
- OWR_FACTORY_CONTRACT: {
220
- address: '0xc0961353fcc43a99e3041db07ac646720e116256',
221
- bytecode: HOLESKY_OWR_FACTORY_BYTECODE,
222
- },
223
- RETROACTIVE_FUNDING_CONTRACT: {
224
- address: '0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5',
225
- bytecode: '',
226
- },
227
- EOA_WITHDRAWAL_CONTRACT: {
228
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
229
- },
230
- OVM_FACTORY_CONTRACT: {
231
- address: '0x4B157b79277E44D12C234680ACE17Db028075EA5',
232
- bytecode: HOLESKY_OVM_FACTORY_BYTECODE,
233
- },
234
- },
235
- [FORK_MAPPING['0x10000910']]: {
236
- SPLITMAIN_CONTRACT: {
237
- address: '0xc05ae267291705ac16F75283572294ed2a91CBc7',
238
- bytecode: HOODI_SPLITMAIN_BYTECODE,
239
- },
240
- MULTICALL3_CONTRACT: {
241
- address: '0xcA11bde05977b3631167028862bE2a173976CA11',
242
- bytecode: HOODI_MULTICALL3_BYTECODE,
243
- },
244
- OWR_FACTORY_CONTRACT: {
245
- address: '0x9ff0c649d0bf5fe7efa4d72e94bed7302ed5c8d7',
246
- bytecode: HOODI_OWR_FACTORY_BYTECODE,
247
- },
248
- RETROACTIVE_FUNDING_CONTRACT: {
249
- address: '0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5',
250
- bytecode: '',
251
- },
252
- // OVM and SplitV2 Contract Addresses
253
- OVM_FACTORY_CONTRACT: {
254
- address: '0x885E7D97E3987BA57EF0d693C508d675e4Bf82FC',
255
- bytecode: HOODI_OVM_FACTORY_BYTECODE,
256
- },
257
- WAREHOUSE_CONTRACT: {
258
- address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
259
- bytecode: HOODI_WAREHOUSE_BYTECODE,
260
- },
261
- SPLIT_V2_FACTORY_CONTRACT: {
262
- address: '0x5cbA88D55Cec83caD5A105Ad40C8c9aF20bE21d1',
263
- bytecode: HOODI_SPLIT_V2_FACTORY_BYTECODE,
264
- },
265
- EOA_WITHDRAWAL_CONTRACT: {
266
- address: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
267
- },
268
- BATCH_DEPOSIT_CONTRACT: {
269
- address: '0x4c9506eE2fCd962f03022D9d8ebf6f7828abEfaf',
270
- },
271
- },
272
- };
273
-
274
- export const DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = 1;
275
-
276
- export const DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = 0.1;
277
-
278
- // OVM and SplitV2 Default Constants
279
- export const SPLITS_V2_SALT =
280
- '0x2fa740d39f3b04b2c7ef4e9f9e1a6e38f4c72c1a91d8595d5d31a3adf17c6b12';
281
- export const PRINCIPAL_THRESHOLD = 16;
282
-
283
- export const OBOL_SDK_EMAIL = 'sdk@dvlabs.tech';
284
-
285
- export const PROVIDER_MAP: Record<number, string> = {
286
- 1: `${process.env.RPC_MAINNET}`, // Mainnet
287
- 17000: `${process.env.RPC_HOLESKY}`, // Holesky
288
- 11155111: `${process.env.RPC_SEPOLIA}`, // Sepolia
289
- 100: `${process.env.RPC_GNOSIS}`, // Gnosis
290
- 560048: `${process.env.RPC_HOODI}`, // Hoodi
291
- };
292
-
293
- /**
294
- * Maps base fork versions to their corresponding Capella fork versions.
295
- * Example: Mainnet Capella fork version.
296
- */
297
- export const CAPELLA_FORK_MAPPING: Record<string, string> = {
298
- '0x00000000': '0x03000000', // Mainnet
299
- '0x00001020': '0x03001020', // Goerli
300
- '0x00000064': '0x03000064', // Gnosis
301
- '0x90000069': '0x90000072', // Sepolia
302
- '0x01017000': '0x04017000', // Holesky
303
- '0x10000910': '0x40000910', // Hoodi
304
- };
305
-
306
- export const CHAIN_PUBLIC_RPC_URL: Record<number, string> = {
307
- 1: 'https://ethereum-rpc.publicnode.com', // Mainnet
308
- 560048: 'https://ethereum-hoodi-rpc.publicnode.com', // Hoodi
309
- };
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
- }