@aurigami/sdk 1.24.0 → 1.24.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.
Files changed (46) hide show
  1. package/dist/consts/constants.d.ts +3 -1
  2. package/dist/consts/constants.js +4 -2
  3. package/dist/entities/auriEnv.d.ts +2 -1
  4. package/dist/entities/auriEnv.js +3 -3
  5. package/dist/helpers/priceFetcher.js +9 -13
  6. package/dist/interactors/misc.js +2 -2
  7. package/package.json +2 -14
  8. package/src/SDK.ts +0 -223
  9. package/src/abis/index.ts +0 -38
  10. package/src/consts/constants.ts +0 -210
  11. package/src/consts/decimals.ts +0 -31
  12. package/src/consts/deployments.ts +0 -4
  13. package/src/consts/dummy.ts +0 -51
  14. package/src/consts/index.ts +0 -5
  15. package/src/consts/symbols.ts +0 -9
  16. package/src/entities/BlockchainEntity.ts +0 -29
  17. package/src/entities/auriEnv.ts +0 -180
  18. package/src/entities/index.ts +0 -4
  19. package/src/entities/token.ts +0 -21
  20. package/src/entities/tokenAmount.ts +0 -48
  21. package/src/helpers/aurigami-api.ts +0 -42
  22. package/src/helpers/aurora-api-helpers.ts +0 -17
  23. package/src/helpers/graphql-helpers.ts +0 -8
  24. package/src/helpers/helpers.ts +0 -212
  25. package/src/helpers/historicalPriceFetcher.ts +0 -200
  26. package/src/helpers/index.ts +0 -7
  27. package/src/helpers/kyber-aggregator-api.ts +0 -37
  28. package/src/helpers/multicall.ts +0 -251
  29. package/src/helpers/notification-api.ts +0 -22
  30. package/src/helpers/one-inch-aggregator-api.ts +0 -45
  31. package/src/helpers/priceFetcher.ts +0 -388
  32. package/src/helpers/subgraphQuery.ts +0 -17
  33. package/src/helpers/transfer-event-query.ts +0 -68
  34. package/src/index.ts +0 -14
  35. package/src/interactors/Airdrop.ts +0 -72
  36. package/src/interactors/MoneyMarket.ts +0 -486
  37. package/src/interactors/Multicall.ts +0 -50
  38. package/src/interactors/Papermill.ts +0 -185
  39. package/src/interactors/PlyGame.ts +0 -172
  40. package/src/interactors/PlyTokenLock.ts +0 -46
  41. package/src/interactors/Pulp.ts +0 -41
  42. package/src/interactors/Referral.ts +0 -214
  43. package/src/interactors/Staking.ts +0 -156
  44. package/src/interactors/index.ts +0 -9
  45. package/src/interactors/misc.ts +0 -433
  46. package/src/types/index.ts +0 -252
