@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,417 @@
1
+ export const splitV2FactoryAbi = [
2
+ {
3
+ inputs: [
4
+ {
5
+ internalType: 'address',
6
+ name: '_splitsWarehouse',
7
+ type: 'address',
8
+ },
9
+ ],
10
+ stateMutability: 'nonpayable',
11
+ type: 'constructor',
12
+ },
13
+ {
14
+ anonymous: false,
15
+ inputs: [
16
+ {
17
+ indexed: true,
18
+ internalType: 'address',
19
+ name: 'split',
20
+ type: 'address',
21
+ },
22
+ {
23
+ components: [
24
+ {
25
+ internalType: 'address[]',
26
+ name: 'recipients',
27
+ type: 'address[]',
28
+ },
29
+ {
30
+ internalType: 'uint256[]',
31
+ name: 'allocations',
32
+ type: 'uint256[]',
33
+ },
34
+ {
35
+ internalType: 'uint256',
36
+ name: 'totalAllocation',
37
+ type: 'uint256',
38
+ },
39
+ {
40
+ internalType: 'uint16',
41
+ name: 'distributionIncentive',
42
+ type: 'uint16',
43
+ },
44
+ ],
45
+ indexed: false,
46
+ internalType: 'struct SplitV2Lib.Split',
47
+ name: 'splitParams',
48
+ type: 'tuple',
49
+ },
50
+ {
51
+ indexed: false,
52
+ internalType: 'address',
53
+ name: 'owner',
54
+ type: 'address',
55
+ },
56
+ {
57
+ indexed: false,
58
+ internalType: 'address',
59
+ name: 'creator',
60
+ type: 'address',
61
+ },
62
+ {
63
+ indexed: false,
64
+ internalType: 'bytes32',
65
+ name: 'salt',
66
+ type: 'bytes32',
67
+ },
68
+ ],
69
+ name: 'SplitCreated',
70
+ type: 'event',
71
+ },
72
+ {
73
+ anonymous: false,
74
+ inputs: [
75
+ {
76
+ indexed: true,
77
+ internalType: 'address',
78
+ name: 'split',
79
+ type: 'address',
80
+ },
81
+ {
82
+ components: [
83
+ {
84
+ internalType: 'address[]',
85
+ name: 'recipients',
86
+ type: 'address[]',
87
+ },
88
+ {
89
+ internalType: 'uint256[]',
90
+ name: 'allocations',
91
+ type: 'uint256[]',
92
+ },
93
+ {
94
+ internalType: 'uint256',
95
+ name: 'totalAllocation',
96
+ type: 'uint256',
97
+ },
98
+ {
99
+ internalType: 'uint16',
100
+ name: 'distributionIncentive',
101
+ type: 'uint16',
102
+ },
103
+ ],
104
+ indexed: false,
105
+ internalType: 'struct SplitV2Lib.Split',
106
+ name: 'splitParams',
107
+ type: 'tuple',
108
+ },
109
+ {
110
+ indexed: false,
111
+ internalType: 'address',
112
+ name: 'owner',
113
+ type: 'address',
114
+ },
115
+ {
116
+ indexed: false,
117
+ internalType: 'address',
118
+ name: 'creator',
119
+ type: 'address',
120
+ },
121
+ ],
122
+ name: 'SplitCreated',
123
+ type: 'event',
124
+ },
125
+ {
126
+ inputs: [],
127
+ name: 'SPLIT_WALLET_IMPLEMENTATION',
128
+ outputs: [
129
+ {
130
+ internalType: 'address',
131
+ name: '',
132
+ type: 'address',
133
+ },
134
+ ],
135
+ stateMutability: 'view',
136
+ type: 'function',
137
+ },
138
+ {
139
+ inputs: [
140
+ {
141
+ components: [
142
+ {
143
+ internalType: 'address[]',
144
+ name: 'recipients',
145
+ type: 'address[]',
146
+ },
147
+ {
148
+ internalType: 'uint256[]',
149
+ name: 'allocations',
150
+ type: 'uint256[]',
151
+ },
152
+ {
153
+ internalType: 'uint256',
154
+ name: 'totalAllocation',
155
+ type: 'uint256',
156
+ },
157
+ {
158
+ internalType: 'uint16',
159
+ name: 'distributionIncentive',
160
+ type: 'uint16',
161
+ },
162
+ ],
163
+ internalType: 'struct SplitV2Lib.Split',
164
+ name: '_splitParams',
165
+ type: 'tuple',
166
+ },
167
+ {
168
+ internalType: 'address',
169
+ name: '_owner',
170
+ type: 'address',
171
+ },
172
+ {
173
+ internalType: 'address',
174
+ name: '_creator',
175
+ type: 'address',
176
+ },
177
+ ],
178
+ name: 'createSplit',
179
+ outputs: [
180
+ {
181
+ internalType: 'address',
182
+ name: 'split',
183
+ type: 'address',
184
+ },
185
+ ],
186
+ stateMutability: 'nonpayable',
187
+ type: 'function',
188
+ },
189
+ {
190
+ inputs: [
191
+ {
192
+ components: [
193
+ {
194
+ internalType: 'address[]',
195
+ name: 'recipients',
196
+ type: 'address[]',
197
+ },
198
+ {
199
+ internalType: 'uint256[]',
200
+ name: 'allocations',
201
+ type: 'uint256[]',
202
+ },
203
+ {
204
+ internalType: 'uint256',
205
+ name: 'totalAllocation',
206
+ type: 'uint256',
207
+ },
208
+ {
209
+ internalType: 'uint16',
210
+ name: 'distributionIncentive',
211
+ type: 'uint16',
212
+ },
213
+ ],
214
+ internalType: 'struct SplitV2Lib.Split',
215
+ name: '_splitParams',
216
+ type: 'tuple',
217
+ },
218
+ {
219
+ internalType: 'address',
220
+ name: '_owner',
221
+ type: 'address',
222
+ },
223
+ {
224
+ internalType: 'address',
225
+ name: '_creator',
226
+ type: 'address',
227
+ },
228
+ {
229
+ internalType: 'bytes32',
230
+ name: '_salt',
231
+ type: 'bytes32',
232
+ },
233
+ ],
234
+ name: 'createSplitDeterministic',
235
+ outputs: [
236
+ {
237
+ internalType: 'address',
238
+ name: 'split',
239
+ type: 'address',
240
+ },
241
+ ],
242
+ stateMutability: 'nonpayable',
243
+ type: 'function',
244
+ },
245
+ {
246
+ inputs: [
247
+ {
248
+ components: [
249
+ {
250
+ internalType: 'address[]',
251
+ name: 'recipients',
252
+ type: 'address[]',
253
+ },
254
+ {
255
+ internalType: 'uint256[]',
256
+ name: 'allocations',
257
+ type: 'uint256[]',
258
+ },
259
+ {
260
+ internalType: 'uint256',
261
+ name: 'totalAllocation',
262
+ type: 'uint256',
263
+ },
264
+ {
265
+ internalType: 'uint16',
266
+ name: 'distributionIncentive',
267
+ type: 'uint16',
268
+ },
269
+ ],
270
+ internalType: 'struct SplitV2Lib.Split',
271
+ name: '_splitParams',
272
+ type: 'tuple',
273
+ },
274
+ {
275
+ internalType: 'address',
276
+ name: '_owner',
277
+ type: 'address',
278
+ },
279
+ {
280
+ internalType: 'bytes32',
281
+ name: '_salt',
282
+ type: 'bytes32',
283
+ },
284
+ ],
285
+ name: 'isDeployed',
286
+ outputs: [
287
+ {
288
+ internalType: 'address',
289
+ name: 'split',
290
+ type: 'address',
291
+ },
292
+ {
293
+ internalType: 'bool',
294
+ name: 'exists',
295
+ type: 'bool',
296
+ },
297
+ ],
298
+ stateMutability: 'view',
299
+ type: 'function',
300
+ },
301
+ {
302
+ inputs: [
303
+ {
304
+ internalType: 'bytes32',
305
+ name: '_hash',
306
+ type: 'bytes32',
307
+ },
308
+ ],
309
+ name: 'nonces',
310
+ outputs: [
311
+ {
312
+ internalType: 'uint256',
313
+ name: '',
314
+ type: 'uint256',
315
+ },
316
+ ],
317
+ stateMutability: 'view',
318
+ type: 'function',
319
+ },
320
+ {
321
+ inputs: [
322
+ {
323
+ components: [
324
+ {
325
+ internalType: 'address[]',
326
+ name: 'recipients',
327
+ type: 'address[]',
328
+ },
329
+ {
330
+ internalType: 'uint256[]',
331
+ name: 'allocations',
332
+ type: 'uint256[]',
333
+ },
334
+ {
335
+ internalType: 'uint256',
336
+ name: 'totalAllocation',
337
+ type: 'uint256',
338
+ },
339
+ {
340
+ internalType: 'uint16',
341
+ name: 'distributionIncentive',
342
+ type: 'uint16',
343
+ },
344
+ ],
345
+ internalType: 'struct SplitV2Lib.Split',
346
+ name: '_splitParams',
347
+ type: 'tuple',
348
+ },
349
+ {
350
+ internalType: 'address',
351
+ name: '_owner',
352
+ type: 'address',
353
+ },
354
+ ],
355
+ name: 'predictDeterministicAddress',
356
+ outputs: [
357
+ {
358
+ internalType: 'address',
359
+ name: '',
360
+ type: 'address',
361
+ },
362
+ ],
363
+ stateMutability: 'view',
364
+ type: 'function',
365
+ },
366
+ {
367
+ inputs: [
368
+ {
369
+ components: [
370
+ {
371
+ internalType: 'address[]',
372
+ name: 'recipients',
373
+ type: 'address[]',
374
+ },
375
+ {
376
+ internalType: 'uint256[]',
377
+ name: 'allocations',
378
+ type: 'uint256[]',
379
+ },
380
+ {
381
+ internalType: 'uint256',
382
+ name: 'totalAllocation',
383
+ type: 'uint256',
384
+ },
385
+ {
386
+ internalType: 'uint16',
387
+ name: 'distributionIncentive',
388
+ type: 'uint16',
389
+ },
390
+ ],
391
+ internalType: 'struct SplitV2Lib.Split',
392
+ name: '_splitParams',
393
+ type: 'tuple',
394
+ },
395
+ {
396
+ internalType: 'address',
397
+ name: '_owner',
398
+ type: 'address',
399
+ },
400
+ {
401
+ internalType: 'bytes32',
402
+ name: '_salt',
403
+ type: 'bytes32',
404
+ },
405
+ ],
406
+ name: 'predictDeterministicAddress',
407
+ outputs: [
408
+ {
409
+ internalType: 'address',
410
+ name: '',
411
+ type: 'address',
412
+ },
413
+ ],
414
+ stateMutability: 'view',
415
+ type: 'function',
416
+ },
417
+ ];
package/src/ajv.ts CHANGED
@@ -2,8 +2,9 @@ import addFormats from 'ajv-formats';
2
2
  import addKeywords from 'ajv-keywords';
