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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/cjs/src/index.js +17457 -382
  2. package/dist/cjs/src/index.js.map +1 -0
  3. package/dist/esm/src/index.js +17424 -361
  4. package/dist/esm/src/index.js.map +1 -0
  5. package/dist/types/src/constants.d.ts +1 -2
  6. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  7. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  8. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  9. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  10. package/dist/types/src/utils.d.ts +2 -2
  11. package/dist/types/src/verification/common.d.ts +0 -2
  12. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  13. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  14. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  15. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  17. package/dist/types/test/client/methods.spec.d.ts +17 -0
  18. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  19. package/dist/types/tsup.config.d.ts +2 -0
  20. package/package.json +79 -54
  21. package/dist/cjs/package.json +0 -139
  22. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  23. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  24. package/dist/cjs/src/abi/Multicall3.js +0 -253
  25. package/dist/cjs/src/abi/OVM.js +0 -627
  26. package/dist/cjs/src/abi/OWR.js +0 -304
  27. package/dist/cjs/src/abi/SplitMain.js +0 -929
  28. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  29. package/dist/cjs/src/ajv.js +0 -136
  30. package/dist/cjs/src/base.js +0 -42
  31. package/dist/cjs/src/bytecodes.js +0 -19
  32. package/dist/cjs/src/constants.js +0 -272
  33. package/dist/cjs/src/eoa/eoa.js +0 -132
  34. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  35. package/dist/cjs/src/errors.js +0 -11
  36. package/dist/cjs/src/exits/ethUtils.js +0 -57
  37. package/dist/cjs/src/exits/exit.js +0 -502
  38. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  39. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  40. package/dist/cjs/src/incentives/incentives.js +0 -119
  41. package/dist/cjs/src/schema.js +0 -352
  42. package/dist/cjs/src/services.js +0 -33
  43. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  44. package/dist/cjs/src/splits/splits.js +0 -366
  45. package/dist/cjs/src/types.js +0 -29
  46. package/dist/cjs/src/utils.js +0 -77
  47. package/dist/cjs/src/verification/common.js +0 -355
  48. package/dist/cjs/src/verification/signature-validator.js +0 -73
  49. package/dist/cjs/src/verification/sszTypes.js +0 -69
  50. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  51. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  52. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  53. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  54. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  55. package/dist/cjs/test/client/ajv.spec.js +0 -320
  56. package/dist/cjs/test/client/methods.spec.js +0 -418
  57. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  58. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  59. package/dist/cjs/test/exit/exit.spec.js +0 -399
  60. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  61. package/dist/cjs/test/fixtures.js +0 -896
  62. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  63. package/dist/cjs/test/splits/splits.spec.js +0 -402
  64. package/dist/esm/package.json +0 -139
  65. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  66. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  67. package/dist/esm/src/abi/Multicall3.js +0 -250
  68. package/dist/esm/src/abi/OVM.js +0 -624
  69. package/dist/esm/src/abi/OWR.js +0 -301
  70. package/dist/esm/src/abi/SplitMain.js +0 -926
  71. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  72. package/dist/esm/src/ajv.js +0 -129
  73. package/dist/esm/src/base.js +0 -38
  74. package/dist/esm/src/bytecodes.js +0 -16
  75. package/dist/esm/src/constants.js +0 -238
  76. package/dist/esm/src/eoa/eoa.js +0 -128
  77. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  78. package/dist/esm/src/errors.js +0 -7
  79. package/dist/esm/src/exits/ethUtils.js +0 -52
  80. package/dist/esm/src/exits/exit.js +0 -475
  81. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  82. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  83. package/dist/esm/src/incentives/incentives.js +0 -115
  84. package/dist/esm/src/schema.js +0 -349
  85. package/dist/esm/src/services.js +0 -29
  86. package/dist/esm/src/splits/splitHelpers.js +0 -554
  87. package/dist/esm/src/splits/splits.js +0 -362
  88. package/dist/esm/src/types.js +0 -26
  89. package/dist/esm/src/utils.js +0 -68
  90. package/dist/esm/src/verification/common.js +0 -319
  91. package/dist/esm/src/verification/signature-validator.js +0 -64
  92. package/dist/esm/src/verification/sszTypes.js +0 -64
  93. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  94. package/dist/esm/src/verification/v1.10.0.js +0 -140
  95. package/dist/esm/src/verification/v1.6.0.js +0 -142
  96. package/dist/esm/src/verification/v1.7.0.js +0 -166
  97. package/dist/esm/src/verification/v1.8.0.js +0 -189
  98. package/dist/esm/test/client/ajv.spec.js +0 -318
  99. package/dist/esm/test/client/methods.spec.js +0 -393
  100. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  101. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  102. package/dist/esm/test/exit/exit.spec.js +0 -374
  103. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  104. package/dist/esm/test/fixtures.js +0 -893
  105. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  106. package/dist/esm/test/splits/splits.spec.js +0 -400
  107. package/src/abi/BatchDeposit.ts +0 -117
  108. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  109. package/src/abi/Multicall3.ts +0 -250
  110. package/src/abi/OVM.ts +0 -624
  111. package/src/abi/OWR.ts +0 -302
  112. package/src/abi/SplitMain.ts +0 -927
  113. package/src/abi/splitV2FactoryAbi.ts +0 -417
  114. package/src/ajv.ts +0 -191
  115. package/src/base.ts +0 -54
  116. package/src/bytecodes.ts +0 -32
  117. package/src/constants.ts +0 -309
  118. package/src/eoa/eoa.ts +0 -153
  119. package/src/eoa/eoaHelpers.ts +0 -112
  120. package/src/errors.ts +0 -8
  121. package/src/exits/ethUtils.ts +0 -49
  122. package/src/exits/exit.ts +0 -661
  123. package/src/exits/verificationHelpers.ts +0 -110
  124. package/src/incentives/incentiveHelpers.ts +0 -55
  125. package/src/incentives/incentives.ts +0 -153
  126. package/src/index.ts +0 -614
  127. package/src/schema.ts +0 -376
  128. package/src/services.ts +0 -24
  129. package/src/splits/splitHelpers.ts +0 -1032
  130. package/src/splits/splits.ts +0 -504
  131. package/src/types.ts +0 -687
  132. package/src/utils.ts +0 -88
  133. package/src/verification/common.ts +0 -532
  134. package/src/verification/signature-validator.ts +0 -103
  135. package/src/verification/sszTypes.ts +0 -88
  136. package/src/verification/termsAndConditions.ts +0 -32
  137. package/src/verification/v1.10.0.ts +0 -245
  138. package/src/verification/v1.6.0.ts +0 -256
  139. package/src/verification/v1.7.0.ts +0 -309
  140. package/src/verification/v1.8.0.ts +0 -340
