@aurigami/sdk 1.8.5 → 1.9.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.
Files changed (30) hide show
  1. package/dist/SDK.d.ts +1 -1
  2. package/dist/helpers/priceFetcher.d.ts +1 -0
  3. package/dist/index.d.ts +1 -1
  4. package/dist/sdk.cjs.development.js +151 -87
  5. package/dist/sdk.cjs.development.js.map +1 -1
  6. package/dist/sdk.cjs.production.min.js +1 -1
  7. package/dist/sdk.cjs.production.min.js.map +1 -1
  8. package/dist/sdk.esm.js +151 -88
  9. package/dist/sdk.esm.js.map +1 -1
  10. package/package.json +2 -2
  11. package/src/SDK.ts +1 -1
  12. package/src/entities/tokenAmount.ts +4 -2
  13. package/src/helpers/priceFetcher.ts +35 -3
  14. package/src/index.ts +1 -1
  15. package/src/{contracts → interactors}/MoneyMarket.ts +1 -1
  16. /package/dist/{contracts → interactors}/Airdrop.d.ts +0 -0
  17. /package/dist/{contracts → interactors}/MoneyMarket.d.ts +0 -0
  18. /package/dist/{contracts → interactors}/Multicall.d.ts +0 -0
  19. /package/dist/{contracts → interactors}/Papermill.d.ts +0 -0
  20. /package/dist/{contracts → interactors}/Referral.d.ts +0 -0
  21. /package/dist/{contracts → interactors}/Staking.d.ts +0 -0
  22. /package/dist/{contracts → interactors}/index.d.ts +0 -0
  23. /package/dist/{contracts → interactors}/misc.d.ts +0 -0
  24. /package/src/{contracts → interactors}/Airdrop.ts +0 -0
  25. /package/src/{contracts → interactors}/Multicall.ts +0 -0
  26. /package/src/{contracts → interactors}/Papermill.ts +0 -0
  27. /package/src/{contracts → interactors}/Referral.ts +0 -0
  28. /package/src/{contracts → interactors}/Staking.ts +0 -0
  29. /package/src/{contracts → interactors}/index.ts +0 -0
  30. /package/src/{contracts → interactors}/misc.ts +0 -0
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.5",
2
+ "version": "1.9.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -70,4 +70,4 @@
70
70
  "jest": {
71
71
  "testURL": "https://app.aurigami.finance"
72
72
  }
73
- }
73
+ }
package/src/SDK.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { ALL_STAKING_POOLS } from './consts';
4
- import { MiscRead, StakingRead, StakingReadWrite } from './contracts';
5
4
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
5
+ import { MiscRead, StakingRead, StakingReadWrite } from './interactors';
6
6
  import * as types from './types';
7
7
 
8
8
  export class SdkRead extends BlockchainEntityRead {
@@ -17,8 +17,10 @@ export class TokenAmount {
17
17
  }
18
18
 
19
19
  public formattedAmount(decimal?: number, fmt?: BigNumber.Format): string {
20
- if (decimal && fmt) {
21
- return new BigNumber(this.rawAmnt).div(decimalFactor(decimal)).toFormat(decimal, fmt);
20
+ if (decimal !== undefined && fmt !== undefined) {
21
+ return new BigNumber(this.rawAmnt)
22
+ .div(decimalFactor(this.token.decimals))
23
+ .toFormat(decimal, fmt);
22
24
  }
23
25
 
24
26
  return new BigNumber(this.rawAmnt).div(decimalFactor(this.token.decimals)).toString();
@@ -18,10 +18,14 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
18
18
  const price = await axios
19
19
  .get(`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`)
20
20
  .then((res: any) => {
21
- return res.data;
21
+ return res.data[id];
22
+ })
23
+ .catch((err: any) => {
24
+ console.log(`Unable to fetch price from Coingecko API for ${id}`);
25
+ return { usd: 0 };
22
26
  });
23
27
 
24
- return new BigNumber(price[id].usd);
28
+ return new BigNumber(price.usd);
25
29
  }
26
30
 
27
31
  export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
@@ -117,6 +121,19 @@ export async function fetchLPPrice(
117
121
  }
118
122
  }
119
123
 
124
+ export async function fetchStNEARPrice(): Promise<BigNumber> {
125
+ const ratioPromise = axios
126
+ .get('https://validators.narwallets.com/metrics_json')
127
+ .then((res) => res.data);
128
+ const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
129
+ const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([
130
+ ratioPromise,
131
+ nearPricePromise,
132
+ ]);
133
+ const ratio = new BigNumber(ratioRes.st_near_price);
134
+ return ratio.multipliedBy(nearPrice);
135
+ }
136
+
120
137
  function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
121
138
  return new BigNumber(rawPrice.toString()).div(decimalFactor(36 - underlyingDecimal));
122
139
  }
@@ -130,7 +147,22 @@ export async function fetchPriceFromOracle(
130
147
  AuriOracleABI.abi,
131
148
  provider
132
149
  ) as PriceOracle;
133
- const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
150
+ const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress).catch((e: any) => {
151
+ console.log(`Unable to fetch price from oracle for ${auTokenAddress}`);
152
+ return BN.from(0);
153
+ });
154
+
155
+ // In case of error, probally it is because the underlying token is not supported
156
+ // by the backup oracle. In that case, we will fetch from third-party.
157
+ if (rawPrice.isZero()) {
158
+ const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
159
+ return isSameAddress(auToken.address, auTokenAddress);
160
+ });
161
+ if (matchingAuToken?.name == 'auSTNEAR') {
162
+ return fetchStNEARPrice();
163
+ }
164
+ }
165
+
134
166
  return processPriceFromOracle(rawPrice, underlyingDecimal);
135
167
  }
136
168
 
package/src/index.ts CHANGED
@@ -7,8 +7,8 @@ BigNumber.config({ DECIMAL_PLACES: 50 });
7
7
 
8
8
  export * as abis from './abis';
9
9
  export * from './consts';
10
- export * from './contracts';
11
10
  export * from './entities';
12
11
  export * from './helpers';
12
+ export * from './interactors';
13
13
  export * from './SDK';
14
14
  export * from './types';
@@ -12,7 +12,7 @@ import {
12
12
  Token,
13
13
  TokenAmount,
14
14
  } from '../entities';
15
- import * as helpers from '../helpers/';
15
+ import * as helpers from '../helpers';
16
16
  import { calcValuation, fetchPrice, fetchValuation } from '../helpers/priceFetcher';
17
17
  import { Address, ComptrollerRewardType, MoneyMarketDetails, NetworkConnection } from '../types';
18
18
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes