@aurigami/sdk 1.6.5 → 1.6.7

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/dist/sdk.esm.js CHANGED
@@ -4,17 +4,18 @@ import { Logger } from 'ethers/lib/utils';
4
4
  import MAINNET_ADDRESSES from '@aurigami/contracts/deployments/aurora_mainnet.json';
5
5
  export { default as MAINNET_ADDRESSES } from '@aurigami/contracts/deployments/aurora_mainnet.json';
6
6
  export { default as TESTNET_ADDRESSES } from '@aurigami/contracts/deployments/aurora_testnet.json';
7
- import abis$7 from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
8
- import abis$6 from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
7
+ import abis$6 from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
8
+ import abis$5 from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
9
9
  import AuriAirdropABI from '@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json';
10
10
  import abis$1 from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
11
11
  import abis$2 from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
12
12
  import AuriOracleABI from '@aurigami/contracts/artifacts/contracts/AuriOracle.sol/AuriOracle.json';
13
13
  import abis from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
14
- import abis$8 from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
14
+ import abis$7 from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
15
15
  import abis$3 from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
16
16
  import IUniswapV2PairABI from '@aurigami/contracts/artifacts/contracts/mock/IUniswapV2Pair.sol/IUniswapV2Pair.json';
17
- import abis$5 from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
17
+ import abis$8 from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
18
+ import abis$a from '@aurigami/contracts/artifacts/contracts/mock/UltilizationHelper.sol/UltilizationHelper.json';
18
19
  import abis$4 from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
19
20
  import abis$9 from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
20
21
  import { Signer } from '@ethersproject/abstract-signer';
@@ -2057,7 +2058,7 @@ var AirdropRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2057
2058
  var _this;
2058
2059
 
2059
2060
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2060
- _this._airDrop = new Contract(networkAddresses.misc.AURI_AIRDROP, AuriAirdropABI.abi, networkConnection.provider);
2061
+ _this.airDrop = new Contract(networkAddresses.misc.AURI_AIRDROP, AuriAirdropABI.abi, networkConnection.provider);
2061
2062
  return _this;
2062
2063
  }
2063
2064
  /**
@@ -2078,7 +2079,7 @@ var AirdropRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2078
2079
  case 0:
2079
2080
  tokenInstance = new Token(token, getDecimal(token));
2080
2081
  _context.next = 3;
2081
- return this._airDrop.getRedeemableReward(utils.formatBytes32String(campaign), token, user);
2082
+ return this.airDrop.getRedeemableReward(utils.formatBytes32String(campaign), token, user);
2082
2083
 
2083
2084
  case 3:
2084
2085
  rewards = _context.sent;
@@ -2122,7 +2123,7 @@ var AirdropReadWrite = /*#__PURE__*/function (_AirdropRead) {
2122
2123
  switch (_context2.prev = _context2.next) {
2123
2124
  case 0:
2124
2125
  assert(campaigns.length == tokens.length, 'campaigns and tokens must have the same length');
2125
- _context2.t0 = this._airDrop.connect(this._networkConnection.signer);
2126
+ _context2.t0 = this.airDrop.connect(this._networkConnection.signer);
2126
2127
  _context2.t1 = campaigns.map(function (e) {
2127
2128
  return utils.formatBytes32String(e);
2128
2129
  });
@@ -2200,92 +2201,6 @@ var Airdrop = /*#__PURE__*/function (_BlockchainEntity) {
2200
2201
  return Airdrop;
2201
2202
  }(BlockchainEntity);
2202
2203
 
2203
- var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2204
- _inheritsLoose(MulticallRead, _BlockchainEntityRead);
2205
-
2206
- function MulticallRead(networkConnection) {
2207
- var _this;
2208
-
2209
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2210
- _this._multicall = new Contract(networkAddresses.misc.MULTICALL, abis$5.abi, networkConnection.provider);
2211
- return _this;
2212
- }
2213
- /**
2214
- * Run multiple calls via multicall contract
2215
- */
2216
-
2217
-
2218
- var _proto = MulticallRead.prototype;
2219
-
2220
- _proto.aggregate =
2221
- /*#__PURE__*/
2222
- function () {
2223
- var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(calls) {
2224
- var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
2225
-
2226
- return runtime_1.wrap(function _callee$(_context) {
2227
- while (1) {
2228
- switch (_context.prev = _context.next) {
2229
- case 0:
2230
- txns = []; // prepare transactions
2231
-
2232
- i = 0;
2233
-
2234
- case 2:
2235
- if (!(i < calls.length)) {
2236
- _context.next = 11;
2237
- break;
2238
- }
2239
-
2240
- call = calls[i];
2241
- _context.next = 6;
2242
- return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
2243
-
2244
- case 6:
2245
- txn = _context.sent;
2246
- txns.push({
2247
- target: txn.to,
2248
- callData: txn.data
2249
- });
2250
-
2251
- case 8:
2252
- i++;
2253
- _context.next = 2;
2254
- break;
2255
-
2256
- case 11:
2257
- _context.next = 13;
2258
- return this._multicall.callStatic.aggregate(txns);
2259
-
2260
- case 13:
2261
- response = _context.sent;
2262
- // parse results
2263
- decodedReturn = [];
2264
-
2265
- for (_i = 0; _i < calls.length; _i++) {
2266
- decodedReturn.push(ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
2267
- }
2268
-
2269
- return _context.abrupt("return", decodedReturn);
2270
-
2271
- case 17:
2272
- case "end":
2273
- return _context.stop();
2274
- }
2275
- }
2276
- }, _callee, this);
2277
- }));
2278
-
2279
- function aggregate(_x) {
2280
- return _aggregate.apply(this, arguments);
2281
- }
2282
-
2283
- return aggregate;
2284
- }();
2285
-
2286
- return MulticallRead;
2287
- }(BlockchainEntityRead);
2288
-
2289
2204
  var ComptrollerRewardType;
2290
2205
 
2291
2206
  (function (ComptrollerRewardType) {
@@ -2304,148 +2219,42 @@ var MarketAction;
2304
2219
  MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
2305
2220
  })(MarketAction || (MarketAction = {}));
2306
2221
 
2307
- var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2308
- _inheritsLoose(MiscRead, _BlockchainEntityRead);
2222
+ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2223
+ _inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
2309
2224
 
2310
- function MiscRead(networkConnection) {
2225
+ function MoneyMarketRead(networkConnection, auToken, underlyingAsset) {
2311
2226
  var _this;
2312
2227
 
2313
2228
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2314
- _this._stakingRead = new StakingRead(networkConnection);
2315
2229
  _this.env = new AuriEnv(networkConnection);
2316
- return _this;
2317
- }
2318
2230
 
2319
- var _proto = MiscRead.prototype;
2231
+ if (isSameAddress(underlyingAsset, ETHAddress)) {
2232
+ _this.auToken = new Contract(auToken, abis$5.abi, networkConnection.provider);
2233
+ } else {
2234
+ _this.auToken = new Contract(auToken, abis$6.abi, networkConnection.provider);
2235
+ }
2320
2236
 
2321
- _proto.getUserDetails = /*#__PURE__*/function () {
2322
- var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
2323
- var _this2 = this;
2237
+ _this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
2238
+ return _this;
2239
+ }
2324
2240
 
2325
- var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
2241
+ var _proto = MoneyMarketRead.prototype;
2326
2242
 
2243
+ _proto.getRewardSpeeds = /*#__PURE__*/function () {
2244
+ var _getRewardSpeeds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2245
+ var speeds;
2327
2246
  return runtime_1.wrap(function _callee$(_context) {
2328
2247
  while (1) {
2329
2248
  switch (_context.prev = _context.next) {
2330
2249
  case 0:
2331
- marketCount = networkAddresses.auTokens.length;
2332
- userMarketDetails = [];
2333
- promises = [];
2334
- totalBorrowLimit = new BigNumber(0);
2335
- pricePromises = [];
2336
-
2337
- _loop2 = function _loop2() {
2338
- var auToken = _step.value;
2339
- var userMarketDetail = {};
2340
- userMarketDetails.push(userMarketDetail);
2341
- userMarketDetail.market = auToken.underlying;
2342
- var moneyMarket = new MoneyMarketRead(_this2._networkConnection, auToken.address, auToken.underlying);
2343
- promises.push(moneyMarket.getUserDepositBalance(userAddress).then(function (res) {
2344
- userMarketDetail.depositBalance = res;
2345
- }));
2346
- promises.push(moneyMarket.getUserBorrowBalance(userAddress).then(function (res) {
2347
- userMarketDetail.borrowBalance = res;
2348
- }));
2349
- promises.push(moneyMarket.getCollateralRatio().then(function (res) {
2350
- userMarketDetail.collateralRatio = res.toNumber();
2351
- }));
2352
- pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider).then(function (res) {
2353
- userMarketDetail.underlyingPrice = res.toString();
2354
- return res;
2355
- }));
2356
- };
2357
-
2358
- for (_iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens); !(_step = _iterator()).done;) {
2359
- _loop2();
2360
- }
2361
-
2362
- promises.push(this.env.comptroller.getAssetsIn(userAddress).then(function (res) {
2363
- assetsIn = res;
2364
- }));
2365
- _context.next = 10;
2366
- return Promise.all(promises);
2367
-
2368
- case 10:
2369
- _context.next = 12;
2370
- return Promise.all(pricePromises);
2371
-
2372
- case 12:
2373
- underlyingPrices = _context.sent;
2374
- depositValues = [];
2375
-
2376
- _loop = function _loop() {
2377
- var auToken = networkAddresses.auTokens[i];
2378
-
2379
- if (assetsIn.find(function (auAddress) {
2380
- return isSameAddress(auToken.address, auAddress);
2381
- }) !== undefined) {
2382
- userMarketDetails[i].isCollateral = true;
2383
- } else {
2384
- userMarketDetails[i].isCollateral = false;
2385
- }
2386
-
2387
- depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
2388
- };
2389
-
2390
- for (i = 0; i < marketCount; i++) {
2391
- _loop();
2392
- }
2393
-
2394
- totalBorrowLimit = depositValues.reduce(function (p, v, index) {
2395
- if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
2396
- return p;
2397
- }, new BigNumber(0));
2398
- _context.next = 19;
2399
- return this.env.comptroller.getAccountLiquidity(userAddress);
2400
-
2401
- case 19:
2402
- accountLiquidity = _context.sent;
2403
- borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
2404
-
2405
- if (borrowedvaluation.lt('0.00001')) {
2406
- // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
2407
- borrowedvaluation = new BigNumber(0);
2408
- }
2409
-
2410
- bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
2411
- minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
2412
-
2413
- if (bufferedBorrowLimit.lte(borrowedvaluation)) {
2414
- borrowableAmount = new BigNumber(0);
2415
- } else {
2416
- borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
2417
- }
2418
-
2419
- for (i = 0; i < marketCount; i++) {
2420
- auToken = networkAddresses.auTokens[i];
2421
- moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
2422
- borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
2423
- maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
2424
- userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount()) ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false) : new TokenAmount(moneyMarket.underlying, userMarketDetails[i].depositBalance.rawAmount());
2425
- }
2426
-
2427
- _context.t0 = userMarketDetails;
2428
- _context.t1 = {
2429
- currency: 'USD',
2430
- amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
2431
- };
2432
- _context.next = 30;
2433
- return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
2250
+ _context.next = 2;
2251
+ return this.env.auriLens.getRewardSpeeds(this.env.comptroller.address, this.auToken.address);
2434
2252
 
2435
- case 30:
2436
- _context.t2 = _context.sent;
2437
- _context.t3 = {
2438
- currency: 'USD',
2439
- amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
2440
- };
2441
- return _context.abrupt("return", {
2442
- markets: _context.t0,
2443
- borrowLimit: _context.t1,
2444
- userLockingDetails: _context.t2,
2445
- borrowableAmount: _context.t3
2446
- });
2253
+ case 2:
2254
+ speeds = _context.sent;
2255
+ return _context.abrupt("return", speeds);
2447
2256
 
2448
- case 33:
2257
+ case 4:
2449
2258
  case "end":
2450
2259
  return _context.stop();
2451
2260
  }
@@ -2453,216 +2262,23 @@ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2453
2262
  }, _callee, this);
2454
2263
  }));
2455
2264
 
2456
- function getUserDetails(_x) {
2457
- return _getUserDetails.apply(this, arguments);
2265
+ function getRewardSpeeds() {
2266
+ return _getRewardSpeeds.apply(this, arguments);
2458
2267
  }
2459
2268
 
2460
- return getUserDetails;
2269
+ return getRewardSpeeds;
2461
2270
  }();
2462
2271
 
