@obolnetwork/obol-sdk 2.7.0 → 2.8.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 +4 -2
- package/dist/cjs/src/abi/OVMFactory.js +620 -0
- package/dist/cjs/src/ajv.js +33 -6
- package/dist/cjs/src/bytecodes.js +8 -1
- package/dist/cjs/src/constants.js +55 -7
- package/dist/cjs/src/index.js +21 -9
- package/dist/cjs/src/schema.js +71 -1
- package/dist/cjs/src/splits/splitHelpers.js +218 -12
- package/dist/cjs/src/splits/splits.js +261 -0
- package/dist/cjs/src/types.js +0 -1
- package/dist/cjs/test/client/ajv.spec.js +269 -0
- package/dist/cjs/test/client/methods.spec.js +418 -0
- package/dist/cjs/test/fixtures.js +13 -1
- package/dist/cjs/test/splits/splits.spec.js +239 -0
- package/dist/esm/package.json +4 -2
- package/dist/esm/src/abi/OVMFactory.js +617 -0
- package/dist/esm/src/ajv.js +33 -6
- package/dist/esm/src/bytecodes.js +7 -0
- package/dist/esm/src/constants.js +54 -7
- package/dist/esm/src/index.js +20 -9
- package/dist/esm/src/schema.js +71 -1
- package/dist/esm/src/splits/splitHelpers.js +213 -13
- package/dist/esm/src/splits/splits.js +257 -0
- package/dist/esm/src/types.js +0 -1
- package/dist/esm/test/client/ajv.spec.js +267 -0
- package/dist/esm/test/client/methods.spec.js +393 -0
- package/dist/esm/test/fixtures.js +12 -0
- package/dist/esm/test/splits/splits.spec.js +237 -0
- package/dist/types/src/abi/OVMFactory.d.ts +662 -0
- package/dist/types/src/bytecodes.d.ts +7 -0
- package/dist/types/src/constants.d.ts +10 -21
- package/dist/types/src/index.d.ts +7 -0
- package/dist/types/src/schema.d.ts +145 -0
- package/dist/types/src/splits/splitHelpers.d.ts +40 -1
- package/dist/types/src/splits/splits.d.ts +51 -0
- package/dist/types/src/types.d.ts +83 -2
- package/dist/types/test/client/ajv.spec.d.ts +1 -0
- package/dist/types/test/client/methods.spec.d.ts +1 -0
- package/dist/types/test/fixtures.d.ts +10 -0
- package/dist/types/test/splits/splits.spec.d.ts +1 -0
- package/package.json +4 -2
- package/src/abi/OVMFactory.ts +617 -0
- package/src/ajv.ts +55 -13
- package/src/bytecodes.ts +15 -0
- package/src/constants.ts +66 -8
- package/src/index.ts +36 -15
- package/src/schema.ts +80 -0
- package/src/splits/splitHelpers.ts +360 -14
- package/src/splits/splits.ts +355 -0
- package/src/types.ts +96 -3
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.CAPELLA_FORK_MAPPING = exports.PROVIDER_MAP = exports.OBOL_SDK_EMAIL = exports.DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = exports.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = exports.CHAIN_CONFIGURATION = exports.AVAILABLE_SPLITTER_CHAINS = exports.TERMS_AND_CONDITIONS_HASH = exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION = exports.ETHER_TO_GWEI = exports.DEFAULT_CHAIN_ID = exports.DEFAULT_BASE_VERSION = exports.DEFAULT_BASE_URL = exports.DefinitionFlow = exports.GENESIS_VALIDATOR_ROOT = exports.DOMAIN_DEPOSIT = exports.DOMAIN_APPLICATION_BUILDER = exports.SDK_VERSION = exports.CONFIG_VERSION = exports.DKG_ALGORITHM = exports.signEnrPayload = exports.signOperatorConfigHashPayload = exports.signCreatorConfigHashPayload = exports.ENRTypedMessage = exports.OperatorTypedMessage = exports.OperatorConfigHashSigningTypes = exports.EnrSigningTypes = exports.CreatorTypedMessage = exports.Domain = exports.TermsAndConditionsSigningTypes = exports.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
|
|
29
|
+
exports.CHAIN_PUBLIC_RPC_URL = exports.CAPELLA_FORK_MAPPING = exports.PROVIDER_MAP = exports.OBOL_SDK_EMAIL = exports.PRINCIPAL_THRESHOLD = exports.SPLITS_V2_SALT = exports.DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = exports.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = exports.CHAIN_CONFIGURATION = exports.isChainSupportedForSplitters = exports.AVAILABLE_SPLITTER_CHAINS = exports.TERMS_AND_CONDITIONS_HASH = exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION = exports.ETHER_TO_GWEI = exports.DEFAULT_CHAIN_ID = exports.DEFAULT_BASE_VERSION = exports.DEFAULT_BASE_URL = exports.DefinitionFlow = exports.GENESIS_VALIDATOR_ROOT = exports.DOMAIN_DEPOSIT = exports.DOMAIN_APPLICATION_BUILDER = exports.SDK_VERSION = exports.CONFIG_VERSION = exports.DKG_ALGORITHM = exports.signEnrPayload = exports.signOperatorConfigHashPayload = exports.signCreatorConfigHashPayload = exports.ENRTypedMessage = exports.OperatorTypedMessage = exports.OperatorConfigHashSigningTypes = exports.EnrSigningTypes = exports.CreatorTypedMessage = exports.Domain = exports.TermsAndConditionsSigningTypes = exports.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
|
|
30
30
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
31
31
|
const types_1 = require("./types");
|
|
32
32
|
const bytecodes_1 = require("./bytecodes");
|
|
@@ -131,12 +131,17 @@ exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION === 1
|
|
|
131
131
|
? 'https://obol.org/terms.pdf'
|
|
132
132
|
: `https://obol.org/${exports.TERMS_AND_CONDITIONS_VERSION}/terms.pdf`;
|
|
133
133
|
exports.TERMS_AND_CONDITIONS_HASH = '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';
|
|
134
|
-
exports.AVAILABLE_SPLITTER_CHAINS =
|
|
135
|
-
types_1.FORK_MAPPING['0x00000000'],
|
|
136
|
-
types_1.FORK_MAPPING['0x01017000'],
|
|
137
|
-
]
|
|
134
|
+
exports.AVAILABLE_SPLITTER_CHAINS = {
|
|
135
|
+
[types_1.FORK_MAPPING['0x00000000']]: true, // Mainnet
|
|
136
|
+
[types_1.FORK_MAPPING['0x01017000']]: true, // Holesky
|
|
137
|
+
[types_1.FORK_MAPPING['0x10000910']]: true, // Hoodi
|
|
138
|
+
};
|
|
139
|
+
const isChainSupportedForSplitters = (chainId) => {
|
|
140
|
+
return chainId in exports.AVAILABLE_SPLITTER_CHAINS;
|
|
141
|
+
};
|
|
142
|
+
exports.isChainSupportedForSplitters = isChainSupportedForSplitters;
|
|
138
143
|
exports.CHAIN_CONFIGURATION = {
|
|
139
|
-
[
|
|
144
|
+
[types_1.FORK_MAPPING['0x00000000']]: {
|
|
140
145
|
SPLITMAIN_ADDRESS: {
|
|
141
146
|
address: '0x2ed6c4B5dA6378c7897AC67Ba9e43102Feb694EE',
|
|
142
147
|
bytecode: bytecodes_1.MAINNET_SPLITMAIN_BYTECODE,
|
|
@@ -153,8 +158,17 @@ exports.CHAIN_CONFIGURATION = {
|
|
|
153
158
|
address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
|
|
154
159
|
bytecode: '',
|
|
155
160
|
},
|
|
161
|
+
// OVM and SplitV2 Contract Addresses
|
|
162
|
+
OVM_FACTORY_ADDRESS: {
|
|
163
|
+
address: '0xdfe2d8b26806583cf03b3cb623b0752f8670e93e',
|
|
164
|
+
bytecode: bytecodes_1.MAINNET_OVM_FACTORY_BYTECODE,
|
|
165
|
+
},
|
|
166
|
+
WAREHOUSE_ADDRESS: {
|
|
167
|
+
address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
|
|
168
|
+
bytecode: bytecodes_1.MAINNET_WAREHOUSE_BYTECODE,
|
|
169
|
+
},
|
|
156
170
|
},
|
|
157
|
-
[
|
|
171
|
+
[types_1.FORK_MAPPING['0x01017000']]: {
|
|
158
172
|
SPLITMAIN_ADDRESS: {
|
|
159
173
|
address: '0xfC8a305728051367797DADE6Aa0344E0987f5286',
|
|
160
174
|
bytecode: bytecodes_1.HOLESKY_SPLITMAIN_BYTECODE,
|
|
@@ -172,9 +186,39 @@ exports.CHAIN_CONFIGURATION = {
|
|
|
172
186
|
bytecode: '',
|
|
173
187
|
},
|
|
174
188
|
},
|
|
189
|
+
[types_1.FORK_MAPPING['0x10000910']]: {
|
|
190
|
+
SPLITMAIN_ADDRESS: {
|
|
191
|
+
address: '0xc05ae267291705ac16F75283572294ed2a91CBc7',
|
|
192
|
+
bytecode: bytecodes_1.HOODI_SPLITMAIN_BYTECODE,
|
|
193
|
+
},
|
|
194
|
+
MULTICALL_ADDRESS: {
|
|
195
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
196
|
+
bytecode: bytecodes_1.HOODI_MULTICALL_BYTECODE,
|
|
197
|
+
},
|
|
198
|
+
OWR_FACTORY_ADDRESS: {
|
|
199
|
+
address: '0x9ff0c649d0bf5fe7efa4d72e94bed7302ed5c8d7',
|
|
200
|
+
bytecode: bytecodes_1.HOODI_OWR_FACTORY_BYTECODE,
|
|
201
|
+
},
|
|
202
|
+
RETROACTIVE_FUNDING_ADDRESS: {
|
|
203
|
+
address: '0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5',
|
|
204
|
+
bytecode: '',
|
|
205
|
+
},
|
|
206
|
+
// OVM and SplitV2 Contract Addresses
|
|
207
|
+
OVM_FACTORY_ADDRESS: {
|
|
208
|
+
address: '0x6F13d929C783a420AE4DC71C1dcc27A02038Ed09',
|
|
209
|
+
bytecode: bytecodes_1.HOODI_OVM_FACTORY_BYTECODE,
|
|
210
|
+
},
|
|
211
|
+
WAREHOUSE_ADDRESS: {
|
|
212
|
+
address: '0x8fb66F38cF86A3d5e8768f8F1754A24A6c661Fb8',
|
|
213
|
+
bytecode: bytecodes_1.HOODI_WAREHOUSE_BYTECODE,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
175
216
|
};
|
|
176
217
|
exports.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = 1;
|
|
177
218
|
exports.DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = 0.1;
|
|
219
|
+
// OVM and SplitV2 Default Constants
|
|
220
|
+
exports.SPLITS_V2_SALT = '0x2fa740d39f3b04b2c7ef4e9f9e1a6e38f4c72c1a91d8595d5d31a3adf17c6b12';
|
|
221
|
+
exports.PRINCIPAL_THRESHOLD = 16;
|
|
178
222
|
exports.OBOL_SDK_EMAIL = 'sdk@dvlabs.tech';
|
|
179
223
|
exports.PROVIDER_MAP = {
|
|
180
224
|
1: `${process.env.RPC_MAINNET}`, // Mainnet
|
|
@@ -194,3 +238,7 @@ exports.CAPELLA_FORK_MAPPING = {
|
|
|
194
238
|
'0x01017000': '0x04017000', // Holesky
|
|
195
239
|
'0x10000910': '0x40000910', // Hoodi
|
|
196
240
|
};
|
|
241
|
+
exports.CHAIN_PUBLIC_RPC_URL = {
|
|
242
|
+
1: 'https://ethereum-rpc.publicnode.com', // Mainnet
|
|
243
|
+
560048: 'https://ethereum-hoodi-rpc.publicnode.com', // Hoodi
|
|
244
|
+
};
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Client = exports.Exit = exports.Incentives = void 0;
|
|
26
|
+
exports.Client = exports.ObolSplits = exports.Exit = exports.Incentives = void 0;
|
|
27
27
|
const uuid_1 = require("uuid");
|
|
28
28
|
const base_js_1 = require("./base.js");
|
|
29
29
|
const constants_js_1 = require("./constants.js");
|
|
@@ -35,6 +35,7 @@ const splitHelpers_js_1 = require("./splits/splitHelpers.js");
|
|
|
35
35
|
const utils_js_1 = require("./utils.js");
|
|
36
36
|
const incentives_js_1 = require("./incentives/incentives.js");
|
|
37
37
|
const exit_js_1 = require("./exits/exit.js");
|
|
38
|
+
const splits_js_1 = require("./splits/splits.js");
|
|
38
39
|
__exportStar(require("./types.js"), exports);
|
|
39
40
|
__exportStar(require("./services.js"), exports);
|
|
40
41
|
__exportStar(require("./verification/signature-validator.js"), exports);
|
|
@@ -44,6 +45,8 @@ var incentives_js_2 = require("./incentives/incentives.js");
|
|
|
44
45
|
Object.defineProperty(exports, "Incentives", { enumerable: true, get: function () { return incentives_js_2.Incentives; } });
|
|
45
46
|
var exit_js_2 = require("./exits/exit.js");
|
|
46
47
|
Object.defineProperty(exports, "Exit", { enumerable: true, get: function () { return exit_js_2.Exit; } });
|
|
48
|
+
var splits_js_2 = require("./splits/splits.js");
|
|
49
|
+
Object.defineProperty(exports, "ObolSplits", { enumerable: true, get: function () { return splits_js_2.ObolSplits; } });
|
|
47
50
|
/**
|
|
48
51
|
* Obol sdk Client can be used for creating, managing and activating distributed validators.
|
|
49
52
|
*/
|
|
@@ -66,6 +69,7 @@ class Client extends base_js_1.Base {
|
|
|
66
69
|
provider !== null && provider !== void 0 ? provider : (signer && 'provider' in signer ? signer.provider : undefined);
|
|
67
70
|
this.incentives = new incentives_js_1.Incentives(this.signer, this.chainId, this.request.bind(this), this.provider);
|
|
68
71
|
this.exit = new exit_js_1.Exit(this.chainId, this.provider);
|
|
72
|
+
this.splits = new splits_js_1.ObolSplits(this.signer, this.chainId, this.provider);
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
75
|
* Accepts Obol terms and conditions to be able to create or update data.
|
|
@@ -140,19 +144,23 @@ class Client extends base_js_1.Base {
|
|
|
140
144
|
recoveryAddress,
|
|
141
145
|
}, schema_js_1.rewardsSplitterPayloadSchema);
|
|
142
146
|
// Check if we allow splitters on this chainId
|
|
143
|
-
if (!constants_js_1.
|
|
147
|
+
if (!(0, constants_js_1.isChainSupportedForSplitters)(this.chainId)) {
|
|
144
148
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
145
149
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
const chainConfig = constants_js_1.CHAIN_CONFIGURATION[this.chainId];
|
|
151
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLITMAIN_ADDRESS)) {
|
|
152
|
+
throw new Error(`SPLITMAIN_ADDRESS is not configured for chain ${this.chainId}`);
|
|
153
|
+
}
|
|
154
|
+
const checkSplitMainAddress = yield (0, utils_js_1.isContractAvailable)(chainConfig.SPLITMAIN_ADDRESS.address, this.signer.provider, chainConfig.SPLITMAIN_ADDRESS.bytecode);
|
|
155
|
+
const checkMulticallAddress = yield (0, utils_js_1.isContractAvailable)(chainConfig.MULTICALL_ADDRESS.address, this.signer.provider, chainConfig.MULTICALL_ADDRESS.bytecode);
|
|
156
|
+
const checkOWRFactoryAddress = yield (0, utils_js_1.isContractAvailable)(chainConfig.OWR_FACTORY_ADDRESS.address, this.signer.provider, chainConfig.OWR_FACTORY_ADDRESS.bytecode);
|
|
149
157
|
if (!checkMulticallAddress ||
|
|
150
158
|
!checkSplitMainAddress ||
|
|
151
159
|
!checkOWRFactoryAddress) {
|
|
152
160
|
throw new Error(`Something isn not working as expected, check this issue with obol-sdk team on ${constants_js_1.OBOL_SDK_EMAIL}`);
|
|
153
161
|
}
|
|
154
162
|
const retroActiveFundingRecipient = {
|
|
155
|
-
account:
|
|
163
|
+
account: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
|
|
156
164
|
percentAllocation: validatedPayload.ObolRAFSplit,
|
|
157
165
|
};
|
|
158
166
|
const copiedSplitRecipients = [...validatedPayload.splitRecipients];
|
|
@@ -210,15 +218,19 @@ class Client extends base_js_1.Base {
|
|
|
210
218
|
controllerAddress,
|
|
211
219
|
}, schema_js_1.totalSplitterPayloadSchema);
|
|
212
220
|
// Check if we allow splitters on this chainId
|
|
213
|
-
if (!constants_js_1.
|
|
221
|
+
if (!(0, constants_js_1.isChainSupportedForSplitters)(this.chainId)) {
|
|
214
222
|
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
215
223
|
}
|
|
216
|
-
const
|
|
224
|
+
const chainConfig = constants_js_1.CHAIN_CONFIGURATION[this.chainId];
|
|
225
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.SPLITMAIN_ADDRESS)) {
|
|
226
|
+
throw new Error(`SPLITMAIN_ADDRESS is not configured for chain ${this.chainId}`);
|
|
227
|
+
}
|
|
228
|
+
const checkSplitMainAddress = yield (0, utils_js_1.isContractAvailable)(chainConfig.SPLITMAIN_ADDRESS.address, this.signer.provider, chainConfig.SPLITMAIN_ADDRESS.bytecode);
|
|
217
229
|
if (!checkSplitMainAddress) {
|
|
218
230
|
throw new Error(`Something isn not working as expected, check this issue with obol-sdk team on ${constants_js_1.OBOL_SDK_EMAIL}`);
|
|
219
231
|
}
|
|
220
232
|
const retroActiveFundingRecipient = {
|
|
221
|
-
account:
|
|
233
|
+
account: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
|
|
222
234
|
percentAllocation: validatedPayload.ObolRAFSplit,
|
|
223
235
|
};
|
|
224
236
|
const copiedSplitRecipients = [...validatedPayload.splitRecipients];
|
package/dist/cjs/src/schema.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rewardsSplitterPayloadSchema = exports.totalSplitterPayloadSchema = exports.definitionSchema = exports.operatorPayloadSchema = void 0;
|
|
3
|
+
exports.ovmTotalSplitPayloadSchema = exports.ovmRewardsSplitPayloadSchema = exports.ovmBaseSplitPayload = exports.rewardsSplitterPayloadSchema = exports.totalSplitterPayloadSchema = exports.definitionSchema = exports.operatorPayloadSchema = void 0;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const ajv_1 = require("./ajv");
|
|
7
|
+
const viem_1 = require("viem");
|
|
7
8
|
exports.operatorPayloadSchema = {
|
|
8
9
|
type: 'object',
|
|
9
10
|
properties: {
|
|
@@ -140,3 +141,72 @@ exports.rewardsSplitterPayloadSchema = {
|
|
|
140
141
|
validateRewardsSplitRecipients: true,
|
|
141
142
|
required: ['splitRecipients', 'principalRecipient', 'etherAmount'],
|
|
142
143
|
};
|
|
144
|
+
exports.ovmBaseSplitPayload = {
|
|
145
|
+
rewardSplitRecipients: {
|
|
146
|
+
type: 'array',
|
|
147
|
+
items: {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
address: {
|
|
151
|
+
type: 'string',
|
|
152
|
+
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
153
|
+
},
|
|
154
|
+
percentAllocation: { type: 'number' },
|
|
155
|
+
},
|
|
156
|
+
required: ['address', 'percentAllocation'],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
OVMOwnerAddress: {
|
|
160
|
+
type: 'string',
|
|
161
|
+
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
162
|
+
},
|
|
163
|
+
splitOwnerAddress: {
|
|
164
|
+
type: 'string',
|
|
165
|
+
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
166
|
+
default: viem_1.zeroAddress,
|
|
167
|
+
},
|
|
168
|
+
principalThreshold: {
|
|
169
|
+
type: 'number',
|
|
170
|
+
minimum: 16,
|
|
171
|
+
default: constants_1.PRINCIPAL_THRESHOLD,
|
|
172
|
+
},
|
|
173
|
+
distributorFeePercent: {
|
|
174
|
+
type: 'number',
|
|
175
|
+
minimum: 0,
|
|
176
|
+
maximum: 10,
|
|
177
|
+
default: 0,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
exports.ovmRewardsSplitPayloadSchema = {
|
|
181
|
+
type: 'object',
|
|
182
|
+
properties: Object.assign(Object.assign({}, exports.ovmBaseSplitPayload), { principalRecipient: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
185
|
+
} }),
|
|
186
|
+
validateOVMRewardsSplitRecipients: true,
|
|
187
|
+
required: ['rewardSplitRecipients', 'OVMOwnerAddress', 'principalRecipient'],
|
|
188
|
+
};
|
|
189
|
+
exports.ovmTotalSplitPayloadSchema = {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: Object.assign(Object.assign({}, exports.ovmBaseSplitPayload), { principalSplitRecipients: {
|
|
192
|
+
type: 'array',
|
|
193
|
+
items: {
|
|
194
|
+
type: 'object',
|
|
195
|
+
properties: {
|
|
196
|
+
address: {
|
|
197
|
+
type: 'string',
|
|
198
|
+
pattern: '^0x[a-fA-F0-9]{40}$',
|
|
199
|
+
},
|
|
200
|
+
percentAllocation: { type: 'number' },
|
|
201
|
+
},
|
|
202
|
+
required: ['address', 'percentAllocation'],
|
|
203
|
+
},
|
|
204
|
+
} }),
|
|
205
|
+
validateOVMRewardsSplitRecipients: true,
|
|
206
|
+
validateOVMTotalSplitRecipients: true,
|
|
207
|
+
required: [
|
|
208
|
+
'rewardSplitRecipients',
|
|
209
|
+
'principalSplitRecipients',
|
|
210
|
+
'OVMOwnerAddress',
|
|
211
|
+
],
|
|
212
|
+
};
|
|
@@ -9,20 +9,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.multicall = exports.getOWRTranches = exports.deploySplitterAndOWRContracts = exports.deploySplitterContract = exports.handleDeployOWRAndSplitter = exports.predictSplitterAddress = exports.formatSplitRecipients = void 0;
|
|
12
|
+
exports.deployOVMAndSplitV2 = exports.deployOVMContract = exports.isSplitV2Deployed = exports.predictSplitV2Address = exports.createSplitsClient = exports.formatRecipientsForSplitV2 = exports.multicall = exports.getOWRTranches = exports.deploySplitterAndOWRContracts = exports.deploySplitterContract = exports.handleDeployOWRAndSplitter = exports.predictSplitterAddress = exports.formatSplitRecipients = void 0;
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
14
|
const OWR_1 = require("../abi/OWR");
|
|
15
|
+
const OVMFactory_1 = require("../abi/OVMFactory");
|
|
15
16
|
const SplitMain_1 = require("../abi/SplitMain");
|
|
16
17
|
const Multicall_1 = require("../abi/Multicall");
|
|
17
18
|
const constants_1 = require("../constants");
|
|
19
|
+
const splits_sdk_1 = require("@0xsplits/splits-sdk");
|
|
20
|
+
const viem_1 = require("viem");
|
|
21
|
+
const chains_1 = require("viem/chains");
|
|
22
|
+
const accounts_1 = require("viem/accounts");
|
|
18
23
|
const splitMainContractInterface = new ethers_1.Interface(SplitMain_1.splitMainEthereumAbi);
|
|
19
24
|
const owrFactoryContractInterface = new ethers_1.Interface(OWR_1.OWRFactoryContract.abi);
|
|
20
|
-
const
|
|
25
|
+
const ovmFactoryContractInterface = new ethers_1.Interface(OVMFactory_1.OVMFactoryContract.abi);
|
|
26
|
+
// Helper function to extract common recipient formatting logic
|
|
27
|
+
const formatRecipientsCommon = (recipients) => {
|
|
28
|
+
const copiedRecipients = [...recipients];
|
|
29
|
+
// Handle both SplitRecipient and SplitV2Recipient types
|
|
30
|
+
const getAddress = (item) => item.account || item.address;
|
|
31
|
+
const getPercentAllocation = (item) => item.percentAllocation;
|
|
21
32
|
// Has to be sorted when passed
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
copiedRecipients.sort((a, b) => getAddress(a).localeCompare(getAddress(b)));
|
|
34
|
+
return {
|
|
35
|
+
sortedRecipients: copiedRecipients,
|
|
36
|
+
getAddress,
|
|
37
|
+
getPercentAllocation,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const formatSplitRecipients = (recipients) => {
|
|
41
|
+
const { sortedRecipients, getAddress, getPercentAllocation } = formatRecipientsCommon(recipients);
|
|
42
|
+
const accounts = sortedRecipients.map(item => getAddress(item));
|
|
43
|
+
const percentAllocations = sortedRecipients.map(recipient => {
|
|
44
|
+
const splitTostring = (getPercentAllocation(recipient) * 1e4).toFixed(0);
|
|
26
45
|
return parseInt(splitTostring);
|
|
27
46
|
});
|
|
28
47
|
return { accounts, percentAllocations };
|
|
@@ -31,7 +50,7 @@ exports.formatSplitRecipients = formatSplitRecipients;
|
|
|
31
50
|
const predictSplitterAddress = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
51
|
var _a, _b, _c;
|
|
33
52
|
try {
|
|
34
|
-
const splitMainContractInstance = new ethers_1.Contract(
|
|
53
|
+
const splitMainContractInstance = new ethers_1.Contract(getChainConfig(chainId).SPLITMAIN_ADDRESS.address, SplitMain_1.splitMainEthereumAbi, signer);
|
|
35
54
|
let predictedSplitterAddress;
|
|
36
55
|
if (controllerAddress === ethers_1.ZeroAddress) {
|
|
37
56
|
try {
|
|
@@ -134,7 +153,7 @@ exports.handleDeployOWRAndSplitter = handleDeployOWRAndSplitter;
|
|
|
134
153
|
const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
154
|
var _g, _h, _j, _k, _l;
|
|
136
155
|
try {
|
|
137
|
-
const OWRFactoryInstance = new ethers_1.Contract(
|
|
156
|
+
const OWRFactoryInstance = new ethers_1.Contract(getChainConfig(chainId).OWR_FACTORY_ADDRESS.address, OWR_1.OWRFactoryContract.abi, signer);
|
|
138
157
|
let tx;
|
|
139
158
|
try {
|
|
140
159
|
tx = yield OWRFactoryInstance.createOWRecipient(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, (0, ethers_1.parseEther)(owrArgs.amountOfPrincipalStake.toString()));
|
|
@@ -178,7 +197,7 @@ const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, v
|
|
|
178
197
|
const deploySplitterContract = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
179
198
|
var _m, _o, _p, _q, _r;
|
|
180
199
|
try {
|
|
181
|
-
const splitMainContractInstance = new ethers_1.Contract(
|
|
200
|
+
const splitMainContractInstance = new ethers_1.Contract(getChainConfig(chainId).SPLITMAIN_ADDRESS.address, SplitMain_1.splitMainEthereumAbi, signer);
|
|
182
201
|
let tx;
|
|
183
202
|
try {
|
|
184
203
|
tx = yield splitMainContractInstance.createSplit(accounts, percentAllocations, distributorFee, controllerAddress);
|
|
@@ -226,13 +245,13 @@ const deploySplitterAndOWRContracts = ({ owrArgs, splitterArgs, signer, chainId,
|
|
|
226
245
|
const splitTxData = encodeCreateSplitTxData(splitterArgs.accounts, splitterArgs.percentAllocations, splitterArgs.distributorFee, splitterArgs.controllerAddress);
|
|
227
246
|
const owrTxData = encodeCreateOWRecipientTxData(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, owrArgs.amountOfPrincipalStake);
|
|
228
247
|
executeCalls.push({
|
|
229
|
-
target:
|
|
248
|
+
target: getChainConfig(chainId).SPLITMAIN_ADDRESS.address,
|
|
230
249
|
callData: splitTxData,
|
|
231
250
|
}, {
|
|
232
|
-
target:
|
|
251
|
+
target: getChainConfig(chainId).OWR_FACTORY_ADDRESS.address,
|
|
233
252
|
callData: owrTxData,
|
|
234
253
|
});
|
|
235
|
-
const multicallAddess =
|
|
254
|
+
const multicallAddess = getChainConfig(chainId).MULTICALL_ADDRESS.address;
|
|
236
255
|
const executeMultiCalls = yield (0, exports.multicall)(executeCalls, signer, multicallAddess);
|
|
237
256
|
const splitAddressData = (_s = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[0]) === null || _s === void 0 ? void 0 : _s.topics[1];
|
|
238
257
|
const formattedSplitterAddress = '0x' + (splitAddressData === null || splitAddressData === void 0 ? void 0 : splitAddressData.slice(26, 66));
|
|
@@ -325,3 +344,190 @@ const encodeCreateOWRecipientTxData = (recoveryAddress, principalRecipient, rewa
|
|
|
325
344
|
(0, ethers_1.parseEther)(amountOfPrincipalStake.toString()),
|
|
326
345
|
]);
|
|
327
346
|
};
|
|
347
|
+
// OVM and SplitV2 Helper Functions
|
|
348
|
+
// Helper function to format recipients specifically for SplitV2 (returns SplitV2Recipient[])
|
|
349
|
+
const formatRecipientsForSplitV2 = (splitRecipients) => {
|
|
350
|
+
const { sortedRecipients, getAddress, getPercentAllocation } = formatRecipientsCommon(splitRecipients);
|
|
351
|
+
return sortedRecipients
|
|
352
|
+
.filter(item => getAddress(item) !== '')
|
|
353
|
+
.map(item => ({
|
|
354
|
+
address: getAddress(item),
|
|
355
|
+
percentAllocation: parseFloat(getPercentAllocation(item).toString()),
|
|
356
|
+
}));
|
|
357
|
+
};
|
|
358
|
+
exports.formatRecipientsForSplitV2 = formatRecipientsForSplitV2;
|
|
359
|
+
const createSplitsClient = (signer, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
360
|
+
const chain = chainId === 1 ? chains_1.mainnet : chains_1.hoodi;
|
|
361
|
+
const client = (0, viem_1.createPublicClient)({
|
|
362
|
+
chain,
|
|
363
|
+
transport: (0, viem_1.http)(constants_1.CHAIN_PUBLIC_RPC_URL[chainId]),
|
|
364
|
+
});
|
|
365
|
+
// convert signer to walletClient
|
|
366
|
+
if (typeof window !== 'undefined' &&
|
|
367
|
+
signer.provider instanceof ethers_1.BrowserProvider) {
|
|
368
|
+
// For browser environment
|
|
369
|
+
const address = yield signer.getAddress();
|
|
370
|
+
const viemWalletClient = (0, viem_1.createWalletClient)({
|
|
371
|
+
account: address,
|
|
372
|
+
chain,
|
|
373
|
+
transport: (0, viem_1.custom)(window.ethereum),
|
|
374
|
+
});
|
|
375
|
+
return new splits_sdk_1.SplitsClient({
|
|
376
|
+
publicClient: client,
|
|
377
|
+
walletClient: viemWalletClient,
|
|
378
|
+
chainId,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// For non-browser environment, extract private key from signer
|
|
383
|
+
const signerPrivateKey = signer === null || signer === void 0 ? void 0 : signer.privateKey;
|
|
384
|
+
if (!signerPrivateKey) {
|
|
385
|
+
throw new Error('Signer private key not available');
|
|
386
|
+
}
|
|
387
|
+
const privateKey = signerPrivateKey.startsWith('0x')
|
|
388
|
+
? signerPrivateKey
|
|
389
|
+
: `0x${signerPrivateKey}`;
|
|
390
|
+
const scriptAccount = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
391
|
+
const account = scriptAccount;
|
|
392
|
+
const viemWalletClient = (0, viem_1.createWalletClient)({
|
|
393
|
+
account,
|
|
394
|
+
chain,
|
|
395
|
+
transport: (0, viem_1.http)(constants_1.CHAIN_PUBLIC_RPC_URL[chainId]),
|
|
396
|
+
});
|
|
397
|
+
return new splits_sdk_1.SplitsClient({
|
|
398
|
+
publicClient: client,
|
|
399
|
+
walletClient: viemWalletClient,
|
|
400
|
+
chainId,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
exports.createSplitsClient = createSplitsClient;
|
|
405
|
+
const predictSplitV2Address = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
406
|
+
var _z;
|
|
407
|
+
try {
|
|
408
|
+
const splitsClient = yield (0, exports.createSplitsClient)(signer, chainId);
|
|
409
|
+
const response = yield splitsClient.splitV2.predictDeterministicAddress({
|
|
410
|
+
ownerAddress: splitOwnerAddress,
|
|
411
|
+
recipients,
|
|
412
|
+
distributorFeePercent,
|
|
413
|
+
salt,
|
|
414
|
+
});
|
|
415
|
+
return response.splitAddress;
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
throw new Error(`Failed to predict SplitV2 address: ${(_z = error.message) !== null && _z !== void 0 ? _z : 'SplitV2 SDK call failed'}`);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
exports.predictSplitV2Address = predictSplitV2Address;
|
|
422
|
+
const isSplitV2Deployed = ({ splitOwnerAddress, recipients, distributorFeePercent, salt, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
423
|
+
try {
|
|
424
|
+
const splitsClient = yield (0, exports.createSplitsClient)(signer, chainId);
|
|
425
|
+
const response = yield splitsClient.splitV2.isDeployed({
|
|
426
|
+
ownerAddress: splitOwnerAddress,
|
|
427
|
+
recipients,
|
|
428
|
+
distributorFeePercent,
|
|
429
|
+
salt,
|
|
430
|
+
});
|
|
431
|
+
return response.deployed;
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
// If the check fails, assume it's not deployed
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
exports.isSplitV2Deployed = isSplitV2Deployed;
|
|
439
|
+
const deployOVMContract = ({ OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
440
|
+
var _0, _1, _2;
|
|
441
|
+
try {
|
|
442
|
+
const chainConfig = getChainConfig(chainId);
|
|
443
|
+
if (!((_0 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_ADDRESS) === null || _0 === void 0 ? void 0 : _0.address)) {
|
|
444
|
+
throw new Error(`OVM Factory not configured for chain ${chainId}`);
|
|
445
|
+
}
|
|
446
|
+
const ovmFactoryContract = new ethers_1.Contract(chainConfig.OVM_FACTORY_ADDRESS.address, OVMFactory_1.OVMFactoryContract.abi, signer);
|
|
447
|
+
const tx = yield ovmFactoryContract.createObolValidatorManager(OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold);
|
|
448
|
+
const receipt = yield tx.wait();
|
|
449
|
+
// Extract OVM address from logs
|
|
450
|
+
const ovmAddressLog = (_1 = receipt === null || receipt === void 0 ? void 0 : receipt.logs[1]) === null || _1 === void 0 ? void 0 : _1.topics[1];
|
|
451
|
+
if (!ovmAddressLog) {
|
|
452
|
+
throw new Error('Failed to extract OVM address from transaction logs');
|
|
453
|
+
}
|
|
454
|
+
const ovmAddress = '0x' + ovmAddressLog.slice(26, 66);
|
|
455
|
+
return ovmAddress;
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
throw new Error(`Failed to deploy OVM contract: ${(_2 = error.message) !== null && _2 !== void 0 ? _2 : 'OVM deployment failed'}`);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
exports.deployOVMContract = deployOVMContract;
|
|
462
|
+
const deployOVMAndSplitV2 = ({ ovmArgs, rewardRecipients, isRewardsSplitterDeployed, distributorFeePercent, salt, signer, chainId, principalSplitRecipients, isPrincipalSplitDeployed, splitOwnerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
463
|
+
var _3, _4, _5, _6, _7;
|
|
464
|
+
try {
|
|
465
|
+
const chainConfig = getChainConfig(chainId);
|
|
466
|
+
if (!((_3 = chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_ADDRESS) === null || _3 === void 0 ? void 0 : _3.address)) {
|
|
467
|
+
throw new Error(`OVM Factory not configured for chain ${chainId}`);
|
|
468
|
+
}
|
|
469
|
+
const splitsClient = yield (0, exports.createSplitsClient)(signer, chainId);
|
|
470
|
+
const executeCalls = [];
|
|
471
|
+
if (rewardRecipients && !isRewardsSplitterDeployed) {
|
|
472
|
+
// Create rewards split call data
|
|
473
|
+
const rewardsSplitTxData = yield splitsClient.splitV2.callData.createSplit({
|
|
474
|
+
recipients: rewardRecipients,
|
|
475
|
+
distributorFeePercent,
|
|
476
|
+
ownerAddress: splitOwnerAddress,
|
|
477
|
+
salt,
|
|
478
|
+
});
|
|
479
|
+
executeCalls.push(rewardsSplitTxData);
|
|
480
|
+
}
|
|
481
|
+
// Create principal split call data if needed (for total split scenario)
|
|
482
|
+
if (principalSplitRecipients && !isPrincipalSplitDeployed) {
|
|
483
|
+
const principalSplitTxData = yield splitsClient.splitV2.callData.createSplit({
|
|
484
|
+
recipients: principalSplitRecipients,
|
|
485
|
+
distributorFeePercent,
|
|
486
|
+
salt,
|
|
487
|
+
ownerAddress: splitOwnerAddress,
|
|
488
|
+
});
|
|
489
|
+
executeCalls.push(principalSplitTxData);
|
|
490
|
+
}
|
|
491
|
+
// Create OVM call data
|
|
492
|
+
const ovmTxData = encodeCreateOVMTxData(ovmArgs.OVMOwnerAddress, ovmArgs.principalRecipient, ovmArgs.rewardRecipient, ovmArgs.principalThreshold);
|
|
493
|
+
executeCalls.push({
|
|
494
|
+
address: chainConfig.OVM_FACTORY_ADDRESS.address,
|
|
495
|
+
data: ovmTxData,
|
|
496
|
+
});
|
|
497
|
+
// Execute multicall
|
|
498
|
+
const executeMultiCalls = yield splitsClient.splitV2.multicall({
|
|
499
|
+
calls: executeCalls,
|
|
500
|
+
});
|
|
501
|
+
// Extract addresses from events
|
|
502
|
+
let ovmAddress;
|
|
503
|
+
const eventCount = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.events.length;
|
|
504
|
+
if (eventCount === 2) {
|
|
505
|
+
ovmAddress = (_4 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.events[0]) === null || _4 === void 0 ? void 0 : _4.address;
|
|
506
|
+
}
|
|
507
|
+
else if (eventCount === 5) {
|
|
508
|
+
ovmAddress = (_5 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.events[3]) === null || _5 === void 0 ? void 0 : _5.address;
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
ovmAddress = (_6 = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.events[6]) === null || _6 === void 0 ? void 0 : _6.address;
|
|
512
|
+
}
|
|
513
|
+
if (!ovmAddress) {
|
|
514
|
+
throw new Error('Failed to extract contract addresses from multicall events');
|
|
515
|
+
}
|
|
516
|
+
return ovmAddress;
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
throw new Error(`Failed to deploy OVM and SplitV2: ${(_7 = error.message) !== null && _7 !== void 0 ? _7 : 'Deployment failed'}`);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
exports.deployOVMAndSplitV2 = deployOVMAndSplitV2;
|
|
523
|
+
const encodeCreateOVMTxData = (OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold) => {
|
|
524
|
+
return ovmFactoryContractInterface.encodeFunctionData('createObolValidatorManager', [OVMOwnerAddress, principalRecipient, rewardRecipient, principalThreshold]);
|
|
525
|
+
};
|
|
526
|
+
// Helper function to safely get chain configuration
|
|
527
|
+
const getChainConfig = (chainId) => {
|
|
528
|
+
const config = constants_1.CHAIN_CONFIGURATION[chainId];
|
|
529
|
+
if (!config) {
|
|
530
|
+
throw new Error(`Chain configuration not found for chain ID ${chainId}`);
|
|
531
|
+
}
|
|
532
|
+
return config;
|
|
533
|
+
};
|