@obolnetwork/obol-sdk 2.11.4 → 2.11.5-rc.1

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 (144) hide show
  1. package/README.md +33 -0
  2. package/dist/browser/src/index.js +18280 -0
  3. package/dist/browser/src/index.js.map +1 -0
  4. package/dist/cjs/src/index.js +17470 -382
  5. package/dist/cjs/src/index.js.map +1 -0
  6. package/dist/esm/src/index.js +17437 -361
  7. package/dist/esm/src/index.js.map +1 -0
  8. package/dist/types/src/constants.d.ts +1 -2
  9. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  10. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  11. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  12. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  13. package/dist/types/src/utils.d.ts +2 -2
  14. package/dist/types/src/verification/common.d.ts +0 -2
  15. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  16. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  17. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  18. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  19. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  20. package/dist/types/test/client/methods.spec.d.ts +17 -0
  21. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  22. package/dist/types/tsup.config.d.ts +2 -0
  23. package/package.json +96 -58
  24. package/dist/cjs/package.json +0 -139
  25. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  26. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  27. package/dist/cjs/src/abi/Multicall3.js +0 -253
  28. package/dist/cjs/src/abi/OVM.js +0 -627
  29. package/dist/cjs/src/abi/OWR.js +0 -304
  30. package/dist/cjs/src/abi/SplitMain.js +0 -929
  31. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  32. package/dist/cjs/src/ajv.js +0 -136
  33. package/dist/cjs/src/base.js +0 -42
  34. package/dist/cjs/src/bytecodes.js +0 -19
  35. package/dist/cjs/src/constants.js +0 -272
  36. package/dist/cjs/src/eoa/eoa.js +0 -132
  37. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  38. package/dist/cjs/src/errors.js +0 -11
  39. package/dist/cjs/src/exits/ethUtils.js +0 -57
  40. package/dist/cjs/src/exits/exit.js +0 -502
  41. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  42. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  43. package/dist/cjs/src/incentives/incentives.js +0 -119
  44. package/dist/cjs/src/schema.js +0 -352
  45. package/dist/cjs/src/services.js +0 -33
  46. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  47. package/dist/cjs/src/splits/splits.js +0 -366
  48. package/dist/cjs/src/types.js +0 -29
  49. package/dist/cjs/src/utils.js +0 -77
  50. package/dist/cjs/src/verification/common.js +0 -355
  51. package/dist/cjs/src/verification/signature-validator.js +0 -73
  52. package/dist/cjs/src/verification/sszTypes.js +0 -69
  53. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  54. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  55. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  56. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  57. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  58. package/dist/cjs/test/client/ajv.spec.js +0 -320
  59. package/dist/cjs/test/client/methods.spec.js +0 -418
  60. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  61. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  62. package/dist/cjs/test/exit/exit.spec.js +0 -399
  63. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  64. package/dist/cjs/test/fixtures.js +0 -896
  65. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  66. package/dist/cjs/test/splits/splits.spec.js +0 -402
  67. package/dist/esm/package.json +0 -139
  68. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  69. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  70. package/dist/esm/src/abi/Multicall3.js +0 -250
  71. package/dist/esm/src/abi/OVM.js +0 -624
  72. package/dist/esm/src/abi/OWR.js +0 -301
  73. package/dist/esm/src/abi/SplitMain.js +0 -926
  74. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  75. package/dist/esm/src/ajv.js +0 -129
  76. package/dist/esm/src/base.js +0 -38
  77. package/dist/esm/src/bytecodes.js +0 -16
  78. package/dist/esm/src/constants.js +0 -238
  79. package/dist/esm/src/eoa/eoa.js +0 -128
  80. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  81. package/dist/esm/src/errors.js +0 -7
  82. package/dist/esm/src/exits/ethUtils.js +0 -52
  83. package/dist/esm/src/exits/exit.js +0 -475
  84. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  85. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  86. package/dist/esm/src/incentives/incentives.js +0 -115
  87. package/dist/esm/src/schema.js +0 -349
  88. package/dist/esm/src/services.js +0 -29
  89. package/dist/esm/src/splits/splitHelpers.js +0 -554
  90. package/dist/esm/src/splits/splits.js +0 -362
  91. package/dist/esm/src/types.js +0 -26
  92. package/dist/esm/src/utils.js +0 -68
  93. package/dist/esm/src/verification/common.js +0 -319
  94. package/dist/esm/src/verification/signature-validator.js +0 -64
  95. package/dist/esm/src/verification/sszTypes.js +0 -64
  96. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  97. package/dist/esm/src/verification/v1.10.0.js +0 -140
  98. package/dist/esm/src/verification/v1.6.0.js +0 -142
  99. package/dist/esm/src/verification/v1.7.0.js +0 -166
  100. package/dist/esm/src/verification/v1.8.0.js +0 -189
  101. package/dist/esm/test/client/ajv.spec.js +0 -318
  102. package/dist/esm/test/client/methods.spec.js +0 -393
  103. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  104. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  105. package/dist/esm/test/exit/exit.spec.js +0 -374
  106. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  107. package/dist/esm/test/fixtures.js +0 -893
  108. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  109. package/dist/esm/test/splits/splits.spec.js +0 -400
  110. package/dist/types/src/verification/termsAndConditions.d.ts +0 -1
  111. package/src/abi/BatchDeposit.ts +0 -117
  112. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  113. package/src/abi/Multicall3.ts +0 -250
  114. package/src/abi/OVM.ts +0 -624
  115. package/src/abi/OWR.ts +0 -302
  116. package/src/abi/SplitMain.ts +0 -927
  117. package/src/abi/splitV2FactoryAbi.ts +0 -417
  118. package/src/ajv.ts +0 -191
  119. package/src/base.ts +0 -54
  120. package/src/bytecodes.ts +0 -32
  121. package/src/constants.ts +0 -309
  122. package/src/eoa/eoa.ts +0 -153
  123. package/src/eoa/eoaHelpers.ts +0 -112
  124. package/src/errors.ts +0 -8
  125. package/src/exits/ethUtils.ts +0 -49
  126. package/src/exits/exit.ts +0 -661
  127. package/src/exits/verificationHelpers.ts +0 -110
  128. package/src/incentives/incentiveHelpers.ts +0 -55
  129. package/src/incentives/incentives.ts +0 -153
  130. package/src/index.ts +0 -614
  131. package/src/schema.ts +0 -376
  132. package/src/services.ts +0 -24
  133. package/src/splits/splitHelpers.ts +0 -1032
  134. package/src/splits/splits.ts +0 -504
  135. package/src/types.ts +0 -687
  136. package/src/utils.ts +0 -88
  137. package/src/verification/common.ts +0 -532
  138. package/src/verification/signature-validator.ts +0 -103
  139. package/src/verification/sszTypes.ts +0 -88
  140. package/src/verification/termsAndConditions.ts +0 -32
  141. package/src/verification/v1.10.0.ts +0 -245
  142. package/src/verification/v1.6.0.ts +0 -256
  143. package/src/verification/v1.7.0.ts +0 -309
  144. package/src/verification/v1.8.0.ts +0 -340