2463
- _proto.getTokenPrice = /*#__PURE__*/function () {
2464
- var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(token) {
2465
- var price;
2272
+ _proto.getTotalTokenBorrowed = /*#__PURE__*/function () {
2273
+ var _getTotalTokenBorrowed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2466
2274
  return runtime_1.wrap(function _callee2$(_context2) {
2467
2275
  while (1) {
2468
2276
  switch (_context2.prev = _context2.next) {
2469
2277
  case 0:
2470
- _context2.next = 2;
2471
- return fetchPrice(token.address, this._networkConnection.provider);
2472
-
2473
- case 2:
2474
- price = _context2.sent;
2475
- return _context2.abrupt("return", {
2476
- currency: 'USD',
2477
- amount: price.toFixed(DECIMAL_PRECISION)
2478
- });
2479
-
2480
- case 4:
2481
- case "end":
2482
- return _context2.stop();
2483
- }
2484
- }
2485
- }, _callee2, this);
2486
- }));
2487
-
2488
- function getTokenPrice(_x2) {
2489
- return _getTokenPrice.apply(this, arguments);
2490
- }
2491
-
2492
- return getTokenPrice;
2493
- }();
2494
-
2495
- _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
2496
- var userMarketDetail = _ref.userMarketDetail,
2497
- currentBorrowLimit = _ref.currentBorrowLimit,
2498
- currentBorrowValuation = _ref.currentBorrowValuation,
2499
- action = _ref.action,
2500
- tokenAmount = _ref.tokenAmount;
2501
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
2502
- newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
2503
-
2504
- switch (action) {
2505
- case MarketAction.EnableCollateral:
2506
- case MarketAction.DisableCollateral:
2507
- var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
2508
- newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
2509
- break;
2510
-
2511
- case MarketAction.Deposit:
2512
- case MarketAction.Withdraw:
2513
- deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
2514
- newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
2515
- break;
2516
-
2517
- case MarketAction.Borrow:
2518
- case MarketAction.Repay:
2519
- var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
2520
- newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
2521
- break;
2522
- }
2523
-
2524
- return {
2525
- newBorrowLimit: {
2526
- amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
2527
- currency: 'USD'
2528
- },
2529
- newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
2530
- };
2531
- }
2532
- /**
2533
- * Get ply circulating supply.
2534
- * It is calculated by the total supply, minus:
2535
- * - Ply in team multisig contract
2536
- * - Ply in comptroller contract
2537
- * - Ply in fairlaunch contract
2538
- * - Ply in vesting contract
2539
- */
2540
- ;
2541
-
2542
- _proto.getPlyCirculatingSupply =
2543
- /*#__PURE__*/
2544
- function () {
2545
- var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
2546
- var multicallRead, baseBalanceOfCall, callResults, circulatingSupply;
2547
- return runtime_1.wrap(function _callee3$(_context3) {
2548
- while (1) {
2549
- switch (_context3.prev = _context3.next) {
2550
- case 0:
2551
- multicallRead = new MulticallRead(this._networkConnection);
2552
- baseBalanceOfCall = {
2553
- contract: this.env.ply,
2554
- method: 'balanceOf',
2555
- returnTypes: ['uint256']
2556
- };
2557
- _context3.next = 4;
2558
- return multicallRead.aggregate([// Get total supply
2559
- _extends({}, baseBalanceOfCall, {
2560
- method: 'totalSupply',
2561
- args: []
2562
- }), // balance in team multisig
2563
- _extends({}, baseBalanceOfCall, {
2564
- args: [networkAddresses.misc.TEAM_MULTISIG]
2565
- }), // balance in comptroller
2566
- _extends({}, baseBalanceOfCall, {
2567
- args: [networkAddresses.misc.COMPTROLLER]
2568
- }), // balance in fair launch
2569
- _extends({}, baseBalanceOfCall, {
2570
- args: [networkAddresses.misc.AURIFAIRLAUNCH]
2571
- }), // balance in vesting contract
2572
- _extends({}, baseBalanceOfCall, {
2573
- args: [networkAddresses.misc.PLY_TOKEN_LOCK]
2574
- })]);
2575
-
2576
- case 4:
2577
- callResults = _context3.sent;
2578
- circulatingSupply = BigNumber$1.from(0);
2579
- callResults.forEach(function (result, i) {
2580
- if (i === 0) {
2581
- circulatingSupply = result[0];
2582
- } else {
2583
- circulatingSupply = circulatingSupply.sub(result[0]);
2584
- }
2585
- });
2586
- return _context3.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
2587
-
2588
- case 8:
2589
- case "end":
2590
- return _context3.stop();
2591
- }
2592
- }
2593
- }, _callee3, this);
2594
- }));
2595
-
2596
- function getPlyCirculatingSupply() {
2597
- return _getPlyCirculatingSupply.apply(this, arguments);
2598
- }
2599
-
2600
- return getPlyCirculatingSupply;
2601
- }();
2602
-
2603
- return MiscRead;
2604
- }(BlockchainEntityRead);
2605
-
2606
- var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2607
- _inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
2608
-
2609
- function MoneyMarketRead(networkConnection, auToken, underlyingAsset) {
2610
- var _this;
2611
-
2612
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2613
- _this.env = new AuriEnv(networkConnection);
2614
-
2615
- if (isSameAddress(underlyingAsset, ETHAddress)) {
2616
- _this.auToken = new Contract(auToken, abis$6.abi, networkConnection.provider);
2617
- } else {
2618
- _this.auToken = new Contract(auToken, abis$7.abi, networkConnection.provider);
2619
- }
2620
-
2621
- _this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
2622
- return _this;
2623
- }
2624
-
2625
- var _proto = MoneyMarketRead.prototype;
2626
-
2627
- _proto.getRewardSpeeds = /*#__PURE__*/function () {
2628
- var _getRewardSpeeds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2629
- var speeds;
2630
- return runtime_1.wrap(function _callee$(_context) {
2631
- while (1) {
2632
- switch (_context.prev = _context.next) {
2633
- case 0:
2634
- _context.next = 2;
2635
- return this.env.auriLens.getRewardSpeeds(this.env.comptroller.address, this.auToken.address);
2636
-
2637
- case 2:
2638
- speeds = _context.sent;
2639
- return _context.abrupt("return", speeds);
2640
-
2641
- case 4:
2642
- case "end":
2643
- return _context.stop();
2644
- }
2645
- }
2646
- }, _callee, this);
2647
- }));
2648
-
2649
- function getRewardSpeeds() {
2650
- return _getRewardSpeeds.apply(this, arguments);
2651
- }
2652
-
2653
- return getRewardSpeeds;
2654
- }();
2655
-
2656
- _proto.getTotalTokenBorrowed = /*#__PURE__*/function () {
2657
- var _getTotalTokenBorrowed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2658
- return runtime_1.wrap(function _callee2$(_context2) {
2659
- while (1) {
2660
- switch (_context2.prev = _context2.next) {
2661
- case 0:
2662
- _context2.t0 = TokenAmount;
2663
- _context2.t1 = this.underlying;
2664
- _context2.next = 4;
2665
- return this.auToken.totalBorrows();
2278
+ _context2.t0 = TokenAmount;
2279
+ _context2.t1 = this.underlying;
2280
+ _context2.next = 4;
2281
+ return this.auToken.totalBorrows();
2666
2282
 
2667
2283
  case 4:
2668
2284
  _context2.t2 = _context2.sent.toString();
@@ -2964,988 +2580,1411 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2964
2580
 
2965
2581
  case 27:
2966
2582
  case "end":
2967
- return _context9.stop();
2583
+ return _context9.stop();
2584
+ }
2585
+ }
2586
+ }, _callee9, this);
2587
+ }));
2588
+
2589
+ function getDetails() {
2590
+ return _getDetails.apply(this, arguments);
2591
+ }
2592
+
2593
+ return getDetails;
2594
+ }();
2595
+
2596
+ _proto.getUserBorrowBalance = /*#__PURE__*/function () {
2597
+ var _getUserBorrowBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(userAddress) {
2598
+ var totalBorrow;
2599
+ return runtime_1.wrap(function _callee10$(_context10) {
2600
+ while (1) {
2601
+ switch (_context10.prev = _context10.next) {
2602
+ case 0:
2603
+ _context10.next = 2;
2604
+ return this.auToken.callStatic.borrowBalanceCurrent(userAddress);
2605
+
2606
+ case 2:
2607
+ totalBorrow = _context10.sent;
2608
+ return _context10.abrupt("return", new TokenAmount(this.underlying, totalBorrow.toString()));
2609
+
2610
+ case 4:
2611
+ case "end":
2612
+ return _context10.stop();
2613
+ }
2614
+ }
2615
+ }, _callee10, this);
2616
+ }));
2617
+
2618
+ function getUserBorrowBalance(_x) {
2619
+ return _getUserBorrowBalance.apply(this, arguments);
2620
+ }
2621
+
2622
+ return getUserBorrowBalance;
2623
+ }();
2624
+
2625
+ _proto.getUserDepositBalance = /*#__PURE__*/function () {
2626
+ var _getUserDepositBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(userAddress) {
2627
+ var totalDeposit;
2628
+ return runtime_1.wrap(function _callee11$(_context11) {
2629
+ while (1) {
2630
+ switch (_context11.prev = _context11.next) {
2631
+ case 0:
2632
+ _context11.next = 2;
2633
+ return this.auToken.callStatic.balanceOfUnderlying(userAddress);
2634
+
2635
+ case 2:
2636
+ totalDeposit = _context11.sent;
2637
+ return _context11.abrupt("return", new TokenAmount(this.underlying, totalDeposit.toString()));
2638
+
2639
+ case 4:
2640
+ case "end":
2641
+ return _context11.stop();
2642
+ }
2643
+ }
2644
+ }, _callee11, this);
2645
+ }));
2646
+
2647
+ function getUserDepositBalance(_x2) {
2648
+ return _getUserDepositBalance.apply(this, arguments);
2649
+ }
2650
+
2651
+ return getUserDepositBalance;
2652
+ }();
2653
+
2654
+ _proto.getDepositNEARRewardPerWeek = function getDepositNEARRewardPerWeek() {
2655
+ var NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
2656
+ var rewardStartTime = 1650636000;
2657
+ var rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
2658
+
2659
+ var currentTime = getCurrentTimestamp();
2660
+
2661
+ if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
2662
+ var _consts$DEPOSIT_NEAR_;
2663
+
2664
+ var reward = (_consts$DEPOSIT_NEAR_ = DEPOSIT_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()]) != null ? _consts$DEPOSIT_NEAR_ : '0';
2665
+ return new TokenAmount(NEARToken, reward, false);
2666
+ } else {
2667
+ return new TokenAmount(NEARToken, '0');
2668
+ }
2669
+ };
2670
+
2671
+ _proto.getBorrowNEARRewardPerWeek = function getBorrowNEARRewardPerWeek() {
2672
+ var NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
2673
+ var rewardStartTime = 1650636000;
2674
+ var rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
2675
+
2676
+ var currentTime = getCurrentTimestamp();
2677
+
2678
+ if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
2679
+ var _consts$BORROW_NEAR_R;
2680
+
2681
+ var reward = (_consts$BORROW_NEAR_R = BORROW_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()]) != null ? _consts$BORROW_NEAR_R : '0';
2682
+ return new TokenAmount(NEARToken, reward, false);
2683
+ } else {
2684
+ return new TokenAmount(NEARToken, '0');
2685
+ }
2686
+ };
2687
+
2688
+ return MoneyMarketRead;
2689
+ }(BlockchainEntityRead);
2690
+ var MoneyMarketReadWrite = /*#__PURE__*/function (_MoneyMarketRead) {
2691
+ _inheritsLoose(MoneyMarketReadWrite, _MoneyMarketRead);
2692
+
2693
+ function MoneyMarketReadWrite(networkConnection, auToken, underlyingAsset) {
2694
+ var _this3;
2695
+
2696
+ _this3 = _MoneyMarketRead.call(this, networkConnection, auToken, underlyingAsset) || this;
2697
+ _this3._EthRepayHelper = new Contract(networkAddresses.misc.ETHREPAYHELPER, abis$7.abi, networkConnection.provider);
2698
+ return _this3;
2699
+ }
2700
+
2701
+ var _proto2 = MoneyMarketReadWrite.prototype;
2702
+
2703
+ _proto2.deposit = /*#__PURE__*/function () {
2704
+ var _deposit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(amount) {
2705
+ return runtime_1.wrap(function _callee12$(_context12) {
2706
+ while (1) {
2707
+ switch (_context12.prev = _context12.next) {
2708
+ case 0:
2709
+ if (!isSameAddress(amount.token.address, ETHAddress)) {
2710
+ _context12.next = 4;
2711
+ break;
2712
+ }
2713
+
2714
+ return _context12.abrupt("return", this.auToken.connect(this._networkConnection.signer).mint({
2715
+ value: amount.rawAmount()
2716
+ }));
2717
+
2718
+ case 4:
2719
+ return _context12.abrupt("return", this.auToken.connect(this._networkConnection.signer).mint(amount.rawAmount()));
2720
+
2721
+ case 5:
2722
+ case "end":
2723
+ return _context12.stop();
2724
+ }
2725
+ }
2726
+ }, _callee12, this);
2727
+ }));
2728
+
2729
+ function deposit(_x3) {
2730
+ return _deposit.apply(this, arguments);
2731
+ }
2732
+
2733
+ return deposit;
2734
+ }();
2735
+
2736
+ _proto2.borrow = /*#__PURE__*/function () {
2737
+ var _borrow = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(amount) {
2738
+ return runtime_1.wrap(function _callee13$(_context13) {
2739
+ while (1) {
2740
+ switch (_context13.prev = _context13.next) {
2741
+ case 0:
2742
+ return _context13.abrupt("return", this.auToken.connect(this._networkConnection.signer).borrow(amount.rawAmount()));
2743
+
2744
+ case 1:
2745
+ case "end":
2746
+ return _context13.stop();
2747
+ }
2748
+ }
2749
+ }, _callee13, this);
2750
+ }));
2751
+
2752
+ function borrow(_x4) {
2753
+ return _borrow.apply(this, arguments);
2754
+ }
2755
+
2756
+ return borrow;
2757
+ }();
2758
+
2759
+ _proto2.withdraw = /*#__PURE__*/function () {
2760
+ var _withdraw = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(amount) {
2761
+ return runtime_1.wrap(function _callee14$(_context14) {
2762
+ while (1) {
2763
+ switch (_context14.prev = _context14.next) {
2764
+ case 0:
2765
+ if (!new BigNumber(amount.rawAmount()).lt(0)) {
2766
+ _context14.next = 2;
2767
+ break;
2768
+ }
2769
+
2770
+ return _context14.abrupt("return", this.auToken.connect(this._networkConnection.signer).redeemUnderlying(INF));
2771
+
2772
+ case 2:
2773
+ return _context14.abrupt("return", this.auToken.connect(this._networkConnection.signer).redeemUnderlying(amount.rawAmount()));
2774
+
2775
+ case 3:
2776
+ case "end":
2777
+ return _context14.stop();
2778
+ }
2779
+ }
2780
+ }, _callee14, this);
2781
+ }));
2782
+
2783
+ function withdraw(_x5) {
2784
+ return _withdraw.apply(this, arguments);
2785
+ }
2786
+
2787
+ return withdraw;
2788
+ }();
2789
+
2790
+ _proto2.repay = /*#__PURE__*/function () {
2791
+ var _repay = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(amount) {
2792
+ return runtime_1.wrap(function _callee15$(_context15) {
2793
+ while (1) {
2794
+ switch (_context15.prev = _context15.next) {
2795
+ case 0:
2796
+ if (!isSameAddress(amount.token.address, ETHAddress)) {
2797
+ _context15.next = 4;
2798
+ break;
2799
+ }
2800
+
2801
+ return _context15.abrupt("return", this._EthRepayHelper.connect(this._networkConnection.signer).repayBorrow({
2802
+ value: amount.rawAmount()
2803
+ }));
2804
+
2805
+ case 4:
2806
+ if (!new BigNumber(amount.rawAmount()).lt(0)) {
2807
+ _context15.next = 8;
2808
+ break;
2809
+ }
2810
+
2811
+ return _context15.abrupt("return", this.auToken.connect(this._networkConnection.signer).repayBorrow(INF));
2812
+
2813
+ case 8:
2814
+ return _context15.abrupt("return", this.auToken.connect(this._networkConnection.signer).repayBorrow(amount.rawAmount()));
2815
+
2816
+ case 9:
2817
+ case "end":
2818
+ return _context15.stop();
2819
+ }
2820
+ }
2821
+ }, _callee15, this);
2822
+ }));
2823
+
2824
+ function repay(_x6) {
2825
+ return _repay.apply(this, arguments);
2826
+ }
2827
+
2828
+ return repay;
2829
+ }();
2830
+
2831
+ _proto2.enableCollateral = /*#__PURE__*/function () {
2832
+ var _enableCollateral = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16() {
2833
+ return runtime_1.wrap(function _callee16$(_context16) {
2834
+ while (1) {
2835
+ switch (_context16.prev = _context16.next) {
2836
+ case 0:
2837
+ return _context16.abrupt("return", this.env.comptroller.connect(this._networkConnection.signer).enterMarkets([this.auToken.address]));
2838
+
2839
+ case 1:
2840
+ case "end":
2841
+ return _context16.stop();
2842
+ }
2843
+ }
2844
+ }, _callee16, this);
2845
+ }));
2846
+
2847
+ function enableCollateral() {
2848
+ return _enableCollateral.apply(this, arguments);
2849
+ }
2850
+
2851
+ return enableCollateral;
2852
+ }();
2853
+
2854
+ _proto2.disableCollateral = /*#__PURE__*/function () {
2855
+ var _disableCollateral = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17() {
2856
+ return runtime_1.wrap(function _callee17$(_context17) {
2857
+ while (1) {
2858
+ switch (_context17.prev = _context17.next) {
2859
+ case 0:
2860
+ return _context17.abrupt("return", this.env.comptroller.connect(this._networkConnection.signer).exitMarket(this.auToken.address));
2861
+
2862
+ case 1:
2863
+ case "end":
2864
+ return _context17.stop();
2865
+ }
2866
+ }
2867
+ }, _callee17, this);
2868
+ }));
2869
+
2870
+ function disableCollateral() {
2871
+ return _disableCollateral.apply(this, arguments);
2872
+ }
2873
+
2874
+ return disableCollateral;
2875
+ }();
2876
+
2877
+ return MoneyMarketReadWrite;
2878
+ }(MoneyMarketRead);
2879
+ var MoneyMarket = /*#__PURE__*/function (_BlockchainEntity) {
2880
+ _inheritsLoose(MoneyMarket, _BlockchainEntity);
2881
+
2882
+ function MoneyMarket(address, underlying) {
2883
+ var _this4;
2884
+
2885
+ _this4 = _BlockchainEntity.call(this) || this;
2886
+ _this4.address = validateAndParseAddress(address);
2887
+ _this4.underlying = validateAndParseAddress(underlying);
2888
+ return _this4;
2889
+ }
2890
+
2891
+ var _proto3 = MoneyMarket.prototype;
2892
+
2893
+ _proto3.read = function read(networkConnection) {
2894
+ return new MoneyMarketRead(networkConnection, this.address, this.underlying);
2895
+ };
2896
+
2897
+ _proto3.readWrite = function readWrite(networkConnection) {
2898
+ return new MoneyMarketReadWrite(networkConnection, this.address, this.underlying);
2899
+ };
2900
+
2901
+ return MoneyMarket;
2902
+ }(BlockchainEntity);
2903
+
2904
+ var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2905
+ _inheritsLoose(MulticallRead, _BlockchainEntityRead);
2906
+
2907
+ function MulticallRead(networkConnection) {
2908
+ var _this;
2909
+
2910
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2911
+ _this.multicall = new Contract(networkAddresses.misc.MULTICALL, abis$8.abi, networkConnection.provider);
2912
+ return _this;
2913
+ }
2914
+ /**
2915
+ * Run multiple calls via multicall contract
2916
+ */
2917
+
2918
+
2919
+ var _proto = MulticallRead.prototype;
2920
+
2921
+ _proto.aggregate =
2922
+ /*#__PURE__*/
2923
+ function () {
2924
+ var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(calls) {
2925
+ var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
2926
+
2927
+ return runtime_1.wrap(function _callee$(_context) {
2928
+ while (1) {
2929
+ switch (_context.prev = _context.next) {
2930
+ case 0:
2931
+ txns = []; // prepare transactions
2932
+
2933
+ i = 0;
2934
+
2935
+ case 2:
2936
+ if (!(i < calls.length)) {
2937
+ _context.next = 11;
2938
+ break;
2939
+ }
2940
+
2941
+ call = calls[i];
2942
+ _context.next = 6;
2943
+ return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
2944
+
2945
+ case 6:
2946
+ txn = _context.sent;
2947
+ txns.push({
2948
+ target: txn.to,
2949
+ callData: txn.data
2950
+ });
2951
+
2952
+ case 8:
2953
+ i++;
2954
+ _context.next = 2;
2955
+ break;
2956
+
2957
+ case 11:
2958
+ _context.next = 13;
2959
+ return this.multicall.callStatic.aggregate(txns);
2960
+
2961
+ case 13:
2962
+ response = _context.sent;
2963
+ // parse results
2964
+ decodedReturn = [];
2965
+
2966
+ for (_i = 0; _i < calls.length; _i++) {
2967
+ decodedReturn.push(ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
2968
+ }
2969
+
2970
+ return _context.abrupt("return", decodedReturn);
2971
+
2972
+ case 17:
2973
+ case "end":
2974
+ return _context.stop();
2975
+ }
2976
+ }
2977
+ }, _callee, this);
2978
+ }));
2979
+
2980
+ function aggregate(_x) {
2981
+ return _aggregate.apply(this, arguments);
2982
+ }
2983
+
2984
+ return aggregate;
2985
+ }();
2986
+
2987
+ return MulticallRead;
2988
+ }(BlockchainEntityRead);
2989
+
2990
+ var LOCKING_DENOMINATOR = /*#__PURE__*/BigNumber$1.from(10000);
2991
+ var PapermillRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2992
+ _inheritsLoose(PapermillRead, _BlockchainEntityRead);
2993
+
2994
+ function PapermillRead(networkConnection) {
2995
+ var _this;
2996
+
2997
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2998
+ _this.env = new AuriEnv(networkConnection);
2999
+ var plyAddress = networkAddresses.tokens.PLY;
3000
+ var pulpAddress = networkAddresses.tokens.PULP;
3001
+ _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
3002
+ _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
3003
+ return _this;
3004
+ }
3005
+
3006
+ var _proto = PapermillRead.prototype;
3007
+
3008
+ _proto.getPlyBalance = /*#__PURE__*/function () {
3009
+ var _getPlyBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3010
+ var plyBalance;
3011
+ return runtime_1.wrap(function _callee$(_context) {
3012
+ while (1) {
3013
+ switch (_context.prev = _context.next) {
3014
+ case 0:
3015
+ _context.next = 2;
3016
+ return this.env.ply.balanceOf(userAddress);
3017
+
3018
+ case 2:
3019
+ plyBalance = _context.sent;
3020
+ return _context.abrupt("return", new TokenAmount(this.plyToken, plyBalance.toString()));
3021
+
3022
+ case 4:
3023
+ case "end":
3024
+ return _context.stop();
2968
3025
  }
2969
3026
  }
2970
- }, _callee9, this);
3027
+ }, _callee, this);
2971
3028
  }));
