@aurigami/sdk 1.4.8 → 1.5.0-dummy-1

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/src/SDK.ts CHANGED
@@ -1,65 +1,82 @@
1
1
  import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
2
2
  import {
3
- LockingDetails,
4
- PlyAuroraPoolDetails,
3
+ PlyUsdcPoolDetails,
5
4
  NetworkConnection,
6
5
  UserDetails,
7
6
  UserMarketDetails,
8
7
  Address,
9
8
  CurrencyAmount,
10
9
  HypotheticalStats,
11
- MarketAction
10
+ MarketAction,
11
+ TokenValuation,
12
12
  } from './types';
13
- import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
13
+ import {
14
+ networkAddresses,
15
+ BORROW_LIMIT_BUFFER,
16
+ DECIMAL_PRECISION,
17
+ ONE_DAY,
18
+ PlyUsdcPid,
19
+ ALL_STAKING_POOLS,
20
+ PLYUSDCRewardTokens,
21
+ } from './constants';
14
22
  import { TransactionResponse } from '@ethersproject/abstract-provider';
15
- import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
16
- import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
23
+ import { Contract, BigNumber as BN } from 'ethers';
24
+ import {
25
+ isSameAddress,
26
+ decimalFactor,
27
+ calcLMRewardApr,
28
+ getDecimal,
29
+ } from './helpers';
17
30
  import { MoneyMarketRead } from './MoneyMarket';
18
- import { fetchValuation, fetchPrice, calcValuation } from './priceFetcher';
19
- import { AuriFairLaunch, Comptroller, TokenLock, AuriLens } from '@aurigami/contracts/typechain';
31
+ import {
32
+ fetchValuation,
33
+ fetchPrice,
34
+ calcValuation,
35
+ valuateToken,
36
+ } from './priceFetcher';
37
+ import {
38
+ AuriFairLaunch,
39
+ Comptroller,
40
+ AuriLens,
41
+ IERC20,
42
+ } from '@aurigami/contracts/typechain';
20
43
  import { TokenAmount } from './tokenAmount';
21
- import { AURPLYToken, PLYToken, Token } from './token';
44
+ import { PLYUSDCToken, PLYToken, Token } from './token';
22
45
  import BigNumber from 'bignumber.js';
23
46
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
24
47
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
25
- import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
26
- import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
27
- import FaucetABI from "@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json";
48
+ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
49
+ import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
50
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
51
+ import { PapermillRead } from './Papermill';
28
52
 
29
53
  export class SdkRead extends BlockchainEntityRead {
30
-
31
54
  protected _comptroller: Comptroller;
32
- protected _tokenLock: TokenLock;
33
55
  protected _auriFairLaunch: AuriFairLaunch;
34
56
  protected _auriLens: AuriLens;
35
57
  constructor(networkConnection: NetworkConnection) {
36
58
  super(networkConnection);
37
- this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
38
- this._tokenLock = new Contract(networkAddresses.misc.TOKENLOCK, TokenLockABI.abi, networkConnection.provider) as TokenLock;
39
- this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
40
- this._auriLens = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider) as AuriLens;
41
- }
42
-
43
- public async getLockingDetails(): Promise<LockingDetails> {
44
- const currentTime = getCurrentTimestamp();
45
- const currentWeek = BN.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
46
- const denominator = 10000;
47
- var promises = [];
48
- promises.push(this._tokenLock.percentageLock(currentWeek));
49
- promises.push(this._tokenLock.percentageLock(currentWeek + 1).catch((err: any) => {return denominator}));
50
- var values: string[] = await Promise.all(promises).then((res) => {
51
- return res.map((v) => {return v.toString()})
52
- });
53
- return {
54
- vestingStart: REWARDCLAIMSTART, // 10 Jan 2023
55
- currentUnlockPortion: (new BigNumber(denominator).minus(values[0])).div(denominator).toNumber(),
56
- nextUnlockPortion: (new BigNumber(denominator).minus(values[1])).div(denominator).toNumber(),
57
- };
59
+ this._comptroller = new Contract(
60
+ networkAddresses.misc.COMPTROLLER,
61
+ ComptrollerABI.abi,
62
+ networkConnection.provider
63
+ ) as Comptroller;
64
+ this._auriFairLaunch = new Contract(
65
+ networkAddresses.misc.AURIFAIRLAUNCH,
66
+ AuriFairLaunchABI.abi,
67
+ networkConnection.provider
68
+ ) as AuriFairLaunch;
69
+ this._auriLens = new Contract(
70
+ networkAddresses.misc.AURILENS,
71
+ AuriLensABI.abi,
72
+ networkConnection.provider
73
+ ) as AuriLens;
58
74
  }
