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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/cjs/src/index.js +17457 -382
  2. package/dist/cjs/src/index.js.map +1 -0
  3. package/dist/esm/src/index.js +17424 -361
  4. package/dist/esm/src/index.js.map +1 -0
  5. package/dist/types/src/abi/OVM.d.ts +103 -0
  6. package/dist/types/src/bytecodes.d.ts +3 -2
  7. package/dist/types/src/constants.d.ts +1 -2
  8. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  9. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  10. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  11. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  12. package/dist/types/src/utils.d.ts +2 -2
  13. package/dist/types/src/verification/common.d.ts +0 -2
  14. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  15. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  17. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  18. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  19. package/dist/types/test/client/methods.spec.d.ts +17 -0
  20. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  21. package/dist/types/tsup.config.d.ts +2 -0
  22. package/package.json +79 -54
  23. package/dist/cjs/package.json +0 -139
  24. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  25. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  26. package/dist/cjs/src/abi/Multicall3.js +0 -253
  27. package/dist/cjs/src/abi/OVMFactory.js +0 -620
  28. package/dist/cjs/src/abi/OWR.js +0 -304
  29. package/dist/cjs/src/abi/SplitMain.js +0 -929
  30. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  31. package/dist/cjs/src/ajv.js +0 -136
  32. package/dist/cjs/src/base.js +0 -42
  33. package/dist/cjs/src/bytecodes.js +0 -18
  34. package/dist/cjs/src/constants.js +0 -268
  35. package/dist/cjs/src/eoa/eoa.js +0 -132
  36. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  37. package/dist/cjs/src/errors.js +0 -11
  38. package/dist/cjs/src/exits/ethUtils.js +0 -57
  39. package/dist/cjs/src/exits/exit.js +0 -502
  40. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  41. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  42. package/dist/cjs/src/incentives/incentives.js +0 -119
  43. package/dist/cjs/src/schema.js +0 -352
  44. package/dist/cjs/src/services.js +0 -33
  45. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  46. package/dist/cjs/src/splits/splits.js +0 -366
  47. package/dist/cjs/src/types.js +0 -29
  48. package/dist/cjs/src/utils.js +0 -77
  49. package/dist/cjs/src/verification/common.js +0 -355
  50. package/dist/cjs/src/verification/signature-validator.js +0 -73
  51. package/dist/cjs/src/verification/sszTypes.js +0 -69
  52. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  53. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  54. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  55. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  56. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  57. package/dist/cjs/test/client/ajv.spec.js +0 -320
  58. package/dist/cjs/test/client/methods.spec.js +0 -418
  59. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  60. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  61. package/dist/cjs/test/exit/exit.spec.js +0 -399
  62. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  63. package/dist/cjs/test/fixtures.js +0 -896
  64. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  65. package/dist/cjs/test/splits/splits.spec.js +0 -402
  66. package/dist/esm/package.json +0 -139
  67. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  68. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  69. package/dist/esm/src/abi/Multicall3.js +0 -250
  70. package/dist/esm/src/abi/OVMFactory.js +0 -617
  71. package/dist/esm/src/abi/OWR.js +0 -301
  72. package/dist/esm/src/abi/SplitMain.js +0 -926
  73. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  74. package/dist/esm/src/ajv.js +0 -129
  75. package/dist/esm/src/base.js +0 -38
  76. package/dist/esm/src/bytecodes.js +0 -15
  77. package/dist/esm/src/constants.js +0 -234
  78. package/dist/esm/src/eoa/eoa.js +0 -128
  79. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  80. package/dist/esm/src/errors.js +0 -7
  81. package/dist/esm/src/exits/ethUtils.js +0 -52
  82. package/dist/esm/src/exits/exit.js +0 -475
  83. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  84. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  85. package/dist/esm/src/incentives/incentives.js +0 -115
  86. package/dist/esm/src/schema.js +0 -349
  87. package/dist/esm/src/services.js +0 -29
  88. package/dist/esm/src/splits/splitHelpers.js +0 -554
  89. package/dist/esm/src/splits/splits.js +0 -362
  90. package/dist/esm/src/types.js +0 -26
  91. package/dist/esm/src/utils.js +0 -68
  92. package/dist/esm/src/verification/common.js +0 -319
  93. package/dist/esm/src/verification/signature-validator.js +0 -64
  94. package/dist/esm/src/verification/sszTypes.js +0 -64
  95. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  96. package/dist/esm/src/verification/v1.10.0.js +0 -140
  97. package/dist/esm/src/verification/v1.6.0.js +0 -142
  98. package/dist/esm/src/verification/v1.7.0.js +0 -166
  99. package/dist/esm/src/verification/v1.8.0.js +0 -189
  100. package/dist/esm/test/client/ajv.spec.js +0 -318
  101. package/dist/esm/test/client/methods.spec.js +0 -393
  102. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  103. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  104. package/dist/esm/test/exit/exit.spec.js +0 -374
  105. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  106. package/dist/esm/test/fixtures.js +0 -893
  107. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  108. package/dist/esm/test/splits/splits.spec.js +0 -400
  109. package/dist/types/src/abi/OVMFactory.d.ts +0 -662
  110. package/src/abi/BatchDeposit.ts +0 -117
  111. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  112. package/src/abi/Multicall3.ts +0 -250
  113. package/src/abi/OVMFactory.ts +0 -617
  114. package/src/abi/OWR.ts +0 -302
  115. package/src/abi/SplitMain.ts +0 -927
  116. package/src/abi/splitV2FactoryAbi.ts +0 -417
  117. package/src/ajv.ts +0 -191
  118. package/src/base.ts +0 -54
  119. package/src/bytecodes.ts +0 -31
  120. package/src/constants.ts +0 -304
  121. package/src/eoa/eoa.ts +0 -153
  122. package/src/eoa/eoaHelpers.ts +0 -112
  123. package/src/errors.ts +0 -8
  124. package/src/exits/ethUtils.ts +0 -49
  125. package/src/exits/exit.ts +0 -661
  126. package/src/exits/verificationHelpers.ts +0 -110
  127. package/src/incentives/incentiveHelpers.ts +0 -55
  128. package/src/incentives/incentives.ts +0 -153
  129. package/src/index.ts +0 -614
  130. package/src/schema.ts +0 -376
  131. package/src/services.ts +0 -24
  132. package/src/splits/splitHelpers.ts +0 -1032
  133. package/src/splits/splits.ts +0 -504
  134. package/src/types.ts +0 -687
  135. package/src/utils.ts +0 -88
  136. package/src/verification/common.ts +0 -532
  137. package/src/verification/signature-validator.ts +0 -103
  138. package/src/verification/sszTypes.ts +0 -88
  139. package/src/verification/termsAndConditions.ts +0 -32
  140. package/src/verification/v1.10.0.ts +0 -245
  141. package/src/verification/v1.6.0.ts +0 -256
  142. package/src/verification/v1.7.0.ts +0 -309
  143. package/src/verification/v1.8.0.ts +0 -340
