@obolnetwork/obol-sdk 2.6.0 → 2.8.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 (56) hide show
  1. package/dist/cjs/package.json +4 -2
  2. package/dist/cjs/src/abi/OVMFactory.js +620 -0
  3. package/dist/cjs/src/ajv.js +33 -6
  4. package/dist/cjs/src/bytecodes.js +8 -1
  5. package/dist/cjs/src/constants.js +55 -7
  6. package/dist/cjs/src/exits/exit.js +82 -0
  7. package/dist/cjs/src/index.js +21 -9
  8. package/dist/cjs/src/schema.js +71 -1
  9. package/dist/cjs/src/splits/splitHelpers.js +218 -12
  10. package/dist/cjs/src/splits/splits.js +261 -0
  11. package/dist/cjs/src/types.js +0 -1
  12. package/dist/cjs/test/client/ajv.spec.js +269 -0
  13. package/dist/cjs/test/client/methods.spec.js +418 -0
  14. package/dist/cjs/test/exit/exit.spec.js +74 -3
  15. package/dist/cjs/test/fixtures.js +13 -1
  16. package/dist/cjs/test/splits/splits.spec.js +239 -0
  17. package/dist/esm/package.json +4 -2
  18. package/dist/esm/src/abi/OVMFactory.js +617 -0
  19. package/dist/esm/src/ajv.js +33 -6
  20. package/dist/esm/src/bytecodes.js +7 -0
  21. package/dist/esm/src/constants.js +54 -7
  22. package/dist/esm/src/exits/exit.js +83 -1
  23. package/dist/esm/src/index.js +20 -9
  24. package/dist/esm/src/schema.js +71 -1
  25. package/dist/esm/src/splits/splitHelpers.js +213 -13
  26. package/dist/esm/src/splits/splits.js +257 -0
  27. package/dist/esm/src/types.js +0 -1
  28. package/dist/esm/test/client/ajv.spec.js +267 -0
  29. package/dist/esm/test/client/methods.spec.js +393 -0
  30. package/dist/esm/test/exit/exit.spec.js +74 -3
  31. package/dist/esm/test/fixtures.js +12 -0
  32. package/dist/esm/test/splits/splits.spec.js +237 -0
  33. package/dist/types/src/abi/OVMFactory.d.ts +662 -0
  34. package/dist/types/src/bytecodes.d.ts +7 -0
  35. package/dist/types/src/constants.d.ts +10 -21
  36. package/dist/types/src/exits/exit.d.ts +21 -1
  37. package/dist/types/src/index.d.ts +7 -0
  38. package/dist/types/src/schema.d.ts +145 -0
  39. package/dist/types/src/splits/splitHelpers.d.ts +40 -1
  40. package/dist/types/src/splits/splits.d.ts +51 -0
  41. package/dist/types/src/types.d.ts +122 -6
  42. package/dist/types/test/client/ajv.spec.d.ts +1 -0
  43. package/dist/types/test/client/methods.spec.d.ts +1 -0
  44. package/dist/types/test/fixtures.d.ts +10 -0
  45. package/dist/types/test/splits/splits.spec.d.ts +1 -0
  46. package/package.json +4 -2
  47. package/src/abi/OVMFactory.ts +617 -0
  48. package/src/ajv.ts +55 -13
  49. package/src/bytecodes.ts +15 -0
  50. package/src/constants.ts +66 -8
  51. package/src/exits/exit.ts +98 -1
  52. package/src/index.ts +36 -15
  53. package/src/schema.ts +80 -0
  54. package/src/splits/splitHelpers.ts +360 -14
  55. package/src/splits/splits.ts +355 -0
  56. package/src/types.ts +138 -10