59
75
 
60
76
  public async getUserDetails(userAddress: string): Promise<UserDetails> {
61
77
  const marketCount = networkAddresses.auTokens.length;
62
- var userMarketDetails: UserMarketDetails[] = [], assetsIn: string[];
78
+ var userMarketDetails: UserMarketDetails[] = [],
79
+ assetsIn: string[];
63
80
  var promises = [];
64
81
  var totalBorrowLimit = new BigNumber(0);
65
82
  var pricePromises = [];
@@ -67,197 +84,340 @@ export class SdkRead extends BlockchainEntityRead {
67
84
  const userMarketDetail: UserMarketDetails = {} as UserMarketDetails;
68
85
  userMarketDetails.push(userMarketDetail);
69
86
  userMarketDetail.market = auToken.underlying;
70
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
71
- promises.push(moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.depositBalance = res}));
72
- promises.push(moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.borrowBalance = res}));
73
- promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {userMarketDetail.collateralRatio = res.toNumber()}));
74
- pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
75
- userMarketDetail.underlyingPrice = res.toString();
76
- return res;
77
- }));
87
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
88
+ this._networkConnection,
89
+ auToken.address,
90
+ auToken.underlying
91
+ );
92
+ promises.push(
93
+ moneyMarket
94
+ .getUserDepositBalance(userAddress)
95
+ .then((res: TokenAmount) => {
96
+ userMarketDetail.depositBalance = res;
97
+ })
98
+ );
99
+ promises.push(
100
+ moneyMarket
101
+ .getUserBorrowBalance(userAddress)
102
+ .then((res: TokenAmount) => {
103
+ userMarketDetail.borrowBalance = res;
104
+ })
105
+ );
106
+ promises.push(
107
+ moneyMarket.getCollateralRatio().then((res: BigNumber) => {
108
+ userMarketDetail.collateralRatio = res.toNumber();
109
+ })
110
+ );
111
+ pricePromises.push(
112
+ fetchPrice(
113
+ moneyMarket.underlying.address,
114
+ this._networkConnection.provider
115
+ ).then((res) => {
116
+ userMarketDetail.underlyingPrice = res.toString();
117
+ return res;
118
+ })
119
+ );
78
120
  }
79
121
 
80
- promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
81
-
122
+ promises.push(
123
+ this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {
124
+ assetsIn = res;
125
+ })
126
+ );
127
+
82
128
  await Promise.all(promises);
83
129
  var underlyingPrices = await Promise.all(pricePromises);
84
- var depositValues = []
85
- for (var i = 0; i < marketCount; i ++) {
130
+ var depositValues = [];
131
+ for (var i = 0; i < marketCount; i++) {
86
132
  const auToken = networkAddresses.auTokens[i];
87
- if (assetsIn!.find((auAddress: Address) => isSameAddress(auToken.address, auAddress)) !== undefined) {
133
+ if (
134
+ assetsIn!.find((auAddress: Address) =>
135
+ isSameAddress(auToken.address, auAddress)
136
+ ) !== undefined
137
+ ) {
88
138
  userMarketDetails[i].isCollateral = true;
89
139
  } else {
90
140
  userMarketDetails[i].isCollateral = false;
91
141
  }
92
- depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
142
+ depositValues.push(
143
+ calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i])
144
+ );
93
145
  }
