@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
|
@@ -0,0 +1,261 @@
|
|
|
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_ADDRESS)) {
|
|
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_ADDRESS;
|
|
67
|
+
if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) || !(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode)) {
|
|
68
|
+
throw new Error(`OVM factory contract configuration is incomplete for chain ${this.chainId}`);
|
|
69
|
+
}
|
|
70
|
+
const checkOVMFactoryAddress = yield (0, utils_1.isContractAvailable)(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
|
|
71
|
+
if (!checkOVMFactoryAddress) {
|
|
72
|
+
throw new Error(`OVM factory contract is not deployed or available on chain ${this.chainId}`);
|
|
73
|
+
}
|
|
74
|
+
const retroActiveFundingRecipient = {
|
|
75
|
+
address: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
|
|
76
|
+
percentAllocation: constants_1.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
|
|
77
|
+
};
|
|
78
|
+
const copiedRewardsSplitRecipients = [
|
|
79
|
+
...validatedPayload.rewardSplitRecipients,
|
|
80
|
+
];
|
|
81
|
+
copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
|
|
82
|
+
// Format recipients for SplitV2
|
|
83
|
+
const rewardRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(copiedRewardsSplitRecipients);
|
|
84
|
+
const predictedSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
|
|
85
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
86
|
+
recipients: rewardRecipients,
|
|
87
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
88
|
+
salt,
|
|
89
|
+
signer: this.signer,
|
|
90
|
+
chainId: this.chainId,
|
|
91
|
+
});
|
|
92
|
+
const isRewardSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
|
|
93
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
94
|
+
recipients: rewardRecipients,
|
|
95
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
96
|
+
salt,
|
|
97
|
+
signer: this.signer,
|
|
98
|
+
chainId: this.chainId,
|
|
99
|
+
});
|
|
100
|
+
if (isRewardSplitterDeployed) {
|
|
101
|
+
const ovmAddress = yield (0, splitHelpers_1.deployOVMContract)({
|
|
102
|
+
OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
|
|
103
|
+
principalRecipient: validatedPayload.principalRecipient,
|
|
104
|
+
rewardRecipient: predictedSplitAddress,
|
|
105
|
+
principalThreshold: validatedPayload.principalThreshold,
|
|
106
|
+
signer: this.signer,
|
|
107
|
+
chainId: this.chainId,
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
withdrawal_address: ovmAddress,
|
|
111
|
+
fee_recipient_address: predictedSplitAddress,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const ovmAddress = yield (0, splitHelpers_1.deployOVMAndSplitV2)({
|
|
116
|
+
ovmArgs: {
|
|
117
|
+
OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
|
|
118
|
+
rewardRecipient: predictedSplitAddress,
|
|
119
|
+
principalRecipient: validatedPayload.principalRecipient,
|
|
120
|
+
principalThreshold: validatedPayload.principalThreshold,
|
|
121
|
+
},
|
|
122
|
+
rewardRecipients,
|
|
123
|
+
isRewardsSplitterDeployed: isRewardSplitterDeployed,
|
|
124
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
125
|
+
salt,
|
|
126
|
+
signer: this.signer,
|
|
127
|
+
chainId: this.chainId,
|
|
128
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
withdrawal_address: ovmAddress,
|
|
132
|
+
fee_recipient_address: predictedSplitAddress,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates an Obol OVM and Total split configuration for total split scenario.
|
|
139
|
+
*
|
|
140
|
+
* This method deploys OVM and SplitV2 contracts for managing both validator rewards and principal.
|
|
141
|
+
* Both rewards and principal are split among recipients, with rewards including RAF recipient.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
|
|
145
|
+
* and not pushed to version control.
|
|
146
|
+
*
|
|
147
|
+
* @param {OVMTotalSplitPayload} payload - Data needed to deploy OVM and SplitV2
|
|
148
|
+
* @returns {Promise<ClusterValidator>} OVM address as withdrawal address and splitter as fee recipient
|
|
149
|
+
* @throws Will throw an error if the splitter configuration is not supported or deployment fails
|
|
150
|
+
*
|
|
151
|
+
* An example of how to use createValidatorManagerAndTotalSplit:
|
|
152
|
+
* [createValidatorManagerAndTotalSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#340)
|
|
153
|
+
*/
|
|
154
|
+
createValidatorManagerAndTotalSplit(payload) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const salt = constants_1.SPLITS_V2_SALT;
|
|
157
|
+
if (!this.signer) {
|
|
158
|
+
throw new Error('Signer is required in createValidatorManagerAndTotalSplit');
|
|
159
|
+
}
|
|
160
|
+
const validatedPayload = (0, ajv_1.validatePayload)(payload, schema_1.ovmTotalSplitPayloadSchema);
|
|
161
|
+
if (!(0, constants_1.isChainSupportedForSplitters)(this.chainId)) {
|
|
162
|
+
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
|
|
163
|
+
}
|
|
164
|
+
const chainConfig = constants_1.CHAIN_CONFIGURATION[this.chainId];
|
|
165
|
+
if (!(chainConfig === null || chainConfig === void 0 ? void 0 : chainConfig.OVM_FACTORY_ADDRESS)) {
|
|
166
|
+
throw new Error(`OVM contract factory is not configured for chain ${this.chainId}`);
|
|
167
|
+
}
|
|
168
|
+
if (!this.provider) {
|
|
169
|
+
throw new Error('Provider is required to check OVM factory contract availability');
|
|
170
|
+
}
|
|
171
|
+
const ovmFactoryConfig = chainConfig.OVM_FACTORY_ADDRESS;
|
|
172
|
+
if (!(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.address) || !(ovmFactoryConfig === null || ovmFactoryConfig === void 0 ? void 0 : ovmFactoryConfig.bytecode)) {
|
|
173
|
+
throw new Error(`OVM factory contract configuration is incomplete for chain ${this.chainId}`);
|
|
174
|
+
}
|
|
175
|
+
const checkOVMFactoryAddress = yield (0, utils_1.isContractAvailable)(ovmFactoryConfig.address, this.provider, ovmFactoryConfig.bytecode);
|
|
176
|
+
if (!checkOVMFactoryAddress) {
|
|
177
|
+
throw new Error(`OVM factory contract is not deployed or available on chain ${this.chainId}`);
|
|
178
|
+
}
|
|
179
|
+
const retroActiveFundingRecipient = {
|
|
180
|
+
address: chainConfig.RETROACTIVE_FUNDING_ADDRESS.address,
|
|
181
|
+
percentAllocation: constants_1.DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
|
|
182
|
+
};
|
|
183
|
+
const copiedRewardsSplitRecipients = [
|
|
184
|
+
...validatedPayload.rewardSplitRecipients,
|
|
185
|
+
];
|
|
186
|
+
copiedRewardsSplitRecipients.push(retroActiveFundingRecipient);
|
|
187
|
+
const rewardsRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(copiedRewardsSplitRecipients);
|
|
188
|
+
const principalSplitRecipients = (0, splitHelpers_1.formatRecipientsForSplitV2)(validatedPayload.principalSplitRecipients);
|
|
189
|
+
const predictedRewardsSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
|
|
190
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
191
|
+
recipients: rewardsRecipients,
|
|
192
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
193
|
+
salt,
|
|
194
|
+
signer: this.signer,
|
|
195
|
+
chainId: this.chainId,
|
|
196
|
+
});
|
|
197
|
+
const predictedPrincipalSplitAddress = yield (0, splitHelpers_1.predictSplitV2Address)({
|
|
198
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
199
|
+
recipients: principalSplitRecipients,
|
|
200
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
201
|
+
salt,
|
|
202
|
+
signer: this.signer,
|
|
203
|
+
chainId: this.chainId,
|
|
204
|
+
});
|
|
205
|
+
const isRewardsSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
|
|
206
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
207
|
+
recipients: rewardsRecipients,
|
|
208
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
209
|
+
salt,
|
|
210
|
+
signer: this.signer,
|
|
211
|
+
chainId: this.chainId,
|
|
212
|
+
});
|
|
213
|
+
const isPrincipalSplitterDeployed = yield (0, splitHelpers_1.isSplitV2Deployed)({
|
|
214
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
215
|
+
recipients: principalSplitRecipients,
|
|
216
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
217
|
+
salt,
|
|
218
|
+
signer: this.signer,
|
|
219
|
+
chainId: this.chainId,
|
|
220
|
+
});
|
|
221
|
+
if (isRewardsSplitterDeployed && isPrincipalSplitterDeployed) {
|
|
222
|
+
const ovmAddress = yield (0, splitHelpers_1.deployOVMContract)({
|
|
223
|
+
OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
|
|
224
|
+
principalRecipient: predictedPrincipalSplitAddress,
|
|
225
|
+
rewardRecipient: predictedRewardsSplitAddress,
|
|
226
|
+
principalThreshold: validatedPayload.principalThreshold,
|
|
227
|
+
signer: this.signer,
|
|
228
|
+
chainId: this.chainId,
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
withdrawal_address: ovmAddress,
|
|
232
|
+
fee_recipient_address: predictedRewardsSplitAddress,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Use multicall to deploy any contracts that aren't deployed
|
|
237
|
+
const ovmAddress = yield (0, splitHelpers_1.deployOVMAndSplitV2)({
|
|
238
|
+
ovmArgs: {
|
|
239
|
+
OVMOwnerAddress: validatedPayload.OVMOwnerAddress,
|
|
240
|
+
rewardRecipient: predictedRewardsSplitAddress,
|
|
241
|
+
principalRecipient: predictedPrincipalSplitAddress,
|
|
242
|
+
principalThreshold: validatedPayload.principalThreshold,
|
|
243
|
+
},
|
|
244
|
+
rewardRecipients: rewardsRecipients,
|
|
245
|
+
distributorFeePercent: validatedPayload.distributorFeePercent,
|
|
246
|
+
salt,
|
|
247
|
+
signer: this.signer,
|
|
248
|
+
chainId: this.chainId,
|
|
249
|
+
principalSplitRecipients,
|
|
250
|
+
isPrincipalSplitDeployed: isPrincipalSplitterDeployed,
|
|
251
|
+
splitOwnerAddress: validatedPayload.splitOwnerAddress,
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
withdrawal_address: ovmAddress,
|
|
255
|
+
fee_recipient_address: predictedRewardsSplitAddress,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.ObolSplits = ObolSplits;
|
package/dist/cjs/src/types.js
CHANGED
|
@@ -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
|
+
});
|