UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

38 lines (37 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculationRewardCardinal = void 0; const anchor_1 = require("@project-serum/anchor"); const calculationRewardCardinal = ({ stakeEntry, rewardDistributor, rewardEntry, currentSeconds }) => { if (!stakeEntry || stakeEntry.pool.toString() !== rewardDistributor.stakePool.toString()) { return 0; } // const rewardSecondsReceived = // rewardEntry.rewardSecondsReceived || new BN(0); const multiplier = (rewardEntry === null || rewardEntry === void 0 ? void 0 : rewardEntry.multiplier) || rewardDistributor.defaultMultiplier; const UTCNow = stakeEntry.cooldownStartSeconds ? new anchor_1.BN(stakeEntry.cooldownStartSeconds) : new anchor_1.BN(currentSeconds); let rewardSeconds = UTCNow .sub(new anchor_1.BN(stakeEntry.lastUpdatedAt)) .mul(new anchor_1.BN(stakeEntry.amount)) .add(new anchor_1.BN(stakeEntry.totalStakeSeconds)); if (rewardDistributor.maxRewardSecondsReceived) { rewardSeconds = anchor_1.BN.min(rewardSeconds, new anchor_1.BN(rewardDistributor.maxRewardSecondsReceived)); } const rewardAmountToReceive = rewardSeconds // .sub(new BN(rewardSecondsReceived)) .div(new anchor_1.BN(rewardDistributor.rewardDurationSeconds)) .mul(new anchor_1.BN(rewardDistributor.rewardAmount)) .mul(new anchor_1.BN(multiplier)) .div(new anchor_1.BN(10).pow(new anchor_1.BN(rewardDistributor.multiplierDecimals))).toNumber(); const nextRewardsIn = new anchor_1.BN(rewardDistributor.rewardDurationSeconds).sub(UTCNow .sub(new anchor_1.BN(stakeEntry.lastStakedAt)) .add(new anchor_1.BN(stakeEntry.totalStakeSeconds)) .mod(new anchor_1.BN(rewardDistributor.rewardDurationSeconds))); return rewardAmountToReceive; }; exports.calculationRewardCardinal = calculationRewardCardinal;