@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
217 lines • 16.7 kB
JavaScript
;
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
};
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0) continue;
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
if (_ = accept(result.get)) descriptor.get = _;
if (_ = accept(result.set)) descriptor.set = _;
if (_ = accept(result.init)) initializers.unshift(_);
}
else if (_ = accept(result)) {
if (kind === "field") initializers.unshift(_);
else descriptor[key] = _;
}
}
if (target) Object.defineProperty(target, contextIn.name, descriptor);
done = true;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventsSDK = void 0;
const CSModuleV1Events_js_1 = require("../abi/CSModuleV1Events.js");
const csm_sdk_module_js_1 = require("../common/class-primitives/csm-sdk-module.js");
const index_js_1 = require("../common/decorators/index.js");
const index_js_2 = require("../common/index.js");
const index_js_3 = require("../common/utils/index.js");
const reconstruct_invites_js_1 = require("./reconstruct-invites.js");
const reconstruct_operators_js_1 = require("./reconstruct-operators.js");
let EventsSDK = (() => {
var _a;
let _classSuper = csm_sdk_module_js_1.CsmSDKModule;
let _instanceExtraInitializers = [];
let _getNodeOperatorsByAddress_decorators;
let _getInvitesByAddress_decorators;
let _getRewardsReports_decorators;
let _getDistributionLogUpdated_decorators;
let _getWithdrawalSubmittedKeys_decorators;
let _getRequestedToExitKeys_decorators;
let _getOperatorsWithPenalties_decorators;
let _getOperatorCurveIdChanges_decorators;
let _parseEventsProps_decorators;
return _a = class EventsSDK extends _classSuper {
get moduleContract() {
return this.core.contractBaseModule;
}
get moduleContractV1() {
return this.core.getContractWithAbi(index_js_2.CONTRACT_NAMES.csModule, CSModuleV1Events_js_1.CSModulev1EventsAbi);
}
get oracleContract() {
return this.core.contractFeeOracle;
}
get distributorContract() {
return this.core.contractFeeDistributor;
}
get accountingContract() {
return this.core.contractAccounting;
}
async getNodeOperatorsByAddress(address, options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all([
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ oldAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ oldAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)),
]);
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return (0, reconstruct_operators_js_1.reconstructOperators)(logs, address);
}
async getInvitesByAddress(address, options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all([
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ oldProposedAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ oldProposedAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ newProposedAddress: address }, stepProps)),
...(0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ newProposedAddress: address }, stepProps)),
]);
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return (0, reconstruct_invites_js_1.reconstructInvites)(logs, address);
}
async getRewardsReports(options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.oracleContract.getEvents.ProcessingStarted(undefined, stepProps)));
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return logs;
}
async getDistributionLogUpdated(options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.distributorContract.getEvents.DistributionLogUpdated(stepProps)));
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return logs;
}
async getWithdrawalSubmittedKeys(nodeOperatorId, options) {
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.ValidatorWithdrawn({ nodeOperatorId }, stepProps)));
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return logs.map((e) => e.args.pubkey).filter(index_js_3.isDefined);
}
async getRequestedToExitKeys(nodeOperatorId, options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.core.contractValidatorsExitBusOracle.getEvents.ValidatorExitRequest({ nodeOperatorId, stakingModuleId: BigInt(this.core.moduleId) }, stepProps)));
const logs = logResults.flat().sort(index_js_3.sortEventsByBlockNumber);
return logs.map((e) => e.args.validatorPubkey).filter(index_js_3.isDefined);
}
async getOperatorsWithPenalties(options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.accountingContract.getEvents.BondLockChanged({}, stepProps)));
const logs = logResults.flat();
return logs
.map((e) => e.args.nodeOperatorId)
.filter(index_js_3.isUnique)
.filter(index_js_3.isDefined)
.sort((a, b) => Number(a - b));
}
async getOperatorCurveIdChanges(nodeOperatorId, options) {
if (this.disabled)
return [];
const stepConfig = await this.parseEventsProps(options);
const logResults = await Promise.all((0, index_js_3.requestWithBlockStep)(stepConfig, (stepProps) => this.accountingContract.getEvents.BondCurveSet({ nodeOperatorId }, stepProps)));
return logResults
.flat()
.map(({ args: { curveId }, blockNumber }) => ({ curveId, blockNumber }))
.filter((0, index_js_3.isPropsDefined)('curveId'))
.sort(index_js_3.sortEventsByBlockNumber);
}
async parseEventsProps(props) {
const step = props?.step ?? this.core.maxEventBlocksRange ?? 1_000_000;
const toBlock = await this.core.core.toBlockNumber({
block: props?.toBlock ?? 'latest',
});
let fromBlock;
if (props?.fromBlock) {
fromBlock = await this.core.core.toBlockNumber({
block: props.fromBlock ?? 'latest',
});
}
else if (props?.maxBlocksDepth !== undefined) {
const depthLimit = toBlock - props.maxBlocksDepth;
const deploymentBlock = this.core.deploymentBlockNumber ?? 0n;
fromBlock = depthLimit > deploymentBlock ? depthLimit : deploymentBlock;
}
else {
fromBlock = this.core.deploymentBlockNumber ?? toBlock - BigInt(step);
}
return {
fromBlock,
toBlock,
step,
};
}
get disabled() {
return this.core.maxEventBlocksRange === 0;
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_getNodeOperatorsByAddress_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getInvitesByAddress_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getRewardsReports_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getDistributionLogUpdated_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getWithdrawalSubmittedKeys_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getRequestedToExitKeys_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getOperatorsWithPenalties_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_getOperatorCurveIdChanges_decorators = [(0, index_js_1.Logger)('Events:'), (0, index_js_1.ErrorHandler)()];
_parseEventsProps_decorators = [(0, index_js_1.Logger)('Utils:'), (0, index_js_1.ErrorHandler)()];
__esDecorate(_a, null, _getNodeOperatorsByAddress_decorators, { kind: "method", name: "getNodeOperatorsByAddress", static: false, private: false, access: { has: obj => "getNodeOperatorsByAddress" in obj, get: obj => obj.getNodeOperatorsByAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getInvitesByAddress_decorators, { kind: "method", name: "getInvitesByAddress", static: false, private: false, access: { has: obj => "getInvitesByAddress" in obj, get: obj => obj.getInvitesByAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getRewardsReports_decorators, { kind: "method", name: "getRewardsReports", static: false, private: false, access: { has: obj => "getRewardsReports" in obj, get: obj => obj.getRewardsReports }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getDistributionLogUpdated_decorators, { kind: "method", name: "getDistributionLogUpdated", static: false, private: false, access: { has: obj => "getDistributionLogUpdated" in obj, get: obj => obj.getDistributionLogUpdated }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getWithdrawalSubmittedKeys_decorators, { kind: "method", name: "getWithdrawalSubmittedKeys", static: false, private: false, access: { has: obj => "getWithdrawalSubmittedKeys" in obj, get: obj => obj.getWithdrawalSubmittedKeys }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getRequestedToExitKeys_decorators, { kind: "method", name: "getRequestedToExitKeys", static: false, private: false, access: { has: obj => "getRequestedToExitKeys" in obj, get: obj => obj.getRequestedToExitKeys }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getOperatorsWithPenalties_decorators, { kind: "method", name: "getOperatorsWithPenalties", static: false, private: false, access: { has: obj => "getOperatorsWithPenalties" in obj, get: obj => obj.getOperatorsWithPenalties }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getOperatorCurveIdChanges_decorators, { kind: "method", name: "getOperatorCurveIdChanges", static: false, private: false, access: { has: obj => "getOperatorCurveIdChanges" in obj, get: obj => obj.getOperatorCurveIdChanges }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _parseEventsProps_decorators, { kind: "method", name: "parseEventsProps", static: false, private: false, access: { has: obj => "parseEventsProps" in obj, get: obj => obj.parseEventsProps }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.EventsSDK = EventsSDK;
//# sourceMappingURL=events-sdk.js.map