@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.
package/dist/sdk.esm.js CHANGED
@@ -4,17 +4,18 @@ import { Logger } from 'ethers/lib/utils';
4
4
  import MAINNET_ADDRESSES from '@aurigami/contracts/deployments/aurora_mainnet.json';
5
5
  export { default as MAINNET_ADDRESSES } from '@aurigami/contracts/deployments/aurora_mainnet.json';
6
6
  export { default as TESTNET_ADDRESSES } from '@aurigami/contracts/deployments/aurora_testnet.json';
7
- import abis$7 from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
8
- import abis$6 from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
7
+ import abis$6 from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
8
+ import abis$5 from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
9
9
  import AuriAirdropABI from '@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json';
10
10
  import abis$1 from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
11
11
  import abis$2 from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
12
12
  import AuriOracleABI from '@aurigami/contracts/artifacts/contracts/AuriOracle.sol/AuriOracle.json';
13
13
  import abis from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
14
- import abis$8 from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
14
+ import abis$7 from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
15
15
  import abis$3 from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
16
16
  import IUniswapV2PairABI from '@aurigami/contracts/artifacts/contracts/mock/IUniswapV2Pair.sol/IUniswapV2Pair.json';
17
- import abis$5 from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
17
+ import abis$8 from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
18
+ import abis$a from '@aurigami/contracts/artifacts/contracts/mock/UltilizationHelper.sol/UltilizationHelper.json';
18
19
  import abis$4 from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
19
20
  import abis$9 from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
20
21
  import { Signer } from '@ethersproject/abstract-signer';
@@ -81,7 +82,8 @@ var networkAddresses = {
81
82
  MULTICALL: /*#__PURE__*/MAINNET_ADDRESSES.multicall.toLowerCase(),
82
83
  TEAM_MULTISIG: /*#__PURE__*/'0x2D05FfFE70CE64c5954710D4C308dB31C8dBd8dE'.toLowerCase(),
83
84
  PLY_TOKEN_LOCK: /*#__PURE__*/MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
84
- REFERRAL: /*#__PURE__*/MAINNET_ADDRESSES.referralDirectory.toLocaleLowerCase()
85
+ REFERRAL: /*#__PURE__*/MAINNET_ADDRESSES.referralDirectory.toLowerCase(),
86
+ ULTILIZATION_HELPER: /*#__PURE__*/MAINNET_ADDRESSES.ultilizationHelper.toLowerCase()
85
87
  },
86
88
  tokens: {
87
89
  AURORA: /*#__PURE__*/'0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
@@ -2200,92 +2202,6 @@ var Airdrop = /*#__PURE__*/function (_BlockchainEntity) {
2200
2202
  return Airdrop;
2201
2203
  }(BlockchainEntity);
2202
2204
 
2203
- var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2204
- _inheritsLoose(MulticallRead, _BlockchainEntityRead);
2205
-
2206
- function MulticallRead(networkConnection) {
2207
- var _this;
2208
-
2209
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2210
- _this.multicall = new Contract(networkAddresses.misc.MULTICALL, abis$5.abi, networkConnection.provider);
2211
- return _this;
2212
- }
2213
- /**
2214
- * Run multiple calls via multicall contract
2215
- */
2216
-
2217
-
2218
- var _proto = MulticallRead.prototype;
2219
-
2220
- _proto.aggregate =
2221
- /*#__PURE__*/
2222
- function () {
2223
- var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(calls) {
2224
- var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
2225
-
2226
- return runtime_1.wrap(function _callee$(_context) {
2227
- while (1) {
2228
- switch (_context.prev = _context.next) {
2229
- case 0:
2230
- txns = []; // prepare transactions
2231
-
2232
- i = 0;
2233
-
2234
- case 2:
2235
- if (!(i < calls.length)) {
2236
- _context.next = 11;
2237
- break;
2238
- }
2239
-
2240
- call = calls[i];
2241
- _context.next = 6;
2242
- return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
2243
-
2244
- case 6:
2245
- txn = _context.sent;
2246
- txns.push({
2247
- target: txn.to,
2248
- callData: txn.data
2249
- });
2250
-
2251
- case 8:
2252
- i++;
2253
- _context.next = 2;
2254
- break;
2255
-
2256
- case 11:
2257
- _context.next = 13;
2258
- return this.multicall.callStatic.aggregate(txns);
2259
-
2260
- case 13:
2261
- response = _context.sent;
2262
- // parse results
2263
- decodedReturn = [];
2264
-
2265
- for (_i = 0; _i < calls.length; _i++) {
2266
- decodedReturn.push(ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
2267
- }
2268
-
2269
- return _context.abrupt("return", decodedReturn);
2270
-
2271
- case 17:
2272
- case "end":
2273
- return _context.stop();
2274
- }
2275
- }
2276
- }, _callee, this);
2277
- }));
2278
-
2279
- function aggregate(_x) {
2280
- return _aggregate.apply(this, arguments);
2281
- }
2282
-
2283
- return aggregate;
2284
- }();
2285
-
2286
- return MulticallRead;
2287
- }(BlockchainEntityRead);
2288
-
2289
2205
  var ComptrollerRewardType;
2290
2206
 
2291
2207
  (function (ComptrollerRewardType) {
@@ -2304,148 +2220,42 @@ var MarketAction;
2304
2220
  MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
2305
2221
  })(MarketAction || (MarketAction = {}));
2306
2222
 
2307
- var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2308
- _inheritsLoose(MiscRead, _BlockchainEntityRead);
2223
+ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2224
+ _inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
2309
2225
 
2310
- function MiscRead(networkConnection) {
2226
+ function MoneyMarketRead(networkConnection, auToken, underlyingAsset) {
2311
2227
  var _this;
2312
2228
 
2313
2229
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2314
- _this.stakingRead = new StakingRead(networkConnection);
2315
2230
  _this.env = new AuriEnv(networkConnection);
2316
- return _this;
2317
- }
2318
2231
 
2319
- var _proto = MiscRead.prototype;
2232
+ if (isSameAddress(underlyingAsset, ETHAddress)) {
2233
+ _this.auToken = new Contract(auToken, abis$5.abi, networkConnection.provider);
2234
+ } else {
2235
+ _this.auToken = new Contract(auToken, abis$6.abi, networkConnection.provider);
2236
+ }
2320
2237
 
2321
- _proto.getUserDetails = /*#__PURE__*/function () {
2322
- var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
2323
- var _this2 = this;
2238
+ _this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
2239
+ return _this;
2240
+ }
2324
2241
 
2325
- var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
2242
+ var _proto = MoneyMarketRead.prototype;
2326
2243
 
2244
+ _proto.getRewardSpeeds = /*#__PURE__*/function () {
2245
+ var _getRewardSpeeds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2246
+ var speeds;
2327
2247
  return runtime_1.wrap(function _callee$(_context) {
2328
2248
  while (1) {
2329
2249
  switch (_context.prev = _context.next) {
2330
2250
  case 0:
2331
- marketCount = networkAddresses.auTokens.length;
2332
- userMarketDetails = [];
2333
- promises = [];
2334
- totalBorrowLimit = new BigNumber(0);
2335
- pricePromises = [];
2336
-
2337
- _loop2 = function _loop2() {
2338
- var auToken = _step.value;
2339
- var userMarketDetail = {};
2340
- userMarketDetails.push(userMarketDetail);
2341
- userMarketDetail.market = auToken.underlying;
2342
- var moneyMarket = new MoneyMarketRead(_this2._networkConnection, auToken.address, auToken.underlying);
2343
- promises.push(moneyMarket.getUserDepositBalance(userAddress).then(function (res) {
2344
- userMarketDetail.depositBalance = res;
2345
- }));
2346
- promises.push(moneyMarket.getUserBorrowBalance(userAddress).then(function (res) {
2347
- userMarketDetail.borrowBalance = res;
2348
- }));
2349
- promises.push(moneyMarket.getCollateralRatio().then(function (res) {
2350
- userMarketDetail.collateralRatio = res.toNumber();
2351
- }));
2352
- pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider).then(function (res) {
2353
- userMarketDetail.underlyingPrice = res.toString();
2354
- return res;
2355
- }));
2356
- };
2357
-
2358
- for (_iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens); !(_step = _iterator()).done;) {
2359
- _loop2();
2360
- }
2361
-
2362
- promises.push(this.env.comptroller.getAssetsIn(userAddress).then(function (res) {
2363
- assetsIn = res;
2364
- }));
2365
- _context.next = 10;
2366
- return Promise.all(promises);
2367
-
2368
- case 10:
2369
- _context.next = 12;
2370
- return Promise.all(pricePromises);
2371
-
2372
- case 12:
2373
- underlyingPrices = _context.sent;
2374
- depositValues = [];
2375
-
2376
- _loop = function _loop() {
2377
- var auToken = networkAddresses.auTokens[i];
2378
-
2379
- if (assetsIn.find(function (auAddress) {
2380
- return isSameAddress(auToken.address, auAddress);
2381
- }) !== undefined) {
2382
- userMarketDetails[i].isCollateral = true;
2383
- } else {
2384
- userMarketDetails[i].isCollateral = false;
2385
- }
2386
-
2387
- depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
2388
- };
2389
-
2390
- for (i = 0; i < marketCount; i++) {
2391
- _loop();
2392
- }
2393
-
2394
- totalBorrowLimit = depositValues.reduce(function (p, v, index) {
2395
- if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
2396
- return p;
2397
- }, new BigNumber(0));
2398
- _context.next = 19;
2399
- return this.env.comptroller.getAccountLiquidity(userAddress);
2400
-
2401
- case 19:
2402
- accountLiquidity = _context.sent;
2403
- borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
2404
-
2405
- if (borrowedvaluation.lt('0.00001')) {
2406
- // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
2407
- borrowedvaluation = new BigNumber(0);
2408
- }
2409
-
2410
- bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
2411
- minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
2412
-
2413
- if (bufferedBorrowLimit.lte(borrowedvaluation)) {
2414
- borrowableAmount = new BigNumber(0);
2415
- } else {
2416
- borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
2417
- }
2418
-
2419
- for (i = 0; i < marketCount; i++) {
2420
- auToken = networkAddresses.auTokens[i];
2421
- moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
2422
- borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
2423
- maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
2424
- userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount()) ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false) : new TokenAmount(moneyMarket.underlying, userMarketDetails[i].depositBalance.rawAmount());
2425
- }
2426
-
2427
- _context.t0 = userMarketDetails;
2428
- _context.t1 = {
2429
- currency: 'USD',
2430
- amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
2431
- };
2432
- _context.next = 30;
2433
- return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
2251
+ _context.next = 2;
2252
+ return this.env.auriLens.getRewardSpeeds(this.env.comptroller.address, this.auToken.address);
2434
2253
 
2435
- case 30:
2436
- _context.t2 = _context.sent;
2437
- _context.t3 = {
2438
- currency: 'USD',
2439
- amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
2440
- };
2441
- return _context.abrupt("return", {
2442
- markets: _context.t0,
2443
- borrowLimit: _context.t1,
2444
- userLockingDetails: _context.t2,
2445
- borrowableAmount: _context.t3
2446
- });
2254
+ case 2:
2255
+ speeds = _context.sent;
2256
+ return _context.abrupt("return", speeds);
2447
2257
 
2448
- case 33:
2258
+ case 4:
2449
2259
  case "end":
2450
2260
  return _context.stop();
2451
2261
  }
