@aurigami/sdk 1.12.1-beta1 → 1.12.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.12.1-beta1",
2
+ "version": "1.12.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -14,6 +14,21 @@ import { TokenAmount } from '../entities/tokenAmount';
14
14
  import { Address, TokenValuation } from '../types';
15
15
  import { assert, decimalFactor, devLog, getDecimal, isSameAddress } from './helpers';
16
16
 
17
+ export async function fetchPriceFromDefiLlamaAPI(id: string): Promise<BigNumber> {
18
+ const price = await axios
19
+ .post(`https://coins.llama.fi/prices`, {
20
+ coins: [id],
21
+ })
22
+ .then((res: any) => {
23
+ return res.data.coins[id].price;
24
+ })
25
+ .catch((err: any) => {
26
+ console.log(`unable to fetch price from DefiLlama API: ${err}`);
27
+ return 0;
28
+ });
29
+ return new BigNumber(price);
30
+ }
31
+
17
32
  export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
18
33
  const price = await axios
19
34
  .get(`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`)
@@ -28,6 +43,17 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
28
43
  return new BigNumber(price.usd);
29
44
  }
30
45
 
46
+ export async function fetchPriceFromDefiLlama(id: Address): Promise<BigNumber> {
47
+ if (
48
+ id.toLowerCase() == networkAddresses.tokens.AURORA ||
49
+ id.toLowerCase() == networkAddresses.tokens.TRI ||
50
+ id.toLowerCase() == networkAddresses.tokens.META
51
+ ) {
52
+ return fetchPriceFromDefiLlamaAPI(`aurora:${id.toLowerCase()}`);
53
+ }
54
+ throw Error(`Unknown token ${id} in fetchPriceFromDefiLlama`);
55
+ }
56
+
31
57
  export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
32
58
  switch (id.toLowerCase()) {
33
59
  case networkAddresses.tokens.AURORA:
@@ -194,7 +220,7 @@ export async function fetchUnderlyingTokensPrices(provider: providers.Provider):
194
220
  });
195
221
  }
196
222
 
197
- function shouldFetchFromCoingecko(address: string) {
223
+ function shouldFetchFromCoingeckoOrDefiLlama(address: string) {
198
224
  address = address.toLowerCase();
199
225
  return (
200
226
  address == networkAddresses.tokens.AURORA ||
@@ -211,9 +237,13 @@ async function _fetchPrice(address: Address, provider: providers.Provider): Prom
211
237
  PRICE_WHITELISTED.has(address.toLocaleLowerCase()),
212
238
  `Address ${address} is not whitelisted for price fetching`
213
239
  );
214
-
215
- if (shouldFetchFromCoingecko(address)) return fetchPriceFromCoingecko(address);
216
-
240
+ if (shouldFetchFromCoingeckoOrDefiLlama(address)) {
241
+ try {
242
+ return await fetchPriceFromCoingecko(address);
243
+ } catch (err) {
244
+ return fetchPriceFromDefiLlama(address);
245
+ }
246
+ }
217
247
  const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
218
248
  return isSameAddress(auToken.underlying, address);
219
249
  });
@@ -1,6 +1,7 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
+ import axios from 'axios';
2
3
  import { ethers } from 'ethers';
3
- import { REFERRAL_CAMPAIGNS } from '../consts';
4
+ import { AURORA_PLUS_API_PREFIX, REFERRAL_CAMPAIGNS } from '../consts';
4
5
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
5
6
  import { getBlocksTimestamp } from '../helpers';
6
7
  import * as AuriAPI from '../helpers/aurigami-api';
@@ -142,10 +143,9 @@ export class ReferralRead extends BlockchainEntityRead {
142
143
  }
143
144
 
144
145
  public async isOnAuroraPlus(address: Address): Promise<boolean> {
145
- return true;
146
- // let resp = await axios.get(AURORA_PLUS_API_PREFIX + address);
146
+ let resp = await axios.get(AURORA_PLUS_API_PREFIX + address);
147
147
 
148
- // return resp.data.status == 'active';
148
+ return resp.data.status == 'active';
149
149
  }
150
150
 
151
151
  public async isNewUserAtReferralTime(address: Address): Promise<boolean> {