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

214 lines 15.8 kB
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; }; import { CSModulev1EventsAbi } from '../abi/CSModuleV1Events.js'; import { CsmSDKModule } from '../common/class-primitives/csm-sdk-module.js'; import { ErrorHandler, Logger } from '../common/decorators/index.js'; import { CONTRACT_NAMES, } from '../common/index.js'; import { isDefined, isPropsDefined, isUnique, requestWithBlockStep, sortEventsByBlockNumber, } from '../common/utils/index.js'; import { reconstructInvites } from './reconstruct-invites.js'; import { reconstructOperators } from './reconstruct-operators.js'; let EventsSDK = (() => { var _a; let _classSuper = 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(CONTRACT_NAMES.csModule, 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([ ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ managerAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContractV1.getEvents.NodeOperatorAdded({ rewardAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ oldAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ oldAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)), ]); const logs = logResults.flat().sort(sortEventsByBlockNumber); return reconstructOperators(logs, address); } async getInvitesByAddress(address, options) { if (this.disabled) return []; const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all([ ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChanged({ newAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChanged({ newAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ oldProposedAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ oldProposedAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorManagerAddressChangeProposed({ newProposedAddress: address }, stepProps)), ...requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.NodeOperatorRewardAddressChangeProposed({ newProposedAddress: address }, stepProps)), ]); const logs = logResults.flat().sort(sortEventsByBlockNumber); return reconstructInvites(logs, address); } async getRewardsReports(options) { if (this.disabled) return []; const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all(requestWithBlockStep(stepConfig, (stepProps) => this.oracleContract.getEvents.ProcessingStarted(undefined, stepProps))); const logs = logResults.flat().sort(sortEventsByBlockNumber); return logs; } async getDistributionLogUpdated(options) { if (this.disabled) return []; const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all(requestWithBlockStep(stepConfig, (stepProps) => this.distributorContract.getEvents.DistributionLogUpdated(stepProps))); const logs = logResults.flat().sort(sortEventsByBlockNumber); return logs; } async getWithdrawalSubmittedKeys(nodeOperatorId, options) { const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all(requestWithBlockStep(stepConfig, (stepProps) => this.moduleContract.getEvents.ValidatorWithdrawn({ nodeOperatorId }, stepProps))); const logs = logResults.flat().sort(sortEventsByBlockNumber); return logs.map((e) => e.args.pubkey).filter(isDefined); } async getRequestedToExitKeys(nodeOperatorId, options) { if (this.disabled) return []; const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all(requestWithBlockStep(stepConfig, (stepProps) => this.core.contractValidatorsExitBusOracle.getEvents.ValidatorExitRequest({ nodeOperatorId, stakingModuleId: BigInt(this.core.moduleId) }, stepProps))); const logs = logResults.flat().sort(sortEventsByBlockNumber); return logs.map((e) => e.args.validatorPubkey).filter(isDefined); } async getOperatorsWithPenalties(options) { if (this.disabled) return []; const stepConfig = await this.parseEventsProps(options); const logResults = await Promise.all(requestWithBlockStep(stepConfig, (stepProps) => this.accountingContract.getEvents.BondLockChanged({}, stepProps))); const logs = logResults.flat(); return logs .map((e) => e.args.nodeOperatorId) .filter(isUnique) .filter(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(requestWithBlockStep(stepConfig, (stepProps) => this.accountingContract.getEvents.BondCurveSet({ nodeOperatorId }, stepProps))); return logResults .flat() .map(({ args: { curveId }, blockNumber }) => ({ curveId, blockNumber })) .filter(isPropsDefined('curveId')) .sort(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 = [Logger('Events:'), ErrorHandler()]; _getInvitesByAddress_decorators = [Logger('Events:'), ErrorHandler()]; _getRewardsReports_decorators = [Logger('Events:'), ErrorHandler()]; _getDistributionLogUpdated_decorators = [Logger('Events:'), ErrorHandler()]; _getWithdrawalSubmittedKeys_decorators = [Logger('Events:'), ErrorHandler()]; _getRequestedToExitKeys_decorators = [Logger('Events:'), ErrorHandler()]; _getOperatorsWithPenalties_decorators = [Logger('Events:'), ErrorHandler()]; _getOperatorCurveIdChanges_decorators = [Logger('Events:'), ErrorHandler()]; _parseEventsProps_decorators = [Logger('Utils:'), 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; })(); export { EventsSDK }; //# sourceMappingURL=events-sdk.js.map