@obolnetwork/obol-sdk 2.5.1 → 2.7.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.
Files changed (56) hide show
  1. package/dist/cjs/package.json +3 -3
  2. package/dist/cjs/src/constants.js +13 -1
  3. package/dist/cjs/src/exits/ethUtils.js +57 -0
  4. package/dist/cjs/src/exits/exit.js +502 -0
  5. package/dist/cjs/src/exits/verificationHelpers.js +86 -0
  6. package/dist/cjs/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
  7. package/dist/cjs/src/{incentives.js → incentives/incentives.js} +3 -3
  8. package/dist/cjs/src/index.js +22 -4
  9. package/dist/cjs/src/splits/splitHelpers.js +327 -0
  10. package/dist/cjs/src/types.js +1 -0
  11. package/dist/cjs/test/exit/ethUtils.spec.js +83 -0
  12. package/dist/cjs/test/exit/exit.spec.js +399 -0
  13. package/dist/cjs/test/exit/verificationHelpers.spec.js +68 -0
  14. package/dist/cjs/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
  15. package/dist/esm/package.json +3 -3
  16. package/dist/esm/src/constants.js +12 -0
  17. package/dist/esm/src/exits/ethUtils.js +52 -0
  18. package/dist/esm/src/exits/exit.js +475 -0
  19. package/dist/esm/src/exits/verificationHelpers.js +81 -0
  20. package/dist/esm/src/{incentiveHelpers.js → incentives/incentiveHelpers.js} +1 -1
  21. package/dist/esm/src/{incentives.js → incentives/incentives.js} +3 -3
  22. package/dist/esm/src/index.js +20 -3
  23. package/dist/esm/src/splits/splitHelpers.js +317 -0
  24. package/dist/esm/src/types.js +1 -0
  25. package/dist/esm/test/exit/ethUtils.spec.js +81 -0
  26. package/dist/esm/test/exit/exit.spec.js +374 -0
  27. package/dist/esm/test/exit/verificationHelpers.spec.js +66 -0
  28. package/dist/esm/test/{incentives.test.js → incentives/incentives.spec.js} +4 -4
  29. package/dist/types/src/constants.d.ts +5 -0
  30. package/dist/types/src/exits/ethUtils.d.ts +13 -0
  31. package/dist/types/src/exits/exit.d.ts +200 -0
  32. package/dist/types/src/exits/verificationHelpers.d.ts +20 -0
  33. package/dist/types/src/{incentiveHelpers.d.ts → incentives/incentiveHelpers.d.ts} +1 -1
  34. package/dist/types/src/{incentives.d.ts → incentives/incentives.d.ts} +1 -1
  35. package/dist/types/src/index.d.ts +16 -2
  36. package/dist/types/src/{splitHelpers.d.ts → splits/splitHelpers.d.ts} +1 -1
  37. package/dist/types/src/types.d.ts +133 -0
  38. package/dist/types/test/exit/verificationHelpers.spec.d.ts +1 -0
  39. package/dist/types/test/incentives/incentives.spec.d.ts +1 -0
  40. package/package.json +3 -3
  41. package/src/constants.ts +13 -0
  42. package/src/exits/ethUtils.ts +49 -0
  43. package/src/exits/exit.ts +661 -0
  44. package/src/exits/verificationHelpers.ts +110 -0
  45. package/src/{incentiveHelpers.ts → incentives/incentiveHelpers.ts} +2 -2
  46. package/src/{incentives.ts → incentives/incentives.ts} +3 -3
  47. package/src/index.ts +29 -3
  48. package/src/splits/splitHelpers.ts +557 -0
  49. package/src/types.ts +158 -0
  50. package/dist/cjs/src/splitHelpers.js +0 -187
  51. package/dist/cjs/test/methods.test.js +0 -418
  52. package/dist/esm/src/splitHelpers.js +0 -177
  53. package/dist/esm/test/methods.test.js +0 -393
  54. package/src/splitHelpers.ts +0 -355
  55. /package/dist/types/test/{incentives.test.d.ts → exit/ethUtils.spec.d.ts} +0 -0
  56. /package/dist/types/test/{methods.test.d.ts → exit/exit.spec.d.ts} +0 -0