@@ -2453,216 +2263,23 @@ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2453
2263
  }, _callee, this);
2454
2264
  }));
2455
2265
 
2456
- function getUserDetails(_x) {
2457
- return _getUserDetails.apply(this, arguments);
2266
+ function getRewardSpeeds() {
2267
+ return _getRewardSpeeds.apply(this, arguments);
2458
2268
  }
2459
2269
 
2460
- return getUserDetails;
2270
+ return getRewardSpeeds;
2461
2271
  }();
2462
2272
 
2463
- _proto.getTokenPrice = /*#__PURE__*/function () {
2464
- var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(token) {
2465
- var price;
2273
+ _proto.getTotalTokenBorrowed = /*#__PURE__*/function () {
2274
+ var _getTotalTokenBorrowed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2466
2275
  return runtime_1.wrap(function _callee2$(_context2) {
2467
2276
  while (1) {
2468
2277
  switch (_context2.prev = _context2.next) {
2469
2278
  case 0:
2470
- _context2.next = 2;
2471
- return fetchPrice(token.address, this._networkConnection.provider);
2472
-
2473
- case 2:
2474
- price = _context2.sent;
2475
- return _context2.abrupt("return", {
2476
- currency: 'USD',
2477
- amount: price.toFixed(DECIMAL_PRECISION)
2478
- });
2479
-
2480
- case 4:
2481
- case "end":
2482
- return _context2.stop();
2483
- }
2484
- }
2485
- }, _callee2, this);
2486
- }));
2487
-
2488
- function getTokenPrice(_x2) {
2489
- return _getTokenPrice.apply(this, arguments);
2490
- }
2491
-
2492
- return getTokenPrice;
2493
- }();
2494
-
2495
- _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
2496
- var userMarketDetail = _ref.userMarketDetail,
2497
- currentBorrowLimit = _ref.currentBorrowLimit,
2498
- currentBorrowValuation = _ref.currentBorrowValuation,
2499
- action = _ref.action,
2500
- tokenAmount = _ref.tokenAmount;
2501
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
2502
- newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
2503
-
2504
- switch (action) {
2505
- case MarketAction.EnableCollateral:
2506
- case MarketAction.DisableCollateral:
2507
- var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
2508
- newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
2509
- break;
2510
-
2511
- case MarketAction.Deposit:
2512
- case MarketAction.Withdraw:
2513
- deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
2514
- newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
2515
- break;
2516
-
2517
- case MarketAction.Borrow:
2518
- case MarketAction.Repay:
2519
- var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
2520
- newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
2521
- break;
2522
- }
2523
-
2524
- return {
2525
- newBorrowLimit: {
2526
- amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
2527
- currency: 'USD'
2528
- },
2529
- newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
2530
- };
2531
- }
2532
- /**
2533
- * Get ply circulating supply.
2534
- * It is calculated by the total supply, minus:
2535
- * - Ply in team multisig contract
2536
- * - Ply in comptroller contract
2537
- * - Ply in fairlaunch contract
2538
- * - Ply in vesting contract
2539
- */
2540
- ;
2541
-
2542
- _proto.getPlyCirculatingSupply =
2543
- /*#__PURE__*/
2544
- function () {
2545
- var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
2546
- var multicallRead, baseBalanceOfCall, callResults, circulatingSupply;
2547
- return runtime_1.wrap(function _callee3$(_context3) {
2548
- while (1) {
2549
- switch (_context3.prev = _context3.next) {
2550
- case 0:
2551
- multicallRead = new MulticallRead(this._networkConnection);
2552
- baseBalanceOfCall = {
2553
- contract: this.env.ply,
2554
- method: 'balanceOf',
2555
- returnTypes: ['uint256']
2556
- };
2557
- _context3.next = 4;
2558
- return multicallRead.aggregate([// Get total supply
2559
- _extends({}, baseBalanceOfCall, {
2560
- method: 'totalSupply',
2561
- args: []
2562
- }), // balance in team multisig
2563
- _extends({}, baseBalanceOfCall, {
2564
- args: [networkAddresses.misc.TEAM_MULTISIG]
2565
- }), // balance in comptroller
2566
- _extends({}, baseBalanceOfCall, {
2567
- args: [networkAddresses.misc.COMPTROLLER]
2568
- }), // balance in fair launch
2569
- _extends({}, baseBalanceOfCall, {
2570
- args: [networkAddresses.misc.AURIFAIRLAUNCH]
2571
- }), // balance in vesting contract
2572
- _extends({}, baseBalanceOfCall, {
2573
- args: [networkAddresses.misc.PLY_TOKEN_LOCK]
2574
- })]);
2575
-
2576
- case 4:
2577
- callResults = _context3.sent;
2578
- circulatingSupply = BigNumber$1.from(0);
2579
- callResults.forEach(function (result, i) {
2580
- if (i === 0) {
2581
- circulatingSupply = result[0];
2582
- } else {
2583
- circulatingSupply = circulatingSupply.sub(result[0]);
2584
- }
2585
- });
2586
- return _context3.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
2587
-
2588
- case 8:
2589
- case "end":
2590
- return _context3.stop();
2591
- }
2592
- }
2593
- }, _callee3, this);
2594
- }));
2595
-
2596
- function getPlyCirculatingSupply() {
2597
- return _getPlyCirculatingSupply.apply(this, arguments);
2598
- }
2599
-
2600
- return getPlyCirculatingSupply;
2601
- }();
2602
-
2603
- return MiscRead;
2604
- }(BlockchainEntityRead);
2605
-
2606
- var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2607
- _inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
2608
-
2609
- function MoneyMarketRead(networkConnection, auToken, underlyingAsset) {
2610
- var _this;
2611
-
2612
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2613
- _this.env = new AuriEnv(networkConnection);
2614
-
2615
- if (isSameAddress(underlyingAsset, ETHAddress)) {
2616
- _this.auToken = new Contract(auToken, abis$6.abi, networkConnection.provider);
2617
- } else {
2618
- _this.auToken = new Contract(auToken, abis$7.abi, networkConnection.provider);
2619
- }
2620
-
2621
- _this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
2622
- return _this;
2623
- }
2624
-
2625
- var _proto = MoneyMarketRead.prototype;
2626
-
2627
- _proto.getRewardSpeeds = /*#__PURE__*/function () {
2628
- var _getRewardSpeeds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
2629
- var speeds;
2630
- return runtime_1.wrap(function _callee$(_context) {
2631
- while (1) {
2632
- switch (_context.prev = _context.next) {
2633
- case 0:
2634
- _context.next = 2;
2635
- return this.env.auriLens.getRewardSpeeds(this.env.comptroller.address, this.auToken.address);
2636
-
2637
- case 2:
2638
- speeds = _context.sent;
2639
- return _context.abrupt("return", speeds);
2640
-
2641
- case 4:
2642
- case "end":
2643
- return _context.stop();
2644
- }
2645
- }
2646
- }, _callee, this);
2647
- }));
2648
-
2649
- function getRewardSpeeds() {
2650
- return _getRewardSpeeds.apply(this, arguments);
2651
- }
2652
-
2653
- return getRewardSpeeds;
2654
- }();
2655
-
2656
- _proto.getTotalTokenBorrowed = /*#__PURE__*/function () {
2657
- var _getTotalTokenBorrowed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
2658
- return runtime_1.wrap(function _callee2$(_context2) {
2659
- while (1) {
2660
- switch (_context2.prev = _context2.next) {
2661
- case 0:
2662
- _context2.t0 = TokenAmount;
2663
- _context2.t1 = this.underlying;
2664
- _context2.next = 4;
2665
- return this.auToken.totalBorrows();
2279
+ _context2.t0 = TokenAmount;
2280
+ _context2.t1 = this.underlying;
2281
+ _context2.next = 4;
2282
+ return this.auToken.totalBorrows();
2666
2283
 
2667
2284
  case 4:
2668
2285
  _context2.t2 = _context2.sent.toString();
@@ -3078,7 +2695,7 @@ var MoneyMarketReadWrite = /*#__PURE__*/function (_MoneyMarketRead) {
3078
2695
  var _this3;
3079
2696
 
3080
2697
  _this3 = _MoneyMarketRead.call(this, networkConnection, auToken, underlyingAsset) || this;
3081
- _this3._EthRepayHelper = new Contract(networkAddresses.misc.ETHREPAYHELPER, abis$8.abi, networkConnection.provider);
2698
+ _this3._EthRepayHelper = new Contract(networkAddresses.misc.ETHREPAYHELPER, abis$7.abi, networkConnection.provider);
3082
2699
  return _this3;
3083
2700
  }
3084
2701
 
@@ -3285,60 +2902,146 @@ var MoneyMarket = /*#__PURE__*/function (_BlockchainEntity) {
3285
2902
  return MoneyMarket;
3286
2903
  }(BlockchainEntity);
3287
2904
 
3288
- var LOCKING_DENOMINATOR = /*#__PURE__*/BigNumber$1.from(10000);
3289
- var PapermillRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3290
- _inheritsLoose(PapermillRead, _BlockchainEntityRead);
2905
+ var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2906
+ _inheritsLoose(MulticallRead, _BlockchainEntityRead);
3291
2907
 
3292
- function PapermillRead(networkConnection) {
2908
+ function MulticallRead(networkConnection) {
3293
2909
  var _this;
3294
2910
 
3295
2911
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3296
- _this.env = new AuriEnv(networkConnection);
3297
- var plyAddress = networkAddresses.tokens.PLY;
3298
- var pulpAddress = networkAddresses.tokens.PULP;
3299
- _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
3300
- _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
2912
+ _this.multicall = new Contract(networkAddresses.misc.MULTICALL, abis$8.abi, networkConnection.provider);
3301
2913
  return _this;
3302
2914
  }
2915
+ /**
2916
+ * Run multiple calls via multicall contract
2917
+ */
3303
2918
 
3304
- var _proto = PapermillRead.prototype;
3305
2919
 
3306
- _proto.getPlyBalance = /*#__PURE__*/function () {
3307
- var _getPlyBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3308
- var plyBalance;
2920
+ var _proto = MulticallRead.prototype;
2921
+
2922
+ _proto.aggregate =
2923
+ /*#__PURE__*/
2924
+ function () {
2925
+ var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(calls) {
2926
+ var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
2927
+
3309
2928
  return runtime_1.wrap(function _callee$(_context) {
3310
2929
  while (1) {
3311
2930
  switch (_context.prev = _context.next) {
3312
2931
  case 0:
3313
- _context.next = 2;
3314
- return this.env.ply.balanceOf(userAddress);
2932
+ txns = []; // prepare transactions
2933
+
2934
+ i = 0;
3315
2935
 
3316
2936
  case 2:
3317
- plyBalance = _context.sent;
3318
- return _context.abrupt("return", new TokenAmount(this.plyToken, plyBalance.toString()));
2937
+ if (!(i < calls.length)) {
2938
+ _context.next = 11;
2939
+ break;
2940
+ }
3319
2941
 
3320
- case 4:
3321
- case "end":
3322
- return _context.stop();
3323
- }
3324
- }
3325
- }, _callee, this);
3326
- }));
2942
+ call = calls[i];
2943
+ _context.next = 6;
2944
+ return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
3327
2945
 
3328
- function getPlyBalance(_x) {
3329
- return _getPlyBalance.apply(this, arguments);
3330
- }
2946
+ case 6:
2947
+ txn = _context.sent;
2948
+ txns.push({
2949
+ target: txn.to,
2950
+ callData: txn.data
2951
+ });
3331
2952
 
3332
- return getPlyBalance;
3333
- }();
2953
+ case 8:
2954
+ i++;
2955
+ _context.next = 2;
2956
+ break;
3334
2957
 
3335
- _proto.getPulpBalance = /*#__PURE__*/function () {
3336
- var _getPulpBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
3337
- var pulpBalance;
3338
- return runtime_1.wrap(function _callee2$(_context2) {
3339
- while (1) {
3340
- switch (_context2.prev = _context2.next) {
3341
- case 0:
2958
+ case 11:
2959
+ _context.next = 13;
2960
+ return this.multicall.callStatic.aggregate(txns);
2961
+
2962
+ case 13:
2963
+ response = _context.sent;
2964
+ // parse results
2965
+ decodedReturn = [];
2966
+
2967
+ for (_i = 0; _i < calls.length; _i++) {
2968
+ decodedReturn.push(ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
2969
+ }
2970
+
2971
+ return _context.abrupt("return", decodedReturn);
2972
+
2973
+ case 17:
2974
+ case "end":
2975
+ return _context.stop();
2976
+ }
2977
+ }
2978
+ }, _callee, this);
2979
+ }));
2980
+
2981
+ function aggregate(_x) {
2982
+ return _aggregate.apply(this, arguments);
2983
+ }
2984
+
2985
+ return aggregate;
2986
+ }();
2987
+
2988
+ return MulticallRead;
2989
+ }(BlockchainEntityRead);
2990
+
2991
+ var LOCKING_DENOMINATOR = /*#__PURE__*/BigNumber$1.from(10000);
2992
+ var PapermillRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2993
+ _inheritsLoose(PapermillRead, _BlockchainEntityRead);
2994
+
2995
+ function PapermillRead(networkConnection) {
2996
+ var _this;
2997
+
2998
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
2999
+ _this.env = new AuriEnv(networkConnection);
3000
+ var plyAddress = networkAddresses.tokens.PLY;
3001
+ var pulpAddress = networkAddresses.tokens.PULP;
3002
+ _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
3003
+ _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
3004
+ return _this;
3005
+ }
3006
+
3007
+ var _proto = PapermillRead.prototype;
3008
+
3009
+ _proto.getPlyBalance = /*#__PURE__*/function () {
3010
+ var _getPlyBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3011
+ var plyBalance;
3012
+ return runtime_1.wrap(function _callee$(_context) {
3013
+ while (1) {
3014
+ switch (_context.prev = _context.next) {
3015
+ case 0:
3016
+ _context.next = 2;
3017
+ return this.env.ply.balanceOf(userAddress);
3018
+
3019
+ case 2:
3020
+ plyBalance = _context.sent;
3021
+ return _context.abrupt("return", new TokenAmount(this.plyToken, plyBalance.toString()));
3022
+
3023
+ case 4:
3024
+ case "end":
3025
+ return _context.stop();
3026
+ }
3027
+ }
3028
+ }, _callee, this);
3029
+ }));
3030
+
3031
+ function getPlyBalance(_x) {
3032
+ return _getPlyBalance.apply(this, arguments);
3033
+ }
3034
+
3035
+ return getPlyBalance;
3036
+ }();
3037
+
3038
+ _proto.getPulpBalance = /*#__PURE__*/function () {
3039
+ var _getPulpBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
3040
+ var pulpBalance;
3041
+ return runtime_1.wrap(function _callee2$(_context2) {
3042
+ while (1) {
3043
+ switch (_context2.prev = _context2.next) {
3044
+ case 0:
3342
3045
  _context2.next = 2;
3343
3046
  return this.env.pulp.balanceOf(userAddress);
3344
3047
 
@@ -3654,60 +3357,68 @@ var Papermill = /*#__PURE__*/function (_BlockchainEntity) {
3654
3357
  return Papermill;
3655
3358
  }(BlockchainEntity);
3656
3359
 
3657
- var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3658
- _inheritsLoose(ReferralRead, _BlockchainEntityRead);
3360
+ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3361
+ _inheritsLoose(StakingRead, _BlockchainEntityRead);
3659
3362
 
3660
- function ReferralRead(networkConnection) {
3363
+ function StakingRead(networkConnection) {
3661
3364
  var _this;
3662
3365
 
3663
3366
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3664
- _this.referral = new Contract(networkAddresses.misc.REFERRAL, abis$9.abi, networkConnection.provider);
3367
+ _this.env = new AuriEnv(networkConnection);
3665
3368
  return _this;
3666
3369
  }
3667
- /**
3668
- * Generate a 10-character referral code
3669
- * containing alphanumeric characters.
3670
- */
3671
-
3672
-
3673
- var _proto = ReferralRead.prototype;
3674
-
3675
- _proto.generateReferralCode = function generateReferralCode() {
3676
- var letters = 'abcdefghijklmnopqrstuvwxyz';
3677
- var numbers = '1234567890';
3678
- var charset = letters + letters.toUpperCase() + numbers;
3679
- var R = '';
3680
-
3681
- for (var i = 0; i < 10; i++) {
3682
- R += charset[Math.floor(Math.random() * charset.length)];
3683
- }
3684
3370
 
3685
- return R;
3686
- }
3687
- /**
3688
- * Get the referral code for a given address, returns empty string if not found.
3689
- *
3690
- * Called to check if a user has a referral code.
3691
- */
3692
- ;
3371
+ var _proto = StakingRead.prototype;
3693
3372
 
3694
- _proto.getUserReferralCode =
3695
- /*#__PURE__*/
3696
- function () {
3697
- var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddr) {
3698
- var result;
3373
+ _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
3374
+ var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
3375
+ var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
3699
3376
  return runtime_1.wrap(function _callee$(_context) {
3700
3377
  while (1) {
3701
3378
  switch (_context.prev = _context.next) {
3702
3379
  case 0:
3703
3380
  _context.next = 2;
3704
- return this.referral.userReferralCode(userAddr);
3381
+ return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
3382
+ stakedLiquidity = res.totalStake;
3383
+ rewardPerSeconds = res.rewardPerSeconds;
3384
+ });
3705
3385
 
3706
3386
  case 2:
3707
- result = _context.sent;
3708
- return _context.abrupt("return", ethers.utils.parseBytes32String(result));
3387
+ stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
3388
+ _context.next = 5;
3389
+ return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
3709
3390
 
3710
- case 4:
3391
+ case 5:
3392
+ totalStakeValuation = _context.sent;
3393
+ promises = []; // Calculate the reward per second in USD
3394
+
3395
+ for (i = 0; i < rewardPerSeconds.length; i++) {
3396
+ rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3397
+ rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
3398
+ rewardPerSecond = rewardPerSeconds[i];
3399
+ promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
3400
+ }
3401
+
3402
+ APYs = [];
3403
+ _context.next = 11;
3404
+ return Promise.all(promises);
3405
+
3406
+ case 11:
3407
+ _context.sent.forEach(function (rewardPerSecondValuation, i) {
3408
+ var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3409
+ var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
3410
+ APYs.push({
3411
+ address: rewardTokenAddress,
3412
+ apy: apy
3413
+ });
3414
+ });
3415
+
3416
+ return _context.abrupt("return", {
3417
+ totalStakedLiquidity: stakedLiquidityAmount,
3418
+ APYs: APYs
3419
+ });
3420
+
3421
+ case 13:
3711
3422
  case "end":
3712
3423
  return _context.stop();
3713
3424
  }
@@ -3715,32 +3426,32 @@ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3715
3426
  }, _callee, this);
3716
3427
  }));
3717
3428
 
3718
- function getUserReferralCode(_x) {
3719
- return _getUserReferralCode.apply(this, arguments);
3429
+ function getPLYWNEARPoolDetails() {
3430
+ return _getPLYWNEARPoolDetails.apply(this, arguments);
3720
3431
  }
3721
3432
 
3722
- return getUserReferralCode;
3433
+ return getPLYWNEARPoolDetails;
3723
3434
  }()
3724
3435
  /**
3725
- * Get referral code that a user was referred by, returns empty string if not found.
3436
+ * Get amount of staked LP tokens
3726
3437
  */
3727
3438
  ;
3728
3439
 
3729
- _proto.getReferralCodeUsed =
3440
+ _proto.stakeBalanceOf =
3730
3441
  /*#__PURE__*/
3731
3442
  function () {
3732
- var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddr) {
3733
- var result;
3443
+ var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(user) {
3444
+ var userInfo;
3734
3445
  return runtime_1.wrap(function _callee2$(_context2) {
3735
3446
  while (1) {
3736
3447
  switch (_context2.prev = _context2.next) {
3737
3448
  case 0:
3738
3449
  _context2.next = 2;
3739
- return this.referral.referralCodeUsed(userAddr);
3450
+ return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
3740
3451
 
3741
3452
  case 2:
3742
- result = _context2.sent;
3743
- return _context2.abrupt("return", ethers.utils.parseBytes32String(result));
3453
+ userInfo = _context2.sent;
3454
+ return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
3744
3455
 
3745
3456
  case 4:
3746
3457
  case "end":
@@ -3750,30 +3461,35 @@ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3750
3461
  }, _callee2, this);
3751
3462
  }));
3752
3463
 
3753
- function getReferralCodeUsed(_x2) {
3754
- return _getReferralCodeUsed.apply(this, arguments);
3464
+ function stakeBalanceOf(_x) {
3465
+ return _stakeBalanceOf.apply(this, arguments);
3755
3466
  }
3756
3467
 
3757
- return getReferralCodeUsed;
3468
+ return stakeBalanceOf;
3758
3469
  }()
3759
3470
  /**
3760
- * Get owner of a referral code, returns zero address if not found.
3471
+ * Get amount of LP token in user wallet
3761
3472
  */
3762
3473
  ;
3763
3474
 
3764
- _proto.getReferralCodeOwner =
3475
+ _proto.LpBalanceOf =
3765
3476
  /*#__PURE__*/
3766
3477
  function () {
3767
- var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(code) {
3768
- var referralCode;
3478
+ var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(user) {
3479
+ var lpContract, balance;
3769
3480
  return runtime_1.wrap(function _callee3$(_context3) {
3770
3481
  while (1) {
3771
3482
  switch (_context3.prev = _context3.next) {
3772
3483
  case 0:
3773
- referralCode = ethers.utils.formatBytes32String(code);
3774
- return _context3.abrupt("return", this.referral.referralCodeOwner(referralCode));
3484
+ lpContract = new Contract(networkAddresses.tokens.PLYWNEAR, abis$3.abi, this._networkConnection.provider);
3485
+ _context3.next = 3;
3486
+ return lpContract.balanceOf(user);
3775
3487
 
3776
- case 2:
3488
+ case 3:
3489
+ balance = _context3.sent;
3490
+ return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
3491
+
3492
+ case 5:
3777
3493
  case "end":
3778
3494
  return _context3.stop();
3779
3495
  }
@@ -3781,73 +3497,67 @@ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3781
3497
  }, _callee3, this);
3782
3498
  }));
3783
3499
 
3784
- function getReferralCodeOwner(_x3) {
3785
- return _getReferralCodeOwner.apply(this, arguments);
3500
+ function LpBalanceOf(_x2) {
3501
+ return _LpBalanceOf.apply(this, arguments);
3786
3502
  }
3787
3503
 
3788
- return getReferralCodeOwner;
3504
+ return LpBalanceOf;
3789
3505
  }();
3790
3506
 
3791
- return ReferralRead;
3792
- }(BlockchainEntityRead);
3793
- var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
3794
- _inheritsLoose(ReferralReadWrite, _ReferralRead);
3795
-
3796
- function ReferralReadWrite() {
3797
- return _ReferralRead.apply(this, arguments) || this;
3798
- }
3799
-
3800
- var _proto2 = ReferralReadWrite.prototype;
3801
-
3802
- /**
3803
- * Generate a referral code for a given address.
3804
- *
3805
- * Called when an user want to creates his own referral code
3806
- */
3807
- _proto2.registerNewReferralCode =
3808
- /*#__PURE__*/
3809
- function () {
3810
- var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
3811
- var referralCode;
3507
+ _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
3508
+ var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(user) {
3509
+ var userInfo, rewards;
3812
3510
  return runtime_1.wrap(function _callee4$(_context4) {
3813
3511
  while (1) {
3814
3512
  switch (_context4.prev = _context4.next) {
3815
3513
  case 0:
3816
- referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
3817
- return _context4.abrupt("return", this.referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
3514
+ _context4.next = 2;
3515
+ return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
3516
+ from: user
3517
+ });
3818
3518
 
3819
3519
  case 2:
3820
- case "end":
3821
- return _context4.stop();
3822
- }
3823
- }
3520
+ userInfo = _context4.sent;
3521
+ rewards = userInfo.unclaimedRewards;
3522
+ return _context4.abrupt("return", rewards.map(function (reward, i) {
3523
+ return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
3524
+ }));
3525
+
3526
+ case 5:
3527
+ case "end":
3528
+ return _context4.stop();
3529
+ }
3530
+ }
3824
3531
  }, _callee4, this);
3825
3532
  }));