94
146
 
95
- totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number)=> {
96
- if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
97
- return p;
98
- }, new BigNumber(0))
99
-
100
- promises = new Array(3);
101
- var accountLiquidity: [BN, BN], rewardBalancesMetadata, lockedAmount: BN;
102
- promises[0] = this._comptroller.getAccountLiquidity(userAddress);
103
- promises[1] = this._auriLens.callStatic.claimRewards(this._comptroller.address, this._auriFairLaunch.address, [], {from: userAddress});
104
- promises[2] = this._tokenLock.lockedAmounts(userAddress);
147
+ totalBorrowLimit = depositValues.reduce(
148
+ (p: BigNumber, v: BigNumber, index: number) => {
149
+ if (userMarketDetails[index].isCollateral)
150
+ return p.plus(
151
+ v.multipliedBy(userMarketDetails[index].collateralRatio)
152
+ );
153
+ return p;
154
+ },
155
+ new BigNumber(0)
156
+ );
105
157
 
106
- [accountLiquidity, rewardBalancesMetadata, lockedAmount] = await Promise.all(promises);
158
+ var accountLiquidity: [BN, BN] =
159
+ await this._comptroller.getAccountLiquidity(userAddress);
107
160
 
108
- var borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
161
+ var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
162
+ new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
163
+ );
109
164
 
110
- if (borrowedvaluation.lt("0.00001")) { // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
165
+ if (borrowedvaluation.lt('0.00001')) {
166
+ // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
111
167
  borrowedvaluation = new BigNumber(0);
112
- }
113
-
114
- const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
115
- const minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
168
+ }
169
+
170
+ const bufferedBorrowLimit: BigNumber =
171
+ totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
172
+ const minimumBorrowLimitAllowed =
173
+ borrowedvaluation.div(BORROW_LIMIT_BUFFER);
116
174
 
117
175
  var borrowableAmount: BigNumber;
118
176
  if (bufferedBorrowLimit.lte(borrowedvaluation)) {
119
- borrowableAmount = new BigNumber(0)
177
+ borrowableAmount = new BigNumber(0);
120
178
  } else {
121
179
  borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
122
180
  }
123
181
 
124
- for (var i = 0; i < marketCount; i ++) {
182
+ for (var i = 0; i < marketCount; i++) {
125
183
  const auToken = networkAddresses.auTokens[i];
126
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
127
- const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
128
- const maxWithdrawCap: BigNumber = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
129
- userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
130
- ? new TokenAmount(
131
- moneyMarket.underlying,
132
- maxWithdrawCap.toFixed(24),
133
- false
134
- )
135
- : new TokenAmount(
136
- moneyMarket.underlying,
137
- userMarketDetails[i].depositBalance.rawAmount()
138
- );
184
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
185
+ this._networkConnection,
186
+ auToken.address,
187
+ auToken.underlying
188
+ );
189
+ const borrowLimitMargin = totalBorrowLimit
190
+ .minus(minimumBorrowLimitAllowed)
191
+ .gt(0)
192
+ ? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
193
+ : new BigNumber(0);
194
+ const maxWithdrawCap: BigNumber = borrowLimitMargin
195
+ .div(userMarketDetails[i].collateralRatio)
196
+ .div(underlyingPrices[i]);
197
+ userMarketDetails[i].maxWithdrawableAmount =
198
+ userMarketDetails[i].isCollateral &&
199
+ maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
200
+ ? new TokenAmount(
201
+ moneyMarket.underlying,
202
+ maxWithdrawCap.toFixed(24),
203
+ false
204
+ )
205
+ : new TokenAmount(
206
+ moneyMarket.underlying,
207
+ userMarketDetails[i].depositBalance.rawAmount()
208
+ );
139
209
  }