2972
3029
 
2973
- function getDetails() {
2974
- return _getDetails.apply(this, arguments);
3030
+ function getPlyBalance(_x) {
3031
+ return _getPlyBalance.apply(this, arguments);
2975
3032
  }
2976
3033
 
2977
- return getDetails;
3034
+ return getPlyBalance;
2978
3035
  }();
2979
3036
 
2980
- _proto.getUserBorrowBalance = /*#__PURE__*/function () {
2981
- var _getUserBorrowBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(userAddress) {
2982
- var totalBorrow;
2983
- return runtime_1.wrap(function _callee10$(_context10) {
3037
+ _proto.getPulpBalance = /*#__PURE__*/function () {
3038
+ var _getPulpBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
3039
+ var pulpBalance;
3040
+ return runtime_1.wrap(function _callee2$(_context2) {
2984
3041
  while (1) {
2985
- switch (_context10.prev = _context10.next) {
3042
+ switch (_context2.prev = _context2.next) {
2986
3043
  case 0:
2987
- _context10.next = 2;
2988
- return this.auToken.callStatic.borrowBalanceCurrent(userAddress);
3044
+ _context2.next = 2;
3045
+ return this.env.pulp.balanceOf(userAddress);
2989
3046
 
2990
3047
  case 2:
2991
- totalBorrow = _context10.sent;
2992
- return _context10.abrupt("return", new TokenAmount(this.underlying, totalBorrow.toString()));
3048
+ pulpBalance = _context2.sent;
3049
+ return _context2.abrupt("return", new TokenAmount(this.pulpToken, pulpBalance.toString()));
2993
3050
 
2994
3051
  case 4:
2995
3052
  case "end":
2996
- return _context10.stop();
3053
+ return _context2.stop();
2997
3054
  }
2998
3055
  }
2999
- }, _callee10, this);
3056
+ }, _callee2, this);
3000
3057
  }));
3001
3058
 
3002
- function getUserBorrowBalance(_x) {
3003
- return _getUserBorrowBalance.apply(this, arguments);
3059
+ function getPulpBalance(_x2) {
3060
+ return _getPulpBalance.apply(this, arguments);
3004
3061
  }
3005
3062
 
3006
- return getUserBorrowBalance;
3007
- }();
3063
+ return getPulpBalance;
3064
+ }()
3065
+ /**
3066
+ * Get all unclaimed PLY reward of the user in all markets + all staking pools
3067
+ */
3068
+ ;
3008
3069
 
3009
- _proto.getUserDepositBalance = /*#__PURE__*/function () {
3010
- var _getUserDepositBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(userAddress) {
3011
- var totalDeposit;
3012
- return runtime_1.wrap(function _callee11$(_context11) {
3070
+ _proto.getUnclaimedPlyReward =
3071
+ /*#__PURE__*/
3072
+ function () {
3073
+ var _getUnclaimedPlyReward = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(userAddress) {
3074
+ var rewardBalancesMetadata;
3075
+ return runtime_1.wrap(function _callee3$(_context3) {
3013
3076
  while (1) {
3014
- switch (_context11.prev = _context11.next) {
3077
+ switch (_context3.prev = _context3.next) {
3015
3078
  case 0:
3016
- _context11.next = 2;
3017
- return this.auToken.callStatic.balanceOfUnderlying(userAddress);
3079
+ _context3.next = 2;
3080
+ return this.env.auriLens.callStatic.claimRewards(this.env.comptroller.address, this.env.auriFairLaunch.address, ALL_STAKING_POOLS, {
3081
+ from: userAddress
3082
+ });
3018
3083
 
3019
3084
  case 2:
3020
- totalDeposit = _context11.sent;
3021
- return _context11.abrupt("return", new TokenAmount(this.underlying, totalDeposit.toString()));
3085
+ rewardBalancesMetadata = _context3.sent;
3086
+ return _context3.abrupt("return", new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString()));
3022
3087
 
3023
3088
  case 4:
3024
3089
  case "end":
3025
- return _context11.stop();
3090
+ return _context3.stop();
3026
3091
  }
3027
3092
  }
3028
- }, _callee11, this);
3093
+ }, _callee3, this);
3029
3094
  }));
3030
3095
 
3031
- function getUserDepositBalance(_x2) {
3032
- return _getUserDepositBalance.apply(this, arguments);
3096
+ function getUnclaimedPlyReward(_x3) {
3097
+ return _getUnclaimedPlyReward.apply(this, arguments);
3033
3098
  }
3034
3099
 
3035
- return getUserDepositBalance;
3100
+ return getUnclaimedPlyReward;
3036
3101
  }();
3037
3102
 
3038
- _proto.getDepositNEARRewardPerWeek = function getDepositNEARRewardPerWeek() {
3039
- var NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
3040
- var rewardStartTime = 1650636000;
3041
- var rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
3042
-
3043
- var currentTime = getCurrentTimestamp();
3044
-
3045
- if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
3046
- var _consts$DEPOSIT_NEAR_;
3047
-
3048
- var reward = (_consts$DEPOSIT_NEAR_ = DEPOSIT_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()]) != null ? _consts$DEPOSIT_NEAR_ : '0';
3049
- return new TokenAmount(NEARToken, reward, false);
3050
- } else {
3051
- return new TokenAmount(NEARToken, '0');
3052
- }
3053
- };
3054
-
3055
- _proto.getBorrowNEARRewardPerWeek = function getBorrowNEARRewardPerWeek() {
3056
- var NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
3057
- var rewardStartTime = 1650636000;
3058
- var rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
3059
-
3060
- var currentTime = getCurrentTimestamp();
3061
-
3062
- if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
3063
- var _consts$BORROW_NEAR_R;
3064
-
3065
- var reward = (_consts$BORROW_NEAR_R = BORROW_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()]) != null ? _consts$BORROW_NEAR_R : '0';
3066
- return new TokenAmount(NEARToken, reward, false);
3067
- } else {
3068
- return new TokenAmount(NEARToken, '0');
3069
- }
3070
- };
3071
-
3072
- return MoneyMarketRead;
3073
- }(BlockchainEntityRead);
3074
- var MoneyMarketReadWrite = /*#__PURE__*/function (_MoneyMarketRead) {
3075
- _inheritsLoose(MoneyMarketReadWrite, _MoneyMarketRead);
3076
-
3077
- function MoneyMarketReadWrite(networkConnection, auToken, underlyingAsset) {
3078
- var _this3;
3079
-
3080
- _this3 = _MoneyMarketRead.call(this, networkConnection, auToken, underlyingAsset) || this;
3081
- _this3._EthRepayHelper = new Contract(networkAddresses.misc.ETHREPAYHELPER, abis$8.abi, networkConnection.provider);
3082
- return _this3;
3103
+ _proto.getWeek = function getWeek(timestamp) {
3104
+ return BigNumber$1.from(timestamp - REWARD_CLAIM_START).div(ONE_WEEK).toNumber();
3083
3105
  }
3106
+ /**
3107
+ * Get all locking details of the user in all markets + all staking pools
3108
+ */
3109
+ ;
3084
3110
 
3085
- var _proto2 = MoneyMarketReadWrite.prototype;
3111
+ _proto.getLockingDetails =
3112
+ /*#__PURE__*/
3113
+ function () {
3114
+ var _getLockingDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(userAddress) {
3115
+ var currentWeek, promises, values, percentLockCurrentWeek, percentLockNextWeek, totalRewards, _yield$this$env$pulp$, pulpAmountCurrentWeek, plyAmountCurrentWeek, plyAmountNextWeek, pulpAmountNextWeek, currentUnlockPortion, nextUnlockPortion;
3086
3116
 
3087
- _proto2.deposit = /*#__PURE__*/function () {
3088
- var _deposit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(amount) {
3089
- return runtime_1.wrap(function _callee12$(_context12) {
3117
+ return runtime_1.wrap(function _callee4$(_context4) {
3090
3118
  while (1) {
3091
- switch (_context12.prev = _context12.next) {
3119
+ switch (_context4.prev = _context4.next) {
3092
3120
  case 0:
3093
- if (!isSameAddress(amount.token.address, ETHAddress)) {
3094
- _context12.next = 4;
3095
- break;
3096
- }
3121
+ currentWeek = this.getWeek(getCurrentTimestamp());
3122
+ promises = [];
3123
+ promises.push(this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek));
3124
+ promises.push(this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek + 1));
3125
+ promises.push(this.getUnclaimedPlyReward(userAddress));
3126
+ _context4.next = 7;
3127
+ return Promise.all(promises);
3097
3128
 
3098
- return _context12.abrupt("return", this.auToken.connect(this._networkConnection.signer).mint({
3099
- value: amount.rawAmount()
3100
- }));
3129
+ case 7:
3130
+ values = _context4.sent;
3131
+ percentLockCurrentWeek = BigNumber$1.from(values[0]);
3132
+ percentLockNextWeek = BigNumber$1.from(values[1]);
3133
+ totalRewards = values[2];
3134
+ _context4.next = 13;
3135
+ return this.env.pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
3101
3136
 
3102
- case 4:
3103
- return _context12.abrupt("return", this.auToken.connect(this._networkConnection.signer).mint(amount.rawAmount()));
3137
+ case 13:
3138
+ _yield$this$env$pulp$ = _context4.sent;
3139
+ pulpAmountCurrentWeek = _yield$this$env$pulp$[0];
3140
+ plyAmountCurrentWeek = _yield$this$env$pulp$[1];
3141
+ // Predict next week lock amount = totalRewards * percentLock next week
3142
+ // This doesn't take (the reward that user might earn in the next week) into account
3143
+ plyAmountNextWeek = percentLockNextWeek.mul(totalRewards.rawAmount()).div(LOCKING_DENOMINATOR);
3144
+ pulpAmountNextWeek = BigNumber$1.from(totalRewards.rawAmount()).sub(plyAmountNextWeek); // we need to divide these two number by 10000 and multiple by 100 to get the percentage
3145
+ // I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
3104
3146
 
3105
- case 5:
3147
+ currentUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockCurrentWeek).toString();
3148
+ nextUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
3149
+ return _context4.abrupt("return", {
3150
+ vestingStart: REWARD_CLAIM_START,
3151
+ currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
3152
+ accruedPly: totalRewards,
3153
+ currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
3154
+ currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
3155
+ //
3156
+ nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
3157
+ nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
3158
+ nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString())
3159
+ });
3160
+
3161
+ case 21:
3106
3162
  case "end":
3107
- return _context12.stop();
3163
+ return _context4.stop();
3108
3164
  }
3109
3165
  }
3110
- }, _callee12, this);
3166
+ }, _callee4, this);
3111
3167
  }));