package/src/index.ts DELETED
@@ -1,614 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { Base } from './base.js';
3
- import {
4
- CONFLICT_ERROR_MSG,
5
- CreatorConfigHashSigningTypes,
6
- Domain,
7
- DKG_ALGORITHM,
8
- CONFIG_VERSION,
9
- OperatorConfigHashSigningTypes,
10
- EnrSigningTypes,
11
- TERMS_AND_CONDITIONS_VERSION,
12
- TermsAndConditionsSigningTypes,
13
- DEFAULT_BASE_VERSION,
14
- TERMS_AND_CONDITIONS_HASH,
15
- CHAIN_CONFIGURATION,
16
- DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
17
- OBOL_SDK_EMAIL,
18
- isChainSupportedForSplitters,
19
- } from './constants.js';
20
- import { ConflictError } from './errors.js';
21
- import {
22
- type RewardsSplitPayload,
23
- type ClusterDefinition,
24
- type ClusterLock,
25
- type ClusterPayload,
26
- type OperatorPayload,
27
- type TotalSplitPayload,
28
- type ClusterValidator,
29
- type ETH_ADDRESS,
30
- type OWRTranches,
31
- type ProviderType,
32
- type SignerType,
33
- } from './types.js';
34
- import { clusterConfigOrDefinitionHash } from './verification/common.js';
35
- import { validatePayload } from './ajv.js';
36
- import {
37
- definitionSchema,
38
- operatorPayloadSchema,
39
- rewardsSplitterPayloadSchema,
40
- totalSplitterPayloadSchema,
41
- } from './schema.js';
42
- import {
43
- deploySplitterContract,
44
- formatSplitRecipients,
45
- handleDeployOWRAndSplitter,
46
- predictSplitterAddress,
47
- getOWRTranches,
48
- } from './splits/splitHelpers.js';
49
- import { isContractAvailable } from './utils.js';
50
- import { Incentives } from './incentives/incentives.js';
51
- import { Exit } from './exits/exit.js';
52
- import { ObolSplits } from './splits/splits.js';
53
- import { EOA } from './eoa/eoa.js';
54
- export * from './types.js';
55
- export * from './services.js';
56
- export * from './verification/signature-validator.js';
57
- export * from './verification/common.js';
58
- export * from './constants.js';
59
- export { Incentives } from './incentives/incentives.js';
60
- export { Exit } from './exits/exit.js';
61
- export { ObolSplits } from './splits/splits.js';
62
- export { EOA } from './eoa/eoa.js';
63
-
64
- /**
65
- * Obol sdk Client can be used for creating, managing and activating distributed validators.
66
- */
67
- export class Client extends Base {
68
- /**
69
- * The signer used for signing transactions.
70
- */
71
- private readonly signer: SignerType | undefined;
72
-
73
- /**
74
- * The incentives module, responsible for managing Obol tokens distribution.
75
- * @type {Incentives}
76
- */
77
- public incentives: Incentives;
78
-
79
- /**
80
- * The exit module, responsible for managing exit validation.
81
- * @type {Exit}
82
- */
83
- public exit: Exit;
84
-
85
- /**
86
- * The splits module, responsible for managing splits.
87
- * @type {ObolSplits}
88
- */
89
- public splits: ObolSplits;
90
-
91
- /**
92
- * The eoa module, responsible for managing EOA operations.
93
- * @type {EOA}
94
- */
95
- public eoa: EOA;
96
-
97
- /**
98
- * The blockchain provider, used to interact with the network.
99
- * It can be null, undefined, or a valid provider instance and defaults to the Signer provider if Signer is passed.
100
- */
101
- public provider: ProviderType | undefined | null;
102
-
103
- /**
104
- * @param config - Client configurations
105
- * @param config.baseUrl - obol-api url
106
- * @param config.chainId - Blockchain network ID
107
- * @param signer - ethersJS Signer
108
- * @returns Obol-SDK Client instance
109
- *
110
- * An example of how to instantiate obol-sdk Client:
111
- * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
112
- */
113
- constructor(
114
- config: { baseUrl?: string; chainId?: number },
115
- signer?: SignerType,
116
- provider?: ProviderType,
117
- ) {
118
- super(config);
119
- this.signer = signer;
120
- // Use the provided provider, or fall back to signer.provider if available
121
- this.provider =
122
- provider ??
123
- (signer && 'provider' in signer ? signer.provider : undefined);
124
- this.incentives = new Incentives(
125
- this.signer,
126
- this.chainId,
127
- this.request.bind(this),
128
- this.provider,
129
- );
130
- this.exit = new Exit(this.chainId, this.provider);
131
- this.splits = new ObolSplits(this.signer, this.chainId, this.provider);
132
- this.eoa = new EOA(this.signer, this.chainId, this.provider);
133
- }
134
-
135
- /**
136
- * Accepts Obol terms and conditions to be able to create or update data.
137
- * @returns {Promise<string>} terms and conditions acceptance success message.
138
- * @throws On unverified signature or wrong hash.
139
- *
140
- * An example of how to use acceptObolLatestTermsAndConditions:
141
- * [acceptObolLatestTermsAndConditions](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L44)
142
- */
143
- async acceptObolLatestTermsAndConditions(): Promise<string> {
144
- if (!this.signer) {
145
- throw new Error('Signer is required in acceptObolTermsAndConditions');
146
- }
147
-
148
- try {
149
- const termsAndConditionsHash = TERMS_AND_CONDITIONS_HASH;
150
- const address = await this.signer.getAddress();
151
- const termsAndConditionsPayload = {
152
- address,
153
- version: TERMS_AND_CONDITIONS_VERSION,
154
- terms_and_conditions_hash: termsAndConditionsHash,
155
- fork_version: this.fork_version,
156
- };
157
-
158
- const termsAndConditionsSignature = await this.signer.signTypedData(
159
- Domain(),
160
- TermsAndConditionsSigningTypes,
161
- {
162
- terms_and_conditions_hash: termsAndConditionsHash,
163
- version: TERMS_AND_CONDITIONS_VERSION,
164
- },
165
- );
166
-
167
- const termsAndConditionsResponse: { message: string; success: boolean } =
168
- await this.request(`/${DEFAULT_BASE_VERSION}/termsAndConditions`, {
169
- method: 'POST',
170
- body: JSON.stringify(termsAndConditionsPayload),
171
- headers: {
172
- Authorization: `Bearer ${termsAndConditionsSignature}`,
173
- },
174
- });
175
- return termsAndConditionsResponse?.message;
176
- } catch (err: any) {
177
- if (err?.message === CONFLICT_ERROR_MSG) {
178
- throw new ConflictError();
179
- }
180
- throw err;
181
- }
182
- }
183
-
184
- /**
185
- * Deploys OWR and Splitter Proxy.
186
- *
187
- * @remarks
188
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
189
- * and not pushed to version control.
190
- *
191
- * @param {RewardsSplitPayload} rewardsSplitPayload - Data needed to deploy owr and splitter.
192
- * @returns {Promise<ClusterValidator>} owr address as withdrawal address and splitter as fee recipient
193
- *
194
- * An example of how to use createObolRewardsSplit:
195
- * [createObolRewardsSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L141)
196
- */
197
- // add the example reference
198
- async createObolRewardsSplit({
199
- splitRecipients,
200
- principalRecipient,
201
- etherAmount,
202
- ObolRAFSplit = DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
203
- distributorFee,
204
- controllerAddress,
205
- recoveryAddress,
206
- }: RewardsSplitPayload): Promise<ClusterValidator> {
207
- // This method doesnt require T&C signature
208
- if (!this.signer) {
209
- throw new Error('Signer is required in createObolRewardsSplit');
210
- }
211
-
212
- const validatedPayload = validatePayload<Required<RewardsSplitPayload>>(
213
- {
214
- splitRecipients,
215
- principalRecipient,
216
- etherAmount,
217
- ObolRAFSplit,
218
- distributorFee,
219
- controllerAddress,
220
- recoveryAddress,
221
- },
222
- rewardsSplitterPayloadSchema,
223
- );
224
-
225
- // Check if we allow splitters on this chainId
226
- if (!isChainSupportedForSplitters(this.chainId)) {
227
- throw new Error(
228
- `Splitter configuration is not supported on ${this.chainId} chain`,
229
- );
230
- }
231
-
232
- const chainConfig = CHAIN_CONFIGURATION[this.chainId];
233
- if (!chainConfig?.SPLITMAIN_CONTRACT) {
234
- throw new Error(
235
- `SPLITMAIN_CONTRACT is not configured for chain ${this.chainId}`,
236
- );
237
- }
238
-
239
- const checkSplitMainAddress = await isContractAvailable(
240
- chainConfig.SPLITMAIN_CONTRACT.address,
241
- this.signer.provider as ProviderType,
242
- chainConfig.SPLITMAIN_CONTRACT.bytecode,
243
- );
244
-
245
- const checkMulticall3Address = await isContractAvailable(
246
- chainConfig.MULTICALL3_CONTRACT.address,
247
- this.signer.provider as ProviderType,
248
- chainConfig.MULTICALL3_CONTRACT.bytecode,
249
- );
250
-
251
- const checkOWRFactoryAddress = await isContractAvailable(
252
- chainConfig.OWR_FACTORY_CONTRACT.address,
253
- this.signer.provider as ProviderType,
254
- chainConfig.OWR_FACTORY_CONTRACT.bytecode,
255
- );
256
-
257
- if (
258
- !checkMulticall3Address ||
259
- !checkSplitMainAddress ||
260
- !checkOWRFactoryAddress
261
- ) {
262
- throw new Error(
263
- `Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`,
264
- );
265
- }
266
-
267
- const retroActiveFundingRecipient = {
268
- account: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
269
- percentAllocation: validatedPayload.ObolRAFSplit,
270
- };
271
-
272
- const copiedSplitRecipients = [...validatedPayload.splitRecipients];
273
- copiedSplitRecipients.push(retroActiveFundingRecipient);
274
-
275
- const { accounts, percentAllocations } = formatSplitRecipients(
276
- copiedSplitRecipients,
277
- );
278
-
279
- const predictedSplitterAddress = await predictSplitterAddress({
280
- signer: this.signer,
281
- accounts,
282
- percentAllocations,
283
- chainId: this.chainId,
284
- distributorFee: validatedPayload.distributorFee,
285
- controllerAddress: validatedPayload.controllerAddress,
286
- });
287
-
288
- const isSplitterDeployed = await isContractAvailable(
289
- predictedSplitterAddress,
290
- this.signer.provider as ProviderType,
291
- );
292
-
293
- const { withdrawal_address, fee_recipient_address } =
294
- await handleDeployOWRAndSplitter({
295
- signer: this.signer,
296
- isSplitterDeployed: !!isSplitterDeployed,
297
- predictedSplitterAddress,
298
- accounts,
299
- percentAllocations,
300
- principalRecipient: validatedPayload.principalRecipient,
301
- etherAmount: validatedPayload.etherAmount,
302
- chainId: this.chainId,
303
- distributorFee: validatedPayload.distributorFee,
304
- controllerAddress: validatedPayload.controllerAddress,
305
- recoveryAddress: validatedPayload.recoveryAddress,
306
- });
307
-
308
- return { withdrawal_address, fee_recipient_address };
309
- }
310
-
311
- /**
312
- * Deploys Splitter Proxy.
313
- *
314
- * @remarks
315
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
316
- * and not pushed to version control.
317
- *
318
- * @param {TotalSplitPayload} totalSplitPayload - Data needed to deploy splitter if it doesnt exist.
319
- * @returns {Promise<ClusterValidator>} splitter address as withdrawal address and splitter as fee recipient too
320
- *
321
- * An example of how to use createObolTotalSplit:
322
- * [createObolTotalSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L168)
323
- */
324
- // add the example reference
325
- async createObolTotalSplit({
326
- splitRecipients,
327
- ObolRAFSplit,
328
- distributorFee,
329
- controllerAddress,
330
- }: TotalSplitPayload): Promise<ClusterValidator> {
331
- // This method doesnt require T&C signature
332
- if (!this.signer) {
333
- throw new Error('Signer is required in createObolTotalSplit');
334
- }
335
-
336
- const validatedPayload = validatePayload<Required<TotalSplitPayload>>(
337
- {
338
- splitRecipients,
339
- ObolRAFSplit,
340
- distributorFee,
341
- controllerAddress,
342
- },
343
- totalSplitterPayloadSchema,
344
- );
345
-
346
- // Check if we allow splitters on this chainId
347
- if (!isChainSupportedForSplitters(this.chainId)) {
348
- throw new Error(
349
- `Splitter configuration is not supported on ${this.chainId} chain`,
350
- );
351
- }
352
-
353
- const chainConfig = CHAIN_CONFIGURATION[this.chainId];
354
- if (!chainConfig?.SPLITMAIN_CONTRACT) {
355
- throw new Error(
356
- `SPLITMAIN_CONTRACT is not configured for chain ${this.chainId}`,
357
- );
358
- }
359
-
360
- const checkSplitMainAddress = await isContractAvailable(
361
- chainConfig.SPLITMAIN_CONTRACT.address,
362
- this.signer.provider as ProviderType,
363
- chainConfig.SPLITMAIN_CONTRACT.bytecode,
364
- );
365
-
366
- if (!checkSplitMainAddress) {
367
- throw new Error(
368
- `Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`,
369
- );
370
- }
371
-
372
- const retroActiveFundingRecipient = {
373
- account: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
374
- percentAllocation: validatedPayload.ObolRAFSplit,
375
- };
376
-
377
- const copiedSplitRecipients = [...validatedPayload.splitRecipients];
378
- copiedSplitRecipients.push(retroActiveFundingRecipient);
379
-
380
- const { accounts, percentAllocations } = formatSplitRecipients(
381
- copiedSplitRecipients,
382
- );
383
-
384
- const predictedSplitterAddress = await predictSplitterAddress({
385
- signer: this.signer,
386
- accounts,
387
- percentAllocations,
388
- chainId: this.chainId,
389
- distributorFee: validatedPayload.distributorFee,
390
- controllerAddress: validatedPayload.controllerAddress,
391
- });
392
-
393
- const isSplitterDeployed = await isContractAvailable(
394
- predictedSplitterAddress,
395
- this.signer.provider as ProviderType,
396
- );
397
-
398
- if (!isSplitterDeployed) {
399
- const splitterAddress = await deploySplitterContract({
400
- signer: this.signer,
401
- accounts,
402
- percentAllocations,
403
- chainId: this.chainId,
404
- distributorFee: validatedPayload.distributorFee,
405
- controllerAddress: validatedPayload.controllerAddress,
406
- });
407
- return {
408
- withdrawal_address: splitterAddress,
409
- fee_recipient_address: splitterAddress,
410
- };
411
- }
412
-
413
- return {
414
- withdrawal_address: predictedSplitterAddress,
415
- fee_recipient_address: predictedSplitterAddress,
416
- };
417
- }
418
-
419
- /**
420
- * Read OWR Tranches.
421
- *
422
- * @remarks
423
- * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
424
- * and not pushed to version control.
425
- *
426
- * @param {ETH_ADDRESS} owrAddress - Address of the Deployed OWR Contract
427
- * @returns {Promise<OWRTranches>} owr tranch information about principal and reward reciepient, as well as the principal amount
428
- *
429
- */
430
- async getOWRTranches(owrAddress: ETH_ADDRESS): Promise<OWRTranches> {
431
- if (!this.signer) {
432
- throw new Error('Signer is required in getOWRTranches');
433
- }
434
-
435
- const signer = this.signer;
436
- return await getOWRTranches({ owrAddress, signer });
437
- }
438
-
439
- /**
440
- * Creates a cluster definition which contains cluster configuration.
441
- * @param {ClusterPayload} newCluster - The new unique cluster.
442
- * @returns {Promise<string>} config_hash.
443
- * @throws On duplicate entries, missing or wrong cluster keys.
444
- *
445
- * An example of how to use createClusterDefinition:
446
- * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L59)
447
- */
448
- async createClusterDefinition(newCluster: ClusterPayload): Promise<string> {
449
- if (!this.signer) {
450
- throw new Error('Signer is required in createClusterDefinition');
451
- }
452
-
453
- const validatedCluster = validatePayload<ClusterPayload>(
454
- newCluster,
455
- definitionSchema,
456
- );
457
-
458
- const clusterConfig: Partial<ClusterDefinition> = {
459
- ...validatedCluster,
460
- fork_version: this.fork_version,
461
- dkg_algorithm: DKG_ALGORITHM,
462
- version: CONFIG_VERSION,
463
- uuid: uuidv4(),
464
- timestamp: new Date().toISOString(),
465
- threshold: Math.ceil((2 * validatedCluster.operators.length) / 3),
466
- num_validators: validatedCluster.validators.length,
467
- };
468
- try {
469
- const address = await this.signer.getAddress();
470
-
471
- clusterConfig.creator = { address };
472
- clusterConfig.config_hash = clusterConfigOrDefinitionHash(
473
- clusterConfig as ClusterDefinition,
474
- true,
475
- );
476
-
477
- const creatorConfigSignature = await this.signer.signTypedData(
478
- Domain(this.chainId),
479
- CreatorConfigHashSigningTypes,
480
- { creator_config_hash: clusterConfig.config_hash },
481
- );
482
-
483
- const clusterDefinition: ClusterDefinition = await this.request(
484
- `/${DEFAULT_BASE_VERSION}/definition`,
485
- {
486
- method: 'POST',
487
- body: JSON.stringify(clusterConfig),
488
- headers: {
489
- Authorization: `Bearer ${creatorConfigSignature}`,
490
- 'fork-version': this.fork_version,
491
- },
492
- },
493
- );
494
- return clusterDefinition?.config_hash;
495
- } catch (err: any) {
496
- if (err?.message === CONFLICT_ERROR_MSG) {
497
- throw new ConflictError();
498
- }
499
- throw err;
500
- }
501
- }
502
-
503
- /**
504
- * Approves joining a cluster with specific configuration.
505
- * @param {OperatorPayload} operatorPayload - The operator data including signatures.
506
- * @param {string} configHash - The config hash of the cluster which the operator confirms joining to.
507
- * @returns {Promise<ClusterDefinition>} The cluster definition.
508
- * @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
509
- *
510
- * An example of how to use acceptClusterDefinition:
511
- * [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L106)
512
- */
513
- async acceptClusterDefinition(
514
- operatorPayload: OperatorPayload,
515
- configHash: string,
516
- ): Promise<ClusterDefinition> {
517
- if (!this.signer) {
518
- throw new Error('Signer is required in acceptClusterDefinition');
519
- }
520
-
521
- const validatedPayload = validatePayload<OperatorPayload>(
522
- operatorPayload,
523
- operatorPayloadSchema,
524
- );
525
-
526
- try {
527
- const address = await this.signer.getAddress();
528
-
529
- const operatorConfigSignature = await this.signer.signTypedData(
530
- Domain(this.chainId),
531
- OperatorConfigHashSigningTypes,
532
- { operator_config_hash: configHash },
533
- );
534
- const operatorENRSignature = await this.signer.signTypedData(
535
- Domain(this.chainId),
536
- EnrSigningTypes,
537
- { enr: validatedPayload.enr },
538
- );
539
-
540
- const operatorData: OperatorPayload = {
541
- ...validatedPayload,
542
- address,
543
- enr_signature: operatorENRSignature,
544
- fork_version: this.fork_version,
545
- };
546
- const clusterDefinition: ClusterDefinition = await this.request(
547
- `/${DEFAULT_BASE_VERSION}/definition/${configHash}`,
548
- {
549
- method: 'PUT',
550
- body: JSON.stringify(operatorData),
551
- headers: {
552
- Authorization: `Bearer ${operatorConfigSignature}`,
553
- },
554
- },
555
- );
556
- return clusterDefinition;
557
- } catch (err: any) {
558
- throw err;
559
- }
560
- }
561
-
562
- /**
563
- * @param configHash - The configuration hash returned in createClusterDefinition
564
- * @returns {Promise<ClusterDefinition>} The cluster definition for config hash
565
- * @throws On not found config hash.
566
- *
567
- * An example of how to use getClusterDefinition:
568
- * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L74)
569
- */
570
- async getClusterDefinition(configHash: string): Promise<ClusterDefinition> {
571
- const clusterDefinition: ClusterDefinition = await this.request(
572
- `/${DEFAULT_BASE_VERSION}/definition/${configHash}`,
573
- {
574
- method: 'GET',
575
- },
576
- );
577
-
578
- return clusterDefinition;
579
- }
580
-
581
- /**
582
- * @param configHash - The configuration hash in cluster-definition
583
- * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
584
- * @throws On not found cluster definition or lock.
585
- *
586
- * An example of how to use getClusterLock:
587
- * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L89)
588
- */
589
- async getClusterLock(configHash: string): Promise<ClusterLock> {
590
- const lock: ClusterLock = await this.request(
591
- `/${DEFAULT_BASE_VERSION}/lock/configHash/${configHash}`,
592
- {
593
- method: 'GET',
594
- },
595
- );
596
- return lock;
597
- }
598
-
599
- /**
600
- * @param lockHash - The configuration hash in cluster-definition
601
- * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
602
- * @throws On not found cluster definition or lock.
603
- *
604
- */
605
- async getClusterLockByHash(lockHash: string): Promise<ClusterLock> {
606
- const lock: ClusterLock = await this.request(
607
- `/${DEFAULT_BASE_VERSION}/lock/${lockHash}`,
608
- {
609
- method: 'GET',
610
- },
611
- );
612
- return lock;
613
- }
614
- }