3826
3533
 
3827
- function registerNewReferralCode() {
3828
- return _registerNewReferralCode.apply(this, arguments);
3534
+ function unclaimedRewardsOf(_x3) {
3535
+ return _unclaimedRewardsOf.apply(this, arguments);
3829
3536
  }
3830
3537
 
3831
- return registerNewReferralCode;
3832
- }()
3833
- /**
3834
- * Called when an user confirms he is referred by a specified code
3835
- */
3836
- ;
3538
+ return unclaimedRewardsOf;
3539
+ }();
3837
3540
 
3838
- _proto2.useReferralCode =
3839
- /*#__PURE__*/
3840
- function () {
3841
- var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(code) {
3842
- var referralCode;
3541
+ return StakingRead;
3542
+ }(BlockchainEntityRead);
3543
+ var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
3544
+ _inheritsLoose(StakingReadWrite, _StakingRead);
3545
+
3546
+ function StakingReadWrite() {
3547
+ return _StakingRead.apply(this, arguments) || this;
3548
+ }
3549
+
3550
+ var _proto2 = StakingReadWrite.prototype;
3551
+
3552
+ _proto2.stake = /*#__PURE__*/function () {
3553
+ var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(amount) {
3843
3554
  return runtime_1.wrap(function _callee5$(_context5) {
3844
3555
  while (1) {
3845
3556
  switch (_context5.prev = _context5.next) {
3846
3557
  case 0:
3847
- referralCode = ethers.utils.formatBytes32String(code);
3848
- return _context5.abrupt("return", this.referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
3558
+ return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
3849
3559
 
3850
- case 2:
3560
+ case 1:
3851
3561
  case "end":
3852
3562
  return _context5.stop();
3853
3563
  }
@@ -3855,97 +3565,427 @@ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
3855
3565
  }, _callee5, this);
3856
3566
  }));
3857
3567
 
3858
- function useReferralCode(_x4) {
3859
- return _useReferralCode.apply(this, arguments);
3568
+ function stake(_x4) {
3569
+ return _stake.apply(this, arguments);
3860
3570
  }
3861
3571
 
3862
- return useReferralCode;
3572
+ return stake;
3863
3573
  }();
3864
3574
 
3865
- return ReferralReadWrite;
3866
- }(ReferralRead);
3867
- var Referral = /*#__PURE__*/function (_BlockchainEntity) {
3868
- _inheritsLoose(Referral, _BlockchainEntity);
3575
+ _proto2.unstake = /*#__PURE__*/function () {
3576
+ var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(amount) {
3577
+ var msgSender, amountInput, stakedAmount, unstakeAmount;
3578
+ return runtime_1.wrap(function _callee6$(_context6) {
3579
+ while (1) {
3580
+ switch (_context6.prev = _context6.next) {
3581
+ case 0:
3582
+ _context6.next = 2;
3583
+ return this._networkConnection.signer.getAddress();
3869
3584
 
3870
- function Referral() {
3585
+ case 2:
3586
+ msgSender = _context6.sent;
3587
+ amountInput = BigNumber$1.from(amount.rawAmount());
3588
+ _context6.t0 = BigNumber$1;
3589
+ _context6.next = 7;
3590
+ return this.stakeBalanceOf(msgSender);
3591
+
3592
+ case 7:
3593
+ _context6.t1 = _context6.sent.rawAmount();
3594
+ stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
3595
+ // unstakeAmount = min(amountInput, stakedAmount - 1)
3596
+ unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
3597
+ return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
3598
+
3599
+ case 11:
3600
+ case "end":
3601
+ return _context6.stop();
3602
+ }
3603
+ }
3604
+ }, _callee6, this);
3605
+ }));
3606
+
3607
+ function unstake(_x5) {
3608
+ return _unstake.apply(this, arguments);
3609
+ }
3610
+
3611
+ return unstake;
3612
+ }();
3613
+
3614
+ return StakingReadWrite;
3615
+ }(StakingRead);
3616
+ var Staking = /*#__PURE__*/function (_BlockchainEntity) {
3617
+ _inheritsLoose(Staking, _BlockchainEntity);
3618
+
3619
+ function Staking() {
3871
3620
  return _BlockchainEntity.call(this) || this;
3872
3621
  }
3873
3622
 
3874
- var _proto3 = Referral.prototype;
3623
+ var _proto3 = Staking.prototype;
3875
3624
 
3876
3625
  _proto3.read = function read(networkConnection) {
3877
- return new ReferralRead(networkConnection);
3626
+ return new StakingRead(networkConnection);
3878
3627
  };
3879
3628
 
3880
3629
  _proto3.readWrite = function readWrite(networkConnection) {
3881
- return new ReferralReadWrite(networkConnection);
3630
+ return new StakingReadWrite(networkConnection);
3882
3631
  };
3883
3632
 
3884
- return Referral;
3633
+ return Staking;
3885
3634
  }(BlockchainEntity);