3112
3168
 
3113
- function deposit(_x3) {
3114
- return _deposit.apply(this, arguments);
3169
+ function getLockingDetails(_x4) {
3170
+ return _getLockingDetails.apply(this, arguments);
3115
3171
  }
3116
3172
 
3117
- return deposit;
3118
- }();
3173
+ return getLockingDetails;
3174
+ }()
3175
+ /**
3176
+ * Get the first timestamp that the unlockPortion reach the target
3177
+ *
3178
+ * @param userAddress currently doesn't matter
3179
+ * @param targetUnlockPortion unlockPortion target
3180
+ */
3181
+ ;
3119
3182
 
3120
- _proto2.borrow = /*#__PURE__*/function () {
3121
- var _borrow = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(amount) {
3122
- return runtime_1.wrap(function _callee13$(_context13) {
3183
+ _proto.getTimestampToUnlock =
3184
+ /*#__PURE__*/
3185
+ function () {
3186
+ var _getTimestampToUnlock = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(userAddress, targetUnlockPortion) {
3187
+ var weekId;
3188
+ return runtime_1.wrap(function _callee5$(_context5) {
3123
3189
  while (1) {
3124
- switch (_context13.prev = _context13.next) {
3190
+ switch (_context5.prev = _context5.next) {
3125
3191
  case 0:
3126
- return _context13.abrupt("return", this.auToken.connect(this._networkConnection.signer).borrow(amount.rawAmount()));
3192
+ _context5.next = 2;
3193
+ return this.env.auriLens.getWeekToUnlock(this.env.pulp.address, userAddress, targetUnlockPortion * 100);
3127
3194
 
3128
- case 1:
3195
+ case 2:
3196
+ weekId = _context5.sent;
3197
+ return _context5.abrupt("return", REWARD_CLAIM_START + ONE_WEEK * weekId.toNumber());
3198
+
3199
+ case 4:
3129
3200
  case "end":
3130
- return _context13.stop();
3201
+ return _context5.stop();
3131
3202
  }
3132
3203
  }
3133
- }, _callee13, this);
3204
+ }, _callee5, this);
3134
3205
  }));
3135
3206
 
3136
- function borrow(_x4) {
3137
- return _borrow.apply(this, arguments);
3207
+ function getTimestampToUnlock(_x5, _x6) {
3208
+ return _getTimestampToUnlock.apply(this, arguments);
3138
3209
  }
3139
3210
 
3140
- return borrow;
3141
- }();
3211
+ return getTimestampToUnlock;
3212
+ }()
3213
+ /**
3214
+ * Get the start timestamp of next week of the papermill contract.
3215
+ *
3216
+ * This is a sync function!
3217
+ *
3218
+ * @returns the timestamp in seconds
3219
+ */
3220
+ ;
3142
3221
 
3143
- _proto2.withdraw = /*#__PURE__*/function () {
3144
- var _withdraw = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(amount) {
3145
- return runtime_1.wrap(function _callee14$(_context14) {
3222
+ _proto.getNextWeekTimestamp = function getNextWeekTimestamp() {
3223
+ var nextWeek = this.getWeek(getCurrentTimestamp()) + 1;
3224
+ return REWARD_CLAIM_START + ONE_WEEK * nextWeek;
3225
+ };
3226
+
3227
+ _proto.getUnlockPortionAt = /*#__PURE__*/function () {
3228
+ var _getUnlockPortionAt = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(userAddress, timestamp) {
3229
+ var lockPortion, unlockPortion;
3230
+ return runtime_1.wrap(function _callee6$(_context6) {
3146
3231
  while (1) {
3147
- switch (_context14.prev = _context14.next) {
3232
+ switch (_context6.prev = _context6.next) {
3148
3233
  case 0:
3149
- if (!new BigNumber(amount.rawAmount()).lt(0)) {
3150
- _context14.next = 2;
3151
- break;
3152
- }
3153
-
3154
- return _context14.abrupt("return", this.auToken.connect(this._networkConnection.signer).redeemUnderlying(INF));
3234
+ _context6.next = 2;
3235
+ return this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, this.getWeek(timestamp));
3155
3236
 
3156
3237
  case 2:
3157
- return _context14.abrupt("return", this.auToken.connect(this._networkConnection.signer).redeemUnderlying(amount.rawAmount()));
3238
+ lockPortion = _context6.sent;
3239
+ unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
3240
+ return _context6.abrupt("return", unlockPortion.toNumber() / 100);
3158
3241
 
3159
- case 3:
3242
+ case 5:
3160
3243
  case "end":
3161
- return _context14.stop();
3244
+ return _context6.stop();
3162
3245
  }
3163
3246
  }
3164
- }, _callee14, this);
3247
+ }, _callee6, this);
3165
3248
  }));
3166
3249
 
3167
- function withdraw(_x5) {
3168
- return _withdraw.apply(this, arguments);
3250
+ function getUnlockPortionAt(_x7, _x8) {
3251
+ return _getUnlockPortionAt.apply(this, arguments);
3169
3252
  }
3170
3253
 
3171
- return withdraw;
3254
+ return getUnlockPortionAt;
3172
3255
  }();
3173
3256
 
3174
- _proto2.repay = /*#__PURE__*/function () {
3175
- var _repay = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(amount) {
3176
- return runtime_1.wrap(function _callee15$(_context15) {
3177
- while (1) {
3178
- switch (_context15.prev = _context15.next) {
3179
- case 0:
3180
- if (!isSameAddress(amount.token.address, ETHAddress)) {
3181
- _context15.next = 4;
3182
- break;
3183
- }
3184
-
3185
- return _context15.abrupt("return", this._EthRepayHelper.connect(this._networkConnection.signer).repayBorrow({
3186
- value: amount.rawAmount()
3187
- }));
3188
-
3189
- case 4:
3190
- if (!new BigNumber(amount.rawAmount()).lt(0)) {
3191
- _context15.next = 8;
3192
- break;
3193
- }
3194
-
3195
- return _context15.abrupt("return", this.auToken.connect(this._networkConnection.signer).repayBorrow(INF));
3196
-
3197
- case 8:
3198
- return _context15.abrupt("return", this.auToken.connect(this._networkConnection.signer).repayBorrow(amount.rawAmount()));
3257
+ return PapermillRead;
3258
+ }(BlockchainEntityRead);
3259
+ var PapermillReadWrite = /*#__PURE__*/function (_PapermillRead) {
3260
+ _inheritsLoose(PapermillReadWrite, _PapermillRead);
3199
3261
 
3200
- case 9:
3201
- case "end":
3202
- return _context15.stop();
3203
- }
3204
- }
3205
- }, _callee15, this);
3206
- }));
3262
+ function PapermillReadWrite(networkConnection) {
3263
+ return _PapermillRead.call(this, networkConnection) || this;
3264
+ }
3265
+ /**
3266
+ * Redeem PLY from PULP and transfer PLY to another address
3267
+ * @param recipient Address that will receive the PLY.
3268
+ * @param amount Amount of PULP to be converted to PLY.
3269
+ * Set to ethers.constants.MaxUint256 for max redeem.
3270
+ */
3207
3271
 
3208
- function repay(_x6) {
3209
- return _repay.apply(this, arguments);
3210
- }
3211
3272
 
3212
- return repay;
3213
- }();
3273
+ var _proto2 = PapermillReadWrite.prototype;
3214
3274
 
3215
- _proto2.enableCollateral = /*#__PURE__*/function () {
3216
- var _enableCollateral = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16() {
3217
- return runtime_1.wrap(function _callee16$(_context16) {
3275
+ _proto2.redeem =
3276
+ /*#__PURE__*/
3277
+ function () {
3278
+ var _redeem = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(recipient, amount) {
3279
+ return runtime_1.wrap(function _callee7$(_context7) {
3218
3280
  while (1) {
3219
- switch (_context16.prev = _context16.next) {
3281
+ switch (_context7.prev = _context7.next) {
3220
3282
  case 0:
3221
- return _context16.abrupt("return", this.env.comptroller.connect(this._networkConnection.signer).enterMarkets([this.auToken.address]));
3283
+ return _context7.abrupt("return", this.env.pulp.connect(this._networkConnection.signer).redeem(recipient, amount.rawAmount()));
3222
3284
 
3223
3285
  case 1:
3224
3286
  case "end":
3225
- return _context16.stop();
3287
+ return _context7.stop();
3226
3288
  }
3227
3289
  }
3228
- }, _callee16, this);
3290
+ }, _callee7, this);
3229
3291
  }));
3230
3292
 
3231
- function enableCollateral() {
3232
- return _enableCollateral.apply(this, arguments);
3293
+ function redeem(_x9, _x10) {
3294
+ return _redeem.apply(this, arguments);
3233
3295
  }
3234
3296
 
3235
- return enableCollateral;
3236
- }();
3297
+ return redeem;
3298
+ }()
3299
+ /**
3300
+ * Redeem PLY from PULP and transfer PLY to msg.sender
3301
+ * @param amount Amount of PULP to be converted to PLY.
3302
+ * Set to ethers.constants.MaxUint256 for max redeem.
3303
+ */
3304
+ ;
3237
3305
 
3238
- _proto2.disableCollateral = /*#__PURE__*/function () {
3239
- var _disableCollateral = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17() {
3240
- return runtime_1.wrap(function _callee17$(_context17) {
3306
+ _proto2.selfRedeem =
3307
+ /*#__PURE__*/
3308
+ function () {
3309
+ var _selfRedeem = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(amount) {
3310
+ var msgSender;
3311
+ return runtime_1.wrap(function _callee8$(_context8) {
3241
3312
  while (1) {
3242
- switch (_context17.prev = _context17.next) {
3313
+ switch (_context8.prev = _context8.next) {
3243
3314
  case 0:
3244
- return _context17.abrupt("return", this.env.comptroller.connect(this._networkConnection.signer).exitMarket(this.auToken.address));
3315
+ _context8.next = 2;
3316
+ return this._networkConnection.signer.getAddress();
3245
3317
 
3246
- case 1:
3318
+ case 2:
3319
+ msgSender = _context8.sent;
3320
+ return _context8.abrupt("return", this.redeem(msgSender, amount));
3321
+
3322
+ case 4:
3247
3323
  case "end":
3248
- return _context17.stop();
3324
+ return _context8.stop();
3249
3325
  }
3250
3326
  }
3251
- }, _callee17, this);
3327
+ }, _callee8, this);
3252
3328
  }));
3253
3329
 
3254
- function disableCollateral() {
3255
- return _disableCollateral.apply(this, arguments);
3330
+ function selfRedeem(_x11) {
3331
+ return _selfRedeem.apply(this, arguments);
3256
3332
  }
3257
3333
 
3258
- return disableCollateral;
3334
+ return selfRedeem;
3259
3335
  }();
3260
3336
 
3261
- return MoneyMarketReadWrite;
3262
- }(MoneyMarketRead);
3263
- var MoneyMarket = /*#__PURE__*/function (_BlockchainEntity) {
3264
- _inheritsLoose(MoneyMarket, _BlockchainEntity);
3265
-
3266
- function MoneyMarket(address, underlying) {
3267
- var _this4;
3337
+ return PapermillReadWrite;
3338
+ }(PapermillRead);
3339
+ var Papermill = /*#__PURE__*/function (_BlockchainEntity) {
3340
+ _inheritsLoose(Papermill, _BlockchainEntity);
3268
3341
 
3269
- _this4 = _BlockchainEntity.call(this) || this;
3270
- _this4.address = validateAndParseAddress(address);
3271
- _this4.underlying = validateAndParseAddress(underlying);
3272
- return _this4;
3342
+ function Papermill() {
3343
+ return _BlockchainEntity.call(this) || this;
3273
3344
  }
3274
3345
 
3275
- var _proto3 = MoneyMarket.prototype;
3346
+ var _proto3 = Papermill.prototype;
3276
3347
 
3277
3348
  _proto3.read = function read(networkConnection) {
3278
- return new MoneyMarketRead(networkConnection, this.address, this.underlying);
3349
+ return new PapermillRead(networkConnection);
3279
3350
  };
3280
3351
 
3281
3352
  _proto3.readWrite = function readWrite(networkConnection) {
3282
- return new MoneyMarketReadWrite(networkConnection, this.address, this.underlying);
3353
+ return new PapermillReadWrite(networkConnection);
3283
3354
  };
3284
3355
 
3285
- return MoneyMarket;
3356
+ return Papermill;
3286
3357
  }(BlockchainEntity);
3287
3358
 
3288
- var LOCKING_DENOMINATOR = /*#__PURE__*/BigNumber$1.from(10000);
3289
- var PapermillRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3290
- _inheritsLoose(PapermillRead, _BlockchainEntityRead);
3359
+ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3360
+ _inheritsLoose(StakingRead, _BlockchainEntityRead);
3291
3361
 
3292
- function PapermillRead(networkConnection) {
3362
+ function StakingRead(networkConnection) {
3293
3363
  var _this;
3294
3364
 
3295
3365
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3296
3366
  _this.env = new AuriEnv(networkConnection);
3297
- var plyAddress = networkAddresses.tokens.PLY;
3298
- var pulpAddress = networkAddresses.tokens.PULP;
3299
- _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
3300
- _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
3301
3367
  return _this;
3302
3368
  }
3303
3369
 
3304
- var _proto = PapermillRead.prototype;
3370
+ var _proto = StakingRead.prototype;
3305
3371
 
3306
- _proto.getPlyBalance = /*#__PURE__*/function () {
3307
- var _getPlyBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3308
- var plyBalance;
3372
+ _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
3373
+ var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
3374
+ var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
3309
3375
  return runtime_1.wrap(function _callee$(_context) {
3310
3376
  while (1) {
3311
3377
  switch (_context.prev = _context.next) {
3312
3378
  case 0:
3313
3379
  _context.next = 2;
3314
- return this.env.ply.balanceOf(userAddress);
3315
-
3316
- case 2:
3317
- plyBalance = _context.sent;
3318
- return _context.abrupt("return", new TokenAmount(this.plyToken, plyBalance.toString()));
3319
-
3320
- case 4:
3321
- case "end":
3322
- return _context.stop();
3323
- }
3324
- }
3325
- }, _callee, this);
3326
- }));
3327
-
3328
- function getPlyBalance(_x) {
3329
- return _getPlyBalance.apply(this, arguments);
3330
- }
3331
-
3332
- return getPlyBalance;
3333
- }();
3334
-
3335
- _proto.getPulpBalance = /*#__PURE__*/function () {
3336
- var _getPulpBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
3337
- var pulpBalance;
3338
- return runtime_1.wrap(function _callee2$(_context2) {
3339
- while (1) {
3340
- switch (_context2.prev = _context2.next) {
3341
- case 0:
3342
- _context2.next = 2;
3343
- return this.env.pulp.balanceOf(userAddress);
3380
+ return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
3381
+ stakedLiquidity = res.totalStake;
3382
+ rewardPerSeconds = res.rewardPerSeconds;
3383
+ });
3344
3384
 
3345
3385
  case 2:
3346
- pulpBalance = _context2.sent;
3347
- return _context2.abrupt("return", new TokenAmount(this.pulpToken, pulpBalance.toString()));
3348
-
3349
- case 4:
3350
- case "end":
3351
- return _context2.stop();
3352
- }
3353
- }
3354
- }, _callee2, this);
3355
- }));
3356
-
3357
- function getPulpBalance(_x2) {
3358
- return _getPulpBalance.apply(this, arguments);
3359
- }
3386
+ stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
3387
+ _context.next = 5;
3388
+ return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
3360
3389
 