3
3
  import { parseUnits } from 'ethers';
4
4
  import {
5
+ type OVMRewardsSplitPayload,
6
+ type OVMTotalSplitPayload,
5
7
  type RewardsSplitPayload,
6
- type SplitRecipient,
7
8
  type TotalSplitPayload,
8
9
  } from './types';
9
10
  import Ajv from 'ajv';
@@ -24,18 +25,31 @@ export const VALID_NON_COMPOUNDING_AMOUNTS = [
24
25
  parseUnits('32', 'gwei').toString(),
25
26
  ];
26
27
 
27
- // They dont see defaults set in schema
28
+ const calculateTotalPercentage = (
29
+ recipients: Array<{ percentAllocation: number }>,
30
+ ): number => {
31
+ return recipients.reduce((acc, curr) => acc + curr.percentAllocation, 0);
32
+ };
33
+
34
+ const validateTotalPercentage = (totalPercentage: number): boolean => {
35
+ return totalPercentage === 100;
36
+ };
37
+
38
+ const validateTotalPercentageWithRAF = (
39
+ totalPercentage: number,
40
+ rafPercentage: number,
41
+ ): boolean => {
42
+ return totalPercentage + rafPercentage === 100;
43
+ };
44
+
28
45
  const validateRewardsSplitRecipients = (
29
46
  _: boolean,
30
47
  data: RewardsSplitPayload,
31
48
  ): boolean => {
32
49
  const obolRAFSplit =
33
- data.ObolRAFSplit ?? DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT;
34
- const splitPercentage = data.splitRecipients.reduce(
35
- (acc: number, curr: SplitRecipient) => acc + curr.percentAllocation,
36
- 0,
37
- );
38
- return splitPercentage + obolRAFSplit === 100;
50
+ data?.ObolRAFSplit ?? DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT;
51
+ const splitPercentage = calculateTotalPercentage(data.splitRecipients);
52
+ return validateTotalPercentageWithRAF(splitPercentage, obolRAFSplit);
39
53
  };
