@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
151 lines • 10.3 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.OperatorSDK = void 0;
const viem_1 = require("viem");
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");
const clear_empty_address_js_1 = require("../common/utils/clear-empty-address.js");
const split_keys_js_1 = require("../common/utils/split-keys.js");
const calc_bond_balance_js_1 = require("./calc-bond-balance.js");
let OperatorSDK = (() => {
var _a;
let _classSuper = csm_sdk_module_js_1.CsmSDKModule;
let _instanceExtraInitializers = [];
let _getCurveId_decorators;
let _getBondBalance_decorators;
let _getLockedBond_decorators;
let _getInfo_decorators;
let _getKeys_decorators;
let _getUnboundKeysCount_decorators;
let _getOwner_decorators;
let _isOwner_decorators;
let _getManagementProperties_decorators;
return _a = class OperatorSDK extends _classSuper {
get accountingContract() {
return this.core.contractAccounting;
}
get moduleContract() {
return this.core.contractBaseModule;
}
async getCurveId(id) {
return this.accountingContract.read.getBondCurveId([id]);
}
async getBondBalance(id) {
const [[current, required], locked] = await Promise.all([
this.accountingContract.read.getBondSummary([id]),
this.accountingContract.read.getActualLockedBond([id]),
]);
return (0, calc_bond_balance_js_1.calcBondBalance)({ current, required, locked });
}
async getLockedBond(id) {
return this.accountingContract.read.getActualLockedBond([id]);
}
async getInfo(id) {
const info = await this.moduleContract.read.getNodeOperator([id]);
return {
...info,
rewardsAddress: info.rewardAddress,
proposedManagerAddress: (0, clear_empty_address_js_1.clearEmptyAddress)(info.proposedManagerAddress),
proposedRewardsAddress: (0, clear_empty_address_js_1.clearEmptyAddress)(info.proposedRewardAddress),
};
}
async getKeys(id, start = 0n, count) {
if (count === undefined) {
const info = await this.getInfo(id);
count = BigInt(info.totalAddedKeys) - start;
}
const keysString = await this.moduleContract.read.getSigningKeys([
id,
start,
count,
]);
return (0, split_keys_js_1.splitKeys)(keysString);
}
async getUnboundKeysCount(id) {
const value = await this.accountingContract.read.getUnbondedKeysCountToEject([id]);
return Number(value);
}
async getOwner(id) {
return this.moduleContract.read.getNodeOperatorOwner([id]);
}
async isOwner(id, address) {
const owner = await this.moduleContract.read.getNodeOperatorOwner([id]);
return (0, viem_1.isAddressEqual)(owner, address) && owner !== viem_1.zeroAddress;
}
async getManagementProperties(id) {
const properties = await this.moduleContract.read.getNodeOperatorManagementProperties([id]);
return {
nodeOperatorId: id,
managerAddress: properties.managerAddress,
rewardsAddress: properties.rewardAddress,
extendedManagerPermissions: properties.extendedManagerPermissions,
};
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_getCurveId_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondBalance_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getLockedBond_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getInfo_decorators = [(0, cache_js_1.Cache)(index_js_1.CACHE_SHORT), (0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getKeys_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)(), (0, cache_js_1.Cache)(index_js_1.CACHE_SHORT)];
_getUnboundKeysCount_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getOwner_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_isOwner_decorators = [(0, logger_js_1.Logger)('Utils:')];
_getManagementProperties_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
__esDecorate(_a, null, _getCurveId_decorators, { kind: "method", name: "getCurveId", static: false, private: false, access: { has: obj => "getCurveId" in obj, get: obj => obj.getCurveId }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondBalance_decorators, { kind: "method", name: "getBondBalance", static: false, private: false, access: { has: obj => "getBondBalance" in obj, get: obj => obj.getBondBalance }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getLockedBond_decorators, { kind: "method", name: "getLockedBond", static: false, private: false, access: { has: obj => "getLockedBond" in obj, get: obj => obj.getLockedBond }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getInfo_decorators, { kind: "method", name: "getInfo", static: false, private: false, access: { has: obj => "getInfo" in obj, get: obj => obj.getInfo }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getKeys_decorators, { kind: "method", name: "getKeys", static: false, private: false, access: { has: obj => "getKeys" in obj, get: obj => obj.getKeys }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getUnboundKeysCount_decorators, { kind: "method", name: "getUnboundKeysCount", static: false, private: false, access: { has: obj => "getUnboundKeysCount" in obj, get: obj => obj.getUnboundKeysCount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getOwner_decorators, { kind: "method", name: "getOwner", static: false, private: false, access: { has: obj => "getOwner" in obj, get: obj => obj.getOwner }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _isOwner_decorators, { kind: "method", name: "isOwner", static: false, private: false, access: { has: obj => "isOwner" in obj, get: obj => obj.isOwner }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getManagementProperties_decorators, { kind: "method", name: "getManagementProperties", static: false, private: false, access: { has: obj => "getManagementProperties" in obj, get: obj => obj.getManagementProperties }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.OperatorSDK = OperatorSDK;
//# sourceMappingURL=operator-sdk.js.map