UNPKG

@kyve/core-beta

Version:

🚀 The base KYVE node implementation.

65 lines (64 loc) • 3.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBalances = void 0; const constants_1 = require("@kyve/sdk-beta/dist/constants"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const __1 = require("../.."); /** * getBalances tries to retrieve the $KYVE balance of the staker account, the $KYVE * balance of the valaccount and the balance of the storage provider which * can be of any currency for metrics * * @method getBalances * @param {Node} this * @return {Promise<void>} */ async function getBalances() { var _a, _b, _c, _d; try { this.logger.debug(`this.client.nativeClient.getBalance(${this.staker},${constants_1.DENOM})`); const stakerBalanceRaw = await this.client.nativeClient.getBalance(this.staker, constants_1.DENOM); this.logger.debug(JSON.stringify(stakerBalanceRaw)); const stakerBalance = new bignumber_js_1.default(stakerBalanceRaw.amount) .dividedBy(new bignumber_js_1.default(10).exponentiatedBy(constants_1.KYVE_DECIMALS)) .toNumber(); this.m.balance_staker.set(stakerBalance); } catch (err) { this.logger.error(`Failed to get $KYVE balance of staker`); this.logger.error((0, __1.standardizeJSON)(err)); } try { this.logger.debug(`this.client.nativeClient.getBalance(${this.client.account.address},${constants_1.DENOM})`); const valaccountBalanceRaw = await this.client.nativeClient.getBalance(this.client.account.address, constants_1.DENOM); this.logger.debug(JSON.stringify(valaccountBalanceRaw)); const valaccountBalance = new bignumber_js_1.default(valaccountBalanceRaw.amount) .dividedBy(new bignumber_js_1.default(10).exponentiatedBy(constants_1.KYVE_DECIMALS)) .toNumber(); this.m.balance_valaccount.set(valaccountBalance); } catch (err) { this.logger.error(`Failed to get $KYVE balance of valaccount`); this.logger.error((0, __1.standardizeJSON)(err)); } try { // get current storage provider defined on pool this.logger.debug(`storageProviderFactory(${(_b = (_a = this.pool.data) === null || _a === void 0 ? void 0 : _a.current_storage_provider_id) !== null && _b !== void 0 ? _b : 0}, $STORAGE_PRIV)`); const storageProvider = await this.storageProviderFactory((_d = (_c = this.pool.data) === null || _c === void 0 ? void 0 : _c.current_storage_provider_id) !== null && _d !== void 0 ? _d : 0); this.logger.debug(`this.storageProvider.getBalance()`); const storageProviderBalanceRaw = await storageProvider.getBalance(); this.logger.debug(JSON.stringify(storageProviderBalanceRaw)); const storageProviderBalance = new bignumber_js_1.default(storageProviderBalanceRaw) .dividedBy(new bignumber_js_1.default(10).exponentiatedBy(storageProvider.decimals)) .toNumber(); this.m.balance_storage_provider.set(storageProviderBalance); } catch (err) { this.logger.error(`Failed to get balance of storage provider`); this.logger.error((0, __1.standardizeJSON)(err)); } } exports.getBalances = getBalances;