@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
47 lines • 2.62 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValidators = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const network_1 = require("../network");
const queries_1 = require("./graphql/queries");
const isTestnet_1 = require("../logic/isTestnet");
const constants_1 = require("../constants");
const staking_1 = require("../logic/staking");
const cache_1 = require("@ledgerhq/live-network/cache");
async function getValidators(currencyId) {
const api = new network_1.AptosAPI(currencyId);
const queryResponse = await cachedValidators(api, currencyId);
const stakingData = queryResponse.data.current_delegator_balances;
const list = await Promise.all(stakingData.map(async (pool) => {
const aptosName = pool.staking_pool_metadata.operator_aptos_name;
const naming = Array.isArray(aptosName) && aptosName.length > 0 && aptosName[0].domain_with_suffix
? aptosName[0].domain_with_suffix
: pool.current_pool_balance.staking_pool_address;
const url = `${constants_1.APTOS_EXPLORER_ACCOUNT_URL}/${pool.current_pool_balance.staking_pool_address}?network=${(0, isTestnet_1.isTestnet)(currencyId) ? "testnet" : "mainnet"}`;
const unblockdata = await api.getNextUnlockTime(pool.current_pool_balance.staking_pool_address);
const nextUnlockTime = unblockdata ? (0, staking_1.formatUnlockTime)(unblockdata) : undefined; //`${30}d ${20}h ${30}m`;
return {
commission: (0, bignumber_js_1.default)(pool.current_pool_balance.operator_commission_percentage).div(100),
activeStake: (0, bignumber_js_1.default)(pool.current_pool_balance.total_coins),
address: pool.current_pool_balance.staking_pool_address,
name: naming,
shares: pool.current_pool_balance.total_shares,
wwwUrl: url,
nextUnlockTime: nextUnlockTime,
};
}));
return list.sort((a, b) => b.activeStake.toNumber() - a.activeStake.toNumber());
}
exports.getValidators = getValidators;
const fetchValidatorsData = async (api, _currencyId) => {
const query = queries_1.GetCurrentDelegatorBalancesData;
return await api.apolloClient.query({
query: query,
fetchPolicy: "network-only",
});
};
const cachedValidators = (0, cache_1.makeLRUCache)(fetchValidatorsData, (_api, currencyId) => currencyId, (0, cache_1.minutes)(30));
//# sourceMappingURL=validators.js.map