@obolnetwork/obol-sdk 2.8.0 → 2.8.1
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 +2 -4
- package/dist/cjs/src/abi/splitV2FactoryAbi.js +420 -0
- package/dist/cjs/src/bytecodes.js +3 -1
- package/dist/cjs/src/constants.js +24 -16
- package/dist/cjs/src/index.js +10 -10
- package/dist/cjs/src/schema.js +1 -2
- package/dist/cjs/src/splits/splitHelpers.js +77 -109
- package/dist/cjs/src/splits/splits.js +38 -16
- package/dist/cjs/test/splits/splits.spec.js +2 -2
- package/dist/esm/package.json +2 -4
- package/dist/esm/src/abi/splitV2FactoryAbi.js +417 -0
- package/dist/esm/src/bytecodes.js +2 -0
- package/dist/esm/src/constants.js +25 -17
- package/dist/esm/src/index.js +10 -10
- package/dist/esm/src/schema.js +1 -2
- package/dist/esm/src/splits/splitHelpers.js +78 -109
- package/dist/esm/src/splits/splits.js +38 -16
- package/dist/esm/test/splits/splits.spec.js +2 -2
- package/dist/types/src/abi/splitV2FactoryAbi.d.ts +60 -0
- package/dist/types/src/bytecodes.d.ts +2 -0
- package/dist/types/src/exits/verificationHelpers.d.ts +1 -0
- package/dist/types/src/schema.d.ts +3 -3
- package/dist/types/src/splits/splitHelpers.d.ts +1 -3
- package/dist/types/src/types.d.ts +10 -6
- package/dist/types/src/verification/common.d.ts +1 -0
- package/package.json +2 -4
- package/src/abi/splitV2FactoryAbi.ts +417 -0
- package/src/bytecodes.ts +4 -0
- package/src/constants.ts +26 -16
- package/src/index.ts +14 -14
- package/src/schema.ts +1 -2
- package/src/splits/splitHelpers.ts +132 -123
- package/src/splits/splits.ts +68 -17
- package/src/types.ts +10 -6
package/dist/esm/src/index.js
CHANGED
|
@@ -128,19 +128,19 @@ export class Client extends Base {
|
|
|
128
128
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
129
129
|
}
|
|
130
130
|
const chainConfig = CHAIN_CONFIGURATION[this.chainId];
|
|
131
|
-
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.
|
|
132
|
-
throw new Error(`
|
|
131
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLITMAIN_CONTRACT)) {
|
|
132
|
+
throw new Error(`SPLITMAIN_CONTRACT is not configured for chain ${this.chainId}`);
|
|
133
133
|
}
|
|
134
|
-
const checkSplitMainAddress = yield isContractAvailable(chainConfig.
|
|
135
|
-
const checkMulticallAddress = yield isContractAvailable(chainConfig.
|
|
136
|
-
const checkOWRFactoryAddress = yield isContractAvailable(chainConfig.
|
|
134
|
+
const checkSplitMainAddress = yield isContractAvailable(chainConfig.SPLITMAIN_CONTRACT.address, this.signer.provider, chainConfig.SPLITMAIN_CONTRACT.bytecode);
|
|
135
|
+
const checkMulticallAddress = yield isContractAvailable(chainConfig.MULTICALL_CONTRACT.address, this.signer.provider, chainConfig.MULTICALL_CONTRACT.bytecode);
|
|
136
|
+
const checkOWRFactoryAddress = yield isContractAvailable(chainConfig.OWR_FACTORY_CONTRACT.address, this.signer.provider, chainConfig.OWR_FACTORY_CONTRACT.bytecode);
|
|
137
137
|
if (!checkMulticallAddress ||
|
|
138
138
|
!checkSplitMainAddress ||
|
|
139
139
|
!checkOWRFactoryAddress) {
|
|
140
140
|
throw new Error(`Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`);
|
|
141
141
|
}
|
|
142
142
|
const retroActiveFundingRecipient = {
|
|
143
|
-
account: chainConfig.
|
|
143
|
+
account: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
|
|
144
144
|
percentAllocation: validatedPayload.ObolRAFSplit,
|
|
145
145
|
};
|
|
146
146
|
const copiedSplitRecipients = [...validatedPayload.splitRecipients];
|
|
@@ -202,15 +202,15 @@ export class Client extends Base {
|
|
|
202
202
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
203
203
|
}
|
|
204
204
|
const chainConfig = CHAIN_CONFIGURATION[this.chainId];
|
|
205
|
-
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.
|
|
206
|
-
throw new Error(`
|
|
205
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLITMAIN_CONTRACT)) {
|
|
206
|
+
throw new Error(`SPLITMAIN_CONTRACT is not configured for chain ${this.chainId}`);
|
|
207
207
|
}
|
|
208
|
-
const checkSplitMainAddress = yield isContractAvailable(chainConfig.
|
|
208
|
+
const checkSplitMainAddress = yield isContractAvailable(chainConfig.SPLITMAIN_CONTRACT.address, this.signer.provider, chainConfig.SPLITMAIN_CONTRACT.bytecode);
|
|
209
209
|
if (!checkSplitMainAddress) {
|
|
210
210
|
throw new Error(`Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`);
|
|
211
211
|
}
|
|
212
212
|
const retroActiveFundingRecipient = {
|
|
213
|
-
account: chainConfig.
|
|
213
|
+
account: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
|
|
214
214
|
percentAllocation: validatedPayload.ObolRAFSplit,
|
|
215
215
|
};
|
|
216
216
|
const copiedSplitRecipients = [...validatedPayload.splitRecipients];
|
package/dist/esm/src/schema.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ZeroAddress } from 'ethers';
|
|
2
2
|
import { DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT, DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT, PRINCIPAL_THRESHOLD, } from './constants';
|
|
3
3
|
import { VALID_DEPOSIT_AMOUNTS, VALID_NON_COMPOUNDING_AMOUNTS } from './ajv';
|
|
4
|
-
import { zeroAddress } from 'viem';
|
|
5
4
|
export const operatorPayloadSchema = {
|
|
6
5
|
type: 'object',
|
|
7
6
|
properties: {
|
|
@@ -160,7 +159,7 @@ export const ovmBaseSplitPayload = {
|
|
|
160
159
|
splitOwnerAddress: {
|
|
161
160
|
type: 'string',
|
|
162
161
|
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
163
|
-
default:
|
|
162
|
+
default: ZeroAddress,
|
|
164
163
|
},
|
|
165
164
|
principalThreshold: {
|
|
166
165
|
type: 'number',
|
|
@@ -7,19 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { Contract, Interface, parseEther, ZeroAddress } from 'ethers';
|
|
11
11
|
import { OWRContract, OWRFactoryContract } from '../abi/OWR';
|
|
12
12
|
import { OVMFactoryContract } from '../abi/OVMFactory';
|
|
13
13
|
import { splitMainEthereumAbi } from '../abi/SplitMain';
|
|
14
14
|
import { MultiCallContract } from '../abi/Multicall';
|
|
15
|
-
import { CHAIN_CONFIGURATION
|
|
16
|
-
import {
|
|
17
|
-
import { createPublicClient, createWalletClient, custom, http } from 'viem';
|
|
18
|
-
import { hoodi, mainnet } from 'viem/chains';
|
|
19
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
15
|
+
import { CHAIN_CONFIGURATION } from '../constants';
|
|
16
|
+
import { splitV2FactoryAbi } from '../abi/splitV2FactoryAbi';
|
|
20
17
|
const splitMainContractInterface = new Interface(splitMainEthereumAbi);
|
|
21
18
|
const owrFactoryContractInterface = new Interface(OWRFactoryContract.abi);
|
|
22
19
|
const ovmFactoryContractInterface = new Interface(OVMFactoryContract.abi);
|
|
20
|
+
const splitV2FactoryInterface = new Interface(splitV2FactoryAbi);
|
|
23
21
|
// Helper function to extract common recipient formatting logic
|
|
24
22
|
const formatRecipientsCommon = (recipients) => {
|
|
25
23
|
const copiedRecipients = [...recipients];
|
|
@@ -46,7 +44,7 @@ export const formatSplitRecipients = (recipients) => {
|
|
|
46
44
|
export const predictSplitterAddress = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
45
|
var _a, _b, _c;
|
|
48
46
|
try {
|
|
49
|
-
const splitMainContractInstance = new Contract(getChainConfig(chainId).
|
|
47
|
+
const splitMainContractInstance = new Contract(getChainConfig(chainId).SPLITMAIN_CONTRACT.address, splitMainEthereumAbi, signer);
|
|
50
48
|
let predictedSplitterAddress;
|
|
51
49
|
if (controllerAddress === ZeroAddress) {
|
|
52
50
|
try {
|
|
@@ -147,7 +145,7 @@ export const handleDeployOWRAndSplitter = ({ signer, isSplitterDeployed, predict
|
|
|
147
145
|
const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
146
|
var _g, _h, _j, _k, _l;
|
|
149
147
|
try {
|
|
150
|
-
const OWRFactoryInstance = new Contract(getChainConfig(chainId).
|
|
148
|
+
const OWRFactoryInstance = new Contract(getChainConfig(chainId).OWR_FACTORY_CONTRACT.address, OWRFactoryContract.abi, signer);
|
|
151
149
|
let tx;
|
|
152
150
|
try {
|
|
153
151
|
tx = yield OWRFactoryInstance.createOWRecipient(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, parseEther(owrArgs.amountOfPrincipalStake.toString()));
|
|
@@ -191,7 +189,7 @@ const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, v
|
|
|
191
189
|
export const deploySplitterContract = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
190
|
var _m, _o, _p, _q, _r;
|
|
193
191
|
try {
|
|
194
|
-
const splitMainContractInstance = new Contract(getChainConfig(chainId).
|
|
192
|
+
const splitMainContractInstance = new Contract(getChainConfig(chainId).SPLITMAIN_CONTRACT.address, splitMainEthereumAbi, signer);
|
|
195
193
|
let tx;
|
|
196
194
|
try {
|
|
197
195
|
tx = yield splitMainContractInstance.createSplit(accounts, percentAllocations, distributorFee, controllerAddress);
|
|
@@ -238,14 +236,13 @@ export const deploySplitterAndOWRContracts = ({ owrArgs, splitterArgs, signer, c
|
|
|
238
236
|
const splitTxData = encodeCreateSplitTxData(splitterArgs.accounts, splitterArgs.percentAllocations, splitterArgs.distributorFee, splitterArgs.controllerAddress);
|
|
239
237
|
const owrTxData = encodeCreateOWRecipientTxData(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, owrArgs.amountOfPrincipalStake);
|
|
240
238
|
executeCalls.push({
|
|
241
|
-
target: getChainConfig(chainId).
|
|
239
|
+
target: getChainConfig(chainId).SPLITMAIN_CONTRACT.address,
|
|
242
240
|
callData: splitTxData,
|
|
243
241
|
}, {
|
|
244
|
-
target: getChainConfig(chainId).
|
|
242
|
+
target: getChainConfig(chainId).OWR_FACTORY_CONTRACT.address,
|
|
245
243
|
callData: owrTxData,
|
|
246
244
|
});
|
|
247
|
-
const
|
|
248
|
-
const executeMultiCalls = yield multicall(executeCalls, signer, multicallAddess);
|
|
245
|
+
const executeMultiCalls = yield multicall(executeCalls, signer, chainId);
|
|
249
246
|
const splitAddressData = (_s = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[0]) === null || _s === void 0 ? void 0 : _s.topics[1];
|
|
250
247
|
const formattedSplitterAddress = '0x' + (splitAddressData === null || splitAddressData === void 0 ? void 0 : splitAddressData.slice(26, 66));
|
|
251
248
|
const owrAddressData = (_t = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[1]) === null || _t === void 0 ? void 0 : _t.topics[1];
|
|
@@ -285,9 +282,11 @@ export const getOWRTranches = ({ owrAddress, signer, }) => __awaiter(void 0, voi
|
|
|
285
282
|
throw new Error(`Unexpected error in getOWRTranches: ${(_v = error.message) !== null && _v !== void 0 ? _v : 'Unknown error while fetching OWR tranche data'}`);
|
|
286
283
|
}
|
|
287
284
|
});
|
|
288
|
-
export const multicall = (calls, signer,
|
|
285
|
+
export const multicall = (calls, signer, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
289
286
|
var _w, _x, _y;
|
|
290
287
|
try {
|
|
288
|
+
const chainConfig = getChainConfig(chainId);
|
|
289
|
+
const multicallAddress = chainConfig.MULTICALL_CONTRACT.address;
|
|
291
290
|
const multiCallContractInstance = new Contract(multicallAddress, MultiCallContract.abi, signer);
|
|
292
291
|
let tx;
|
|
293
292
|
try {
|
|
@@ -345,77 +344,45 @@ export const formatRecipientsForSplitV2 = (splitRecipients) => {
|
|
|
345
344
|
percentAllocation: parseFloat(getPercentAllocation(item).toString()),
|
|
346
345
|
}));
|
|
347
346
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
account: address,
|
|
361
|
-
chain,
|
|
362
|
-
transport: custom(window.ethereum),
|
|
363
|
-
});
|
|
364
|
-
return new SplitsClient({
|
|
365
|
-
publicClient: client,
|
|
366
|
-
walletClient: viemWalletClient,
|
|
367
|
-
chainId,
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
// For non-browser environment, extract private key from signer
|
|
372
|
-
const signerPrivateKey = signer === null || signer === void 0 ? void 0 : signer.privateKey;
|
|
373
|
-
if (!signerPrivateKey) {
|
|
374
|
-
throw new Error('Signer private key not available');
|
|
375
|
-
}
|
|
376
|
-
const privateKey = signerPrivateKey.startsWith('0x')
|
|
377
|
-
? signerPrivateKey
|
|
378
|
-
: `0x${signerPrivateKey}`;
|
|
379
|
-
const scriptAccount = privateKeyToAccount(privateKey);
|
|
380
|
-
const account = scriptAccount;
|
|
381
|
-
const viemWalletClient = createWalletClient({
|
|
382
|
-
account,
|
|
383
|
-
chain,
|
|
384
|
-
transport: http(CHAIN_PUBLIC_RPC_URL[chainId]),
|
|
385
|
-
});
|
|
386
|
-
return new SplitsClient({
|
|
387
|
-
publicClient: client,
|
|
388
|
-
walletClient: viemWalletClient,
|
|
389
|
-
chainId,
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
});
|
|
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
|
+
};
|
|
393
359
|
export const predictSplitV2Address = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
394
|
-
var _z;
|
|
360
|
+
var _z, _0;
|
|
395
361
|
try {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return
|
|
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;
|
|
404
370
|
}
|
|
405
371
|
catch (error) {
|
|
406
|
-
throw new Error(`Failed to predict SplitV2 address: ${(
|
|
372
|
+
throw new Error(`Failed to predict SplitV2 address: ${(_0 = error.message) !== null && _0 !== void 0 ? _0 : 'SplitV2 contract call failed'}`);
|
|
407
373
|
}
|
|
408
374
|
});
|
|
409
375
|
export const isSplitV2Deployed = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
376
|
+
var _1;
|
|
410
377
|
try {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return
|
|
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;
|
|
419
386
|
}
|
|
420
387
|
catch (error) {
|
|
421
388
|
// If the check fails, assume it's not deployed
|
|
@@ -423,17 +390,17 @@ export const isSplitV2Deployed = ({ splitOwnerAddress, recipients, distributorFe
|
|
|
423
390
|
}
|
|
424
391
|
});
|
|
425
392
|
export const deployOVMContract = ({ OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
426
|
-
var
|
|
393
|
+
var _2, _3, _4;
|
|
427
394
|
try {
|
|
428
395
|
const chainConfig = getChainConfig(chainId);
|
|
429
|
-
if (!((
|
|
396
|
+
if (!((_2 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT) === null || _2 === void 0 ? void 0 : _2.address)) {
|
|
430
397
|
throw new Error(`OVM Factory not configured for chain ${chainId}`);
|
|
431
398
|
}
|
|
432
|
-
const ovmFactoryContract = new Contract(chainConfig.
|
|
399
|
+
const ovmFactoryContract = new Contract(chainConfig.OVM_FACTORY_CONTRACT.address, OVMFactoryContract.abi, signer);
|
|
433
400
|
const tx = yield ovmFactoryContract.createObolValidatorManager(OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold);
|
|
434
401
|
const receipt = yield tx.wait();
|
|
435
402
|
// Extract OVM address from logs
|
|
436
|
-
const ovmAddressLog = (
|
|
403
|
+
const ovmAddressLog = (_3 = receipt === null || receipt === void 0 ? void 0 : receipt.logs[1]) === null || _3 === void 0 ? void 0 : _3.topics[1];
|
|
437
404
|
if (!ovmAddressLog) {
|
|
438
405
|
throw new Error('Failed to extract OVM address from transaction logs');
|
|
439
406
|
}
|
|
@@ -441,59 +408,57 @@ export const deployOVMContract = ({ OVMOwnerAddress, principalRecipient, rewardR
|
|
|
441
408
|
return ovmAddress;
|
|
442
409
|
}
|
|
443
410
|
catch (error) {
|
|
444
|
-
throw new Error(`Failed to deploy OVM contract: ${(
|
|
411
|
+
throw new Error(`Failed to deploy OVM contract: ${(_4 = error.message) !== null && _4 !== void 0 ? _4 : 'OVM deployment failed'}`);
|
|
445
412
|
}
|
|
446
413
|
});
|
|
447
414
|
export const deployOVMAndSplitV2 = ({ ovmArgs, rewardRecipients, isRewardsSplitterDeployed, distributorFeePercent, salt, signer, chainId, principalSplitRecipients, isPrincipalSplitDeployed, splitOwnerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
448
|
-
var
|
|
415
|
+
var _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
|
449
416
|
try {
|
|
450
417
|
const chainConfig = getChainConfig(chainId);
|
|
451
|
-
if (!((
|
|
418
|
+
if (!((_5 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT) === null || _5 === void 0 ? void 0 : _5.address)) {
|
|
452
419
|
throw new Error(`OVM Factory not configured for chain ${chainId}`);
|
|
453
420
|
}
|
|
454
|
-
|
|
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
|
+
}
|
|
455
424
|
const executeCalls = [];
|
|
456
425
|
if (rewardRecipients && !isRewardsSplitterDeployed) {
|
|
457
426
|
// Create rewards split call data
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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,
|
|
463
432
|
});
|
|
464
|
-
executeCalls.push(rewardsSplitTxData);
|
|
465
433
|
}
|
|
466
434
|
// Create principal split call data if needed (for total split scenario)
|
|
467
435
|
if (principalSplitRecipients && !isPrincipalSplitDeployed) {
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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,
|
|
473
441
|
});
|
|
474
|
-
executeCalls.push(principalSplitTxData);
|
|
475
442
|
}
|
|
476
443
|
// Create OVM call data
|
|
477
444
|
const ovmTxData = encodeCreateOVMTxData(ovmArgs.OVMOwnerAddress, ovmArgs.principalRecipient, ovmArgs.rewardRecipient, ovmArgs.principalThreshold);
|
|
478
445
|
executeCalls.push({
|
|
479
|
-
|
|
480
|
-
|
|
446
|
+
target: chainConfig.OVM_FACTORY_CONTRACT.address,
|
|
447
|
+
callData: ovmTxData,
|
|
481
448
|
});
|
|
482
449
|
// Execute multicall
|
|
483
|
-
const executeMultiCalls = yield
|
|
484
|
-
calls: executeCalls,
|
|
485
|
-
});
|
|
450
|
+
const executeMultiCalls = yield multicall(executeCalls, signer, chainId);
|
|
486
451
|
// Extract addresses from events
|
|
487
452
|
let ovmAddress;
|
|
488
|
-
const
|
|
489
|
-
if (
|
|
490
|
-
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));
|
|
491
456
|
}
|
|
492
|
-
else if (
|
|
493
|
-
ovmAddress = (
|
|
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));
|
|
494
459
|
}
|
|
495
460
|
else {
|
|
496
|
-
ovmAddress = (
|
|
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));
|
|
497
462
|
}
|
|
498
463
|
if (!ovmAddress) {
|
|
499
464
|
throw new Error('Failed to extract contract addresses from multicall events');
|
|
@@ -501,12 +466,16 @@ export const deployOVMAndSplitV2 = ({ ovmArgs, rewardRecipients, isRewardsSplitt
|
|
|
501
466
|
return ovmAddress;
|
|
502
467
|
}
|
|
503
468
|
catch (error) {
|
|
504
|
-
throw new Error(`Failed to deploy OVM and SplitV2: ${(
|
|
469
|
+
throw new Error(`Failed to deploy OVM and SplitV2: ${(_14 = error.message) !== null && _14 !== void 0 ? _14 : 'Deployment failed'}`);
|
|
505
470
|
}
|
|
506
471
|
});
|
|
507
472
|
const encodeCreateOVMTxData = (OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold) => {
|
|
508
473
|
return ovmFactoryContractInterface.encodeFunctionData('createObolValidatorManager', [OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold]);
|
|
509
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
|
+
};
|
|
510
479
|
// Helper function to safely get chain configuration
|
|
511
480
|
const getChainConfig = (chainId) => {
|
|
512
481
|
const config = CHAIN_CONFIGURATION[chainId];
|
|
@@ -54,22 +54,33 @@ export class ObolSplits {
|
|
|
54
54
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
55
55
|
}
|
|
56
56
|
const chainConfig = CHAIN_CONFIGURATION[this.chainId];
|
|
57
|
-
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.
|
|
57
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT)) {
|
|
58
58
|
throw new Error(`OVM contract factory is not configured for chain ${this.chainId}`);
|
|
59
59
|
}
|
|
60
60
|
if (!this.provider) {
|
|
61
61
|
throw new Error('Provider is required to check OVM factory contract availability');
|
|
62
62
|
}
|
|
63
|
-
const ovmFactoryConfig = chainConfig.
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const ovmFactoryConfig = chainConfig.OVM_FACTORY_CONTRACT;
|
|
64
|
+
const splitV2FactoryConfig = chainConfig.SPLIT_V2_FACTORY_CONTRACT;
|
|
65
|
+
const multiCallConfig = chainConfig.MULTICALL_CONTRACT;
|
|
66
|
+
if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) ||
|
|
67
|
+
!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode) ||
|
|
68
|
+
!(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.address) ||
|
|
69
|
+
!(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.bytecode) ||
|
|
70
|
+
!(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.address) ||
|
|
71
|
+
!(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.bytecode)) {
|
|
72
|
+
throw new Error(`Contracts configuration is incomplete for chain ${this.chainId}`);
|
|
66
73
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
const checkOVMFactoryContract = yield isContractAvailable(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
|
|
75
|
+
const checkSplitV2FactoryContract = yield isContractAvailable(splitV2FactoryConfig.address, this.provider, splitV2FactoryConfig.bytecode);
|
|
76
|
+
const checkMultiCallContract = yield isContractAvailable(multiCallConfig.address, this.provider, multiCallConfig.bytecode);
|
|
77
|
+
if (!checkOVMFactoryContract ||
|
|
78
|
+
!checkSplitV2FactoryContract ||
|
|
79
|
+
!checkMultiCallContract) {
|
|
80
|
+
throw new Error(`Splitter contract is not deployed or available on chain ${this.chainId}`);
|
|
70
81
|
}
|
|
71
82
|
const retroActiveFundingRecipient = {
|
|
72
|
-
address: chainConfig.
|
|
83
|
+
address: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
|
|
73
84
|
percentAllocation: DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
|
|
74
85
|
};
|
|
75
86
|
const copiedRewardsSplitRecipients = [
|
|
@@ -159,22 +170,33 @@ export class ObolSplits {
|
|
|
159
170
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
160
171
|
}
|
|
161
172
|
const chainConfig = CHAIN_CONFIGURATION[this.chainId];
|
|
162
|
-
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.
|
|
173
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT)) {
|
|
163
174
|
throw new Error(`OVM contract factory is not configured for chain ${this.chainId}`);
|
|
164
175
|
}
|
|
165
176
|
if (!this.provider) {
|
|
166
177
|
throw new Error('Provider is required to check OVM factory contract availability');
|
|
167
178
|
}
|
|
168
|
-
const ovmFactoryConfig = chainConfig.
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
const ovmFactoryConfig = chainConfig.OVM_FACTORY_CONTRACT;
|
|
180
|
+
const splitV2FactoryConfig = chainConfig.SPLIT_V2_FACTORY_CONTRACT;
|
|
181
|
+
const multiCallConfig = chainConfig.MULTICALL_CONTRACT;
|
|
182
|
+
if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) ||
|
|
183
|
+
!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode) ||
|
|
184
|
+
!(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.address) ||
|
|
185
|
+
!(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.bytecode) ||
|
|
186
|
+
!(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.address) ||
|
|
187
|
+
!(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.bytecode)) {
|
|
188
|
+
throw new Error(`Contracts configuration is incomplete for chain ${this.chainId}`);
|
|
171
189
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
190
|
+
const checkOVMFactoryContract = yield isContractAvailable(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
|
|
191
|
+
const checkSplitV2FactoryContract = yield isContractAvailable(splitV2FactoryConfig.address, this.provider, splitV2FactoryConfig.bytecode);
|
|
192
|
+
const checkMultiCallContract = yield isContractAvailable(multiCallConfig.address, this.provider, multiCallConfig.bytecode);
|
|
193
|
+
if (!checkOVMFactoryContract ||
|
|
194
|
+
!checkSplitV2FactoryContract ||
|
|
195
|
+
!checkMultiCallContract) {
|
|
196
|
+
throw new Error(`Splitter contract is not deployed or available on chain ${this.chainId}`);
|
|
175
197
|
}
|
|
176
198
|
const retroActiveFundingRecipient = {
|
|
177
|
-
address: chainConfig.
|
|
199
|
+
address: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
|
|
178
200
|
percentAllocation: DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
|
|
179
201
|
};
|
|
180
202
|
const copiedRewardsSplitRecipients = [
|
|
@@ -102,9 +102,9 @@ describe('ObolSplits', () => {
|
|
|
102
102
|
it('should throw error when OVM factory is not configured', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
103
|
// Mock chain configuration without OVM factory
|
|
104
104
|
const originalConfig = CHAIN_CONFIGURATION[1];
|
|
105
|
-
// Create a new config object without
|
|
105
|
+
// Create a new config object without OVM_FACTORY_CONTRACT
|
|
106
106
|
const configWithoutOVM = Object.assign({}, originalConfig);
|
|
107
|
-
delete configWithoutOVM.
|
|
107
|
+
delete configWithoutOVM.OVM_FACTORY_CONTRACT;
|
|
108
108
|
CHAIN_CONFIGURATION[1] = configWithoutOVM;
|
|
109
109
|
yield expect(client.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('OVM contract factory is not configured for chain 1');
|
|
110
110
|
// Restore original config
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const splitV2FactoryAbi: ({
|
|
2
|
+
inputs: {
|
|
3
|
+
internalType: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}[];
|
|
7
|
+
stateMutability: string;
|
|
8
|
+
type: string;
|
|
9
|
+
anonymous?: undefined;
|
|
10
|
+
name?: undefined;
|
|
11
|
+
outputs?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
anonymous: boolean;
|
|
14
|
+
inputs: ({
|
|
15
|
+
indexed: boolean;
|
|
16
|
+
internalType: string;
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
components?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
components: {
|
|
22
|
+
internalType: string;
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
}[];
|
|
26
|
+
indexed: boolean;
|
|
27
|
+
internalType: string;
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
})[];
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
stateMutability?: undefined;
|
|
34
|
+
outputs?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
inputs: ({
|
|
37
|
+
components: {
|
|
38
|
+
internalType: string;
|
|
39
|
+
name: string;
|
|
40
|
+
type: string;
|
|
41
|
+
}[];
|
|
42
|
+
internalType: string;
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
} | {
|
|
46
|
+
internalType: string;
|
|
47
|
+
name: string;
|
|
48
|
+
type: string;
|
|
49
|
+
components?: undefined;
|
|
50
|
+
})[];
|
|
51
|
+
name: string;
|
|
52
|
+
outputs: {
|
|
53
|
+
internalType: string;
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
}[];
|
|
57
|
+
stateMutability: string;
|
|
58
|
+
type: string;
|
|
59
|
+
anonymous?: undefined;
|
|
60
|
+
})[];
|