3886
3635
 
3887
- var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3888
- _inheritsLoose(StakingRead, _BlockchainEntityRead);
3636
+ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3637
+ _inheritsLoose(MiscRead, _BlockchainEntityRead);
3889
3638
 
3890
- function StakingRead(networkConnection) {
3639
+ function MiscRead(networkConnection) {
3891
3640
  var _this;
3892
3641
 
3893
3642
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3643
+ _this.stakingRead = new StakingRead(networkConnection);
3894
3644
  _this.env = new AuriEnv(networkConnection);
3895
3645
  return _this;
3896
3646
  }
3897
3647
 
3898
- var _proto = StakingRead.prototype;
3648
+ var _proto = MiscRead.prototype;
3649
+
3650
+ _proto.getUserDetails = /*#__PURE__*/function () {
3651
+ var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddress) {
3652
+ var _this2 = this;
3653
+
3654
+ var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
3899
3655
 
3900
- _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
3901
- var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
3902
- var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
3903
3656
  return runtime_1.wrap(function _callee$(_context) {
3904
3657
  while (1) {
3905
3658
  switch (_context.prev = _context.next) {
3906
3659
  case 0:
3907
- _context.next = 2;
3908
- return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
3909
- stakedLiquidity = res.totalStake;
3910
- rewardPerSeconds = res.rewardPerSeconds;
3660
+ marketCount = networkAddresses.auTokens.length;
3661
+ userMarketDetails = [];
3662
+ promises = [];
3663
+ totalBorrowLimit = new BigNumber(0);
3664
+ pricePromises = [];
3665
+
3666
+ _loop2 = function _loop2() {
3667
+ var auToken = _step.value;
3668
+ var userMarketDetail = {};
3669
+ userMarketDetails.push(userMarketDetail);
3670
+ userMarketDetail.market = auToken.underlying;
3671
+ var moneyMarket = new MoneyMarketRead(_this2._networkConnection, auToken.address, auToken.underlying);
3672
+ promises.push(moneyMarket.getUserDepositBalance(userAddress).then(function (res) {
3673
+ userMarketDetail.depositBalance = res;
3674
+ }));
3675
+ promises.push(moneyMarket.getUserBorrowBalance(userAddress).then(function (res) {
3676
+ userMarketDetail.borrowBalance = res;
3677
+ }));
3678
+ promises.push(moneyMarket.getCollateralRatio().then(function (res) {
3679
+ userMarketDetail.collateralRatio = res.toNumber();
3680
+ }));
3681
+ pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider).then(function (res) {
3682
+ userMarketDetail.underlyingPrice = res.toString();
3683
+ return res;
3684
+ }));
3685
+ };
3686
+
3687
+ for (_iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens); !(_step = _iterator()).done;) {
3688
+ _loop2();
3689
+ }
3690
+
3691
+ promises.push(this.env.comptroller.getAssetsIn(userAddress).then(function (res) {
3692
+ assetsIn = res;
3693
+ }));
3694
+ _context.next = 10;
3695
+ return Promise.all(promises);
3696
+
3697
+ case 10:
3698
+ _context.next = 12;
3699
+ return Promise.all(pricePromises);
3700
+
3701
+ case 12:
3702
+ underlyingPrices = _context.sent;
3703
+ depositValues = [];
3704
+
3705
+ _loop = function _loop() {
3706
+ var auToken = networkAddresses.auTokens[i];
3707
+
3708
+ if (assetsIn.find(function (auAddress) {
3709
+ return isSameAddress(auToken.address, auAddress);
3710
+ }) !== undefined) {
3711
+ userMarketDetails[i].isCollateral = true;
3712
+ } else {
3713
+ userMarketDetails[i].isCollateral = false;
3714
+ }
3715
+
3716
+ depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
3717
+ };
3718
+
3719
+ for (i = 0; i < marketCount; i++) {
3720
+ _loop();
3721
+ }
3722
+
3723
+ totalBorrowLimit = depositValues.reduce(function (p, v, index) {
3724
+ if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
3725
+ return p;
3726
+ }, new BigNumber(0));
3727
+ _context.next = 19;
3728
+ return this.env.comptroller.getAccountLiquidity(userAddress);
3729
+
3730
+ case 19:
3731
+ accountLiquidity = _context.sent;
3732
+ borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
3733
+
3734
+ if (borrowedvaluation.lt('0.00001')) {
3735
+ // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
3736
+ borrowedvaluation = new BigNumber(0);
3737
+ }
3738
+
3739
+ bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
3740
+ minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
3741
+
3742
+ if (bufferedBorrowLimit.lte(borrowedvaluation)) {
3743
+ borrowableAmount = new BigNumber(0);
3744
+ } else {
3745
+ borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
3746
+ }
3747
+
3748
+ for (i = 0; i < marketCount; i++) {
3749
+ auToken = networkAddresses.auTokens[i];
3750
+ moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
3751
+ borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
3752
+ maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
3753
+ userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount()) ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false) : new TokenAmount(moneyMarket.underlying, userMarketDetails[i].depositBalance.rawAmount());
3754
+ }
3755
+
3756
+ _context.t0 = userMarketDetails;
3757
+ _context.t1 = {
3758
+ currency: 'USD',
3759
+ amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
3760
+ };
3761
+ _context.next = 30;
3762
+ return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
3763
+
3764
+ case 30:
3765
+ _context.t2 = _context.sent;
3766
+ _context.t3 = {
3767
+ currency: 'USD',
3768
+ amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
3769
+ };
3770
+ return _context.abrupt("return", {
3771
+ markets: _context.t0,
3772
+ borrowLimit: _context.t1,
3773
+ userLockingDetails: _context.t2,
3774
+ borrowableAmount: _context.t3
3911
3775
  });
3912
3776
 
3777
+ case 33:
3778
+ case "end":
3779
+ return _context.stop();
3780
+ }
3781
+ }
3782
+ }, _callee, this);
3783
+ }));
3784
+
3785
+ function getUserDetails(_x) {
3786
+ return _getUserDetails.apply(this, arguments);
3787
+ }
3788
+
3789
+ return getUserDetails;
3790
+ }();
3791
+
3792
+ _proto.getTokenPrice = /*#__PURE__*/function () {
3793
+ var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(token) {
3794
+ var price;
3795
+ return runtime_1.wrap(function _callee2$(_context2) {
3796
+ while (1) {
3797
+ switch (_context2.prev = _context2.next) {
3798
+ case 0:
3799
+ _context2.next = 2;
3800
+ return fetchPrice(token.address, this._networkConnection.provider);
3801
+
3913
3802
  case 2:
3914
- stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
3915
- _context.next = 5;
3916
- return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
3803
+ price = _context2.sent;
3804
+ return _context2.abrupt("return", {
3805
+ currency: 'USD',
3806
+ amount: price.toFixed(DECIMAL_PRECISION)
3807
+ });
3917
3808
 
3918
- case 5:
3919
- totalStakeValuation = _context.sent;
3920
- promises = []; // Calculate the reward per second in USD
3809
+ case 4:
3810
+ case "end":
3811
+ return _context2.stop();
3812
+ }
3813
+ }
3814
+ }, _callee2, this);
3815
+ }));
3921
3816
 
