@obolnetwork/obol-sdk 2.5.1 → 2.6.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.
- package/dist/cjs/package.json +3 -3
- package/dist/cjs/src/constants.js +13 -1
- package/dist/cjs/src/exits/ethUtils.js +57 -0
- package/dist/cjs/src/exits/exit.js +420 -0
- package/dist/cjs/src/exits/verificationHelpers.js +86 -0
- package/dist/cjs/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
- package/dist/cjs/src/{incentives.js → incentives/incentives.js} +3 -3
- package/dist/cjs/src/index.js +22 -4
- package/dist/cjs/src/splits/splitHelpers.js +327 -0
- package/dist/cjs/src/types.js +1 -0
- package/dist/cjs/test/exit/ethUtils.spec.js +83 -0
- package/dist/cjs/test/exit/exit.spec.js +328 -0
- package/dist/cjs/test/exit/verificationHelpers.spec.js +68 -0
- package/dist/cjs/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
- package/dist/esm/package.json +3 -3
- package/dist/esm/src/constants.js +12 -0
- package/dist/esm/src/exits/ethUtils.js +52 -0
- package/dist/esm/src/exits/exit.js +393 -0
- package/dist/esm/src/exits/verificationHelpers.js +81 -0
- package/dist/esm/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
- package/dist/esm/src/{incentives.js → incentives/incentives.js} +3 -3
- package/dist/esm/src/index.js +20 -3
- package/dist/esm/src/splits/splitHelpers.js +317 -0
- package/dist/esm/src/types.js +1 -0
- package/dist/esm/test/exit/ethUtils.spec.js +81 -0
- package/dist/esm/test/exit/exit.spec.js +303 -0
- package/dist/esm/test/exit/verificationHelpers.spec.js +66 -0
- package/dist/esm/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
- package/dist/types/src/constants.d.ts +5 -0
- package/dist/types/src/exits/ethUtils.d.ts +13 -0
- package/dist/types/src/exits/exit.d.ts +180 -0
- package/dist/types/src/exits/verificationHelpers.d.ts +20 -0
- package/dist/types/src/{incentiveHelpers.d.ts → incentives/incentiveHelpers.d.ts} +1 -1
- package/dist/types/src/{incentives.d.ts → incentives/incentives.d.ts} +1 -1
- package/dist/types/src/index.d.ts +16 -2
- package/dist/types/src/{splitHelpers.d.ts → splits/splitHelpers.d.ts} +1 -1
- package/dist/types/src/types.d.ts +98 -0
- package/dist/types/test/exit/verificationHelpers.spec.d.ts +1 -0
- package/dist/types/test/incentives/incentives.spec.d.ts +1 -0
- package/package.json +3 -3
- package/src/constants.ts +13 -0
- package/src/exits/ethUtils.ts +49 -0
- package/src/exits/exit.ts +564 -0
- package/src/exits/verificationHelpers.ts +110 -0
- package/src/{incentiveHelpers.ts → incentives/incentiveHelpers.ts} +2 -2
- package/src/{incentives.ts → incentives/incentives.ts} +3 -3
- package/src/index.ts +29 -3
- package/src/splits/splitHelpers.ts +557 -0
- package/src/types.ts +123 -0
- package/dist/cjs/src/splitHelpers.js +0 -187
- package/dist/cjs/test/methods.test.js +0 -418
- package/dist/esm/src/splitHelpers.js +0 -177
- package/dist/esm/test/methods.test.js +0 -393
- package/src/splitHelpers.ts +0 -355
- /package/dist/types/test/{incentives.test.d.ts → exit/ethUtils.spec.d.ts} +0 -0
- /package/dist/types/test/{methods.test.d.ts → exit/exit.spec.d.ts} +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Contract, Interface, parseEther, ZeroAddress } from 'ethers';
|
|
11
|
+
import { OWRContract, OWRFactoryContract } from '../abi/OWR';
|
|
12
|
+
import { splitMainEthereumAbi } from '../abi/SplitMain';
|
|
13
|
+
import { MultiCallContract } from '../abi/Multicall';
|
|
14
|
+
import { CHAIN_CONFIGURATION } from '../constants';
|
|
15
|
+
const splitMainContractInterface = new Interface(splitMainEthereumAbi);
|
|
16
|
+
const owrFactoryContractInterface = new Interface(OWRFactoryContract.abi);
|
|
17
|
+
export const formatSplitRecipients = (recipients) => {
|
|
18
|
+
// Has to be sorted when passed
|
|
19
|
+
recipients.sort((a, b) => a.account.localeCompare(b.account));
|
|
20
|
+
const accounts = recipients.map(item => item.account);
|
|
21
|
+
const percentAllocations = recipients.map(recipient => {
|
|
22
|
+
const splitTostring = (recipient.percentAllocation * 1e4).toFixed(0);
|
|
23
|
+
return parseInt(splitTostring);
|
|
24
|
+
});
|
|
25
|
+
return { accounts, percentAllocations };
|
|
26
|
+
};
|
|
27
|
+
export const predictSplitterAddress = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
try {
|
|
30
|
+
const splitMainContractInstance = new Contract(CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address, splitMainEthereumAbi, signer);
|
|
31
|
+
let predictedSplitterAddress;
|
|
32
|
+
if (controllerAddress === ZeroAddress) {
|
|
33
|
+
try {
|
|
34
|
+
predictedSplitterAddress =
|
|
35
|
+
yield splitMainContractInstance.predictImmutableSplitAddress(accounts, percentAllocations, distributorFee);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new Error(`Failed to predict immutable splitter address: ${(_a = error.message) !== null && _a !== void 0 ? _a : 'Contract call failed'}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
try {
|
|
43
|
+
// It throws on deployed Immutable splitter
|
|
44
|
+
predictedSplitterAddress =
|
|
45
|
+
yield splitMainContractInstance.createSplit.staticCall(accounts, percentAllocations, distributorFee, controllerAddress);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(`Failed to predict mutable splitter address via static call: ${(_b = error.message) !== null && _b !== void 0 ? _b : 'Static call failed'}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return predictedSplitterAddress;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// Re-throw if it's already our custom error
|
|
55
|
+
if (error.message.includes('Failed to predict')) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
// Handle unexpected errors
|
|
59
|
+
throw new Error(`Unexpected error in predictSplitterAddress: ${(_c = error.message) !== null && _c !== void 0 ? _c : 'Unknown contract interaction error'}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export const handleDeployOWRAndSplitter = ({ signer, isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, etherAmount, principalRecipient, chainId, distributorFee, controllerAddress, recoveryAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
var _d, _e, _f;
|
|
64
|
+
try {
|
|
65
|
+
if (isSplitterDeployed) {
|
|
66
|
+
let owrAddress;
|
|
67
|
+
try {
|
|
68
|
+
owrAddress = yield createOWRContract({
|
|
69
|
+
owrArgs: {
|
|
70
|
+
principalRecipient,
|
|
71
|
+
amountOfPrincipalStake: etherAmount,
|
|
72
|
+
predictedSplitterAddress,
|
|
73
|
+
recoveryAddress,
|
|
74
|
+
},
|
|
75
|
+
signer,
|
|
76
|
+
chainId,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new Error(`Failed to create OWR contract with existing splitter: ${(_d = error.message) !== null && _d !== void 0 ? _d : 'OWR contract creation failed'}`);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
withdrawal_address: owrAddress,
|
|
84
|
+
fee_recipient_address: predictedSplitterAddress,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
let owrAddress;
|
|
89
|
+
let splitterAddress;
|
|
90
|
+
try {
|
|
91
|
+
const result = yield deploySplitterAndOWRContracts({
|
|
92
|
+
owrArgs: {
|
|
93
|
+
principalRecipient,
|
|
94
|
+
amountOfPrincipalStake: etherAmount,
|
|
95
|
+
predictedSplitterAddress,
|
|
96
|
+
recoveryAddress,
|
|
97
|
+
},
|
|
98
|
+
splitterArgs: {
|
|
99
|
+
accounts,
|
|
100
|
+
percentAllocations,
|
|
101
|
+
distributorFee,
|
|
102
|
+
controllerAddress,
|
|
103
|
+
},
|
|
104
|
+
signer,
|
|
105
|
+
chainId,
|
|
106
|
+
});
|
|
107
|
+
owrAddress = result.owrAddress;
|
|
108
|
+
splitterAddress = result.splitterAddress;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new Error(`Failed to deploy both splitter and OWR contracts: ${(_e = error.message) !== null && _e !== void 0 ? _e : 'Multicall contract deployment failed'}`);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
withdrawal_address: owrAddress,
|
|
115
|
+
fee_recipient_address: splitterAddress,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Re-throw if it's already our custom error
|
|
121
|
+
if (error.message.includes('Failed to')) {
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
// Handle unexpected errors
|
|
125
|
+
throw new Error(`Unexpected error in handleDeployOWRAndSplitter: ${(_f = error.message) !== null && _f !== void 0 ? _f : 'Unknown error during contract deployment orchestration'}`);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
var _g, _h, _j, _k, _l;
|
|
130
|
+
try {
|
|
131
|
+
const OWRFactoryInstance = new Contract(CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address, OWRFactoryContract.abi, signer);
|
|
132
|
+
let tx;
|
|
133
|
+
try {
|
|
134
|
+
tx = yield OWRFactoryInstance.createOWRecipient(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, parseEther(owrArgs.amountOfPrincipalStake.toString()));
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
throw new Error(`Failed to submit OWR contract creation transaction: ${(_g = error.message) !== null && _g !== void 0 ? _g : 'Transaction submission failed'}`);
|
|
138
|
+
}
|
|
139
|
+
let receipt;
|
|
140
|
+
try {
|
|
141
|
+
receipt = yield tx.wait();
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new Error(`OWR contract creation transaction failed or was reverted: ${(_h = error.message) !== null && _h !== void 0 ? _h : 'Transaction execution failed'}`);
|
|
145
|
+
}
|
|
146
|
+
if (!((_j = receipt === null || receipt === void 0 ? void 0 : receipt.logs) === null || _j === void 0 ? void 0 : _j.length)) {
|
|
147
|
+
throw new Error('OWR contract creation transaction succeeded but no events were emitted - unable to determine contract address');
|
|
148
|
+
}
|
|
149
|
+
const OWRAddressData = (_k = receipt.logs[0]) === null || _k === void 0 ? void 0 : _k.topics[1];
|
|
150
|
+
if (!OWRAddressData) {
|
|
151
|
+
throw new Error('OWR contract creation transaction succeeded but contract address could not be extracted from events');
|
|
152
|
+
}
|
|
153
|
+
const formattedOWRAddress = '0x' + OWRAddressData.slice(26, 66);
|
|
154
|
+
// Basic address validation
|
|
155
|
+
if (formattedOWRAddress.length !== 42 ||
|
|
156
|
+
!formattedOWRAddress.startsWith('0x')) {
|
|
157
|
+
throw new Error(`Invalid OWR contract address format: ${formattedOWRAddress}`);
|
|
158
|
+
}
|
|
159
|
+
return formattedOWRAddress;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
// Re-throw if it's already our custom error
|
|
163
|
+
if (error.message.includes('Failed to') ||
|
|
164
|
+
error.message.includes('OWR contract') ||
|
|
165
|
+
error.message.includes('Invalid OWR')) {
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
// Handle unexpected errors
|
|
169
|
+
throw new Error(`Unexpected error in createOWRContract: ${(_l = error.message) !== null && _l !== void 0 ? _l : 'Unknown error during OWR contract creation'}`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
export const deploySplitterContract = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
var _m, _o, _p, _q, _r;
|
|
174
|
+
try {
|
|
175
|
+
const splitMainContractInstance = new Contract(CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address, splitMainEthereumAbi, signer);
|
|
176
|
+
let tx;
|
|
177
|
+
try {
|
|
178
|
+
tx = yield splitMainContractInstance.createSplit(accounts, percentAllocations, distributorFee, controllerAddress);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw new Error(`Failed to submit splitter contract creation transaction: ${(_m = error.message) !== null && _m !== void 0 ? _m : 'Transaction submission failed'}`);
|
|
182
|
+
}
|
|
183
|
+
let receipt;
|
|
184
|
+
try {
|
|
185
|
+
receipt = yield tx.wait();
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
throw new Error(`Splitter contract creation transaction failed or was reverted: ${(_o = error.message) !== null && _o !== void 0 ? _o : 'Transaction execution failed'}`);
|
|
189
|
+
}
|
|
190
|
+
if (!((_p = receipt === null || receipt === void 0 ? void 0 : receipt.logs) === null || _p === void 0 ? void 0 : _p.length)) {
|
|
191
|
+
throw new Error('Splitter contract creation transaction succeeded but no events were emitted - unable to determine contract address');
|
|
192
|
+
}
|
|
193
|
+
const splitterAddressData = (_q = receipt.logs[0]) === null || _q === void 0 ? void 0 : _q.topics[1];
|
|
194
|
+
if (!splitterAddressData) {
|
|
195
|
+
throw new Error('Splitter contract creation transaction succeeded but contract address could not be extracted from events');
|
|
196
|
+
}
|
|
197
|
+
const formattedSplitterAddress = '0x' + splitterAddressData.slice(26, 66);
|
|
198
|
+
// Basic address validation
|
|
199
|
+
if (formattedSplitterAddress.length !== 42 ||
|
|
200
|
+
!formattedSplitterAddress.startsWith('0x')) {
|
|
201
|
+
throw new Error(`Invalid splitter contract address format: ${formattedSplitterAddress}`);
|
|
202
|
+
}
|
|
203
|
+
return formattedSplitterAddress;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
// Re-throw if it's already our custom error
|
|
207
|
+
if (error.message.includes('Failed to') ||
|
|
208
|
+
error.message.includes('Splitter contract') ||
|
|
209
|
+
error.message.includes('Invalid splitter')) {
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
// Handle unexpected errors
|
|
213
|
+
throw new Error(`Unexpected error in deploySplitterContract: ${(_r = error.message) !== null && _r !== void 0 ? _r : 'Unknown error during splitter contract creation'}`);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
export const deploySplitterAndOWRContracts = ({ owrArgs, splitterArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
+
var _s, _t;
|
|
218
|
+
const executeCalls = [];
|
|
219
|
+
const splitTxData = encodeCreateSplitTxData(splitterArgs.accounts, splitterArgs.percentAllocations, splitterArgs.distributorFee, splitterArgs.controllerAddress);
|
|
220
|
+
const owrTxData = encodeCreateOWRecipientTxData(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, owrArgs.amountOfPrincipalStake);
|
|
221
|
+
executeCalls.push({
|
|
222
|
+
target: CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address,
|
|
223
|
+
callData: splitTxData,
|
|
224
|
+
}, {
|
|
225
|
+
target: CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address,
|
|
226
|
+
callData: owrTxData,
|
|
227
|
+
});
|
|
228
|
+
const multicallAddess = CHAIN_CONFIGURATION[chainId].MULTICALL_ADDRESS.address;
|
|
229
|
+
const executeMultiCalls = yield multicall(executeCalls, signer, multicallAddess);
|
|
230
|
+
const splitAddressData = (_s = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[0]) === null || _s === void 0 ? void 0 : _s.topics[1];
|
|
231
|
+
const formattedSplitterAddress = '0x' + (splitAddressData === null || splitAddressData === void 0 ? void 0 : splitAddressData.slice(26, 66));
|
|
232
|
+
const owrAddressData = (_t = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[1]) === null || _t === void 0 ? void 0 : _t.topics[1];
|
|
233
|
+
const formattedOwrAddress = '0x' + (owrAddressData === null || owrAddressData === void 0 ? void 0 : owrAddressData.slice(26, 66));
|
|
234
|
+
return {
|
|
235
|
+
owrAddress: formattedOwrAddress,
|
|
236
|
+
splitterAddress: formattedSplitterAddress,
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
export const getOWRTranches = ({ owrAddress, signer, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
+
var _u, _v;
|
|
241
|
+
try {
|
|
242
|
+
const owrContract = new Contract(owrAddress, OWRContract.abi, signer);
|
|
243
|
+
let res;
|
|
244
|
+
try {
|
|
245
|
+
res = yield owrContract.getTranches();
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
throw new Error(`Failed to call getTranches on OWR contract at ${owrAddress}: ${(_u = error.message) !== null && _u !== void 0 ? _u : 'Contract call failed'}`);
|
|
249
|
+
}
|
|
250
|
+
if (!res) {
|
|
251
|
+
throw new Error(`OWR contract at ${owrAddress} returned empty result for getTranches()`);
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
principalRecipient: res.principalRecipient,
|
|
255
|
+
rewardRecipient: res.rewardRecipient,
|
|
256
|
+
amountOfPrincipalStake: res.amountOfPrincipalStake,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
// Re-throw if it's already our custom error
|
|
261
|
+
if (error.message.includes('Failed to') ||
|
|
262
|
+
error.message.includes('OWR contract')) {
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
// Handle unexpected errors
|
|
266
|
+
throw new Error(`Unexpected error in getOWRTranches: ${(_v = error.message) !== null && _v !== void 0 ? _v : 'Unknown error while fetching OWR tranche data'}`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
export const multicall = (calls, signer, multicallAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
|
+
var _w, _x, _y;
|
|
271
|
+
try {
|
|
272
|
+
const multiCallContractInstance = new Contract(multicallAddress, MultiCallContract.abi, signer);
|
|
273
|
+
let tx;
|
|
274
|
+
try {
|
|
275
|
+
tx = yield multiCallContractInstance.aggregate(calls);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
throw new Error(`Failed to submit multicall transaction: ${(_w = error.message) !== null && _w !== void 0 ? _w : 'Transaction submission failed'}`);
|
|
279
|
+
}
|
|
280
|
+
let receipt;
|
|
281
|
+
try {
|
|
282
|
+
receipt = yield tx.wait();
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
throw new Error(`Multicall transaction failed or was reverted: ${(_x = error.message) !== null && _x !== void 0 ? _x : 'Transaction execution failed'}`);
|
|
286
|
+
}
|
|
287
|
+
if (!receipt) {
|
|
288
|
+
throw new Error('Multicall transaction succeeded but no receipt was returned');
|
|
289
|
+
}
|
|
290
|
+
return receipt;
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
// Re-throw if it's already our custom error
|
|
294
|
+
if (error.message.includes('Failed to') ||
|
|
295
|
+
error.message.includes('Multicall transaction')) {
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
// Handle unexpected errors
|
|
299
|
+
throw new Error(`Unexpected error in multicall: ${(_y = error.message) !== null && _y !== void 0 ? _y : 'Unknown error during multicall execution'}`);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
const encodeCreateSplitTxData = (accounts, percentAllocations, distributorFee, controller) => {
|
|
303
|
+
return splitMainContractInterface.encodeFunctionData('createSplit', [
|
|
304
|
+
accounts,
|
|
305
|
+
percentAllocations,
|
|
306
|
+
distributorFee,
|
|
307
|
+
controller,
|
|
308
|
+
]);
|
|
309
|
+
};
|
|
310
|
+
const encodeCreateOWRecipientTxData = (recoveryAddress, principalRecipient, rewardRecipient, amountOfPrincipalStake) => {
|
|
311
|
+
return owrFactoryContractInterface.encodeFunctionData('createOWRecipient', [
|
|
312
|
+
recoveryAddress,
|
|
313
|
+
principalRecipient,
|
|
314
|
+
rewardRecipient,
|
|
315
|
+
parseEther(amountOfPrincipalStake.toString()),
|
|
316
|
+
]);
|
|
317
|
+
};
|
package/dist/esm/src/types.js
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getCapellaFork, getGenesisValidatorsRoot, } from '../../src/exits/ethUtils';
|
|
11
|
+
import { CAPELLA_FORK_MAPPING } from '../../src/constants';
|
|
12
|
+
describe('ethUtils', () => {
|
|
13
|
+
describe('getCapellaFork', () => {
|
|
14
|
+
Object.entries(CAPELLA_FORK_MAPPING).forEach(([baseFork, expectedCapellaFork]) => {
|
|
15
|
+
it(`should return ${expectedCapellaFork} for base fork ${baseFork}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const result = yield getCapellaFork(baseFork);
|
|
17
|
+
expect(result).toBe(expectedCapellaFork);
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
it('should return null for an unknown base fork version', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const result = yield getCapellaFork('0xUNKNOWNFORK');
|
|
22
|
+
expect(result).toBeNull();
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
describe('getGenesisValidatorsRoot', () => {
|
|
26
|
+
const mockBeaconApiUrl = 'http://localhost:5052';
|
|
27
|
+
const mockGenesisRoot = '0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2';
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
// Reset fetch mock
|
|
30
|
+
global.fetch = jest.fn();
|
|
31
|
+
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
jest.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
it('should fetch and return the genesis_validators_root successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
global.fetch.mockResolvedValueOnce({
|
|
37
|
+
json: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
return ({
|
|
39
|
+
data: { genesis_validators_root: mockGenesisRoot },
|
|
40
|
+
});
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
|
|
44
|
+
expect(result).toBe(mockGenesisRoot);
|
|
45
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
46
|
+
expect(global.fetch).toHaveBeenCalledWith(`${mockBeaconApiUrl}/eth/v1/beacon/genesis`, { method: 'GET' });
|
|
47
|
+
}));
|
|
48
|
+
it('should return null if the HTTP request fails (e.g., network error)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
global.fetch.mockRejectedValueOnce(new Error('Network error'));
|
|
50
|
+
yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: Network error');
|
|
51
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
52
|
+
}));
|
|
53
|
+
it('should return null if the response data structure is invalid (missing genesis_validators_root)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
global.fetch.mockResolvedValueOnce({
|
|
55
|
+
json: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
return ({
|
|
57
|
+
data: { some_other_field: 'value' },
|
|
58
|
+
});
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
|
|
62
|
+
expect(result).toBeNull();
|
|
63
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
64
|
+
}));
|
|
65
|
+
it('should return null if the response data is missing', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
global.fetch.mockResolvedValueOnce({
|
|
67
|
+
json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); }),
|
|
68
|
+
});
|
|
69
|
+
const result = yield getGenesisValidatorsRoot(mockBeaconApiUrl);
|
|
70
|
+
expect(result).toBeNull();
|
|
71
|
+
}));
|
|
72
|
+
it('should throw an error if fetch throws an error with a message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
global.fetch.mockRejectedValueOnce(new Error('Custom HTTP error'));
|
|
74
|
+
yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: Custom HTTP error');
|
|
75
|
+
}));
|
|
76
|
+
it('should throw an error if fetch throws a non-Error object', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
global.fetch.mockRejectedValueOnce('some string error');
|
|
78
|
+
yield expect(getGenesisValidatorsRoot(mockBeaconApiUrl)).rejects.toThrow('Failed to fetch genesis validators root: some string error');
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
});
|