@aurigami/sdk 0.3.5 → 0.4.0

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/dist/types.d.ts CHANGED
@@ -46,8 +46,13 @@ export declare type UserMarketDetails = {
46
46
  isCollateral: boolean;
47
47
  maxWithdrawableAmount: TokenAmount;
48
48
  collateralRatio: number;
49
+ underlyingPrice: string;
49
50
  };
50
51
  export declare type PlyAuroraPoolDetails = {
51
52
  totalStakedLiquidity: TokenAmount;
52
53
  apy: string;
53
54
  };
55
+ export declare type HypotheticalStats = {
56
+ newBorrowLimit: CurrencyAmount;
57
+ newBorrowUtilization: number;
58
+ };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.5",
2
+ "version": "0.4.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -60,6 +60,7 @@
60
60
  "@aurigami/contracts": "^1.1.1",
61
61
  "axios": "^0.24.0",
62
62
  "bignumber.js": "^9.0.2",
63
+ "dotenv": "^16.0.0",
63
64
  "ethers": "^5.0.0"
64
65
  }
65
66
  }
package/src/SDK.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  UserMarketDetails,
8
8
  Address,
9
9
  CurrencyAmount,
10
+ HypotheticalStats
10
11
  } from './types';
11
12
  import { AVAX_DEFAULT_PROVIDER_URL, networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
12
13
  import { TransactionResponse } from '@ethersproject/abstract-provider';
@@ -22,7 +23,6 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
22
23
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
23
24
  import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
24
25
  import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
25
- import dummyABI from "./abis/dummy.json";
26
26
 
27
27
  export class SdkRead extends BlockchainEntityRead {
28
28
 
@@ -69,7 +69,10 @@ export class SdkRead extends BlockchainEntityRead {
69
69
  promises.push(moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.depositBalance = res}));
70
70
  promises.push(moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.borrowBalance = res}));
71
71
  promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {userMarketDetail.collateralRatio = res.toNumber()}));
72
- pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider));
72
+ pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
73
+ userMarketDetail.underlyingPrice = res.toString();
74
+ return res;
75
+ }));
73
76
  }
74
77
 
75
78
  promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
@@ -187,6 +190,18 @@ export class SdkRead extends BlockchainEntityRead {
187
190
  userInfo.amount.toString()
188
191
  )
189
192
  }
193
+
194
+ public calcHypotheticalStats(args: {userMarketDetail: UserMarketDetails, currentBorrowLimit: CurrencyAmount, currentBorrowValuation: CurrencyAmount, isEnable: boolean}): HypotheticalStats {
195
+ const deltaBorrowLimit = new BigNumber(args.userMarketDetail.depositBalance.formattedAmount()).multipliedBy(args.userMarketDetail.underlyingPrice).multipliedBy(args.userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
196
+ const newBorrowLimit = args.isEnable ? new BigNumber(args.currentBorrowLimit.amount).plus(deltaBorrowLimit) : new BigNumber(args.currentBorrowLimit.amount).minus(deltaBorrowLimit);
197
+ return {
198
+ newBorrowLimit: {
199
+ amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
200
+ currency: "USD"
201
+ },
202
+ newBorrowUtilization: new BigNumber(args.currentBorrowValuation.amount).div(newBorrowLimit).toNumber()
203
+ }
204
+ }
190
205
  }
191
206
 
192
207
  export class SdkReadWrite extends SdkRead {
package/src/constants.ts CHANGED
@@ -2,6 +2,9 @@ import BigNumber from 'bignumber.js';
2
2
  // import ethers from 'ethers';
3
3
  const ethers = require('ethers');
4
4
  import { Signer } from 'ethers';
5
+ import * as dotenv from "dotenv";
6
+ dotenv.config();
7
+
5
8
  export const AVAX_DEFAULT_PROVIDER_URL =
6
9
  'https://api.avax.network/ext/bc/C/rpc';
7
10
 
@@ -9,7 +12,7 @@ export const AVAX_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
9
12
  AVAX_DEFAULT_PROVIDER_URL
10
13
  );
11
14
 
12
- export const AURORA_DEFAULT_PROVIDER_URL = "https://mainnet.aurora.dev";
15
+ export const AURORA_DEFAULT_PROVIDER_URL = `https://mainnet.aurora.dev/${process.env.AURORA_API_KEY}`;
13
16
 
14
17
  export const AURORA_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
15
18
  AURORA_DEFAULT_PROVIDER_URL
@@ -8,8 +8,7 @@ import { TokenAmount } from "./tokenAmount";
8
8
  import { Address } from "./types";
9
9
  import IUniswapV2PairABI from './abis/IUniswapV2Pair.json';
10
10
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
11
-
12
- const axios = require('axios')
11
+ import axios from 'axios';
13
12
 
14
13
  export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
15
14
  const price = await axios.get(
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { providers, Signer } from 'ethers';
1
+ import type { BigNumber, providers, Signer } from 'ethers';
2
2
  import { TokenAmount } from './tokenAmount';
3
3
 
4
4
  export enum ComptrollerRewardType {
@@ -54,9 +54,15 @@ export type UserMarketDetails = {
54
54
  isCollateral: boolean;
55
55
  maxWithdrawableAmount: TokenAmount;
56
56
  collateralRatio: number;
57
+ underlyingPrice: string;
57
58
  };
58
59
 
59
60
  export type PlyAuroraPoolDetails = {
60
61
  totalStakedLiquidity: TokenAmount;
61
62
  apy: string;
62
- };
63
+ };
64
+
65
+ export type HypotheticalStats = {
66
+ newBorrowLimit: CurrencyAmount;
67
+ newBorrowUtilization: number;
68
+ }