@aurigami/sdk 1.12.9-hf → 1.13.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.
@@ -25,9 +25,7 @@ export class MiscRead extends BlockchainEntityRead {
25
25
  const marketCount = consts.networkAddresses.auTokens.length;
26
26
  var userMarketDetails: types.UserMarketDetails[] = [],
27
27
  assetsIn: string[];
28
- var promises = [];
29
28
  var totalBorrowLimit = new BigNumber(0);
30
- var pricePromises = [];
31
29
  for (const auToken of consts.networkAddresses.auTokens) {
32
30
  const userMarketDetail: types.UserMarketDetails = {} as types.UserMarketDetails;
33
31
  userMarketDetails.push(userMarketDetail);
@@ -37,37 +35,21 @@ export class MiscRead extends BlockchainEntityRead {
37
35
  auToken.address,
38
36
  auToken.underlying
39
37
  );
40
- promises.push(
41
- moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {
42
- userMarketDetail.depositBalance = res;
43
- })
44
- );
45
- promises.push(
46
- moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {
47
- userMarketDetail.borrowBalance = res;
48
- })
49
- );
50
- promises.push(
51
- moneyMarket.getCollateralRatio().then((res: BigNumber) => {
52
- userMarketDetail.collateralRatio = res.toNumber();
53
- })
54
- );
55
- pricePromises.push(
56
- fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
57
- userMarketDetail.underlyingPrice = res.toString();
58
- return res;
59
- })
60
- );
38
+ const [depositBalance, borrowBalance, collateralRatio, underlyingPrice] = await Promise.all([
39
+ moneyMarket.getUserDepositBalance(userAddress),
40
+ moneyMarket.getUserBorrowBalance(userAddress),
41
+ moneyMarket.getCollateralRatio(),
42
+ fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider),
43
+ ]);
44
+
45
+ userMarketDetail.depositBalance = depositBalance;
46
+ userMarketDetail.borrowBalance = borrowBalance;
47
+ userMarketDetail.collateralRatio = collateralRatio.toNumber();
48
+ userMarketDetail.underlyingPrice = underlyingPrice.toString();
61
49
  }
62
50
 
63
- promises.push(
64
- this.env.comptroller.getAssetsIn(userAddress).then((res: string[]) => {
65
- assetsIn = res;
66
- })
67
- );
51
+ assetsIn = await this.env.comptroller.getAssetsIn(userAddress);
68
52
 
69
- await Promise.all(promises);
70
- var underlyingPrices = await Promise.all(pricePromises);
71
53
  var depositValues = [];
72
54
  for (var i = 0; i < marketCount; i++) {
73
55
  const auToken = consts.networkAddresses.auTokens[i];
@@ -79,7 +61,12 @@ export class MiscRead extends BlockchainEntityRead {
79
61
  } else {
80
62
  userMarketDetails[i].isCollateral = false;
81
63
  }
82
- depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
64
+ depositValues.push(
65
+ calcValuation(
66
+ userMarketDetails[i].depositBalance,
67
+ new BigNumber(userMarketDetails[i].underlyingPrice)
68
+ )
69
+ );
83
70
  }
84
71
 
85
72
  totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number) => {
@@ -88,10 +75,7 @@ export class MiscRead extends BlockchainEntityRead {
88
75
  return p;
89
76
  }, new BigNumber(0));
90
77
 
91
- var accountLiquidity: [BN, BN] = await this.env.comptroller.getAccountLiquidity(userAddress).catch((e) => {
92
- console.log(e);
93
- return [BN.from(0), BN.from(0)]
94
- });
78
+ var accountLiquidity: [BN, BN] = await this.env.comptroller.getAccountLiquidity(userAddress);
95
79
 
96
80
  var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
97
81
  new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
@@ -126,15 +110,15 @@ export class MiscRead extends BlockchainEntityRead {
126
110
  : new BigNumber(0);
127
111
  const maxWithdrawCap: BigNumber = borrowLimitMargin
128
112
  .div(userMarketDetails[i].collateralRatio)
129
- .div(underlyingPrices[i]);
113
+ .div(userMarketDetails[i].underlyingPrice);
130
114
  userMarketDetails[i].maxWithdrawableAmount =
131
115
  userMarketDetails[i].isCollateral &&
132
- maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
116
+ maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
133
117
  ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false)
