@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,418 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var _a, _b;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const ethers_1 = require("ethers");
37
+ const index_1 = require("../../src/index");
38
+ const fixtures_js_1 = require("../fixtures.js");
39
+ const constants_1 = require("../../src/constants");
40
+ const base_1 = require("../../src/base");
41
+ const msw_1 = require("msw");
42
+ const node_1 = require("msw/node");
43
+ const termsAndConditions_1 = require("../../src/verification/termsAndConditions");
44
+ const utils = __importStar(require("../../src/utils"));
45
+ const splitsHelpers = __importStar(require("../../src/splits/splitHelpers"));
46
+ jest.setTimeout(20000);
47
+ const mnemonic = (_b = (_a = ethers_1.ethers.Wallet.createRandom().mnemonic) === null || _a === void 0 ? void 0 : _a.phrase) !== null && _b !== void 0 ? _b : '';
48
+ const privateKey = ethers_1.ethers.Wallet.fromPhrase(mnemonic).privateKey;
49
+ const provider = new ethers_1.JsonRpcProvider('https://ethereum-holesky.publicnode.com');
50
+ const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
51
+ const mockSigner = wallet.connect(provider);
52
+ /* eslint no-new: 0 */
53
+ describe('Cluster Client', () => {
54
+ const mockConfigHash = '0x1f6c94e6c070393a68c1aa6073a21cb1fd57f0e14d2a475a2958990ab728c2fd';
55
+ const clientInstance = new index_1.Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
56
+ test('createTermsAndConditions should return "successful authorization"', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ clientInstance['request'] = jest
58
+ .fn()
59
+ .mockReturnValue(Promise.resolve({ message: 'successful authorization' }));
60
+ const isAuthorized = yield clientInstance.acceptObolLatestTermsAndConditions();
61
+ expect(isAuthorized).toEqual('successful authorization');
62
+ }));
63
+ test('createClusterDefinition should return config_hash', () => __awaiter(void 0, void 0, void 0, function* () {
64
+ clientInstance['request'] = jest
65
+ .fn()
66
+ .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
67
+ const configHash = yield clientInstance.createClusterDefinition(fixtures_js_1.clusterConfigV1X10);
68
+ expect(configHash).toEqual(mockConfigHash);
69
+ }));
70
+ test('acceptClusterDefinition should return cluster definition', () => __awaiter(void 0, void 0, void 0, function* () {
71
+ clientInstance['request'] = jest
72
+ .fn()
73
+ .mockReturnValue(Promise.resolve(fixtures_js_1.clusterLockV1X10.cluster_definition));
74
+ const clusterDefinition = yield clientInstance.acceptClusterDefinition({
75
+ enr: fixtures_js_1.clusterLockV1X10.cluster_definition.operators[0].enr,
76
+ version: fixtures_js_1.clusterLockV1X10.cluster_definition.version,
77
+ }, fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
78
+ expect(clusterDefinition).toEqual(fixtures_js_1.clusterLockV1X10.cluster_definition);
79
+ }));
80
+ test('createClusterDefinition should throw an error on invalid operators', () => __awaiter(void 0, void 0, void 0, function* () {
81
+ clientInstance['request'] = jest
82
+ .fn()
83
+ .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
84
+ try {
85
+ yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, fixtures_js_1.clusterConfigV1X10), { operators: [] }));
86
+ }
87
+ catch (error) {
88
+ expect(error.message).toEqual('Validation failed: /operators must pass "validateUniqueAddresses" keyword validation, /operators must NOT have fewer than 4 items');
89
+ }
90
+ }));
91
+ // cause we default to null
92
+ test('createClusterDefinition should accept a configuration without deposit_amounts', () => __awaiter(void 0, void 0, void 0, function* () {
93
+ clientInstance['request'] = jest
94
+ .fn()
95
+ .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
96
+ const configHash = yield clientInstance.createClusterDefinition(Object.assign({}, fixtures_js_1.clusterConfigV1X7));
97
+ expect(configHash).toEqual(mockConfigHash);
98
+ }));
99
+ test('createClusterDefinition should throw on not valid deposit_amounts ', () => __awaiter(void 0, void 0, void 0, function* () {
100
+ clientInstance['request'] = jest
101
+ .fn()
102
+ .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
103
+ try {
104
+ yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, fixtures_js_1.clusterConfigV1X7), { deposit_amounts: ['34000000'] }));
105
+ }
106
+ catch (error) {
107
+ expect(error.message).toEqual('Validation failed: /deposit_amounts/0 must be equal to one of the allowed values, /deposit_amounts must match "then" schema');
108
+ }
109
+ }));
110
+ test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
111
+ clientInstance['request'] = jest
112
+ .fn()
113
+ .mockReturnValue(Promise.resolve(fixtures_js_1.clusterLockV1X10.cluster_definition));
114
+ const clusterDefinition = yield clientInstance.getClusterDefinition(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
115
+ expect(clusterDefinition.deposit_amounts).toBeDefined();
116
+ expect(clusterDefinition.config_hash).toEqual(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
117
+ // Test for new fields
118
+ expect(clusterDefinition.compounding).toBeDefined();
119
+ expect(clusterDefinition.target_gas_limit).toBeDefined();
120
+ expect(clusterDefinition.consensus_protocol).toBeDefined();
121
+ }));
122
+ test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
123
+ clientInstance['request'] = jest
124
+ .fn()
125
+ .mockReturnValue(Promise.resolve(fixtures_js_1.clusterLockV1X10));
126
+ const clusterLock = yield clientInstance.getClusterLock(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
127
+ expect(clusterLock.lock_hash).toEqual(fixtures_js_1.clusterLockV1X10.lock_hash);
128
+ }));
129
+ test('request method should set user agent header', () => __awaiter(void 0, void 0, void 0, function* () {
130
+ const server = (0, node_1.setupServer)(msw_1.http.get('http://testexample.com/test', ({ request }) => {
131
+ // Check if the request contains specific headers
132
+ if (request.headers.get('User-Agent') === `Obol-SDK/${constants_1.SDK_VERSION}`) {
133
+ return msw_1.HttpResponse.json({ message: 'user-agent header exist' });
134
+ }
135
+ }));
136
+ server.listen();
137
+ class TestBase extends base_1.Base {
138
+ callProtectedRequest(endpoint, options) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ return yield this['request'](endpoint, options);
141
+ });
142
+ }
143
+ }
144
+ const testBaseInstance = new TestBase({
145
+ baseUrl: 'http://testExample.com',
146
+ });
147
+ const result = yield testBaseInstance.callProtectedRequest('/test', {
148
+ method: 'GET',
149
+ });
150
+ expect(result === null || result === void 0 ? void 0 : result.message).toEqual('user-agent header exist');
151
+ server.close();
152
+ }));
153
+ });
154
+ describe('Cluster Client without a signer', () => {
155
+ const clientInstance = new index_1.Client({
156
+ baseUrl: 'https://obol-api-dev.gcp.obol.tech',
157
+ chainId: 17000,
158
+ });
159
+ beforeAll(() => {
160
+ jest.restoreAllMocks();
161
+ });
162
+ beforeEach(() => {
163
+ jest.resetModules();
164
+ });
165
+ test('createClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
166
+ try {
167
+ yield clientInstance.createClusterDefinition(fixtures_js_1.clusterConfigV1X10);
168
+ }
169
+ catch (err) {
170
+ expect(err.message).toEqual('Signer is required in createClusterDefinition');
171
+ }
172
+ }));
173
+ test('acceptClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
174
+ try {
175
+ yield clientInstance.acceptClusterDefinition({
176
+ enr: fixtures_js_1.clusterLockV1X10.cluster_definition.operators[0].enr,
177
+ version: fixtures_js_1.clusterLockV1X10.cluster_definition.version,
178
+ }, fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
179
+ }
180
+ catch (err) {
181
+ expect(err.message).toEqual('Signer is required in acceptClusterDefinition');
182
+ }
183
+ }));
184
+ test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
185
+ clientInstance['request'] = jest
186
+ .fn()
187
+ .mockReturnValue(Promise.resolve(fixtures_js_1.clusterLockV1X10.cluster_definition));
188
+ const clusterDefinition = yield clientInstance.getClusterDefinition(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
189
+ expect(clusterDefinition.config_hash).toEqual(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
190
+ }));
191
+ test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
192
+ clientInstance['request'] = jest
193
+ .fn()
194
+ .mockReturnValue(Promise.resolve(fixtures_js_1.clusterLockV1X10));
195
+ const clusterLock = yield clientInstance.getClusterLock(fixtures_js_1.clusterLockV1X10.cluster_definition.config_hash);
196
+ expect(clusterLock.lock_hash).toEqual(fixtures_js_1.clusterLockV1X10.lock_hash);
197
+ }));
198
+ test.each([
199
+ { version: 'v1.6.0', clusterLock: fixtures_js_1.clusterLockV1X6 },
200
+ { version: 'v1.7.0', clusterLock: fixtures_js_1.clusterLockV1X7 },
201
+ { version: 'v1.8.0', clusterLock: fixtures_js_1.clusterLockV1X8 },
202
+ {
203
+ version: 'null deposit_amounts v1.8.0',
204
+ clusterLock: fixtures_js_1.nullDepositAmountsClusterLockV1X8,
205
+ },
206
+ {
207
+ version: 'Cluster with safe address v1.8.0',
208
+ clusterLock: fixtures_js_1.clusterLockWithSafe,
209
+ },
210
+ { version: 'v1.10.0', clusterLock: fixtures_js_1.clusterLockV1X10 },
211
+ {
212
+ version: 'v1.10.0 with compunding withdrawals',
213
+ clusterLock: fixtures_js_1.clusterLockWithCompoundingWithdrawals,
214
+ },
215
+ ])("$version: 'should return true on verified cluster lock'", ({ clusterLock }) => __awaiter(void 0, void 0, void 0, function* () {
216
+ const isValidLock = yield (0, index_1.validateClusterLock)(clusterLock);
217
+ expect(isValidLock).toEqual(true);
218
+ }));
219
+ test('should return true on verified cluster lock with Safe wallet and safe rpc url', () => __awaiter(void 0, void 0, void 0, function* () {
220
+ process.env.RPC_HOLESKY = undefined;
221
+ /* eslint-disable @typescript-eslint/no-var-requires */
222
+ const { validateClusterLock: validateLockWithRpcUrl, } = require('../../src/index');
223
+ const safeRpcUrl = 'https://ethereum-holesky-rpc.publicnode.com';
224
+ const isValidLock = yield validateLockWithRpcUrl(fixtures_js_1.clusterLockWithSafe, safeRpcUrl);
225
+ expect(isValidLock).toEqual(true);
226
+ }));
227
+ test('validateCluster should return false for cluster with null deposit_amounts and incorrect partial_deposits', () => __awaiter(void 0, void 0, void 0, function* () {
228
+ const partialDeposit = fixtures_js_1.nullDepositAmountsClusterLockV1X8.distributed_validators[0]
229
+ .partial_deposit_data[0];
230
+ const isValidLock = yield (0, index_1.validateClusterLock)(Object.assign(Object.assign({}, fixtures_js_1.nullDepositAmountsClusterLockV1X8), { distributed_validators: [
231
+ Object.assign(Object.assign({}, fixtures_js_1.nullDepositAmountsClusterLockV1X8.distributed_validators[0]), { partial_deposit_data: [partialDeposit, partialDeposit] }),
232
+ ] }));
233
+ expect(isValidLock).toEqual(false);
234
+ }));
235
+ test('Finds the hash of the latest version of terms and conditions', () => __awaiter(void 0, void 0, void 0, function* () {
236
+ const termsAndConditionsHash = yield (0, termsAndConditions_1.hashTermsAndConditions)();
237
+ expect(termsAndConditionsHash).toEqual('0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273');
238
+ }));
239
+ });
240
+ describe('createObolRewardsSplit', () => {
241
+ let clientInstance, clientInstanceWithourSigner, mockSplitRecipients, mockPrincipalRecipient, mockEtherAmount;
242
+ beforeAll(() => {
243
+ jest
244
+ .spyOn(utils, 'isContractAvailable')
245
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
246
+ jest
247
+ .spyOn(splitsHelpers, 'predictSplitterAddress')
248
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
249
+ jest.spyOn(splitsHelpers, 'handleDeployOWRAndSplitter').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
250
+ return yield Promise.resolve({
251
+ withdrawal_address: '0xWithdrawalAddress',
252
+ fee_recipient_address: '0xFeeRecipientAddress',
253
+ });
254
+ }));
255
+ clientInstance = new index_1.Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
256
+ clientInstanceWithourSigner = new index_1.Client({
257
+ baseUrl: 'https://obol-api-dev.gcp.obol.tech',
258
+ chainId: 17000,
259
+ });
260
+ mockSplitRecipients = [
261
+ {
262
+ account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
263
+ percentAllocation: 99,
264
+ },
265
+ ];
266
+ mockPrincipalRecipient = '0x86B8145c98e5BD25BA722645b15eD65f024a87EC';
267
+ mockEtherAmount = 64;
268
+ });
269
+ it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
270
+ yield expect(clientInstanceWithourSigner.createObolRewardsSplit({
271
+ splitRecipients: mockSplitRecipients,
272
+ principalRecipient: mockPrincipalRecipient,
273
+ etherAmount: mockEtherAmount,
274
+ })).rejects.toThrow('Signer is required in createObolRewardsSplit');
275
+ }));
276
+ it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
277
+ const unsupportedSplitterChainClient = new index_1.Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
278
+ try {
279
+ yield unsupportedSplitterChainClient.createObolRewardsSplit({
280
+ splitRecipients: mockSplitRecipients,
281
+ principalRecipient: mockPrincipalRecipient,
282
+ etherAmount: mockEtherAmount,
283
+ });
284
+ }
285
+ catch (error) {
286
+ expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
287
+ }
288
+ }));
289
+ test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
290
+ try {
291
+ yield clientInstance.createObolRewardsSplit({
292
+ splitRecipients: [
293
+ {
294
+ account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
295
+ percentAllocation: 22,
296
+ },
297
+ ],
298
+ principalRecipient: mockPrincipalRecipient,
299
+ etherAmount: mockEtherAmount,
300
+ });
301
+ }
302
+ catch (error) {
303
+ expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation');
304
+ }
305
+ }));
306
+ test('should throw an error if ObolRAFSplit is less than 1', () => __awaiter(void 0, void 0, void 0, function* () {
307
+ try {
308
+ yield clientInstance.createObolRewardsSplit({
309
+ splitRecipients: mockSplitRecipients,
310
+ principalRecipient: mockPrincipalRecipient,
311
+ etherAmount: mockEtherAmount,
312
+ ObolRAFSplit: 0.5,
313
+ });
314
+ }
315
+ catch (error) {
316
+ expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation, /ObolRAFSplit must be >= 1');
317
+ }
318
+ }));
319
+ it('should return the correct withdrawal and fee recipient addresses', () => __awaiter(void 0, void 0, void 0, function* () {
320
+ const result = yield clientInstance.createObolRewardsSplit({
321
+ splitRecipients: mockSplitRecipients,
322
+ principalRecipient: mockPrincipalRecipient,
323
+ etherAmount: mockEtherAmount,
324
+ });
325
+ expect(result).toEqual({
326
+ withdrawal_address: '0xWithdrawalAddress',
327
+ fee_recipient_address: '0xFeeRecipientAddress',
328
+ });
329
+ }));
330
+ });
331
+ describe('createObolTotalSplit', () => {
332
+ let clientInstanceWithourSigner, mockSplitRecipients, clientInstance;
333
+ beforeAll(() => {
334
+ jest
335
+ .spyOn(utils, 'isContractAvailable')
336
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
337
+ jest
338
+ .spyOn(splitsHelpers, 'predictSplitterAddress')
339
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
340
+ jest
341
+ .spyOn(splitsHelpers, 'deploySplitterContract')
342
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xSplitterAddress'); }));
343
+ clientInstance = new index_1.Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
344
+ clientInstanceWithourSigner = new index_1.Client({
345
+ baseUrl: 'https://obol-api-dev.gcp.obol.tech',
346
+ chainId: 17000,
347
+ });
348
+ mockSplitRecipients = [
349
+ {
350
+ account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
351
+ percentAllocation: 99.9,
352
+ },
353
+ ];
354
+ });
355
+ it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
356
+ yield expect(clientInstanceWithourSigner.createObolTotalSplit({
357
+ splitRecipients: mockSplitRecipients,
358
+ })).rejects.toThrow('Signer is required in createObolTotalSplit');
359
+ }));
360
+ it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
361
+ const unsupportedSplitterChainClient = new index_1.Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
362
+ try {
363
+ yield unsupportedSplitterChainClient.createObolTotalSplit({
364
+ splitRecipients: mockSplitRecipients,
365
+ });
366
+ }
367
+ catch (error) {
368
+ expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
369
+ }
370
+ }));
371
+ test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
372
+ try {
373
+ yield clientInstance.createObolTotalSplit({
374
+ splitRecipients: [
375
+ {
376
+ account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
377
+ percentAllocation: 22,
378
+ },
379
+ ],
380
+ });
381
+ }
382
+ catch (error) {
383
+ expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation');
384
+ }
385
+ }));
386
+ test('should throw an error if ObolRAFSplit is less than 0.1', () => __awaiter(void 0, void 0, void 0, function* () {
387
+ try {
388
+ yield clientInstance.createObolTotalSplit({
389
+ splitRecipients: mockSplitRecipients,
390
+ ObolRAFSplit: 0.05,
391
+ });
392
+ }
393
+ catch (error) {
394
+ expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation, /ObolRAFSplit must be >= 0.1');
395
+ }
396
+ }));
397
+ it('should return the correct withdrawal and fee recipient addresses and ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
398
+ const result = yield clientInstance.createObolTotalSplit({
399
+ splitRecipients: mockSplitRecipients,
400
+ ObolRAFSplit: 0.1,
401
+ });
402
+ // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
403
+ expect(result).toEqual({
404
+ withdrawal_address: '0xPredictedAddress',
405
+ fee_recipient_address: '0xPredictedAddress',
406
+ });
407
+ }));
408
+ it('should return the correct withdrawal and fee recipient addresses without passing ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
409
+ const result = yield clientInstance.createObolTotalSplit({
410
+ splitRecipients: mockSplitRecipients,
411
+ });
412
+ // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
413
+ expect(result).toEqual({
414
+ withdrawal_address: '0xPredictedAddress',
415
+ fee_recipient_address: '0xPredictedAddress',
416
+ });
417
+ }));
418
+ });
@@ -44,7 +44,7 @@ const verificationHelpers = __importStar(require("../../src/exits/verificationHe
44
44
  jest.mock('../../src/exits/ethUtils');
45
45
  jest.mock('@chainsafe/bls', () => {
46
46
  const actual = jest.requireActual('@chainsafe/bls');
47
- return Object.assign(Object.assign({ __esModule: true }, actual), { init: jest.fn(), verify: jest.fn() });
47
+ return Object.assign(Object.assign({ __esModule: true }, actual), { init: jest.fn(), verify: jest.fn(), aggregateSignatures: jest.fn() });
48
48
  });
49
49
  // ENR and elliptic will be spied on, not fully mocked at module level for more flexibility
50
50
  const mockedEthUtils = ethUtils;
@@ -323,6 +323,77 @@ describe('exit', () => {
323
323
  yield expect(exit.validateExitBlobs(clusterConfigWithMissingShare, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Public share for operator index 0 not found for validator 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd');
324
324
  }));
325
325
  });
326
- // Add other tests for different scenarios: epoch mismatch, already exited, etc.
327
- // Consider testing the case where getExistingBlobData throws an error
326
+ describe('recombineExitBlobs', () => {
327
+ it('should successfully recombine signatures into a single exit blob', () => __awaiter(void 0, void 0, void 0, function* () {
328
+ const mockExistingBlob = {
329
+ public_key: '0x' + '1234'.repeat(24),
330
+ epoch: '100',
331
+ validator_index: '200',
332
+ shares_exit_data: [
333
+ {
334
+ 0: { partial_exit_signature: '0x' + 'a0'.repeat(96) },
335
+ 2: { partial_exit_signature: '0x' + 'a2'.repeat(96) }, // Note non-sequential indices
336
+ 1: { partial_exit_signature: '0x' + 'a1'.repeat(96) },
337
+ },
338
+ ],
339
+ };
340
+ const expectedAggregatedSig = '0x' + 'ff'.repeat(96);
341
+ const expectedAggregatedSigBytes = (0, ssz_1.fromHexString)(expectedAggregatedSig);
342
+ mockedBls.aggregateSignatures.mockReturnValue(expectedAggregatedSigBytes);
343
+ const result = yield exit.recombineExitBlobs(mockExistingBlob);
344
+ expect(mockedBls.init).toHaveBeenCalledWith('herumi');
345
+ expect(mockedBls.aggregateSignatures).toHaveBeenCalledTimes(1);
346
+ const calls = mockedBls.aggregateSignatures.mock.calls;
347
+ const rawSignatures = calls[0][0];
348
+ // Check if signatures were passed in sorted order of operator index
349
+ expect(rawSignatures[0]).toEqual((0, ssz_1.fromHexString)('a0'.repeat(96)));
350
+ expect(rawSignatures[1]).toEqual((0, ssz_1.fromHexString)('a1'.repeat(96)));
351
+ expect(rawSignatures[2]).toEqual((0, ssz_1.fromHexString)('a2'.repeat(96)));
352
+ expect(result).toEqual({
353
+ public_key: mockExistingBlob.public_key,
354
+ signed_exit_message: {
355
+ message: {
356
+ epoch: mockExistingBlob.epoch,
357
+ validator_index: mockExistingBlob.validator_index,
358
+ },
359
+ signature: expectedAggregatedSig,
360
+ },
361
+ });
362
+ }));
363
+ it('should throw if no valid signatures are found', () => __awaiter(void 0, void 0, void 0, function* () {
364
+ const mockExistingBlob = {
365
+ public_key: '0x' + '1234'.repeat(24),
366
+ epoch: '100',
367
+ validator_index: '200',
368
+ shares_exit_data: [
369
+ {
370
+ 0: { partial_exit_signature: '' }, // empty sig
371
+ },
372
+ ],
373
+ };
374
+ yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('No valid signatures found for aggregation');
375
+ }));
376
+ it('should throw on invalid signature length', () => __awaiter(void 0, void 0, void 0, function* () {
377
+ const mockExistingBlob = {
378
+ public_key: '0x' + '1234'.repeat(24),
379
+ epoch: '100',
380
+ validator_index: '200',
381
+ shares_exit_data: [
382
+ {
383
+ 0: { partial_exit_signature: '0x1234' },
384
+ },
385
+ ],
386
+ };
387
+ yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('Invalid signature length');
388
+ }));
389
+ it('should handle empty shares_exit_data', () => __awaiter(void 0, void 0, void 0, function* () {
390
+ const mockExistingBlob = {
391
+ public_key: '0x' + '1234'.repeat(24),
392
+ epoch: '100',
393
+ validator_index: '200',
394
+ shares_exit_data: [],
395
+ };
396
+ yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('No shares exit data available for aggregation');
397
+ }));
398
+ });
328
399
  });