3361
- return getPulpBalance;
3362
- }()
3363
- /**
3364
- * Get all unclaimed PLY reward of the user in all markets + all staking pools
3365
- */
3366
- ;
3390
+ case 5:
3391
+ totalStakeValuation = _context.sent;
3392
+ promises = []; // Calculate the reward per second in USD
3367
3393
 
3368
- _proto.getUnclaimedPlyReward =
3369
- /*#__PURE__*/
3370
- function () {
3371
- var _getUnclaimedPlyReward = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(userAddress) {
3372
- var rewardBalancesMetadata;
3373
- return runtime_1.wrap(function _callee3$(_context3) {
3374
- while (1) {
3375
- switch (_context3.prev = _context3.next) {
3376
- case 0:
3377
- _context3.next = 2;
3378
- return this.env.auriLens.callStatic.claimRewards(this.env.comptroller.address, this.env.auriFairLaunch.address, ALL_STAKING_POOLS, {
3379
- from: userAddress
3394
+ for (i = 0; i < rewardPerSeconds.length; i++) {
3395
+ rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3396
+ rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
3397
+ rewardPerSecond = rewardPerSeconds[i];
3398
+ promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
3399
+ }
3400
+
3401
+ APYs = [];
3402
+ _context.next = 11;
3403
+ return Promise.all(promises);
3404
+
3405
+ case 11:
3406
+ _context.sent.forEach(function (rewardPerSecondValuation, i) {
3407
+ var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3408
+ var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
3409
+ APYs.push({
3410
+ address: rewardTokenAddress,
3411
+ apy: apy
3412
+ });
3380
3413
  });
3381
3414
 
3382
- case 2:
3383
- rewardBalancesMetadata = _context3.sent;
3384
- return _context3.abrupt("return", new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString()));
3415
+ return _context.abrupt("return", {
3416
+ totalStakedLiquidity: stakedLiquidityAmount,
3417
+ APYs: APYs
3418
+ });
3385
3419
 
3386
- case 4:
3420
+ case 13:
3387
3421
  case "end":
3388
- return _context3.stop();
3422
+ return _context.stop();
3389
3423
  }
3390
3424
  }
3391
- }, _callee3, this);
3425
+ }, _callee, this);
3392
3426
  }));
3393
3427
 
3394
- function getUnclaimedPlyReward(_x3) {
3395
- return _getUnclaimedPlyReward.apply(this, arguments);
3428
+ function getPLYWNEARPoolDetails() {
3429
+ return _getPLYWNEARPoolDetails.apply(this, arguments);
3396
3430
  }
3397
3431
 
3398
- return getUnclaimedPlyReward;
3399
- }();
3400
-
3401
- _proto.getWeek = function getWeek(timestamp) {
3402
- return BigNumber$1.from(timestamp - REWARD_CLAIM_START).div(ONE_WEEK).toNumber();
3403
- }
3432
+ return getPLYWNEARPoolDetails;
3433
+ }()
3404
3434
  /**
3405
- * Get all locking details of the user in all markets + all staking pools
3435
+ * Get amount of staked LP tokens
3406
3436
  */
3407
3437
  ;
3408
3438
 
3409
- _proto.getLockingDetails =
3439
+ _proto.stakeBalanceOf =
3410
3440
  /*#__PURE__*/
3411
3441
  function () {
3412
- var _getLockingDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(userAddress) {
3413
- var currentWeek, promises, values, percentLockCurrentWeek, percentLockNextWeek, totalRewards, _yield$this$env$pulp$, pulpAmountCurrentWeek, plyAmountCurrentWeek, plyAmountNextWeek, pulpAmountNextWeek, currentUnlockPortion, nextUnlockPortion;
3414
-
3415
- return runtime_1.wrap(function _callee4$(_context4) {
3442
+ var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(user) {
3443
+ var userInfo;
3444
+ return runtime_1.wrap(function _callee2$(_context2) {
3416
3445
  while (1) {
3417
- switch (_context4.prev = _context4.next) {
3446
+ switch (_context2.prev = _context2.next) {
3418
3447
  case 0:
3419
- currentWeek = this.getWeek(getCurrentTimestamp());
3420
- promises = [];
3421
- promises.push(this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek));
3422
- promises.push(this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek + 1));
3423
- promises.push(this.getUnclaimedPlyReward(userAddress));
3424
- _context4.next = 7;
3425
- return Promise.all(promises);
3426
-
3427
- case 7:
3428
- values = _context4.sent;
3429
- percentLockCurrentWeek = BigNumber$1.from(values[0]);
3430
- percentLockNextWeek = BigNumber$1.from(values[1]);
3431
- totalRewards = values[2];
3432
- _context4.next = 13;
3433
- return this.env.pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
3434
-
3435
- case 13:
3436
- _yield$this$env$pulp$ = _context4.sent;
3437
- pulpAmountCurrentWeek = _yield$this$env$pulp$[0];
3438
- plyAmountCurrentWeek = _yield$this$env$pulp$[1];
3439
- // Predict next week lock amount = totalRewards * percentLock next week
3440
- // This doesn't take (the reward that user might earn in the next week) into account
3441
- plyAmountNextWeek = percentLockNextWeek.mul(totalRewards.rawAmount()).div(LOCKING_DENOMINATOR);
3442
- pulpAmountNextWeek = BigNumber$1.from(totalRewards.rawAmount()).sub(plyAmountNextWeek); // we need to divide these two number by 10000 and multiple by 100 to get the percentage
3443
- // I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
3448
+ _context2.next = 2;
3449
+ return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
3444
3450
 
3445
- currentUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockCurrentWeek).toString();
3446
- nextUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
3447
- return _context4.abrupt("return", {
3448
- vestingStart: REWARD_CLAIM_START,
3449
- currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
3450
- accruedPly: totalRewards,
3451
- currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
3452
- currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
3453
- //
3454
- nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
3455
- nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
3456
- nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString())
3457
- });
3451
+ case 2:
3452
+ userInfo = _context2.sent;
3453
+ return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
3458
3454
 
3459
- case 21:
3455
+ case 4:
3460
3456
  case "end":
3461
- return _context4.stop();
3457
+ return _context2.stop();
3462
3458
  }
3463
3459
  }
3464
- }, _callee4, this);
3460
+ }, _callee2, this);
3465
3461
  }));
3466
3462
 
3467
- function getLockingDetails(_x4) {
3468
- return _getLockingDetails.apply(this, arguments);
3463
+ function stakeBalanceOf(_x) {
3464
+ return _stakeBalanceOf.apply(this, arguments);
3469
3465
  }
3470
3466
 
3471
- return getLockingDetails;
3467
+ return stakeBalanceOf;
3472
3468
  }()
3473
3469
  /**
3474
- * Get the first timestamp that the unlockPortion reach the target
3475
- *
3476
- * @param userAddress currently doesn't matter
3477
- * @param targetUnlockPortion unlockPortion target
3470
+ * Get amount of LP token in user wallet
3478
3471
  */
3479
3472
  ;
3480
3473
 
3481
- _proto.getTimestampToUnlock =
3474
+ _proto.LpBalanceOf =
3482
3475
  /*#__PURE__*/
3483
3476
  function () {
3484
- var _getTimestampToUnlock = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(userAddress, targetUnlockPortion) {
3485
- var weekId;
3486
- return runtime_1.wrap(function _callee5$(_context5) {
3477
+ var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(user) {
3478
+ var lpContract, balance;
3479
+ return runtime_1.wrap(function _callee3$(_context3) {
3487
3480
  while (1) {
3488
- switch (_context5.prev = _context5.next) {
3481
+ switch (_context3.prev = _context3.next) {
3489
3482
  case 0:
3490
- _context5.next = 2;
3491
- return this.env.auriLens.getWeekToUnlock(this.env.pulp.address, userAddress, targetUnlockPortion * 100);
3483
+ lpContract = new Contract(networkAddresses.tokens.PLYWNEAR, abis$3.abi, this._networkConnection.provider);
3484
+ _context3.next = 3;
3485
+ return lpContract.balanceOf(user);
3492
3486
 
3493
- case 2:
3494
- weekId = _context5.sent;
3495
- return _context5.abrupt("return", REWARD_CLAIM_START + ONE_WEEK * weekId.toNumber());
3487
+ case 3:
3488
+ balance = _context3.sent;
3489
+ return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
3496
3490
 
3497
- case 4:
3491
+ case 5:
3498
3492
  case "end":
3499
- return _context5.stop();
3493
+ return _context3.stop();
3500
3494
  }
3501
3495
  }
3502
- }, _callee5, this);
3496
+ }, _callee3, this);
3503
3497
  }));
3504
3498
 
3505
- function getTimestampToUnlock(_x5, _x6) {
3506
- return _getTimestampToUnlock.apply(this, arguments);
3499
+ function LpBalanceOf(_x2) {
3500
+ return _LpBalanceOf.apply(this, arguments);
3507
3501
  }
3508
3502
 
3509
- return getTimestampToUnlock;
3510
- }()
3511
- /**
3512
- * Get the start timestamp of next week of the papermill contract.
3513
- *
3514
- * This is a sync function!
3515
- *
3516
- * @returns the timestamp in seconds
3517
- */
3518
- ;
3519
-
3520
- _proto.getNextWeekTimestamp = function getNextWeekTimestamp() {
3521
- var nextWeek = this.getWeek(getCurrentTimestamp()) + 1;
3522
- return REWARD_CLAIM_START + ONE_WEEK * nextWeek;
3523
- };
3503
+ return LpBalanceOf;
3504
+ }();
3524
3505
 
3525
- _proto.getUnlockPortionAt = /*#__PURE__*/function () {
3526
- var _getUnlockPortionAt = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(userAddress, timestamp) {
3527
- var lockPortion, unlockPortion;
3528
- return runtime_1.wrap(function _callee6$(_context6) {
3506
+ _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
3507
+ var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(user) {
3508
+ var userInfo, rewards;
3509
+ return runtime_1.wrap(function _callee4$(_context4) {
3529
3510
  while (1) {
3530
- switch (_context6.prev = _context6.next) {
3511
+ switch (_context4.prev = _context4.next) {
3531
3512
  case 0:
3532
- _context6.next = 2;
3533
- return this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, this.getWeek(timestamp));
3513
+ _context4.next = 2;
3514
+ return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
3515
+ from: user
3516
+ });
3534
3517
 
3535
3518
  case 2:
3536
- lockPortion = _context6.sent;
3537
- unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
3538
- return _context6.abrupt("return", unlockPortion.toNumber() / 100);
3519
+ userInfo = _context4.sent;
3520
+ rewards = userInfo.unclaimedRewards;
3521
+ return _context4.abrupt("return", rewards.map(function (reward, i) {
3522
+ return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
3523
+ }));
3539
3524
 
3540
3525
  case 5:
3541
3526
  case "end":
3542
- return _context6.stop();
3527
+ return _context4.stop();
3543
3528
  }
3544
3529
  }
3545
- }, _callee6, this);
3530
+ }, _callee4, this);
3546
3531
  }));
3547
3532
 
3548
- function getUnlockPortionAt(_x7, _x8) {
3549
- return _getUnlockPortionAt.apply(this, arguments);
3533
+ function unclaimedRewardsOf(_x3) {
3534
+ return _unclaimedRewardsOf.apply(this, arguments);
3550
3535
  }
3551
3536
 
3552
- return getUnlockPortionAt;
3537
+ return unclaimedRewardsOf;
3553
3538
  }();
3554
3539
 
3555
- return PapermillRead;
3540
+ return StakingRead;
3556
3541
  }(BlockchainEntityRead);
