You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
@@ -134,7 +134,6 @@ export function amountToUiAmountWithoutSimulation(
134
134
* @param connection Connection to use
135
135
* @param mint Mint to use for calculations
136
136
* @param amount Amount of tokens to be converted to Ui Amount
137
-
* @param programId SPL Token program account (default: TOKEN_PROGRAM_ID)
138
137
*
139
138
* @return Ui Amount generated
140
139
*/
@@ -175,29 +174,29 @@ export async function amountToUiAmountForMintWithoutSimulation(
175
174
* Convert an amount with interest back to the original amount without interest
176
175
* This implements the same logic as the CPI instruction available in /token/program-2022/src/extension/interest_bearing_mint/mod.rs
177
176
*
178
-
* @param uiAmount UI Amount (principle plus continuously compounding interest) to be converted back to original principle
177
+
* @param uiAmount UI Amount (principal plus continuously compounding interest) to be converted back to original principal
179
178
* @param decimals Number of decimals for the mint
180
179
* @param currentTimestamp Current timestamp in seconds
181
180
* @param lastUpdateTimestamp Last time the interest rate was updated in seconds
182
181
* @param initializationTimestamp Time the interest bearing extension was initialized in seconds
183
182
* @param preUpdateAverageRate Interest rate in basis points (hundredths of a percent) before the last update
184
183
* @param currentRate Current interest rate in basis points
185
184
*
186
-
* In general to calculate the principle from the UI amount, the formula is:
185
+
* In general to calculate the principal from the UI amount, the formula is:
187
186
* P = A / (e^(r * t)) where
188
-
* P = principle
187
+
* P = principal
189
188
* A = UI amount
190
189
* r = annual interest rate (as a decimal, e.g., 5% = 0.05)
191
190
* t = time in years
192
191
*
193
-
* In this case, we are calculating the principle by dividing the UI amount by the total scale factor which is the product of two exponential functions:
192
+
* 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:
194
193
* totalScale = e^(r1 * t1) * e^(r2 * t2)
195
194
* 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,
196
195
* and t2 is the time in years between the last update timestamp and the current timestamp.
197
-
* then to calculate the principle, we divide the UI amount by the total scale factor:
196
+
* then to calculate the principal, we divide the UI amount by the total scale factor:
198
197
* P = A / totalScale
199
198
*
200
-
* @return Original amount (principle) without interest
199
+
* @return Original amount (principal) without interest
201
200
*/
202
201
exportfunctionuiAmountToAmountWithoutSimulation(
203
202
uiAmount: string,
@@ -225,9 +224,9 @@ export function uiAmountToAmountWithoutSimulation(
225
224
// Calculate total scale
226
225
consttotalScale=preUpdateExp*postUpdateExp;
227
226
228
-
// Calculate original principle by dividing the UI amount (principle + interest) by the total scale
229
-
constoriginalPrinciple=uiAmountScaled/totalScale;
230
-
returnBigInt(Math.floor(originalPrinciple));
227
+
// Calculate original principal by dividing the UI amount (principal + interest) by the total scale
228
+
constoriginalprincipal=uiAmountScaled/totalScale;
229
+
returnBigInt(Math.trunc(originalprincipal));
231
230
}
232
231
233
232
/**
@@ -236,7 +235,6 @@ export function uiAmountToAmountWithoutSimulation(
236
235
* @param connection Connection to use
237
236
* @param mint Mint to use for calculations
238
237
* @param uiAmount UI Amount to be converted back to raw amount
239
-
* @param programId SPL Token program account (default: TOKEN_PROGRAM_ID)
240
238
*
241
239
*
242
240
* @return Raw amount
@@ -252,12 +250,11 @@ export async function uiAmountToAmountForMintWithoutSimulation(
0 commit comments