@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,239 @@
|
|
|
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
|
+
const src_1 = require("../../src");
|
|
13
|
+
const constants_1 = require("../../src/constants");
|
|
14
|
+
const splitHelpers_1 = require("../../src/splits/splitHelpers");
|
|
15
|
+
const utils_1 = require("../../src/utils");
|
|
16
|
+
const fixtures_1 = require("../fixtures");
|
|
17
|
+
// Mock the split helpers
|
|
18
|
+
jest.mock('../../src/splits/splitHelpers', () => ({
|
|
19
|
+
formatRecipientsForSplitV2: jest.fn(),
|
|
20
|
+
predictSplitV2Address: jest.fn(),
|
|
21
|
+
isSplitV2Deployed: jest.fn(),
|
|
22
|
+
deployOVMContract: jest.fn(),
|
|
23
|
+
deployOVMAndSplitV2: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
// Mock the utils
|
|
26
|
+
jest.mock('../../src/utils', () => ({
|
|
27
|
+
isContractAvailable: jest.fn(),
|
|
28
|
+
}));
|
|
29
|
+
// Mock the validation
|
|
30
|
+
jest.mock('../../src/ajv', () => ({
|
|
31
|
+
validatePayload: jest.fn(data => data),
|
|
32
|
+
}));
|
|
33
|
+
// Type the mocked functions
|
|
34
|
+
const mockFormatRecipientsForSplitV2 = splitHelpers_1.formatRecipientsForSplitV2;
|
|
35
|
+
const mockPredictSplitV2Address = splitHelpers_1.predictSplitV2Address;
|
|
36
|
+
const mockIsSplitV2Deployed = splitHelpers_1.isSplitV2Deployed;
|
|
37
|
+
const mockDeployOVMAndSplitV2 = splitHelpers_1.deployOVMAndSplitV2;
|
|
38
|
+
const mockDeployOVMContract = splitHelpers_1.deployOVMContract;
|
|
39
|
+
const mockIsContractAvailable = utils_1.isContractAvailable;
|
|
40
|
+
describe('ObolSplits', () => {
|
|
41
|
+
let client;
|
|
42
|
+
let mockSigner;
|
|
43
|
+
let mockProvider;
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
// Clear all mocks before each test
|
|
46
|
+
jest.clearAllMocks();
|
|
47
|
+
mockSigner = {
|
|
48
|
+
getAddress: jest
|
|
49
|
+
.fn()
|
|
50
|
+
.mockResolvedValue('0x1234567890123456789012345678901234567890'),
|
|
51
|
+
signTypedData: jest.fn().mockResolvedValue('0xsigned'),
|
|
52
|
+
provider: {
|
|
53
|
+
getCode: jest.fn().mockResolvedValue('0x123456'),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
mockProvider = {
|
|
57
|
+
getCode: jest.fn().mockResolvedValue('0x123456'),
|
|
58
|
+
};
|
|
59
|
+
client = new src_1.Client({ chainId: 1 }, mockSigner, mockProvider);
|
|
60
|
+
});
|
|
61
|
+
describe('createValidatorManagerAndRewardsSplit', () => {
|
|
62
|
+
const mockRewardsSplitPayload = {
|
|
63
|
+
rewardSplitRecipients: [
|
|
64
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
|
|
65
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
|
|
66
|
+
],
|
|
67
|
+
OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
|
|
68
|
+
splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
|
|
69
|
+
principalRecipient: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT,
|
|
70
|
+
distributorFeePercent: 0,
|
|
71
|
+
};
|
|
72
|
+
it('should create rewards-only split successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
// Mock helper functions
|
|
74
|
+
mockFormatRecipientsForSplitV2.mockReturnValue([
|
|
75
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
|
|
76
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
|
|
77
|
+
{
|
|
78
|
+
address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
|
|
79
|
+
percentAllocation: 1,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
mockPredictSplitV2Address.mockResolvedValue('0xRewardsSplitAddress');
|
|
83
|
+
mockIsSplitV2Deployed.mockResolvedValue(false);
|
|
84
|
+
mockDeployOVMAndSplitV2.mockResolvedValue('0xOVMAddress');
|
|
85
|
+
mockIsContractAvailable.mockResolvedValue(true);
|
|
86
|
+
const result = yield client.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload);
|
|
87
|
+
expect(result).toEqual({
|
|
88
|
+
withdrawal_address: '0xOVMAddress',
|
|
89
|
+
fee_recipient_address: '0xRewardsSplitAddress',
|
|
90
|
+
});
|
|
91
|
+
expect(mockFormatRecipientsForSplitV2).toHaveBeenCalled();
|
|
92
|
+
expect(mockPredictSplitV2Address).toHaveBeenCalled();
|
|
93
|
+
expect(mockIsSplitV2Deployed).toHaveBeenCalled();
|
|
94
|
+
expect(mockDeployOVMAndSplitV2).toHaveBeenCalled();
|
|
95
|
+
}));
|
|
96
|
+
it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
|
|
98
|
+
yield expect(clientWithoutSigner.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('Signer is required in createValidatorManagerAndRewardsSplit');
|
|
99
|
+
}));
|
|
100
|
+
it('should throw error when chain is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const clientUnsupportedChain = new src_1.Client({ chainId: 999 }, mockSigner, mockProvider);
|
|
102
|
+
yield expect(clientUnsupportedChain.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('Splitter configuration is not supported on 999 chain');
|
|
103
|
+
}));
|
|
104
|
+
it('should throw error when OVM factory is not configured', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
// Mock chain configuration without OVM factory
|
|
106
|
+
const originalConfig = constants_1.CHAIN_CONFIGURATION[1];
|
|
107
|
+
// Create a new config object without OVM_FACTORY_CONTRACT
|
|
108
|
+
const configWithoutOVM = Object.assign({}, originalConfig);
|
|
109
|
+
delete configWithoutOVM.OVM_FACTORY_CONTRACT;
|
|
110
|
+
constants_1.CHAIN_CONFIGURATION[1] = configWithoutOVM;
|
|
111
|
+
yield expect(client.splits.createValidatorManagerAndRewardsSplit(mockRewardsSplitPayload)).rejects.toThrow('OVM contract factory is not configured for chain 1');
|
|
112
|
+
// Restore original config
|
|
113
|
+
constants_1.CHAIN_CONFIGURATION[1] = originalConfig;
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
116
|
+
describe('createValidatorManagerAndTotalSplit', () => {
|
|
117
|
+
const mockTotalSplitPayload = {
|
|
118
|
+
rewardSplitRecipients: [
|
|
119
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
|
|
120
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
|
|
121
|
+
],
|
|
122
|
+
principalSplitRecipients: [
|
|
123
|
+
{
|
|
124
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
|
|
125
|
+
percentAllocation: 60,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
|
|
129
|
+
percentAllocation: 40,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
OVMOwnerAddress: fixtures_1.TEST_ADDRESSES.OVM_OWNER,
|
|
133
|
+
splitOwnerAddress: fixtures_1.TEST_ADDRESSES.SPLIT_OWNER,
|
|
134
|
+
distributorFeePercent: 0,
|
|
135
|
+
};
|
|
136
|
+
it('should create total split successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
// Mock helper functions
|
|
138
|
+
mockFormatRecipientsForSplitV2
|
|
139
|
+
.mockReturnValueOnce([
|
|
140
|
+
// rewards recipients
|
|
141
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
|
|
142
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
|
|
143
|
+
{
|
|
144
|
+
address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
|
|
145
|
+
percentAllocation: 1,
|
|
146
|
+
},
|
|
147
|
+
])
|
|
148
|
+
.mockReturnValueOnce([
|
|
149
|
+
// principal recipients
|
|
150
|
+
{
|
|
151
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
|
|
152
|
+
percentAllocation: 60,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
|
|
156
|
+
percentAllocation: 40,
|
|
157
|
+
},
|
|
158
|
+
]);
|
|
159
|
+
mockPredictSplitV2Address
|
|
160
|
+
.mockResolvedValueOnce('0xRewardsSplitAddress')
|
|
161
|
+
.mockResolvedValueOnce('0xPrincipalSplitAddress');
|
|
162
|
+
mockIsSplitV2Deployed
|
|
163
|
+
.mockResolvedValueOnce(false) // rewards split not deployed
|
|
164
|
+
.mockResolvedValueOnce(false); // principal split not deployed
|
|
165
|
+
mockDeployOVMAndSplitV2.mockResolvedValue('0xOVMAddress');
|
|
166
|
+
mockIsContractAvailable.mockResolvedValue(true);
|
|
167
|
+
const result = yield client.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload);
|
|
168
|
+
expect(result).toEqual({
|
|
169
|
+
withdrawal_address: '0xOVMAddress',
|
|
170
|
+
fee_recipient_address: '0xRewardsSplitAddress',
|
|
171
|
+
});
|
|
172
|
+
expect(mockFormatRecipientsForSplitV2).toHaveBeenCalledTimes(2);
|
|
173
|
+
expect(mockPredictSplitV2Address).toHaveBeenCalledTimes(2);
|
|
174
|
+
expect(mockIsSplitV2Deployed).toHaveBeenCalledTimes(2);
|
|
175
|
+
expect(mockDeployOVMAndSplitV2).toHaveBeenCalled();
|
|
176
|
+
}));
|
|
177
|
+
it('should handle case when both splits are already deployed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
// Mock helper functions
|
|
179
|
+
mockFormatRecipientsForSplitV2
|
|
180
|
+
.mockReturnValueOnce([
|
|
181
|
+
// rewards recipients
|
|
182
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_1, percentAllocation: 50 },
|
|
183
|
+
{ address: fixtures_1.TEST_ADDRESSES.REWARD_RECIPIENT_2, percentAllocation: 49 },
|
|
184
|
+
{
|
|
185
|
+
address: '0xDe5aE4De36c966747Ea7DF13BD9589642e2B1D0d',
|
|
186
|
+
percentAllocation: 1,
|
|
187
|
+
},
|
|
188
|
+
])
|
|
189
|
+
.mockReturnValueOnce([
|
|
190
|
+
// principal recipients
|
|
191
|
+
{
|
|
192
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_1,
|
|
193
|
+
percentAllocation: 60,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
address: fixtures_1.TEST_ADDRESSES.PRINCIPAL_RECIPIENT_2,
|
|
197
|
+
percentAllocation: 40,
|
|
198
|
+
},
|
|
199
|
+
]);
|
|
200
|
+
mockPredictSplitV2Address
|
|
201
|
+
.mockResolvedValueOnce('0xRewardsSplitAddress')
|
|
202
|
+
.mockResolvedValueOnce('0xPrincipalSplitAddress');
|
|
203
|
+
mockIsSplitV2Deployed
|
|
204
|
+
.mockResolvedValueOnce(true) // rewards split deployed
|
|
205
|
+
.mockResolvedValueOnce(true); // principal split deployed
|
|
206
|
+
mockDeployOVMContract.mockResolvedValue('0xOVMAddress');
|
|
207
|
+
mockIsContractAvailable.mockResolvedValue(true);
|
|
208
|
+
const result = yield client.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload);
|
|
209
|
+
expect(result).toEqual({
|
|
210
|
+
withdrawal_address: '0xOVMAddress',
|
|
211
|
+
fee_recipient_address: '0xRewardsSplitAddress',
|
|
212
|
+
});
|
|
213
|
+
expect(mockDeployOVMContract).toHaveBeenCalledWith({
|
|
214
|
+
OVMOwnerAddress: mockTotalSplitPayload.OVMOwnerAddress,
|
|
215
|
+
principalRecipient: '0xPrincipalSplitAddress',
|
|
216
|
+
rewardRecipient: '0xRewardsSplitAddress',
|
|
217
|
+
principalThreshold: mockTotalSplitPayload.principalThreshold,
|
|
218
|
+
signer: mockSigner,
|
|
219
|
+
chainId: 1,
|
|
220
|
+
});
|
|
221
|
+
}));
|
|
222
|
+
it('should throw error when signer is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
+
const clientWithoutSigner = new src_1.Client({ chainId: 1 }, undefined, mockProvider);
|
|
224
|
+
yield expect(clientWithoutSigner.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload)).rejects.toThrow('Signer is required in createValidatorManagerAndTotalSplit');
|
|
225
|
+
}));
|
|
226
|
+
it('should throw error when chain is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
227
|
+
const clientUnsupportedChain = new src_1.Client({ chainId: 999 }, mockSigner, mockProvider);
|
|
228
|
+
yield expect(clientUnsupportedChain.splits.createValidatorManagerAndTotalSplit(mockTotalSplitPayload)).rejects.toThrow('Splitter configuration is not supported on 999 chain');
|
|
229
|
+
}));
|
|
230
|
+
});
|
|
231
|
+
describe('constructor', () => {
|
|
232
|
+
it('should create Client instance with splits property', () => {
|
|
233
|
+
const testClient = new src_1.Client({ chainId: 1 }, mockSigner, mockProvider);
|
|
234
|
+
expect(testClient.splits).toBeDefined();
|
|
235
|
+
expect(testClient.splits.chainId).toBe(1);
|
|
236
|
+
expect(testClient.splits.provider).toBe(mockProvider);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
package/dist/esm/package.json
CHANGED