gill

amountToUiAmountForInterestBearingMintWithoutSimulation

function amountToUiAmountForInterestBearingMintWithoutSimulation(
   amount, 
   decimals, 
   currentTimestamp, 
   lastUpdateTimestamp, 
   initializationTimestamp, 
   preUpdateAverageRate, 
   currentRate): string;

Convert amount to UiAmount for a mint with interest bearing extension without simulating a transaction This implements the same logic as the CPI instruction available in /token/program-2022/src/extension/interest_bearing_mint/mod.rs In general to calculate compounding interest over a period of time, the formula is: A = P * e^(r * t) where A = final amount after interest P = principal amount (initial investment) r = annual interest rate (as a decimal, e.g., 5% = 0.05) t = time in years e = mathematical constant (~2.718)

In this case, we are calculating the total scale factor for the interest bearing extension which is the product of two exponential functions: totalScale = e^(r1 * t1) * e^(r2 * t2) where r1 and r2 are the interest rates before and after the last update, and t1 and t2 are the times in years between the initialization timestamp and the last update timestamp, and between the last update timestamp and the current timestamp.

Parameters

ParameterTypeDescription
amountbigintAmount of tokens to be converted
decimalsnumberNumber of decimals of the mint
currentTimestampnumberCurrent timestamp in seconds
lastUpdateTimestampnumberLast time the interest rate was updated in seconds
initializationTimestampnumberTime the interest bearing extension was initialized in seconds
preUpdateAverageRatenumberInterest rate in basis points (1 basis point = 0.01%) before last update
currentRatenumberCurrent interest rate in basis points

Returns

string

Amount scaled by accrued interest as a string with appropriate decimal places

On this page