140
210
 
141
211
  return {
142
212
  markets: userMarketDetails,
143
213
  borrowLimit: {
144
- currency: "USD",
145
- amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
214
+ currency: 'USD',
215
+ amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION),
146
216
  },
147
- accruedPly: new TokenAmount(PLYToken, rewardBalancesMetadata.plyAccrured.toString()),
148
- lockedPly: new TokenAmount(PLYToken, lockedAmount.toString()),
217
+ userLockingDetails: await new PapermillRead(
218
+ this._networkConnection
219
+ ).getLockingDetails(userAddress),
149
220
  borrowableAmount: {
150
- currency: "USD",
151
- amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
221
+ currency: 'USD',
222
+ amount: borrowableAmount.toFixed(DECIMAL_PRECISION),
152
223
  },
153
224
  };
154
225
  }
155
226
 
156
- public async getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails> {
157
- var stakedLiquidity: BN, rewardPerSecond: BN;
158
- var promises = [];
159
- promises.push(this._auriFairLaunch.getPoolInfo(AurPlyPid).then((res) => {
160
- stakedLiquidity = res.totalStake;
161
- rewardPerSecond = res.rewardPerSeconds[0];
162
- }));
163
- await Promise.all(promises);
227
+ public async getPlyUsdcPoolDetails(): Promise<PlyUsdcPoolDetails> {
228
+ var stakedLiquidity: BN, rewardPerSeconds: BN[];
229
+ await this._auriFairLaunch.getPoolInfo(PlyUsdcPid).then((res) => {
230
+ stakedLiquidity = res.totalStake;
231
+ rewardPerSeconds = res.rewardPerSeconds;
232
+ });
164
233
 
165
- promises = [];
166
- var rewardPerSecondValuation: BigNumber, totalStakeValuation: BigNumber;
167
- promises.push(fetchValuation(new TokenAmount(
168
- PLYToken,
169
- rewardPerSecond!.toString()
170
- ), this._networkConnection.provider).then((res) => rewardPerSecondValuation = res));
171
- promises.push(fetchValuation(new TokenAmount(
172
- AURPLYToken,
234
+ let stakedLiquidityAmount = new TokenAmount(
235
+ PLYUSDCToken,
173
236
  stakedLiquidity!.toString()
174
- ), this._networkConnection.provider).then((res) => totalStakeValuation = res));
175
- await Promise.all(promises);
237
+ );
238
+
239
+ var promises = [];
240
+ for (let i = 0; i < rewardPerSeconds!.length; i++) {
241
+ let rewardTokenAddress = PLYUSDCRewardTokens[i];
242
+ let rewardToken = new Token(
243
+ rewardTokenAddress,
244
+ getDecimal(rewardTokenAddress)
245
+ );
246
+ let rewardPerSecond = rewardPerSeconds![i];
247
+ promises.push(
248
+ fetchValuation(
249
+ new TokenAmount(rewardToken, rewardPerSecond!.toString()),
250
+ this._networkConnection.provider
251
+ )
252
+ );
253
+ }
254
+
255
+ const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
256
+ (p: BigNumber, v: BigNumber) => p.plus(v),
257
+ new BigNumber(0)
258
+ );
259
+
260
+ var totalStakeValuation: BigNumber = await fetchValuation(
261
+ stakedLiquidityAmount,
262
+ this._networkConnection.provider
263
+ );
176
264
 
177
265
  return {
178
- totalStakedLiquidity: new TokenAmount(
179
- AURPLYToken,
180
- stakedLiquidity!.toString()
181
- ),
182
- apy: calcLMRewardApr(rewardPerSecondValuation!, totalStakeValuation!, ONE_DAY * 365).toFixed(DECIMAL_PRECISION),
266
+ totalStakedLiquidity: {
267
+ tokenAmount: stakedLiquidityAmount,
268
+ currencyAmount: {
269
+ currency: 'USD',
270
+ amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION),
271
+ },
272
+ },
273
+ apy: calcLMRewardApr(
274
+ rewardPerSecondValuation,
275
+ totalStakeValuation,
276
+ ONE_DAY * 365
277
+ ).toFixed(DECIMAL_PRECISION),
183
278
  };
