amountToUiAmountForInterestBearingMintWithoutSimulation
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
Parameter | Type | Description |
---|---|---|
amount | bigint | Amount of tokens to be converted |
decimals | number | Number of decimals of the mint |
currentTimestamp | number | Current timestamp in seconds |
lastUpdateTimestamp | number | Last time the interest rate was updated in seconds |
initializationTimestamp | number | Time the interest bearing extension was initialized in seconds |
preUpdateAverageRate | number | Interest rate in basis points (1 basis point = 0.01%) before last update |
currentRate | number | Current interest rate in basis points |
Returns
string
Amount scaled by accrued interest as a string with appropriate decimal places