134
118
  : new TokenAmount(
135
- moneyMarket.underlying,
136
- userMarketDetails[i].depositBalance.rawAmount()
137
- );
119
+ moneyMarket.underlying,
120
+ userMarketDetails[i].depositBalance.rawAmount()
121
+ );
138
122
  }
139
123
 
140
124
  return {
@@ -323,4 +307,67 @@ export class MiscRead extends BlockchainEntityRead {
323
307
  }
324
308
  return res;
325
309
  }
310
+
311
+ public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
312
+ let sum = new BigNumber(0);
313
+ let totalSuppliedValue = new BigNumber(0);
314
+ let totalBorrowedValue = new BigNumber(0);
315
+ let netApy = new BigNumber(0);
316
+
317
+ const apys = await Promise.all(
318
+ consts.networkAddresses.auTokens.map((auToken) => {
319
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
320
+ this._networkConnection,
321
+ auToken.address,
322
+ auToken.underlying
323
+ );
324
+ const apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
325
+ return apyWithoutIncentive;
326
+ })
327
+ );
328
+
329
+ for (const apy of apys) {
330
+ sum = sum.plus(apy.sum);
331
+ totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
332
+ totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
333
+ }
334
+
335
+ if (sum.gt(0)) {
336
+ netApy = sum.div(totalSuppliedValue);
337
+ } else if (sum.lt(0)) {
338
+ netApy = sum.div(totalBorrowedValue);
339
+ }
340
+ return netApy;
341
+ }
342
+
343
+ public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
344
+ let sum = new BigNumber(0);
345
+ let totalSuppliedValue = new BigNumber(0);
346
+ let totalBorrowedValue = new BigNumber(0);
347
+ let netApy = new BigNumber(0);
348
+ const apys = await Promise.all(
349
+ consts.networkAddresses.auTokens.map((auToken) => {
350
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
351
+ this._networkConnection,
352
+ auToken.address,
353
+ auToken.underlying
354
+ );
355
+ const apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
356
+ return apyWithIncentive;
357
+ })
358
+ );
359
+
360
+ for (const apy of apys) {
361
+ sum = sum.plus(apy.sum);
362
+ totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
363
+ totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
364
+ }
365
+
366
+ if (sum.gt(0)) {
367
+ netApy = sum.div(totalSuppliedValue);
368
+ } else if (sum.lt(0)) {
369
+ netApy = sum.div(totalBorrowedValue);
370
+ }
371
+ return netApy;
372
+ }
326
373
  }