3557
- var PapermillReadWrite = /*#__PURE__*/function (_PapermillRead) {
3558
- _inheritsLoose(PapermillReadWrite, _PapermillRead);
3542
+ var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
3543
+ _inheritsLoose(StakingReadWrite, _StakingRead);
3559
3544
 
3560
- function PapermillReadWrite(networkConnection) {
3561
- return _PapermillRead.call(this, networkConnection) || this;
3545
+ function StakingReadWrite() {
3546
+ return _StakingRead.apply(this, arguments) || this;
3562
3547
  }
3563
- /**
3564
- * Redeem PLY from PULP and transfer PLY to another address
3565
- * @param recipient Address that will receive the PLY.
3566
- * @param amount Amount of PULP to be converted to PLY.
3567
- * Set to ethers.constants.MaxUint256 for max redeem.
3568
- */
3569
3548
 
3549
+ var _proto2 = StakingReadWrite.prototype;
3570
3550
 
3571
- var _proto2 = PapermillReadWrite.prototype;
3572
-
3573
- _proto2.redeem =
3574
- /*#__PURE__*/
3575
- function () {
3576
- var _redeem = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(recipient, amount) {
3577
- return runtime_1.wrap(function _callee7$(_context7) {
3551
+ _proto2.stake = /*#__PURE__*/function () {
3552
+ var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(amount) {
3553
+ return runtime_1.wrap(function _callee5$(_context5) {
3578
3554
  while (1) {
3579
- switch (_context7.prev = _context7.next) {
3555
+ switch (_context5.prev = _context5.next) {
3580
3556
  case 0:
3581
- return _context7.abrupt("return", this.env.pulp.connect(this._networkConnection.signer).redeem(recipient, amount.rawAmount()));
3557
+ return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
3582
3558
 
3583
3559
  case 1:
3584
3560
  case "end":
3585
- return _context7.stop();
3561
+ return _context5.stop();
3586
3562
  }
3587
3563
  }
3588
- }, _callee7, this);
3564
+ }, _callee5, this);
3589
3565
  }));
3590
3566
 
3591
- function redeem(_x9, _x10) {
3592
- return _redeem.apply(this, arguments);
3567
+ function stake(_x4) {
3568
+ return _stake.apply(this, arguments);
3593
3569
  }
3594
3570
 
3595
- return redeem;
3596
- }()
3597
- /**
3598
- * Redeem PLY from PULP and transfer PLY to msg.sender
3599
- * @param amount Amount of PULP to be converted to PLY.
3600
- * Set to ethers.constants.MaxUint256 for max redeem.
3601
- */
3602
- ;
3571
+ return stake;
3572
+ }();
3603
3573
 
3604
- _proto2.selfRedeem =
3605
- /*#__PURE__*/
3606
- function () {
3607
- var _selfRedeem = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(amount) {
3608
- var msgSender;
3609
- return runtime_1.wrap(function _callee8$(_context8) {
3574
+ _proto2.unstake = /*#__PURE__*/function () {
3575
+ var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(amount) {
3576
+ var msgSender, amountInput, stakedAmount, unstakeAmount;
3577
+ return runtime_1.wrap(function _callee6$(_context6) {
3610
3578
  while (1) {
3611
- switch (_context8.prev = _context8.next) {
3579
+ switch (_context6.prev = _context6.next) {
3612
3580
  case 0:
3613
- _context8.next = 2;
3581
+ _context6.next = 2;
3614
3582
  return this._networkConnection.signer.getAddress();
3615
3583
 
3616
3584
  case 2:
3617
- msgSender = _context8.sent;
3618
- return _context8.abrupt("return", this.redeem(msgSender, amount));
3585
+ msgSender = _context6.sent;
3586
+ amountInput = BigNumber$1.from(amount.rawAmount());
3587
+ _context6.t0 = BigNumber$1;
3588
+ _context6.next = 7;
3589
+ return this.stakeBalanceOf(msgSender);
3619
3590
 
3620
- case 4:
3591
+ case 7:
3592
+ _context6.t1 = _context6.sent.rawAmount();
3593
+ stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
3594
+ // unstakeAmount = min(amountInput, stakedAmount - 1)
3595
+ unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
3596
+ return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
3597
+
3598
+ case 11:
3621
3599
  case "end":
3622
- return _context8.stop();
3600
+ return _context6.stop();
3623
3601
  }
3624
3602
  }
3625
- }, _callee8, this);
3603
+ }, _callee6, this);
3626
3604
  }));
3627
3605
 
3628
- function selfRedeem(_x11) {
3629
- return _selfRedeem.apply(this, arguments);
3606
+ function unstake(_x5) {
3607
+ return _unstake.apply(this, arguments);
3630
3608
  }
3631
3609
 
3632
- return selfRedeem;
3610
+ return unstake;
3633
3611
  }();
3634
3612
 
3635
- return PapermillReadWrite;
3636
- }(PapermillRead);
3637
- var Papermill = /*#__PURE__*/function (_BlockchainEntity) {
3638
- _inheritsLoose(Papermill, _BlockchainEntity);
3613
+ return StakingReadWrite;
3614
+ }(StakingRead);
3615
+ var Staking = /*#__PURE__*/function (_BlockchainEntity) {
3616
+ _inheritsLoose(Staking, _BlockchainEntity);
3639
3617
 
3640
- function Papermill() {
3618
+ function Staking() {
3641
3619
  return _BlockchainEntity.call(this) || this;
3642
3620
  }
3643
3621
 
3644
- var _proto3 = Papermill.prototype;
3622
+ var _proto3 = Staking.prototype;
3645
3623
 
3646
3624
  _proto3.read = function read(networkConnection) {
3647
- return new PapermillRead(networkConnection);
3625
+ return new StakingRead(networkConnection);
3648
3626
  };
3649
3627
 
3650
3628
  _proto3.readWrite = function readWrite(networkConnection) {
3651
- return new PapermillReadWrite(networkConnection);
3629
+ return new StakingReadWrite(networkConnection);
3652
3630
  };
3653
3631
 
3654
- return Papermill;
3632
+ return Staking;
3655
3633
  }(BlockchainEntity);
3656
3634
 
3657
- var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3658
- _inheritsLoose(ReferralRead, _BlockchainEntityRead);
3635
+ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3636
+ _inheritsLoose(MiscRead, _BlockchainEntityRead);
3659
3637
 
3660
- function ReferralRead(networkConnection) {
3638
+ function MiscRead(networkConnection) {
3661
3639
  var _this;
3662
3640
 
3663
3641
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3664
- _this._referral = new Contract(networkAddresses.misc.REFERRAL, abis$9.abi, networkConnection.provider);
3642
+ _this.stakingRead = new StakingRead(networkConnection);
3643
+ _this.env = new AuriEnv(networkConnection);
3665
3644
  return _this;
3666
3645
  }
3667
- /**
3668
- * Generate a 10-character referral code
3669
- * containing alphanumeric characters.
3670
- */
3671
3646
 
3647
+ var _proto = MiscRead.prototype;
3672
3648
 
3673
- var _proto = ReferralRead.prototype;
3674
-
3675
- _proto.generateReferralCode = function generateReferralCode() {
3676
- var letters = 'abcdefghijklmnopqrstuvwxyz';
3677
- var numbers = '1234567890';
3678
- var charset = letters + letters.toUpperCase() + numbers;
3679
- var R = '';
3680
-
3681
- for (var i = 0; i < 10; i++) {
3682
- R += charset[Math.floor(Math.random() * charset.length)];
3683
- }
3649
+ _proto.getUserDetails = /*#__PURE__*/function () {
3650
+ var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3651
+ var _this2 = this;
3684
3652
 
3685
- return R;
3686
- }
3687
- /**
3688
- * Get the referral code for a given address, returns empty string if not found.
3689
- *
3690
- * Called to check if a user has a referral code.
3691
- */
3692
- ;
3653
+ var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
3693
3654
 
3694
- _proto.getUserReferralCode =
3695
- /*#__PURE__*/
3696
- function () {
3697
- var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddr) {
3698
- var result;
3699
3655
  return runtime_1.wrap(function _callee$(_context) {
3700
3656
  while (1) {
3701
3657
  switch (_context.prev = _context.next) {
3702
3658
  case 0:
3703
- _context.next = 2;
3704
- return this._referral.userReferralCode(userAddr);
3659
+ marketCount = networkAddresses.auTokens.length;
3660
+ userMarketDetails = [];
3661
+ promises = [];
3662
+ totalBorrowLimit = new BigNumber(0);
3663
+ pricePromises = [];
3705
3664
 
3706
- case 2:
3707
- result = _context.sent;
3708
- return _context.abrupt("return", ethers.utils.parseBytes32String(result));
3665
+ _loop2 = function _loop2() {
3666
+ var auToken = _step.value;
3667
+ var userMarketDetail = {};
3668
+ userMarketDetails.push(userMarketDetail);
3669
+ userMarketDetail.market = auToken.underlying;
3670
+ var moneyMarket = new MoneyMarketRead(_this2._networkConnection, auToken.address, auToken.underlying);
3671
+ promises.push(moneyMarket.getUserDepositBalance(userAddress).then(function (res) {
3672
+ userMarketDetail.depositBalance = res;
3673
+ }));
3674
+ promises.push(moneyMarket.getUserBorrowBalance(userAddress).then(function (res) {
3675
+ userMarketDetail.borrowBalance = res;
3676
+ }));
3677
+ promises.push(moneyMarket.getCollateralRatio().then(function (res) {
3678
+ userMarketDetail.collateralRatio = res.toNumber();
3679
+ }));
3680
+ pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider).then(function (res) {
3681
+ userMarketDetail.underlyingPrice = res.toString();
3682
+ return res;
3683
+ }));
3684
+ };
3709
3685
 
3710
- case 4:
3711
- case "end":
3712
- return _context.stop();
3713
- }
3714
- }
3715
- }, _callee, this);
3716
- }));
3686
+ for (_iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens); !(_step = _iterator()).done;) {
3687
+ _loop2();
3688
+ }
3717
3689
 
3718
- function getUserReferralCode(_x) {
3719
- return _getUserReferralCode.apply(this, arguments);
3720
- }
3690
+ promises.push(this.env.comptroller.getAssetsIn(userAddress).then(function (res) {
3691
+ assetsIn = res;
3692
+ }));
3693
+ _context.next = 10;
3694
+ return Promise.all(promises);
3721
3695
 
3722
- return getUserReferralCode;
3723
- }()
3724
- /**
3725
- * Get referral code that a user was referred by, returns empty string if not found.
3726
- */
3727
- ;
3696
+ case 10:
3697
+ _context.next = 12;
3698
+ return Promise.all(pricePromises);
3728
3699
 
3729
- _proto.getReferralCodeUsed =
3730
- /*#__PURE__*/
3731
- function () {
3732
- var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddr) {
3733
- var result;
3734
- return runtime_1.wrap(function _callee2$(_context2) {
3735
- while (1) {
3736
- switch (_context2.prev = _context2.next) {
3737
- case 0:
3738
- _context2.next = 2;
3739
- return this._referral.referralCodeUsed(userAddr);
3700
+ case 12:
3701
+ underlyingPrices = _context.sent;
3702
+ depositValues = [];
3740
3703
 
3741
- case 2:
3742
- result = _context2.sent;
3743
- return _context2.abrupt("return", ethers.utils.parseBytes32String(result));
3704
+ _loop = function _loop() {
3705
+ var auToken = networkAddresses.auTokens[i];
3744
3706
 
3745
- case 4:
3746
- case "end":
3747
- return _context2.stop();
3748
- }
3749
- }
3750
- }, _callee2, this);
3751
- }));
3707
+ if (assetsIn.find(function (auAddress) {
3708
+ return isSameAddress(auToken.address, auAddress);
3709
+ }) !== undefined) {
3710
+ userMarketDetails[i].isCollateral = true;
3711
+ } else {
3712
+ userMarketDetails[i].isCollateral = false;
3713
+ }
3752
3714
 
3753
- function getReferralCodeUsed(_x2) {
3754
- return _getReferralCodeUsed.apply(this, arguments);
3755
- }
3715
+ depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
3716
+ };
3756
3717
 
3757
- return getReferralCodeUsed;
3758
- }()
3759
- /**
3760
- * Get owner of a referral code, returns zero address if not found.
3761
- */
3762
- ;
3718
+ for (i = 0; i < marketCount; i++) {
3719
+ _loop();
3720
+ }
3763
3721
 
3764
- _proto.getReferralCodeOwner =
3765
- /*#__PURE__*/
3766
- function () {
3767
- var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(code) {
3768
- var referralCode;
3769
- return runtime_1.wrap(function _callee3$(_context3) {
3770
- while (1) {
3771
- switch (_context3.prev = _context3.next) {
3772
- case 0:
3773
- referralCode = ethers.utils.formatBytes32String(code);
3774
- return _context3.abrupt("return", this._referral.referralCodeOwner(referralCode));
3722
+ totalBorrowLimit = depositValues.reduce(function (p, v, index) {
3723
+ if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
3724
+ return p;
3725
+ }, new BigNumber(0));
3726
+ _context.next = 19;
3727
+ return this.env.comptroller.getAccountLiquidity(userAddress);
3775
3728
 
3776
- case 2:
3729
+ case 19:
3730
+ accountLiquidity = _context.sent;
3731
+ borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
3732
+
3733
+ if (borrowedvaluation.lt('0.00001')) {
3734
+ // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
3735
+ borrowedvaluation = new BigNumber(0);
3736
+ }
3737
+
3738
+ bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
3739
+ minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
3740
+
3741
+ if (bufferedBorrowLimit.lte(borrowedvaluation)) {
3742
+ borrowableAmount = new BigNumber(0);
3743
+ } else {
3744
+ borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
3745
+ }
3746
+
3747
+ for (i = 0; i < marketCount; i++) {
3748
+ auToken = networkAddresses.auTokens[i];
3749
+ moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
3750
+ borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
3751
+ maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
3752
+ userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount()) ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false) : new TokenAmount(moneyMarket.underlying, userMarketDetails[i].depositBalance.rawAmount());
3753
+ }
3754
+
3755
+ _context.t0 = userMarketDetails;
3756
+ _context.t1 = {
3757
+ currency: 'USD',
3758
+ amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
3759
+ };
3760
+ _context.next = 30;
3761
+ return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
3762
+
3763
+ case 30:
3764
+ _context.t2 = _context.sent;
3765
+ _context.t3 = {
3766
+ currency: 'USD',
3767
+ amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
3768
+ };
3769
+ return _context.abrupt("return", {
3770
+ markets: _context.t0,
3771
+ borrowLimit: _context.t1,
3772
+ userLockingDetails: _context.t2,
3773
+ borrowableAmount: _context.t3
3774
+ });
3775
+
3776
+ case 33:
3777
3777
  case "end":
3778
- return _context3.stop();
3778
+ return _context.stop();
3779
3779
  }
3780
3780
  }
3781
- }, _callee3, this);
3781
+ }, _callee, this);
3782
3782
  }));
