@aurigami/sdk 1.19.1 → 1.19.2

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.19.1",
2
+ "version": "1.19.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/SDK.ts CHANGED
@@ -101,14 +101,16 @@ export class SdkRead extends BlockchainEntityRead {
101
101
  return this._misc.sneakAccounts(accounts, tokenAddresses, dust);
102
102
  }
103
103
 
104
+ public async getLTVAndLiquidationThreshold(userAddr: types.Address) {
105
+ return this._misc.getLTVAndLiquidationThreshold(userAddr);
106
+ }
107
+
104
108
  public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
105
- const miscRead = new MiscRead(this._networkConnection);
106
- return miscRead.getNetApyWithoutIncentive(userAddress);
109
+ return this._misc.getNetApyWithoutIncentive(userAddress);
107
110
  }
108
111
 
109
112
  public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
110
- const miscRead = new MiscRead(this._networkConnection);
111
- return miscRead.getNetApyWithIncentive(userAddress);
113
+ return this._misc.getNetApyWithIncentive(userAddress);
112
114
  }
113
115
 
114
116
  public async setUserNotificationSettings(
@@ -326,6 +326,20 @@ export class MoneyMarketRead extends BlockchainEntityRead {
326
326
  );
327
327
  }
328
328
 
329
+ public async getDepositBorrowValue(userAddress: Address) {
330
+ const [price, depositBalance, borrowBalance] = await Promise.all([
331
+ this.getUnderlyingPrice(),
332
+ this.getUserDepositBalance(userAddress),
333
+ this.getUserBorrowBalance(userAddress),
334
+ ]);
335
+ const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
336
+ const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
337
+ return {
338
+ suppliedValue,
339
+ borrowedValue,
340
+ };
341
+ }
342
+
329
343
  public async getApyWithoutIncentive(userAddress: Address): Promise<Apy> {
330
344
  const [price, depositApy, borrowApy, depositBalance, borrowBalance] = await Promise.all([
331
345
  this.getUnderlyingPrice(),
@@ -332,6 +332,47 @@ export class MiscRead extends BlockchainEntityRead {
332
332
  return res;
333
333
  }
334
334
 
335
+ public async getLTVAndLiquidationThreshold(userAddr: types.Address) {
336
+ let totalSuppliedValue = new BigNumber(0);
337
+ let totalBorrowedValue = new BigNumber(0);
338
+ let collateralValue = new BigNumber(0);
339
+ const assetsIn = await this.env.comptroller.getAssetsIn(userAddr);
340
+ const marketValues = await Promise.all(
341
+ consts.networkAddresses.auTokens.map(async (auToken) => {
342
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
343
+ this._networkConnection,
344
+ auToken.address,
345
+ auToken.underlying
346
+ );
347
+ return Promise.all([
348
+ moneyMarket.getCollateralRatio(),
349
+ moneyMarket.getDepositBorrowValue(userAddr),
350
+ ]);
351
+ })
352
+ );
353
+ consts.networkAddresses.auTokens.forEach(async (auToken, i) => {});
354
+ for (var i = 0; i < marketValues.length; i++) {
355
+ const auToken = consts.networkAddresses.auTokens[i];
356
+ const [collateralRatio, depositBorrowValue] = marketValues[i];
357
+ if (
358
+ assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
359
+ undefined
360
+ ) {
361
+ totalSuppliedValue = totalSuppliedValue.plus(depositBorrowValue.suppliedValue);
362
+ collateralValue = collateralValue.plus(
363
+ depositBorrowValue.suppliedValue.times(collateralRatio)
364
+ );
365
+ }
366
+ totalBorrowedValue = totalBorrowedValue.plus(depositBorrowValue.borrowedValue);
367
+ }
368
+ const ltv = totalBorrowedValue.div(totalSuppliedValue);
369
+ const liquidationThreshold = collateralValue.div(totalSuppliedValue);
370
+ return {
371
+ ltv,
372
+ liquidationThreshold,
373
+ };
374
+ }
375
+
335
376
  public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
336
377
  let sum = new BigNumber(0);
337
378
  let totalSuppliedValue = new BigNumber(0);