184
279
  }
185
280
 
186
281
  public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
187
- const price = await fetchPrice(token.address, this._networkConnection.provider);
282
+ const price = await fetchPrice(
283
+ token.address,
284
+ this._networkConnection.provider
285
+ );
188
286
  return {
189
- currency: "USD",
190
- amount: price.toFixed(DECIMAL_PRECISION)
191
- }
287
+ currency: 'USD',
288
+ amount: price.toFixed(DECIMAL_PRECISION),
289
+ };
192
290
  }
193
- public async stakeBalanceOf(user: string): Promise<TokenAmount> {
194
- const userInfo = await this._auriFairLaunch.getUserInfo(AurPlyPid, user);
195
- return new TokenAmount(
196
- AURPLYToken,
197
- userInfo.amount.toString()
198
- )
291
+
292
+ /**
293
+ * Get amount and value in $ of staked LP tokens
294
+ */
295
+ public async stakeBalanceOf(user: string): Promise<TokenValuation> {
296
+ const userInfo = await this._auriFairLaunch.getUserInfo(PlyUsdcPid, user);
297
+ let stakeAmount = new TokenAmount(PLYUSDCToken, userInfo.amount.toString());
298
+
299
+ return valuateToken(stakeAmount, this._networkConnection.provider);
300
+ }
301
+
302
+ /**
303
+ * Get amount and value in $ of LP token in user wallet
304
+ */
305
+ public async LpBalanceOf(user: string): Promise<TokenValuation> {
306
+ let lpERC20 = new Contract(
307
+ networkAddresses.tokens.PLYUSDC,
308
+ EIP20InterfaceABI.abi,
309
+ this._networkConnection.provider
310
+ ) as IERC20;
311
+ let balance = await lpERC20.balanceOf(user);
312
+
313
+ return valuateToken(
314
+ new TokenAmount(PLYUSDCToken, balance.toString()),
315
+ this._networkConnection.provider
316
+ );
199
317
  }
200
318
 
201
319
  public calcHypotheticalStats({
202
- userMarketDetail,
320
+ userMarketDetail,
203
321
  currentBorrowLimit,
204
322
  currentBorrowValuation,
205
323
  action,
206
- tokenAmount
324
+ tokenAmount,
207
325
  }: {
208
- userMarketDetail: UserMarketDetails,
209
- currentBorrowLimit: CurrencyAmount,
210
- currentBorrowValuation: CurrencyAmount,
211
- action: MarketAction,
212
- tokenAmount?: TokenAmount
326
+ userMarketDetail: UserMarketDetails;
327
+ currentBorrowLimit: CurrencyAmount;
328
+ currentBorrowValuation: CurrencyAmount;
329
+ action: MarketAction;
330
+ tokenAmount?: TokenAmount;
213
331
  }): HypotheticalStats {
214
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount), newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
332
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
333
+ newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
215
334
  switch (action) {
216
335
  case MarketAction.EnableCollateral:
217
336
  case MarketAction.DisableCollateral:
218
- var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
219
- newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
337
+ var deltaBorrowLimit = calcValuation(
338
+ userMarketDetail.depositBalance,
339
+ new BigNumber(userMarketDetail.underlyingPrice)
340
+ )
341
+ .multipliedBy(userMarketDetail.collateralRatio)
342
+ .multipliedBy(BORROW_LIMIT_BUFFER);
343
+ newBorrowLimit =
344
+ action == MarketAction.EnableCollateral
345
+ ? newBorrowLimit.plus(deltaBorrowLimit)
346
+ : newBorrowLimit.minus(deltaBorrowLimit);
220
347
  break;
221
348
 
222
349
  case MarketAction.Deposit:
223
350
  case MarketAction.Withdraw:
224
- deltaBorrowLimit = calcValuation(tokenAmount!, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
225
- newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
351
+ deltaBorrowLimit = calcValuation(
352
+ tokenAmount!,
353
+ new BigNumber(userMarketDetail.underlyingPrice)
354
+ )
355
+ .multipliedBy(userMarketDetail.collateralRatio)
356
+ .multipliedBy(BORROW_LIMIT_BUFFER);
357
+ newBorrowLimit =
358
+ action == MarketAction.Deposit
359
+ ? newBorrowLimit.plus(deltaBorrowLimit)
360
+ : newBorrowLimit.minus(deltaBorrowLimit);
226
361
  break;
227
362
 
228
363
  case MarketAction.Borrow:
229
364
  case MarketAction.Repay:
230
- var deltaBorrowValuation = calcValuation(tokenAmount!, new BigNumber(userMarketDetail.underlyingPrice));
231
- newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
365
+ var deltaBorrowValuation = calcValuation(
366
+ tokenAmount!,
367
+ new BigNumber(userMarketDetail.underlyingPrice)
368
+ );
369
+ newBorrowValuation =
370
+ action == MarketAction.Borrow
371
+ ? newBorrowValuation.plus(deltaBorrowValuation)
372
+ : newBorrowValuation.minus(deltaBorrowValuation);
232
373
  break;
233
374
  }
234
375
  return {
235
376
  newBorrowLimit: {
236
377
  amount: newBorrowLimit!.toFixed(DECIMAL_PRECISION),
237
- currency: "USD"
378
+ currency: 'USD',
238
379
  },
239
- newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99
240
- : newBorrowValuation!.div(newBorrowLimit!).toNumber()
241
- }
380
+ newBorrowUtilization: newBorrowLimit.eq(0)
381
+ ? newBorrowValuation.eq(0)
382
+ ? 0
383
+ : 9999.99
384
+ : newBorrowValuation!.div(newBorrowLimit!).toNumber(),
385
+ };
242
386
  }