3783
3783
 
3784
- function getReferralCodeOwner(_x3) {
3785
- return _getReferralCodeOwner.apply(this, arguments);
3784
+ function getUserDetails(_x) {
3785
+ return _getUserDetails.apply(this, arguments);
3786
3786
  }
3787
3787
 
3788
- return getReferralCodeOwner;
3788
+ return getUserDetails;
3789
3789
  }();
3790
3790
 
3791
- return ReferralRead;
3792
- }(BlockchainEntityRead);
3793
- var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
3794
- _inheritsLoose(ReferralReadWrite, _ReferralRead);
3795
-
3796
- function ReferralReadWrite() {
3797
- return _ReferralRead.apply(this, arguments) || this;
3798
- }
3799
-
3800
- var _proto2 = ReferralReadWrite.prototype;
3801
-
3802
- /**
3803
- * Generate a referral code for a given address.
3804
- *
3805
- * Called when an user want to creates his own referral code
3806
- */
3807
- _proto2.registerNewReferralCode =
3808
- /*#__PURE__*/
3809
- function () {
3810
- var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
3811
- var referralCode;
3812
- return runtime_1.wrap(function _callee4$(_context4) {
3791
+ _proto.getTokenPrice = /*#__PURE__*/function () {
3792
+ var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(token) {
3793
+ var price;
3794
+ return runtime_1.wrap(function _callee2$(_context2) {
3813
3795
  while (1) {
3814
- switch (_context4.prev = _context4.next) {
3796
+ switch (_context2.prev = _context2.next) {
3815
3797
  case 0:
3816
- referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
3817
- return _context4.abrupt("return", this._referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
3798
+ _context2.next = 2;
3799
+ return fetchPrice(token.address, this._networkConnection.provider);
3818
3800
 
3819
3801
  case 2:
3802
+ price = _context2.sent;
3803
+ return _context2.abrupt("return", {
3804
+ currency: 'USD',
3805
+ amount: price.toFixed(DECIMAL_PRECISION)
3806
+ });
3807
+
3808
+ case 4:
3820
3809
  case "end":
3821
- return _context4.stop();
3810
+ return _context2.stop();
3822
3811
  }
3823
3812
  }
3824
- }, _callee4, this);
3813
+ }, _callee2, this);
3825
3814
  }));
3826
3815
 
3827
- function registerNewReferralCode() {
3828
- return _registerNewReferralCode.apply(this, arguments);
3816
+ function getTokenPrice(_x2) {
3817
+ return _getTokenPrice.apply(this, arguments);
3829
3818
  }
3830
3819
 
3831
- return registerNewReferralCode;
3832
- }()
3820
+ return getTokenPrice;
3821
+ }();
3822
+
3823
+ _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
3824
+ var userMarketDetail = _ref.userMarketDetail,
3825
+ currentBorrowLimit = _ref.currentBorrowLimit,
3826
+ currentBorrowValuation = _ref.currentBorrowValuation,
3827
+ action = _ref.action,
3828
+ tokenAmount = _ref.tokenAmount;
3829
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
3830
+ newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
3831
+
3832
+ switch (action) {
3833
+ case MarketAction.EnableCollateral:
3834
+ case MarketAction.DisableCollateral:
3835
+ var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
3836
+ newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
3837
+ break;
3838
+
3839
+ case MarketAction.Deposit:
3840
+ case MarketAction.Withdraw:
3841
+ deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
3842
+ newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
3843
+ break;
3844
+
3845
+ case MarketAction.Borrow:
3846
+ case MarketAction.Repay:
3847
+ var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
3848
+ newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
3849
+ break;
3850
+ }
3851
+
3852
+ return {
3853
+ newBorrowLimit: {
3854
+ amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
3855
+ currency: 'USD'
3856
+ },
3857
+ newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
3858
+ };
3859
+ }
3833
3860
  /**
3834
- * Called when an user confirms he is referred by a specified code
3861
+ * Get ply circulating supply.
3862
+ * It is calculated by the total supply, minus:
3863
+ * - Ply in team multisig contract
3864
+ * - Ply in comptroller contract
3865
+ * - Ply in fairlaunch contract
3866
+ * - Ply in vesting contract
3835
3867
  */
3836
3868
  ;
3837
3869
 
3838
- _proto2.useReferralCode =
3870
+ _proto.getPlyCirculatingSupply =
3839
3871
  /*#__PURE__*/
3840
3872
  function () {
3841
- var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(code) {
3842
- var referralCode;
3843
- return runtime_1.wrap(function _callee5$(_context5) {
3873
+ var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
3874
+ var multicallRead, baseBalanceOfCall, callResults, circulatingSupply;
3875
+ return runtime_1.wrap(function _callee3$(_context3) {
3844
3876
  while (1) {
3845
- switch (_context5.prev = _context5.next) {
3877
+ switch (_context3.prev = _context3.next) {
3846
3878
  case 0:
3847
- referralCode = ethers.utils.formatBytes32String(code);
3848
- return _context5.abrupt("return", this._referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
3879
+ multicallRead = new MulticallRead(this._networkConnection);
3880
+ baseBalanceOfCall = {
3881
+ contract: this.env.ply,
3882
+ method: 'balanceOf',
3883
+ returnTypes: ['uint256']
3884
+ };
3885
+ _context3.next = 4;
3886
+ return multicallRead.aggregate([// Get total supply
3887
+ _extends({}, baseBalanceOfCall, {
3888
+ method: 'totalSupply',
3889
+ args: []
3890
+ }), // balance in team multisig
3891
+ _extends({}, baseBalanceOfCall, {
3892
+ args: [networkAddresses.misc.TEAM_MULTISIG]
3893
+ }), // balance in comptroller
3894
+ _extends({}, baseBalanceOfCall, {
3895
+ args: [networkAddresses.misc.COMPTROLLER]
3896
+ }), // balance in fair launch
3897
+ _extends({}, baseBalanceOfCall, {
3898
+ args: [networkAddresses.misc.AURIFAIRLAUNCH]
3899
+ }), // balance in vesting contract
3900
+ _extends({}, baseBalanceOfCall, {
3901
+ args: [networkAddresses.misc.PLY_TOKEN_LOCK]
3902
+ })]);
3849
3903
 
3850
- case 2:
3904
+ case 4:
3905
+ callResults = _context3.sent;
3906
+ circulatingSupply = BigNumber$1.from(0);
3907
+ callResults.forEach(function (result, i) {
3908
+ if (i === 0) {
3909
+ circulatingSupply = result[0];
3910
+ } else {
3911
+ circulatingSupply = circulatingSupply.sub(result[0]);
3912
+ }
3913
+ });
3914
+ return _context3.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
3915
+
3916
+ case 8:
3851
3917
  case "end":
3852
- return _context5.stop();
3918
+ return _context3.stop();
3853
3919
  }
3854
3920
  }
3855
- }, _callee5, this);
3921
+ }, _callee3, this);
3856
3922
  }));
3857
3923
 
3858
- function useReferralCode(_x4) {
3859
- return _useReferralCode.apply(this, arguments);
3924
+ function getPlyCirculatingSupply() {
3925
+ return _getPlyCirculatingSupply.apply(this, arguments);
3860
3926
  }
3861
3927
 
3862
- return useReferralCode;
3928
+ return getPlyCirculatingSupply;
3863
3929
  }();
3864
3930
 
3865
- return ReferralReadWrite;
3866
- }(ReferralRead);
3867
- var Referral = /*#__PURE__*/function (_BlockchainEntity) {
3868
- _inheritsLoose(Referral, _BlockchainEntity);
3869
-
3870
- function Referral() {
3871
- return _BlockchainEntity.call(this) || this;
3872
- }
3873
-
3874
- var _proto3 = Referral.prototype;
3875
-
3876
- _proto3.read = function read(networkConnection) {
3877
- return new ReferralRead(networkConnection);
3878
- };
3879
-
3880
- _proto3.readWrite = function readWrite(networkConnection) {
3881
- return new ReferralReadWrite(networkConnection);
3882
- };
3883
-
3884
- return Referral;
3885
- }(BlockchainEntity);
3931
+ return MiscRead;
3932
+ }(BlockchainEntityRead);
3886
3933
 
3887
- var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3888
- _inheritsLoose(StakingRead, _BlockchainEntityRead);
3934
+ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3935
+ _inheritsLoose(ReferralRead, _BlockchainEntityRead);
3889
3936
 
3890
- function StakingRead(networkConnection) {
3937
+ function ReferralRead(networkConnection) {
3891
3938
  var _this;
3892
3939
 
3893
3940
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3894
- _this.env = new AuriEnv(networkConnection);
3941
+ _this.referral = new Contract(networkAddresses.misc.REFERRAL, abis$9.abi, networkConnection.provider);
3895
3942
  return _this;
3896
3943
  }
3944
+ /**
3945
+ * Generate a 10-character referral code
3946
+ * containing alphanumeric characters.
3947
+ */
3897
3948
 
3898
- var _proto = StakingRead.prototype;
3899
-
3900
- _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
3901
- var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
3902
- var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
3903
- return runtime_1.wrap(function _callee$(_context) {
3904
- while (1) {
3905
- switch (_context.prev = _context.next) {
3906
- case 0:
3907
- _context.next = 2;
3908
- return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
3909
- stakedLiquidity = res.totalStake;
3910
- rewardPerSeconds = res.rewardPerSeconds;
3911
- });
3912
3949
 
3913
- case 2:
3914
- stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
3915
- _context.next = 5;
3916
- return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
3950
+ var _proto = ReferralRead.prototype;
3917
3951
 
3918
- case 5:
3919
- totalStakeValuation = _context.sent;
3920
- promises = []; // Calculate the reward per second in USD
3952
+ _proto.generateReferralCode = function generateReferralCode() {
3953
+ var letters = 'abcdefghijklmnopqrstuvwxyz';
3954
+ var numbers = '1234567890';
3955
+ var charset = letters + letters.toUpperCase() + numbers;
3956
+ var R = '';
3921
3957
 
3922
- for (i = 0; i < rewardPerSeconds.length; i++) {
3923
- rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3924
- rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
3925
- rewardPerSecond = rewardPerSeconds[i];
3926
- promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
3927
- }
3958
+ for (var i = 0; i < 10; i++) {
3959
+ R += charset[Math.floor(Math.random() * charset.length)];
3960
+ }
3928
3961
 
3929
- APYs = [];
3930
- _context.next = 11;
3931
- return Promise.all(promises);
3962
+ return R;
3963
+ }
3964
+ /**
3965
+ * Get the referral code for a given address, returns empty string if not found.
3966
+ *
3967
+ * Called to check if a user has a referral code.
3968
+ */
3969
+ ;
3932
3970
 
3933
- case 11:
3934
- _context.sent.forEach(function (rewardPerSecondValuation, i) {
3935
- var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3936
- var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
3937
- APYs.push({
3938
- address: rewardTokenAddress,
3939
- apy: apy
3940
- });
3941
- });
3971
+ _proto.getUserReferralCode =
3972
+ /*#__PURE__*/
3973
+ function () {
3974
+ var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddr) {
3975
+ var result;
3976
+ return runtime_1.wrap(function _callee$(_context) {
3977
+ while (1) {
3978
+ switch (_context.prev = _context.next) {
3979
+ case 0:
3980
+ _context.next = 2;
3981
+ return this.referral.userReferralCode(userAddr);
3942
3982
 
3943
- return _context.abrupt("return", {
3944
- totalStakedLiquidity: stakedLiquidityAmount,
3945
- APYs: APYs
3946
- });
3983
+ case 2:
3984
+ result = _context.sent;
3985
+ return _context.abrupt("return", ethers.utils.parseBytes32String(result));
3947
3986
 
3948
- case 13:
3987
+ case 4:
3949
3988
  case "end":
3950
3989
  return _context.stop();
3951
3990
  }
@@ -3953,32 +3992,32 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3953
3992
  }, _callee, this);
3954
3993
  }));
3955
3994
 
3956
- function getPLYWNEARPoolDetails() {
3957
- return _getPLYWNEARPoolDetails.apply(this, arguments);
3995
+ function getUserReferralCode(_x) {
3996
+ return _getUserReferralCode.apply(this, arguments);
3958
3997
  }
3959
3998
 
3960
- return getPLYWNEARPoolDetails;
3999
+ return getUserReferralCode;
3961
4000
  }()
3962
4001
  /**
3963
- * Get amount of staked LP tokens
4002
+ * Get referral code that a user was referred by, returns empty string if not found.
3964
4003
  */
3965
4004
  ;
3966
4005
 
3967
- _proto.stakeBalanceOf =
4006
+ _proto.getReferralCodeUsed =
3968
4007
  /*#__PURE__*/
3969
4008
  function () {
3970
- var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(user) {
3971
- var userInfo;
4009
+ var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddr) {
4010
+ var result;
3972
4011
  return runtime_1.wrap(function _callee2$(_context2) {
3973
4012
  while (1) {
3974
4013
  switch (_context2.prev = _context2.next) {
3975
4014
  case 0:
3976
4015
  _context2.next = 2;
3977
- return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
4016
+ return this.referral.referralCodeUsed(userAddr);
3978
4017
 
3979
4018
  case 2:
3980
- userInfo = _context2.sent;
3981
- return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
4019
+ result = _context2.sent;
4020
+ return _context2.abrupt("return", ethers.utils.parseBytes32String(result));
3982
4021
 
3983
4022
  case 4:
3984
4023
  case "end":
@@ -3988,35 +4027,30 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3988
4027
  }, _callee2, this);
3989
4028
  }));
3990
4029
 
3991
- function stakeBalanceOf(_x) {
3992
- return _stakeBalanceOf.apply(this, arguments);
4030
+ function getReferralCodeUsed(_x2) {
4031
+ return _getReferralCodeUsed.apply(this, arguments);
3993
4032
  }
3994
4033
 
3995
- return stakeBalanceOf;
4034
+ return getReferralCodeUsed;
3996
4035
  }()
3997
4036
  /**
3998
- * Get amount of LP token in user wallet
4037
+ * Get owner of a referral code, returns zero address if not found.
3999
4038
  */
4000
4039
  ;
4001
4040
 
4002
- _proto.LpBalanceOf =
4041
+ _proto.getReferralCodeOwner =
4003
4042
  /*#__PURE__*/
4004
4043
  function () {
4005
- var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(user) {
4006
- var lpContract, balance;
4044
+ var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(code) {
4045
+ var referralCode;
4007
4046
  return runtime_1.wrap(function _callee3$(_context3) {
4008
4047
  while (1) {
4009
4048
  switch (_context3.prev = _context3.next) {
4010
4049
  case 0:
4011
- lpContract = new Contract(networkAddresses.tokens.PLYWNEAR, abis$3.abi, this._networkConnection.provider);
4012
- _context3.next = 3;
4013
- return lpContract.balanceOf(user);
4014
-
4015
- case 3:
4016
- balance = _context3.sent;
4017
- return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
4050
+ referralCode = ethers.utils.formatBytes32String(code);
4051
+ return _context3.abrupt("return", this.referral.referralCodeOwner(referralCode));
4018
4052
 
4019
- case 5:
4053
+ case 2:
4020
4054
  case "end":
4021
4055
  return _context3.stop();
4022
4056
  }
@@ -4024,33 +4058,42 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4024
4058
  }, _callee3, this);
4025
4059
  }));
4026
4060
 
4027
- function LpBalanceOf(_x2) {
4028
- return _LpBalanceOf.apply(this, arguments);
4061
+ function getReferralCodeOwner(_x3) {
4062
+ return _getReferralCodeOwner.apply(this, arguments);
4029
4063
  }
4030
4064
 
4031
- return LpBalanceOf;
4065
+ return getReferralCodeOwner;
4032
4066
  }();
4033
4067
 
4034
- _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
4035
- var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(user) {
4036
- var userInfo, rewards;
4068
+ return ReferralRead;
4069
+ }(BlockchainEntityRead);
4070
+ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
4071
+ _inheritsLoose(ReferralReadWrite, _ReferralRead);
4072
+
4073
+ function ReferralReadWrite() {
4074
+ return _ReferralRead.apply(this, arguments) || this;
4075
+ }
4076
+
4077
+ var _proto2 = ReferralReadWrite.prototype;
4078
+
4079
+ /**
4080
+ * Generate a referral code for a given address.
4081
+ *
4082
+ * Called when an user want to creates his own referral code
4083
+ */
4084
+ _proto2.registerNewReferralCode =
4085
+ /*#__PURE__*/
4086
+ function () {
4087
+ var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
4088
+ var referralCode;
4037
4089
  return runtime_1.wrap(function _callee4$(_context4) {
4038
4090
  while (1) {
4039
4091
  switch (_context4.prev = _context4.next) {
4040
4092
  case 0:
4041
- _context4.next = 2;
4042
- return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
4043
- from: user
4044
- });
4093
+ referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
4094
+ return _context4.abrupt("return", this.referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
4045
4095
 
4046
4096
  case 2:
4047
- userInfo = _context4.sent;
4048
- rewards = userInfo.unclaimedRewards;
4049
- return _context4.abrupt("return", rewards.map(function (reward, i) {
4050
- return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
4051
- }));
4052
-
4053
- case 5:
4054
4097
  case "end":
4055
4098
  return _context4.stop();
4056
4099
  }
@@ -4058,33 +4101,30 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4058
4101
  }, _callee4, this);
4059
4102
  }));
4060
4103
 
4061
- function unclaimedRewardsOf(_x3) {
4062
- return _unclaimedRewardsOf.apply(this, arguments);
4104
+ function registerNewReferralCode() {
4105
+ return _registerNewReferralCode.apply(this, arguments);
4063
4106
  }
4064
4107
 
4065
- return unclaimedRewardsOf;
4066
- }();
4067
-
4068
- return StakingRead;
4069
- }(BlockchainEntityRead);
4070
- var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
4071
- _inheritsLoose(StakingReadWrite, _StakingRead);
4072
-
4073
- function StakingReadWrite() {
4074
- return _StakingRead.apply(this, arguments) || this;
4075
- }
4076
-
4077
- var _proto2 = StakingReadWrite.prototype;
4108
+ return registerNewReferralCode;
4109
+ }()
4110
+ /**
4111
+ * Called when an user confirms he is referred by a specified code
4112
+ */
4113
+ ;
4078
4114
 