3922
- for (i = 0; i < rewardPerSeconds.length; i++) {
3923
- rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3924
- rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
3925
- rewardPerSecond = rewardPerSeconds[i];
3926
- promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
3927
- }
3817
+ function getTokenPrice(_x2) {
3818
+ return _getTokenPrice.apply(this, arguments);
3819
+ }
3928
3820
 
3929
- APYs = [];
3930
- _context.next = 11;
3931
- return Promise.all(promises);
3821
+ return getTokenPrice;
3822
+ }();
3932
3823
 
3933
- case 11:
3934
- _context.sent.forEach(function (rewardPerSecondValuation, i) {
3935
- var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3936
- var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
3937
- APYs.push({
3938
- address: rewardTokenAddress,
3939
- apy: apy
3940
- });
3824
+ _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
3825
+ var userMarketDetail = _ref.userMarketDetail,
3826
+ currentBorrowLimit = _ref.currentBorrowLimit,
3827
+ currentBorrowValuation = _ref.currentBorrowValuation,
3828
+ action = _ref.action,
3829
+ tokenAmount = _ref.tokenAmount;
3830
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
3831
+ newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
3832
+
3833
+ switch (action) {
3834
+ case MarketAction.EnableCollateral:
3835
+ case MarketAction.DisableCollateral:
3836
+ var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
3837
+ newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
3838
+ break;
3839
+
3840
+ case MarketAction.Deposit:
3841
+ case MarketAction.Withdraw:
3842
+ deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
3843
+ newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
3844
+ break;
3845
+
3846
+ case MarketAction.Borrow:
3847
+ case MarketAction.Repay:
3848
+ var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
3849
+ newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
3850
+ break;
3851
+ }
3852
+
3853
+ return {
3854
+ newBorrowLimit: {
3855
+ amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
3856
+ currency: 'USD'
3857
+ },
3858
+ newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
3859
+ };
3860
+ }
3861
+ /**
3862
+ * Get ply circulating supply.
3863
+ * It is calculated by the total supply, minus:
3864
+ * - Ply in team multisig contract
3865
+ * - Ply in comptroller contract
3866
+ * - Ply in fairlaunch contract
3867
+ * - Ply in vesting contract
3868
+ */
3869
+ ;
3870
+
3871
+ _proto.getPlyCirculatingSupply =
3872
+ /*#__PURE__*/
3873
+ function () {
3874
+ var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
3875
+ var multicallRead, baseBalanceOfCall, callResults, circulatingSupply;
3876
+ return runtime_1.wrap(function _callee3$(_context3) {
3877
+ while (1) {
3878
+ switch (_context3.prev = _context3.next) {
3879
+ case 0:
3880
+ multicallRead = new MulticallRead(this._networkConnection);
3881
+ baseBalanceOfCall = {
3882
+ contract: this.env.ply,
3883
+ method: 'balanceOf',
3884
+ returnTypes: ['uint256']
3885
+ };
3886
+ _context3.next = 4;
3887
+ return multicallRead.aggregate([// Get total supply
3888
+ _extends({}, baseBalanceOfCall, {
3889
+ method: 'totalSupply',
3890
+ args: []
3891
+ }), // balance in team multisig
3892
+ _extends({}, baseBalanceOfCall, {
3893
+ args: [networkAddresses.misc.TEAM_MULTISIG]
3894
+ }), // balance in comptroller
3895
+ _extends({}, baseBalanceOfCall, {
3896
+ args: [networkAddresses.misc.COMPTROLLER]
3897
+ }), // balance in fair launch
3898
+ _extends({}, baseBalanceOfCall, {
3899
+ args: [networkAddresses.misc.AURIFAIRLAUNCH]
3900
+ }), // balance in vesting contract
3901
+ _extends({}, baseBalanceOfCall, {
3902
+ args: [networkAddresses.misc.PLY_TOKEN_LOCK]
3903
+ })]);
3904
+
3905
+ case 4:
3906
+ callResults = _context3.sent;
3907
+ circulatingSupply = BigNumber$1.from(0);
3908
+ callResults.forEach(function (result, i) {
3909
+ if (i === 0) {
3910
+ circulatingSupply = result[0];
3911
+ } else {
3912
+ circulatingSupply = circulatingSupply.sub(result[0]);
3913
+ }
3941
3914
  });
3915
+ return _context3.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
3916
+
3917
+ case 8:
3918
+ case "end":
3919
+ return _context3.stop();
3920
+ }
3921
+ }
3922
+ }, _callee3, this);
3923
+ }));
3924
+
3925
+ function getPlyCirculatingSupply() {
3926
+ return _getPlyCirculatingSupply.apply(this, arguments);
3927
+ }
3928
+
3929
+ return getPlyCirculatingSupply;
3930
+ }();
3931
+
3932
+ return MiscRead;
3933
+ }(BlockchainEntityRead);
3934
+
3935
+ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3936
+ _inheritsLoose(ReferralRead, _BlockchainEntityRead);
3937
+
3938
+ function ReferralRead(networkConnection) {
3939
+ var _this;
3940
+
3941
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3942
+ _this.referral = new Contract(networkAddresses.misc.REFERRAL, abis$9.abi, networkConnection.provider);
3943
+ return _this;
3944
+ }
3945
+ /**
3946
+ * Generate a 10-character referral code
3947
+ * containing alphanumeric characters.
3948
+ */
3949
+
3950
+
3951
+ var _proto = ReferralRead.prototype;
3952
+
3953
+ _proto.generateReferralCode = function generateReferralCode() {
3954
+ var letters = 'abcdefghijklmnopqrstuvwxyz';
3955
+ var numbers = '1234567890';
3956
+ var charset = letters + letters.toUpperCase() + numbers;
3957
+ var R = '';
3958
+
3959
+ for (var i = 0; i < 10; i++) {
3960
+ R += charset[Math.floor(Math.random() * charset.length)];
3961
+ }
3962
+
3963
+ return R;
3964
+ }
3965
+ /**
3966
+ * Get the referral code for a given address, returns empty string if not found.
3967
+ *
3968
+ * Called to check if a user has a referral code.
3969
+ */
3970
+ ;
3971
+
3972
+ _proto.getUserReferralCode =
3973
+ /*#__PURE__*/
3974
+ function () {
3975
+ var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(userAddr) {
3976
+ var result;
3977
+ return runtime_1.wrap(function _callee$(_context) {
3978
+ while (1) {
3979
+ switch (_context.prev = _context.next) {
3980
+ case 0:
3981
+ _context.next = 2;
3982
+ return this.referral.userReferralCode(userAddr);
3942
3983
 
3943
- return _context.abrupt("return", {
3944
- totalStakedLiquidity: stakedLiquidityAmount,
3945
- APYs: APYs
3946
- });
3984
+ case 2:
3985
+ result = _context.sent;
3986
+ return _context.abrupt("return", ethers.utils.parseBytes32String(result));
3947
3987
 
3948
- case 13:
3988
+ case 4:
3949
3989
  case "end":
3950
3990
  return _context.stop();
3951
3991
  }
@@ -3953,32 +3993,32 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3953
3993
  }, _callee, this);
3954
3994
  }));
