@aurigami/sdk 1.13.0 → 1.14.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.13.0",
2
+ "version": "1.14.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -65,6 +65,7 @@
65
65
  "@aurigami/contracts": "3.11.3",
66
66
  "axios": "^0.26.1",
67
67
  "bignumber.js": "^9.0.2",
68
+ "cache-decorator": "^0.1.6",
68
69
  "ethers": "^5.6.4"
69
70
  },
70
71
  "jest": {
package/src/.DS_Store ADDED
Binary file
@@ -113,7 +113,6 @@ export const networkAddresses: NetworkAddresses = {
113
113
  };
114
114
 
115
115
  export const DEPOSIT_ONLY_TOKENS = [
116
- MAINNET_ADDRESSES.auTokens.STNEAR.toLowerCase(),
117
116
  MAINNET_ADDRESSES.auTokens.AURORA.toLowerCase(),
118
117
  MAINNET_ADDRESSES.auTokens.TRI.toLowerCase(),
119
118
  MAINNET_ADDRESSES.auTokens.PLY.toLowerCase(),
@@ -191,22 +191,22 @@ export function sortEvents<T extends Result>(events: TypedEvent<T>[]): TypedEven
191
191
  });
192
192
  }
193
193
 
194
- export function Cache(cacheTimeout: number) {
195
- return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
196
- const originalMethod = descriptor.value;
197
- let cache = new Map<string, any>();
198
- descriptor.value = function (...args: any[]) {
199
- let key = JSON.stringify(args);
200
- if (cache.has(key)) {
201
- let [timestamp, value] = cache.get(key);
202
- if (Date.now() - timestamp < cacheTimeout) {
203
- return value;
204
- }
205
- }
206
- let result = originalMethod.apply(this, args);
207
- cache.set(key, [Date.now(), result]);
208
- return result;
209
- };
210
- return descriptor;
211
- };
212
- }
194
+ // export function Cache(cacheTimeout: number) {
195
+ // return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
196
+ // const originalMethod = descriptor.value;
197
+ // let cache = new Map<string, any>();
198
+ // descriptor.value = function (...args: any[]) {
199
+ // let key = JSON.stringify(args);
200
+ // if (cache.has(key)) {
201
+ // let [timestamp, value] = cache.get(key);
202
+ // if (Date.now() - timestamp < cacheTimeout) {
203
+ // return value;
204
+ // }
205
+ // }
206
+ // let result = originalMethod.apply(this, args);
207
+ // cache.set(key, [Date.now(), result]);
208
+ // return result;
209
+ // };
210
+ // return descriptor;
211
+ // };
212
+ // }
@@ -8,7 +8,7 @@ import {
8
8
  DECIMAL_PRECISION,
9
9
  HARDCODE_PRICE_TOKENS,
10
10
  networkAddresses,
11
- PRICE_WHITELISTED,
11
+ PRICE_WHITELISTED
12
12
  } from '../consts/constants';
13
13
  import { TokenAmount } from '../entities/tokenAmount';
14
14
  import { Address, TokenValuation } from '../types';
@@ -24,6 +24,7 @@ export async function fetchPriceFromDefiLlamaAPI(id: string): Promise<BigNumber>
24
24
  })
25
25
  .catch((err: any) => {
26
26
  console.log(`unable to fetch price from DefiLlama API: ${err}`);
27
+ console.error(err);
27
28
  return 0;
28
29
  });
29
30
  return new BigNumber(price);
@@ -37,6 +38,7 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
37
38
  })
38
39
  .catch((err: any) => {
39
40
  console.log(`Unable to fetch price from Coingecko API for ${id}`);
41
+ console.error(err);
40
42
  return { usd: 0 };
41
43
  });
42
44
 
@@ -22,7 +22,8 @@ import {
22
22
  MoneyMarketDetails,
23
23
  NetworkConnection,
24
24
  } from '../types';
25
- import { Cache } from '../helpers/helpers';
25
+ import { getUnderlying } from '../helpers/helpers';
26
+ import { cache, CacheType } from 'cache-decorator';
26
27
 
27
28
  type RewardSpeeds = {
28
29
  plyRewardSupplySpeed: BN;
@@ -50,17 +51,17 @@ export class MoneyMarketRead extends BlockchainEntityRead {
50
51
  this.underlying = new Token(underlyingAsset, helpers.getDecimal(underlyingAsset));
51
52
  }
52
53
 
53
- @Cache(CACHE_TIMEOUT)
54
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
54
55
  public async getUnderlyingPrice(): Promise<BigNumber> {
55
56
  return fetchPrice(this.underlying.address, this._networkConnection.provider);
56
57
  }
57
58
 
58
- @Cache(CACHE_TIMEOUT)
59
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
59
60
  public async getPlyPrice(): Promise<BigNumber> {
60
61
  return fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider);
61
62
  }
62
63
 
