@aurigami/sdk 1.12.1 → 1.12.3

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",
2
+ "version": "1.12.3",
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
  });
@@ -118,6 +118,14 @@ export class PlyGameRead extends BlockchainEntityRead {
118
118
  gamesPlayed: item.count!,
119
119
  }));
120
120
  }
121
+
122
+ public async getJackpotResult(round: number): Promise<{ winner: Address; amount: TokenAmount }> {
123
+ let result = await this.env.plygame.jackpotHistory(round);
124
+ return {
125
+ winner: result.winner,
126
+ amount: new TokenAmount(this.plyToken, result.amount.toString()),
127
+ };
128
+ }
121
129
  }
122
130
 
123
131
  export class PlyGameReadWrite extends PlyGameRead {