3955
3995
 
3956
- function getPLYWNEARPoolDetails() {
3957
- return _getPLYWNEARPoolDetails.apply(this, arguments);
3996
+ function getUserReferralCode(_x) {
3997
+ return _getUserReferralCode.apply(this, arguments);
3958
3998
  }
3959
3999
 
3960
- return getPLYWNEARPoolDetails;
4000
+ return getUserReferralCode;
3961
4001
  }()
3962
4002
  /**
3963
- * Get amount of staked LP tokens
4003
+ * Get referral code that a user was referred by, returns empty string if not found.
3964
4004
  */
3965
4005
  ;
3966
4006
 
3967
- _proto.stakeBalanceOf =
4007
+ _proto.getReferralCodeUsed =
3968
4008
  /*#__PURE__*/
3969
4009
  function () {
3970
- var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(user) {
3971
- var userInfo;
4010
+ var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddr) {
4011
+ var result;
3972
4012
  return runtime_1.wrap(function _callee2$(_context2) {
3973
4013
  while (1) {
3974
4014
  switch (_context2.prev = _context2.next) {
3975
4015
  case 0:
3976
4016
  _context2.next = 2;
3977
- return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
4017
+ return this.referral.referralCodeUsed(userAddr);
3978
4018
 
3979
4019
  case 2:
3980
- userInfo = _context2.sent;
3981
- return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
4020
+ result = _context2.sent;
4021
+ return _context2.abrupt("return", ethers.utils.parseBytes32String(result));
3982
4022
 
3983
4023
  case 4:
3984
4024
  case "end":
@@ -3988,35 +4028,30 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3988
4028
  }, _callee2, this);
3989
4029
  }));
3990
4030
 
3991
- function stakeBalanceOf(_x) {
3992
- return _stakeBalanceOf.apply(this, arguments);
4031
+ function getReferralCodeUsed(_x2) {
4032
+ return _getReferralCodeUsed.apply(this, arguments);
3993
4033
  }
3994
4034
 
3995
- return stakeBalanceOf;
4035
+ return getReferralCodeUsed;
3996
4036
  }()
3997
4037
  /**
3998
- * Get amount of LP token in user wallet
4038
+ * Get owner of a referral code, returns zero address if not found.
3999
4039
  */
4000
4040
  ;
4001
4041
 
4002
- _proto.LpBalanceOf =
4042
+ _proto.getReferralCodeOwner =
4003
4043
  /*#__PURE__*/
4004
4044
  function () {
4005
- var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(user) {
4006
- var lpContract, balance;
4045
+ var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(code) {
4046
+ var referralCode;
4007
4047
  return runtime_1.wrap(function _callee3$(_context3) {
4008
4048
  while (1) {
4009
4049
  switch (_context3.prev = _context3.next) {
4010
4050
  case 0:
4011
- lpContract = new Contract(networkAddresses.tokens.PLYWNEAR, abis$3.abi, this._networkConnection.provider);
4012
- _context3.next = 3;
4013
- return lpContract.balanceOf(user);
4014
-
4015
- case 3:
4016
- balance = _context3.sent;
4017
- return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
4051
+ referralCode = ethers.utils.formatBytes32String(code);
4052
+ return _context3.abrupt("return", this.referral.referralCodeOwner(referralCode));
4018
4053
 
4019
- case 5:
4054
+ case 2:
4020
4055
  case "end":
4021
4056
  return _context3.stop();
4022
4057
  }
@@ -4024,33 +4059,42 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4024
4059
  }, _callee3, this);
4025
4060
  }));
4026
4061
 
4027
- function LpBalanceOf(_x2) {
4028
- return _LpBalanceOf.apply(this, arguments);
4062
+ function getReferralCodeOwner(_x3) {
4063
+ return _getReferralCodeOwner.apply(this, arguments);
4029
4064
  }
4030
4065
 
4031
- return LpBalanceOf;
4066
+ return getReferralCodeOwner;
4032
4067
  }();
4033
4068
 
4034
- _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
4035
- var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(user) {
4036
- var userInfo, rewards;
4069
+ return ReferralRead;
4070
+ }(BlockchainEntityRead);
4071
+ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
4072
+ _inheritsLoose(ReferralReadWrite, _ReferralRead);
4073
+
4074
+ function ReferralReadWrite() {
4075
+ return _ReferralRead.apply(this, arguments) || this;
4076
+ }
4077
+
4078
+ var _proto2 = ReferralReadWrite.prototype;
4079
+
4080
+ /**
4081
+ * Generate a referral code for a given address.
4082
+ *
4083
+ * Called when an user want to creates his own referral code
4084
+ */
4085
+ _proto2.registerNewReferralCode =
4086
+ /*#__PURE__*/
4087
+ function () {
4088
+ var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
4089
+ var referralCode;
4037
4090
  return runtime_1.wrap(function _callee4$(_context4) {
4038
4091
  while (1) {
4039
4092
  switch (_context4.prev = _context4.next) {
4040
4093
  case 0:
4041
- _context4.next = 2;
4042
- return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
4043
- from: user
4044
- });
4094
+ referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
4095
+ return _context4.abrupt("return", this.referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
4045
4096
 
4046
4097
  case 2:
4047
- userInfo = _context4.sent;
4048
- rewards = userInfo.unclaimedRewards;
4049
- return _context4.abrupt("return", rewards.map(function (reward, i) {
4050
- return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
4051
- }));
4052
-
4053
- case 5:
4054
4098
  case "end":
4055
4099
  return _context4.stop();
4056
4100
  }
@@ -4058,33 +4102,30 @@ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4058
4102
  }, _callee4, this);
4059
4103
  }));