@@ -1,6 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clusterLockWithCompoundingWithdrawalss = exports.clusterLockWithCompoundingWithdrawals = exports.clusterLockV1X10 = exports.soloClusterConfigV1X10 = exports.clusterConfigV1X10 = exports.clusterLockWithSafe = exports.nullDepositAmountsClusterLockV1X8 = exports.clusterLockV1X8 = exports.clusterLockV1X7 = exports.clusterConfigV1X7 = exports.clusterLockV1X6 = exports.enr = void 0;
3
+ exports.clusterLockWithCompoundingWithdrawalss = exports.clusterLockWithCompoundingWithdrawals = exports.clusterLockV1X10 = exports.soloClusterConfigV1X10 = exports.clusterConfigV1X10 = exports.clusterLockWithSafe = exports.nullDepositAmountsClusterLockV1X8 = exports.clusterLockV1X8 = exports.clusterLockV1X7 = exports.clusterConfigV1X7 = exports.clusterLockV1X6 = exports.enr = exports.TEST_ADDRESSES = void 0;
4
+ const ethers_1 = require("ethers");
5
+ // Test address constants for OVM splits
6
+ exports.TEST_ADDRESSES = {
7
+ REWARD_RECIPIENT_1: '0x1234567890123456789012345678901234567890',
8
+ REWARD_RECIPIENT_2: '0x2345678901234567890123456789012345678901',
9
+ PRINCIPAL_RECIPIENT_1: '0x3456789012345678901234567890123456789012',
10
+ PRINCIPAL_RECIPIENT_2: '0x4567890123456789012345678901234567890123',
11
+ OVM_OWNER: '0x5678901234567890123456789012345678901234',
12
+ SPLIT_OWNER: '0x6789012345678901234567890123456789012345',
13
+ PRINCIPAL_RECIPIENT: '0x7890123456789012345678901234567890123456',
14
+ ZERO_ADDRESS: ethers_1.ZeroAddress,
15
+ };
4
16
  exports.enr = 'enr:-HW4QLlrtMjFLGkFT1bwdGbvZQlH8hLi0M2g44JAxEYP3BZmYpcsy9Q56HPPD87fMucjvLv4-obEFacpsg0ehRilbHeAgmlkgnY0iXNlY3AyNTZrMaEDRaa5o2aSgqyFq_ERZcQTztrOij1mFtXX1bJuVI6ieak';
5
17
  // v1.6.0
6
18
  exports.clusterLockV1X6 = {