All files staking.ts

100% Statements 27/27
100% Branches 8/8
100% Functions 2/2
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x   1x 6x 6x 6x 6x 6x 6x 6x 1x 1x   5x 5x 5x 6x 6x   1x 7x 7x 7x 7x 7x 7x 7x   4x 4x 4x  
const SECONDS_IN_YEAR = 365 * 24 * 60 * 60;
 
export function calculateSnatchShortfall(
  outstandingStake: bigint,
  desiredStakeShares: bigint,
  stakeTotalSupply: bigint,
  capNumerator: bigint = 2n,
  capDenominator: bigint = 10n
): bigint {
  if (capDenominator === 0n) {
    throw new Error('capDenominator must be greater than zero');
  }
 
  const cap = (stakeTotalSupply * capNumerator) / capDenominator;
  const required = outstandingStake + desiredStakeShares;
  const delta = required - cap;
  return delta > 0n ? delta : 0n;
}
 
export function isPositionDelinquent(
  lastTaxTimestamp: number,
  taxRate: number,
  referenceTimestamp: number = Math.floor(Date.now() / 1000),
  secondsInYear: number = SECONDS_IN_YEAR
): boolean {
  const rate = Number(taxRate);
  if (rate <= 0) return false;
 
  const allowance = secondsInYear / rate;
  return referenceTimestamp - lastTaxTimestamp > allowance;
}