4060
4104
 
4061
- function unclaimedRewardsOf(_x3) {
4062
- return _unclaimedRewardsOf.apply(this, arguments);
4105
+ function registerNewReferralCode() {
4106
+ return _registerNewReferralCode.apply(this, arguments);
4063
4107
  }
4064
4108
 
4065
- return unclaimedRewardsOf;
4066
- }();
4067
-
4068
- return StakingRead;
4069
- }(BlockchainEntityRead);
4070
- var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
4071
- _inheritsLoose(StakingReadWrite, _StakingRead);
4072
-
4073
- function StakingReadWrite() {
4074
- return _StakingRead.apply(this, arguments) || this;
4075
- }
4076
-
4077
- var _proto2 = StakingReadWrite.prototype;
4109
+ return registerNewReferralCode;
4110
+ }()
4111
+ /**
4112
+ * Called when an user confirms he is referred by a specified code
4113
+ */
4114
+ ;
4078
4115
 
4079
- _proto2.stake = /*#__PURE__*/function () {
4080
- var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(amount) {
4116
+ _proto2.useReferralCode =
4117
+ /*#__PURE__*/
4118
+ function () {
4119
+ var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(code) {
4120
+ var referralCode;
4081
4121
  return runtime_1.wrap(function _callee5$(_context5) {
4082
4122
  while (1) {
4083
4123
  switch (_context5.prev = _context5.next) {
4084
4124
  case 0:
4085
- return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
4125
+ referralCode = ethers.utils.formatBytes32String(code);
4126
+ return _context5.abrupt("return", this.referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
4086
4127
 
4087
- case 1:
4128
+ case 2:
4088
4129
  case "end":
4089
4130
  return _context5.stop();
4090
4131
  }
@@ -4092,72 +4133,33 @@ var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
4092
4133
  }, _callee5, this);
4093
4134
  }));
4094
4135
 
4095
- function stake(_x4) {
4096
- return _stake.apply(this, arguments);
4097
- }
4098
-
4099
- return stake;
4100
- }();
4101
-
4102
- _proto2.unstake = /*#__PURE__*/function () {
4103
- var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(amount) {
4104
- var msgSender, amountInput, stakedAmount, unstakeAmount;
4105
- return runtime_1.wrap(function _callee6$(_context6) {
4106
- while (1) {
4107
- switch (_context6.prev = _context6.next) {
4108
- case 0:
4109
- _context6.next = 2;
4110
- return this._networkConnection.signer.getAddress();
4111
-
4112
- case 2:
4113
- msgSender = _context6.sent;
4114
- amountInput = BigNumber$1.from(amount.rawAmount());
4115
- _context6.t0 = BigNumber$1;
4116
- _context6.next = 7;
4117
- return this.stakeBalanceOf(msgSender);
4118
-
4119
- case 7:
4120
- _context6.t1 = _context6.sent.rawAmount();
4121
- stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
4122
- // unstakeAmount = min(amountInput, stakedAmount - 1)
4123
- unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
4124
- return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
4125
-
4126
- case 11:
4127
- case "end":
4128
- return _context6.stop();
4129
- }
4130
- }
4131
- }, _callee6, this);
4132
- }));
4133
-
4134
- function unstake(_x5) {
4135
- return _unstake.apply(this, arguments);
4136
+ function useReferralCode(_x4) {
4137
+ return _useReferralCode.apply(this, arguments);
4136
4138
  }
4137
4139
 
4138
- return unstake;
4140
+ return useReferralCode;
4139
4141
  }();
4140
4142
 
4141
- return StakingReadWrite;
4142
- }(StakingRead);
4143
- var Staking = /*#__PURE__*/function (_BlockchainEntity) {
4144
- _inheritsLoose(Staking, _BlockchainEntity);
4143
+ return ReferralReadWrite;
4144
+ }(ReferralRead);
4145
+ var Referral = /*#__PURE__*/function (_BlockchainEntity) {
4146
+ _inheritsLoose(Referral, _BlockchainEntity);
4145
4147
 
4146
- function Staking() {
4148
+ function Referral() {
4147
4149
  return _BlockchainEntity.call(this) || this;
4148
4150
  }
4149
4151
 
4150
- var _proto3 = Staking.prototype;
4152
+ var _proto3 = Referral.prototype;
4151
4153
 
4152
4154
  _proto3.read = function read(networkConnection) {
4153
- return new StakingRead(networkConnection);
4155
+ return new ReferralRead(networkConnection);
4154
4156
  };
4155
4157
 
4156
4158
  _proto3.readWrite = function readWrite(networkConnection) {
4157
- return new StakingReadWrite(networkConnection);
4159
+ return new ReferralReadWrite(networkConnection);
4158
4160
  };
4159
4161
 
4160
- return Staking;
4162
+ return Referral;
4161
4163
  }(BlockchainEntity);
4162
4164
 
4163
4165
  var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
@@ -4374,6 +4376,38 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4374
4376
  return getPlyCirculatingSupply;
4375
4377
  }();