40
54
 
41
55
  const validateTotalSplitRecipients = (
@@ -44,11 +58,8 @@ const validateTotalSplitRecipients = (
44
58
  ): boolean => {
45
59
  const obolRAFSplit =
46
60
  data.ObolRAFSplit ?? DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT;
47
- const splitPercentage = data.splitRecipients.reduce(
48
- (acc: number, curr: SplitRecipient) => acc + curr.percentAllocation,
49
- 0,
50
- );
51
- return splitPercentage + obolRAFSplit === 100;
61
+ const splitPercentage = calculateTotalPercentage(data.splitRecipients);
62
+ return validateTotalPercentageWithRAF(splitPercentage, obolRAFSplit);
52
63
  };
53
64
 
54
65
  const validateUniqueAddresses = (
@@ -77,6 +88,25 @@ const validateUniqueAddresses = (
77
88
  return isUnique;
78
89
  };
79
90
 
91
+ const validateOVMRewardsSplitRecipients = (
92
+ _: boolean,
93
+ data: OVMRewardsSplitPayload,
94
+ ): boolean => {
95
+ const obolRAFSplit = DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT;
96
+ const splitPercentage = calculateTotalPercentage(data.rewardSplitRecipients);
97
+ return validateTotalPercentageWithRAF(splitPercentage, obolRAFSplit);
98
+ };
99
+
100
+ const validateOVMTotalSplitRecipients = (
101
+ _: boolean,
102
+ data: OVMTotalSplitPayload,
103
+ ): boolean => {
104
+ const splitPercentage = calculateTotalPercentage(
105
+ data.principalSplitRecipients,
106
+ );
107
+ return validateTotalPercentage(splitPercentage);
108
+ };
109
+
80
110
  const ajv = new Ajv({
81
111
  allErrors: true,
82
112
  useDefaults: true,
@@ -104,6 +134,18 @@ ajv.addKeyword({
104
134
  schemaType: 'boolean',
105
135
  });
106
136
 
137
+ ajv.addKeyword({
138
+ keyword: 'validateOVMRewardsSplitRecipients',
139
+ validate: validateOVMRewardsSplitRecipients,
140
+ schemaType: 'boolean',
141
+ });
142
+
143
+ ajv.addKeyword({
144
+ keyword: 'validateOVMTotalSplitRecipients',
145
+ validate: validateOVMTotalSplitRecipients,
146
+ schemaType: 'boolean',
147
+ });
148
+
107
149
  export function validatePayload<T>(data: unknown, schema: object): T {
108
150
  const validate = ajv.compile<T>(schema);
109
151
  const valid = validate(data);