@reflectmoney/stable.ts 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -177,5 +177,12 @@ class ReflectTokenisedBond {
177
177
  return ix;
178
178
  });
179
179
  }
180
+ getVault(vaultId) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ const vault = PdaClient_1.PdaClient.deriveLpVault(vaultId);
183
+ const data = yield reflect_tokenised_bonds_1.Vault.fromAccountAddress(this.connection, vault);
184
+ return data;
185
+ });
186
+ }
180
187
  }
181
188
  exports.ReflectTokenisedBond = ReflectTokenisedBond;
@@ -280,7 +280,7 @@ class LstStablecoin extends Stablecoin_1.Stablecoin {
280
280
  *
281
281
  * @returns Promise resolving to the USD exchange rate as a number
282
282
  */
283
- getUsdExchangeRate() {
283
+ getBaseUsdExchangeRate() {
284
284
  return __awaiter(this, void 0, void 0, function* () {
285
285
  const usdBalances = yield Promise.all(this
286
286
  .collaterals
@@ -312,5 +312,18 @@ class LstStablecoin extends Stablecoin_1.Stablecoin {
312
312
  return totalUsdValue;
313
313
  });
314
314
  }
315
+ getReceiptUsdExchangeRate() {
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ const baseUsdExchangeRate = yield this.getBaseUsdExchangeRate();
318
+ const vault = yield this.tokenisedBondsClient.getVault(this.index);
319
+ const { amount: poolDeposits } = yield (0, spl_token_1.getAccount)(this.connection, classes_1.PdaClient.deriveLpVaultPool(this.index), "confirmed");
320
+ const { supply: receiptSupply, decimals: receiptDecimals } = yield (0, spl_token_1.getMint)(this.connection, vault.receiptTokenMint, "confirmed");
321
+ const exchangeRate = new bn_js_1.default(poolDeposits.toString()) // with deposit decimals equal receipt decimals
322
+ .mul(new bn_js_1.default(baseUsdExchangeRate)) // with exchange rate precision
323
+ .div(new bn_js_1.default(receiptSupply.toString())) // with receipt decimals, cancel out deposit decimals
324
+ .toNumber();
325
+ return exchangeRate;
326
+ });
327
+ }
315
328
  }
316
329
  exports.LstStablecoin = LstStablecoin;
@@ -254,7 +254,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
254
254
  *
255
255
  * @returns Promise resolving to the USD exchange rate as a number
256
256
  */
257
- getUsdExchangeRate() {
257
+ getBaseUsdExchangeRate() {
258
258
  return __awaiter(this, void 0, void 0, function* () {
259
259
  const { scaledBalance, balanceType } = this
260
260
  .driftClient
@@ -275,5 +275,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
275
275
  return exchangeRate.toNumber();
276
276
  });
277
277
  }
278
+ getReceiptUsdExchangeRate() {
279
+ return __awaiter(this, void 0, void 0, function* () {
280
+ return this.getBaseUsdExchangeRate();
281
+ });
282
+ }
278
283
  }
279
284
  exports.UsdcPlusStablecoin = UsdcPlusStablecoin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {