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

222 lines 16.7 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.ParametersSDK = void 0; const csm_sdk_module_js_1 = require("../common/class-primitives/csm-sdk-module.js"); const cache_js_1 = require("../common/decorators/cache.js"); const error_handler_js_1 = require("../common/decorators/error-handler.js"); const logger_js_1 = require("../common/decorators/logger.js"); const index_js_1 = require("../common/index.js"); let ParametersSDK = (() => { var _a; let _classSuper = csm_sdk_module_js_1.CsmSDKModule; let _instanceExtraInitializers = []; let _getCurvesCount_decorators; let _getDefaultCurveId_decorators; let _getKeyRemovalFee_decorators; let _getMaxWithdrawalRequestFee_decorators; let _getKeysLimit_decorators; let _getELStealingPenalty_decorators; let _getBadPerformancePenalty_decorators; let _getExitDelayPenalty_decorators; let _getAllowedExitDelay_decorators; let _getRewardsShare_decorators; let _getPerformanceLewayConfig_decorators; let _getPerformanceCoefficients_decorators; let _getStrikesConfig_decorators; let _getQueueConfig_decorators; let _getBondConfig_decorators; let _getAll_decorators; return _a = class ParametersSDK extends _classSuper { get parametersContract() { return this.core.contractParametersRegistry; } get accountingContract() { return this.core.contractAccounting; } async getCurvesCount() { return this.accountingContract.read.getCurvesCount(); } async getDefaultCurveId() { return this.accountingContract.read.DEFAULT_BOND_CURVE_ID(); } async getKeyRemovalFee(curveId) { return this.parametersContract.read.getKeyRemovalCharge([curveId]); } async getMaxWithdrawalRequestFee(curveId) { return this.parametersContract.read.getMaxElWithdrawalRequestFee([curveId]); } async getKeysLimit(curveId) { const keysLimit = await this.parametersContract.read.getKeysLimit([ curveId, ]); return Number(keysLimit); } async getELStealingPenalty(curveId) { return this.parametersContract.read.getGeneralDelayedPenaltyAdditionalFine([ curveId, ]); } async getBadPerformancePenalty(curveId) { return this.parametersContract.read.getBadPerformancePenalty([curveId]); } async getExitDelayPenalty(curveId) { return this.parametersContract.read.getExitDelayFee([curveId]); } async getAllowedExitDelay(curveId) { const value = await this.parametersContract.read.getAllowedExitDelay([ curveId, ]); return Number(value); } async getRewardsShare(curveId) { const [rewardsShare, digest] = await Promise.all([ this.parametersContract.read.getRewardShareData([curveId]), this.bus.module.getDigest(), ]); return rewardsShare.map((item) => ({ ...item, minKeyNumber: Number(item.minKeyNumber), value: (item.value * digest.state.stakingModuleFee) / index_js_1.PERCENT_BASIS, })); } async getPerformanceLewayConfig(curveId) { return (await this.parametersContract.read.getPerformanceLeewayData([curveId])).map((item) => ({ ...item, minKeyNumber: Number(item.minKeyNumber), })); } async getPerformanceCoefficients(curveId) { const [attestationsWeight, blocksWeight, syncWeight] = await this.parametersContract.read.getPerformanceCoefficients([curveId]); return { attestationsWeight, blocksWeight, syncWeight }; } async getStrikesConfig(curveId) { const [lifetime, threshold] = await this.parametersContract.read.getStrikesParams([curveId]); return { lifetime: Number(lifetime), threshold: Number(threshold) }; } async getQueueConfig(curveId) { const [[priority, maxDeposits], lowestPriority] = await Promise.all([ this.parametersContract.read.getQueueConfig([curveId]), this.parametersContract.read.QUEUE_LOWEST_PRIORITY(), ]); return { priority, maxDeposits, lowestPriority: Number(lowestPriority) }; } async getBondConfig(curveId) { const { intervals } = await this.accountingContract.read.getCurveInfo([ curveId, ]); return intervals.map(({ minKeysCount, trend }) => ({ minKeyNumber: Number(minKeysCount), value: trend, })); } async getAll(curveId) { const [keyRemovalFee, keysLimit, allowedExitDelay, exitDelayPenalty, badPerformancePenalty, elStealingPenalty, maxWithdrawalRequestFee, performanceCoefficients, performanceLeewayConfig, rewardsConfig, bondConfig, queueConfig, strikesConfig,] = await Promise.all([ this.getKeyRemovalFee(curveId), this.getKeysLimit(curveId), this.getAllowedExitDelay(curveId), this.getExitDelayPenalty(curveId), this.getBadPerformancePenalty(curveId), this.getELStealingPenalty(curveId), this.getMaxWithdrawalRequestFee(curveId), this.getPerformanceCoefficients(curveId), this.getPerformanceLewayConfig(curveId), this.getRewardsShare(curveId), this.getBondConfig(curveId), this.getQueueConfig(curveId), this.getStrikesConfig(curveId), ]); return { keyRemovalFee, keysLimit, allowedExitDelay, exitDelayPenalty, badPerformancePenalty, elStealingPenalty, maxWithdrawalRequestFee, performanceCoefficients, performanceLeewayConfig, rewardsConfig, bondConfig, queueConfig, strikesConfig, }; } constructor() { super(...arguments); __runInitializers(this, _instanceExtraInitializers); } }, (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _getCurvesCount_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_LONG), (0, error_handler_js_1.ErrorHandler)()]; _getDefaultCurveId_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getKeyRemovalFee_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getMaxWithdrawalRequestFee_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getKeysLimit_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getELStealingPenalty_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getBadPerformancePenalty_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getExitDelayPenalty_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getAllowedExitDelay_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getRewardsShare_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getPerformanceLewayConfig_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getPerformanceCoefficients_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getStrikesConfig_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getQueueConfig_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getBondConfig_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()]; _getAll_decorators = [(0, logger_js_1.Logger)('Utils:')]; __esDecorate(_a, null, _getCurvesCount_decorators, { kind: "method", name: "getCurvesCount", static: false, private: false, access: { has: obj => "getCurvesCount" in obj, get: obj => obj.getCurvesCount }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getDefaultCurveId_decorators, { kind: "method", name: "getDefaultCurveId", static: false, private: false, access: { has: obj => "getDefaultCurveId" in obj, get: obj => obj.getDefaultCurveId }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getKeyRemovalFee_decorators, { kind: "method", name: "getKeyRemovalFee", static: false, private: false, access: { has: obj => "getKeyRemovalFee" in obj, get: obj => obj.getKeyRemovalFee }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getMaxWithdrawalRequestFee_decorators, { kind: "method", name: "getMaxWithdrawalRequestFee", static: false, private: false, access: { has: obj => "getMaxWithdrawalRequestFee" in obj, get: obj => obj.getMaxWithdrawalRequestFee }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getKeysLimit_decorators, { kind: "method", name: "getKeysLimit", static: false, private: false, access: { has: obj => "getKeysLimit" in obj, get: obj => obj.getKeysLimit }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getELStealingPenalty_decorators, { kind: "method", name: "getELStealingPenalty", static: false, private: false, access: { has: obj => "getELStealingPenalty" in obj, get: obj => obj.getELStealingPenalty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getBadPerformancePenalty_decorators, { kind: "method", name: "getBadPerformancePenalty", static: false, private: false, access: { has: obj => "getBadPerformancePenalty" in obj, get: obj => obj.getBadPerformancePenalty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getExitDelayPenalty_decorators, { kind: "method", name: "getExitDelayPenalty", static: false, private: false, access: { has: obj => "getExitDelayPenalty" in obj, get: obj => obj.getExitDelayPenalty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getAllowedExitDelay_decorators, { kind: "method", name: "getAllowedExitDelay", static: false, private: false, access: { has: obj => "getAllowedExitDelay" in obj, get: obj => obj.getAllowedExitDelay }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getRewardsShare_decorators, { kind: "method", name: "getRewardsShare", static: false, private: false, access: { has: obj => "getRewardsShare" in obj, get: obj => obj.getRewardsShare }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getPerformanceLewayConfig_decorators, { kind: "method", name: "getPerformanceLewayConfig", static: false, private: false, access: { has: obj => "getPerformanceLewayConfig" in obj, get: obj => obj.getPerformanceLewayConfig }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getPerformanceCoefficients_decorators, { kind: "method", name: "getPerformanceCoefficients", static: false, private: false, access: { has: obj => "getPerformanceCoefficients" in obj, get: obj => obj.getPerformanceCoefficients }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getStrikesConfig_decorators, { kind: "method", name: "getStrikesConfig", static: false, private: false, access: { has: obj => "getStrikesConfig" in obj, get: obj => obj.getStrikesConfig }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getQueueConfig_decorators, { kind: "method", name: "getQueueConfig", static: false, private: false, access: { has: obj => "getQueueConfig" in obj, get: obj => obj.getQueueConfig }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getBondConfig_decorators, { kind: "method", name: "getBondConfig", static: false, private: false, access: { has: obj => "getBondConfig" in obj, get: obj => obj.getBondConfig }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getAll_decorators, { kind: "method", name: "getAll", static: false, private: false, access: { has: obj => "getAll" in obj, get: obj => obj.getAll }, metadata: _metadata }, null, _instanceExtraInitializers); if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); })(), _a; })(); exports.ParametersSDK = ParametersSDK; //# sourceMappingURL=parameters-sdk.js.map