@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
@@ -1,393 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var _a, _b;
11
- import { ethers, JsonRpcProvider } from 'ethers';
12
- import { Client, validateClusterLock } from '../../src/index';
13
- import { clusterConfigV1X7, clusterConfigV1X10, clusterLockV1X10, clusterLockV1X6, clusterLockV1X7, clusterLockV1X8, clusterLockWithCompoundingWithdrawals, clusterLockWithSafe, nullDepositAmountsClusterLockV1X8, } from '../fixtures.js';
14
- import { SDK_VERSION } from '../../src/constants';
15
- import { Base } from '../../src/base';
16
- import { HttpResponse, http } from 'msw';
17
- import { setupServer } from 'msw/node';
18
- import { hashTermsAndConditions } from '../../src/verification/termsAndConditions';
19
- import * as utils from '../../src/utils';
20
- import * as splitsHelpers from '../../src/splits/splitHelpers';
21
- jest.setTimeout(20000);
22
- const mnemonic = (_b = (_a = ethers.Wallet.createRandom().mnemonic) === null || _a === void 0 ? void 0 : _a.phrase) !== null && _b !== void 0 ? _b : '';
23
- const privateKey = ethers.Wallet.fromPhrase(mnemonic).privateKey;
24
- const provider = new JsonRpcProvider('https://ethereum-holesky.publicnode.com');
25
- const wallet = new ethers.Wallet(privateKey, provider);
26
- const mockSigner = wallet.connect(provider);
27
- /* eslint no-new: 0 */
28
- describe('Cluster Client', () => {
29
- const mockConfigHash = '0x1f6c94e6c070393a68c1aa6073a21cb1fd57f0e14d2a475a2958990ab728c2fd';
30
- const clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
31
- test('createTermsAndConditions should return "successful authorization"', () => __awaiter(void 0, void 0, void 0, function* () {
32
- clientInstance['request'] = jest
33
- .fn()
34
- .mockReturnValue(Promise.resolve({ message: 'successful authorization' }));
35
- const isAuthorized = yield clientInstance.acceptObolLatestTermsAndConditions();
36
- expect(isAuthorized).toEqual('successful authorization');
37
- }));
38
- test('createClusterDefinition should return config_hash', () => __awaiter(void 0, void 0, void 0, function* () {
39
- clientInstance['request'] = jest
40
- .fn()
41
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
42
- const configHash = yield clientInstance.createClusterDefinition(clusterConfigV1X10);
43
- expect(configHash).toEqual(mockConfigHash);
44
- }));
45
- test('acceptClusterDefinition should return cluster definition', () => __awaiter(void 0, void 0, void 0, function* () {
46
- clientInstance['request'] = jest
47
- .fn()
48
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
49
- const clusterDefinition = yield clientInstance.acceptClusterDefinition({
50
- enr: clusterLockV1X10.cluster_definition.operators[0].enr,
51
- version: clusterLockV1X10.cluster_definition.version,
52
- }, clusterLockV1X10.cluster_definition.config_hash);
53
- expect(clusterDefinition).toEqual(clusterLockV1X10.cluster_definition);
54
- }));
55
- test('createClusterDefinition should throw an error on invalid operators', () => __awaiter(void 0, void 0, void 0, function* () {
56
- clientInstance['request'] = jest
57
- .fn()
58
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
59
- try {
60
- yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, clusterConfigV1X10), { operators: [] }));
61
- }
62
- catch (error) {
63
- expect(error.message).toEqual('Validation failed: /operators must pass "validateUniqueAddresses" keyword validation, /operators must NOT have fewer than 4 items');
64
- }
65
- }));
66
- // cause we default to null
67
- test('createClusterDefinition should accept a configuration without deposit_amounts', () => __awaiter(void 0, void 0, void 0, function* () {
68
- clientInstance['request'] = jest
69
- .fn()
70
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
71
- const configHash = yield clientInstance.createClusterDefinition(Object.assign({}, clusterConfigV1X7));
72
- expect(configHash).toEqual(mockConfigHash);
73
- }));
74
- test('createClusterDefinition should throw on not valid deposit_amounts ', () => __awaiter(void 0, void 0, void 0, function* () {
75
- clientInstance['request'] = jest
76
- .fn()
77
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
78
- try {
79
- yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, clusterConfigV1X7), { deposit_amounts: ['34000000'] }));
80
- }
81
- catch (error) {
82
- expect(error.message).toEqual('Validation failed: /deposit_amounts/0 must be equal to one of the allowed values, /deposit_amounts must match "then" schema');
83
- }
84
- }));
85
- test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
86
- clientInstance['request'] = jest
87
- .fn()
88
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
89
- const clusterDefinition = yield clientInstance.getClusterDefinition(clusterLockV1X10.cluster_definition.config_hash);
90
- expect(clusterDefinition.deposit_amounts).toBeDefined();
91
- expect(clusterDefinition.config_hash).toEqual(clusterLockV1X10.cluster_definition.config_hash);
92
- // Test for new fields
93
- expect(clusterDefinition.compounding).toBeDefined();
94
- expect(clusterDefinition.target_gas_limit).toBeDefined();
95
- expect(clusterDefinition.consensus_protocol).toBeDefined();
96
- }));
97
- test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
98
- clientInstance['request'] = jest
99
- .fn()
100
- .mockReturnValue(Promise.resolve(clusterLockV1X10));
101
- const clusterLock = yield clientInstance.getClusterLock(clusterLockV1X10.cluster_definition.config_hash);
102
- expect(clusterLock.lock_hash).toEqual(clusterLockV1X10.lock_hash);
103
- }));
104
- test('request method should set user agent header', () => __awaiter(void 0, void 0, void 0, function* () {
105
- const server = setupServer(http.get('http://testexample.com/test', ({ request }) => {
106
- // Check if the request contains specific headers
107
- if (request.headers.get('User-Agent') === `Obol-SDK/${SDK_VERSION}`) {
108
- return HttpResponse.json({ message: 'user-agent header exist' });
109
- }
110
- }));
111
- server.listen();
112
- class TestBase extends Base {
113
- callProtectedRequest(endpoint, options) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- return yield this['request'](endpoint, options);
116
- });
117
- }
118
- }
119
- const testBaseInstance = new TestBase({
120
- baseUrl: 'http://testExample.com',
121
- });
122
- const result = yield testBaseInstance.callProtectedRequest('/test', {
123
- method: 'GET',
124
- });
125
- expect(result === null || result === void 0 ? void 0 : result.message).toEqual('user-agent header exist');
126
- server.close();
127
- }));
128
- });
129
- describe('Cluster Client without a signer', () => {
130
- const clientInstance = new Client({
131
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
132
- chainId: 17000,
133
- });
134
- beforeAll(() => {
135
- jest.restoreAllMocks();
136
- });
137
- beforeEach(() => {
138
- jest.resetModules();
139
- });
140
- test('createClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
141
- try {
142
- yield clientInstance.createClusterDefinition(clusterConfigV1X10);
143
- }
144
- catch (err) {
145
- expect(err.message).toEqual('Signer is required in createClusterDefinition');
146
- }
147
- }));
148
- test('acceptClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
149
- try {
150
- yield clientInstance.acceptClusterDefinition({
151
- enr: clusterLockV1X10.cluster_definition.operators[0].enr,
152
- version: clusterLockV1X10.cluster_definition.version,
153
- }, clusterLockV1X10.cluster_definition.config_hash);
154
- }
155
- catch (err) {
156
- expect(err.message).toEqual('Signer is required in acceptClusterDefinition');
157
- }
158
- }));
159
- test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
160
- clientInstance['request'] = jest
161
- .fn()
162
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
163
- const clusterDefinition = yield clientInstance.getClusterDefinition(clusterLockV1X10.cluster_definition.config_hash);
164
- expect(clusterDefinition.config_hash).toEqual(clusterLockV1X10.cluster_definition.config_hash);
165
- }));
166
- test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
167
- clientInstance['request'] = jest
168
- .fn()
169
- .mockReturnValue(Promise.resolve(clusterLockV1X10));
170
- const clusterLock = yield clientInstance.getClusterLock(clusterLockV1X10.cluster_definition.config_hash);
171
- expect(clusterLock.lock_hash).toEqual(clusterLockV1X10.lock_hash);
172
- }));
173
- test.each([
174
- { version: 'v1.6.0', clusterLock: clusterLockV1X6 },
175
- { version: 'v1.7.0', clusterLock: clusterLockV1X7 },
176
- { version: 'v1.8.0', clusterLock: clusterLockV1X8 },
177
- {
178
- version: 'null deposit_amounts v1.8.0',
179
- clusterLock: nullDepositAmountsClusterLockV1X8,
180
- },
181
- {
182
- version: 'Cluster with safe address v1.8.0',
183
- clusterLock: clusterLockWithSafe,
184
- },
185
- { version: 'v1.10.0', clusterLock: clusterLockV1X10 },
186
- {
187
- version: 'v1.10.0 with compunding withdrawals',
188
- clusterLock: clusterLockWithCompoundingWithdrawals,
189
- },
190
- ])("$version: 'should return true on verified cluster lock'", ({ clusterLock }) => __awaiter(void 0, void 0, void 0, function* () {
191
- const isValidLock = yield validateClusterLock(clusterLock);
192
- expect(isValidLock).toEqual(true);
193
- }));
194
- test('should return true on verified cluster lock with Safe wallet and safe rpc url', () => __awaiter(void 0, void 0, void 0, function* () {
195
- process.env.RPC_HOLESKY = undefined;
196
- /* eslint-disable @typescript-eslint/no-var-requires */
197
- const { validateClusterLock: validateLockWithRpcUrl, } = require('../../src/index');
198
- const safeRpcUrl = 'https://ethereum-holesky-rpc.publicnode.com';
199
- const isValidLock = yield validateLockWithRpcUrl(clusterLockWithSafe, safeRpcUrl);
200
- expect(isValidLock).toEqual(true);
201
- }));
202
- test('validateCluster should return false for cluster with null deposit_amounts and incorrect partial_deposits', () => __awaiter(void 0, void 0, void 0, function* () {
203
- const partialDeposit = nullDepositAmountsClusterLockV1X8.distributed_validators[0]
204
- .partial_deposit_data[0];
205
- const isValidLock = yield validateClusterLock(Object.assign(Object.assign({}, nullDepositAmountsClusterLockV1X8), { distributed_validators: [
206
- Object.assign(Object.assign({}, nullDepositAmountsClusterLockV1X8.distributed_validators[0]), { partial_deposit_data: [partialDeposit, partialDeposit] }),
207
- ] }));
208
- expect(isValidLock).toEqual(false);
209
- }));
210
- test('Finds the hash of the latest version of terms and conditions', () => __awaiter(void 0, void 0, void 0, function* () {
211
- const termsAndConditionsHash = yield hashTermsAndConditions();
212
- expect(termsAndConditionsHash).toEqual('0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273');
213
- }));
214
- });
215
- describe('createObolRewardsSplit', () => {
216
- let clientInstance, clientInstanceWithourSigner, mockSplitRecipients, mockPrincipalRecipient, mockEtherAmount;
217
- beforeAll(() => {
218
- jest
219
- .spyOn(utils, 'isContractAvailable')
220
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
221
- jest
222
- .spyOn(splitsHelpers, 'predictSplitterAddress')
223
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
224
- jest.spyOn(splitsHelpers, 'handleDeployOWRAndSplitter').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
225
- return yield Promise.resolve({
226
- withdrawal_address: '0xWithdrawalAddress',
227
- fee_recipient_address: '0xFeeRecipientAddress',
228
- });
229
- }));
230
- clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
231
- clientInstanceWithourSigner = new Client({
232
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
233
- chainId: 17000,
234
- });
235
- mockSplitRecipients = [
236
- {
237
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
238
- percentAllocation: 99,
239
- },
240
- ];
241
- mockPrincipalRecipient = '0x86B8145c98e5BD25BA722645b15eD65f024a87EC';
242
- mockEtherAmount = 64;
243
- });
244
- it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
245
- yield expect(clientInstanceWithourSigner.createObolRewardsSplit({
246
- splitRecipients: mockSplitRecipients,
247
- principalRecipient: mockPrincipalRecipient,
248
- etherAmount: mockEtherAmount,
249
- })).rejects.toThrow('Signer is required in createObolRewardsSplit');
250
- }));
251
- it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
252
- const unsupportedSplitterChainClient = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
253
- try {
254
- yield unsupportedSplitterChainClient.createObolRewardsSplit({
255
- splitRecipients: mockSplitRecipients,
256
- principalRecipient: mockPrincipalRecipient,
257
- etherAmount: mockEtherAmount,
258
- });
259
- }
260
- catch (error) {
261
- expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
262
- }
263
- }));
264
- test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
265
- try {
266
- yield clientInstance.createObolRewardsSplit({
267
- splitRecipients: [
268
- {
269
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
270
- percentAllocation: 22,
271
- },
272
- ],
273
- principalRecipient: mockPrincipalRecipient,
274
- etherAmount: mockEtherAmount,
275
- });
276
- }
277
- catch (error) {
278
- expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation');
279
- }
280
- }));
281
- test('should throw an error if ObolRAFSplit is less than 1', () => __awaiter(void 0, void 0, void 0, function* () {
282
- try {
283
- yield clientInstance.createObolRewardsSplit({
284
- splitRecipients: mockSplitRecipients,
285
- principalRecipient: mockPrincipalRecipient,
286
- etherAmount: mockEtherAmount,
287
- ObolRAFSplit: 0.5,
288
- });
289
- }
290
- catch (error) {
291
- expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation, /ObolRAFSplit must be >= 1');
292
- }
293
- }));
294
- it('should return the correct withdrawal and fee recipient addresses', () => __awaiter(void 0, void 0, void 0, function* () {
295
- const result = yield clientInstance.createObolRewardsSplit({
296
- splitRecipients: mockSplitRecipients,
297
- principalRecipient: mockPrincipalRecipient,
298
- etherAmount: mockEtherAmount,
299
- });
300
- expect(result).toEqual({
301
- withdrawal_address: '0xWithdrawalAddress',
302
- fee_recipient_address: '0xFeeRecipientAddress',
303
- });
304
- }));
305
- });
306
- describe('createObolTotalSplit', () => {
307
- let clientInstanceWithourSigner, mockSplitRecipients, clientInstance;
308
- beforeAll(() => {
309
- jest
310
- .spyOn(utils, 'isContractAvailable')
311
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
312
- jest
313
- .spyOn(splitsHelpers, 'predictSplitterAddress')
314
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
315
- jest
316
- .spyOn(splitsHelpers, 'deploySplitterContract')
317
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xSplitterAddress'); }));
318
- clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
319
- clientInstanceWithourSigner = new Client({
320
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
321
- chainId: 17000,
322
- });
323
- mockSplitRecipients = [
324
- {
325
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
326
- percentAllocation: 99.9,
327
- },
328
- ];
329
- });
330
- it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
331
- yield expect(clientInstanceWithourSigner.createObolTotalSplit({
332
- splitRecipients: mockSplitRecipients,
333
- })).rejects.toThrow('Signer is required in createObolTotalSplit');
334
- }));
335
- it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
336
- const unsupportedSplitterChainClient = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
337
- try {
338
- yield unsupportedSplitterChainClient.createObolTotalSplit({
339
- splitRecipients: mockSplitRecipients,
340
- });
341
- }
342
- catch (error) {
343
- expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
344
- }
345
- }));
346
- test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
347
- try {
348
- yield clientInstance.createObolTotalSplit({
349
- splitRecipients: [
350
- {
351
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
352
- percentAllocation: 22,
353
- },
354
- ],
355
- });
356
- }
357
- catch (error) {
358
- expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation');
359
- }
360
- }));
361
- test('should throw an error if ObolRAFSplit is less than 0.1', () => __awaiter(void 0, void 0, void 0, function* () {
362
- try {
363
- yield clientInstance.createObolTotalSplit({
364
- splitRecipients: mockSplitRecipients,
365
- ObolRAFSplit: 0.05,
366
- });
367
- }
368
- catch (error) {
369
- expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation, /ObolRAFSplit must be >= 0.1');
370
- }
371
- }));
372
- it('should return the correct withdrawal and fee recipient addresses and ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
373
- const result = yield clientInstance.createObolTotalSplit({
374
- splitRecipients: mockSplitRecipients,
375
- ObolRAFSplit: 0.1,
376
- });
377
- // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
378
- expect(result).toEqual({
379
- withdrawal_address: '0xPredictedAddress',
380
- fee_recipient_address: '0xPredictedAddress',
381
- });
382
- }));
383
- it('should return the correct withdrawal and fee recipient addresses without passing ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
384
- const result = yield clientInstance.createObolTotalSplit({
385
- splitRecipients: mockSplitRecipients,
386
- });
387
- // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
388
- expect(result).toEqual({
389
- withdrawal_address: '0xPredictedAddress',
390
- fee_recipient_address: '0xPredictedAddress',
391
- });
392
- }));
393
- });
@@ -1,174 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { EOA } from '../../src/eoa/eoa';
11
- import { submitEOAWithdrawalRequest, submitEOABatchDeposit, } from '../../src/eoa/eoaHelpers';
12
- // Mock the helper function
13
- jest.mock('../../src/eoa/eoaHelpers', () => ({
14
- submitEOAWithdrawalRequest: jest.fn(),
15
- submitEOABatchDeposit: jest.fn(),
16
- }));
17
- describe('EOA', () => {
18
- let eoa;
19
- let mockSigner;
20
- let mockProvider;
21
- beforeEach(() => {
22
- // Clear all mocks before each test
23
- jest.clearAllMocks();
24
- mockSigner = {
25
- getAddress: jest
26
- .fn()
27
- .mockResolvedValue('0x1234567890123456789012345678901234567890'),
28
- };
29
- mockProvider = {
30
- getNetwork: jest.fn().mockResolvedValue({ chainId: 1 }),
31
- };
32
- eoa = new EOA(mockSigner, 1, mockProvider);
33
- });
34
- describe('requestWithdrawal', () => {
35
- it('should successfully request withdrawal', () => __awaiter(void 0, void 0, void 0, function* () {
36
- const mockPayload = {
37
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
38
- allocation: 32,
39
- requiredFee: '1',
40
- };
41
- const mockResult = {
42
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
43
- };
44
- submitEOAWithdrawalRequest.mockResolvedValue(mockResult);
45
- const result = yield eoa.requestWithdrawal(mockPayload);
46
- expect(submitEOAWithdrawalRequest).toHaveBeenCalledWith({
47
- pubkey: mockPayload.pubkey,
48
- allocation: mockPayload.allocation,
49
- withdrawalAddress: '0x1234567890123456789012345678901234567890',
50
- withdrawalContractAddress: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
51
- requiredFee: mockPayload.requiredFee,
52
- chainId: 1,
53
- signer: mockSigner,
54
- provider: mockProvider,
55
- });
56
- expect(result).toEqual(mockResult);
57
- }));
58
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
59
- const eoaWithoutSigner = new EOA(undefined, 1, mockProvider);
60
- const mockPayload = {
61
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
62
- allocation: 32,
63
- requiredFee: '1',
64
- };
65
- yield expect(eoaWithoutSigner.requestWithdrawal(mockPayload)).rejects.toThrow('Signer is required in requestWithdrawal');
66
- }));
67
- it('should throw error when provider is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
68
- const eoaWithoutProvider = new EOA(mockSigner, 1, null);
69
- const mockPayload = {
70
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
71
- allocation: 32,
72
- requiredFee: '1',
73
- };
74
- yield expect(eoaWithoutProvider.requestWithdrawal(mockPayload)).rejects.toThrow('Provider is required in requestWithdrawal');
75
- }));
76
- it('should throw error when EOA withdrawal contract is not configured for chain', () => __awaiter(void 0, void 0, void 0, function* () {
77
- const eoaUnsupportedChain = new EOA(mockSigner, 999, mockProvider);
78
- const mockPayload = {
79
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
80
- allocation: 32,
81
- requiredFee: '1',
82
- };
83
- yield expect(eoaUnsupportedChain.requestWithdrawal(mockPayload)).rejects.toThrow('EOA withdrawal contract is not configured for chain 999');
84
- }));
85
- it('should return null txHash when transaction receipt is null', () => __awaiter(void 0, void 0, void 0, function* () {
86
- const mockPayload = {
87
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
88
- allocation: 32,
89
- requiredFee: '1',
90
- };
91
- const mockResult = { txHash: null };
92
- submitEOAWithdrawalRequest.mockResolvedValue(mockResult);
93
- const result = yield eoa.requestWithdrawal(mockPayload);
94
- expect(result).toEqual(mockResult);
95
- }));
96
- });
97
- describe('deposit', () => {
98
- const mockDeposits = [
99
- {
100
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
101
- withdrawal_credentials: '0x1234567890123456789012345678901234567890123456789012345678901234',
102
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
103
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
104
- amount: '32000000000000000000', // 32 ETH in wei
105
- },
106
- ];
107
- it('should successfully deposit to batch contract', () => __awaiter(void 0, void 0, void 0, function* () {
108
- const mockPayload = {
109
- deposits: mockDeposits,
110
- };
111
- const mockResult = {
112
- txHashes: [
113
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
114
- ],
115
- };
116
- submitEOABatchDeposit.mockResolvedValue(mockResult);
117
- const result = yield eoa.deposit(mockPayload);
118
- expect(submitEOABatchDeposit).toHaveBeenCalledWith({
119
- deposits: mockDeposits,
120
- batchDepositContractAddress: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
121
- signer: mockSigner,
122
- });
123
- expect(result).toEqual(mockResult);
124
- }));
125
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
126
- const eoaWithoutSigner = new EOA(undefined, 1, mockProvider);
127
- const mockPayload = {
128
- deposits: mockDeposits,
129
- };
130
- yield expect(eoaWithoutSigner.deposit(mockPayload)).rejects.toThrow('Signer is required in deposit');
131
- }));
132
- it('should throw error when batch deposit contract is not configured for chain', () => __awaiter(void 0, void 0, void 0, function* () {
133
- const eoaUnsupportedChain = new EOA(mockSigner, 999, mockProvider);
134
- const mockPayload = {
135
- deposits: mockDeposits,
136
- };
137
- yield expect(eoaUnsupportedChain.deposit(mockPayload)).rejects.toThrow('Batch deposit contract is not configured for chain 999');
138
- }));
139
- it('should handle multiple deposits', () => __awaiter(void 0, void 0, void 0, function* () {
140
- const multipleDeposits = [
141
- {
142
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
143
- withdrawal_credentials: '0x1234567890123456789012345678901234567890123456789012345678901234',
144
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
145
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
146
- amount: '32000000000000000000',
147
- },
148
- {
149
- pubkey: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdcd',
150
- withdrawal_credentials: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
151
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
152
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
153
- amount: '16000000000000000000',
154
- },
155
- ];
156
- const mockPayload = {
157
- deposits: multipleDeposits,
158
- };
159
- const mockResult = {
160
- txHashes: [
161
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
162
- ],
163
- };
164
- submitEOABatchDeposit.mockResolvedValue(mockResult);
165
- const result = yield eoa.deposit(mockPayload);
166
- expect(submitEOABatchDeposit).toHaveBeenCalledWith({
167
- deposits: multipleDeposits,
168
- batchDepositContractAddress: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
169
- signer: mockSigner,
170
- });
171
- expect(result).toEqual(mockResult);
172
- }));
173
- });
174
- });
@@ -1,81 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { getCapellaFork, getGenesisValidatorsRoot, } from '../../src/exits/ethUtils';
11
- import { CAPELLA_FORK_MAPPING } from '../../src/constants';
12
- describe('ethUtils', () => {
13
- describe('getCapellaFork', () => {
14
- Object.entries(CAPELLA_FORK_MAPPING).forEach(([baseFork, expectedCapellaFork]) => {
15
- it(`should return ${expectedCapellaFork} for base fork ${baseFork}`, () => __awaiter(void 0, void 0, void 0, function* () {
16
- const result = yield getCapellaFork(baseFork);
17
- expect(result).toBe(expectedCapellaFork);
18
- }));
19
- });
20
- it('should return null for an unknown base fork version', () => __awaiter(void 0, void 0, void 0, function* () {
21
- const result = yield getCapellaFork('0xUNKNOWNFORK');
22
- expect(result).toBeNull();
23
- }));
24
- });
25
- describe('getGenesisValidatorsRoot', () => {
26
- const mockBeaconApiUrl = 'http://localhost:5052';
27
- const mockGenesisRoot = '0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2';
28
- beforeEach(() => {
29
- // Reset fetch mock
30
- global.fetch = jest.fn();
31
- });
32
- afterEach(() => {
33
- jest.restoreAllMocks();
34
- });
35
- it('should fetch and return the genesis_validators_root successfully', () => __awaiter(void 0, void 0, void 0, function* () {
36
- global.fetch.mockResolvedValueOnce({
37
- json: () => __awaiter(void 0, void 0, void 0, function* () {
38
- return ({
39
- data: { genesis_validators_root: mockGenesisRoot },
40
- });
41
- }),
42
- });
43
- const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
44
- expect(result).toBe(mockGenesisRoot);
45
- expect(global.fetch).toHaveBeenCalledTimes(1);
46
- expect(global.fetch).toHaveBeenCalledWith(`${mockBeaconApiUrl}/eth/v1/beacon/genesis`, { method: 'GET' });
47
- }));
48
- it('should return null if the HTTP request fails (e.g., network error)', () => __awaiter(void 0, void 0, void 0, function* () {
49
- global.fetch.mockRejectedValueOnce(new Error('Network error'));
50
- yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: Network error');
51
- expect(global.fetch).toHaveBeenCalledTimes(1);
52
- }));
53
- it('should return null if the response data structure is invalid (missing genesis_validators_root)', () => __awaiter(void 0, void 0, void 0, function* () {
54
- global.fetch.mockResolvedValueOnce({
55
- json: () => __awaiter(void 0, void 0, void 0, function* () {
56
- return ({
57
- data: { some_other_field: 'value' },
58
- });
59
- }),
60
- });
61
- const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
62
- expect(result).toBeNull();
63
- expect(global.fetch).toHaveBeenCalledTimes(1);
64
- }));
65
- it('should return null if the response data is missing', () => __awaiter(void 0, void 0, void 0, function* () {
66
- global.fetch.mockResolvedValueOnce({
67
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); }),
68
- });
69
- const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
70
- expect(result).toBeNull();
71
- }));
72
- it('should throw an error if fetch throws an error with a message', () => __awaiter(void 0, void 0, void 0, function* () {
73
- global.fetch.mockRejectedValueOnce(new Error('Custom HTTP error'));
74
- yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: Custom HTTP error');
75
- }));
76
- it('should throw an error if fetch throws a non-Error object', () => __awaiter(void 0, void 0, void 0, function* () {
77
- global.fetch.mockRejectedValueOnce('some string error');
78
- yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: some string error');
79
- }));
80
- });
81
- });