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