@aurigami/sdk 1.6.6 → 1.6.8

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