@@ -1,177 +0,0 @@
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 { Contract, Interface, parseEther, ZeroAddress } from 'ethers';
11
- import { OWRContract, OWRFactoryContract } from './abi/OWR';
12
- import { splitMainEthereumAbi } from './abi/SplitMain';
13
- import { MultiCallContract } from './abi/Multicall';
14
- import { CHAIN_CONFIGURATION } from './constants';
15
- const splitMainContractInterface = new Interface(splitMainEthereumAbi);
16
- const owrFactoryContractInterface = new Interface(OWRFactoryContract.abi);
17
- export const formatSplitRecipients = (recipients) => {
18
- // Has to be sorted when passed
19
- recipients.sort((a, b) => a.account.localeCompare(b.account));
20
- const accounts = recipients.map(item => item.account);
21
- const percentAllocations = recipients.map(recipient => {
22
- const splitTostring = (recipient.percentAllocation * 1e4).toFixed(0);
23
- return parseInt(splitTostring);
24
- });
25
- return { accounts, percentAllocations };
26
- };
27
- export const predictSplitterAddress = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
28
- try {
29
- let predictedSplitterAddress;
30
- const splitMainContractInstance = new Contract(CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address, splitMainEthereumAbi, signer);
31
- if (controllerAddress === ZeroAddress) {
32
- predictedSplitterAddress =
33
- yield splitMainContractInstance.predictImmutableSplitAddress(accounts, percentAllocations, distributorFee);
34
- }
35
- else {
36
- // It throws on deployed Immutable splitter
37
- predictedSplitterAddress =
38
- yield splitMainContractInstance.createSplit.staticCall(accounts, percentAllocations, distributorFee, controllerAddress);
39
- }
40
- return predictedSplitterAddress;
41
- }
42
- catch (e) {
43
- throw e;
44
- }
45
- });
46
- export const handleDeployOWRAndSplitter = ({ signer, isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, etherAmount, principalRecipient, chainId, distributorFee, controllerAddress, recoveryAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
47
- try {
48
- if (isSplitterDeployed) {
49
- const owrAddress = yield createOWRContract({
50
- owrArgs: {
51
- principalRecipient,
52
- amountOfPrincipalStake: etherAmount,
53
- predictedSplitterAddress,
54
- recoveryAddress,
55
- },
56
- signer,
57
- chainId,
58
- });
59
- return {
60
- withdrawal_address: owrAddress,
61
- fee_recipient_address: predictedSplitterAddress,
62
- };
63
- }
64
- else {
65
- const { owrAddress, splitterAddress } = yield deploySplitterAndOWRContracts({
66
- owrArgs: {
67
- principalRecipient,
68
- amountOfPrincipalStake: etherAmount,
69
- predictedSplitterAddress,
70
- recoveryAddress,
71
- },
72
- splitterArgs: {
73
- accounts,
74
- percentAllocations,
75
- distributorFee,
76
- controllerAddress,
77
- },
78
- signer,
79
- chainId,
80
- });
81
- return {
82
- withdrawal_address: owrAddress,
83
- fee_recipient_address: splitterAddress,
84
- };
85
- }
86
- }
87
- catch (e) {
88
- throw e;
89
- }
90
- });
91
- const createOWRContract = ({ owrArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
92
- var _a;
93
- try {
94
- const OWRFactoryInstance = new Contract(CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address, OWRFactoryContract.abi, signer);
95
- const tx = yield OWRFactoryInstance.createOWRecipient(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, parseEther(owrArgs.amountOfPrincipalStake.toString()));
96
- const receipt = yield tx.wait();
97
- const OWRAddressData = (_a = receipt === null || receipt === void 0 ? void 0 : receipt.logs[0]) === null || _a === void 0 ? void 0 : _a.topics[1];
98
- const formattedOWRAddress = '0x' + (OWRAddressData === null || OWRAddressData === void 0 ? void 0 : OWRAddressData.slice(26, 66));
99
- return formattedOWRAddress;
100
- }
101
- catch (e) {
102
- throw e;
103
- }
104
- });
105
- export const deploySplitterContract = ({ signer, accounts, percentAllocations, chainId, distributorFee, controllerAddress, }) => __awaiter(void 0, void 0, void 0, function* () {
106
- var _b;
107
- try {
108
- const splitMainContractInstance = new Contract(CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address, splitMainEthereumAbi, signer);
109
- const tx = yield splitMainContractInstance.createSplit(accounts, percentAllocations, distributorFee, controllerAddress);
110
- const receipt = yield tx.wait();
111
- const splitterAddressData = (_b = receipt === null || receipt === void 0 ? void 0 : receipt.logs[0]) === null || _b === void 0 ? void 0 : _b.topics[1];
112
- const formattedSplitterAddress = '0x' + (splitterAddressData === null || splitterAddressData === void 0 ? void 0 : splitterAddressData.slice(26, 66));
113
- return formattedSplitterAddress;
114
- }
115
- catch (e) {
116
- throw e;
117
- }
118
- });
119
- export const deploySplitterAndOWRContracts = ({ owrArgs, splitterArgs, signer, chainId, }) => __awaiter(void 0, void 0, void 0, function* () {
120
- var _c, _d;
121
- const executeCalls = [];
122
- try {
123
- const splitTxData = encodeCreateSplitTxData(splitterArgs.accounts, splitterArgs.percentAllocations, splitterArgs.distributorFee, splitterArgs.controllerAddress);
124
- const owrTxData = encodeCreateOWRecipientTxData(owrArgs.recoveryAddress, owrArgs.principalRecipient, owrArgs.predictedSplitterAddress, owrArgs.amountOfPrincipalStake);
125
- executeCalls.push({
126
- target: CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS.address,
127
- callData: splitTxData,
128
- }, {
129
- target: CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS.address,
130
- callData: owrTxData,
131
- });
132
- const multicallAddess = CHAIN_CONFIGURATION[chainId].MULTICALL_ADDRESS.address;
133
- const executeMultiCalls = yield multicall(executeCalls, signer, multicallAddess);
134
- const splitAddressData = (_c = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[0]) === null || _c === void 0 ? void 0 : _c.topics[1];
135
- const formattedSplitterAddress = '0x' + (splitAddressData === null || splitAddressData === void 0 ? void 0 : splitAddressData.slice(26, 66));
136
- const owrAddressData = (_d = executeMultiCalls === null || executeMultiCalls === void 0 ? void 0 : executeMultiCalls.logs[1]) === null || _d === void 0 ? void 0 : _d.topics[1];
137
- const formattedOwrAddress = '0x' + (owrAddressData === null || owrAddressData === void 0 ? void 0 : owrAddressData.slice(26, 66));
138
- return {
139
- owrAddress: formattedOwrAddress,
140
- splitterAddress: formattedSplitterAddress,
141
- };
142
- }
143
- catch (e) {
144
- throw e;
145
- }
146
- });
147
- export const getOWRTranches = ({ owrAddress, signer, }) => __awaiter(void 0, void 0, void 0, function* () {
148
- const owrContract = new Contract(owrAddress, OWRContract.abi, signer);
149
- const res = yield owrContract.getTranches();
150
- return {
151
- principalRecipient: res.principalRecipient,
152
- rewardRecipient: res.rewardRecipient,
153
- amountOfPrincipalStake: res.amountOfPrincipalStake,
154
- };
155
- });
156
- export const multicall = (calls, signer, multicallAddress) => __awaiter(void 0, void 0, void 0, function* () {
157
- const multiCallContractInstance = new Contract(multicallAddress, MultiCallContract.abi, signer);
158
- const tx = yield multiCallContractInstance.aggregate(calls);
159
- const receipt = yield tx.wait();
160
- return receipt;
161
- });
162
- const encodeCreateSplitTxData = (accounts, percentAllocations, distributorFee, controller) => {
163
- return splitMainContractInterface.encodeFunctionData('createSplit', [
164
- accounts,
165
- percentAllocations,
166
- distributorFee,
167
- controller,
168
- ]);
169
- };
170
- const encodeCreateOWRecipientTxData = (recoveryAddress, principalRecipient, rewardRecipient, amountOfPrincipalStake) => {
171
- return owrFactoryContractInterface.encodeFunctionData('createOWRecipient', [
172
- recoveryAddress,
173
- principalRecipient,
174
- rewardRecipient,
175
- parseEther(amountOfPrincipalStake.toString()),
176
- ]);
177
- };
@@ -1,393 +0,0 @@
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
- var _a, _b;
11
- import { ethers, JsonRpcProvider } from 'ethers';
12
- import { Client, validateClusterLock } from '../src/index';
13
- import { clusterConfigV1X7, clusterConfigV1X10, clusterLockV1X10, clusterLockV1X6, clusterLockV1X7, clusterLockV1X8, clusterLockWithCompoundingWithdrawals, clusterLockWithSafe, nullDepositAmountsClusterLockV1X8, } from './fixtures.js';
14
- import { SDK_VERSION } from '../src/constants';
15
- import { Base } from '../src/base';
16
- import { HttpResponse, http } from 'msw';
17
- import { setupServer } from 'msw/node';
18
- import { hashTermsAndConditions } from '../src/verification/termsAndConditions';
19
- import * as utils from '../src/utils';
20
- import * as splitsHelpers from '../src/splitHelpers';
21
- jest.setTimeout(20000);
22
- const mnemonic = (_b = (_a = ethers.Wallet.createRandom().mnemonic) === null || _a === void 0 ? void 0 : _a.phrase) !== null && _b !== void 0 ? _b : '';
23
- const privateKey = ethers.Wallet.fromPhrase(mnemonic).privateKey;
24
- const provider = new JsonRpcProvider('https://ethereum-holesky.publicnode.com');
25
- const wallet = new ethers.Wallet(privateKey, provider);
26
- const mockSigner = wallet.connect(provider);
27
- /* eslint no-new: 0 */
28
- describe('Cluster Client', () => {
29
- const mockConfigHash = '0x1f6c94e6c070393a68c1aa6073a21cb1fd57f0e14d2a475a2958990ab728c2fd';
30
- const clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
31
- test('createTermsAndConditions should return "successful authorization"', () => __awaiter(void 0, void 0, void 0, function* () {
32
- clientInstance['request'] = jest
33
- .fn()
34
- .mockReturnValue(Promise.resolve({ message: 'successful authorization' }));
35
- const isAuthorized = yield clientInstance.acceptObolLatestTermsAndConditions();
36
- expect(isAuthorized).toEqual('successful authorization');
37
- }));
38
- test('createClusterDefinition should return config_hash', () => __awaiter(void 0, void 0, void 0, function* () {
39
- clientInstance['request'] = jest
40
- .fn()
41
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
42
- const configHash = yield clientInstance.createClusterDefinition(clusterConfigV1X10);
43
- expect(configHash).toEqual(mockConfigHash);
44
- }));
45
- test('acceptClusterDefinition should return cluster definition', () => __awaiter(void 0, void 0, void 0, function* () {
46
- clientInstance['request'] = jest
47
- .fn()
48
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
49
- const clusterDefinition = yield clientInstance.acceptClusterDefinition({
50
- enr: clusterLockV1X10.cluster_definition.operators[0].enr,
51
- version: clusterLockV1X10.cluster_definition.version,
52
- }, clusterLockV1X10.cluster_definition.config_hash);
53
- expect(clusterDefinition).toEqual(clusterLockV1X10.cluster_definition);
54
- }));
55
- test('createClusterDefinition should throw an error on invalid operators', () => __awaiter(void 0, void 0, void 0, function* () {
56
- clientInstance['request'] = jest
57
- .fn()
58
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
59
- try {
60
- yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, clusterConfigV1X10), { operators: [] }));
61
- }
62
- catch (error) {
63
- expect(error.message).toEqual('Validation failed: /operators must pass "validateUniqueAddresses" keyword validation, /operators must NOT have fewer than 4 items');
64
- }
65
- }));
66
- // cause we default to null
67
- test('createClusterDefinition should accept a configuration without deposit_amounts', () => __awaiter(void 0, void 0, void 0, function* () {
68
- clientInstance['request'] = jest
69
- .fn()
70
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
71
- const configHash = yield clientInstance.createClusterDefinition(Object.assign({}, clusterConfigV1X7));
72
- expect(configHash).toEqual(mockConfigHash);
73
- }));
74
- test('createClusterDefinition should throw on not valid deposit_amounts ', () => __awaiter(void 0, void 0, void 0, function* () {
75
- clientInstance['request'] = jest
76
- .fn()
77
- .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash }));
78
- try {
79
- yield clientInstance.createClusterDefinition(Object.assign(Object.assign({}, clusterConfigV1X7), { deposit_amounts: ['34000000'] }));
80
- }
81
- catch (error) {
82
- expect(error.message).toEqual('Validation failed: /deposit_amounts/0 must be equal to one of the allowed values, /deposit_amounts must match "then" schema');
83
- }
84
- }));
85
- test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
86
- clientInstance['request'] = jest
87
- .fn()
88
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
89
- const clusterDefinition = yield clientInstance.getClusterDefinition(clusterLockV1X10.cluster_definition.config_hash);
90
- expect(clusterDefinition.deposit_amounts).toBeDefined();
91
- expect(clusterDefinition.config_hash).toEqual(clusterLockV1X10.cluster_definition.config_hash);
92
- // Test for new fields
93
- expect(clusterDefinition.compounding).toBeDefined();
94
- expect(clusterDefinition.target_gas_limit).toBeDefined();
95
- expect(clusterDefinition.consensus_protocol).toBeDefined();
96
- }));
97
- test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
98
- clientInstance['request'] = jest
99
- .fn()
100
- .mockReturnValue(Promise.resolve(clusterLockV1X10));
101
- const clusterLock = yield clientInstance.getClusterLock(clusterLockV1X10.cluster_definition.config_hash);
102
- expect(clusterLock.lock_hash).toEqual(clusterLockV1X10.lock_hash);
103
- }));
104
- test('request method should set user agent header', () => __awaiter(void 0, void 0, void 0, function* () {
105
- const server = setupServer(http.get('http://testexample.com/test', ({ request }) => {
106
- // Check if the request contains specific headers
107
- if (request.headers.get('User-Agent') === `Obol-SDK/${SDK_VERSION}`) {
108
- return HttpResponse.json({ message: 'user-agent header exist' });
109
- }
110
- }));
111
- server.listen();
112
- class TestBase extends Base {
113
- callProtectedRequest(endpoint, options) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- return yield this['request'](endpoint, options);
116
- });
117
- }
118
- }
119
- const testBaseInstance = new TestBase({
120
- baseUrl: 'http://testExample.com',
121
- });
122
- const result = yield testBaseInstance.callProtectedRequest('/test', {
123
- method: 'GET',
124
- });
125
- expect(result === null || result === void 0 ? void 0 : result.message).toEqual('user-agent header exist');
126
- server.close();
127
- }));
128
- });
129
- describe('Cluster Client without a signer', () => {
130
- const clientInstance = new Client({
131
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
132
- chainId: 17000,
133
- });
134
- beforeAll(() => {
135
- jest.restoreAllMocks();
136
- });
137
- beforeEach(() => {
138
- jest.resetModules();
139
- });
140
- test('createClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
141
- try {
142
- yield clientInstance.createClusterDefinition(clusterConfigV1X10);
143
- }
144
- catch (err) {
145
- expect(err.message).toEqual('Signer is required in createClusterDefinition');
146
- }
147
- }));
148
- test('acceptClusterDefinition should throw an error without signer', () => __awaiter(void 0, void 0, void 0, function* () {
149
- try {
150
- yield clientInstance.acceptClusterDefinition({
151
- enr: clusterLockV1X10.cluster_definition.operators[0].enr,
152
- version: clusterLockV1X10.cluster_definition.version,
153
- }, clusterLockV1X10.cluster_definition.config_hash);
154
- }
155
- catch (err) {
156
- expect(err.message).toEqual('Signer is required in acceptClusterDefinition');
157
- }
158
- }));
159
- test('getClusterdefinition should return cluster definition if config hash exist', () => __awaiter(void 0, void 0, void 0, function* () {
160
- clientInstance['request'] = jest
161
- .fn()
162
- .mockReturnValue(Promise.resolve(clusterLockV1X10.cluster_definition));
163
- const clusterDefinition = yield clientInstance.getClusterDefinition(clusterLockV1X10.cluster_definition.config_hash);
164
- expect(clusterDefinition.config_hash).toEqual(clusterLockV1X10.cluster_definition.config_hash);
165
- }));
166
- test('getClusterLock should return lockFile if exist', () => __awaiter(void 0, void 0, void 0, function* () {
167
- clientInstance['request'] = jest
168
- .fn()
169
- .mockReturnValue(Promise.resolve(clusterLockV1X10));
170
- const clusterLock = yield clientInstance.getClusterLock(clusterLockV1X10.cluster_definition.config_hash);
171
- expect(clusterLock.lock_hash).toEqual(clusterLockV1X10.lock_hash);
172
- }));
173
- test.each([
174
- { version: 'v1.6.0', clusterLock: clusterLockV1X6 },
175
- { version: 'v1.7.0', clusterLock: clusterLockV1X7 },
176
- { version: 'v1.8.0', clusterLock: clusterLockV1X8 },
177
- {
178
- version: 'null deposit_amounts v1.8.0',
179
- clusterLock: nullDepositAmountsClusterLockV1X8,
180
- },
181
- {
182
- version: 'Cluster with safe address v1.8.0',
183
- clusterLock: clusterLockWithSafe,
184
- },
185
- { version: 'v1.10.0', clusterLock: clusterLockV1X10 },
186
- {
187
- version: 'v1.10.0 with compunding withdrawals',
188
- clusterLock: clusterLockWithCompoundingWithdrawals,
189
- },
190
- ])("$version: 'should return true on verified cluster lock'", ({ clusterLock }) => __awaiter(void 0, void 0, void 0, function* () {
191
- const isValidLock = yield validateClusterLock(clusterLock);
192
- expect(isValidLock).toEqual(true);
193
- }));
194
- test('should return true on verified cluster lock with Safe wallet and safe rpc url', () => __awaiter(void 0, void 0, void 0, function* () {
195
- process.env.RPC_HOLESKY = undefined;
196
- /* eslint-disable @typescript-eslint/no-var-requires */
197
- const { validateClusterLock: validateLockWithRpcUrl, } = require('../src/index');
198
- const safeRpcUrl = 'https://ethereum-holesky-rpc.publicnode.com';
199
- const isValidLock = yield validateLockWithRpcUrl(clusterLockWithSafe, safeRpcUrl);
200
- expect(isValidLock).toEqual(true);
201
- }));
202
- test('validateCluster should return false for cluster with null deposit_amounts and incorrect partial_deposits', () => __awaiter(void 0, void 0, void 0, function* () {
203
- const partialDeposit = nullDepositAmountsClusterLockV1X8.distributed_validators[0]
204
- .partial_deposit_data[0];
205
- const isValidLock = yield validateClusterLock(Object.assign(Object.assign({}, nullDepositAmountsClusterLockV1X8), { distributed_validators: [
206
- Object.assign(Object.assign({}, nullDepositAmountsClusterLockV1X8.distributed_validators[0]), { partial_deposit_data: [partialDeposit, partialDeposit] }),
207
- ] }));
208
- expect(isValidLock).toEqual(false);
209
- }));
210
- test('Finds the hash of the latest version of terms and conditions', () => __awaiter(void 0, void 0, void 0, function* () {
211
- const termsAndConditionsHash = yield hashTermsAndConditions();
212
- expect(termsAndConditionsHash).toEqual('0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273');
213
- }));
214
- });
215
- describe('createObolRewardsSplit', () => {
216
- let clientInstance, clientInstanceWithourSigner, mockSplitRecipients, mockPrincipalRecipient, mockEtherAmount;
217
- beforeAll(() => {
218
- jest
219
- .spyOn(utils, 'isContractAvailable')
220
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
221
- jest
222
- .spyOn(splitsHelpers, 'predictSplitterAddress')
223
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
224
- jest.spyOn(splitsHelpers, 'handleDeployOWRAndSplitter').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
225
- return yield Promise.resolve({
226
- withdrawal_address: '0xWithdrawalAddress',
227
- fee_recipient_address: '0xFeeRecipientAddress',
228
- });
229
- }));
230
- clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
231
- clientInstanceWithourSigner = new Client({
232
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
233
- chainId: 17000,
234
- });
235
- mockSplitRecipients = [
236
- {
237
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
238
- percentAllocation: 99,
239
- },
240
- ];
241
- mockPrincipalRecipient = '0x86B8145c98e5BD25BA722645b15eD65f024a87EC';
242
- mockEtherAmount = 64;
243
- });
244
- it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
245
- yield expect(clientInstanceWithourSigner.createObolRewardsSplit({
246
- splitRecipients: mockSplitRecipients,
247
- principalRecipient: mockPrincipalRecipient,
248
- etherAmount: mockEtherAmount,
249
- })).rejects.toThrow('Signer is required in createObolRewardsSplit');
250
- }));
251
- it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
252
- const unsupportedSplitterChainClient = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
253
- try {
254
- yield unsupportedSplitterChainClient.createObolRewardsSplit({
255
- splitRecipients: mockSplitRecipients,
256
- principalRecipient: mockPrincipalRecipient,
257
- etherAmount: mockEtherAmount,
258
- });
259
- }
260
- catch (error) {
261
- expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
262
- }
263
- }));
264
- test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
265
- try {
266
- yield clientInstance.createObolRewardsSplit({
267
- splitRecipients: [
268
- {
269
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
270
- percentAllocation: 22,
271
- },
272
- ],
273
- principalRecipient: mockPrincipalRecipient,
274
- etherAmount: mockEtherAmount,
275
- });
276
- }
277
- catch (error) {
278
- expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation');
279
- }
280
- }));
281
- test('should throw an error if ObolRAFSplit is less than 1', () => __awaiter(void 0, void 0, void 0, function* () {
282
- try {
283
- yield clientInstance.createObolRewardsSplit({
284
- splitRecipients: mockSplitRecipients,
285
- principalRecipient: mockPrincipalRecipient,
286
- etherAmount: mockEtherAmount,
287
- ObolRAFSplit: 0.5,
288
- });
289
- }
290
- catch (error) {
291
- expect(error.message).toEqual('Validation failed: must pass "validateRewardsSplitRecipients" keyword validation, /ObolRAFSplit must be >= 1');
292
- }
293
- }));
294
- it('should return the correct withdrawal and fee recipient addresses', () => __awaiter(void 0, void 0, void 0, function* () {
295
- const result = yield clientInstance.createObolRewardsSplit({
296
- splitRecipients: mockSplitRecipients,
297
- principalRecipient: mockPrincipalRecipient,
298
- etherAmount: mockEtherAmount,
299
- });
300
- expect(result).toEqual({
301
- withdrawal_address: '0xWithdrawalAddress',
302
- fee_recipient_address: '0xFeeRecipientAddress',
303
- });
304
- }));
305
- });
306
- describe('createObolTotalSplit', () => {
307
- let clientInstanceWithourSigner, mockSplitRecipients, clientInstance;
308
- beforeAll(() => {
309
- jest
310
- .spyOn(utils, 'isContractAvailable')
311
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve(true); }));
312
- jest
313
- .spyOn(splitsHelpers, 'predictSplitterAddress')
314
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xPredictedAddress'); }));
315
- jest
316
- .spyOn(splitsHelpers, 'deploySplitterContract')
317
- .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve('0xSplitterAddress'); }));
318
- clientInstance = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 17000 }, mockSigner);
319
- clientInstanceWithourSigner = new Client({
320
- baseUrl: 'https://obol-api-dev.gcp.obol.tech',
321
- chainId: 17000,
322
- });
323
- mockSplitRecipients = [
324
- {
325
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
326
- percentAllocation: 99.9,
327
- },
328
- ];
329
- });
330
- it('should throw an error if signer is not defined', () => __awaiter(void 0, void 0, void 0, function* () {
331
- yield expect(clientInstanceWithourSigner.createObolTotalSplit({
332
- splitRecipients: mockSplitRecipients,
333
- })).rejects.toThrow('Signer is required in createObolTotalSplit');
334
- }));
335
- it('should throw an error if chainId is not supported', () => __awaiter(void 0, void 0, void 0, function* () {
336
- const unsupportedSplitterChainClient = new Client({ baseUrl: 'https://obol-api-dev.gcp.obol.tech', chainId: 100 }, mockSigner);
337
- try {
338
- yield unsupportedSplitterChainClient.createObolTotalSplit({
339
- splitRecipients: mockSplitRecipients,
340
- });
341
- }
342
- catch (error) {
343
- expect(error.message).toEqual('Splitter configuration is not supported on 100 chain');
344
- }
345
- }));
346
- test('should throw an error on invalid recipients', () => __awaiter(void 0, void 0, void 0, function* () {
347
- try {
348
- yield clientInstance.createObolTotalSplit({
349
- splitRecipients: [
350
- {
351
- account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
352
- percentAllocation: 22,
353
- },
354
- ],
355
- });
356
- }
357
- catch (error) {
358
- expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation');
359
- }
360
- }));
361
- test('should throw an error if ObolRAFSplit is less than 0.1', () => __awaiter(void 0, void 0, void 0, function* () {
362
- try {
363
- yield clientInstance.createObolTotalSplit({
364
- splitRecipients: mockSplitRecipients,
365
- ObolRAFSplit: 0.05,
366
- });
367
- }
368
- catch (error) {
369
- expect(error.message).toEqual('Validation failed: must pass "validateTotalSplitRecipients" keyword validation, /ObolRAFSplit must be >= 0.1');
370
- }
371
- }));
372
- it('should return the correct withdrawal and fee recipient addresses and ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
373
- const result = yield clientInstance.createObolTotalSplit({
374
- splitRecipients: mockSplitRecipients,
375
- ObolRAFSplit: 0.1,
376
- });
377
- // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
378
- expect(result).toEqual({
379
- withdrawal_address: '0xPredictedAddress',
380
- fee_recipient_address: '0xPredictedAddress',
381
- });
382
- }));
383
- it('should return the correct withdrawal and fee recipient addresses without passing ObolRAFSplit', () => __awaiter(void 0, void 0, void 0, function* () {
384
- const result = yield clientInstance.createObolTotalSplit({
385
- splitRecipients: mockSplitRecipients,
386
- });
387
- // 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
388
- expect(result).toEqual({
389
- withdrawal_address: '0xPredictedAddress',
390
- fee_recipient_address: '0xPredictedAddress',
391
- });
392
- }));
393
- });