@aurigami/sdk 1.0.3 → 1.1.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
@@ -22,6 +22,8 @@ export declare type MoneyMarketDetails = {
22
22
  borrowApy: number;
23
23
  borrowPlyApy: number;
24
24
  collateralRatio: number;
25
+ depositPlyPerWeek: TokenAmount;
26
+ BorrowPlyPerWeek: TokenAmount;
25
27
  };
26
28
  export declare type UserDetails = {
27
29
  markets: UserMarketDetails[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.3",
2
+ "version": "1.1.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -57,7 +57,7 @@
57
57
  "typescript": "^4.5.4"
58
58
  },
59
59
  "dependencies": {
60
- "@aurigami/contracts": "2.4.4",
60
+ "@aurigami/contracts": "2.5.0-beta",
61
61
  "axios": "^0.24.0",
62
62
  "bignumber.js": "^9.0.2",
63
63
  "dotenv": "^16.0.0",
@@ -8,7 +8,7 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
8
8
  import EthRepayHelperABI from "@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json"
9
9
  import { AuErc20, AuETH, AuriLens, Comptroller, EthRepayHelper } from "@aurigami/contracts/typechain";
10
10
  import { TransactionResponse } from '@ethersproject/abstract-provider';
11
- import { networkAddresses, ETHAddress, ONE_YEAR, INF } from "./constants";
11
+ import { networkAddresses, ETHAddress, ONE_YEAR, INF, ONE_DAY } from "./constants";
12
12
  import BigNumber from "bignumber.js";
13
13
  import { decimalFactor, isSameAddress, calcLMRewardApr } from './helpers';
14
14
  import { Token, PLYToken } from './token';
@@ -169,7 +169,15 @@ export class MoneyMarketRead extends BlockchainEntityRead {
169
169
  depositPlyApy: depositPlyApy.toNumber(),
170
170
  borrowApy: borrowAPY!,
171
171
  borrowPlyApy: borrowPlyApy.toNumber(),
172
- collateralRatio: collateralRatio!
172
+ collateralRatio: collateralRatio!,
173
+ depositPlyPerWeek: new TokenAmount(
174
+ PLYToken,
175
+ rewardSpeeds!.plyRewardSupplySpeed.mul(ONE_DAY).mul(7).toString()
176
+ ),
177
+ BorrowPlyPerWeek: new TokenAmount(
178
+ PLYToken,
179
+ rewardSpeeds!.plyRewardBorrowSpeed.mul(ONE_DAY).mul(7).toString()
180
+ ),
173
181
  };
174
182
  }
175
183
 
package/src/constants.ts CHANGED
@@ -47,6 +47,16 @@ export const networkAddresses: NetworkAddresses = {
47
47
  name: "auWNEAR",
48
48
  address: '0xaE4fac24dCdAE0132C6d04f564dCf059616E9423'.toLowerCase(),
49
49
  underlying: '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase()
50
+ },
51
+ {
52
+ name: "auSTNEAR",
53
+ address: "0x3195949f267702723bc614cAE037cdc8D1E94786".toLowerCase(),
54
+ underlying: '0x07f9f7f963c5cd2bbffd30ccfb964be114332e30'.toLowerCase()
55
+ },
56
+ {
57
+ name: "auAURORA",
58
+ address: "0x8888682E24dd4Df7B7Ff2B91fccB575737E433bf".toLowerCase(),
59
+ underlying: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
50
60
  }
51
61
  ],
52
62
  misc: {
@@ -60,6 +70,7 @@ export const networkAddresses: NetworkAddresses = {
60
70
  tokens: {
61
71
  AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
62
72
  PLY: "0x981bD5832EAB9C8F607940E0e9faCBf8C09ee20a".toLowerCase(),
73
+ stNEAR: "0x07f9f7f963c5cd2bbffd30ccfb964be114332e30".toLowerCase(),
63
74
  AURPLY: dummyAddress.toLowerCase() // This is dummy
64
75
  }
65
76
  }
@@ -1,5 +1,5 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { Contract, providers, BigNumber as BN } from "ethers";
2
+ import { Contract, providers, BigNumber as BN, ethers } from "ethers";
3
3
  import { networkAddresses } from "./constants";
4
4
  import OracleABI from "./abis/Oracle.json";
5
5
  import { isSameAddress, decimalFactor, getDecimal } from "./helpers";
@@ -21,11 +21,11 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
21
21
  return new BigNumber(price[id].usd)
22
22
  }
23
23
 
24
- export async function fetchPriceFromCoingecko(address: Address): Promise<BigNumber> {
25
- if (isSameAddress(address, networkAddresses.tokens.AURORA)) {
24
+ export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
25
+ if (isSameAddress(id, networkAddresses.tokens.AURORA)) {
26
26
  return fetchPriceFromCoingeckoAPI('aurora-near');
27
27
  } else {
28
- throw Error(`Unknown token ${address} in fetchPriceFromCoingecko`);
28
+ throw Error(`Unknown token ${id} in fetchPriceFromCoingecko`);
29
29
  }
30
30
  }
31
31
 
@@ -94,8 +94,20 @@ export async function fetchUnderlyingTokensPrices(provider: providers.Provider):
94
94
  })
95
95
  }
96
96
 
97
+ export async function fetchStNEARPrice(): Promise<BigNumber> {
98
+ const ratioPromise = axios.get("https://validators.narwallets.com/metrics_json").then((res) => res.data);
99
+ const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
100
+ const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([ratioPromise, nearPricePromise]);
101
+ const ratio = new BigNumber(ratioRes.st_near_price);
102
+ return ratio.multipliedBy(nearPrice)
103
+ }
104
+
97
105
  export async function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
98
106
  if (hardcodePLYPrice && isSameAddress(address, networkAddresses.tokens.PLY)) return new BigNumber(0);
107
+
108
+ if (isSameAddress(address, networkAddresses.tokens.stNEAR)) return fetchStNEARPrice();
109
+ if (isSameAddress(address, networkAddresses.tokens.AURORA)) return fetchPriceFromCoingecko(address);
110
+
99
111
  const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
100
112
  return isSameAddress(auToken.underlying, address)
101
113
  });
package/src/types.ts CHANGED
@@ -26,6 +26,8 @@ export type MoneyMarketDetails = {
26
26
  borrowApy: number;
27
27
  borrowPlyApy: number;
28
28
  collateralRatio: number;
29
+ depositPlyPerWeek: TokenAmount;
30
+ BorrowPlyPerWeek: TokenAmount;
29
31
  };
30
32
 
31
33
  export type UserDetails = {