@obolnetwork/obol-sdk 2.5.1 → 2.7.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 +3 -3
  2. package/dist/cjs/src/constants.js +13 -1
  3. package/dist/cjs/src/exits/ethUtils.js +57 -0
  4. package/dist/cjs/src/exits/exit.js +502 -0
  5. package/dist/cjs/src/exits/verificationHelpers.js +86 -0
  6. package/dist/cjs/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
  7. package/dist/cjs/src/{incentives.js → incentives/incentives.js} +3 -3
  8. package/dist/cjs/src/index.js +22 -4
  9. package/dist/cjs/src/splits/splitHelpers.js +327 -0
  10. package/dist/cjs/src/types.js +1 -0
  11. package/dist/cjs/test/exit/ethUtils.spec.js +83 -0
  12. package/dist/cjs/test/exit/exit.spec.js +399 -0
  13. package/dist/cjs/test/exit/verificationHelpers.spec.js +68 -0
  14. package/dist/cjs/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
  15. package/dist/esm/package.json +3 -3
  16. package/dist/esm/src/constants.js +12 -0
  17. package/dist/esm/src/exits/ethUtils.js +52 -0
  18. package/dist/esm/src/exits/exit.js +475 -0
  19. package/dist/esm/src/exits/verificationHelpers.js +81 -0
  20. package/dist/esm/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
  21. package/dist/esm/src/{incentives.js → incentives/incentives.js} +3 -3
  22. package/dist/esm/src/index.js +20 -3
  23. package/dist/esm/src/splits/splitHelpers.js +317 -0
  24. package/dist/esm/src/types.js +1 -0
  25. package/dist/esm/test/exit/ethUtils.spec.js +81 -0
  26. package/dist/esm/test/exit/exit.spec.js +374 -0
  27. package/dist/esm/test/exit/verificationHelpers.spec.js +66 -0
  28. package/dist/esm/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
  29. package/dist/types/src/constants.d.ts +5 -0
  30. package/dist/types/src/exits/ethUtils.d.ts +13 -0
  31. package/dist/types/src/exits/exit.d.ts +200 -0
  32. package/dist/types/src/exits/verificationHelpers.d.ts +20 -0
  33. package/dist/types/src/{incentiveHelpers.d.ts → incentives/incentiveHelpers.d.ts} +1 -1
  34. package/dist/types/src/{incentives.d.ts → incentives/incentives.d.ts} +1 -1
  35. package/dist/types/src/index.d.ts +16 -2
  36. package/dist/types/src/{splitHelpers.d.ts → splits/splitHelpers.d.ts} +1 -1
  37. package/dist/types/src/types.d.ts +133 -0
  38. package/dist/types/test/exit/verificationHelpers.spec.d.ts +1 -0
  39. package/dist/types/test/incentives/incentives.spec.d.ts +1 -0
  40. package/package.json +3 -3
  41. package/src/constants.ts +13 -0
  42. package/src/exits/ethUtils.ts +49 -0
  43. package/src/exits/exit.ts +661 -0
  44. package/src/exits/verificationHelpers.ts +110 -0
  45. package/src/{incentiveHelpers.ts → incentives/incentiveHelpers.ts} +2 -2
  46. package/src/{incentives.ts → incentives/incentives.ts} +3 -3
  47. package/src/index.ts +29 -3
  48. package/src/splits/splitHelpers.ts +557 -0
  49. package/src/types.ts +158 -0
  50. package/dist/cjs/src/splitHelpers.js +0 -187
  51. package/dist/cjs/test/methods.test.js +0 -418
  52. package/dist/esm/src/splitHelpers.js +0 -177
  53. package/dist/esm/test/methods.test.js +0 -393
  54. package/src/splitHelpers.ts +0 -355
  55. /package/dist/types/test/{incentives.test.d.ts → exit/ethUtils.spec.d.ts} +0 -0
  56. /package/dist/types/test/{methods.test.d.ts → exit/exit.spec.d.ts} +0 -0
