uiAmountToAmountForInterestBearingMintWithoutSimulation
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
Parameter | Type | Description |
---|---|---|
uiAmount | string | UI Amount (principal plus continuously compounding interest) to be converted back to original principal |
decimals | number | Number of decimals for 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 (hundredths of a percent) before the last update |
currentRate | number | Current 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