243
387
  }
244
388
 
245
389
  export class SdkReadWrite extends SdkRead {
390
+ /**
391
+ * Claim PLY reward in all markets + staking pools
392
+ */
246
393
  public async claim(): Promise<TransactionResponse> {
247
- return this._auriLens.connect(this._networkConnection.signer!).claimRewards(
248
- this._comptroller.address,
249
- this._auriFairLaunch.address,
250
- [AurPlyPid]
251
- );
394
+ return this._auriLens
395
+ .connect(this._networkConnection.signer!)
396
+ .claimRewards(
397
+ this._comptroller.address,
398
+ this._auriFairLaunch.address,
399
+ ALL_STAKING_POOLS
400
+ );
252
401
  }
402
+
253
403
  public async stake(amount: TokenAmount): Promise<TransactionResponse> {
254
- return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(AurPlyPid, amount.rawAmount());
404
+ return this._auriFairLaunch
405
+ .connect(this._networkConnection.signer!)
406
+ .deposit(PlyUsdcPid, amount.rawAmount());
255
407
  }
408
+
256
409
  public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
257
- return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(AurPlyPid, amount.rawAmount());
410
+ return this._auriFairLaunch
411
+ .connect(this._networkConnection.signer!)
412
+ .withdraw(PlyUsdcPid, amount.rawAmount());
258
413
  }
414
+
259
415
  public async faucetDrip(): Promise<TransactionResponse> {
260
- const faucet = new Contract(networkAddresses.misc.FAUCET, FaucetABI.abi, this._networkConnection.provider);
416
+ const faucet = new Contract(
417
+ networkAddresses.misc.FAUCET,
418
+ FaucetABI.abi,
419
+ this._networkConnection.provider
420
+ );
261
421
  return faucet.connect(this._networkConnection.signer!).drip();
262
422
  }
263
423
  }