@obolnetwork/obol-sdk 2.7.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.
Files changed (56) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/abi/OVMFactory.js +620 -0
  3. package/dist/cjs/src/abi/splitV2FactoryAbi.js +420 -0
  4. package/dist/cjs/src/ajv.js +33 -6
  5. package/dist/cjs/src/bytecodes.js +10 -1
  6. package/dist/cjs/src/constants.js +71 -15
  7. package/dist/cjs/src/index.js +21 -9
  8. package/dist/cjs/src/schema.js +70 -1
  9. package/dist/cjs/src/splits/splitHelpers.js +188 -14
  10. package/dist/cjs/src/splits/splits.js +283 -0
  11. package/dist/cjs/src/types.js +0 -1
  12. package/dist/cjs/test/client/ajv.spec.js +269 -0
  13. package/dist/cjs/test/client/methods.spec.js +418 -0
  14. package/dist/cjs/test/fixtures.js +13 -1
  15. package/dist/cjs/test/splits/splits.spec.js +239 -0
  16. package/dist/esm/package.json +1 -1
  17. package/dist/esm/src/abi/OVMFactory.js +617 -0
  18. package/dist/esm/src/abi/splitV2FactoryAbi.js +417 -0
  19. package/dist/esm/src/ajv.js +33 -6
  20. package/dist/esm/src/bytecodes.js +9 -0
  21. package/dist/esm/src/constants.js +70 -15
  22. package/dist/esm/src/index.js +20 -9
  23. package/dist/esm/src/schema.js +70 -1
  24. package/dist/esm/src/splits/splitHelpers.js +182 -13
  25. package/dist/esm/src/splits/splits.js +279 -0
  26. package/dist/esm/src/types.js +0 -1
  27. package/dist/esm/test/client/ajv.spec.js +267 -0
  28. package/dist/esm/test/client/methods.spec.js +393 -0
  29. package/dist/esm/test/fixtures.js +12 -0
  30. package/dist/esm/test/splits/splits.spec.js +237 -0
  31. package/dist/types/src/abi/OVMFactory.d.ts +662 -0
  32. package/dist/types/src/abi/splitV2FactoryAbi.d.ts +60 -0
  33. package/dist/types/src/bytecodes.d.ts +9 -0
  34. package/dist/types/src/constants.d.ts +10 -21
  35. package/dist/types/src/exits/verificationHelpers.d.ts +1 -0
  36. package/dist/types/src/index.d.ts +7 -0
  37. package/dist/types/src/schema.d.ts +145 -0
  38. package/dist/types/src/splits/splitHelpers.d.ts +39 -2
  39. package/dist/types/src/splits/splits.d.ts +51 -0
  40. package/dist/types/src/types.d.ts +87 -2
  41. package/dist/types/src/verification/common.d.ts +1 -0
  42. package/dist/types/test/client/ajv.spec.d.ts +1 -0
  43. package/dist/types/test/client/methods.spec.d.ts +1 -0
  44. package/dist/types/test/fixtures.d.ts +10 -0
  45. package/dist/types/test/splits/splits.spec.d.ts +1 -0
  46. package/package.json +1 -1
  47. package/src/abi/OVMFactory.ts +617 -0
  48. package/src/abi/splitV2FactoryAbi.ts +417 -0
  49. package/src/ajv.ts +55 -13
  50. package/src/bytecodes.ts +19 -0
  51. package/src/constants.ts +84 -16
  52. package/src/index.ts +36 -15
  53. package/src/schema.ts +79 -0
  54. package/src/splits/splitHelpers.ts +373 -18
  55. package/src/splits/splits.ts +406 -0
  56. package/src/types.ts +100 -3
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ObolSplits = void 0;
13
+ const splitHelpers_1 = require("./splitHelpers");
14
+ const constants_1 = require("../constants");
15
+ const schema_1 = require("../schema");
16
+ const ajv_1 = require("../ajv");
17
+ const utils_1 = require("../utils");
18
+ /**
19
+ * ObolSplits can be used for creating and managing Obol splits.
20
+ * @class
21
+ * @internal Access it through Client.splits.
22
+ * @example
23
+ * const obolClient = new Client(config);
24
+ * await obolClient.splits.createValidatorManagerAndRewardsSplit(OVMRewardsSplitPayload);
25
+ */
26
+ class ObolSplits {
27
+ constructor(signer, chainId, provider) {
28
+ this.signer = signer;
29
+ this.chainId = chainId;
30
+ this.provider = provider;
31
+ }
32
+ /**
33
+ * Creates an Obol OVM and Pull split configuration for rewards-only scenario.
34
+ *
35
+ * This method deploys OVM and SplitV2 contracts for managing validator rewards only.
36
+ * Principal is handled by a single address, while rewards are split among recipients.
37
+ *
38
+ * @remarks
39
+ * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
40
+ * and not pushed to version control.
41
+ *
42
+ * @param {OVMRewardsSplitPayload} payload - Data needed to deploy OVM and SplitV2
43
+ * @returns {Promise<ClusterValidator>} OVM address as withdrawal address and splitter as fee recipient
44
+ * @throws Will throw an error if the splitter configuration is not supported or deployment fails
45
+ *
46
+ * An example of how to use createValidatorManagerAndRewardsSplit:
47
+ * [createValidatorManagerAndRewardsSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L333)
48
+ */
49
+ createValidatorManagerAndRewardsSplit(payload) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const salt = constants_1.SPLITS_V2_SALT;
52
+ if (!this.signer) {
53
+ throw new Error('Signer is required in createValidatorManagerAndRewardsSplit');
54
+ }
55
+ const validatedPayload = (0, ajv_1.validatePayload)(payload, schema_1.ovmRewardsSplitPayloadSchema);
56
+ if (!(0, constants_1.isChainSupportedForSplitters)(this.chainId)) {
57
+ throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
58
+ }
59
+ const chainConfig = constants_1.CHAIN_CONFIGURATION[this.chainId];
60
+ if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT)) {
61
+ throw new Error(`OVM contract factory is not configured for chain ${this.chainId}`);
62
+ }
63
+ if (!this.provider) {
64
+ throw new Error('Provider is required to check OVM factory contract availability');
65
+ }
66
+ const ovmFactoryConfig = chainConfig.OVM_FACTORY_CONTRACT;
67
+ const splitV2FactoryConfig = chainConfig.SPLIT_V2_FACTORY_CONTRACT;
68
+ const multiCallConfig = chainConfig.MULTICALL_CONTRACT;
69
+ if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) ||
70
+ !(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode) ||
71
+ !(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.address) ||
72
+ !(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.bytecode) ||
73
+ !(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.address) ||
74
+ !(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.bytecode)) {
75
+ throw new Error(`Contracts configuration is incomplete for chain ${this.chainId}`);
76
+ }
77
+ const checkOVMFactoryContract = yield (0, utils_1.isContractAvailable)(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
78
+ const checkSplitV2FactoryContract = yield (0, utils_1.isContractAvailable)(splitV2FactoryConfig.address, this.provider, splitV2FactoryConfig.bytecode);
79
+ const checkMultiCallContract = yield (0, utils_1.isContractAvailable)(multiCallConfig.address, this.provider, multiCallConfig.bytecode);
80
+ if (!checkOVMFactoryContract ||
81
+ !checkSplitV2FactoryContract ||
82
+ !checkMultiCallContract) {
83
+ throw new Error(`Splitter contract is not deployed or available on chain ${this.chainId}`);
84
+ }
85
+ const retroActiveFundingRecipient = {
86
+ address: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
87
+ percentAllocation: constants_1.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
88
+ };
89
+ const copiedRewardsSplitRecipients = [
90
+ ...validatedPayload.rewardSplitRecipients,
91
+ ];
92
+ copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
93
+ // Format recipients for SplitV2
94
+ const rewardRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(copiedRewardsSplitRecipients);
95
+ const predictedSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
96
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
97
+ recipients: rewardRecipients,
98
+ distributorFeePercent: validatedPayload.distributorFeePercent,
99
+ salt,
100
+ signer: this.signer,
101
+ chainId: this.chainId,
102
+ });
103
+ const isRewardSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
104
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
105
+ recipients: rewardRecipients,
106
+ distributorFeePercent: validatedPayload.distributorFeePercent,
107
+ salt,
108
+ signer: this.signer,
109
+ chainId: this.chainId,
110
+ });
111
+ if (isRewardSplitterDeployed) {
112
+ const ovmAddress = yield (0, splitHelpers_1.deployOVMContract)({
113
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
114
+ principalRecipient: validatedPayload.principalRecipient,
115
+ rewardRecipient: predictedSplitAddress,
116
+ principalThreshold: validatedPayload.principalThreshold,
117
+ signer: this.signer,
118
+ chainId: this.chainId,
119
+ });
120
+ return {
121
+ withdrawal_address: ovmAddress,
122
+ fee_recipient_address: predictedSplitAddress,
123
+ };
124
+ }
125
+ else {
126
+ const ovmAddress = yield (0, splitHelpers_1.deployOVMAndSplitV2)({
127
+ ovmArgs: {
128
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
129
+ rewardRecipient: predictedSplitAddress,
130
+ principalRecipient: validatedPayload.principalRecipient,
131
+ principalThreshold: validatedPayload.principalThreshold,
132
+ },
133
+ rewardRecipients,
134
+ isRewardsSplitterDeployed: isRewardSplitterDeployed,
135
+ distributorFeePercent: validatedPayload.distributorFeePercent,
136
+ salt,
137
+ signer: this.signer,
138
+ chainId: this.chainId,
139
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
140
+ });
141
+ return {
142
+ withdrawal_address: ovmAddress,
143
+ fee_recipient_address: predictedSplitAddress,
144
+ };
145
+ }
146
+ });
147
+ }
148
+ /**
149
+ * Creates an Obol OVM and Total split configuration for total split scenario.
150
+ *
151
+ * This method deploys OVM and SplitV2 contracts for managing both validator rewards and principal.
152
+ * Both rewards and principal are split among recipients, with rewards including RAF recipient.
153
+ *
154
+ * @remarks
155
+ * **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
156
+ * and not pushed to version control.
157
+ *
158
+ * @param {OVMTotalSplitPayload} payload - Data needed to deploy OVM and SplitV2
159
+ * @returns {Promise<ClusterValidator>} OVM address as withdrawal address and splitter as fee recipient
160
+ * @throws Will throw an error if the splitter configuration is not supported or deployment fails
161
+ *
162
+ * An example of how to use createValidatorManagerAndTotalSplit:
163
+ * [createValidatorManagerAndTotalSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#340)
164
+ */
165
+ createValidatorManagerAndTotalSplit(payload) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const salt = constants_1.SPLITS_V2_SALT;
168
+ if (!this.signer) {
169
+ throw new Error('Signer is required in createValidatorManagerAndTotalSplit');
170
+ }
171
+ const validatedPayload = (0, ajv_1.validatePayload)(payload, schema_1.ovmTotalSplitPayloadSchema);
172
+ if (!(0, constants_1.isChainSupportedForSplitters)(this.chainId)) {
173
+ throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
174
+ }
175
+ const chainConfig = constants_1.CHAIN_CONFIGURATION[this.chainId];
176
+ if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_CONTRACT)) {
177
+ throw new Error(`OVM contract factory is not configured for chain ${this.chainId}`);
178
+ }
179
+ if (!this.provider) {
180
+ throw new Error('Provider is required to check OVM factory contract availability');
181
+ }
182
+ const ovmFactoryConfig = chainConfig.OVM_FACTORY_CONTRACT;
183
+ const splitV2FactoryConfig = chainConfig.SPLIT_V2_FACTORY_CONTRACT;
184
+ const multiCallConfig = chainConfig.MULTICALL_CONTRACT;
185
+ if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) ||
186
+ !(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode) ||
187
+ !(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.address) ||
188
+ !(splitV2FactoryConfig === null || splitV2FactoryConfig === void 0 ? void 0 : splitV2FactoryConfig.bytecode) ||
189
+ !(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.address) ||
190
+ !(multiCallConfig === null || multiCallConfig === void 0 ? void 0 : multiCallConfig.bytecode)) {
191
+ throw new Error(`Contracts configuration is incomplete for chain ${this.chainId}`);
192
+ }
193
+ const checkOVMFactoryContract = yield (0, utils_1.isContractAvailable)(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
194
+ const checkSplitV2FactoryContract = yield (0, utils_1.isContractAvailable)(splitV2FactoryConfig.address, this.provider, splitV2FactoryConfig.bytecode);
195
+ const checkMultiCallContract = yield (0, utils_1.isContractAvailable)(multiCallConfig.address, this.provider, multiCallConfig.bytecode);
196
+ if (!checkOVMFactoryContract ||
197
+ !checkSplitV2FactoryContract ||
198
+ !checkMultiCallContract) {
199
+ throw new Error(`Splitter contract is not deployed or available on chain ${this.chainId}`);
200
+ }
201
+ const retroActiveFundingRecipient = {
202
+ address: chainConfig.RETROACTIVE_FUNDING_CONTRACT.address,
203
+ percentAllocation: constants_1.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
204
+ };
205
+ const copiedRewardsSplitRecipients = [
206
+ ...validatedPayload.rewardSplitRecipients,
207
+ ];
208
+ copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
209
+ const rewardsRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(copiedRewardsSplitRecipients);
210
+ const principalSplitRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(validatedPayload.principalSplitRecipients);
211
+ const predictedRewardsSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
212
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
213
+ recipients: rewardsRecipients,
214
+ distributorFeePercent: validatedPayload.distributorFeePercent,
215
+ salt,
216
+ signer: this.signer,
217
+ chainId: this.chainId,
218
+ });
219
+ const predictedPrincipalSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
220
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
221
+ recipients: principalSplitRecipients,
222
+ distributorFeePercent: validatedPayload.distributorFeePercent,
223
+ salt,
224
+ signer: this.signer,
225
+ chainId: this.chainId,
226
+ });
227
+ const isRewardsSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
228
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
229
+ recipients: rewardsRecipients,
230
+ distributorFeePercent: validatedPayload.distributorFeePercent,
231
+ salt,
232
+ signer: this.signer,
233
+ chainId: this.chainId,
234
+ });
235
+ const isPrincipalSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
236
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
237
+ recipients: principalSplitRecipients,
238
+ distributorFeePercent: validatedPayload.distributorFeePercent,
239
+ salt,
240
+ signer: this.signer,
241
+ chainId: this.chainId,
242
+ });
243
+ if (isRewardsSplitterDeployed && isPrincipalSplitterDeployed) {
244
+ const ovmAddress = yield (0, splitHelpers_1.deployOVMContract)({
245
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
246
+ principalRecipient: predictedPrincipalSplitAddress,
247
+ rewardRecipient: predictedRewardsSplitAddress,
248
+ principalThreshold: validatedPayload.principalThreshold,
249
+ signer: this.signer,
250
+ chainId: this.chainId,
251
+ });
252
+ return {
253
+ withdrawal_address: ovmAddress,
254
+ fee_recipient_address: predictedRewardsSplitAddress,
255
+ };
256
+ }
257
+ else {
258
+ // Use multicall to deploy any contracts that aren't deployed
259
+ const ovmAddress = yield (0, splitHelpers_1.deployOVMAndSplitV2)({
260
+ ovmArgs: {
261
+ OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
262
+ rewardRecipient: predictedRewardsSplitAddress,
263
+ principalRecipient: predictedPrincipalSplitAddress,
264
+ principalThreshold: validatedPayload.principalThreshold,
265
+ },
266
+ rewardRecipients: rewardsRecipients,
267
+ distributorFeePercent: validatedPayload.distributorFeePercent,
268
+ salt,
269
+ signer: this.signer,
270
+ chainId: this.chainId,
271
+ principalSplitRecipients,
272
+ isPrincipalSplitDeployed: isPrincipalSplitterDeployed,
273
+ splitOwnerAddress: validatedPayload.splitOwnerAddress,
274
+ });
275
+ return {
276
+ withdrawal_address: ovmAddress,
277
+ fee_recipient_address: predictedRewardsSplitAddress,
278
+ };
279
+ }
280
+ });
281
+ }
282
+ }
283
+ exports.ObolSplits = ObolSplits;
@@ -27,4 +27,3 @@ exports.FORK_NAMES = {
27
27
  [FORK_MAPPING['0x90000069']]: 'sepolia',
28
28
  [FORK_MAPPING['0x10000910']]: 'hoodi',
29
29
  };
