@moonwell-fi/moonwell-sdk
Version:
TypeScript Interface for Moonwell
42 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStakingInfo = getStakingInfo;
const index_js_1 = require("../../common/index.js");
const index_js_2 = require("../../environments/index.js");
async function getStakingInfo(client, args) {
const environments = (0, index_js_1.getEnvironmentsFromArgs)(client, args);
const envsWithStaking = environments.filter((env) => env.config.contracts.stakingToken);
const envStakingInfo = await Promise.all(envsWithStaking.map((environment) => {
const homeEnvironment = Object.values(index_js_2.publicEnvironments).find((e) => e.custom?.governance?.chainIds?.includes(environment.chainId)) || environment;
return Promise.all([
environment.contracts.views?.read.getStakingInfo(),
homeEnvironment.contracts.views?.read.getGovernanceTokenPrice(),
]);
}));
const result = envsWithStaking.flatMap((curr, index) => {
const token = curr.config.tokens[curr.config.contracts.governanceToken];
const stakingToken = curr.config.tokens[curr.config.contracts.stakingToken];
const { cooldown, distributionEnd, emissionPerSecond: emissionPerSecondRaw, totalSupply: totalSupplyRaw, unstakeWindow, } = envStakingInfo[index]?.[0];
const governanceTokenPriceRaw = envStakingInfo[index]?.[1];
const governanceTokenPrice = new index_js_1.Amount(governanceTokenPriceRaw, 18);
const totalSupply = new index_js_1.Amount(totalSupplyRaw, 18);
const emissionPerSecond = new index_js_1.Amount(emissionPerSecondRaw, 18);
const emissionPerYear = emissionPerSecond.value * index_js_1.SECONDS_PER_DAY * index_js_1.DAYS_PER_YEAR;
const apr = ((emissionPerYear + totalSupply.value) / totalSupply.value - 1) * 100;
const stakingInfo = {
apr,
chainId: curr.chainId,
cooldown: Number(cooldown),
distributionEnd: Number(distributionEnd),
token,
tokenPrice: governanceTokenPrice.value,
stakingToken,
totalSupply,
totalSupplyUSD: totalSupply.value * governanceTokenPrice.value,
unstakeWindow: Number(unstakeWindow),
};
return stakingInfo;
});
return result;
}
//# sourceMappingURL=getStakingInfo.js.map