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