@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
@@ -1,110 +0,0 @@
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,55 +0,0 @@
1
- import { type ProviderType, type SignerType, type ETH_ADDRESS } from '../types';
2
- import { Contract } from 'ethers';
3
- import { MerkleDistributorABI } from '../abi/MerkleDistributorWithDeadline';
4
-
5
- export const claimIncentivesFromMerkleDistributor = async (incentivesData: {
6
- signer: SignerType;
7
- contractAddress: ETH_ADDRESS;
8
- index: number;
9
- operatorAddress: ETH_ADDRESS;
10
- amount: string;
11
- merkleProof: string[];
12
- }): Promise<{ txHash: string }> => {
13
- try {
14
- const contract = new Contract(
15
- incentivesData.contractAddress,
16
- MerkleDistributorABI.abi,
17
- incentivesData.signer,
18
- );
19
-
20
- const tx = await contract.claim(
21
- BigInt(incentivesData.index),
22
- incentivesData.operatorAddress,
23
- BigInt(incentivesData.amount),
24
- incentivesData.merkleProof,
25
- );
26
-
27
- const receipt = await tx.wait();
28
-
29
- return { txHash: receipt.hash };
30
- } catch (error: any) {
31
- console.log('Error claiming incentives:', error);
32
- throw new Error(`Failed to claim incentives: ${error.message}`);
33
- }
34
- };
35
-
36
- export const isClaimedFromMerkleDistributor = async (
37
- contractAddress: ETH_ADDRESS,
38
- index: number,
39
- provider: ProviderType | undefined | null,
40
- ): Promise<boolean> => {
41
- try {
42
- const contract = new Contract(
43
- contractAddress,
44
- MerkleDistributorABI.abi,
45
- provider,
46
- );
47
-
48
- const claimed = await contract.isClaimed(BigInt(index));
49
-
50
- return claimed;
51
- } catch (error: any) {
52
- console.log('Error checking claim status:', error);
53
- throw new Error(`Failed to check claim status: ${error.message}`);
54
- }
55
- };
@@ -1,153 +0,0 @@
1
- import { isContractAvailable } from '../utils';
2
- import {
3
- type ClaimableIncentives,
4
- type ETH_ADDRESS,
5
- FORK_NAMES,
6
- type ProviderType,
7
- type SignerType,
8
- type ClaimIncentivesResponse,
9
- } from '../types';
10
- import {
11
- claimIncentivesFromMerkleDistributor,
12
- isClaimedFromMerkleDistributor,
13
- } from './incentiveHelpers';
14
- import { DEFAULT_BASE_VERSION } from '../constants';
15
-
16
- /**
17
- * Incentives can be used for fetching and claiming Obol incentives.
18
- * @class
19
- * @internal Access it through Client.incentives.
20
- * @example
21
- * const obolClient = new Client(config);
22
- * await obolClient.incentives.claimIncentives(address);
23
- */
24
- export class Incentives {
25
- private readonly signer: SignerType | undefined;
26
- public readonly chainId: number;
27
- private readonly request: (
28
- endpoint: string,
29
- options?: RequestInit,
30
- ) => Promise<any>;
31
-
32
- public readonly provider: ProviderType | undefined | null;
33
-
34
- constructor(
35
- signer: SignerType | undefined,
36
- chainId: number,
37
- request: (endpoint: string, options?: RequestInit) => Promise<any>,
38
- provider: ProviderType | undefined | null,
39
- ) {
40
- this.signer = signer;
41
- this.chainId = chainId;
42
- this.request = request;
43
- this.provider = provider;
44
- }
45
-
46
- /**
47
- * Claims Obol incentives from a Merkle Distributor contract using an address.
48
- *
49
- * This method automatically fetches incentive data and verifies whether the incentives have already been claimed.
50
- * If `txHash` is `null`, it indicates that the incentives were already claimed.
51
- *
52
- * Note: This method is not yet enabled and will throw an error if called.
53
- *
54
- * @remarks
55
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
56
- * and not pushed to version control.
57
- *
58
- * @param {string} address - The address to claim incentives for
59
- * @returns {Promise<ClaimIncentivesResponse>} The transaction hash or already claimed status
60
- * @throws Will throw an error if the incentives data is not found or the claim fails
61
- *
62
- * An example of how to use claimIncentives:
63
- * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L281)
64
- */
65
- async claimIncentives(address: string): Promise<ClaimIncentivesResponse> {
66
- if (!this.signer) {
67
- throw new Error('Signer is required in claimIncentives');
68
- }
69
-
70
- try {
71
- const incentivesData = await this.getIncentivesByAddress(address);
72
-
73
- if (!incentivesData?.contract_address) {
74
- throw new Error(`No incentives found for address ${address}`);
75
- }
76
-
77
- const isContractDeployed = await isContractAvailable(
78
- incentivesData.contract_address,
79
- this.provider as ProviderType,
80
- );
81
-
82
- if (!isContractDeployed) {
83
- throw new Error(
84
- `Merkle Distributor contract is not available at address ${incentivesData.contract_address}`,
85
- );
86
- }
87
-
88
- const claimed = await this.isClaimed(
89
- incentivesData.contract_address,
90
- incentivesData.index,
91
- );
92
-
93
- if (claimed) {
94
- return { txHash: null };
95
- }
96
-
97
- const { txHash } = await claimIncentivesFromMerkleDistributor({
98
- signer: this.signer,
99
- contractAddress: incentivesData.contract_address,
100
- index: incentivesData.index,
101
- operatorAddress: incentivesData.operator_address,
102
- amount: incentivesData.amount,
103
- merkleProof: incentivesData.merkle_proof,
104
- });
105
-
106
- return { txHash };
107
- } catch (error: any) {
108
- console.log('Error claiming incentives:', error);
109
- throw new Error(`Failed to claim incentives: ${error.message}`);
110
- }
111
- }
112
-
113
- /**
114
- * Read isClaimed.
115
- *
116
- * @param {ETH_ADDRESS} contractAddress - Address of the Merkle Distributor Contract
117
- * @param {ETH_ADDRESS} index - operator index in merkle tree
118
- * @returns {Promise<boolean>} true if incentives are already claime
119
- *
120
- *
121
- * An example of how to use isClaimed:
122
- * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L266)
123
- */
124
- async isClaimed(
125
- contractAddress: ETH_ADDRESS,
126
- index: number,
127
- ): Promise<boolean> {
128
- return await isClaimedFromMerkleDistributor(
129
- contractAddress,
130
- index,
131
- this.provider,
132
- );
133
- }
134
-
135
- /**
136
- * @param address - Operator address
137
- * @returns {Promise<IncentivesType>} The matched incentives from DB
138
- * @throws On not found if address not found.
139
- *
140
- * An example of how to use getIncentivesByAddress:
141
- * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L250)
142
- */
143
- async getIncentivesByAddress(address: string): Promise<ClaimableIncentives> {
144
- const network = FORK_NAMES[this.chainId];
145
- const incentives: ClaimableIncentives = await this.request(
146
- `/${DEFAULT_BASE_VERSION}/address/incentives/${network}/${address}`,
147
- {
148
- method: 'GET',
149
- },
150
- );
151
- return incentives;
152
- }
153
- }