harb/kraiken-lib/src/staking.ts

32 lines
909 B
TypeScript
Raw Normal View History

2025-10-01 14:43:55 +02:00
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');
2025-10-01 14:43:55 +02:00
}
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;
}