63
- @Cache(CACHE_TIMEOUT)
64
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
64
65
  protected async getRewardSpeeds(): Promise<RewardSpeeds> {
65
66
  var speeds = await this.env.auriLens.getRewardSpeeds(
66
67
  this.env.comptroller.address,
@@ -69,12 +70,12 @@ export class MoneyMarketRead extends BlockchainEntityRead {
69
70
  return speeds;
70
71
  }
71
72
 
72
- @Cache(CACHE_TIMEOUT)
73
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
73
74
  public async getTotalTokenBorrowed(): Promise<TokenAmount> {
74
75
  return new TokenAmount(this.underlying, (await this.auToken.totalBorrows()).toString());
75
76
  }
76
77
 
77
- @Cache(CACHE_TIMEOUT)
78
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
78
79
  public async getTotalTokenDeposited(): Promise<TokenAmount> {
79
80
  const [totalBorrow, totalCash] = await Promise.all([
80
81
  this.getTotalTokenBorrowed(),
@@ -88,7 +89,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
88
89
  );
89
90
  }
90
91
 
91
- @Cache(CACHE_TIMEOUT)
92
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
92
93
  public async getDepositAPY(): Promise<BigNumber> {
93
94
  const supplyRatePerTimestamp = await this.auToken.supplyRatePerTimestamp();
94
95
  const supplyRatePerDay = new BigNumber(supplyRatePerTimestamp.toString())
@@ -98,7 +99,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
98
99
  return new BigNumber(supplyRatePerDay.plus(1)).pow(365).minus(1);
99
100
  }
100
101
 
101
- @Cache(CACHE_TIMEOUT)
102
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
102
103
  public async getBorrowAPY(): Promise<BigNumber> {
103
104
  const borrowRatePerTimestamp = await this.auToken.borrowRatePerTimestamp();
104
105
  const borrowRatePerDay = new BigNumber(borrowRatePerTimestamp.toString())
@@ -107,14 +108,14 @@ export class MoneyMarketRead extends BlockchainEntityRead {
107
108
  return new BigNumber(borrowRatePerDay.plus(1)).pow(365).minus(1);
108
109
  }
109
110
 
110
- @Cache(CACHE_TIMEOUT)
111
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
111
112
  public async getCollateralRatio(): Promise<BigNumber> {
112
113
  return this.env.comptroller.markets(this.auToken.address).then((res: any) => {
113
114
  return new BigNumber(res.collateralFactorMantissa.toString()).div(helpers.decimalFactor(18));
114
115
  });
115
116
  }
116
117
 
117
- @Cache(CACHE_TIMEOUT)
118
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
118
119
  public async getBorrowPlyAPY(): Promise<BigNumber> {
119
120
  const [totalBorrowed, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
120
121
  this.getTotalTokenBorrowed(),
@@ -132,7 +133,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
132
133
  );
133
134
  }
134
135
 
135
- @Cache(CACHE_TIMEOUT)
136
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
136
137
  public async getDepositPlyAPY(): Promise<BigNumber> {
137
138
  const [totalDeposited, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
138
139
  this.getTotalTokenDeposited(),
@@ -150,7 +151,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
150
151
  );
151
152
  }
152
153
 
153
- @Cache(CACHE_TIMEOUT)
154
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
154
155
  public async getDepositNearAPY(): Promise<BigNumber> {
155
156
  const [totalDeposited, underlyingPrice] = await Promise.all([
156
157
  this.getTotalTokenDeposited(),
@@ -164,7 +165,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
164
165
  return depositNEARApy;
165
166
  }
166
167
 
167
- @Cache(CACHE_TIMEOUT)
168
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
168
169
  public async getBorrowNearAPY(): Promise<BigNumber> {
169
170
  const [totalBorrowed, underlyingPrice] = await Promise.all([
170
171
  this.getTotalTokenBorrowed(),
@@ -178,7 +179,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
178
179
  return borrowNEARApy;
179
180
  }
180
181
 
181
- @Cache(CACHE_TIMEOUT)
182
+ @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
182
183
  public async getDepositMetaAPY(): Promise<BigNumber> {
183
184
  const [totalDeposited, underlyingPrice] = await Promise.all([
184
185
  this.getTotalTokenDeposited(),
@@ -131,6 +131,15 @@ export class PlyGameRead extends BlockchainEntityRead {
131
131
  amount: new TokenAmount(this.plyToken, result.amount.toString()),
132
132
  };
133
133
  }
134
+
135
+ public async overallLeaderboard(): Promise<PlyGameLeaderboardItem[]> {
136
+ const result = await AuriAPI.getPaginatedApi('/plygame/overallLeaderboard');
137
+ return result.items.map((item) => ({
138
+ player: item.user,
139
+ unlockedPulpAmount: new TokenAmount(this.pulpToken, item.unlockedAmount!),
140
+ gamesPlayed: item.count!,
141
+ }));
142
+ }
134
143
  }
135
144
 
136
145
  export class PlyGameReadWrite extends PlyGameRead {