@@ -1,156 +0,0 @@
1
- import { IERC20 } from '@aurigami/contracts/typechain';
2
- import { TransactionResponse } from '@ethersproject/abstract-provider';
3
- import BigNumber from 'bignumber.js';
4
- import { BigNumber as BN } from 'ethers';
5
- import { EIP20InterfaceABI } from '../abis';
6
- import * as consts from '../consts';
7
- import {
8
- AuriEnv,
9
- BlockchainEntity,
10
- BlockchainEntityRead,
11
- PLYWNEARToken,
12
- Token,
13
- TokenAmount,
14
- } from '../entities';
15
- import { calcLMRewardApr, getDecimal } from '../helpers';
16
- import { createContract } from '../helpers/multicall';
17
- import { fetchValuation } from '../helpers/priceFetcher';
18
- import { NetworkConnection, PLYWNEARPoolDetails, TokenAPY } from '../types';
19
-
20
- export class StakingRead extends BlockchainEntityRead {
21
- public readonly env: AuriEnv;
22
- constructor(networkConnection: NetworkConnection) {
23
- super(networkConnection);
24
- this.env = new AuriEnv(networkConnection);
25
- }
26
-
27
- public async getPLYWNEARPoolDetails(): Promise<PLYWNEARPoolDetails> {
28
- const { stakedLiquidity, rewardPerSeconds } = await this.env.auriFairLaunch.callStatic
29
- .getPoolInfo(consts.PLYWNEAR_POOL_ID)
30
- .then((res) => {
31
- const endedTime = res.endTime;
32
- const startTime = res.startTime;
33
- const now = Date.now() / 1000;
34
- // If the pool has ended or not started, return 0 reward per second
35
- if (endedTime < now || startTime > now) {
36
- return {
37
- stakedLiquidity: res.totalStake,
38
- rewardPerSeconds: res.rewardPerSeconds.map((_) => BN.from(0)),
39
- };
40
- }
41
- return { stakedLiquidity: res.totalStake, rewardPerSeconds: res.rewardPerSeconds };
42
- });
43
-
44
- let stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity!.toString());
45
-
46
- var totalStakeValuation: BigNumber = await fetchValuation(
47
- stakedLiquidityAmount,
48
- this._networkConnection.provider
49
- );
50
-
51
- var promises = [];
52
-
53
- // Calculate the reward per second in USD
54
- for (let i = 0; i < rewardPerSeconds!.length; i++) {
55
- let rewardTokenAddress = consts.PLYWNEAR_REWARD_TOKENS[i];
56
- let rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
57
- let rewardPerSecond = rewardPerSeconds![i];
58
- promises.push(
59
- fetchValuation(
60
- new TokenAmount(rewardToken, rewardPerSecond!.toString()),
61
- this._networkConnection.provider
62
- )
63
- );
64
- }
65
-
66
- let APYs: TokenAPY[] = [];
67
- (await Promise.all(promises)).forEach((rewardPerSecondValuation, i) => {
68
- let rewardTokenAddress = consts.PLYWNEAR_REWARD_TOKENS[i];
69
- let apy = calcLMRewardApr(
70
- rewardPerSecondValuation,
71
- totalStakeValuation,
72
- consts.ONE_DAY * 365
73
- ).toFixed(consts.DECIMAL_PRECISION);
74
-
75
- APYs.push({
76
- address: rewardTokenAddress,
77
- apy: apy,
78
- });
79
- });
80
-
81
- return {
82
- totalStakedLiquidity: stakedLiquidityAmount,
83
- APYs: APYs,
84
- };
85
- }
86
-
87
- /**
88
- * Get amount of staked LP tokens
89
- */
90
- public async stakeBalanceOf(user: string): Promise<TokenAmount> {
91
- const userInfo = await this.env.auriFairLaunch.callStatic.getUserInfo(
92
- consts.PLYWNEAR_POOL_ID,
93
- user
94
- );
95
- return new TokenAmount(PLYWNEARToken, userInfo.amount.toString());
96
- }
97
-
98
- /**
99
- * Get amount of LP token in user wallet
100
- */
101
- public async LpBalanceOf(user: string): Promise<TokenAmount> {
102
- let lpContract = createContract<IERC20>(
103
- consts.networkAddresses.tokens.PLYWNEAR,
104
- EIP20InterfaceABI.abi,
105
- this._networkConnection.provider
106
- );
107
- let balance = await lpContract.callStatic.balanceOf(user);
108
-
109
- return new TokenAmount(PLYWNEARToken, balance.toString());
110
- }
111
-
112
- public async unclaimedRewardsOf(user: string): Promise<TokenAmount[]> {
113
- let userInfo = await this.env.auriFairLaunch.raw.callStatic.updateAndGetUserInfo(
114
- consts.PLYWNEAR_POOL_ID,
115
- user,
116
- { from: user }
117
- );
118
-
119
- let rewards = userInfo.unclaimedRewards;
120
- return rewards.map((reward, i) =>
121
- TokenAmount.fromAddressAndAmount(consts.PLYWNEAR_REWARD_TOKENS[i], reward.toString())
122
- );
123
- }
124
- }
125
-
126
- export class StakingReadWrite extends StakingRead {
127
- public async stake(amount: TokenAmount): Promise<TransactionResponse> {
128
- return this.env.auriFairLaunch.raw
129
- .connect(this._networkConnection.signer!)
130
- .deposit(consts.PLYWNEAR_POOL_ID, amount.rawAmount());
131
- }
132
-
133
- public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
134
- const msgSender = await this._networkConnection.signer!.getAddress();
135
- const amountInput = BN.from(amount.rawAmount());
136
- const stakedAmount = BN.from((await this.stakeBalanceOf(msgSender)).rawAmount());
137
- // unstakeAmount = min(amountInput, stakedAmount - 1)
138
- const unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
139
- return this.env.auriFairLaunch.raw
140
- .connect(this._networkConnection.signer!)
141
- .withdraw(consts.PLYWNEAR_POOL_ID, unstakeAmount);
142
- }
143
- }
144
-
145
- export class Staking extends BlockchainEntity {
146
- constructor() {
147
- super();
148
- }
149
- public read(networkConnection: NetworkConnection): StakingRead {
150
- return new StakingRead(networkConnection);
151
- }
152
-
153
- public readWrite(networkConnection: NetworkConnection): StakingReadWrite {
154
- return new StakingReadWrite(networkConnection);
155
- }
156
- }
@@ -1,9 +0,0 @@
1
- export * from './Airdrop';
2
- export * from './MoneyMarket';
3
- export * from './Papermill';
4
- export * from './PlyGame';
5
- export * from './Pulp';
6
- export * from './Referral';
7
- export * from './Staking';
8
- export * from './misc';
9
- export * from './PlyTokenLock';
@@ -1,433 +0,0 @@
1
- import { AuToken } from '@aurigami/contracts/typechain';
2
- import BigNumber from 'bignumber.js';
3
- import { BigNumber as BN } from 'ethers';
4
- import * as abis from '../abis';
5
- import * as consts from '../consts';
6
- import { AuriEnv, BlockchainEntityRead, PLYToken, Token, TokenAmount } from '../entities';
7
- import { decimalFactor, getDecimal, getSymbol, isSameAddress } from '../helpers/helpers';
8
- import { calcValuation, fetchPrice } from '../helpers/priceFetcher';
9
- import * as types from '../types';
10
- import { MoneyMarketRead } from './MoneyMarket';
11
- import { MulticallRead } from './Multicall';
12
- import { StakingRead } from './Staking';
13
-
14
- export class MiscRead extends BlockchainEntityRead {
15
- public readonly env: AuriEnv;
16
- public readonly stakingRead: StakingRead;
17
- constructor(networkConnection: types.NetworkConnection) {
18
- super(networkConnection);
19
- this.stakingRead = new StakingRead(networkConnection);
20
- this.env = new AuriEnv(networkConnection);
21
- }
22
-
23
- public async getUserDetails(userAddress: string): Promise<types.UserDetails> {
24
- const marketCount = consts.networkAddresses.auTokens.length;
25
- var userMarketDetails: types.UserMarketDetails[] = [],
26
- assetsIn: string[];
27
- var totalBorrowLimit = new BigNumber(0);
28
- for (const auToken of consts.networkAddresses.auTokens) {
29
- const userMarketDetail: types.UserMarketDetails = {} as types.UserMarketDetails;
30
- userMarketDetails.push(userMarketDetail);
31
- userMarketDetail.market = auToken.underlying;
32
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
33
- this._networkConnection,
34
- auToken.address,
35
- auToken.underlying
36
- );
37
- const [depositBalance, borrowBalance, collateralRatio, underlyingPrice] = await Promise.all([
38
- moneyMarket.getUserDepositBalance(userAddress),
39
- moneyMarket.getUserBorrowBalance(userAddress),
40
- moneyMarket.getCollateralRatio(),
41
- fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider),
42
- ]);
43
-
44
- userMarketDetail.depositBalance = depositBalance;
45
- userMarketDetail.borrowBalance = borrowBalance;
46
- userMarketDetail.collateralRatio = collateralRatio.toNumber();
47
- userMarketDetail.underlyingPrice = underlyingPrice.toString();
48
- }
49
-
50
- assetsIn = await this.env.comptroller.raw.getAssetsIn(userAddress);
51
-
52
- var depositValues = [];
53
- for (var i = 0; i < marketCount; i++) {
54
- const auToken = consts.networkAddresses.auTokens[i];
55
- if (
56
- assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
57
- undefined
58
- ) {
59
- userMarketDetails[i].isCollateral = true;
60
- } else {
61
- userMarketDetails[i].isCollateral = false;
62
- }
63
- depositValues.push(
64
- calcValuation(
65
- userMarketDetails[i].depositBalance,
66
- new BigNumber(userMarketDetails[i].underlyingPrice)
67
- )
68
- );
69
- }
70
-
71
- totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number) => {
72
- if (userMarketDetails[index].isCollateral)
73
- return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
74
- return p;
75
- }, new BigNumber(0));
76
-
77
- var accountLiquidity: [BN, BN] = await this.env.comptroller.raw.getAccountLiquidity(
78
- userAddress
79
- );
80
-
81
- var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
82
- new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
83
- );
84
-
85
- if (borrowedvaluation.lt('0.00001')) {
86
- // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
87
- borrowedvaluation = new BigNumber(0);
88
- }
89
-
90
- const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(
91
- consts.BORROW_LIMIT_BUFFER
92
- );
93
- const minimumBorrowLimitAllowed = borrowedvaluation.div(consts.BORROW_LIMIT_BUFFER);
94
-
95
- var borrowableAmount: BigNumber;
96
- if (bufferedBorrowLimit.lte(borrowedvaluation)) {
97
- borrowableAmount = new BigNumber(0);
98
- } else {
99
- borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
100
- }
101
-
102
- for (var i = 0; i < marketCount; i++) {
103
- const auToken = consts.networkAddresses.auTokens[i];
104
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
105
- this._networkConnection,
106
- auToken.address,
107
- auToken.underlying
108
- );
109
- const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0)
110
- ? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
111
- : new BigNumber(0);
112
- const maxWithdrawCap: BigNumber = borrowLimitMargin
113
- .div(userMarketDetails[i].collateralRatio)
114
- .div(userMarketDetails[i].underlyingPrice);
115
- userMarketDetails[i].maxWithdrawableAmount =
116
- userMarketDetails[i].isCollateral &&
117
- maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
118
- ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false)
119
- : new TokenAmount(
120
- moneyMarket.underlying,
121
- userMarketDetails[i].depositBalance.rawAmount()
122
- );
123
- }
124
-
125
- return {
126
- markets: userMarketDetails,
127
- borrowLimit: {
128
- currency: 'USD',
129
- amount: bufferedBorrowLimit.toFixed(consts.DECIMAL_PRECISION),
130
- },
131
- borrowableAmount: {
132
- currency: 'USD',
133
- amount: borrowableAmount.toFixed(consts.DECIMAL_PRECISION),
134
- },
135
- };
136
- }
137
-
138
- public async getTokenPrice(token: Token): Promise<types.CurrencyAmount> {
139
- const price = await fetchPrice(token.address, this._networkConnection.provider);
140
- return {
141
- currency: 'USD',
142
- amount: price.toFixed(consts.DECIMAL_PRECISION),
143
- };
144
- }
145
-
146
- public async calcBorrowPower(tokenAmount: TokenAmount) {
147
- const autoken = consts.networkAddresses.auTokens.find((auToken) =>
148
- isSameAddress(auToken.underlying, tokenAmount.token.address)
149
- )!;
150
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
151
- this._networkConnection,
152
- autoken.address,
153
- autoken.underlying
154
- );
155
- const collateralRatio = await moneyMarket.getCollateralRatio();
156
- const underlyingPrice = await fetchPrice(
157
- tokenAmount.token.address,
158
- this._networkConnection.provider
159
- );
160
- const borrowPower = calcValuation(tokenAmount!, new BigNumber(underlyingPrice))
161
- .multipliedBy(collateralRatio)
162
- .multipliedBy(consts.BORROW_LIMIT_BUFFER);
163
- return {
164
- currency: 'USD',
165
- amount: borrowPower.toFixed(consts.DECIMAL_PRECISION),
166
- };
167
- }
168
-
169
- public calcHypotheticalStats({
170
- userMarketDetail,
171
- currentBorrowLimit,
172
- currentBorrowValuation,
173
- action,
174
- tokenAmount,
175
- }: {
176
- userMarketDetail: types.UserMarketDetails;
177
- currentBorrowLimit: types.CurrencyAmount;
178
- currentBorrowValuation: types.CurrencyAmount;
179
- action: types.MarketAction;
180
- tokenAmount?: TokenAmount;
181
- }): types.HypotheticalStats {
182
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
183
- newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
184
- switch (action) {
185
- case types.MarketAction.EnableCollateral:
186
- case types.MarketAction.DisableCollateral:
187
- var deltaBorrowLimit = calcValuation(
188
- userMarketDetail.depositBalance,
189
- new BigNumber(userMarketDetail.underlyingPrice)
190
- )
191
- .multipliedBy(userMarketDetail.collateralRatio)
192
- .multipliedBy(consts.BORROW_LIMIT_BUFFER);
193
- newBorrowLimit =
194
- action == types.MarketAction.EnableCollateral
195
- ? newBorrowLimit.plus(deltaBorrowLimit)
196
- : newBorrowLimit.minus(deltaBorrowLimit);
197
- break;
198
-
199
- case types.MarketAction.Deposit:
200
- case types.MarketAction.Withdraw:
201
- deltaBorrowLimit = calcValuation(
202
- tokenAmount!,
203
- new BigNumber(userMarketDetail.underlyingPrice)
204
- )
205
- .multipliedBy(userMarketDetail.collateralRatio)
206
- .multipliedBy(consts.BORROW_LIMIT_BUFFER);
207
- newBorrowLimit =
208
- action == types.MarketAction.Deposit
209
- ? newBorrowLimit.plus(deltaBorrowLimit)
210
- : newBorrowLimit.minus(deltaBorrowLimit);
211
- break;
212
-
213
- case types.MarketAction.Borrow:
214
- case types.MarketAction.Repay:
215
- var deltaBorrowValuation = calcValuation(
216
- tokenAmount!,
217
- new BigNumber(userMarketDetail.underlyingPrice)
218
- );
219
- newBorrowValuation =
220
- action == types.MarketAction.Borrow
221
- ? newBorrowValuation.plus(deltaBorrowValuation)
222
- : newBorrowValuation.minus(deltaBorrowValuation);
223
- break;
224
- }
225
- return {
226
- newBorrowLimit: {
227
- amount: newBorrowLimit!.toFixed(consts.DECIMAL_PRECISION),
228
- currency: 'USD',
229
- },
230
- newBorrowUtilization: newBorrowLimit.eq(0)
231
- ? newBorrowValuation.eq(0)
232
- ? 0
233
- : 9999.99
234
- : newBorrowValuation!.div(newBorrowLimit!).toNumber(),
235
- };
236
- }
237
-
238
- /**
239
- * Get ply circulating supply.
240
- * It is calculated by the total supply, minus:
241
- * - Ply in team multisig contract
242
- * - Ply in comptroller contract
243
- * - Ply in fairlaunch contract
244
- * - Ply in vesting contract
245
- */
246
- public async getPlyCirculatingSupply(): Promise<TokenAmount> {
247
- const multicallRead = new MulticallRead(this._networkConnection);
248
- const baseBalanceOfCall = {
249
- contract: this.env.ply,
250
- method: 'balanceOf',
251
- returnTypes: ['uint256'],
252
- };
253
-
254
- const listAddrs = [
255
- consts.networkAddresses.misc.TEAM_MULTISIG,
256
- consts.networkAddresses.misc.COMPTROLLER,
257
- consts.networkAddresses.misc.AURIFAIRLAUNCH,
258
- consts.networkAddresses.misc.PLY_TOKEN_LOCK,
259
- consts.networkAddresses.misc.TEAM_MULTISIG_AURORA_PLUS,
260
- consts.networkAddresses.misc.AURORA_PLUS,
261
- consts.networkAddresses.misc.PULP_CONTRACT,
262
- ];
263
-
264
- const calls = listAddrs.map((addr) => ({
265
- ...baseBalanceOfCall,
266
- args: [addr],
267
- }));
268
-
269
- const callResults = (await multicallRead.aggregate(calls)) as BN[][];
270
-
271
- let circulatingSupply: BN = BN.from(
272
- '1' + '0'.repeat(10) + '0'.repeat(getDecimal(this.env.ply.address))
273
- );
274
- callResults.forEach((result, i) => {
275
- circulatingSupply = circulatingSupply.sub(result[0]);
276
- });
277
-
278
- return new TokenAmount(PLYToken, circulatingSupply.toString());
279
- }
280
-
281
- public async getUtilisation(userAddr: types.Address): Promise<BigNumber> {
282
- let accountDetail =
283
- await this.env.auriInternalLens.callStatic.getAccountLiquidityAccrueInterest(userAddr);
284
- let sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
285
- let sumCol = new BigNumber(accountDetail.sumCollateral.toString());
286
- return sumBorrow.dividedBy(sumCol);
287
- }
288
-
289
- public async sneakAccounts(
290
- accounts: string[],
291
- tokenAddresses: string[],
292
- dust: BigNumber = new BigNumber(0.1)
293
- ): Promise<types.AccountAuTokensInfo[]> {
294
- const _1E18 = BN.from(10).pow(18);
295
- const oracle = this.env.oracle;
296
- const tokens = tokenAddresses.map((addr) =>
297
- this.env.getContract<AuToken>(addr, abis.AuTokenABI.abi)
298
- );
299
- const prices = await oracle.callStatic.getUnderlyingPrices(tokenAddresses);
300
- const exrate = await this.env.auriInternalLens.callStatic.getExchangeRates(tokenAddresses);
301
-
302
- const res: types.AccountAuTokensInfo[] = [];
303
-
304
- for (let addr of accounts) {
305
- const infos: types.AccountAuTokenInfo[] = [];
306
- for (let i = 0; i < tokens.length; ++i) {
307
- const snapshot = await tokens[i].callStatic.getAccountSnapshot(addr);
308
- const bal = snapshot[0].mul(exrate[i]).div(_1E18).mul(prices[i]).div(_1E18);
309
- const bor = snapshot[1].mul(prices[i]).div(_1E18);
310
-
311
- let balR = new BigNumber(bal.toString()).dividedBy(_1E18.toString());
312
- let borR = new BigNumber(bor.toString()).dividedBy(_1E18.toString());
313
-
314
- if (balR.lte(dust) && borR.lte(dust)) continue;
315
-
316
- infos.push({
317
- token: getSymbol(tokenAddresses[i]),
318
- deposit: balR,
319
- borrow: borR,
320
- });
321
- }
322
- res.push({
323
- address: addr,
324
- tokens: infos,
325
- });
326
- }
327
- return res;
328
- }
329
-
330
- public async getLTVAndLiquidationThreshold(userAddr: types.Address) {
331
- let totalSuppliedValue = new BigNumber(0);
332
- let totalBorrowedValue = new BigNumber(0);
333
- let collateralValue = new BigNumber(0);
334
- const assetsIn = await this.env.comptroller.callStatic.getAssetsIn(userAddr);
335
- const marketValues = await Promise.all(
336
- consts.networkAddresses.auTokens.map(async (auToken) => {
337
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
338
- this._networkConnection,
339
- auToken.address,
340
- auToken.underlying
341
- );
342
- return Promise.all([
343
- moneyMarket.getCollateralRatio(),
344
- moneyMarket.getDepositBorrowValue(userAddr),
345
- ]);
346
- })
347
- );
348
- consts.networkAddresses.auTokens.forEach(async (auToken, i) => {});
349
- for (var i = 0; i < marketValues.length; i++) {
350
- const auToken = consts.networkAddresses.auTokens[i];
351
- const [collateralRatio, depositBorrowValue] = marketValues[i];
352
- if (
353
- assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
354
- undefined
355
- ) {
356
- totalSuppliedValue = totalSuppliedValue.plus(depositBorrowValue.suppliedValue);
357
- collateralValue = collateralValue.plus(
358
- depositBorrowValue.suppliedValue.times(collateralRatio)
359
- );
360
- }
361
- totalBorrowedValue = totalBorrowedValue.plus(depositBorrowValue.borrowedValue);
362
- }
363
- const ltv = totalBorrowedValue.div(totalSuppliedValue);
364
- const liquidationThreshold = collateralValue.div(totalSuppliedValue);
365
- return {
366
- ltv,
367
- liquidationThreshold,
368
- };
369
- }
370
-
371
- public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
372
- let sum = new BigNumber(0);
373
- let totalSuppliedValue = new BigNumber(0);
374
- let totalBorrowedValue = new BigNumber(0);
375
- let netApy = new BigNumber(0);
376
-
377
- const apys = await Promise.all(
378
- consts.networkAddresses.auTokens.map((auToken) => {
379
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
380
- this._networkConnection,
381
- auToken.address,
382
- auToken.underlying
383
- );
384
- const apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
385
- return apyWithoutIncentive;
386
- })
387
- );
388
-
389
- for (const apy of apys) {
390
- sum = sum.plus(apy.sum);
391
- totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
392
- totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
393
- }
394
-
395
- if (sum.gt(0)) {
396
- netApy = sum.div(totalSuppliedValue);
397
- } else if (sum.lt(0)) {
398
- netApy = sum.div(totalBorrowedValue);
399
- }
400
- return netApy;
401
- }
402
-
403
- public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
404
- let sum = new BigNumber(0);
405
- let totalSuppliedValue = new BigNumber(0);
406
- let totalBorrowedValue = new BigNumber(0);
407
- let netApy = new BigNumber(0);
408
- const apys = await Promise.all(
409
- consts.networkAddresses.auTokens.map((auToken) => {
410
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
411
- this._networkConnection,
412
- auToken.address,
413
- auToken.underlying
414
- );
415
- const apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
416
- return apyWithIncentive;
417
- })
418
- );
419
-
420
- for (const apy of apys) {
421
- sum = sum.plus(apy.sum);
422
- totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
423
- totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
424
- }
425
-
426
- if (sum.gt(0)) {
427
- netApy = sum.div(totalSuppliedValue);
428
- } else if (sum.lt(0)) {
429
- netApy = sum.div(totalBorrowedValue);
430
- }
431
- return netApy;
432
- }
433
- }