@@ -1,202 +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 utils = __importStar(require("../../src/utils"));
39
- const incentivesHelpers = __importStar(require("../../src/incentives/incentiveHelpers"));
40
- const constants_1 = require("../../src/constants");
41
- const globals_1 = require("@jest/globals");
42
- const mnemonic = (_b = (_a = ethers_1.ethers.Wallet.createRandom().mnemonic) === null || _a === void 0 ? void 0 : _a.phrase) !== null && _b !== void 0 ? _b : '';
43
- const privateKey = ethers_1.ethers.Wallet.fromPhrase(mnemonic).privateKey;
44
- const provider = new ethers_1.JsonRpcProvider('https://ethereum-holesky.publicnode.com');
45
- const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
46
- const mockSigner = wallet.connect(provider);
47
- const baseUrl = 'https://obol-api-dev.gcp.obol.tech';
48
- // Fix the type error by properly typing the mock function
49
- global.fetch = globals_1.jest.fn();
50
- (0, globals_1.describe)('Client.incentives', () => {
51
- let clientInstance;
52
- const mockIncentivesData = {
53
- contract_address: '0x1234567890abcdef1234567890abcdef12345678',
54
- index: 5,
55
- operator_address: '0xabcdef1234567890abcdef1234567890abcdef12',
56
- amount: '1000000000000000000',
57
- merkle_proof: [
58
- '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
59
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
60
- ],
61
- };
62
- (0, globals_1.beforeEach)(() => {
63
- globals_1.jest.clearAllMocks();
64
- clientInstance = new index_1.Client({ baseUrl, chainId: 17000 }, mockSigner);
65
- global.fetch.mockReset();
66
- });
67
- (0, globals_1.test)('claimIncentives should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
68
- const clientWithoutSigner = new index_1.Client({
69
- baseUrl,
70
- chainId: 17000,
71
- });
72
- yield (0, globals_1.expect)(clientWithoutSigner.incentives.claimIncentives(mockIncentivesData.operator_address)).rejects.toThrow('Signer is required in claimIncentives');
73
- }));
74
- (0, globals_1.test)('claimIncentives should throw an error if contract is not available', () => __awaiter(void 0, void 0, void 0, function* () {
75
- globals_1.jest
76
- .spyOn(clientInstance.incentives, 'getIncentivesByAddress')
77
- .mockResolvedValue(mockIncentivesData);
78
- globals_1.jest.spyOn(clientInstance.incentives, 'isClaimed').mockResolvedValue(false);
79
- globals_1.jest
80
- .spyOn(utils, 'isContractAvailable')
81
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(false); }));
82
- yield (0, globals_1.expect)(clientInstance.incentives.claimIncentives(mockIncentivesData.operator_address)).rejects.toThrow(`Merkle Distributor contract is not available at address ${mockIncentivesData.contract_address}`);
83
- }));
84
- (0, globals_1.test)('claimIncentives should return txHash on successful claim', () => __awaiter(void 0, void 0, void 0, function* () {
85
- const mockTxHash = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
86
- globals_1.jest
87
- .spyOn(clientInstance.incentives, 'getIncentivesByAddress')
88
- .mockResolvedValue(mockIncentivesData);
89
- globals_1.jest.spyOn(clientInstance.incentives, 'isClaimed').mockResolvedValue(false);
90
- globals_1.jest
91
- .spyOn(utils, 'isContractAvailable')
92
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
93
- globals_1.jest
94
- .spyOn(incentivesHelpers, 'claimIncentivesFromMerkleDistributor')
95
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve({ txHash: mockTxHash }); }));
96
- const result = yield clientInstance.incentives.claimIncentives(mockIncentivesData.operator_address);
97
- (0, globals_1.expect)(result).toEqual({ txHash: mockTxHash });
98
- (0, globals_1.expect)(incentivesHelpers.claimIncentivesFromMerkleDistributor).toHaveBeenCalledWith({
99
- signer: mockSigner,
100
- contractAddress: mockIncentivesData.contract_address,
101
- index: mockIncentivesData.index,
102
- operatorAddress: mockIncentivesData.operator_address,
103
- amount: mockIncentivesData.amount,
104
- merkleProof: mockIncentivesData.merkle_proof,
105
- });
106
- }));
107
- (0, globals_1.test)('claimIncentives should return txHash as null when incentives are already claimed', () => __awaiter(void 0, void 0, void 0, function* () {
108
- globals_1.jest
109
- .spyOn(clientInstance.incentives, 'getIncentivesByAddress')
110
- .mockResolvedValue(mockIncentivesData);
111
- globals_1.jest.spyOn(clientInstance.incentives, 'isClaimed').mockResolvedValue(true);
112
- const result = yield clientInstance.incentives.claimIncentives(mockIncentivesData.operator_address);
113
- (0, globals_1.expect)(result).toEqual({ txHash: null });
114
- (0, globals_1.expect)(incentivesHelpers.claimIncentivesFromMerkleDistributor).not.toHaveBeenCalled();
115
- }));
116
- (0, globals_1.test)('claimIncentives should throw an error if no incentives found for address', () => __awaiter(void 0, void 0, void 0, function* () {
117
- globals_1.jest
118
- .spyOn(clientInstance.incentives, 'getIncentivesByAddress')
119
- .mockRejectedValue(new Error('No incentives found for address'));
120
- yield (0, globals_1.expect)(clientInstance.incentives.claimIncentives(mockIncentivesData.operator_address)).rejects.toThrow('Failed to claim incentives: No incentives found for address');
121
- }));
122
- (0, globals_1.test)('claimIncentives should throw an error if helper function fails', () => __awaiter(void 0, void 0, void 0, function* () {
123
- globals_1.jest
124
- .spyOn(clientInstance.incentives, 'getIncentivesByAddress')
125
- .mockResolvedValue(mockIncentivesData);
126
- globals_1.jest.spyOn(clientInstance.incentives, 'isClaimed').mockResolvedValue(false);
127
- globals_1.jest
128
- .spyOn(utils, 'isContractAvailable')
129
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
130
- globals_1.jest
131
- .spyOn(incentivesHelpers, 'claimIncentivesFromMerkleDistributor')
132
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
133
- throw new Error('Helper function error');
134
- }));
135
- yield (0, globals_1.expect)(clientInstance.incentives.claimIncentives(mockIncentivesData.operator_address)).rejects.toThrow('Failed to claim incentives: Helper function error');
136
- }));
137
- (0, globals_1.test)('incentives should be initialized with the same chainId as client', () => {
138
- const customChainId = 5;
139
- const clientWithCustomChain = new index_1.Client({ baseUrl, chainId: customChainId }, mockSigner);
140
- (0, globals_1.expect)(clientWithCustomChain.incentives.chainId).toBe(customChainId);
141
- });
142
- (0, globals_1.test)('isClaimed should return true when incentive is claimed', () => __awaiter(void 0, void 0, void 0, function* () {
143
- globals_1.jest
144
- .spyOn(incentivesHelpers, 'isClaimedFromMerkleDistributor')
145
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
146
- const result = yield clientInstance.incentives.isClaimed(mockIncentivesData.contract_address, mockIncentivesData.index);
147
- (0, globals_1.expect)(result).toBe(true);
148
- (0, globals_1.expect)(incentivesHelpers.isClaimedFromMerkleDistributor).toHaveBeenCalledWith(mockIncentivesData.contract_address, mockIncentivesData.index, {});
149
- }));
150
- (0, globals_1.test)('isClaimed should return false when incentive is not claimed', () => __awaiter(void 0, void 0, void 0, function* () {
151
- globals_1.jest
152
- .spyOn(incentivesHelpers, 'isClaimedFromMerkleDistributor')
153
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(false); }));
154
- const result = yield clientInstance.incentives.isClaimed(mockIncentivesData.contract_address, mockIncentivesData.index);
155
- (0, globals_1.expect)(result).toBe(false);
156
- }));
157
- (0, globals_1.test)('isClaimed should throw an error if helper function fails', () => __awaiter(void 0, void 0, void 0, function* () {
158
- globals_1.jest
159
- .spyOn(incentivesHelpers, 'isClaimedFromMerkleDistributor')
160
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
161
- throw new Error('Helper function error');
162
- }));
163
- yield (0, globals_1.expect)(clientInstance.incentives.isClaimed(mockIncentivesData.contract_address, mockIncentivesData.index)).rejects.toThrow('Helper function error');
164
- }));
165
- (0, globals_1.test)('isClaimed should work with a provider and a without signer', () => __awaiter(void 0, void 0, void 0, function* () {
166
- const clientWithoutSigner = new index_1.Client({
167
- baseUrl,
168
- chainId: 17000,
169
- }, undefined, provider);
170
- globals_1.jest
171
- .spyOn(incentivesHelpers, 'isClaimedFromMerkleDistributor')
172
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
173
- const result = yield clientWithoutSigner.incentives.isClaimed(mockIncentivesData.contract_address, mockIncentivesData.index);
174
- (0, globals_1.expect)(result).toBe(true);
175
- (0, globals_1.expect)(incentivesHelpers.isClaimedFromMerkleDistributor).toHaveBeenCalledWith(mockIncentivesData.contract_address, mockIncentivesData.index, provider);
176
- }));
177
- (0, globals_1.test)('getIncentivesByAddress should make the correct API request', () => __awaiter(void 0, void 0, void 0, function* () {
178
- const mockAddress = '0x1234567890abcdef1234567890abcdef12345678';
179
- const mockIncentives = {
180
- operator_address: '0x8c00157cae72c4ed6a1f8bfb60205601f0252e26',
181
- amount: '100',
182
- index: 1,
183
- merkle_proof: ['hash1', 'hash2'],
184
- contract_address: '0xContract',
185
- };
186
- global.fetch.mockResolvedValueOnce({
187
- ok: true,
188
- status: 200,
189
- json: () => __awaiter(void 0, void 0, void 0, function* () { return mockIncentives; }),
190
- headers: new Headers(),
191
- });
192
- const result = yield clientInstance.incentives.getIncentivesByAddress(mockAddress);
193
- (0, globals_1.expect)(result).toEqual(mockIncentives);
194
- (0, globals_1.expect)(global.fetch).toHaveBeenCalledWith(`${baseUrl}/${constants_1.DEFAULT_BASE_VERSION}/address/incentives/holesky/${mockAddress}`, globals_1.expect.objectContaining({ method: 'GET' }));
195
- }));
196
- (0, globals_1.test)('getIncentivesByAddress should handle API errors', () => __awaiter(void 0, void 0, void 0, function* () {
197
- const mockAddress = '0x1234567890abcdef1234567890abcdef12345678';
198
- global.fetch.mockRejectedValue(new Error('Network error'));
199
- yield (0, globals_1.expect)(clientInstance.incentives.getIncentivesByAddress(mockAddress)).rejects.toThrow();
200
- (0, globals_1.expect)(global.fetch).toHaveBeenCalled();
201
- }));
202
- });
@@ -1,402 +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 src_1 = require("../../src");
13
- const constants_1 = require("../../src/constants");
14
- const splitHelpers_1 = require("../../src/splits/splitHelpers");
15
- const utils_1 = require("../../src/utils");
16
- const fixtures_1 = require("../fixtures");
17
- // Mock the split helpers
18
- jest.mock('../../src/splits/splitHelpers', () => ({
19
- formatRecipientsForSplitV2: jest.fn(),
20
- predictSplitV2Address: jest.fn(),
21
- isSplitV2Deployed: jest.fn(),
22
- deployOVMContract: jest.fn(),
23
- deployOVMAndSplitV2: jest.fn(),
24
- requestWithdrawalFromOVM: jest.fn(),
25
- depositWithMulticall3: jest.fn(),
26
- }));
27
- // Mock the utils
28
- jest.mock('../../src/utils', () => ({
29
- isContractAvailable: jest.fn(),
30
- }));
31
- // Mock the validation
32
- jest.mock('../../src/ajv', () => ({
33
- validatePayload: jest.fn(data => data),
34
- }));
35
- // Type the mocked functions
36
- const mockFormatRecipientsForSplitV2 = splitHelpers_1.formatRecipientsForSplitV2;
37
- const mockPredictSplitV2Address = splitHelpers_1.predictSplitV2Address;
38
- const mockIsSplitV2Deployed = splitHelpers_1.isSplitV2Deployed;
39
- const mockDeployOVMAndSplitV2 = splitHelpers_1.deployOVMAndSplitV2;
40
- const mockDeployOVMContract = splitHelpers_1.deployOVMContract;
41
- const mockRequestWithdrawalFromOVM = splitHelpers_1.requestWithdrawalFromOVM;
42
- const mockdepositWithMulticall3 = splitHelpers_1.depositWithMulticall3;
43
- const mockIsContractAvailable = utils_1.isContractAvailable;
44
- describe('ObolSplits', () => {
45
- let client;
46
- let mockSigner;
47
- let mockProvider;
48
- beforeEach(() => {
49
- // Clear all mocks before each test
50
- jest.clearAllMocks();
51
- // Reset the mock to not be called by default
52
- mockRequestWithdrawalFromOVM.mockReset();
53
- mockSigner = {
54
- getAddress: jest
55
- .fn()
56
- .mockResolvedValue('0x1234567890123456789012345678901234567890'),
57
- signTypedData: jest.fn().mockResolvedValue('0xsigned'),
58
- provider: {
59
- getCode: jest.fn().mockResolvedValue('0x123456'),
60
- },
61
- };
62
- mockProvider = {
63
- getCode: jest.fn().mockResolvedValue('0x123456'),
64
- };
65
- client = new src_1.Client({ chainId: 1 }, mockSigner, mockProvider);
66
- });
67
- describe('createValidatorManagerAndRewardsSplit', () => {
68
- const mockRewardsSplitPayload = {
69
- rewardSplitRecipients: [
70
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
71
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
72
- ],
73
- OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
74
- splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
75
- principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
76
- distributorFeePercent: 0,
77
- };
78
- it('should create rewards-only split successfully', () => __awaiter(void 0, void 0, void 0, function* () {
79
- // Mock helper functions
80
- mockFormatRecipientsForSplitV2.mockReturnValue([
81
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
82
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
83
- {
84
- address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
85
- percentAllocation: 1,
86
- },
87
- ]);
88
- mockPredictSplitV2Address.mockResolvedValue('0xRewardsSplitAddress');
89
- mockIsSplitV2Deployed.mockResolvedValue(false);
90
- mockDeployOVMAndSplitV2.mockResolvedValue('0xOVMAddress');
91
- mockIsContractAvailable.mockResolvedValue(true);
92
- const result = yield client.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload);
93
- expect(result).toEqual({
94
- withdrawal_address: '0xOVMAddress',
95
- fee_recipient_address: '0xRewardsSplitAddress',
96
- });
97
- expect(mockFormatRecipientsForSplitV2).toHaveBeenCalled();
98
- expect(mockPredictSplitV2Address).toHaveBeenCalled();
99
- expect(mockIsSplitV2Deployed).toHaveBeenCalled();
100
- expect(mockDeployOVMAndSplitV2).toHaveBeenCalled();
101
- }));
102
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
103
- const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
104
- yield expect(clientWithoutSigner.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('Signer is required in createValidatorManagerAndRewardsSplit');
105
- }));
106
- it('should throw error when chain is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
107
- const clientUnsupportedChain = new src_1.Client({ chainId: 999 }, mockSigner, mockProvider);
108
- yield expect(clientUnsupportedChain.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('Splitter configuration is not supported on 999 chain');
109
- }));
110
- it('should throw error when OVM factory is not configured', () => __awaiter(void 0, void 0, void 0, function* () {
111
- // Mock chain configuration without OVM factory
112
- const originalConfig = constants_1.CHAIN_CONFIGURATION[1];
113
- // Create a new config object without OVM_FACTORY_CONTRACT
114
- const configWithoutOVM = Object.assign({}, originalConfig);
115
- delete configWithoutOVM.OVM_FACTORY_CONTRACT;
116
- constants_1.CHAIN_CONFIGURATION[1] = configWithoutOVM;
117
- yield expect(client.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('OVM contract factory is not configured for chain 1');
118
- // Restore original config
119
- constants_1.CHAIN_CONFIGURATION[1] = originalConfig;
120
- }));
121
- });
122
- describe('createValidatorManagerAndTotalSplit', () => {
123
- const mockTotalSplitPayload = {
124
- rewardSplitRecipients: [
125
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
126
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
127
- ],
128
- principalSplitRecipients: [
129
- {
130
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
131
- percentAllocation: 60,
132
- },
133
- {
134
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
135
- percentAllocation: 40,
136
- },
137
- ],
138
- OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
139
- splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
140
- distributorFeePercent: 0,
141
- };
142
- it('should create total split successfully', () => __awaiter(void 0, void 0, void 0, function* () {
143
- // Mock helper functions
144
- mockFormatRecipientsForSplitV2
145
- .mockReturnValueOnce([
146
- // rewards recipients
147
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
148
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
149
- {
150
- address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
151
- percentAllocation: 1,
152
- },
153
- ])
154
- .mockReturnValueOnce([
155
- // principal recipients
156
- {
157
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
158
- percentAllocation: 60,
159
- },
160
- {
161
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
162
- percentAllocation: 40,
163
- },
164
- ]);
165
- mockPredictSplitV2Address
166
- .mockResolvedValueOnce('0xRewardsSplitAddress')
167
- .mockResolvedValueOnce('0xPrincipalSplitAddress');
168
- mockIsSplitV2Deployed
169
- .mockResolvedValueOnce(false) // rewards split not deployed
170
- .mockResolvedValueOnce(false); // principal split not deployed
171
- mockDeployOVMAndSplitV2.mockResolvedValue('0xOVMAddress');
172
- mockIsContractAvailable.mockResolvedValue(true);
173
- const result = yield client.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload);
174
- expect(result).toEqual({
175
- withdrawal_address: '0xOVMAddress',
176
- fee_recipient_address: '0xRewardsSplitAddress',
177
- });
178
- expect(mockFormatRecipientsForSplitV2).toHaveBeenCalledTimes(2);
179
- expect(mockPredictSplitV2Address).toHaveBeenCalledTimes(2);
180
- expect(mockIsSplitV2Deployed).toHaveBeenCalledTimes(2);
181
- expect(mockDeployOVMAndSplitV2).toHaveBeenCalled();
182
- }));
183
- it('should handle case when both splits are already deployed', () => __awaiter(void 0, void 0, void 0, function* () {
184
- // Mock helper functions
185
- mockFormatRecipientsForSplitV2
186
- .mockReturnValueOnce([
187
- // rewards recipients
188
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
189
- { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
190
- {
191
- address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
192
- percentAllocation: 1,
193
- },
194
- ])
195
- .mockReturnValueOnce([
196
- // principal recipients
197
- {
198
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
199
- percentAllocation: 60,
200
- },
201
- {
202
- address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
203
- percentAllocation: 40,
204
- },
205
- ]);
206
- mockPredictSplitV2Address
207
- .mockResolvedValueOnce('0xRewardsSplitAddress')
208
- .mockResolvedValueOnce('0xPrincipalSplitAddress');
209
- mockIsSplitV2Deployed
210
- .mockResolvedValueOnce(true) // rewards split deployed
211
- .mockResolvedValueOnce(true); // principal split deployed
212
- mockDeployOVMContract.mockResolvedValue('0xOVMAddress');
213
- mockIsContractAvailable.mockResolvedValue(true);
214
- const result = yield client.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload);
215
- expect(result).toEqual({
216
- withdrawal_address: '0xOVMAddress',
217
- fee_recipient_address: '0xRewardsSplitAddress',
218
- });
219
- expect(mockDeployOVMContract).toHaveBeenCalledWith({
220
- OVMOwnerAddress: mockTotalSplitPayload.OVMOwnerAddress,
221
- principalRecipient: '0xPrincipalSplitAddress',
222
- rewardRecipient: '0xRewardsSplitAddress',
223
- principalThreshold: mockTotalSplitPayload.principalThreshold,
224
- signer: mockSigner,
225
- chainId: 1,
226
- });
227
- }));
228
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
229
- const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
230
- yield expect(clientWithoutSigner.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload)).rejects.toThrow('Signer is required in createValidatorManagerAndTotalSplit');
231
- }));
232
- it('should throw error when chain is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
233
- const clientUnsupportedChain = new src_1.Client({ chainId: 999 }, mockSigner, mockProvider);
234
- yield expect(clientUnsupportedChain.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload)).rejects.toThrow('Splitter configuration is not supported on 999 chain');
235
- }));
236
- });
237
- describe('requestWithdrawal', () => {
238
- const mockOVMAddress = '0x1234567890123456789012345678901234567890';
239
- const mockPubKeys = [
240
- '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
241
- ];
242
- const mockAmounts = ['32000000000']; // 32 ETH in gwei
243
- it('should request withdrawal successfully', () => __awaiter(void 0, void 0, void 0, function* () {
244
- mockRequestWithdrawalFromOVM.mockResolvedValue({
245
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
246
- });
247
- const result = yield client.splits.requestWithdrawal({
248
- ovmAddress: mockOVMAddress,
249
- pubKeys: mockPubKeys,
250
- amounts: mockAmounts,
251
- withdrawalFees: '1',
252
- });
253
- expect(result).toEqual({
254
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
255
- });
256
- expect(mockRequestWithdrawalFromOVM).toHaveBeenCalledWith({
257
- ovmAddress: mockOVMAddress,
258
- pubKeys: mockPubKeys,
259
- amounts: mockAmounts,
260
- withdrawalFees: '1',
261
- signer: mockSigner,
262
- });
263
- }));
264
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
265
- const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
266
- yield expect(clientWithoutSigner.splits.requestWithdrawal({
267
- ovmAddress: mockOVMAddress,
268
- pubKeys: mockPubKeys,
269
- amounts: mockAmounts,
270
- withdrawalFees: '1',
271
- })).rejects.toThrow('Signer is required in requestWithdrawal');
272
- }));
273
- // it('should throw error when amount is below minimum (1,000,000 gwei)', async () => {
274
- // await expect(
275
- // client.splits.requestWithdrawal({
276
- // ovmAddress: mockOVMAddress,
277
- // pubKeys: mockPubKeys,
278
- // amounts: ['500000'], // Below minimum of 1,000,000 gwei
279
- // }),
280
- // ).rejects.toThrow('Validation failed');
281
- // });
282
- it('should handle multiple validators withdrawal request', () => __awaiter(void 0, void 0, void 0, function* () {
283
- const multiplePubKeys = [
284
- '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
285
- '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
286
- ];
287
- const multipleAmounts = [
288
- '32000000000', // 32 ETH
289
- '16000000000', // 16 ETH
290
- ];
291
- mockRequestWithdrawalFromOVM.mockResolvedValue({
292
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
293
- });
294
- const result = yield client.splits.requestWithdrawal({
295
- ovmAddress: mockOVMAddress,
296
- pubKeys: multiplePubKeys,
297
- amounts: multipleAmounts,
298
- withdrawalFees: '1',
299
- });
300
- expect(result).toEqual({
301
- txHash: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
302
- });
303
- expect(mockRequestWithdrawalFromOVM).toHaveBeenCalledWith({
304
- ovmAddress: mockOVMAddress,
305
- pubKeys: multiplePubKeys,
306
- amounts: multipleAmounts,
307
- withdrawalFees: '1',
308
- signer: mockSigner,
309
- });
310
- }));
311
- });
312
- describe('deposit', () => {
313
- const mockOVMAddress = '0x1234567890123456789012345678901234567890';
314
- const mockDeposits = [
315
- {
316
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
317
- withdrawal_credentials: '0x1234567890123456789012345678901234567890',
318
- signature: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
319
- deposit_data_root: '0x1234567890123456789012345678901234567890123456789012345678901234',
320
- amount: '32000000000000000000', // 32 ETH in wei
321
- },
322
- ];
323
- beforeEach(() => {
324
- mockdepositWithMulticall3.mockReset();
325
- });
326
- it('should successfully deposit to OVM with multicall3', () => __awaiter(void 0, void 0, void 0, function* () {
327
- mockdepositWithMulticall3.mockResolvedValue({
328
- txHashes: [
329
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
330
- ],
331
- });
332
- const result = yield client.splits.deposit({
333
- ovmAddress: mockOVMAddress,
334
- deposits: mockDeposits,
335
- });
336
- expect(result).toEqual({
337
- txHashes: [
338
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
339
- ],
340
- });
341
- expect(mockdepositWithMulticall3).toHaveBeenCalledWith({
342
- ovmAddress: mockOVMAddress,
343
- deposits: mockDeposits,
344
- signer: mockSigner,
345
- chainId: 1,
346
- });
347
- }));
348
- it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
349
- const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
350
- yield expect(clientWithoutSigner.splits.deposit({
351
- ovmAddress: mockOVMAddress,
352
- deposits: mockDeposits,
353
- })).rejects.toThrow('Signer is required in deposit');
354
- }));
355
- it('should handle multiple deposits', () => __awaiter(void 0, void 0, void 0, function* () {
356
- const multipleDeposits = [
357
- {
358
- pubkey: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
359
- withdrawal_credentials: '0x1234567890123456789012345678901234567890',
360
- signature: '0x123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456',
361
- deposit_data_root: '0x1234567890123456789012345678901234567890123456789012345678901234',
362
- amount: '32000000000000000000', // 32 ETH in wei
363
- },
364
- {
365
- pubkey: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
366
- withdrawal_credentials: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
367
- signature: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
368
- deposit_data_root: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
369
- amount: '16000000000000000000', // 16 ETH in wei
370
- },
371
- ];
372
- mockdepositWithMulticall3.mockResolvedValue({
373
- txHashes: [
374
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
375
- ],
376
- });
377
- const result = yield client.splits.deposit({
378
- ovmAddress: mockOVMAddress,
379
- deposits: multipleDeposits,
380
- });
381
- expect(result).toEqual({
382
- txHashes: [
383
- '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
384
- ],
385
- });
386
- expect(mockdepositWithMulticall3).toHaveBeenCalledWith({
387
- ovmAddress: mockOVMAddress,
388
- deposits: multipleDeposits,
389
- signer: mockSigner,
390
- chainId: 1,
391
- });
392
- }));
393
- });
394
- describe('constructor', () => {
395
- it('should create Client instance with splits property', () => {
396
- const testClient = new src_1.Client({ chainId: 1 }, mockSigner, mockProvider);
397
- expect(testClient.splits).toBeDefined();
398
- expect(testClient.splits.chainId).toBe(1);
399
- expect(testClient.splits.provider).toBe(mockProvider);
400
- });
401
- });
402
- });