gill

uiAmountToAmountForInterestBearingMintWithoutSimulation

function uiAmountToAmountForInterestBearingMintWithoutSimulation(
   uiAmount, 
   decimals, 
   currentTimestamp, 
   lastUpdateTimestamp, 
   initializationTimestamp, 
   preUpdateAverageRate, 
   currentRate): bigint;

Convert an amount with interest back to the original amount without interest This implements the same logic as the CPI instruction available in /token/program-2022/src/extension/interest_bearing_mint/mod.rs

Parameters

ParameterTypeDescription
uiAmountstringUI Amount (principal plus continuously compounding interest) to be converted back to original principal
decimalsnumberNumber of decimals for 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 (hundredths of a percent) before the last update
currentRatenumberCurrent interest rate in basis points In general to calculate the principal from the UI amount, the formula is: P = A / (e^(r * t)) where P = principal A = UI amount r = annual interest rate (as a decimal, e.g., 5% = 0.05) t = time in years In this case, we are calculating the principal by dividing the UI amount by the total scale factor which is the product of two exponential functions: totalScale = e^(r1 * t1) * e^(r2 * t2) where r1 is the pre-update average rate, r2 is the current rate, t1 is the time in years between the initialization timestamp and the last update timestamp, and t2 is the time in years between the last update timestamp and the current timestamp. then to calculate the principal, we divide the UI amount by the total scale factor: P = A / totalScale

Returns

bigint

Original amount (principal) without interest

On this page