UNPKG

@substrate/api-sidecar

Version:

REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.

88 lines (87 loc) 3.69 kB
import BN from 'bn.js'; /** * Represents a vesting schedule with the essential fields needed for calculations. */ export interface IVestingSchedule { /** Total amount of tokens locked at the start of vesting */ locked: BN; /** Number of tokens that unlock per block */ perBlock: BN; /** Block number when vesting/unlocking begins */ startingBlock: BN; } /** * Result of vesting calculation for a single schedule. */ export interface IVestingCalculationResult { /** Amount that has vested based on time elapsed */ vested: BN; /** Block number when vesting will be complete */ endBlock: BN; } /** * Calculate the amount that has vested for a single vesting schedule. * * The calculation follows the formula used in the vesting pallet: * - If currentBlock <= startingBlock: nothing is vested yet * - Otherwise: vested = min(blocksPassed * perBlock, locked) * * Note: This is the theoretical vested amount based on time. The actual * claimable amount depends on the on-chain lock state (see calculateVestedClaimable). * * @param currentBlock - The block number to calculate vested amount at * @param schedule - The vesting schedule containing locked, perBlock, and startingBlock * @returns The amount that has vested at the given block */ export declare const calculateVested: (currentBlock: BN, schedule: IVestingSchedule) => BN; /** * Calculate the block number when a vesting schedule will be fully vested. * * The end block is calculated as: startingBlock + (locked / perBlock) * * @param schedule - The vesting schedule * @returns The block number when vesting completes */ export declare const calculateEndBlock: (schedule: IVestingSchedule) => BN; /** * Calculate the total vested amount across multiple vesting schedules. * * @param currentBlock - The block number to calculate vested amounts at * @param schedules - Array of vesting schedules * @returns The total amount that has vested across all schedules (vestedBalance) */ export declare const calculateTotalVested: (currentBlock: BN, schedules: IVestingSchedule[]) => BN; /** * Calculate the total locked amount across multiple vesting schedules. * * @param schedules - Array of vesting schedules * @returns The total locked amount across all schedules (vestingTotal) */ export declare const calculateVestingTotal: (schedules: IVestingSchedule[]) => BN; /** * Calculate the actual claimable amount that can be unlocked. * * This follows the polkadot-js formula: * vestedClaimable = vestingLocked - (vestingTotal - vestedBalance) * * Where: * - vestingLocked: actual on-chain lock amount from balances.locks * - vestingTotal: sum of all locked amounts from vesting schedules * - vestedBalance: sum of all vested amounts from vesting schedules * * The difference accounts for previous claims that reduced the on-chain lock. * * @param vestingLocked - The actual on-chain vesting lock amount * @param vestingTotal - Total locked across all vesting schedules * @param vestedBalance - Total vested across all vesting schedules * @returns The amount that can actually be claimed right now */ export declare const calculateVestedClaimable: (vestingLocked: BN, vestingTotal: BN, vestedBalance: BN) => BN; /** * Calculate vested amounts for multiple schedules, returning per-schedule results. * * @param currentBlock - The block number to calculate vested amounts at * @param schedules - Array of vesting schedules * @returns Array of calculation results with vested amount and end block for each schedule */ export declare const calculateVestingDetails: (currentBlock: BN, schedules: IVestingSchedule[]) => IVestingCalculationResult[];