UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

166 lines 14 kB
"use strict"; 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 is_defined_js_1 = require("../common/utils/is-defined.js"); const request_with_block_step_js_1 = require("../common/utils/request-with-block-step.js"); const sort_events_js_1 = require("../common/utils/sort-events.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 _getWithdrawalSubmittedKeys_decorators; let _getRequestedToExitKeys_decorators; let _getOperatorsWithPenalties_decorators; let _parseEventsProps_decorators; return _a = class EventsSDK extends _classSuper { get moduleContract() { return this.core.contractCSModule; } get moduleContractV1() { return this.core.getContract(index_js_2.CSM_CONTRACT_NAMES.csModule, CSModuleV1Events_js_1.CSModulev1EventsAbi); } get oracleContract() { return this.core.contractCSFeeOracle; } async getNodeOperatorsByAddress(address, options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all([ ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ oldAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ oldAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)), ]); const logs = logResults.flat().sort(sort_events_js_1.sortEventsByBlockNumber); return (0, reconstruct_operators_js_1.reconstructOperators)(logs, address); } async getInvitesByAddress(address, options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all([ ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ oldProposedAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ oldProposedAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ newProposedAddress: address }, stepProps)), ...(0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ newProposedAddress: address }, stepProps)), ]); const logs = logResults.flat().sort(sort_events_js_1.sortEventsByBlockNumber); return (0, reconstruct_invites_js_1.reconstructInvites)(logs, address); } async getRewardsReports(options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all((0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.oracleContract.getEvents.ProcessingStarted(undefined, stepProps))); const logs = logResults.flat().sort(sort_events_js_1.sortEventsByBlockNumber); return logs; } async getWithdrawalSubmittedKeys(nodeOperatorId, options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all((0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.moduleContract.getEvents.WithdrawalSubmitted({ nodeOperatorId }, stepProps))); const logs = logResults.flat().sort(sort_events_js_1.sortEventsByBlockNumber); return logs.map((e) => e.args.pubkey).filter((k) => k !== undefined); } async getRequestedToExitKeys(nodeOperatorId, options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all((0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.core.contractValidatorsExitBusOracle.getEvents.ValidatorExitRequest({ nodeOperatorId, stakingModuleId: BigInt(this.core.moduleId) }, stepProps))); const logs = logResults.flat().sort(sort_events_js_1.sortEventsByBlockNumber); return logs.map((e) => e.args.validatorPubkey).filter(is_defined_js_1.isDefined); } async getOperatorsWithPenalties(options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all((0, request_with_block_step_js_1.requestWithBlockStep)(stepConfig, (stepProps) => this.core.contractCSModule.getEvents.ELRewardsStealingPenaltyReported({}, stepProps))); const logs = logResults.flat(); return logs .map((e) => e.args.nodeOperatorId) .filter(is_defined_js_1.isUnique) .filter(is_defined_js_1.isDefined) .sort((a, b) => Number(a - b)); } async parseEventsProps(props) { const step = props?.step ?? this.core.maxEventBlocksRange ?? 1_000_000; const toBlock = await this.core.core.toBlockNumber({ block: props?.toBlock ?? 'latest', }); const fromBlock = props?.fromBlock ? await this.core.core.toBlockNumber({ block: props.fromBlock ?? 'latest', }) : this.core.deploymentBlockNumber ?? toBlock - BigInt(step); return { fromBlock, toBlock, step, }; } 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)()]; _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)()]; _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, _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, _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