@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
package/src/splitHelpers.ts
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type OWRTranches,
|
|
3
|
-
type ClusterValidator,
|
|
4
|
-
type ETH_ADDRESS,
|
|
5
|
-
type SplitRecipient,
|
|
6
|
-
type SignerType,
|
|
7
|
-
} from './types';
|
|
8
|
-
import { Contract, Interface, parseEther, ZeroAddress } from 'ethers';
|
|
9
|
-
import { OWRContract, OWRFactoryContract } from './abi/OWR';
|
|
10
|
-
import { splitMainEthereumAbi } from './abi/SplitMain';
|
|
11
|
-
import { MultiCallContract } from './abi/Multicall';
|
|
12
|
-
import { CHAIN_CONFIGURATION } from './constants';
|
|
13
|
-
|
|
14
|
-
const splitMainContractInterface = new Interface(splitMainEthereumAbi);
|
|
15
|
-
const owrFactoryContractInterface = new Interface(OWRFactoryContract.abi);
|
|
16
|
-
|
|
17
|
-
type Call = {
|
|
18
|
-
target: ETH_ADDRESS;
|
|
19
|
-
callData: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type OWRArgs = {
|
|
23
|
-
recoveryAddress: ETH_ADDRESS;
|
|
24
|
-
principalRecipient: ETH_ADDRESS;
|
|
25
|
-
amountOfPrincipalStake: number;
|
|
26
|
-
predictedSplitterAddress: ETH_ADDRESS;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type SplitArgs = {
|
|
30
|
-
accounts: ETH_ADDRESS[];
|
|
31
|
-
percentAllocations: number[];
|
|
32
|
-
distributorFee: number;
|
|
33
|
-
controllerAddress: ETH_ADDRESS;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const formatSplitRecipients = (
|
|
37
|
-
recipients: SplitRecipient[],
|
|
38
|
-
): { accounts: ETH_ADDRESS[]; percentAllocations: number[] } => {
|
|
39
|
-
// Has to be sorted when passed
|
|
40
|
-
recipients.sort((a, b) => a.account.localeCompare(b.account));
|
|
41
|
-
const accounts = recipients.map(item => item.account);
|
|
42
|
-
const percentAllocations = recipients.map(recipient => {
|
|
43
|
-
const splitTostring = (recipient.percentAllocation * 1e4).toFixed(0);
|
|
44
|
-
return parseInt(splitTostring);
|
|
45
|
-
});
|
|
46
|
-
return { accounts, percentAllocations };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const predictSplitterAddress = async ({
|
|
50
|
-
signer,
|
|
51
|
-
accounts,
|
|
52
|
-
percentAllocations,
|
|
53
|
-
chainId,
|
|
54
|
-
distributorFee,
|
|
55
|
-
controllerAddress,
|
|
56
|
-
}: {
|
|
57
|
-
signer: SignerType;
|
|
58
|
-
accounts: ETH_ADDRESS[];
|
|
59
|
-
percentAllocations: number[];
|
|
60
|
-
chainId: number;
|
|
61
|
-
distributorFee: number;
|
|
62
|
-
controllerAddress: ETH_ADDRESS;
|
|
63
|
-
}): Promise<ETH_ADDRESS> => {
|
|
64
|
-
try {
|
|
65
|
-
let predictedSplitterAddress: string;
|
|
66
|
-
const splitMainContractInstance = new Contract(
|
|
67
|
-
CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address,
|
|
68
|
-
splitMainEthereumAbi,
|
|
69
|
-
signer,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (controllerAddress === ZeroAddress) {
|
|
73
|
-
predictedSplitterAddress =
|
|
74
|
-
await splitMainContractInstance.predictImmutableSplitAddress(
|
|
75
|
-
accounts,
|
|
76
|
-
percentAllocations,
|
|
77
|
-
distributorFee,
|
|
78
|
-
);
|
|
79
|
-
} else {
|
|
80
|
-
// It throws on deployed Immutable splitter
|
|
81
|
-
predictedSplitterAddress =
|
|
82
|
-
await splitMainContractInstance.createSplit.staticCall(
|
|
83
|
-
accounts,
|
|
84
|
-
percentAllocations,
|
|
85
|
-
distributorFee,
|
|
86
|
-
controllerAddress,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return predictedSplitterAddress;
|
|
91
|
-
} catch (e) {
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const handleDeployOWRAndSplitter = async ({
|
|
97
|
-
signer,
|
|
98
|
-
isSplitterDeployed,
|
|
99
|
-
predictedSplitterAddress,
|
|
100
|
-
accounts,
|
|
101
|
-
percentAllocations,
|
|
102
|
-
etherAmount,
|
|
103
|
-
principalRecipient,
|
|
104
|
-
chainId,
|
|
105
|
-
distributorFee,
|
|
106
|
-
controllerAddress,
|
|
107
|
-
recoveryAddress,
|
|
108
|
-
}: {
|
|
109
|
-
signer: SignerType;
|
|
110
|
-
isSplitterDeployed: boolean;
|
|
111
|
-
predictedSplitterAddress: ETH_ADDRESS;
|
|
112
|
-
accounts: ETH_ADDRESS[];
|
|
113
|
-
percentAllocations: number[];
|
|
114
|
-
etherAmount: number;
|
|
115
|
-
principalRecipient: ETH_ADDRESS;
|
|
116
|
-
chainId: number;
|
|
117
|
-
distributorFee: number;
|
|
118
|
-
controllerAddress: ETH_ADDRESS;
|
|
119
|
-
recoveryAddress: ETH_ADDRESS;
|
|
120
|
-
}): Promise<ClusterValidator> => {
|
|
121
|
-
try {
|
|
122
|
-
if (isSplitterDeployed) {
|
|
123
|
-
const owrAddress = await createOWRContract({
|
|
124
|
-
owrArgs: {
|
|
125
|
-
principalRecipient,
|
|
126
|
-
amountOfPrincipalStake: etherAmount,
|
|
127
|
-
predictedSplitterAddress,
|
|
128
|
-
recoveryAddress,
|
|
129
|
-
},
|
|
130
|
-
signer,
|
|
131
|
-
chainId,
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
withdrawal_address: owrAddress,
|
|
135
|
-
fee_recipient_address: predictedSplitterAddress,
|
|
136
|
-
};
|
|
137
|
-
} else {
|
|
138
|
-
const { owrAddress, splitterAddress } =
|
|
139
|
-
await deploySplitterAndOWRContracts({
|
|
140
|
-
owrArgs: {
|
|
141
|
-
principalRecipient,
|
|
142
|
-
amountOfPrincipalStake: etherAmount,
|
|
143
|
-
predictedSplitterAddress,
|
|
144
|
-
recoveryAddress,
|
|
145
|
-
},
|
|
146
|
-
splitterArgs: {
|
|
147
|
-
accounts,
|
|
148
|
-
percentAllocations,
|
|
149
|
-
distributorFee,
|
|
150
|
-
controllerAddress,
|
|
151
|
-
},
|
|
152
|
-
signer,
|
|
153
|
-
chainId,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
withdrawal_address: owrAddress,
|
|
158
|
-
fee_recipient_address: splitterAddress,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
} catch (e) {
|
|
162
|
-
throw e;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const createOWRContract = async ({
|
|
167
|
-
owrArgs,
|
|
168
|
-
signer,
|
|
169
|
-
chainId,
|
|
170
|
-
}: {
|
|
171
|
-
owrArgs: OWRArgs;
|
|
172
|
-
signer: SignerType;
|
|
173
|
-
chainId: number;
|
|
174
|
-
}): Promise<ETH_ADDRESS> => {
|
|
175
|
-
try {
|
|
176
|
-
const OWRFactoryInstance = new Contract(
|
|
177
|
-
CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address,
|
|
178
|
-
OWRFactoryContract.abi,
|
|
179
|
-
signer,
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const tx = await OWRFactoryInstance.createOWRecipient(
|
|
183
|
-
owrArgs.recoveryAddress,
|
|
184
|
-
owrArgs.principalRecipient,
|
|
185
|
-
owrArgs.predictedSplitterAddress,
|
|
186
|
-
parseEther(owrArgs.amountOfPrincipalStake.toString()),
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
const receipt = await tx.wait();
|
|
190
|
-
const OWRAddressData = receipt?.logs[0]?.topics[1];
|
|
191
|
-
const formattedOWRAddress = '0x' + OWRAddressData?.slice(26, 66);
|
|
192
|
-
|
|
193
|
-
return formattedOWRAddress;
|
|
194
|
-
} catch (e) {
|
|
195
|
-
throw e;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export const deploySplitterContract = async ({
|
|
200
|
-
signer,
|
|
201
|
-
accounts,
|
|
202
|
-
percentAllocations,
|
|
203
|
-
chainId,
|
|
204
|
-
distributorFee,
|
|
205
|
-
controllerAddress,
|
|
206
|
-
}: {
|
|
207
|
-
signer: SignerType;
|
|
208
|
-
accounts: ETH_ADDRESS[];
|
|
209
|
-
percentAllocations: number[];
|
|
210
|
-
chainId: number;
|
|
211
|
-
distributorFee: number;
|
|
212
|
-
controllerAddress: ETH_ADDRESS;
|
|
213
|
-
}): Promise<ETH_ADDRESS> => {
|
|
214
|
-
try {
|
|
215
|
-
const splitMainContractInstance = new Contract(
|
|
216
|
-
CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address,
|
|
217
|
-
splitMainEthereumAbi,
|
|
218
|
-
signer,
|
|
219
|
-
);
|
|
220
|
-
const tx = await splitMainContractInstance.createSplit(
|
|
221
|
-
accounts,
|
|
222
|
-
percentAllocations,
|
|
223
|
-
distributorFee,
|
|
224
|
-
controllerAddress,
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
const receipt = await tx.wait();
|
|
228
|
-
const splitterAddressData = receipt?.logs[0]?.topics[1];
|
|
229
|
-
const formattedSplitterAddress = '0x' + splitterAddressData?.slice(26, 66);
|
|
230
|
-
|
|
231
|
-
return formattedSplitterAddress;
|
|
232
|
-
} catch (e) {
|
|
233
|
-
throw e;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
export const deploySplitterAndOWRContracts = async ({
|
|
238
|
-
owrArgs,
|
|
239
|
-
splitterArgs,
|
|
240
|
-
signer,
|
|
241
|
-
chainId,
|
|
242
|
-
}: {
|
|
243
|
-
owrArgs: OWRArgs;
|
|
244
|
-
splitterArgs: SplitArgs;
|
|
245
|
-
signer: SignerType;
|
|
246
|
-
chainId: number;
|
|
247
|
-
}): Promise<{ owrAddress: ETH_ADDRESS; splitterAddress: ETH_ADDRESS }> => {
|
|
248
|
-
const executeCalls: Call[] = [];
|
|
249
|
-
try {
|
|
250
|
-
const splitTxData = encodeCreateSplitTxData(
|
|
251
|
-
splitterArgs.accounts,
|
|
252
|
-
splitterArgs.percentAllocations,
|
|
253
|
-
splitterArgs.distributorFee,
|
|
254
|
-
splitterArgs.controllerAddress,
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
const owrTxData = encodeCreateOWRecipientTxData(
|
|
258
|
-
owrArgs.recoveryAddress,
|
|
259
|
-
owrArgs.principalRecipient,
|
|
260
|
-
owrArgs.predictedSplitterAddress,
|
|
261
|
-
owrArgs.amountOfPrincipalStake,
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
executeCalls.push(
|
|
265
|
-
{
|
|
266
|
-
target: CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address,
|
|
267
|
-
callData: splitTxData,
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
target: CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address,
|
|
271
|
-
callData: owrTxData,
|
|
272
|
-
},
|
|
273
|
-
);
|
|
274
|
-
const multicallAddess =
|
|
275
|
-
CHAIN_CONFIGURATION[chainId].MULTICALL_ADDRESS.address;
|
|
276
|
-
|
|
277
|
-
const executeMultiCalls = await multicall(
|
|
278
|
-
executeCalls,
|
|
279
|
-
signer,
|
|
280
|
-
multicallAddess,
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
const splitAddressData = executeMultiCalls?.logs[0]?.topics[1];
|
|
284
|
-
const formattedSplitterAddress = '0x' + splitAddressData?.slice(26, 66);
|
|
285
|
-
const owrAddressData = executeMultiCalls?.logs[1]?.topics[1];
|
|
286
|
-
const formattedOwrAddress = '0x' + owrAddressData?.slice(26, 66);
|
|
287
|
-
|
|
288
|
-
return {
|
|
289
|
-
owrAddress: formattedOwrAddress,
|
|
290
|
-
splitterAddress: formattedSplitterAddress,
|
|
291
|
-
};
|
|
292
|
-
} catch (e) {
|
|
293
|
-
throw e;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export const getOWRTranches = async ({
|
|
298
|
-
owrAddress,
|
|
299
|
-
signer,
|
|
300
|
-
}: {
|
|
301
|
-
owrAddress: ETH_ADDRESS;
|
|
302
|
-
signer: SignerType;
|
|
303
|
-
}): Promise<OWRTranches> => {
|
|
304
|
-
const owrContract = new Contract(owrAddress, OWRContract.abi, signer);
|
|
305
|
-
const res = await owrContract.getTranches();
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
principalRecipient: res.principalRecipient,
|
|
309
|
-
rewardRecipient: res.rewardRecipient,
|
|
310
|
-
amountOfPrincipalStake: res.amountOfPrincipalStake,
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
export const multicall = async (
|
|
315
|
-
calls: Call[],
|
|
316
|
-
signer: SignerType,
|
|
317
|
-
multicallAddress: string,
|
|
318
|
-
): Promise<any> => {
|
|
319
|
-
const multiCallContractInstance = new Contract(
|
|
320
|
-
multicallAddress,
|
|
321
|
-
MultiCallContract.abi,
|
|
322
|
-
signer,
|
|
323
|
-
);
|
|
324
|
-
const tx = await multiCallContractInstance.aggregate(calls);
|
|
325
|
-
const receipt = await tx.wait();
|
|
326
|
-
return receipt;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
const encodeCreateSplitTxData = (
|
|
330
|
-
accounts: ETH_ADDRESS[],
|
|
331
|
-
percentAllocations: number[],
|
|
332
|
-
distributorFee: number,
|
|
333
|
-
controller: ETH_ADDRESS,
|
|
334
|
-
): ETH_ADDRESS => {
|
|
335
|
-
return splitMainContractInterface.encodeFunctionData('createSplit', [
|
|
336
|
-
accounts,
|
|
337
|
-
percentAllocations,
|
|
338
|
-
distributorFee,
|
|
339
|
-
controller,
|
|
340
|
-
]);
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
const encodeCreateOWRecipientTxData = (
|
|
344
|
-
recoveryAddress: ETH_ADDRESS,
|
|
345
|
-
principalRecipient: ETH_ADDRESS,
|
|
346
|
-
rewardRecipient: ETH_ADDRESS,
|
|
347
|
-
amountOfPrincipalStake: number,
|
|
348
|
-
): ETH_ADDRESS => {
|
|
349
|
-
return owrFactoryContractInterface.encodeFunctionData('createOWRecipient', [
|
|
350
|
-
recoveryAddress,
|
|
351
|
-
principalRecipient,
|
|
352
|
-
rewardRecipient,
|
|
353
|
-
parseEther(amountOfPrincipalStake.toString()),
|
|
354
|
-
]);
|
|
355
|
-
};
|
|
File without changes
|
|
File without changes
|