@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
184 lines • 13 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.AccountingSDK = void 0;
const lido_ethereum_sdk_1 = require("@lidofinance/lido-ethereum-sdk");
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 convert_shares_js_1 = require("./convert-shares.js");
let AccountingSDK = (() => {
var _a;
let _classSuper = csm_sdk_module_js_1.CsmSDKModule;
let _instanceExtraInitializers = [];
let _get_stethContract_decorators;
let _getStethPoolData_decorators;
let _getStethPoolDataByBlockNumbers_decorators;
let _sharesToEth_decorators;
let _ethToShares_decorators;
let _getBondAmountByKeysCountETH_decorators;
let _getBondAmountByKeysCountWstETH_decorators;
let _getCurve_decorators;
let _getKeysCountByBondAmount_decorators;
let _getBondForNextKeysETH_decorators;
let _getBondForNextKeysWstETH_decorators;
let _getBondForNextKeysPerToken_decorators;
return _a = class AccountingSDK extends _classSuper {
get accountingContract() {
return this.core.contractAccounting;
}
get stethContract() {
return this.core.getContractWithAbi(index_js_1.CONTRACT_NAMES.stETH, lido_ethereum_sdk_1.stethSharesAbi);
}
async getStethPoolData(blockNumber) {
const effectiveBlockNumber = this.core.skipHistoricalCalls
? undefined
: blockNumber;
const [totalPooledEther, totalShares] = await Promise.all([
this.stethContract.read.getTotalPooledEther({
blockNumber: effectiveBlockNumber,
}),
this.stethContract.read.getTotalShares({
blockNumber: effectiveBlockNumber,
}),
]);
return { totalPooledEther, totalShares };
}
async getStethPoolDataByBlockNumbers(blockNumbers) {
return new Map(await Promise.all(blockNumbers.map(async (blockNumber) => [blockNumber, await this.getStethPoolData(blockNumber)])));
}
async sharesToEth(amount, blockNumber) {
const poolData = await this.getStethPoolData(blockNumber);
return (0, convert_shares_js_1.convertSharesToEth)(amount, poolData);
}
async ethToShares(amount, blockNumber) {
const poolData = await this.getStethPoolData(blockNumber);
return (0, convert_shares_js_1.convertEthToShares)(amount, poolData);
}
async getBondAmountByKeysCountETH({ curveId, keysCount, }) {
return this.accountingContract.read.getBondAmountByKeysCount([
keysCount,
curveId,
]);
}
async getBondAmountByKeysCountWstETH({ curveId, keysCount, }) {
return this.accountingContract.read.getBondAmountByKeysCountWstETH([
keysCount,
curveId,
]);
}
async getBondAmountByKeysCountPerToken(props) {
const [eth, wsteth] = await Promise.all([
this.getBondAmountByKeysCountETH(props),
this.getBondAmountByKeysCountWstETH(props),
]);
return {
[index_js_1.TOKENS.eth]: eth,
[index_js_1.TOKENS.steth]: eth,
[index_js_1.TOKENS.wsteth]: wsteth,
};
}
async getCurve(curveId) {
return this.accountingContract.read.getCurveInfo([curveId]);
}
async getKeysCountByBondAmount({ amount, curveId, }) {
return this.accountingContract.read.getKeysCountByBondAmount([
amount,
curveId,
]);
}
async getBondForNextKeysETH({ nodeOperatorId, keysCount, }) {
return this.accountingContract.read.getRequiredBondForNextKeys([
nodeOperatorId,
keysCount,
]);
}
async getBondForNextKeysWstETH({ nodeOperatorId, keysCount, }) {
return this.accountingContract.read.getRequiredBondForNextKeysWstETH([
nodeOperatorId,
keysCount,
]);
}
async getBondForNextKeysPerToken(props) {
const [eth, wsteth] = await Promise.all([
this.getBondForNextKeysETH(props),
this.getBondForNextKeysWstETH(props),
]);
return {
[index_js_1.TOKENS.eth]: eth,
[index_js_1.TOKENS.steth]: eth,
[index_js_1.TOKENS.wsteth]: wsteth,
};
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_get_stethContract_decorators = [(0, cache_js_1.Cache)(index_js_1.CACHE_LONG)];
_getStethPoolData_decorators = [(0, logger_js_1.Logger)('Views:'), (0, cache_js_1.Cache)(index_js_1.CACHE_MID), (0, error_handler_js_1.ErrorHandler)()];
_getStethPoolDataByBlockNumbers_decorators = [(0, logger_js_1.Logger)('Utils:')];
_sharesToEth_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_ethToShares_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondAmountByKeysCountETH_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondAmountByKeysCountWstETH_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getCurve_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getKeysCountByBondAmount_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondForNextKeysETH_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondForNextKeysWstETH_decorators = [(0, logger_js_1.Logger)('Views:'), (0, error_handler_js_1.ErrorHandler)()];
_getBondForNextKeysPerToken_decorators = [(0, logger_js_1.Logger)('Utils:'), (0, error_handler_js_1.ErrorHandler)()];
__esDecorate(_a, null, _get_stethContract_decorators, { kind: "getter", name: "stethContract", static: false, private: false, access: { has: obj => "stethContract" in obj, get: obj => obj.stethContract }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getStethPoolData_decorators, { kind: "method", name: "getStethPoolData", static: false, private: false, access: { has: obj => "getStethPoolData" in obj, get: obj => obj.getStethPoolData }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getStethPoolDataByBlockNumbers_decorators, { kind: "method", name: "getStethPoolDataByBlockNumbers", static: false, private: false, access: { has: obj => "getStethPoolDataByBlockNumbers" in obj, get: obj => obj.getStethPoolDataByBlockNumbers }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _sharesToEth_decorators, { kind: "method", name: "sharesToEth", static: false, private: false, access: { has: obj => "sharesToEth" in obj, get: obj => obj.sharesToEth }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _ethToShares_decorators, { kind: "method", name: "ethToShares", static: false, private: false, access: { has: obj => "ethToShares" in obj, get: obj => obj.ethToShares }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondAmountByKeysCountETH_decorators, { kind: "method", name: "getBondAmountByKeysCountETH", static: false, private: false, access: { has: obj => "getBondAmountByKeysCountETH" in obj, get: obj => obj.getBondAmountByKeysCountETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondAmountByKeysCountWstETH_decorators, { kind: "method", name: "getBondAmountByKeysCountWstETH", static: false, private: false, access: { has: obj => "getBondAmountByKeysCountWstETH" in obj, get: obj => obj.getBondAmountByKeysCountWstETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getCurve_decorators, { kind: "method", name: "getCurve", static: false, private: false, access: { has: obj => "getCurve" in obj, get: obj => obj.getCurve }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getKeysCountByBondAmount_decorators, { kind: "method", name: "getKeysCountByBondAmount", static: false, private: false, access: { has: obj => "getKeysCountByBondAmount" in obj, get: obj => obj.getKeysCountByBondAmount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondForNextKeysETH_decorators, { kind: "method", name: "getBondForNextKeysETH", static: false, private: false, access: { has: obj => "getBondForNextKeysETH" in obj, get: obj => obj.getBondForNextKeysETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondForNextKeysWstETH_decorators, { kind: "method", name: "getBondForNextKeysWstETH", static: false, private: false, access: { has: obj => "getBondForNextKeysWstETH" in obj, get: obj => obj.getBondForNextKeysWstETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getBondForNextKeysPerToken_decorators, { kind: "method", name: "getBondForNextKeysPerToken", static: false, private: false, access: { has: obj => "getBondForNextKeysPerToken" in obj, get: obj => obj.getBondForNextKeysPerToken }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.AccountingSDK = AccountingSDK;
//# sourceMappingURL=accounting-sdk.js.map