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