4079
- _proto2.stake = /*#__PURE__*/function () {
4080
- var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(amount) {
4115
+ _proto2.useReferralCode =
4116
+ /*#__PURE__*/
4117
+ function () {
4118
+ var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(code) {
4119
+ var referralCode;
4081
4120
  return runtime_1.wrap(function _callee5$(_context5) {
4082
4121
  while (1) {
4083
4122
  switch (_context5.prev = _context5.next) {
4084
4123
  case 0:
4085
- return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
4124
+ referralCode = ethers.utils.formatBytes32String(code);
4125
+ return _context5.abrupt("return", this.referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
4086
4126
 
4087
- case 1:
4127
+ case 2:
4088
4128
  case "end":
4089
4129
  return _context5.stop();
4090
4130
  }
@@ -4092,72 +4132,33 @@ var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
4092
4132
  }, _callee5, this);
4093
4133
  }));
4094
4134
 
4095
- function stake(_x4) {
4096
- return _stake.apply(this, arguments);
4097
- }
4098
-
4099
- return stake;
4100
- }();
4101
-
4102
- _proto2.unstake = /*#__PURE__*/function () {
4103
- var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(amount) {
4104
- var msgSender, amountInput, stakedAmount, unstakeAmount;
4105
- return runtime_1.wrap(function _callee6$(_context6) {
4106
- while (1) {
4107
- switch (_context6.prev = _context6.next) {
4108
- case 0:
4109
- _context6.next = 2;
4110
- return this._networkConnection.signer.getAddress();
4111
-
4112
- case 2:
4113
- msgSender = _context6.sent;
4114
- amountInput = BigNumber$1.from(amount.rawAmount());
4115
- _context6.t0 = BigNumber$1;
4116
- _context6.next = 7;
4117
- return this.stakeBalanceOf(msgSender);
4118
-
4119
- case 7:
4120
- _context6.t1 = _context6.sent.rawAmount();
4121
- stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
4122
- // unstakeAmount = min(amountInput, stakedAmount - 1)
4123
- unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
4124
- return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
4125
-
4126
- case 11:
4127
- case "end":
4128
- return _context6.stop();
4129
- }
4130
- }
4131
- }, _callee6, this);
4132
- }));
4133
-
4134
- function unstake(_x5) {
4135
- return _unstake.apply(this, arguments);
4135
+ function useReferralCode(_x4) {
4136
+ return _useReferralCode.apply(this, arguments);
4136
4137
  }
4137
4138
 
4138
- return unstake;
4139
+ return useReferralCode;
4139
4140
  }();
4140
4141
 
4141
- return StakingReadWrite;
4142
- }(StakingRead);
4143
- var Staking = /*#__PURE__*/function (_BlockchainEntity) {
4144
- _inheritsLoose(Staking, _BlockchainEntity);
4142
+ return ReferralReadWrite;
4143
+ }(ReferralRead);
4144
+ var Referral = /*#__PURE__*/function (_BlockchainEntity) {
4145
+ _inheritsLoose(Referral, _BlockchainEntity);
4145
4146
 
4146
- function Staking() {
4147
+ function Referral() {
4147
4148
  return _BlockchainEntity.call(this) || this;
4148
4149
  }
4149
4150
 
4150
- var _proto3 = Staking.prototype;
4151
+ var _proto3 = Referral.prototype;
4151
4152
 
4152
4153
  _proto3.read = function read(networkConnection) {
4153
- return new StakingRead(networkConnection);
4154
+ return new ReferralRead(networkConnection);
4154
4155
  };
4155
4156
 
4156
4157
  _proto3.readWrite = function readWrite(networkConnection) {
4157
- return new StakingReadWrite(networkConnection);
4158
+ return new ReferralReadWrite(networkConnection);
4158
4159
  };
4159
4160
 
4160
- return Staking;
4161
+ return Referral;
4161
4162
  }(BlockchainEntity);
4162
4163
 
4163
4164
  var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
@@ -4374,6 +4375,38 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4374
4375
  return getPlyCirculatingSupply;
4375
4376
  }();
4376
4377
 
4378
+ _proto.getUltilizations = /*#__PURE__*/function () {
4379
+ var _getUltilizations = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(userAddr) {
4380
+ var helper, accountDetail, sumBorrow, sumCol;
4381
+ return runtime_1.wrap(function _callee8$(_context8) {
4382
+ while (1) {
4383
+ switch (_context8.prev = _context8.next) {
4384
+ case 0:
4385
+ helper = new Contract(networkAddresses.misc.ultilizationHelper, abis$a.abi, this._networkConnection.provider);
4386
+ _context8.next = 3;
4387
+ return helper.getAccountLiquidity(userAddr);
4388
+
4389
+ case 3:
4390
+ accountDetail = _context8.sent;
4391
+ sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
4392
+ sumCol = new BigNumber(accountDetail.sumCollateral.toString());
4393
+ return _context8.abrupt("return", sumBorrow.dividedBy(sumCol));
4394
+
4395
+ case 7:
4396
+ case "end":
4397
+ return _context8.stop();
4398
+ }
4399
+ }
4400
+ }, _callee8, this);
4401
+ }));
4402
+
4403
+ function getUltilizations(_x6) {
4404
+ return _getUltilizations.apply(this, arguments);
4405
+ }
4406
+
4407
+ return getUltilizations;
4408
+ }();
4409
+
4377
4410
  return SdkRead;
4378
4411
  }(BlockchainEntityRead);
4379
4412
  var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
@@ -4391,25 +4424,25 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4391
4424
  _proto2.claim =
4392
4425
  /*#__PURE__*/
4393
4426
  function () {
4394
- var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
4395
- return runtime_1.wrap(function _callee8$(_context8) {
4427
+ var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
4428
+ return runtime_1.wrap(function _callee9$(_context9) {
4396
4429
  while (1) {
4397
- switch (_context8.prev = _context8.next) {
4430
+ switch (_context9.prev = _context9.next) {
4398
4431
  case 0:
4399
- _context8.t0 = this.env.comptroller.connect(this._networkConnection.signer);
4400
- _context8.next = 3;
4432
+ _context9.t0 = this.env.comptroller.connect(this._networkConnection.signer);
4433
+ _context9.next = 3;
4401
4434
  return this._networkConnection.signer.getAddress();
4402
4435
 
4403
4436
  case 3:
4404
- _context8.t1 = _context8.sent;
4405
- return _context8.abrupt("return", _context8.t0['claimReward(uint8,address)'].call(_context8.t0, 0, _context8.t1));
4437
+ _context9.t1 = _context9.sent;
4438
+ return _context9.abrupt("return", _context9.t0['claimReward(uint8,address)'].call(_context9.t0, 0, _context9.t1));
4406
4439
 
4407
4440
  case 5:
4408
4441
  case "end":
4409
- return _context8.stop();
4442
+ return _context9.stop();
4410
4443
  }
4411
4444
  }
4412
- }, _callee8, this);
4445
+ }, _callee9, this);
4413
4446
  }));
4414
4447
 
4415
4448
  function claim() {
@@ -4420,26 +4453,26 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4420
4453
  }();
4421
4454
 
4422
4455
  _proto2.claimLpRewards = /*#__PURE__*/function () {
4423
- var _claimLpRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
4424
- return runtime_1.wrap(function _callee9$(_context9) {
4456
+ var _claimLpRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10() {
4457
+ return runtime_1.wrap(function _callee10$(_context10) {
4425
4458
  while (1) {
4426
- switch (_context9.prev = _context9.next) {
4459
+ switch (_context10.prev = _context10.next) {
4427
4460
  case 0:
4428
- _context9.t0 = this.env.auriFairLaunch.connect(this._networkConnection.signer);
4429
- _context9.next = 3;
4461
+ _context10.t0 = this.env.auriFairLaunch.connect(this._networkConnection.signer);
4462
+ _context10.next = 3;
4430
4463
  return this._networkConnection.signer.getAddress();
4431
4464
 
4432
4465
  case 3:
4433
- _context9.t1 = _context9.sent;
4434
- _context9.t2 = INF;
4435
- return _context9.abrupt("return", _context9.t0.harvest.call(_context9.t0, _context9.t1, 0, _context9.t2));
4466
+ _context10.t1 = _context10.sent;
4467
+ _context10.t2 = INF;
4468
+ return _context10.abrupt("return", _context10.t0.harvest.call(_context10.t0, _context10.t1, 0, _context10.t2));
4436
4469
 
4437
4470
  case 6:
4438
4471
  case "end":
4439
- return _context9.stop();
4472
+ return _context10.stop();
4440
4473
  }
4441
4474
  }
4442
- }, _callee9, this);
4475
+ }, _callee10, this);
4443
4476
  }));
4444
4477
 
4445
4478
  function claimLpRewards() {
@@ -4450,22 +4483,22 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4450
4483
  }();
4451
4484
 
4452
4485
  _proto2.stake = /*#__PURE__*/function () {
4453
- var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(amount) {
4454
- return runtime_1.wrap(function _callee10$(_context10) {
4486
+ var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(amount) {
4487
+ return runtime_1.wrap(function _callee11$(_context11) {
4455
4488
  while (1) {
4456
- switch (_context10.prev = _context10.next) {
4489
+ switch (_context11.prev = _context11.next) {
4457
4490
  case 0:
4458
- return _context10.abrupt("return", new StakingReadWrite(this._networkConnection).stake(amount));
4491
+ return _context11.abrupt("return", new StakingReadWrite(this._networkConnection).stake(amount));
4459
4492
 
4460
4493
  case 1:
4461
4494
  case "end":
4462
- return _context10.stop();
4495
+ return _context11.stop();
4463
4496
  }
4464
4497
  }
4465
- }, _callee10, this);
4498
+ }, _callee11, this);
4466
4499
  }));
4467
4500
 
4468
- function stake(_x6) {
4501
+ function stake(_x7) {
4469
4502
  return _stake.apply(this, arguments);
4470
4503
  }
4471
4504
 
@@ -4473,22 +4506,22 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4473
4506
  }();
4474
4507
 
4475
4508
  _proto2.unstake = /*#__PURE__*/function () {
4476
- var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(amount) {
4477
- return runtime_1.wrap(function _callee11$(_context11) {
4509
+ var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(amount) {
4510
+ return runtime_1.wrap(function _callee12$(_context12) {
4478
4511
  while (1) {
4479
- switch (_context11.prev = _context11.next) {
4512
+ switch (_context12.prev = _context12.next) {
4480
4513
  case 0:
4481
- return _context11.abrupt("return", new StakingReadWrite(this._networkConnection).unstake(amount));
4514
+ return _context12.abrupt("return", new StakingReadWrite(this._networkConnection).unstake(amount));
4482
4515
 
4483
4516
  case 1:
4484
4517
  case "end":
4485
- return _context11.stop();
4518
+ return _context12.stop();
4486
4519
  }
4487
4520
  }
4488
- }, _callee11, this);
4521
+ }, _callee12, this);
4489
4522
  }));
4490
4523
 
4491
- function unstake(_x7) {
4524
+ function unstake(_x8) {
4492
4525
  return _unstake.apply(this, arguments);
4493
4526
  }
4494
4527