@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,571 +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
- exports.depositWithMulticall3 = exports.requestWithdrawalFromOVM = exports.deployOVMAndSplitV2 = exports.deployOVMContract = exports.isSplitV2Deployed = exports.predictSplitV2Address = exports.formatRecipientsForSplitV2 = exports.multicall3 = exports.getOWRTranches = exports.deploySplitterAndOWRContracts = exports.deploySplitterContract = exports.handleDeployOWRAndSplitter = exports.predictSplitterAddress = exports.formatSplitRecipients = void 0;
13
- const ethers_1 = require("ethers");
14
- const OWR_1 = require("../abi/OWR");
15
- const OVM_1 = require("../abi/OVM");
16
- const SplitMain_1 = require("../abi/SplitMain");
17
- const constants_1 = require("../constants");
18
- const splitV2FactoryAbi_1 = require("../abi/splitV2FactoryAbi");
19
- const Multicall3_1 = require("../abi/Multicall3");
20
- const splitMainContractInterface = new ethers_1.Interface(SplitMain_1.splitMainEthereumAbi);
21
- const owrFactoryContractInterface = new ethers_1.Interface(OWR_1.OWRFactoryContract.abi);
22
- const ovmFactoryContractInterface = new ethers_1.Interface(OVM_1.OVMFactoryContract.abi);
23
- const splitV2FactoryInterface = new ethers_1.Interface(splitV2FactoryAbi_1.splitV2FactoryAbi);
24
- // Helper function to extract common recipient formatting logic
25
- const formatRecipientsCommon = (recipients) => {
26
- const copiedRecipients = [...recipients];
27
- // Handle both SplitRecipient and SplitV2Recipient types
28
- const getAddress = (item) => item.account || item.address;
29
- const getPercentAllocation = (item) => item.percentAllocation;
30
- // Has to be sorted when passed
31
- copiedRecipients.sort((a, b) => getAddress(a).localeCompare(getAddress(b)));
32
- return {
33
- sortedRecipients: copiedRecipients,
34
- getAddress,
35
- getPercentAllocation,
36
- };
37
- };
38
- const formatSplitRecipients = (recipients) => {
39
- const { sortedRecipients, getAddress, getPercentAllocation } = formatRecipientsCommon(recipients);
40
- const accounts = sortedRecipients.map(item => getAddress(item));
41
- const percentAllocations = sortedRecipients.map(recipient => {
42
- const splitTostring = (getPercentAllocation(recipient) * 1e4).toFixed(0);
43
- return parseInt(splitTostring);
44
- });
45
- return { accounts, percentAllocations };
46
- };
47
- exports.formatSplitRecipients = formatSplitRecipients;
48
- const predictSplitterAddress = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
49
- var _a, _b, _c;
50
- try {
51
- const splitMainContractInstance = new ethers_1.Contract(getChainConfig(chainId).SPLITMAIN_CONTRACT.address, SplitMain_1.splitMainEthereumAbi, signer);
52
- let predictedSplitterAddress;
53
- if (controllerAddress === ethers_1.ZeroAddress) {
54
- try {
55
- predictedSplitterAddress =
56
- yield splitMainContractInstance.predictImmutableSplitAddress(accounts, percentAllocations, distributorFee);
57
- }
58
- catch (error) {
59
- throw new Error(`Failed to predict immutable splitter address: ${(_a = error.message) !== null && _a !== void 0 ? _a : 'Contract call failed'}`);
60
- }
61
- }
62
- else {
63
- try {
64
- // It throws on deployed Immutable splitter
65
- predictedSplitterAddress =
66
- yield splitMainContractInstance.createSplit.staticCall(accounts, percentAllocations, distributorFee, controllerAddress);
67
- }
68
- catch (error) {
69
- throw new Error(`Failed to predict mutable splitter address via static call: ${(_b = error.message) !== null && _b !== void 0 ? _b : 'Static call failed'}`);
70
- }
71
- }
72
- return predictedSplitterAddress;
73
- }
74
- catch (error) {
75
- // Re-throw if it's already our custom error
76
- if (error.message.includes('Failed to predict')) {
77
- throw error;
78
- }
79
- // Handle unexpected errors
80
- throw new Error(`Unexpected error in predictSplitterAddress: ${(_c = error.message) !== null && _c !== void 0 ? _c : 'Unknown contract interaction error'}`);
81
- }
82
- });
83
- exports.predictSplitterAddress = predictSplitterAddress;
84
- const handleDeployOWRAndSplitter = ({ signer, isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, etherAmount, principalRecipient, chainId, distributorFee, controllerAddress, recoveryAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
85
- var _d, _e, _f;
86
- try {
87
- if (isSplitterDeployed) {
88
- let owrAddress;
89
- try {
90
- owrAddress = yield createOWRContract({
91
- owrArgs: {
92
- principalRecipient,
93
- amountOfPrincipalStake: etherAmount,
94
- predictedSplitterAddress,
95
- recoveryAddress,
96
- },
97
- signer,
98
- chainId,
99
- });
100
- }
101
- catch (error) {
102
- throw new Error(`Failed to create OWR contract with existing splitter: ${(_d = error.message) !== null && _d !== void 0 ? _d : 'OWR contract creation failed'}`);
103
- }
104
- return {
105
- withdrawal_address: owrAddress,
106
- fee_recipient_address: predictedSplitterAddress,
107
- };
108
- }
109
- else {
110
- let owrAddress;
111
- let splitterAddress;
112
- try {
113
- const result = yield (0, exports.deploySplitterAndOWRContracts)({
114
- owrArgs: {
115
- principalRecipient,
116
- amountOfPrincipalStake: etherAmount,
117
- predictedSplitterAddress,
118
- recoveryAddress,
119
- },
120
- splitterArgs: {
121
- accounts,
122
- percentAllocations,
123
- distributorFee,
124
- controllerAddress,
125
- },
126
- signer,
127
- chainId,
128
- });
129
- owrAddress = result.owrAddress;
130
- splitterAddress = result.splitterAddress;
131
- }
132
- catch (error) {
133
- throw new Error(`Failed to deploy both splitter and OWR contracts: ${(_e = error.message) !== null && _e !== void 0 ? _e : 'Multicall3 contract deployment failed'}`);
134
- }
135
- return {
136
- withdrawal_address: owrAddress,
137
- fee_recipient_address: splitterAddress,
138
- };
139
- }
140
- }
141
- catch (error) {
142
- // Re-throw if it's already our custom error
143
- if (error.message.includes('Failed to')) {
144
- throw error;
145
- }
146
- // Handle unexpected errors
147
- throw new Error(`Unexpected error in handleDeployOWRAndSplitter: ${(_f = error.message) !== null && _f !== void 0 ? _f : 'Unknown error during contract deployment orchestration'}`);
148
- }
149
- });
150
- exports.handleDeployOWRAndSplitter = handleDeployOWRAndSplitter;
151
- const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
152
- var _g, _h, _j, _k, _l;
153
- try {
154
- const OWRFactoryInstance = new ethers_1.Contract(getChainConfig(chainId).OWR_FACTORY_CONTRACT.address, OWR_1.OWRFactoryContract.abi, signer);
155
- let tx;
156
- try {
157
- tx = yield OWRFactoryInstance.createOWRecipient(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, (0, ethers_1.parseEther)(owrArgs.amountOfPrincipalStake.toString()));
158
- }
159
- catch (error) {
160
- throw new Error(`Failed to submit OWR contract creation transaction: ${(_g = error.message) !== null && _g !== void 0 ? _g : 'Transaction submission failed'}`);
161
- }
162
- let receipt;
163
- try {
164
- receipt = yield tx.wait();
165
- }
166
- catch (error) {
167
- throw new Error(`OWR contract creation transaction failed or was reverted: ${(_h = error.message) !== null && _h !== void 0 ? _h : 'Transaction execution failed'}`);
168
- }
169
- if (!((_j = receipt === null || receipt === void 0 ? void 0 : receipt.logs) === null || _j === void 0 ? void 0 : _j.length)) {
170
- throw new Error('OWR contract creation transaction succeeded but no events were emitted - unable to determine contract address');
171
- }
172
- const OWRAddressData = (_k = receipt.logs[0]) === null || _k === void 0 ? void 0 : _k.topics[1];
173
- if (!OWRAddressData) {
174
- throw new Error('OWR contract creation transaction succeeded but contract address could not be extracted from events');
175
- }
176
- const formattedOWRAddress = '0x' + OWRAddressData.slice(26, 66);
177
- // Basic address validation
178
- if (formattedOWRAddress.length !== 42 ||
179
- !formattedOWRAddress.startsWith('0x')) {
180
- throw new Error(`Invalid OWR contract address format: ${formattedOWRAddress}`);
181
- }
182
- return formattedOWRAddress;
183
- }
184
- catch (error) {
185
- // Re-throw if it's already our custom error
186
- if (error.message.includes('Failed to') ||
187
- error.message.includes('OWR contract') ||
188
- error.message.includes('Invalid OWR')) {
189
- throw error;
190
- }
191
- // Handle unexpected errors
192
- throw new Error(`Unexpected error in createOWRContract: ${(_l = error.message) !== null && _l !== void 0 ? _l : 'Unknown error during OWR contract creation'}`);
193
- }
194
- });
195
- const deploySplitterContract = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
196
- var _m, _o, _p, _q, _r;
197
- try {
198
- const splitMainContractInstance = new ethers_1.Contract(getChainConfig(chainId).SPLITMAIN_CONTRACT.address, SplitMain_1.splitMainEthereumAbi, signer);
199
- let tx;
200
- try {
201
- tx = yield splitMainContractInstance.createSplit(accounts, percentAllocations, distributorFee, controllerAddress);
202
- }
203
- catch (error) {
204
- throw new Error(`Failed to submit splitter contract creation transaction: ${(_m = error.message) !== null && _m !== void 0 ? _m : 'Transaction submission failed'}`);
205
- }
206
- let receipt;
207
- try {
208
- receipt = yield tx.wait();
209
- }
210
- catch (error) {
211
- throw new Error(`Splitter contract creation transaction failed or was reverted: ${(_o = error.message) !== null && _o !== void 0 ? _o : 'Transaction execution failed'}`);
212
- }
213
- if (!((_p = receipt === null || receipt === void 0 ? void 0 : receipt.logs) === null || _p === void 0 ? void 0 : _p.length)) {
214
- throw new Error('Splitter contract creation transaction succeeded but no events were emitted - unable to determine contract address');
215
- }
216
- const splitterAddressData = (_q = receipt.logs[0]) === null || _q === void 0 ? void 0 : _q.topics[1];
217
- if (!splitterAddressData) {
218
- throw new Error('Splitter contract creation transaction succeeded but contract address could not be extracted from events');
219
- }
220
- const formattedSplitterAddress = '0x' + splitterAddressData.slice(26, 66);
221
- // Basic address validation
222
- if (formattedSplitterAddress.length !== 42 ||
223
- !formattedSplitterAddress.startsWith('0x')) {
224
- throw new Error(`Invalid splitter contract address format: ${formattedSplitterAddress}`);
225
- }
226
- return formattedSplitterAddress;
227
- }
228
- catch (error) {
229
- // Re-throw if it's already our custom error
230
- if (error.message.includes('Failed to') ||
231
- error.message.includes('Splitter contract') ||
232
- error.message.includes('Invalid splitter')) {
233
- throw error;
234
- }
235
- // Handle unexpected errors
236
- throw new Error(`Unexpected error in deploySplitterContract: ${(_r = error.message) !== null && _r !== void 0 ? _r : 'Unknown error during splitter contract creation'}`);
237
- }
238
- });
239
- exports.deploySplitterContract = deploySplitterContract;
240
- const deploySplitterAndOWRContracts = ({ owrArgs, splitterArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
241
- var _s, _t;
242
- const executeCalls = [];
243
- const splitTxData = encodeCreateSplitTxData(splitterArgs.accounts, splitterArgs.percentAllocations, splitterArgs.distributorFee, splitterArgs.controllerAddress);
244
- const owrTxData = encodeCreateOWRecipientTxData(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, owrArgs.amountOfPrincipalStake);
245
- executeCalls.push({
246
- target: getChainConfig(chainId).SPLITMAIN_CONTRACT.address,
247
- callData: splitTxData,
248
- }, {
249
- target: getChainConfig(chainId).OWR_FACTORY_CONTRACT.address,
250
- callData: owrTxData,
251
- });
252
- const executeMultiCalls = yield (0, exports.multicall3)(executeCalls, signer, chainId);
253
- const splitAddressData = (_s = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[0]) === null || _s === void 0 ? void 0 : _s.topics[1];
254
- const formattedSplitterAddress = '0x' + (splitAddressData === null || splitAddressData === void 0 ? void 0 : splitAddressData.slice(26, 66));
255
- const owrAddressData = (_t = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[1]) === null || _t === void 0 ? void 0 : _t.topics[1];
256
- const formattedOwrAddress = '0x' + (owrAddressData === null || owrAddressData === void 0 ? void 0 : owrAddressData.slice(26, 66));
257
- return {
258
- owrAddress: formattedOwrAddress,
259
- splitterAddress: formattedSplitterAddress,
260
- };
261
- });
262
- exports.deploySplitterAndOWRContracts = deploySplitterAndOWRContracts;
263
- const getOWRTranches = ({ owrAddress, signer, }) => __awaiter(void 0, void 0, void 0, function* () {
264
- var _u, _v;
265
- try {
266
- const owrContract = new ethers_1.Contract(owrAddress, OWR_1.OWRContract.abi, signer);
267
- let res;
268
- try {
269
- res = yield owrContract.getTranches();
270
- }
271
- catch (error) {
272
- throw new Error(`Failed to call getTranches on OWR contract at ${owrAddress}: ${(_u = error.message) !== null && _u !== void 0 ? _u : 'Contract call failed'}`);
273
- }
274
- if (!res) {
275
- throw new Error(`OWR contract at ${owrAddress} returned empty result for getTranches()`);
276
- }
277
- return {
278
- principalRecipient: res.principalRecipient,
279
- rewardRecipient: res.rewardRecipient,
280
- amountOfPrincipalStake: res.amountOfPrincipalStake,
281
- };
282
- }
283
- catch (error) {
284
- // Re-throw if it's already our custom error
285
- if (error.message.includes('Failed to') ||
286
- error.message.includes('OWR contract')) {
287
- throw error;
288
- }
289
- // Handle unexpected errors
290
- throw new Error(`Unexpected error in getOWRTranches: ${(_v = error.message) !== null && _v !== void 0 ? _v : 'Unknown error while fetching OWR tranche data'}`);
291
- }
292
- });
293
- exports.getOWRTranches = getOWRTranches;
294
- const multicall3 = (calls, signer, chainId) => __awaiter(void 0, void 0, void 0, function* () {
295
- var _w, _x, _y;
296
- try {
297
- const chainConfig = getChainConfig(chainId);
298
- const multicall3Address = chainConfig.MULTICALL3_CONTRACT.address;
299
- const multiCall3ContractInstance = new ethers_1.Contract(multicall3Address, Multicall3_1.MultiCall3Contract.abi, signer);
300
- let tx;
301
- try {
302
- tx = yield multiCall3ContractInstance.aggregate(calls);
303
- }
304
- catch (error) {
305
- throw new Error(`Failed to submit multicall3 transaction: ${(_w = error.message) !== null && _w !== void 0 ? _w : 'Transaction submission failed'}`);
306
- }
307
- let receipt;
308
- try {
309
- receipt = yield tx.wait();
310
- }
311
- catch (error) {
312
- throw new Error(`Multicall3 transaction failed or was reverted: ${(_x = error.message) !== null && _x !== void 0 ? _x : 'Transaction execution failed'}`);
313
- }
314
- if (!receipt) {
315
- throw new Error('Multicall3 transaction succeeded but no receipt was returned');
316
- }
317
- return receipt;
318
- }
319
- catch (error) {
320
- // Re-throw if it's already our custom error
321
- if (error.message.includes('Failed to') ||
322
- error.message.includes('Multicall3 transaction')) {
323
- throw error;
324
- }
325
- // Handle unexpected errors
326
- throw new Error(`Unexpected error in multicall3: ${(_y = error.message) !== null && _y !== void 0 ? _y : 'Unknown error during multicall3 execution'}`);
327
- }
328
- });
329
- exports.multicall3 = multicall3;
330
- const encodeCreateSplitTxData = (accounts, percentAllocations, distributorFee, controller) => {
331
- return splitMainContractInterface.encodeFunctionData('createSplit', [
332
- accounts,
333
- percentAllocations,
334
- distributorFee,
335
- controller,
336
- ]);
337
- };
338
- const encodeCreateOWRecipientTxData = (recoveryAddress, principalRecipient, rewardRecipient, amountOfPrincipalStake) => {
339
- return owrFactoryContractInterface.encodeFunctionData('createOWRecipient', [
340
- recoveryAddress,
341
- principalRecipient,
342
- rewardRecipient,
343
- (0, ethers_1.parseEther)(amountOfPrincipalStake.toString()),
344
- ]);
345
- };
346
- // OVM and SplitV2 Helper Functions
347
- // Helper function to format recipients specifically for SplitV2 (returns SplitV2Recipient[])
348
- const formatRecipientsForSplitV2 = (splitRecipients) => {
349
- const { sortedRecipients, getAddress, getPercentAllocation } = formatRecipientsCommon(splitRecipients);
350
- return sortedRecipients
351
- .filter(item => getAddress(item) !== '')
352
- .map(item => ({
353
- address: getAddress(item),
354
- percentAllocation: parseFloat(getPercentAllocation(item).toString()),
355
- }));
356
- };
357
- exports.formatRecipientsForSplitV2 = formatRecipientsForSplitV2;
358
- // Helper function to create SplitV2 parameters
359
- const createSplitV2Params = (recipients, distributorFeePercent) => {
360
- const addresses = recipients.map(r => r.address);
361
- const allocations = recipients.map(r => Math.floor(r.percentAllocation * 1e4)); // Convert to basis points
362
- const totalAllocation = allocations.reduce((sum, allocation) => sum + allocation, 0);
363
- return {
364
- recipients: addresses,
365
- allocations,
366
- totalAllocation,
367
- distributionIncentive: distributorFeePercent,
368
- };
369
- };
370
- const predictSplitV2Address = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
371
- var _z, _0;
372
- try {
373
- const chainConfig = getChainConfig(chainId);
374
- if (!((_z = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLIT_V2_FACTORY_CONTRACT) === null || _z === void 0 ? void 0 : _z.address)) {
375
- throw new Error(`SplitV2 Factory not configured for chain ${chainId}`);
376
- }
377
- const splitV2FactoryContract = new ethers_1.Contract(chainConfig.SPLIT_V2_FACTORY_CONTRACT.address, splitV2FactoryAbi_1.splitV2FactoryAbi, signer);
378
- const splitParams = createSplitV2Params(recipients, distributorFeePercent);
379
- const predictedAddress = yield splitV2FactoryContract['predictDeterministicAddress((address[],uint256[],uint256,uint16),address,bytes32)'](splitParams, splitOwnerAddress, salt);
380
- return predictedAddress;
381
- }
382
- catch (error) {
383
- throw new Error(`Failed to predict SplitV2 address: ${(_0 = error.message) !== null && _0 !== void 0 ? _0 : 'SplitV2 contract call failed'}`);
384
- }
385
- });
386
- exports.predictSplitV2Address = predictSplitV2Address;
387
- const isSplitV2Deployed = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
388
- var _1;
389
- try {
390
- const chainConfig = getChainConfig(chainId);
391
- if (!((_1 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLIT_V2_FACTORY_CONTRACT) === null || _1 === void 0 ? void 0 : _1.address)) {
392
- throw new Error(`SplitV2 Factory not configured for chain ${chainId}`);
393
- }
394
- const splitV2FactoryContract = new ethers_1.Contract(chainConfig.SPLIT_V2_FACTORY_CONTRACT.address, splitV2FactoryAbi_1.splitV2FactoryAbi, signer);
395
- const splitParams = createSplitV2Params(recipients, distributorFeePercent);
396
- const [, exists] = yield splitV2FactoryContract.isDeployed(splitParams, splitOwnerAddress, salt);
397
- return exists;
398
- }
399
- catch (error) {
400
- // If the check fails, assume it's not deployed
401
- return false;
402
- }
403
- });
404
- exports.isSplitV2Deployed = isSplitV2Deployed;
405
- const deployOVMContract = ({ OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
406
- var _2, _3, _4;
407
- try {
408
- const chainConfig = getChainConfig(chainId);
409
- if (!((_2 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT) === null || _2 === void 0 ? void 0 : _2.address)) {
410
- throw new Error(`OVM Factory not configured for chain ${chainId}`);
411
- }
412
- const ovmFactoryContract = new ethers_1.Contract(chainConfig.OVM_FACTORY_CONTRACT.address, OVM_1.OVMFactoryContract.abi, signer);
413
- const tx = yield ovmFactoryContract.createObolValidatorManager(OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold * constants_1.ETHER_TO_GWEI);
414
- const receipt = yield tx.wait();
415
- // Extract OVM address from logs
416
- const ovmAddressLog = (_3 = receipt === null || receipt === void 0 ? void 0 : receipt.logs[1]) === null || _3 === void 0 ? void 0 : _3.topics[1];
417
- if (!ovmAddressLog) {
418
- throw new Error('Failed to extract OVM address from transaction logs');
419
- }
420
- const ovmAddress = '0x' + ovmAddressLog.slice(26, 66);
421
- return ovmAddress;
422
- }
423
- catch (error) {
424
- throw new Error(`Failed to deploy OVM contract: ${(_4 = error.message) !== null && _4 !== void 0 ? _4 : 'OVM deployment failed'}`);
425
- }
426
- });
427
- exports.deployOVMContract = deployOVMContract;
428
- const deployOVMAndSplitV2 = ({ ovmArgs, rewardRecipients, isRewardsSplitterDeployed, distributorFeePercent, salt, signer, chainId, principalSplitRecipients, isPrincipalSplitDeployed, splitOwnerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
429
- var _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
430
- try {
431
- const chainConfig = getChainConfig(chainId);
432
- if (!((_5 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT) === null || _5 === void 0 ? void 0 : _5.address)) {
433
- throw new Error(`OVM Factory not configured for chain ${chainId}`);
434
- }
435
- if (!((_6 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLIT_V2_FACTORY_CONTRACT) === null || _6 === void 0 ? void 0 : _6.address)) {
436
- throw new Error(`SplitV2 Factory not configured for chain ${chainId}`);
437
- }
438
- const executeCalls = [];
439
- if (rewardRecipients && !isRewardsSplitterDeployed) {
440
- // Create rewards split call data
441
- const splitParams = createSplitV2Params(rewardRecipients, distributorFeePercent);
442
- const rewardsSplitTxData = encodeCreateSplitV2DeterministicTxData(splitParams, splitOwnerAddress, salt);
443
- executeCalls.push({
444
- target: chainConfig.SPLIT_V2_FACTORY_CONTRACT.address,
445
- callData: rewardsSplitTxData,
446
- });
447
- }
448
- // Create principal split call data if needed (for total split scenario)
449
- if (principalSplitRecipients && !isPrincipalSplitDeployed) {
450
- const principalSplitParams = createSplitV2Params(principalSplitRecipients, distributorFeePercent);
451
- const principalSplitTxData = encodeCreateSplitV2DeterministicTxData(principalSplitParams, splitOwnerAddress, salt);
452
- executeCalls.push({
453
- target: chainConfig.SPLIT_V2_FACTORY_CONTRACT.address,
454
- callData: principalSplitTxData,
455
- });
456
- }
457
- // Create OVM call data
458
- const ovmTxData = encodeCreateOVMTxData(ovmArgs.OVMOwnerAddress, ovmArgs.principalRecipient, ovmArgs.rewardRecipient, ovmArgs.principalThreshold * constants_1.ETHER_TO_GWEI);
459
- executeCalls.push({
460
- target: chainConfig.OVM_FACTORY_CONTRACT.address,
461
- callData: ovmTxData,
462
- });
463
- // Execute multicall3
464
- const executeMultiCalls = yield (0, exports.multicall3)(executeCalls, signer, chainId);
465
- // Extract addresses from events
466
- let ovmAddress;
467
- const logsCount = ((_7 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs) === null || _7 === void 0 ? void 0 : _7.length) || 0;
468
- if (logsCount === 2) {
469
- ovmAddress = '0x' + ((_9 = (_8 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[1]) === null || _8 === void 0 ? void 0 : _8.topics[1]) === null || _9 === void 0 ? void 0 : _9.slice(26, 66));
470
- }
471
- else if (logsCount === 5) {
472
- ovmAddress = '0x' + ((_11 = (_10 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[4]) === null || _10 === void 0 ? void 0 : _10.topics[1]) === null || _11 === void 0 ? void 0 : _11.slice(26, 66));
473
- }
474
- else {
475
- ovmAddress = '0x' + ((_13 = (_12 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[7]) === null || _12 === void 0 ? void 0 : _12.topics[1]) === null || _13 === void 0 ? void 0 : _13.slice(26, 66));
476
- }
477
- if (!ovmAddress) {
478
- throw new Error('Failed to extract contract addresses from multicall3 events');
479
- }
480
- return ovmAddress;
481
- }
482
- catch (error) {
483
- throw new Error(`Failed to deploy OVM and SplitV2: ${(_14 = error.message) !== null && _14 !== void 0 ? _14 : 'Deployment failed'}`);
484
- }
485
- });
486
- exports.deployOVMAndSplitV2 = deployOVMAndSplitV2;
487
- const encodeCreateOVMTxData = (OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold) => {
488
- return ovmFactoryContractInterface.encodeFunctionData('createObolValidatorManager', [OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold]);
489
- };
490
- const encodeCreateSplitV2DeterministicTxData = (splitParams, splitOwnerAddress, salt) => {
491
- // creatorAddress can be kept as default https://docs.splits.org/sdk/splits-v2#createsplit
492
- return splitV2FactoryInterface.encodeFunctionData('createSplitDeterministic', [splitParams, splitOwnerAddress, ethers_1.ZeroAddress, salt]);
493
- };
494
- // Helper function to safely get chain configuration
495
- const getChainConfig = (chainId) => {
496
- const config = constants_1.CHAIN_CONFIGURATION[chainId];
497
- if (!config) {
498
- throw new Error(`Chain configuration not found for chain ID ${chainId}`);
499
- }
500
- return config;
501
- };
502
- /**
503
- * Requests withdrawal from an OVM contract
504
- * @param ovmAddress - The address of the OVM contract
505
- * @param pubKeys - Array of validator public keys in bytes format
506
- * @param amounts - Array of withdrawal amounts in wei (uint64)
507
- * @param signer - The signer to use for the transaction
508
- * @returns Promise that resolves to the transaction hash
509
- */
510
- const requestWithdrawalFromOVM = ({ ovmAddress, pubKeys, amounts, withdrawalFees, signer, }) => __awaiter(void 0, void 0, void 0, function* () {
511
- try {
512
- // Convert string amounts to bigint
513
- const bigintAmounts = amounts.map(amount => BigInt(amount));
514
- const ovmContract = new ethers_1.Contract(ovmAddress, OVM_1.OVMContract.abi, signer);
515
- const tx = yield ovmContract.requestWithdrawal(pubKeys, bigintAmounts, {
516
- value: BigInt(withdrawalFees),
517
- });
518
- const receipt = yield tx.wait();
519
- return { txHash: receipt.hash };
520
- }
521
- catch (error) {
522
- const errorMessage = error instanceof Error ? error.message : 'Request withdrawal failed';
523
- throw new Error(`Failed to request withdrawal from OVM: ${errorMessage}`);
524
- }
525
- });
526
- exports.requestWithdrawalFromOVM = requestWithdrawalFromOVM;
527
- /**
528
- * Deposits to OVM contract using multicall3 for batch operations
529
- * @param ovmAddress - The address of the OVM contract
530
- * @param deposits - Array of deposit objects with all required parameters
531
- * @param signer - The signer to use for the transaction
532
- * @returns Promise that resolves to an array of transaction hashes
533
- */
534
- const depositWithMulticall3 = ({ ovmAddress, deposits, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
535
- try {
536
- const ovmContract = new ethers_1.Contract(ovmAddress, OVM_1.OVMContract.abi, signer);
537
- const chainConfig = getChainConfig(chainId);
538
- const multicall3Address = chainConfig.MULTICALL3_CONTRACT.address;
539
- const multiCall3ContractInstance = new ethers_1.Contract(multicall3Address, Multicall3_1.MultiCall3Contract.abi, signer);
540
- const BATCH_SIZE = 500;
541
- const txHashes = [];
542
- // Process deposits in batches of 500
543
- for (let i = 0; i < deposits.length; i += BATCH_SIZE) {
544
- const batchDeposits = deposits.slice(i, i + BATCH_SIZE);
545
- // Use Multicall3 aggregate3Value (payable per-call)
546
- const callsWithValue = batchDeposits.map(deposit => ({
547
- target: ovmAddress,
548
- allowFailure: false,
549
- callData: ovmContract.interface.encodeFunctionData('deposit', [
550
- deposit.pubkey,
551
- deposit.withdrawal_credentials,
552
- deposit.signature,
553
- deposit.deposit_data_root,
554
- ]),
555
- value: BigInt(deposit.amount),
556
- }));
557
- const totalBatchValue = callsWithValue.reduce((sum, c) => sum + c.value, BigInt(0));
558
- const tx = yield multiCall3ContractInstance.aggregate3Value(callsWithValue, { value: totalBatchValue });
559
- const receipt = yield tx.wait();
560
- if (receipt === null || receipt === void 0 ? void 0 : receipt.hash) {
561
- txHashes.push(receipt.hash);
562
- }
563
- }
564
- return { txHashes };
565
- }
566
- catch (error) {
567
- const errorMessage = error instanceof Error ? error.message : 'Deposit failed';
568
- throw new Error(`Failed to deposit to OVM with multicall3: ${errorMessage}`);
569
- }
570
- });
571
- exports.depositWithMulticall3 = depositWithMulticall3;