@@ -0,0 +1,110 @@
1
+ import { ContainerType, ByteVectorType, fromHexString } from '@chainsafe/ssz';
2
+
3
+ // From obol-api/src/verification/common.ts
4
+ export const GENESIS_VALIDATOR_ROOT_HEX_STRING =
5
+ '0x0000000000000000000000000000000000000000000000000000000000000000'; // Added 0x prefix
6
+
7
+ const ForkDataType = new ContainerType({
8
+ currentVersion: new ByteVectorType(4),
9
+ genesisValidatorsRoot: new ByteVectorType(32),
10
+ });
11
+
12
+ const SigningRootType = new ContainerType({
13
+ objectRoot: new ByteVectorType(32),
14
+ domain: new ByteVectorType(32),
15
+ });
16
+
17
+ /**
18
+ * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_fork_data_root
19
+ * @param currentVersion - Uint8Array of the current fork version.
20
+ * @param genesisValidatorsRoot - Uint8Array of the genesis validators root.
21
+ * @returns Uint8Array - The 32-byte fork data root.
22
+ */
23
+ function computeForkDataRoot(
24
+ currentVersion: Uint8Array,
25
+ genesisValidatorsRoot: Uint8Array,
26
+ ): Uint8Array {
27
+ const forkDataVal = ForkDataType.defaultValue();
28
+ forkDataVal.currentVersion = currentVersion;
29
+ forkDataVal.genesisValidatorsRoot = genesisValidatorsRoot;
30
+ return Buffer.from(ForkDataType.hashTreeRoot(forkDataVal).buffer);
31
+ }
32
+
33
+ /**
34
+ * Computes the domain for a given domain type, fork version, and genesis state.
35
+ * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_domain
36
+ * @param domainType - Uint8Array representing the domain type (e.g., DOMAIN_VOLUNTARY_EXIT).
37
+ * @param forkVersionString - Hex string of the fork version (e.g., Capella fork version).
38
+ * @param genesisValidatorsRootOverride - Optional Uint8Array to override the default genesis validators root.
39
+ * @returns Uint8Array - The 32-byte domain.
40
+ */
41
+ export function computeDomain(
42
+ domainType: Uint8Array, // Should be 4 bytes
43
+ forkVersionString: string, // Hex string, e.g., '0x03000000'
44
+ genesisValidatorsRootOverride?: Uint8Array, // 32 bytes
45
+ ): Uint8Array {
46
+ const forkVersionBytes = fromHexString(
47
+ forkVersionString.substring(2, forkVersionString.length),
48
+ );
49
+
50
+ if (forkVersionBytes.length !== 4) {
51
+ throw new Error('Fork version must be 4 bytes');
52
+ }
53
+ if (domainType.length !== 4) {
54
+ throw new Error('Domain type must be 4 bytes');
55
+ }
56
+
57
+ const actualGenesisValidatorsRoot =
58
+ genesisValidatorsRootOverride ??
59
+ fromHexString(GENESIS_VALIDATOR_ROOT_HEX_STRING.substring(2));
60
+
61
+ if (actualGenesisValidatorsRoot.length !== 32) {
62
+ throw new Error('genesisValidatorsRoot must be 32 bytes');
63
+ }
64
+ const forkDataRoot = computeForkDataRoot(
65
+ forkVersionBytes,
66
+ actualGenesisValidatorsRoot,
67
+ );
68
+ const domain = new Uint8Array(32);
69
+ domain.set(domainType);
70
+ domain.set(forkDataRoot.subarray(0, 28), 4); // Set the remaining 28 bytes from forkDataRoot
71
+ return domain;
72
+ }
73
+
74
+ /**
75
+ * Computes the signing root for an SSZ object and a domain.
76
+ * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_signing_root
77
+ * @param sszObjectRoot - Uint8Array of the hash tree root of the SSZ object.
78
+ * @param domain - Uint8Array of the domain.
79
+ * @returns Uint8Array - The 32-byte signing root.
80
+ */
81
+ function computeSigningRoot(
82
+ sszObjectRoot: Uint8Array, // Should be 32 bytes
83
+ domain: Uint8Array, // Should be 32 bytes
84
+ ): Uint8Array {
85
+ if (sszObjectRoot.length !== 32) {
86
+ throw new Error('SSZ object root must be 32 bytes');
87
+ }
88
+ if (domain.length !== 32) {
89
+ throw new Error('Domain must be 32 bytes');
90
+ }
91
+
92
+ const val = SigningRootType.defaultValue();
93
+ val.objectRoot = sszObjectRoot;
94
+ val.domain = domain;
95
+ return Buffer.from(SigningRootType.hashTreeRoot(val).buffer);
96
+ }
97
+
98
+ /**
99
+ * Convenience wrapper for computeSigningRoot.
100
+ * @param domain - Uint8Array of the domain.
101
+ * @param messageBuffer - Buffer of the message (SSZ object root).
102
+ * @returns Uint8Array - The signing root.
103
+ */
104
+ export function signingRoot(
105
+ domain: Uint8Array,
106
+ messageBuffer: Buffer, // Assumed to be the 32-byte sszObjectRoot
107
+ ): Uint8Array {
108
+ const sszObjectRootU8 = Uint8Array.from(messageBuffer);
109
+ return computeSigningRoot(sszObjectRootU8, domain);
110
+ }
@@ -1,6 +1,6 @@
1
- import { type ProviderType, type SignerType, type ETH_ADDRESS } from './types';
1
+ import { type ProviderType, type SignerType, type ETH_ADDRESS } from '../types';
2
2
  import { Contract } from 'ethers';