@@ -1,418 +0,0 @@
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
- });
@@ -1,176 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const eoa_1 = require("../../src/eoa/eoa");
13
- const eoaHelpers_1 = require("../../src/eoa/eoaHelpers");
14
- // Mock the helper function
15
- jest.mock('../../src/eoa/eoaHelpers', () => ({
16
- submitEOAWithdrawalRequest: jest.fn(),
17
- submitEOABatchDeposit: jest.fn(),
18
- }));
19
- describe('EOA', () => {
20
- let eoa;
21
- let mockSigner;
22
- let mockProvider;
23
- beforeEach(() => {
24
- // Clear all mocks before each test
25
- jest.clearAllMocks();
26
- mockSigner = {
27
- getAddress: jest
28
- .fn()
29
- .mockResolvedValue('0x1234567890123456789012345678901234567890'),
30
- };
31
- mockProvider = {
32
- getNetwork: jest.fn().mockResolvedValue({ chainId: 1 }),
33
- };
34
- eoa = new eoa_1.EOA(mockSigner, 1, mockProvider);
35
- });
36
- describe('requestWithdrawal', () => {
37
- it('should successfully request withdrawal', () => __awaiter(void 0, void 0, void 0, function* () {
38
- const mockPayload = {
39
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
40
- allocation: 32,
41
- requiredFee: '1',
42
- };
43
- const mockResult = {
44
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
45
- };
46
- eoaHelpers_1.submitEOAWithdrawalRequest.mockResolvedValue(mockResult);
47
- const result = yield eoa.requestWithdrawal(mockPayload);
48
- expect(eoaHelpers_1.submitEOAWithdrawalRequest).toHaveBeenCalledWith({
49
- pubkey: mockPayload.pubkey,
50
- allocation: mockPayload.allocation,
51
- withdrawalAddress: '0x1234567890123456789012345678901234567890',
52
- withdrawalContractAddress: '0x00000961Ef480Eb55e80D19ad83579A64c007002',
53
- requiredFee: mockPayload.requiredFee,
54
- chainId: 1,
55
- signer: mockSigner,
56
- provider: mockProvider,
57
- });
58
- expect(result).toEqual(mockResult);
59
- }));
60
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
61
- const eoaWithoutSigner = new eoa_1.EOA(undefined, 1, mockProvider);
62
- const mockPayload = {
63
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
64
- allocation: 32,
65
- requiredFee: '1',
66
- };
67
- yield expect(eoaWithoutSigner.requestWithdrawal(mockPayload)).rejects.toThrow('Signer is required in requestWithdrawal');
68
- }));
69
- it('should throw error when provider is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
70
- const eoaWithoutProvider = new eoa_1.EOA(mockSigner, 1, null);
71
- const mockPayload = {
72
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
73
- allocation: 32,
74
- requiredFee: '1',
75
- };
76
- yield expect(eoaWithoutProvider.requestWithdrawal(mockPayload)).rejects.toThrow('Provider is required in requestWithdrawal');
77
- }));
78
- it('should throw error when EOA withdrawal contract is not configured for chain', () => __awaiter(void 0, void 0, void 0, function* () {
79
- const eoaUnsupportedChain = new eoa_1.EOA(mockSigner, 999, mockProvider);
80
- const mockPayload = {
81
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
82
- allocation: 32,
83
- requiredFee: '1',
84
- };
85
- yield expect(eoaUnsupportedChain.requestWithdrawal(mockPayload)).rejects.toThrow('EOA withdrawal contract is not configured for chain 999');
86
- }));
87
- it('should return null txHash when transaction receipt is null', () => __awaiter(void 0, void 0, void 0, function* () {
88
- const mockPayload = {
89
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
90
- allocation: 32,
91
- requiredFee: '1',
92
- };
93
- const mockResult = { txHash: null };
94
- eoaHelpers_1.submitEOAWithdrawalRequest.mockResolvedValue(mockResult);
95
- const result = yield eoa.requestWithdrawal(mockPayload);
96
- expect(result).toEqual(mockResult);
97
- }));
98
- });
99
- describe('deposit', () => {
100
- const mockDeposits = [
101
- {
102
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
103
- withdrawal_credentials: '0x1234567890123456789012345678901234567890123456789012345678901234',
104
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
105
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
106
- amount: '32000000000000000000', // 32 ETH in wei
107
- },
108
- ];
109
- it('should successfully deposit to batch contract', () => __awaiter(void 0, void 0, void 0, function* () {
110
- const mockPayload = {
111
- deposits: mockDeposits,
112
- };
113
- const mockResult = {
114
- txHashes: [
115
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
116
- ],
117
- };
118
- eoaHelpers_1.submitEOABatchDeposit.mockResolvedValue(mockResult);
119
- const result = yield eoa.deposit(mockPayload);
120
- expect(eoaHelpers_1.submitEOABatchDeposit).toHaveBeenCalledWith({
121
- deposits: mockDeposits,
122
- batchDepositContractAddress: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
123
- signer: mockSigner,
124
- });
125
- expect(result).toEqual(mockResult);
126
- }));
127
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
128
- const eoaWithoutSigner = new eoa_1.EOA(undefined, 1, mockProvider);
129
- const mockPayload = {
130
- deposits: mockDeposits,
131
- };
132
- yield expect(eoaWithoutSigner.deposit(mockPayload)).rejects.toThrow('Signer is required in deposit');
133
- }));
134
- it('should throw error when batch deposit contract is not configured for chain', () => __awaiter(void 0, void 0, void 0, function* () {
135
- const eoaUnsupportedChain = new eoa_1.EOA(mockSigner, 999, mockProvider);
136
- const mockPayload = {
137
- deposits: mockDeposits,
138
- };
139
- yield expect(eoaUnsupportedChain.deposit(mockPayload)).rejects.toThrow('Batch deposit contract is not configured for chain 999');
140
- }));
141
- it('should handle multiple deposits', () => __awaiter(void 0, void 0, void 0, function* () {
142
- const multipleDeposits = [
143
- {
144
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
145
- withdrawal_credentials: '0x1234567890123456789012345678901234567890123456789012345678901234',
146
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
147
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
148
- amount: '32000000000000000000',
149
- },
150
- {
151
- pubkey: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdcd',
152
- withdrawal_credentials: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
153
- deposit_data_root: '0x7f7f280756b8d5fe06ae922e5a20afb708c0f00d8954caede4c262795d956c01',
154
- signature: '0x121234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012000000000000000000',
155
- amount: '16000000000000000000',
156
- },
157
- ];
158
- const mockPayload = {
159
- deposits: multipleDeposits,
160
- };
161
- const mockResult = {
162
- txHashes: [
163
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
164
- ],
165
- };
166
- eoaHelpers_1.submitEOABatchDeposit.mockResolvedValue(mockResult);
167
- const result = yield eoa.deposit(mockPayload);
168
- expect(eoaHelpers_1.submitEOABatchDeposit).toHaveBeenCalledWith({
169
- deposits: multipleDeposits,
170
- batchDepositContractAddress: '0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756',
171
- signer: mockSigner,
172
- });
173
- expect(result).toEqual(mockResult);
174
- }));
175
- });
176
- });