@@ -183,3 +183,9 @@ export type PlyGameLeaderboardItem = {
183
183
  export type PlyBetMadeEvent = TypedEvent<
184
184
  [string, BN, number] & { player: string; amount: BN; outcome: number }
185
185
  >;
186
+
187
+ export type Apy = {
188
+ sum: BigNumber;
189
+ suppliedValue: BigNumber;
190
+ borrowedValue: BigNumber;
191
+ };
package/ChangeLog.md DELETED
@@ -1,371 +0,0 @@
1
- # Change Logs
2
-
3
- # 1.12.8:
4
-
5
- - Add `mintCap(): Promise<TokenAmount>` return the mint cap of the autoken
6
- - Add `borrowCap(): Promise<TokenAmount>)` return the borrow cap of the autoken
7
-
8
- # 1.12.7:
9
-
10
- - Add `(...).queuePosition(address: Address): Promise<number>` return the position of the address in referral queue. -1 if not in queue,
11
- 999 if not in top 600.
12
- - `slotsInUse()` now will not accept any param, and return the total slots in total.
13
-
14
- ## 1.12.6:
15
-
16
- - Remove `getJackpotResult`, use `getLastJackpotResult` instead.
17
- - Hide winner address in jackpot result.
18
-
19
- ## 1.12.3
20
-
21
- - Add `PlyGameRead(...).getJackpotResult(round:number): Promise<{amount: TokenAmount, winner: Address}>`: return jackpot winner of the given round
22
-
23
- ## 1.12.2
24
-
25
- - Use DefiLlama API as an backup for Coingecko
26
-
27
- ## 1.12.0 + 1.12.1
28
-
29
- - Use new referral contract
30
- - Remove referral V1 data
31
-
32
- - `ReferralRead(...).isNewUserAtReferralTime(address: Address): Promise<boolean>`: Return true if this is a new user of aurigami
33
- when he got referred
34
- - `...(...).depositedMoreThanMinimumAmount(address: Address): Promise<boolean>`: Return true if the user has deposited more than the minimum amount (100$)
35
-
36
- - `ReferralRead(...).isWhitelistedAddress(address: Address): Promise<boolean>`: check whether a user is a whitelisted referrer or not
37
- - `ReferralRead(...).isOnAuroraPlus(address: Address): Promise<boolean>`: Check whether a user on Aurora+ or not
38
-
39
- - `ReferralRead(...).slotsInUse(referralCode: string): Promise<number>`
40
- - `(...).totalReferralSlots(): number` -> return 500
41
- - `(...).userReferralStatus(userAddr: Address): Promise<string>` -> return `notReferred`, `notQualified`, `Qualified`, or `Withdrawn` base on the user status
42
- - Type changes: `ReferralReward` now will have `refereeAddress: string | null`
43
-
44
- ## 1.11.1
45
-
46
- - PlyGame `getPlyGameResultsInTransaction` get result faster by using `getTransactionReceipt` instead of `waitForTransaction`
47
-
48
- ## 1.11.0
49
-
50
- - Add support for Plygame with testing contract
51
- - Type:
52
-
53
- ```ts
54
- export type PlyGameBetResult = {
55
- player: string;
56
- outcome: string;
57
- lostAmount: TokenAmount;
58
- unlockedPulpAmount: TokenAmount;
59
-
60
- block: number;
61
- timestamp: number;
62
- transactionHash: string;
63
- };
64
-
65
- type PlyGameLeaderboardItem = {
66
- player: string;
67
- gamesPlayed: number;
68
- unlockedPulpAmount: TokenAmount;
69
- };
70
- ```
71
-
72
- - Read functions:
73
-
74
- - `PlyGameRead(...).getUserPlyGameHistory(user) -> Promise<PlyGameBetResult[]>`: Get 100 most recent bets of the market users
75
- - `(...).currentJackpotAmount(): Promise<TokenAmount>`
76
- - `(...).earlyUnlockedPulpAmount(user): Promise<TokenAmount>`: get total unlocked pulp amount since launch.
77
- - `(...).getPlyGameResultsInTransaction(txHash): Promise<PlyGameBetResult[]>`: Return list of bet made from the given transaction.
78
- - `PlyGameRead(...).leaderboard(): Promise<PlyGameLeaderboardItem[]>`: ranking list of the top 100 users by amount of PULP unlocked
79
-
80
- - Write functions:
81
-
82
- - `PlyGameReadWrite(...).makeBetOnce(amount: TokenAmount)`
83
- - `(...).approve(amount: TokenAmount)`: approve plygame contract spending user's PLY
84
-
85
- ## 1.10.0
86
-
87
- - Public `PapermillRead(...).getWeek(timestamp: number): number`
88
-
89
- ## 1.9.7
90
-
91
- - Change oracle address
92
-
93
- ## 1.9.6
94
-
95
- - Add oracle to ENV
96
-
97
- ## 1.9.5
98
-
99
- - Use compound formular to calculate market APY.
100
-
101
- ## 1.9.4
102
-
103
- - Allow to set custom dust in sneak account
104
-
105
- ## 1.9.3
106
-
107
- - Change ply circulating supply
108
-
109
- ## 1.9.2
110
-
111
- - Use 10B for PLY total supply
112
-
113
- ## 1.9.1
114
-
115
- - Handle error in fetching LP price
116
-
117
- ## 1.9.0
118
-
119
- - Rename `contracts` folder to `interactors`.
120
- - Catching fetch price error
121
-
122
- ## 1.8.6
123
-
124
- - Fix bug in `formattedAmount` when using custom format.
125
-
126
- ## 1.8.5
127
-
128
- - Able to customize format in TokenAmount.formattedAmount()
129
-
130
- ## 1.8.4
131
-
132
- - Add campaign ids for referrals
133
-
134
- ## 1.8.3
135
-
136
- - Markets rewards + staking rewards can be claim in one txn by `SdkReadWrite(...).claim()`
137
- - Remove `SdkReadWrite(...).claimLpRewards()`
138
-
139
- ## 1.8.2
140
-
141
- Bug fix on missing txnHash in referralReward type
142
-
143
- ## 1.8.1
144
-
145
- - Change campaign id
146
-
147
- ## 1.8.0
148
-
149
- - Return actual data for referral rewards.
150
- - Change `ReferralRead(...).leaderboard()` to `ReferralRead(...).leaderboard(campaign: string)`: now can get the leaderboard of a given campaign.
151
-
152
- ## 1.7.9-dummy
153
-
154
- - Add `userAddr` in ReferralReward type
155
-
156
- ## 1.7.8-dummy
157
-
158
- - Update Meta rewards for stNEAR to `1,250,000` META.
159
-
160
- ## 1.7.7-dummy
161
-
162
- - [Dummy data] Add `ReferralRead(...).referralRewards(userAddr: Address): Promise<ReferralReward[]>`: Array of rewards, sorted by time of the referral period (from latest to oldest)
163
- - [Dummy data] Add `ReferralRead(...).leaderboard(): Promise<ReferralReward[]>`: Top 50 reward earners from the last round, sorted by token amount.
164
-
165
- - Add `ReferralReadWrite(...).claimReferralRewards()`: Claim all unclaimed rewards for a given user
166
-
167
- New type:
168
-
169
- ```ts
170
- export type ReferralReward = {
171
- campaign: string;
172
- /**
173
- * start timetamp of the referral round
174
- */
175
- startTime: number;
176
- /**
177
- * end timetamp of the referral round
178
- */
179
- endTime: number;
180
- /**
181
- * referrer's rewards
182
- */
183
- isReferrer: boolean;
184
- /**
185
- * reward amount
186
- */
187
- rewardTokenAmount: TokenAmount;
188
- /**
189
- * hash of the transaction on aurorascan (if no, return null)
190
- */
191
- transactionHash: string | null;
192
- };
193
- ```
194
-
195
- ## 1.7.3
196
-
197
- - Add helper functions for Auri monitoring system
198
-
199
- ## 1.7.1 & 1.7.2
200
-
201
- - Return correct timestamp in referrals list
202
-
203
- ## 1.7.0
204
-
205
- - Add `ReferralRead(...).getReferralsList(userAddr: Address): Promise<{ user: string; timestamp: number }[]>`: Get 50 latest referrals of the given address, sorted descending by timestamp. Currently the timestamp is dummy data.
206
-
207
- ## 1.6.9
208
-
209
- Support internal aurilens
210
-
211
- ## 1.6.6
212
-
213
- Use `public readonly` modifier instead of `private/protected` in SDK.
214
-
215
- ## 1.6.5
216
-
217
- SDK refactor #2, remove support for loterry campaign. Package size reduced from 3MB -> 200KB
218
-
219
- ## 1.6.4
220
-
221
- Return meaningful result instead of INF in `calcLMRewardApr`
222
-
223
- ## 1.6.3
224
-
225
- Add USN supports. Hardcoded USN price to $1.
226
-
227
- ## 1.6.2
228
-
229
- - Add `ReferralRead(...).getUserReferralCode(userAddr: Address): Promise<string>`: Get the referral code for a given address, returns empty string if not found. Called to check if a user has a referral code.
230
- - Add `ReferralRead(...).getReferralCodeOwner(code: string): Promise<Address>`: Get owner of a referral code, returns zero address if not found.
231
- - Add `ReferralRead(...).getReferralCodeUsed(userAddr: Address): Promise<string>`: Get referral code that a user was referred by, returns empty string if not found.
232
- - Add `ReferralReadWrite(...).registerNewReferralCode(): Promise<TransactionResponse>`: Generate a referral code for a given address. Called when an user want to creates his own referral code
233
- - Add `ReferralReadWrite(...).useReferralCode(code: string): Promise<TransactionResponse>`: Called when an user confirms he is referred by a specified code
234
-
235
- ## 1.6.1
236
-
237
- Add `PapermillRead(...).getNextWeekTimestamp(): number`: get the start timestamp of next week of the papermill contract.
238
-
239
- Add `SdkRead(...).getPlyCirculatingSupply(): Promise<TokenAmount>`: get the ply's circulating supply
240
-
241
- ## 1.6.0
242
-
243
- SDK refactor - Why?:
244
-
245
- - more modular and less coupled.
246
- - more testable.
247
- - more maintainable.
248
-
249
- Things to do:
250
-
251
- - [x] Restructure the folder structure.
252
- - Refactor the code - Use composition pattern to SDK class
253
- - [x] Use address from contract package instead of hardcoded address.
254
-
255
- ## 1.5.8 + 1.5.9
256
-
257
- Fix gas error on claim rewards: Instead of claim all the rewards in all market in 1 txns, we will claim rewards in 2 txns.
258
-
259
- ## 1.5.7
260
-
261
- - Change return type of `SdkRead(...).LpBalanceOf` and `stakeBalanceOf` from `TokenValuation` to `TokenAmount` to match other functions in the SDK.
262
- - `totalStakedLiquidity` field in `PLYWNEARPoolDetails` is now `TokenAmount` instead of `TokenValuation`.
263
-
264
- ```ts
265
- export type PLYWNEARPoolDetails = {
266
- totalStakedLiquidity: TokenAmount;
267
- APYs: TokenAPY[];
268
- };
269
- ```
270
-
271
- ## 1.5.6
272
-
273
- Add PLYWNEAR pool to ALL_STAKING_POOLS
274
-
275
- ## 1.5.5
276
-
277
- Add auPLY market, integrate new fair launch contract
278
-
279
- Hard code PULP price to 0
280
-
281
- ## 1.5.4
282
-
283
- Use browser-friendly assert
284
-
285
- ## 1.5.2
286
-
287
- Added `SdkRead(...).unclaimedRewardsOf(userAddress: Address): Promise<TokenAmount[]>` to get unclaimed rewards of a user in LP staking.
288
-
289
- ## 1.5.1
290
-
291
- Added `PapermillRead(...).getUnlockPortionAt(userAddress: Address, timestamp: number)`
292
-
293
- ```ts
294
- export type TokenAPY = {
295
- address: string;
296
- apy: string;
297
- };
298
-
299
- export type PLYWNEARPoolDetails = {
300
- totalStakedLiquidity: TokenValuation;
301
- APYs: TokenAPY[];
302
- //apy: string; removed
303
- };
304
- ```
305
-
306
- ## 1.5.0 For staking PLYWNEAR
307
-
308
- ### Unchanged:
309
-
310
- - Stake/unstake: Use `SdkReadWrite(...).stake(amount: TokenAmount)` (or `unstake`)
311
-
312
- ### Rename:
313
-
314
- - `SdkRead(...).getPlyAuroraPoolDetails` -> `SdkRead(...).getPLYWNEARPoolDetails`
315
-
316
- ### Add
317
-
318
- - Read:
319
- - `SdkRead(...).LpBalanceOf(user: Address):TokenValuation` => amount and $ value of LP token in wallet. To get amount staked, use the old `stakeBalanceOf()` above
320
- - Type:
321
- - `TokenValuation` is a type that contains amount and $ value of token.
322
-
323
- ```ts
324
- export type TokenValuation = {
325
- tokenAmount: TokenAmount;
326
- currencyAmount: CurrencyAmount;
327
- };
328
- ```
329
-
330
- ```ts
331
- export type PLYWNEARPoolDetails = {
332
- totalStakedLiquidity: TokenValuation;
333
- apy: string;
334
- };
335
- ```
336
-
337
- ### Return type changed:
338
-
339
- - `SdkRead(...).stakeBalanceOf()` will return `TokenValuation` instead of `TokenAmount`
340
-
341
- ### Remove:
342
-
343
- - Type `PlyAuroraPoolDetails` removed.
344
-
345
- ## 1.5.0 For Papermill
346
-
347
- ### Add
348
-
349
- - Read functions:
350
-
351
- - `new PapermillRead(...).getPlyBalance(address: Address): TokenAmount` => PLY balance in user wallet
352
- - `new PapermillRead(...).getPulpBalance(address: Address): TokenAmount` => PULP balance in user wallet
353
- - `new PapermillRead(...).getLockingDetails(address: Address): UserLockingDetails`: Get locking details. This function is for convenience only, because the locking details are already available in the `UserLockingDetails` result (which you can get by calling the old `SdkRead(...).getUserDetails()`)
354
-
355
- - Write functions:
356
-
357
- - `new PapermillReadWrite(...).redeem(recipient: Address, amount: TokenAmount)` => Redeem Ply from PULP. Set `amount` to `ethers.constants.MaxUint256` for max redeem.
358
- - `new PapermillReadWrite(...).selfRedeem(amount: TokenAmount)` => Redeem Ply from PULP to msg.sender. This is just a shortcut for the redeem function above.
359
- - Collect all PLY reward from all markets + staking pool: No added functions, using the old `SdkReadWrite(...).claim()`
360
-
361
- - Type:
362
- - `UserLockingDetails` to store all user locking details
363
-
364
- ### Update
365
-
366
- - `SdkRead(...).getUserDetails()`: this will include the result from `getLockingDetails`.
367
-
368
- ### Remove
369
-
370
- - `SdkRead(...).getLockingDetails()`: Use the `getLockingDetails` in papermill instead if needed.
371
- - Remove `LockingDetails` type
package/src/.DS_Store DELETED
Binary file