@@ -0,0 +1,355 @@
1
+ import {
2
+ formatRecipientsForSplitV2,
3
+ predictSplitV2Address,
4
+ isSplitV2Deployed,
5
+ deployOVMContract,
6
+ deployOVMAndSplitV2,
7
+ } from './splitHelpers';
8
+ import {
9
+ CHAIN_CONFIGURATION,
10
+ SPLITS_V2_SALT,
11
+ DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
12
+ isChainSupportedForSplitters,
13
+ } from '../constants';
14
+ import {
15
+ ovmRewardsSplitPayloadSchema,
16
+ ovmTotalSplitPayloadSchema,
17
+ } from '../schema';
18
+ import { validatePayload } from '../ajv';
19
+ import { isContractAvailable } from '../utils';
20
+ import {
21
+ type ClusterValidator,
22
+ type ProviderType,
23
+ type SignerType,
24
+ type OVMRewardsSplitPayload,
25
+ type OVMTotalSplitPayload,
26
+ } from '../types';
27
+
28
+ /**
29
+ * ObolSplits can be used for creating and managing Obol splits.
30
+ * @class
31
+ * @internal Access it through Client.splits.
32
+ * @example
33
+ * const obolClient = new Client(config);
34
+ * await obolClient.splits.createValidatorManagerAndRewardsSplit(OVMRewardsSplitPayload);
35
+ */
36
+ export class ObolSplits {
37
+ private readonly signer: SignerType | undefined;
38
+ public readonly chainId: number;
39
+ public readonly provider: ProviderType | undefined | null;
40
+
41
+ constructor(
42
+ signer: SignerType | undefined,
43
+ chainId: number,
44
+ provider: ProviderType | undefined | null,
45
+ ) {
46
+ this.signer = signer;
47
+ this.chainId = chainId;
48
+ this.provider = provider;
49
+ }
50
+
51
+ /**
52
+ * Creates an Obol OVM and Pull split configuration for rewards-only scenario.
53
+ *
54
+ * This method deploys OVM and SplitV2 contracts for managing validator rewards only.
55
+ * Principal is handled by a single address, while rewards are split among recipients.
56
+ *
57
+ * @remarks
58
+ * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
59
+ * and not pushed to version control.
60
+ *
61
+ * @param {OVMRewardsSplitPayload} payload - Data needed to deploy OVM and SplitV2
62
+ * @returns {Promise<ClusterValidator>} OVM address as withdrawal address and splitter as fee recipient
63
+ * @throws Will throw an error if the splitter configuration is not supported or deployment fails
64
+ *
65
+ * An example of how to use createValidatorManagerAndRewardsSplit:
66
+ * [createValidatorManagerAndRewardsSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L333)
67
+ */
68
+ async createValidatorManagerAndRewardsSplit(
69
+ payload: OVMRewardsSplitPayload,
70
+ ): Promise<ClusterValidator> {
71
+ const salt = SPLITS_V2_SALT;
72
+ if (!this.signer) {
73
+ throw new Error(
74
+ 'Signer is required in createValidatorManagerAndRewardsSplit',
75
+ );
76
+ }
77
+
78
+ const validatedPayload = validatePayload<Required<OVMRewardsSplitPayload>>(
79
+ payload,
80
+ ovmRewardsSplitPayloadSchema,
81
+ );
82
+
83
+ if (!isChainSupportedForSplitters(this.chainId)) {
84
+ throw new Error(
85
+ `Splitter configuration is not supported on ${this.chainId} chain`,
86
+ );
87
+ }
88
+
89
+ const chainConfig = CHAIN_CONFIGURATION[this.chainId];
90
+ if (!chainConfig?.OVM_FACTORY_ADDRESS) {
91
+ throw new Error(
92
+ `OVM contract factory is not configured for chain ${this.chainId}`,
93
+ );
94
+ }
95
+
96
+ if (!this.provider) {
97
+ throw new Error(
98
+ 'Provider is required to check OVM factory contract availability',
99
+ );
100
+ }
101
+
102
+ const ovmFactoryConfig = chainConfig.OVM_FACTORY_ADDRESS;
103
+ if (!ovmFactoryConfig?.address || !ovmFactoryConfig?.bytecode) {
104
+ throw new Error(
105
+ `OVM factory contract configuration is incomplete for chain ${this.chainId}`,
106
+ );
107
+ }
108
+
109
+ const checkOVMFactoryAddress = await isContractAvailable(
110
+ ovmFactoryConfig.address,
111
+ this.provider,
112
+ ovmFactoryConfig.bytecode,
113
+ );
114
+
115
+ if (!checkOVMFactoryAddress) {
116
+ throw new Error(
117
+ `OVM factory contract is not deployed or available on chain ${this.chainId}`,
118
+ );
119
+ }
120
+
121
+ const retroActiveFundingRecipient = {
122
+ address: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
123
+ percentAllocation: DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
124
+ };
125
+
126
+ const copiedRewardsSplitRecipients = [
127
+ ...validatedPayload.rewardSplitRecipients,
128
+ ];
129
+ copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
130
+
131
+ // Format recipients for SplitV2
132
+ const rewardRecipients = formatRecipientsForSplitV2(
133
+ copiedRewardsSplitRecipients,
134
+ );
135
+
136
+ const predictedSplitAddress = await predictSplitV2Address({
137
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
138
+ recipients: rewardRecipients,
139
+ distributorFeePercent: validatedPayload.distributorFeePercent,
140
+ salt,
141
+ signer: this.signer,
142
+ chainId: this.chainId,
143
+ });
144
+
145
+ const isRewardSplitterDeployed = await isSplitV2Deployed({
146
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
147
+ recipients: rewardRecipients,
148
+ distributorFeePercent: validatedPayload.distributorFeePercent,
149
+ salt,
150
+ signer: this.signer,
151
+ chainId: this.chainId,
152
+ });
153
+
154
+ if (isRewardSplitterDeployed) {
155
+ const ovmAddress = await deployOVMContract({
156
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
157
+ principalRecipient: validatedPayload.principalRecipient,
158
+ rewardRecipient: predictedSplitAddress,
159
+ principalThreshold: validatedPayload.principalThreshold,
160
+ signer: this.signer,
161
+ chainId: this.chainId,
162
+ });
163
+
164
+ return {
165
+ withdrawal_address: ovmAddress,
166
+ fee_recipient_address: predictedSplitAddress,
167
+ };
168
+ } else {
169
+ const ovmAddress = await deployOVMAndSplitV2({
170
+ ovmArgs: {
171
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
172
+ rewardRecipient: predictedSplitAddress,
173
+ principalRecipient: validatedPayload.principalRecipient,
174
+ principalThreshold: validatedPayload.principalThreshold,
175
+ },
176
+ rewardRecipients,
177
+ isRewardsSplitterDeployed: isRewardSplitterDeployed,
178
+ distributorFeePercent: validatedPayload.distributorFeePercent,
179
+ salt,
180
+ signer: this.signer,
181
+ chainId: this.chainId,
182
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
183
+ });
184
+
185
+ return {
186
+ withdrawal_address: ovmAddress,
187
+ fee_recipient_address: predictedSplitAddress,
188
+ };
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Creates an Obol OVM and Total split configuration for total split scenario.
194
+ *
195
+ * This method deploys OVM and SplitV2 contracts for managing both validator rewards and principal.
196
+ * Both rewards and principal are split among recipients, with rewards including RAF recipient.
197
+ *
198
+ * @remarks
199
+ * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
200
+ * and not pushed to version control.
201
+ *
202
+ * @param {OVMTotalSplitPayload} payload - Data needed to deploy OVM and SplitV2
203
+ * @returns {Promise<ClusterValidator>} OVM address as withdrawal address and splitter as fee recipient
204
+ * @throws Will throw an error if the splitter configuration is not supported or deployment fails
205
+ *
206
+ * An example of how to use createValidatorManagerAndTotalSplit:
207
+ * [createValidatorManagerAndTotalSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#340)
208
+ */
209
+ async createValidatorManagerAndTotalSplit(
210
+ payload: OVMTotalSplitPayload,
211
+ ): Promise<ClusterValidator> {
212
+ const salt = SPLITS_V2_SALT;
213
+ if (!this.signer) {
214
+ throw new Error(
215
+ 'Signer is required in createValidatorManagerAndTotalSplit',
216
+ );
217
+ }
218
+
219
+ const validatedPayload = validatePayload<Required<OVMTotalSplitPayload>>(
220
+ payload,
221
+ ovmTotalSplitPayloadSchema,
222
+ );
223
+
224
+ if (!isChainSupportedForSplitters(this.chainId)) {
225
+ throw new Error(
226
+ `Splitter configuration is not supported on ${this.chainId} chain`,
227
+ );
228
+ }
229
+
230
+ const chainConfig = CHAIN_CONFIGURATION[this.chainId];
231
+ if (!chainConfig?.OVM_FACTORY_ADDRESS) {
232
+ throw new Error(
233
+ `OVM contract factory is not configured for chain ${this.chainId}`,
234
+ );
235
+ }
236
+
237
+ if (!this.provider) {
238
+ throw new Error(
239
+ 'Provider is required to check OVM factory contract availability',
240
+ );
241
+ }
242
+
243
+ const ovmFactoryConfig = chainConfig.OVM_FACTORY_ADDRESS;
244
+ if (!ovmFactoryConfig?.address || !ovmFactoryConfig?.bytecode) {
245
+ throw new Error(
246
+ `OVM factory contract configuration is incomplete for chain ${this.chainId}`,
247
+ );
248
+ }
249
+
250
+ const checkOVMFactoryAddress = await isContractAvailable(
251
+ ovmFactoryConfig.address,
252
+ this.provider,
253
+ ovmFactoryConfig.bytecode,
254
+ );
255
+
256
+ if (!checkOVMFactoryAddress) {
257
+ throw new Error(
258
+ `OVM factory contract is not deployed or available on chain ${this.chainId}`,
259
+ );
260
+ }
261
+
262
+ const retroActiveFundingRecipient = {
263
+ address: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
264
+ percentAllocation: DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
265
+ };
266
+
267
+ const copiedRewardsSplitRecipients = [
268
+ ...validatedPayload.rewardSplitRecipients,
269
+ ];
270
+ copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
271
+
272
+ const rewardsRecipients = formatRecipientsForSplitV2(
273
+ copiedRewardsSplitRecipients,
274
+ );
275
+
276
+ const principalSplitRecipients = formatRecipientsForSplitV2(
277
+ validatedPayload.principalSplitRecipients,
278
+ );
279
+
280
+ const predictedRewardsSplitAddress = await predictSplitV2Address({
281
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
282
+ recipients: rewardsRecipients,
283
+ distributorFeePercent: validatedPayload.distributorFeePercent,
284
+ salt,
285
+ signer: this.signer,
286
+ chainId: this.chainId,
287
+ });
288
+
289
+ const predictedPrincipalSplitAddress = await predictSplitV2Address({
290
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
291
+ recipients: principalSplitRecipients,
292
+ distributorFeePercent: validatedPayload.distributorFeePercent,
293
+ salt,
294
+ signer: this.signer,
295
+ chainId: this.chainId,
296
+ });
297
+
298
+ const isRewardsSplitterDeployed = await isSplitV2Deployed({
299
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
300
+ recipients: rewardsRecipients,
301
+ distributorFeePercent: validatedPayload.distributorFeePercent,
302
+ salt,
303
+ signer: this.signer,
304
+ chainId: this.chainId,
305
+ });
306
+
307
+ const isPrincipalSplitterDeployed = await isSplitV2Deployed({
308
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
309
+ recipients: principalSplitRecipients,
310
+ distributorFeePercent: validatedPayload.distributorFeePercent,
311
+ salt,
312
+ signer: this.signer,
313
+ chainId: this.chainId,
314
+ });
315
+
316
+ if (isRewardsSplitterDeployed && isPrincipalSplitterDeployed) {
317
+ const ovmAddress = await deployOVMContract({
318
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
319
+ principalRecipient: predictedPrincipalSplitAddress,
320
+ rewardRecipient: predictedRewardsSplitAddress,
321
+ principalThreshold: validatedPayload.principalThreshold,
322
+ signer: this.signer,
323
+ chainId: this.chainId,
324
+ });
325
+
326
+ return {
327
+ withdrawal_address: ovmAddress,
328
+ fee_recipient_address: predictedRewardsSplitAddress,
329
+ };
330
+ } else {
331
+ // Use multicall to deploy any contracts that aren't deployed
332
+ const ovmAddress = await deployOVMAndSplitV2({
333
+ ovmArgs: {
334
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
335
+ rewardRecipient: predictedRewardsSplitAddress,
336
+ principalRecipient: predictedPrincipalSplitAddress,
337
+ principalThreshold: validatedPayload.principalThreshold,
338
+ },
339
+ rewardRecipients: rewardsRecipients,
340
+ distributorFeePercent: validatedPayload.distributorFeePercent,
341
+ salt,
342
+ signer: this.signer,
343
+ chainId: this.chainId,
344
+ principalSplitRecipients,
345
+ isPrincipalSplitDeployed: isPrincipalSplitterDeployed,
346
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
347
+ });
348
+
349
+ return {
350
+ withdrawal_address: ovmAddress,
351
+ fee_recipient_address: predictedRewardsSplitAddress,
352
+ };
353
+ }
354
+ }
355
+ }
package/src/types.ts CHANGED
@@ -5,7 +5,6 @@ import {
5
5
  type JsonRpcProvider,
6
6
  type JsonRpcSigner,
7
7
  type Provider,
8
- type Signer,
9
8
  } from 'ethers';
10
9
 
11
10
  /**
@@ -202,6 +201,58 @@ export interface RewardsSplitPayload extends TotalSplitPayload {
202
201
  recoveryAddress?: string;
203
202
  }
204
203
 
204
+ /**
205
+ * OVM and SplitV2 Base Params
206
+ */
207
+ export type OVMBaseSplitPayload = {
208
+ /** The split recipients addresses and splits. */
209
+ rewardSplitRecipients: SplitV2Recipient[];
210
+
211
+ /** Owner address for the OVM contract. */
212
+ OVMOwnerAddress: string;
213
+
214
+ /** Owner address for the splitter contracts. */
215
+ splitOwnerAddress?: string;
216
+
217
+ /** Principal threshold for OVM contract. */
218
+ principalThreshold?: number;
219
+
220
+ /** Distributor fee percentage (0-10). */
221
+ distributorFeePercent?: number;
222
+ };
223
+
224
+ /**
225
+ * OVM and SplitV2 Params for rewards-only split
226
+ */
227
+ export type OVMRewardsSplitPayload = OVMBaseSplitPayload & {
228
+ /** Principal recipient address (single address for rewards-only split). */
229
+ principalRecipient: string;
230
+ };
231
+
232
+ /**
233
+ * OVM and SplitV2 Params for total split scenario
234
+ */
235
+ export type OVMTotalSplitPayload = OVMBaseSplitPayload & {
236
+ /** Principal recipients addresses and splits (array for total split scenario). */
237
+ principalSplitRecipients: SplitV2Recipient[];
238
+ };
239
+
240
+ /**
241
+ * Union type for both OVM split scenarios
242
+ */
243
+ export type OVMSplitPayload = OVMRewardsSplitPayload | OVMTotalSplitPayload;
244
+
245
+ /**
246
+ * SplitV2 Recipient structure
247
+ */
248
+ export type SplitV2Recipient = {
249
+ /** Recipient address. */
250
+ address: string;
251
+
252
+ /** Percentage allocation (0-100 with up to 4 decimals). */
253
+ percentAllocation: number;
254
+ };
255
+
205
256
  /**
206
257
  * OWR Tranches
207
258
  */
@@ -346,7 +397,7 @@ export type SafeRpcUrl = string;
346
397
  /**
347
398
  * Signer Types
348
399
  */
349
- export type SignerType = Signer | JsonRpcSigner | Wallet;
400
+ export type SignerType = JsonRpcSigner | Wallet;
350
401
 
351
402
  /**
352
403
  * claimIncentives Response
@@ -448,19 +499,54 @@ export interface ExitValidationPayload {
448
499
  * Represents the data structure for an already existing exit blob for exit validation.
449
500
  */
450
501
  export interface ExistingExitValidationBlobData {
451
- /** The public key of the validator to exit. */
502
+ /**
503
+ * The BLS public key of the validator in hex format
504
+ */
452
505
  public_key: string;
453
-
454
- /** The epoch at which the validator wishes to exit. */
506
+ /**
507
+ * The epoch number when the exit is scheduled to occur
508
+ */
455
509
  epoch: string;
456
-
457
- /** The index of the validator in the beacon chain. */
510
+ /**
511
+ * The unique index of the validator in the beacon chain
512
+ */
458
513
  validator_index: string;
459
-
460
- /** Collection of partial exit signatures from different shares. */
514
+ /**
515
+ * Array of distributed validator shares exit data, where each share contains
516
+ * the partial exit signature from each operator in the cluster
517
+ */
461
518
  shares_exit_data: Array<Record<string, { partial_exit_signature: string }>>;
462
519
  }
463
520
 
521
+ // ExitBlob is an exit message alongside its BLS12-381 hex-encoded signature.
522
+ export interface FullExitBlob {
523
+ /**
524
+ * The signed voluntary exit message containing the exit details and signature
525
+ */
526
+ signed_exit_message: {
527
+ /**
528
+ * The voluntary exit message details
529
+ */
530
+ message: {
531
+ /**
532
+ * The epoch number when the validator exit will be processed
533
+ */
534
+ epoch: string;
535
+ /**
536
+ * The unique index of the validator requesting to exit
537
+ */
538
+ validator_index: string;
539
+ };
540
+ /**
541
+ * The BLS12-381 hex-encoded signature of the exit message
542
+ */
543
+ signature: string;
544
+ };
545
+
546
+ /** The public key of the validator to exit. */
547
+ public_key: string;
548
+ }
549
+
464
550
  /**
465
551
  * Generic HTTP request function type.
466
552
  * Args:
@@ -474,4 +560,46 @@ export type HttpRequestFunc = (
474
560
  config?: Record<string, any>,
475
561
  ) => Promise<any>;
476
562
 
477
- // Add other SDK-specific types below or import from other type files
563
+ /**
564
+ * OVM Arguments for contract creation
565
+ */
566
+ export type OVMArgs = {
567
+ /** Owner address for the OVM contract. */
568
+ OVMOwnerAddress: string;
569
+
570
+ /** Principal recipient address. */
571
+ principalRecipient: string;
572
+
573
+ /** Rewards recipient of the cluster. */
574
+ rewardRecipient: string;
575
+
576
+ /** Principal threshold for OVM contract. */
577
+ principalThreshold: number;
578
+ };
579
+
580
+ export type ChainConfig = {
581
+ SPLITMAIN_ADDRESS: {
582
+ address: string;
583
+ bytecode: string;
584
+ };
585
+ MULTICALL_ADDRESS: {
586
+ address: string;
587
+ bytecode: string;
588
+ };
589
+ OWR_FACTORY_ADDRESS: {
590
+ address: string;
591
+ bytecode: string;
592
+ };
593
+ RETROACTIVE_FUNDING_ADDRESS: {
594
+ address: string;
595
+ bytecode: string;
596
+ };
597
+ OVM_FACTORY_ADDRESS?: {
598
+ address: string;
599
+ bytecode: string;
600
+ };
601
+ WAREHOUSE_ADDRESS?: {
602
+ address: string;
603
+ bytecode: string;
604
+ };
605
+ };