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