3
- import { MerkleDistributorABI } from './abi/MerkleDistributorWithDeadline';
3
+ import { MerkleDistributorABI } from '../abi/MerkleDistributorWithDeadline';
4
4
 
5
5
  export const claimIncentivesFromMerkleDistributor = async (incentivesData: {
6
6
  signer: SignerType;
@@ -1,4 +1,4 @@
1
- import { isContractAvailable } from './utils';
1
+ import { isContractAvailable } from '../utils';
2
2
  import {
3
3
  type ClaimableIncentives,
4
4
  type ETH_ADDRESS,
@@ -6,12 +6,12 @@ import {
6
6
  type ProviderType,
7
7
  type SignerType,
8
8
  type ClaimIncentivesResponse,
9
- } from './types';
9
+ } from '../types';
10
10
  import {
11
11
  claimIncentivesFromMerkleDistributor,
12
12
  isClaimedFromMerkleDistributor,
13
13
  } from './incentiveHelpers';
14
- import { DEFAULT_BASE_VERSION } from './constants';
14
+ import { DEFAULT_BASE_VERSION } from '../constants';
15
15
 
16
16
  /**
17
17
  * Incentives can be used for fetching and claiming Obol incentives.
package/src/index.ts CHANGED
@@ -45,15 +45,17 @@ import {
45
45
  handleDeployOWRAndSplitter,
46
46
  predictSplitterAddress,
47
47
  getOWRTranches,
48
- } from './splitHelpers.js';
48
+ } from './splits/splitHelpers.js';
49
49
  import { isContractAvailable } from './utils.js';
50
- import { Incentives } from './incentives.js';
50
+ import { Incentives } from './incentives/incentives.js';
51
+ import { Exit } from './exits/exit.js';
51
52
  export * from './types.js';
52
53
  export * from './services.js';
53
54
  export * from './verification/signature-validator.js';
54
55
  export * from './verification/common.js';
55
56
  export * from './constants.js';
56
- export { Incentives } from './incentives.js';
57
+ export { Incentives } from './incentives/incentives.js';
58
+ export { Exit } from './exits/exit.js';
57
59
 
58
60
  /**
59
61
  * Obol sdk Client can be used for creating, managing and activating distributed validators.
@@ -70,6 +72,12 @@ export class Client extends Base {
70
72
  */
71
73
  public incentives: Incentives;
72
74
 
75
+ /**
76
+ * The exit module, responsible for managing exit validation.
77
+ * @type {Exit}
78
+ */
79
+ public exit: Exit;
80
+
73
81
  /**
74
82
  * The blockchain provider, used to interact with the network.
75
83
  * It can be null, undefined, or a valid provider instance and defaults to the Signer provider if Signer is passed.
@@ -103,6 +111,7 @@ export class Client extends Base {
103
111
  this.request.bind(this),
104
112
  this.provider,
105
113
  );
114
+ this.exit = new Exit(this.chainId, this.provider);
106
115
  }
107
116
 
108
117
  /**
@@ -341,6 +350,7 @@ export class Client extends Base {
341
350
  const { accounts, percentAllocations } = formatSplitRecipients(
342
351
  copiedSplitRecipients,
343
352
  );
353
+
344
354
  const predictedSplitterAddress = await predictSplitterAddress({
345
355
  signer: this.signer,
346
356
  accounts,
@@ -555,4 +565,20 @@ export class Client extends Base {
555
565
  );
556
566
  return lock;
557
567
  }
568
+
569
+ /**
570
+ * @param lockHash - The configuration hash in cluster-definition
571
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
572
+ * @throws On not found cluster definition or lock.
573
+ *
574
+ */
575
+ async getClusterLockByHash(lockHash: string): Promise<ClusterLock> {
576
+ const lock: ClusterLock = await this.request(
577
+ `/${DEFAULT_BASE_VERSION}/lock/${lockHash}`,
578
+ {
579
+ method: 'GET',
580
+ },
581
+ );
582
+ return lock;
583
+ }
558
584
  }