4376
4378
 
4379
+ _proto.getUltilizations = /*#__PURE__*/function () {
4380
+ var _getUltilizations = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(userAddr) {
4381
+ var helper, accountDetail, sumBorrow, sumCol;
4382
+ return runtime_1.wrap(function _callee8$(_context8) {
4383
+ while (1) {
4384
+ switch (_context8.prev = _context8.next) {
4385
+ case 0:
4386
+ helper = new Contract(networkAddresses.misc.ULTILIZATION_HELPER, abis$a.abi, this._networkConnection.provider);
4387
+ _context8.next = 3;
4388
+ return helper.getAccountLiquidity(userAddr);
4389
+
4390
+ case 3:
4391
+ accountDetail = _context8.sent;
4392
+ sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
4393
+ sumCol = new BigNumber(accountDetail.sumCollateral.toString());
4394
+ return _context8.abrupt("return", sumBorrow.dividedBy(sumCol));
4395
+
4396
+ case 7:
4397
+ case "end":
4398
+ return _context8.stop();
4399
+ }
4400
+ }
4401
+ }, _callee8, this);
4402
+ }));
4403
+
4404
+ function getUltilizations(_x6) {
4405
+ return _getUltilizations.apply(this, arguments);
4406
+ }
4407
+
4408
+ return getUltilizations;
4409
+ }();
4410
+
4377
4411
  return SdkRead;
4378
4412
  }(BlockchainEntityRead);
4379
4413
  var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
@@ -4391,25 +4425,25 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4391
4425
  _proto2.claim =
4392
4426
  /*#__PURE__*/
4393
4427
  function () {
4394
- var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
4395
- return runtime_1.wrap(function _callee8$(_context8) {
4428
+ var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
4429
+ return runtime_1.wrap(function _callee9$(_context9) {
4396
4430
  while (1) {
4397
- switch (_context8.prev = _context8.next) {
4431
+ switch (_context9.prev = _context9.next) {
4398
4432
  case 0:
4399
- _context8.t0 = this.env.comptroller.connect(this._networkConnection.signer);
4400
- _context8.next = 3;
4433
+ _context9.t0 = this.env.comptroller.connect(this._networkConnection.signer);
4434
+ _context9.next = 3;
4401
4435
  return this._networkConnection.signer.getAddress();
4402
4436
 
4403
4437
  case 3:
4404
- _context8.t1 = _context8.sent;
4405
- return _context8.abrupt("return", _context8.t0['claimReward(uint8,address)'].call(_context8.t0, 0, _context8.t1));
4438
+ _context9.t1 = _context9.sent;
4439
+ return _context9.abrupt("return", _context9.t0['claimReward(uint8,address)'].call(_context9.t0, 0, _context9.t1));
4406
4440
 
4407
4441
  case 5:
4408
4442
  case "end":
4409
- return _context8.stop();
4443
+ return _context9.stop();
4410
4444
  }
4411
4445
  }
4412
- }, _callee8, this);
4446
+ }, _callee9, this);
4413
4447
  }));
4414
4448
 
4415
4449
  function claim() {
@@ -4420,26 +4454,26 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4420
4454
  }();
4421
4455
 
4422
4456
  _proto2.claimLpRewards = /*#__PURE__*/function () {
4423
- var _claimLpRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
4424
- return runtime_1.wrap(function _callee9$(_context9) {
4457
+ var _claimLpRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10() {
4458
+ return runtime_1.wrap(function _callee10$(_context10) {
4425
4459
  while (1) {
4426
- switch (_context9.prev = _context9.next) {
4460
+ switch (_context10.prev = _context10.next) {
4427
4461
  case 0:
4428
- _context9.t0 = this.env.auriFairLaunch.connect(this._networkConnection.signer);
4429
- _context9.next = 3;
4462
+ _context10.t0 = this.env.auriFairLaunch.connect(this._networkConnection.signer);
4463
+ _context10.next = 3;
4430
4464
  return this._networkConnection.signer.getAddress();
4431
4465
 
4432
4466
  case 3:
4433
- _context9.t1 = _context9.sent;
4434
- _context9.t2 = INF;
4435
- return _context9.abrupt("return", _context9.t0.harvest.call(_context9.t0, _context9.t1, 0, _context9.t2));
4467
+ _context10.t1 = _context10.sent;
4468
+ _context10.t2 = INF;
4469
+ return _context10.abrupt("return", _context10.t0.harvest.call(_context10.t0, _context10.t1, 0, _context10.t2));
4436
4470
 
4437
4471
  case 6:
4438
4472
  case "end":
4439
- return _context9.stop();
4473
+ return _context10.stop();
4440
4474
  }
4441
4475
  }
4442
- }, _callee9, this);
4476
+ }, _callee10, this);
4443
4477
  }));
4444
4478
 
4445
4479
  function claimLpRewards() {
@@ -4450,22 +4484,22 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4450
4484
  }();
4451
4485
 
4452
4486
  _proto2.stake = /*#__PURE__*/function () {
4453
- var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(amount) {
4454
- return runtime_1.wrap(function _callee10$(_context10) {
4487
+ var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(amount) {
4488
+ return runtime_1.wrap(function _callee11$(_context11) {
4455
4489
  while (1) {
4456
- switch (_context10.prev = _context10.next) {
4490
+ switch (_context11.prev = _context11.next) {
4457
4491
  case 0:
4458
- return _context10.abrupt("return", new StakingReadWrite(this._networkConnection).stake(amount));
4492
+ return _context11.abrupt("return", new StakingReadWrite(this._networkConnection).stake(amount));
4459
4493
 
4460
4494
  case 1:
4461
4495
  case "end":
4462
- return _context10.stop();
4496
+ return _context11.stop();
4463
4497
  }
4464
4498
  }
4465
- }, _callee10, this);
4499
+ }, _callee11, this);
4466
4500
  }));
4467
4501
 
4468
- function stake(_x6) {
4502
+ function stake(_x7) {
4469
4503
  return _stake.apply(this, arguments);
4470
4504
  }
4471
4505
 
@@ -4473,22 +4507,22 @@ var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
4473
4507
  }();
4474
4508
 
4475
4509
  _proto2.unstake = /*#__PURE__*/function () {
4476
- var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(amount) {
4477
- return runtime_1.wrap(function _callee11$(_context11) {
4510
+ var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(amount) {
4511
+ return runtime_1.wrap(function _callee12$(_context12) {
4478
4512
  while (1) {
4479
- switch (_context11.prev = _context11.next) {
4513
+ switch (_context12.prev = _context12.next) {
4480
4514
  case 0:
4481
- return _context11.abrupt("return", new StakingReadWrite(this._networkConnection).unstake(amount));
4515
+ return _context12.abrupt("return", new StakingReadWrite(this._networkConnection).unstake(amount));
4482
4516
 
4483
4517
  case 1:
4484
4518
  case "end":
4485
- return _context11.stop();
4519
+ return _context12.stop();
4486
4520
  }
4487
4521
  }
4488
- }, _callee11, this);
4522
+ }, _callee12, this);
4489
4523
  }));
4490
4524
 
4491
- function unstake(_x7) {
4525
+ function unstake(_x8) {
4492
4526
  return _unstake.apply(this, arguments);
4493
4527
  }
4494
4528