30
- // Add other SDK-specific types below or import from other type files
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ajv_1 = require("../../src/ajv");
4
+ const schema_1 = require("../../src/schema");
5
+ const fixtures_1 = require("../fixtures");
6
+ describe('validatePayload - OVM Schemas', () => {
7
+ describe('ovmRewardsSplitPayloadSchema', () => {
8
+ const validRewardsSplitPayload = {
9
+ rewardSplitRecipients: [
10
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
11
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
12
+ ],
13
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
14
+ splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
15
+ principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
16
+ distributorFeePercent: 0,
17
+ };
18
+ it('should validate a valid rewards split payload', () => {
19
+ const result = (0, ajv_1.validatePayload)(validRewardsSplitPayload, schema_1.ovmRewardsSplitPayloadSchema);
20
+ expect(result).toEqual(validRewardsSplitPayload);
21
+ });
22
+ it('should validate rewards split payload with default values', () => {
23
+ const payloadWithoutDefaults = {
24
+ rewardSplitRecipients: [
25
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
26
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
27
+ ],
28
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
29
+ principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
30
+ };
31
+ const result = (0, ajv_1.validatePayload)(payloadWithoutDefaults, schema_1.ovmRewardsSplitPayloadSchema);
32
+ expect(result).toEqual(Object.assign(Object.assign({}, payloadWithoutDefaults), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
33
+ });
34
+ it('should throw error when rewardSplitRecipients total percentage is not 99%', () => {
35
+ const invalidPayload = Object.assign(Object.assign({}, validRewardsSplitPayload), { rewardSplitRecipients: [
36
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
37
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 40 }, // Total: 90%
38
+ ] });
39
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMRewardsSplitRecipients" keyword validation');
40
+ });
41
+ it('should throw error when rewardSplitRecipients total percentage exceeds 99%', () => {
42
+ const invalidPayload = Object.assign(Object.assign({}, validRewardsSplitPayload), { rewardSplitRecipients: [
43
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 60 },
44
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 50 }, // Total: 110%
45
+ ] });
46
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMRewardsSplitRecipients" keyword validation');
47
+ });
48
+ it('should throw error when rewardSplitRecipients is empty', () => {
49
+ const invalidPayload = Object.assign(Object.assign({}, validRewardsSplitPayload), { rewardSplitRecipients: [] });
50
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMRewardsSplitRecipients" keyword validation');
51
+ });
52
+ it('should throw error when rewardSplitRecipients has invalid address format', () => {
53
+ const invalidPayload = Object.assign(Object.assign({}, validRewardsSplitPayload), { rewardSplitRecipients: [
54
+ { address: 'invalid-address', percentAllocation: 50 },
55
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
56
+ ] });
57
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow('Validation failed: /rewardSplitRecipients/0/address must match pattern');
58
+ });
59
+ it('should throw error when OVMOwnerAddress is missing', () => {
60
+ const invalidPayload = {
61
+ rewardSplitRecipients: validRewardsSplitPayload.rewardSplitRecipients,
62
+ principalRecipient: validRewardsSplitPayload.principalRecipient,
63
+ };
64
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow("Validation failed: must have required property 'OVMOwnerAddress'");
65
+ });
66
+ it('should throw error when principalRecipient is missing', () => {
67
+ const invalidPayload = {
68
+ rewardSplitRecipients: validRewardsSplitPayload.rewardSplitRecipients,
69
+ OVMOwnerAddress: validRewardsSplitPayload.OVMOwnerAddress,
70
+ };
71
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmRewardsSplitPayloadSchema)).toThrow("Validation failed: must have required property 'principalRecipient'");
72
+ });
73
+ });
74
+ describe('ovmTotalSplitPayloadSchema', () => {
75
+ const validTotalSplitPayload = {
76
+ rewardSplitRecipients: [
77
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
78
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
79
+ ],
80
+ principalSplitRecipients: [
81
+ {
82
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
83
+ percentAllocation: 60,
84
+ },
85
+ {
86
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
87
+ percentAllocation: 40,
88
+ },
89
+ ],
90
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
91
+ splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
92
+ distributorFeePercent: 0,
93
+ };
94
+ it('should validate a valid total split payload', () => {
95
+ const result = (0, ajv_1.validatePayload)(validTotalSplitPayload, schema_1.ovmTotalSplitPayloadSchema);
96
+ expect(result).toEqual(validTotalSplitPayload);
97
+ });
98
+ it('should validate total split payload with default values', () => {
99
+ const payloadWithoutDefaults = {
100
+ rewardSplitRecipients: [
101
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
102
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
103
+ ],
104
+ principalSplitRecipients: [
105
+ {
106
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
107
+ percentAllocation: 60,
108
+ },
109
+ {
110
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
111
+ percentAllocation: 40,
112
+ },
113
+ ],
114
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
115
+ };
116
+ const result = (0, ajv_1.validatePayload)(payloadWithoutDefaults, schema_1.ovmTotalSplitPayloadSchema);
117
+ expect(result).toEqual(Object.assign(Object.assign({}, payloadWithoutDefaults), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
118
+ });
119
+ it('should throw error when rewardSplitRecipients total percentage is not 99%', () => {
120
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { rewardSplitRecipients: [
121
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
122
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 40 }, // Total: 90%
123
+ ] });
124
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMRewardsSplitRecipients" keyword validation');
125
+ });
126
+ it('should throw error when principalSplitRecipients total percentage is not 100%', () => {
127
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalSplitRecipients: [
128
+ {
129
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
130
+ percentAllocation: 60,
131
+ },
132
+ {
133
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
134
+ percentAllocation: 30,
135
+ }, // Total: 90%
136
+ ] });
137
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMTotalSplitRecipients" keyword validation');
138
+ });
139
+ it('should throw error when principalSplitRecipients total percentage exceeds 100%', () => {
140
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalSplitRecipients: [
141
+ {
142
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
143
+ percentAllocation: 70,
144
+ },
145
+ {
146
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
147
+ percentAllocation: 40,
148
+ }, // Total: 110%
149
+ ] });
150
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMTotalSplitRecipients" keyword validation');
151
+ });
152
+ it('should throw error when principalSplitRecipients is empty', () => {
153
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalSplitRecipients: [] });
154
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: must pass "validateOVMTotalSplitRecipients" keyword validation');
155
+ });
156
+ it('should throw error when principalSplitRecipients has invalid address format', () => {
157
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalSplitRecipients: [
158
+ { address: 'invalid-address', percentAllocation: 60 },
159
+ {
160
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
161
+ percentAllocation: 40,
162
+ },
163
+ ] });
164
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: /principalSplitRecipients/0/address must match pattern');
165
+ });
166
+ it('should throw error when OVMOwnerAddress is missing', () => {
167
+ const invalidPayload = {
168
+ rewardSplitRecipients: validTotalSplitPayload.rewardSplitRecipients,
169
+ principalSplitRecipients: validTotalSplitPayload.principalSplitRecipients,
170
+ };
171
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow("Validation failed: must have required property 'OVMOwnerAddress'");
172
+ });
173
+ it('should throw error when principalThreshold is less than 16', () => {
174
+ const invalidPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalThreshold: 15 });
175
+ expect(() => (0, ajv_1.validatePayload)(invalidPayload, schema_1.ovmTotalSplitPayloadSchema)).toThrow('Validation failed: /principalThreshold must be >= 16');
176
+ });
177
+ it('should validate when principalThreshold is exactly 16', () => {
178
+ const validPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalThreshold: 16 });
179
+ const result = (0, ajv_1.validatePayload)(validPayload, schema_1.ovmTotalSplitPayloadSchema);
180
+ expect(result).toEqual(validPayload);
181
+ });
182
+ it('should validate when principalThreshold is greater than 16', () => {
183
+ const validPayload = Object.assign(Object.assign({}, validTotalSplitPayload), { principalThreshold: 20 });
184
+ const result = (0, ajv_1.validatePayload)(validPayload, schema_1.ovmTotalSplitPayloadSchema);
185
+ expect(result).toEqual(validPayload);
186
+ });
187
+ });
188
+ describe('Edge cases and boundary conditions', () => {
189
+ it('should handle decimal percentages correctly for rewards split', () => {
190
+ const payload = {
191
+ rewardSplitRecipients: [
192
+ {
193
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1,
194
+ percentAllocation: 49.5,
195
+ },
196
+ {
197
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2,
198
+ percentAllocation: 49.5,
199
+ },
200
+ ],
201
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
202
+ principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
203
+ };
204
+ const result = (0, ajv_1.validatePayload)(payload, schema_1.ovmRewardsSplitPayloadSchema);
205
+ expect(result).toEqual(Object.assign(Object.assign({}, payload), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
206
+ });
207
+ it('should handle decimal percentages correctly for total split', () => {
208
+ const payload = {
209
+ rewardSplitRecipients: [
210
+ {
211
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1,
212
+ percentAllocation: 49.5,
213
+ },
214
+ {
215
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2,
216
+ percentAllocation: 49.5,
217
+ },
218
+ ],
219
+ principalSplitRecipients: [
220
+ {
221
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
222
+ percentAllocation: 60.5,
223
+ },
224
+ {
225
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
226
+ percentAllocation: 39.5,
227
+ },
228
+ ],
229
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
230
+ };
231
+ const result = (0, ajv_1.validatePayload)(payload, schema_1.ovmTotalSplitPayloadSchema);
232
+ expect(result).toEqual(Object.assign(Object.assign({}, payload), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
233
+ });
234
+ it('should handle single recipient with 99% allocation for rewards split', () => {
235
+ const payload = {
236
+ rewardSplitRecipients: [
237
+ { address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 99 },
238
+ ],
239
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
240
+ principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
241
+ };
242
+ const result = (0, ajv_1.validatePayload)(payload, schema_1.ovmRewardsSplitPayloadSchema);
243
+ expect(result).toEqual(Object.assign(Object.assign({}, payload), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
244
+ });
245
+ it('should handle single recipient with 100% allocation for total split', () => {
246
+ const payload = {
247
+ rewardSplitRecipients: [
248
+ {
249
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1,
250
+ percentAllocation: 49.5,
251
+ },
252
+ {
253
+ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2,
254
+ percentAllocation: 49.5,
255
+ },
256
+ ],
257
+ principalSplitRecipients: [
258
+ {
259
+ address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
260
+ percentAllocation: 100,
261
+ },
262
+ ],
263
+ OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
264
+ };
265
+ const result = (0, ajv_1.validatePayload)(payload, schema_1.ovmTotalSplitPayloadSchema);
266
+ expect(result).toEqual(Object.assign(Object.assign({}, payload), { splitOwnerAddress: fixtures_1.TEST_ADDRESSES.ZERO_ADDRESS, principalThreshold: 16, distributorFeePercent: 0 }));
267
+ });
268
+ });
269
+ });