@aurigami/sdk 1.17.1 → 1.17.2

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.
@@ -2414,19 +2414,6 @@ var Airdrop = /*#__PURE__*/function (_BlockchainEntity) {
2414
2414
  return Airdrop;
2415
2415
  }(BlockchainEntity);
2416
2416
 
2417
- (function (ComptrollerRewardType) {
2418
- ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
2419
- ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
2420
- })(exports.ComptrollerRewardType || (exports.ComptrollerRewardType = {}));
2421
- (function (MarketAction) {
2422
- MarketAction[MarketAction["Deposit"] = 0] = "Deposit";
2423
- MarketAction[MarketAction["Borrow"] = 1] = "Borrow";
2424
- MarketAction[MarketAction["Withdraw"] = 2] = "Withdraw";
2425
- MarketAction[MarketAction["Repay"] = 3] = "Repay";
2426
- MarketAction[MarketAction["EnableCollateral"] = 4] = "EnableCollateral";
2427
- MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
2428
- })(exports.MarketAction || (exports.MarketAction = {}));
2429
-
2430
2417
  var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2431
2418
  _inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
2432
2419
  function MoneyMarketRead(networkConnection, auToken, underlyingAsset) {
@@ -3268,71 +3255,6 @@ var MoneyMarket = /*#__PURE__*/function (_BlockchainEntity) {
3268
3255
  return MoneyMarket;
3269
3256
  }(BlockchainEntity);
3270
3257
 
3271
- var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3272
- _inheritsLoose(MulticallRead, _BlockchainEntityRead);
3273
- function MulticallRead(networkConnection) {
3274
- var _this;
3275
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3276
- _this.multicall = new ethers.Contract(networkAddresses.misc.MULTICALL, abis$a.abi, networkConnection.provider);
3277
- return _this;
3278
- }
3279
- /**
3280
- * Run multiple calls via multicall contract
3281
- */
3282
- var _proto = MulticallRead.prototype;
3283
- _proto.aggregate =
3284
- /*#__PURE__*/
3285
- function () {
3286
- var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(calls) {
3287
- var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
3288
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3289
- while (1) switch (_context.prev = _context.next) {
3290
- case 0:
3291
- txns = []; // prepare transactions
3292
- i = 0;
3293
- case 2:
3294
- if (!(i < calls.length)) {
3295
- _context.next = 11;
3296
- break;
3297
- }
3298
- call = calls[i];
3299
- _context.next = 6;
3300
- return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
3301
- case 6:
3302
- txn = _context.sent;
3303
- txns.push({
3304
- target: txn.to,
3305
- callData: txn.data
3306
- });
3307
- case 8:
3308
- i++;
3309
- _context.next = 2;
3310
- break;
3311
- case 11:
3312
- _context.next = 13;
3313
- return this.multicall.callStatic.aggregate(txns);
3314
- case 13:
3315
- response = _context.sent;
3316
- // parse results
3317
- decodedReturn = [];
3318
- for (_i = 0; _i < calls.length; _i++) {
3319
- decodedReturn.push(ethers.ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
3320
- }
3321
- return _context.abrupt("return", decodedReturn);
3322
- case 17:
3323
- case "end":
3324
- return _context.stop();
3325
- }
3326
- }, _callee, this);
3327
- }));
3328
- function aggregate(_x) {
3329
- return _aggregate.apply(this, arguments);
3330
- }
3331
- return aggregate;
3332
- }();
3333
- return MulticallRead;
3334
- }(BlockchainEntityRead);
3335
-
3336
3258
  var LOCKING_DENOMINATOR = /*#__PURE__*/ethers.BigNumber.from(10000);
3337
3259
  var PapermillRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3338
3260
  _inheritsLoose(PapermillRead, _BlockchainEntityRead);
@@ -3624,1571 +3546,1719 @@ var Papermill = /*#__PURE__*/function (_BlockchainEntity) {
3624
3546
  return Papermill;
3625
3547
  }(BlockchainEntity);
3626
3548
 
3627
- var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3628
- _inheritsLoose(StakingRead, _BlockchainEntityRead);
3629
- function StakingRead(networkConnection) {
3549
+ var PlyGameRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3550
+ _inheritsLoose(PlyGameRead, _BlockchainEntityRead);
3551
+ function PlyGameRead(networkConnection) {
3630
3552
  var _this;
3631
3553
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3632
3554
  _this.env = new AuriEnv(networkConnection);
3555
+ var plyAddress = networkAddresses.tokens.PLY;
3556
+ var pulpAddress = networkAddresses.tokens.PULP;
3557
+ _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
3558
+ _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
3633
3559
  return _this;
3634
3560
  }
3635
- var _proto = StakingRead.prototype;
3636
- _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
3637
- var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
3638
- var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
3561
+ var _proto = PlyGameRead.prototype;
3562
+ _proto.parseBetMakeEvent = function parseBetMakeEvent(event) {
3563
+ var outcome = ['bigWin', 'win', 'lose', 'noImpact'][event.args.outcome];
3564
+ var betAmount = event.args.amount;
3565
+ // 0%, 0%, 100%, 2%
3566
+ // big win, win, lose, no impact
3567
+ var lostAmount = betAmount.mul([0, 0, 100, 2][event.args.outcome]).div(100);
3568
+ var unlock = betAmount.mul([10, 1, 0, 0][event.args.outcome]);
3569
+ return {
3570
+ player: event.args.player,
3571
+ lostAmount: new TokenAmount(this.plyToken, lostAmount.toString()),
3572
+ unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
3573
+ outcome: outcome,
3574
+ transactionHash: event.transactionHash,
3575
+ block: event.blockNumber,
3576
+ timestamp: 0
3577
+ };
3578
+ };
3579
+ _proto.attachTimestamp = /*#__PURE__*/function () {
3580
+ var _attachTimestamp = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(results) {
3581
+ var blockNumbers, blockstimestamp;
3639
3582
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3640
3583
  while (1) switch (_context.prev = _context.next) {
3641
3584
  case 0:
3642
- _context.next = 2;
3643
- return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
3644
- stakedLiquidity = res.totalStake;
3645
- rewardPerSeconds = res.rewardPerSeconds;
3585
+ blockNumbers = results.map(function (e) {
3586
+ return e.block;
3646
3587
  });
3647
- case 2:
3648
- stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
3649
- _context.next = 5;
3650
- return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
3651
- case 5:
3652
- totalStakeValuation = _context.sent;
3653
- promises = []; // Calculate the reward per second in USD
3654
- for (i = 0; i < rewardPerSeconds.length; i++) {
3655
- rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3656
- rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
3657
- rewardPerSecond = rewardPerSeconds[i];
3658
- promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
3659
- }
3660
- APYs = [];
3661
- _context.next = 11;
3662
- return Promise.all(promises);
3663
- case 11:
3664
- _context.sent.forEach(function (rewardPerSecondValuation, i) {
3665
- var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
3666
- var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
3667
- APYs.push({
3668
- address: rewardTokenAddress,
3669
- apy: apy
3588
+ _context.next = 3;
3589
+ return getBlocksTimestamp(this._networkConnection.provider, blockNumbers);
3590
+ case 3:
3591
+ blockstimestamp = _context.sent;
3592
+ return _context.abrupt("return", results.map(function (e, i) {
3593
+ return _extends({}, e, {
3594
+ timestamp: blockstimestamp[i]
3670
3595
  });
3671
- });
3672
- return _context.abrupt("return", {
3673
- totalStakedLiquidity: stakedLiquidityAmount,
3674
- APYs: APYs
3675
- });
3676
- case 13:
3596
+ }));
3597
+ case 5:
3677
3598
  case "end":
3678
3599
  return _context.stop();
3679
3600
  }
3680
3601
  }, _callee, this);
3681
3602
  }));
3682
- function getPLYWNEARPoolDetails() {
3683
- return _getPLYWNEARPoolDetails.apply(this, arguments);
3603
+ function attachTimestamp(_x) {
3604
+ return _attachTimestamp.apply(this, arguments);
3684
3605
  }
3685
- return getPLYWNEARPoolDetails;
3606
+ return attachTimestamp;
3686
3607
  }()
3687
3608
  /**
3688
- * Get amount of staked LP tokens
3609
+ * Get 100 most recent bets of the market users
3689
3610
  */
3690
3611
  ;
3691
- _proto.stakeBalanceOf =
3612
+ _proto.getUserPlyGameHistory =
3692
3613
  /*#__PURE__*/
3693
3614
  function () {
3694
- var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(user) {
3695
- var userInfo;
3615
+ var _getUserPlyGameHistory = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(user) {
3616
+ var _this2 = this;
3617
+ var block100, filter, events;
3696
3618
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3697
3619
  while (1) switch (_context2.prev = _context2.next) {
3698
3620
  case 0:
3699
3621
  _context2.next = 2;
3700
- return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
3622
+ return this.env.plygame.getLastBlock(user, 100);
3701
3623
  case 2:
3702
- userInfo = _context2.sent;
3703
- return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
3704
- case 4:
3624
+ block100 = _context2.sent;
3625
+ if (!block100.eq(0)) {
3626
+ _context2.next = 5;
3627
+ break;
3628
+ }
3629
+ return _context2.abrupt("return", []);
3630
+ case 5:
3631
+ filter = this.env.plygame.filters.BetMade(user);
3632
+ _context2.next = 8;
3633
+ return this.env.plygame.queryFilter(filter, block100.toNumber());
3634
+ case 8:
3635
+ events = _context2.sent;
3636
+ // Sort descending by block number
3637
+ sortEvents(events).reverse();
3638
+ return _context2.abrupt("return", this.attachTimestamp(events.map(function (event) {
3639
+ return _this2.parseBetMakeEvent(event);
3640
+ })));
3641
+ case 11:
3705
3642
  case "end":
3706
3643
  return _context2.stop();
3707
3644
  }
3708
3645
  }, _callee2, this);
3709
3646
  }));
3710
- function stakeBalanceOf(_x) {
3711
- return _stakeBalanceOf.apply(this, arguments);
3647
+ function getUserPlyGameHistory(_x2) {
3648
+ return _getUserPlyGameHistory.apply(this, arguments);
3712
3649
  }
3713
- return stakeBalanceOf;
3650
+ return getUserPlyGameHistory;
3714
3651
  }()
3715
3652
  /**
3716
- * Get amount of LP token in user wallet
3653
+ * Get current jackpot amount
3717
3654
  */
3718
3655
  ;
3719
- _proto.LpBalanceOf =
3656
+ _proto.currentJackpotAmount =
3720
3657
  /*#__PURE__*/
3721
3658
  function () {
3722
- var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(user) {
3723
- var lpContract, balance;
3659
+ var _currentJackpotAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
3660
+ var jackpot;
3724
3661
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3725
3662
  while (1) switch (_context3.prev = _context3.next) {
3726
3663
  case 0:
3727
- lpContract = new ethers.Contract(networkAddresses.tokens.PLYWNEAR, abis$8.abi, this._networkConnection.provider);
3728
- _context3.next = 3;
3729
- return lpContract.balanceOf(user);
3730
- case 3:
3731
- balance = _context3.sent;
3732
- return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
3733
- case 5:
3664
+ _context3.next = 2;
3665
+ return this.env.plygame.currentJackpotAmount();
3666
+ case 2:
3667
+ jackpot = _context3.sent;
3668
+ return _context3.abrupt("return", new TokenAmount(this.plyToken, jackpot.toString()));
3669
+ case 4:
3734
3670
  case "end":
3735
3671
  return _context3.stop();
3736
3672
  }
3737
3673
  }, _callee3, this);
3738
3674
  }));
3739
- function LpBalanceOf(_x2) {
3740
- return _LpBalanceOf.apply(this, arguments);
3675
+ function currentJackpotAmount() {
3676
+ return _currentJackpotAmount.apply(this, arguments);
3741
3677
  }
3742
- return LpBalanceOf;
3678
+ return currentJackpotAmount;
3743
3679
  }();
3744
- _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
3745
- var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(user) {
3746
- var userInfo, rewards;
3680
+ _proto.earlyUnlockedPulpAmount = /*#__PURE__*/function () {
3681
+ var _earlyUnlockedPulpAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(user) {
3682
+ var earlyUnlockedPulpAmount;
3747
3683
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3748
3684
  while (1) switch (_context4.prev = _context4.next) {
3749
3685
  case 0:
3750
3686
  _context4.next = 2;
3751
- return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
3752
- from: user
3753
- });
3687
+ return this.env.plygame.totalPlyUnlockedEarly(user);
3754
3688
  case 2:
3755
- userInfo = _context4.sent;
3756
- rewards = userInfo.unclaimedRewards;
3757
- return _context4.abrupt("return", rewards.map(function (reward, i) {
3758
- return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
3759
- }));
3760
- case 5:
3689
+ earlyUnlockedPulpAmount = _context4.sent;
3690
+ return _context4.abrupt("return", new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString()));
3691
+ case 4:
3761
3692
  case "end":
3762
3693
  return _context4.stop();
3763
3694
  }
3764
3695
  }, _callee4, this);
3765
3696
  }));
3766
- function unclaimedRewardsOf(_x3) {
3767
- return _unclaimedRewardsOf.apply(this, arguments);
3697
+ function earlyUnlockedPulpAmount(_x3) {
3698
+ return _earlyUnlockedPulpAmount.apply(this, arguments);
3768
3699
  }
3769
- return unclaimedRewardsOf;
3700
+ return earlyUnlockedPulpAmount;
3770
3701
  }();
3771
- return StakingRead;
3772
- }(BlockchainEntityRead);
3773
- var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
3774
- _inheritsLoose(StakingReadWrite, _StakingRead);
3775
- function StakingReadWrite() {
3776
- return _StakingRead.apply(this, arguments) || this;
3777
- }
3778
- var _proto2 = StakingReadWrite.prototype;
3779
- _proto2.stake = /*#__PURE__*/function () {
3780
- var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(amount) {
3702
+ _proto.getPlyGameResultsInTransaction = /*#__PURE__*/function () {
3703
+ var _getPlyGameResultsInTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(txHash) {
3704
+ var _this3 = this;
3705
+ var tx, i, filter, betMadeEvents;
3781
3706
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
3782
3707
  while (1) switch (_context5.prev = _context5.next) {
3783
3708
  case 0:
3784
- return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
3785
- case 1:
3709
+ _context5.next = 2;
3710
+ return this._networkConnection.provider.getTransactionReceipt(txHash);
3711
+ case 2:
3712
+ tx = _context5.sent;
3713
+ i = 0;
3714
+ case 4:
3715
+ if (!(i < 100 && !tx)) {
3716
+ _context5.next = 13;
3717
+ break;
3718
+ }
3719
+ _context5.next = 7;
3720
+ return sleep(1000);
3721
+ case 7:
3722
+ _context5.next = 9;
3723
+ return this._networkConnection.provider.getTransactionReceipt(txHash);
3724
+ case 9:
3725
+ tx = _context5.sent;
3726
+ case 10:
3727
+ i++;
3728
+ _context5.next = 4;
3729
+ break;
3730
+ case 13:
3731
+ if (tx) {
3732
+ _context5.next = 15;
3733
+ break;
3734
+ }
3735
+ throw new Error("Transaction " + txHash + " takes too long to be mined");
3736
+ case 15:
3737
+ filter = this.env.plygame.filters.BetMade();
3738
+ betMadeEvents = tx.logs.filter(function (log) {
3739
+ return isSameAddress(log.topics[0], filter.topics[0]);
3740
+ }).map(function (log) {
3741
+ return _extends({}, _this3.env.plygame["interface"].parseLog(log), {
3742
+ blockNumber: tx.blockNumber,
3743
+ transactionHash: txHash
3744
+ });
3745
+ });
3746
+ return _context5.abrupt("return", this.attachTimestamp(betMadeEvents.map(function (e) {
3747
+ return _this3.parseBetMakeEvent(e);
3748
+ })));
3749
+ case 18:
3786
3750
  case "end":
3787
3751
  return _context5.stop();
3788
3752
  }
3789
3753
  }, _callee5, this);
3790
3754
  }));
3791
- function stake(_x4) {
3792
- return _stake.apply(this, arguments);
3755
+ function getPlyGameResultsInTransaction(_x4) {
3756
+ return _getPlyGameResultsInTransaction.apply(this, arguments);
3793
3757
  }
3794
- return stake;
3795
- }();
3796
- _proto2.unstake = /*#__PURE__*/function () {
3797
- var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(amount) {
3798
- var msgSender, amountInput, stakedAmount, unstakeAmount;
3758
+ return getPlyGameResultsInTransaction;
3759
+ }()
3760
+ /**
3761
+ * Top 100 users by amount of PULP unlocked
3762
+ */
3763
+ ;
3764
+ _proto.leaderboard =
3765
+ /*#__PURE__*/
3766
+ function () {
3767
+ var _leaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
3768
+ var _this4 = this;
3769
+ var result;
3799
3770
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
3800
3771
  while (1) switch (_context6.prev = _context6.next) {
3801
3772
  case 0:
3802
3773
  _context6.next = 2;
3803
- return this._networkConnection.signer.getAddress();
3774
+ return getPaginatedApi('/plygame/leaderboard');
3804
3775
  case 2:
3805
- msgSender = _context6.sent;
3806
- amountInput = ethers.BigNumber.from(amount.rawAmount());
3807
- _context6.t0 = ethers.BigNumber;
3808
- _context6.next = 7;
3809
- return this.stakeBalanceOf(msgSender);
3810
- case 7:
3811
- _context6.t1 = _context6.sent.rawAmount();
3812
- stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
3813
- // unstakeAmount = min(amountInput, stakedAmount - 1)
3814
- unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
3815
- return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
3816
- case 11:
3776
+ result = _context6.sent;
3777
+ return _context6.abrupt("return", result.items.map(function (item, i) {
3778
+ return {
3779
+ player: item.user,
3780
+ unlockedPulpAmount: new TokenAmount(_this4.pulpToken, item.unlockedAmount),
3781
+ gamesPlayed: item.count
3782
+ };
3783
+ }));
3784
+ case 4:
3817
3785
  case "end":
3818
3786
  return _context6.stop();
3819
3787
  }
3820
- }, _callee6, this);
3788
+ }, _callee6);
3821
3789
  }));
3822
- function unstake(_x5) {
3823
- return _unstake.apply(this, arguments);
3790
+ function leaderboard() {
3791
+ return _leaderboard.apply(this, arguments);
3824
3792
  }
3825
- return unstake;
3793
+ return leaderboard;
3826
3794
  }();
3827
- return StakingReadWrite;
3828
- }(StakingRead);
3829
- var Staking = /*#__PURE__*/function (_BlockchainEntity) {
3830
- _inheritsLoose(Staking, _BlockchainEntity);
3831
- function Staking() {
3795
+ _proto.getLastJackpotResult = /*#__PURE__*/function () {
3796
+ var _getLastJackpotResult = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
3797
+ var round, result;
3798
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
3799
+ while (1) switch (_context7.prev = _context7.next) {
3800
+ case 0:
3801
+ _context7.t0 = ethers.BigNumber;
3802
+ _context7.next = 3;
3803
+ return this._networkConnection.provider.getStorageAt(this.env.plygame.address, 158);
3804
+ case 3:
3805
+ _context7.t1 = _context7.sent;
3806
+ round = _context7.t0.from.call(_context7.t0, _context7.t1);
3807
+ _context7.next = 7;
3808
+ return this.env.plygame.jackpotHistory(round.sub(1));
3809
+ case 7:
3810
+ result = _context7.sent;
3811
+ return _context7.abrupt("return", {
3812
+ winner: result.winner.slice(0, 5) + '...' + result.winner.slice(-3),
3813
+ amount: new TokenAmount(this.plyToken, result.amount.toString())
3814
+ });
3815
+ case 9:
3816
+ case "end":
3817
+ return _context7.stop();
3818
+ }
3819
+ }, _callee7, this);
3820
+ }));
3821
+ function getLastJackpotResult() {
3822
+ return _getLastJackpotResult.apply(this, arguments);
3823
+ }
3824
+ return getLastJackpotResult;
3825
+ }();
3826
+ _proto.overallLeaderboard = /*#__PURE__*/function () {
3827
+ var _overallLeaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
3828
+ var _this5 = this;
3829
+ var result;
3830
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
3831
+ while (1) switch (_context8.prev = _context8.next) {
3832
+ case 0:
3833
+ _context8.next = 2;
3834
+ return getPaginatedApi('/plygame/overallLeaderboard');
3835
+ case 2:
3836
+ result = _context8.sent;
3837
+ return _context8.abrupt("return", result.items.map(function (item) {
3838
+ return {
3839
+ player: item.user,
3840
+ unlockedPulpAmount: new TokenAmount(_this5.pulpToken, item.unlockedAmount),
3841
+ gamesPlayed: item.count
3842
+ };
3843
+ }));
3844
+ case 4:
3845
+ case "end":
3846
+ return _context8.stop();
3847
+ }
3848
+ }, _callee8);
3849
+ }));
3850
+ function overallLeaderboard() {
3851
+ return _overallLeaderboard.apply(this, arguments);
3852
+ }
3853
+ return overallLeaderboard;
3854
+ }();
3855
+ return PlyGameRead;
3856
+ }(BlockchainEntityRead);
3857
+ var PlyGameReadWrite = /*#__PURE__*/function (_PlyGameRead) {
3858
+ _inheritsLoose(PlyGameReadWrite, _PlyGameRead);
3859
+ function PlyGameReadWrite() {
3860
+ return _PlyGameRead.apply(this, arguments) || this;
3861
+ }
3862
+ var _proto2 = PlyGameReadWrite.prototype;
3863
+ /**
3864
+ * Make a single bet
3865
+ */
3866
+ _proto2.makeBetOnce =
3867
+ /*#__PURE__*/
3868
+ function () {
3869
+ var _makeBetOnce = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(amount) {
3870
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
3871
+ while (1) switch (_context9.prev = _context9.next) {
3872
+ case 0:
3873
+ return _context9.abrupt("return", this.env.plygame.connect(this._networkConnection.signer).makeBetOnce(amount.rawAmount()));
3874
+ case 1:
3875
+ case "end":
3876
+ return _context9.stop();
3877
+ }
3878
+ }, _callee9, this);
3879
+ }));
3880
+ function makeBetOnce(_x5) {
3881
+ return _makeBetOnce.apply(this, arguments);
3882
+ }
3883
+ return makeBetOnce;
3884
+ }();
3885
+ _proto2.approve = /*#__PURE__*/function () {
3886
+ var _approve = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(amount) {
3887
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
3888
+ while (1) switch (_context10.prev = _context10.next) {
3889
+ case 0:
3890
+ return _context10.abrupt("return", this.env.ply.connect(this._networkConnection.signer).approve(this.env.plygame.address, amount.rawAmount()));
3891
+ case 1:
3892
+ case "end":
3893
+ return _context10.stop();
3894
+ }
3895
+ }, _callee10, this);
3896
+ }));
3897
+ function approve(_x6) {
3898
+ return _approve.apply(this, arguments);
3899
+ }
3900
+ return approve;
3901
+ }();
3902
+ return PlyGameReadWrite;
3903
+ }(PlyGameRead);
3904
+ var PlyGame = /*#__PURE__*/function (_BlockchainEntity) {
3905
+ _inheritsLoose(PlyGame, _BlockchainEntity);
3906
+ function PlyGame() {
3832
3907
  return _BlockchainEntity.call(this) || this;
3833
3908
  }
3834
- var _proto3 = Staking.prototype;
3909
+ var _proto3 = PlyGame.prototype;
3835
3910
  _proto3.read = function read(networkConnection) {
3836
- return new StakingRead(networkConnection);
3911
+ return new PlyGameRead(networkConnection);
3837
3912
  };
3838
3913
  _proto3.readWrite = function readWrite(networkConnection) {
3839
- return new StakingReadWrite(networkConnection);
3914
+ return new PlyGameReadWrite(networkConnection);
3840
3915
  };
3841
- return Staking;
3916
+ return PlyGame;
3842
3917
  }(BlockchainEntity);
3843
3918
 
3844
- var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3845
- _inheritsLoose(MiscRead, _BlockchainEntityRead);
3846
- function MiscRead(networkConnection) {
3919
+ var PulpRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3920
+ _inheritsLoose(PulpRead, _BlockchainEntityRead);
3921
+ function PulpRead(networkConnection) {
3847
3922
  var _this;
3848
3923
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3849
- _this.stakingRead = new StakingRead(networkConnection);
3850
3924
  _this.env = new AuriEnv(networkConnection);
3851
3925
  return _this;
3852
3926
  }
3853
- var _proto = MiscRead.prototype;
3854
- _proto.getUserDetails = /*#__PURE__*/function () {
3855
- var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(userAddress) {
3856
- var marketCount, userMarketDetails, assetsIn, totalBorrowLimit, _iterator, _step, _auToken, userMarketDetail, _moneyMarket, _yield$Promise$all, depositBalance, borrowBalance, collateralRatio, underlyingPrice, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
3857
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
3927
+ var _proto = PulpRead.prototype;
3928
+ _proto.remainingEarlyUnlockPulp = /*#__PURE__*/function () {
3929
+ var _remainingEarlyUnlockPulp = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(user) {
3930
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3931
+ while (1) switch (_context.prev = _context.next) {
3932
+ case 0:
3933
+ return _context.abrupt("return", this.env.pulp.getMaxAmountRedeemable(user));
3934
+ case 1:
3935
+ case "end":
3936
+ return _context.stop();
3937
+ }
3938
+ }, _callee, this);
3939
+ }));
3940
+ function remainingEarlyUnlockPulp(_x) {
3941
+ return _remainingEarlyUnlockPulp.apply(this, arguments);
3942
+ }
3943
+ return remainingEarlyUnlockPulp;
3944
+ }();
3945
+ return PulpRead;
3946
+ }(BlockchainEntityRead);
3947
+ var PulpReadWrite = /*#__PURE__*/function (_PulpRead) {
3948
+ _inheritsLoose(PulpReadWrite, _PulpRead);
3949
+ function PulpReadWrite() {
3950
+ return _PulpRead.apply(this, arguments) || this;
3951
+ }
3952
+ var _proto2 = PulpReadWrite.prototype;
3953
+ _proto2.convertEarlyPulp = /*#__PURE__*/function () {
3954
+ var _convertEarlyPulp = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(recipient, amount) {
3955
+ var amountToRedeem;
3956
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3858
3957
  while (1) switch (_context2.prev = _context2.next) {
3859
3958
  case 0:
3860
- marketCount = networkAddresses.auTokens.length;
3861
- userMarketDetails = [];
3862
- totalBorrowLimit = new BigNumber(0);
3863
- _iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens);
3864
- case 4:
3865
- if ((_step = _iterator()).done) {
3866
- _context2.next = 23;
3867
- break;
3868
- }
3869
- _auToken = _step.value;
3870
- userMarketDetail = {};
3871
- userMarketDetails.push(userMarketDetail);
3872
- userMarketDetail.market = _auToken.underlying;
3873
- _moneyMarket = new MoneyMarketRead(this._networkConnection, _auToken.address, _auToken.underlying);
3874
- _context2.next = 12;
3875
- return Promise.all([_moneyMarket.getUserDepositBalance(userAddress), _moneyMarket.getUserBorrowBalance(userAddress), _moneyMarket.getCollateralRatio(), fetchPrice(_moneyMarket.underlying.address, this._networkConnection.provider)]);
3876
- case 12:
3877
- _yield$Promise$all = _context2.sent;
3878
- depositBalance = _yield$Promise$all[0];
3879
- borrowBalance = _yield$Promise$all[1];
3880
- collateralRatio = _yield$Promise$all[2];
3881
- underlyingPrice = _yield$Promise$all[3];
3882
- userMarketDetail.depositBalance = depositBalance;
3883
- userMarketDetail.borrowBalance = borrowBalance;
3884
- userMarketDetail.collateralRatio = collateralRatio.toNumber();
3885
- userMarketDetail.underlyingPrice = underlyingPrice.toString();
3886
- case 21:
3887
- _context2.next = 4;
3888
- break;
3889
- case 23:
3890
- _context2.next = 25;
3891
- return this.env.comptroller.getAssetsIn(userAddress);
3892
- case 25:
3893
- assetsIn = _context2.sent;
3894
- depositValues = [];
3895
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
3896
- var auToken;
3897
- return _regeneratorRuntime().wrap(function _loop$(_context) {
3898
- while (1) switch (_context.prev = _context.next) {
3899
- case 0:
3900
- auToken = networkAddresses.auTokens[i];
3901
- if (assetsIn.find(function (auAddress) {
3902
- return isSameAddress(auToken.address, auAddress);
3903
- }) !== undefined) {
3904
- userMarketDetails[i].isCollateral = true;
3905
- } else {
3906
- userMarketDetails[i].isCollateral = false;
3907
- }
3908
- depositValues.push(calcValuation(userMarketDetails[i].depositBalance, new BigNumber(userMarketDetails[i].underlyingPrice)));
3909
- case 3:
3910
- case "end":
3911
- return _context.stop();
3912
- }
3913
- }, _loop);
3914
- });
3915
- i = 0;
3916
- case 29:
3917
- if (!(i < marketCount)) {
3918
- _context2.next = 34;
3919
- break;
3920
- }
3921
- return _context2.delegateYield(_loop(), "t0", 31);
3922
- case 31:
3923
- i++;
3924
- _context2.next = 29;
3925
- break;
3926
- case 34:
3927
- totalBorrowLimit = depositValues.reduce(function (p, v, index) {
3928
- if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
3929
- return p;
3930
- }, new BigNumber(0));
3931
- _context2.next = 37;
3932
- return this.env.comptroller.getAccountLiquidity(userAddress);
3933
- case 37:
3934
- accountLiquidity = _context2.sent;
3935
- borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
3936
- if (borrowedvaluation.lt('0.00001')) {
3937
- // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
3938
- borrowedvaluation = new BigNumber(0);
3939
- }
3940
- bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
3941
- minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
3942
- if (bufferedBorrowLimit.lte(borrowedvaluation)) {
3943
- borrowableAmount = new BigNumber(0);
3944
- } else {
3945
- borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
3946
- }
3947
- for (i = 0; i < marketCount; i++) {
3948
- auToken = networkAddresses.auTokens[i];
3949
- moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
3950
- borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
3951
- maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(userMarketDetails[i].underlyingPrice);
3952
- 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());
3953
- }
3954
- _context2.t1 = userMarketDetails;
3955
- _context2.t2 = {
3956
- currency: 'USD',
3957
- amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
3958
- };
3959
- _context2.next = 48;
3960
- return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
3961
- case 48:
3962
- _context2.t3 = _context2.sent;
3963
- _context2.t4 = {
3964
- currency: 'USD',
3965
- amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
3966
- };
3967
- return _context2.abrupt("return", {
3968
- markets: _context2.t1,
3969
- borrowLimit: _context2.t2,
3970
- userLockingDetails: _context2.t3,
3971
- borrowableAmount: _context2.t4
3972
- });
3973
- case 51:
3974
- case "end":
3975
- return _context2.stop();
3976
- }
3977
- }, _callee, this);
3978
- }));
3979
- function getUserDetails(_x) {
3980
- return _getUserDetails.apply(this, arguments);
3981
- }
3982
- return getUserDetails;
3983
- }();
3984
- _proto.getTokenPrice = /*#__PURE__*/function () {
3985
- var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
3986
- var price;
3987
- return _regeneratorRuntime().wrap(function _callee2$(_context3) {
3988
- while (1) switch (_context3.prev = _context3.next) {
3989
- case 0:
3990
- _context3.next = 2;
3991
- return fetchPrice(token.address, this._networkConnection.provider);
3959
+ amountToRedeem = ethers.BigNumber.from(amount.rawAmount);
3960
+ return _context2.abrupt("return", this.env.pulp.redeem(recipient, amountToRedeem));
3992
3961
  case 2:
3993
- price = _context3.sent;
3994
- return _context3.abrupt("return", {
3995
- currency: 'USD',
3996
- amount: price.toFixed(DECIMAL_PRECISION)
3997
- });
3998
- case 4:
3999
3962
  case "end":
4000
- return _context3.stop();
3963
+ return _context2.stop();
4001
3964
  }
4002
3965
  }, _callee2, this);
4003
3966
  }));
4004
- function getTokenPrice(_x2) {
4005
- return _getTokenPrice.apply(this, arguments);
3967
+ function convertEarlyPulp(_x2, _x3) {
3968
+ return _convertEarlyPulp.apply(this, arguments);
4006
3969
  }
4007
- return getTokenPrice;
3970
+ return convertEarlyPulp;
4008
3971
  }();
4009
- _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
4010
- var userMarketDetail = _ref.userMarketDetail,
4011
- currentBorrowLimit = _ref.currentBorrowLimit,
4012
- currentBorrowValuation = _ref.currentBorrowValuation,
4013
- action = _ref.action,
4014
- tokenAmount = _ref.tokenAmount;
4015
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
4016
- newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
4017
- switch (action) {
4018
- case exports.MarketAction.EnableCollateral:
4019
- case exports.MarketAction.DisableCollateral:
4020
- var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
4021
- newBorrowLimit = action == exports.MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
4022
- break;
4023
- case exports.MarketAction.Deposit:
4024
- case exports.MarketAction.Withdraw:
4025
- deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
4026
- newBorrowLimit = action == exports.MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
4027
- break;
4028
- case exports.MarketAction.Borrow:
4029
- case exports.MarketAction.Repay:
4030
- var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
4031
- newBorrowValuation = action == exports.MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
4032
- break;
4033
- }
4034
- return {
4035
- newBorrowLimit: {
4036
- amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
4037
- currency: 'USD'
4038
- },
4039
- newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
4040
- };
3972
+ return PulpReadWrite;
3973
+ }(PulpRead);
3974
+ var Pulp = /*#__PURE__*/function (_BlockchainEntity) {
3975
+ _inheritsLoose(Pulp, _BlockchainEntity);
3976
+ function Pulp() {
3977
+ return _BlockchainEntity.call(this) || this;
3978
+ }
3979
+ var _proto3 = Pulp.prototype;
3980
+ _proto3.read = function read(networkConnection) {
3981
+ return new PulpRead(networkConnection);
3982
+ };
3983
+ _proto3.readWrite = function readWrite(networkConnection) {
3984
+ return new PulpReadWrite(networkConnection);
3985
+ };
3986
+ return Pulp;
3987
+ }(BlockchainEntity);
3988
+
3989
+ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3990
+ _inheritsLoose(ReferralRead, _BlockchainEntityRead);
3991
+ function ReferralRead(networkConnection) {
3992
+ var _this;
3993
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
3994
+ _this.env = new AuriEnv(networkConnection);
3995
+ return _this;
4041
3996
  }
4042
3997
  /**
4043
- * Get ply circulating supply.
4044
- * It is calculated by the total supply, minus:
4045
- * - Ply in team multisig contract
4046
- * - Ply in comptroller contract
4047
- * - Ply in fairlaunch contract
4048
- * - Ply in vesting contract
3998
+ * Generate a 10-character referral code
3999
+ * containing alphanumeric characters.
4000
+ */
4001
+ var _proto = ReferralRead.prototype;
4002
+ _proto.generateReferralCode = function generateReferralCode() {
4003
+ var letters = 'abcdefghijklmnopqrstuvwxyz';
4004
+ var numbers = '1234567890';
4005
+ var charset = letters + letters.toUpperCase() + numbers;
4006
+ var R = '';
4007
+ for (var i = 0; i < 10; i++) R += charset[Math.floor(Math.random() * charset.length)];
4008
+ return R;
4009
+ }
4010
+ /**
4011
+ * Get the referral code for a given address, returns empty string if not found.
4012
+ *
4013
+ * Called to check if a user has a referral code.
4049
4014
  */;
4050
- _proto.getPlyCirculatingSupply =
4015
+ _proto.getUserReferralCode =
4051
4016
  /*#__PURE__*/
4052
4017
  function () {
4053
- var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
4054
- var multicallRead, baseBalanceOfCall, listAddrs, calls, callResults, circulatingSupply;
4055
- return _regeneratorRuntime().wrap(function _callee3$(_context4) {
4056
- while (1) switch (_context4.prev = _context4.next) {
4018
+ var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(userAddr) {
4019
+ var result;
4020
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4021
+ while (1) switch (_context.prev = _context.next) {
4057
4022
  case 0:
4058
- multicallRead = new MulticallRead(this._networkConnection);
4059
- baseBalanceOfCall = {
4060
- contract: this.env.ply,
4061
- method: 'balanceOf',
4062
- returnTypes: ['uint256']
4063
- };
4064
- listAddrs = [networkAddresses.misc.TEAM_MULTISIG, networkAddresses.misc.COMPTROLLER, networkAddresses.misc.AURIFAIRLAUNCH, networkAddresses.misc.PLY_TOKEN_LOCK, networkAddresses.misc.TEAM_MULTISIG_AURORA_PLUS, networkAddresses.misc.AURORA_PLUS, networkAddresses.misc.PULP_CONTRACT];
4065
- calls = listAddrs.map(function (addr) {
4066
- return _extends({}, baseBalanceOfCall, {
4067
- args: [addr]
4068
- });
4069
- });
4070
- _context4.next = 6;
4071
- return multicallRead.aggregate(calls);
4072
- case 6:
4073
- callResults = _context4.sent;
4074
- circulatingSupply = ethers.BigNumber.from('1' + '0'.repeat(10) + '0'.repeat(getDecimal(this.env.ply.address)));
4075
- callResults.forEach(function (result, i) {
4076
- circulatingSupply = circulatingSupply.sub(result[0]);
4077
- });
4078
- return _context4.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
4079
- case 10:
4023
+ _context.next = 2;
4024
+ return this.env.referralDirectoryV2.userReferralCode(userAddr);
4025
+ case 2:
4026
+ result = _context.sent;
4027
+ return _context.abrupt("return", ethers.ethers.utils.parseBytes32String(result));
4028
+ case 4:
4080
4029
  case "end":
4081
- return _context4.stop();
4030
+ return _context.stop();
4082
4031
  }
4083
- }, _callee3, this);
4032
+ }, _callee, this);
4084
4033
  }));
4085
- function getPlyCirculatingSupply() {
4086
- return _getPlyCirculatingSupply.apply(this, arguments);
4034
+ function getUserReferralCode(_x) {
4035
+ return _getUserReferralCode.apply(this, arguments);
4087
4036
  }
4088
- return getPlyCirculatingSupply;
4089
- }();
4090
- _proto.getUtilisation = /*#__PURE__*/function () {
4091
- var _getUtilisation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(userAddr) {
4092
- var accountDetail, sumBorrow, sumCol;
4093
- return _regeneratorRuntime().wrap(function _callee4$(_context5) {
4094
- while (1) switch (_context5.prev = _context5.next) {
4037
+ return getUserReferralCode;
4038
+ }()
4039
+ /**
4040
+ * Get referral code that a user was referred by, returns empty string if not found.
4041
+ */
4042
+ ;
4043
+ _proto.getReferralCodeUsed =
4044
+ /*#__PURE__*/
4045
+ function () {
4046
+ var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(userAddr) {
4047
+ var result;
4048
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4049
+ while (1) switch (_context2.prev = _context2.next) {
4095
4050
  case 0:
4096
- _context5.next = 2;
4097
- return this.env.auriInternalLens.callStatic.getAccountLiquidityAccrueInterest(userAddr);
4051
+ _context2.next = 2;
4052
+ return this.env.referralDirectoryV2.referralCodeUsed(userAddr);
4098
4053
  case 2:
4099
- accountDetail = _context5.sent;
4100
- sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
4101
- sumCol = new BigNumber(accountDetail.sumCollateral.toString());
4102
- return _context5.abrupt("return", sumBorrow.dividedBy(sumCol));
4103
- case 6:
4054
+ result = _context2.sent;
4055
+ return _context2.abrupt("return", ethers.ethers.utils.parseBytes32String(result));
4056
+ case 4:
4104
4057
  case "end":
4105
- return _context5.stop();
4058
+ return _context2.stop();
4106
4059
  }
4107
- }, _callee4, this);
4060
+ }, _callee2, this);
4108
4061
  }));
4109
- function getUtilisation(_x3) {
4110
- return _getUtilisation.apply(this, arguments);
4062
+ function getReferralCodeUsed(_x2) {
4063
+ return _getReferralCodeUsed.apply(this, arguments);
4111
4064
  }
4112
- return getUtilisation;
4113
- }();
4114
- _proto.sneakAccounts = /*#__PURE__*/function () {
4115
- var _sneakAccounts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(accounts, tokenAddresses, dust) {
4116
- var _this2 = this;
4117
- var _1E18, oracle, tokens, prices, exrate, res, _iterator2, _step2, addr, infos, i, snapshot, bal, bor, balR, borR;
4118
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
4119
- while (1) switch (_context6.prev = _context6.next) {
4065
+ return getReferralCodeUsed;
4066
+ }()
4067
+ /**
4068
+ * Get owner of a referral code, returns zero address if not found.
4069
+ */
4070
+ ;
4071
+ _proto.getReferralCodeOwner =
4072
+ /*#__PURE__*/
4073
+ function () {
4074
+ var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(code) {
4075
+ var referralCode;
4076
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4077
+ while (1) switch (_context3.prev = _context3.next) {
4120
4078
  case 0:
4121
- if (dust === void 0) {
4122
- dust = /*#__PURE__*/new BigNumber(0.1);
4123
- }
4124
- _1E18 = ethers.BigNumber.from(10).pow(18);
4125
- oracle = this.env.getContract(networkAddresses.misc.oracle, AuriOracleABI.abi);
4126
- tokens = tokenAddresses.map(function (addr) {
4127
- return _this2.env.getContract(addr, abis$5.abi);
4079
+ referralCode = ethers.ethers.utils.formatBytes32String(code);
4080
+ return _context3.abrupt("return", this.env.referralDirectoryV2.referralCodeOwner(referralCode));
4081
+ case 2:
4082
+ case "end":
4083
+ return _context3.stop();
4084
+ }
4085
+ }, _callee3, this);
4086
+ }));
4087
+ function getReferralCodeOwner(_x3) {
4088
+ return _getReferralCodeOwner.apply(this, arguments);
4089
+ }
4090
+ return getReferralCodeOwner;
4091
+ }()
4092
+ /**
4093
+ * Get referrals of a user, sorted descending by timestamp.
4094
+ */
4095
+ ;
4096
+ _proto.getReferralsList =
4097
+ /*#__PURE__*/
4098
+ function () {
4099
+ var _getReferralsList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(userAddr) {
4100
+ var result, blocks, blocksTimestamp, items;
4101
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4102
+ while (1) switch (_context4.prev = _context4.next) {
4103
+ case 0:
4104
+ _context4.next = 2;
4105
+ return getPaginatedApi('/referral/list', {
4106
+ address: userAddr
4128
4107
  });
4129
- _context6.next = 6;
4130
- return oracle.getUnderlyingPrices(tokenAddresses);
4131
- case 6:
4132
- prices = _context6.sent;
4133
- _context6.next = 9;
4134
- return this.env.auriInternalLens.callStatic.getExchangeRates(tokenAddresses);
4135
- case 9:
4136
- exrate = _context6.sent;
4137
- res = [];
4138
- _iterator2 = _createForOfIteratorHelperLoose(accounts);
4139
- case 12:
4140
- if ((_step2 = _iterator2()).done) {
4141
- _context6.next = 33;
4142
- break;
4143
- }
4144
- addr = _step2.value;
4145
- infos = [];
4146
- i = 0;
4147
- case 16:
4148
- if (!(i < tokens.length)) {
4149
- _context6.next = 30;
4150
- break;
4151
- }
4152
- _context6.next = 19;
4153
- return tokens[i].getAccountSnapshot(addr);
4154
- case 19:
4155
- snapshot = _context6.sent;
4156
- bal = snapshot[0].mul(exrate[i]).div(_1E18).mul(prices[i]).div(_1E18);
4157
- bor = snapshot[1].mul(prices[i]).div(_1E18);
4158
- balR = new BigNumber(bal.toString()).dividedBy(_1E18.toString());
4159
- borR = new BigNumber(bor.toString()).dividedBy(_1E18.toString());
4160
- if (!(balR.lte(dust) && borR.lte(dust))) {
4161
- _context6.next = 26;
4162
- break;
4163
- }
4164
- return _context6.abrupt("continue", 27);
4165
- case 26:
4166
- infos.push({
4167
- token: getSymbol(tokenAddresses[i]),
4168
- deposit: balR,
4169
- borrow: borR
4108
+ case 2:
4109
+ result = _context4.sent;
4110
+ blocks = result.items.map(function (item) {
4111
+ return item.blockNumber;
4170
4112
  });
4171
- case 27:
4172
- ++i;
4173
- _context6.next = 16;
4174
- break;
4175
- case 30:
4176
- res.push({
4177
- address: addr,
4178
- tokens: infos
4113
+ _context4.next = 6;
4114
+ return getBlocksTimestamp(this._networkConnection.provider, blocks);
4115
+ case 6:
4116
+ blocksTimestamp = _context4.sent;
4117
+ items = result.items.map(function (item, i) {
4118
+ return {
4119
+ user: item.user,
4120
+ timestamp: blocksTimestamp[i]
4121
+ };
4179
4122
  });
4180
- case 31:
4181
- _context6.next = 12;
4182
- break;
4183
- case 33:
4184
- return _context6.abrupt("return", res);
4185
- case 34:
4123
+ return _context4.abrupt("return", items);
4124
+ case 9:
4186
4125
  case "end":
4187
- return _context6.stop();
4126
+ return _context4.stop();
4188
4127
  }
4189
- }, _callee5, this);
4128
+ }, _callee4, this);
4190
4129
  }));
4191
- function sneakAccounts(_x4, _x5, _x6) {
4192
- return _sneakAccounts.apply(this, arguments);
4130
+ function getReferralsList(_x4) {
4131
+ return _getReferralsList.apply(this, arguments);
4193
4132
  }
4194
- return sneakAccounts;
4195
- }();
4196
- _proto.getNetApyWithoutIncentive = /*#__PURE__*/function () {
4197
- var _getNetApyWithoutIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(userAddress) {
4198
- var _this3 = this;
4199
- var sum, totalSuppliedValue, totalBorrowedValue, netApy, apys, _iterator3, _step3, apy;
4200
- return _regeneratorRuntime().wrap(function _callee6$(_context7) {
4201
- while (1) switch (_context7.prev = _context7.next) {
4133
+ return getReferralsList;
4134
+ }()
4135
+ /**
4136
+ * Array of rewards, sorted by time of the referral period (from latest to oldest)
4137
+ */
4138
+ ;
4139
+ _proto.referralRewards =
4140
+ /*#__PURE__*/
4141
+ function () {
4142
+ var _referralRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(userAddr) {
4143
+ var result, items;
4144
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4145
+ while (1) switch (_context5.prev = _context5.next) {
4202
4146
  case 0:
4203
- sum = new BigNumber(0);
4204
- totalSuppliedValue = new BigNumber(0);
4205
- totalBorrowedValue = new BigNumber(0);
4206
- netApy = new BigNumber(0);
4207
- _context7.next = 6;
4208
- return Promise.all(networkAddresses.auTokens.map(function (auToken) {
4209
- var moneyMarket = new MoneyMarketRead(_this3._networkConnection, auToken.address, auToken.underlying);
4210
- var apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
4211
- return apyWithoutIncentive;
4212
- }));
4213
- case 6:
4214
- apys = _context7.sent;
4215
- for (_iterator3 = _createForOfIteratorHelperLoose(apys); !(_step3 = _iterator3()).done;) {
4216
- apy = _step3.value;
4217
- sum = sum.plus(apy.sum);
4218
- totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
4219
- totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
4220
- }
4221
- if (sum.gt(0)) {
4222
- netApy = sum.div(totalSuppliedValue);
4223
- } else if (sum.lt(0)) {
4224
- netApy = sum.div(totalBorrowedValue);
4225
- }
4226
- return _context7.abrupt("return", netApy);
4227
- case 10:
4147
+ _context5.next = 2;
4148
+ return getPaginatedApi('/referral/rewards', {
4149
+ address: userAddr
4150
+ });
4151
+ case 2:
4152
+ result = _context5.sent;
4153
+ items = result.items.map(function (item, i) {
4154
+ var _item$transactionHash;
4155
+ return {
4156
+ campaign: item.campaign,
4157
+ userAddr: userAddr,
4158
+ isReferrer: item.campaign.includes('referrer'),
4159
+ rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
4160
+ startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
4161
+ endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
4162
+ transactionHash: (_item$transactionHash = item.transactionHash) != null ? _item$transactionHash : null,
4163
+ refereeAddress: null
4164
+ };
4165
+ });
4166
+ return _context5.abrupt("return", items);
4167
+ case 5:
4228
4168
  case "end":
4229
- return _context7.stop();
4169
+ return _context5.stop();
4230
4170
  }
4231
- }, _callee6);
4171
+ }, _callee5);
4232
4172
  }));
4233
- function getNetApyWithoutIncentive(_x7) {
4234
- return _getNetApyWithoutIncentive.apply(this, arguments);
4173
+ function referralRewards(_x5) {
4174
+ return _referralRewards.apply(this, arguments);
4235
4175
  }
4236
- return getNetApyWithoutIncentive;
4237
- }();
4238
- _proto.getNetApyWithIncentive = /*#__PURE__*/function () {
4239
- var _getNetApyWithIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(userAddress) {
4240
- var _this4 = this;
4241
- var sum, totalSuppliedValue, totalBorrowedValue, netApy, apys, _iterator4, _step4, apy;
4242
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
4243
- while (1) switch (_context8.prev = _context8.next) {
4244
- case 0:
4245
- sum = new BigNumber(0);
4246
- totalSuppliedValue = new BigNumber(0);
4247
- totalBorrowedValue = new BigNumber(0);
4248
- netApy = new BigNumber(0);
4249
- _context8.next = 6;
4250
- return Promise.all(networkAddresses.auTokens.map(function (auToken) {
4251
- var moneyMarket = new MoneyMarketRead(_this4._networkConnection, auToken.address, auToken.underlying);
4252
- var apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
4253
- return apyWithIncentive;
4254
- }));
4255
- case 6:
4256
- apys = _context8.sent;
4257
- for (_iterator4 = _createForOfIteratorHelperLoose(apys); !(_step4 = _iterator4()).done;) {
4258
- apy = _step4.value;
4259
- sum = sum.plus(apy.sum);
4260
- totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
4261
- totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
4262
- }
4263
- if (sum.gt(0)) {
4264
- netApy = sum.div(totalSuppliedValue);
4265
- } else if (sum.lt(0)) {
4266
- netApy = sum.div(totalBorrowedValue);
4267
- }
4268
- return _context8.abrupt("return", netApy);
4269
- case 10:
4270
- case "end":
4271
- return _context8.stop();
4272
- }
4273
- }, _callee7);
4274
- }));
4275
- function getNetApyWithIncentive(_x8) {
4276
- return _getNetApyWithIncentive.apply(this, arguments);
4277
- }
4278
- return getNetApyWithIncentive;
4279
- }();
4280
- return MiscRead;
4281
- }(BlockchainEntityRead);
4282
-
4283
- var PlyGameRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4284
- _inheritsLoose(PlyGameRead, _BlockchainEntityRead);
4285
- function PlyGameRead(networkConnection) {
4286
- var _this;
4287
- _this = _BlockchainEntityRead.call(this, networkConnection) || this;
4288
- _this.env = new AuriEnv(networkConnection);
4289
- var plyAddress = networkAddresses.tokens.PLY;
4290
- var pulpAddress = networkAddresses.tokens.PULP;
4291
- _this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
4292
- _this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
4293
- return _this;
4294
- }
4295
- var _proto = PlyGameRead.prototype;
4296
- _proto.parseBetMakeEvent = function parseBetMakeEvent(event) {
4297
- var outcome = ['bigWin', 'win', 'lose', 'noImpact'][event.args.outcome];
4298
- var betAmount = event.args.amount;
4299
- // 0%, 0%, 100%, 2%
4300
- // big win, win, lose, no impact
4301
- var lostAmount = betAmount.mul([0, 0, 100, 2][event.args.outcome]).div(100);
4302
- var unlock = betAmount.mul([10, 1, 0, 0][event.args.outcome]);
4303
- return {
4304
- player: event.args.player,
4305
- lostAmount: new TokenAmount(this.plyToken, lostAmount.toString()),
4306
- unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
4307
- outcome: outcome,
4308
- transactionHash: event.transactionHash,
4309
- block: event.blockNumber,
4310
- timestamp: 0
4311
- };
4312
- };
4313
- _proto.attachTimestamp = /*#__PURE__*/function () {
4314
- var _attachTimestamp = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(results) {
4315
- var blockNumbers, blockstimestamp;
4316
- return _regeneratorRuntime().wrap(function _callee$(_context) {
4317
- while (1) switch (_context.prev = _context.next) {
4318
- case 0:
4319
- blockNumbers = results.map(function (e) {
4320
- return e.block;
4321
- });
4322
- _context.next = 3;
4323
- return getBlocksTimestamp(this._networkConnection.provider, blockNumbers);
4324
- case 3:
4325
- blockstimestamp = _context.sent;
4326
- return _context.abrupt("return", results.map(function (e, i) {
4327
- return _extends({}, e, {
4328
- timestamp: blockstimestamp[i]
4329
- });
4330
- }));
4331
- case 5:
4332
- case "end":
4333
- return _context.stop();
4334
- }
4335
- }, _callee, this);
4336
- }));
4337
- function attachTimestamp(_x) {
4338
- return _attachTimestamp.apply(this, arguments);
4339
- }
4340
- return attachTimestamp;
4176
+ return referralRewards;
4341
4177
  }()
4342
4178
  /**
4343
- * Get 100 most recent bets of the market users
4179
+ * Top 50 reward earners from the last round, sorted by token amount
4344
4180
  */
4345
4181
  ;
4346
- _proto.getUserPlyGameHistory =
4182
+ _proto.leaderboard =
4347
4183
  /*#__PURE__*/
4348
4184
  function () {
4349
- var _getUserPlyGameHistory = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(user) {
4350
- var _this2 = this;
4351
- var block100, filter, events;
4352
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4353
- while (1) switch (_context2.prev = _context2.next) {
4185
+ var _leaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(campaign) {
4186
+ var result, items;
4187
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4188
+ while (1) switch (_context6.prev = _context6.next) {
4354
4189
  case 0:
4355
- _context2.next = 2;
4356
- return this.env.plygame.getLastBlock(user, 100);
4190
+ _context6.next = 2;
4191
+ return getPaginatedApi('/referral/leaderboard', {
4192
+ campaign: campaign
4193
+ });
4357
4194
  case 2:
4358
- block100 = _context2.sent;
4359
- if (!block100.eq(0)) {
4360
- _context2.next = 5;
4361
- break;
4362
- }
4363
- return _context2.abrupt("return", []);
4364
- case 5:
4365
- filter = this.env.plygame.filters.BetMade(user);
4366
- _context2.next = 8;
4367
- return this.env.plygame.queryFilter(filter, block100.toNumber());
4368
- case 8:
4369
- events = _context2.sent;
4370
- // Sort descending by block number
4371
- sortEvents(events).reverse();
4372
- return _context2.abrupt("return", this.attachTimestamp(events.map(function (event) {
4373
- return _this2.parseBetMakeEvent(event);
4374
- })));
4375
- case 11:
4195
+ result = _context6.sent;
4196
+ items = result.items.map(function (item, i) {
4197
+ return {
4198
+ campaign: campaign,
4199
+ userAddr: item.user,
4200
+ isReferrer: item.campaign.includes('referrer'),
4201
+ rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
4202
+ startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
4203
+ endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
4204
+ transactionHash: null,
4205
+ refereeAddress: null
4206
+ };
4207
+ });
4208
+ items.sort(function (a, b) {
4209
+ return b.rewardTokenAmount.compare(a.rewardTokenAmount);
4210
+ });
4211
+ return _context6.abrupt("return", items);
4212
+ case 6:
4376
4213
  case "end":
4377
- return _context2.stop();
4214
+ return _context6.stop();
4378
4215
  }
4379
- }, _callee2, this);
4216
+ }, _callee6);
4380
4217
  }));
4381
- function getUserPlyGameHistory(_x2) {
4382
- return _getUserPlyGameHistory.apply(this, arguments);
4218
+ function leaderboard(_x6) {
4219
+ return _leaderboard.apply(this, arguments);
4383
4220
  }
4384
- return getUserPlyGameHistory;
4221
+ return leaderboard;
4385
4222
  }()
4386
4223
  /**
4387
- * Get current jackpot amount
4224
+ * current number of slots under a referral code being used that exceed minimum deposit amount
4388
4225
  */
4389
4226
  ;
4390
- _proto.currentJackpotAmount =
4227
+ _proto.slotsInUse =
4391
4228
  /*#__PURE__*/
4392
4229
  function () {
4393
- var _currentJackpotAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
4394
- var jackpot;
4395
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4396
- while (1) switch (_context3.prev = _context3.next) {
4230
+ var _slotsInUse = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
4231
+ var result;
4232
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4233
+ while (1) switch (_context7.prev = _context7.next) {
4397
4234
  case 0:
4398
- _context3.next = 2;
4399
- return this.env.plygame.currentJackpotAmount();
4235
+ _context7.next = 2;
4236
+ return getApi('/referral/slotsInUse');
4400
4237
  case 2:
4401
- jackpot = _context3.sent;
4402
- return _context3.abrupt("return", new TokenAmount(this.plyToken, jackpot.toString()));
4238
+ result = _context7.sent;
4239
+ return _context7.abrupt("return", result);
4403
4240
  case 4:
4404
4241
  case "end":
4405
- return _context3.stop();
4242
+ return _context7.stop();
4406
4243
  }
4407
- }, _callee3, this);
4244
+ }, _callee7);
4408
4245
  }));
4409
- function currentJackpotAmount() {
4410
- return _currentJackpotAmount.apply(this, arguments);
4246
+ function slotsInUse() {
4247
+ return _slotsInUse.apply(this, arguments);
4411
4248
  }
4412
- return currentJackpotAmount;
4249
+ return slotsInUse;
4413
4250
  }();
4414
- _proto.earlyUnlockedPulpAmount = /*#__PURE__*/function () {
4415
- var _earlyUnlockedPulpAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(user) {
4416
- var earlyUnlockedPulpAmount;
4417
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4418
- while (1) switch (_context4.prev = _context4.next) {
4251
+ _proto.totalReferralSlots = function totalReferralSlots() {
4252
+ return 500;
4253
+ };
4254
+ _proto.queuePosition = /*#__PURE__*/function () {
4255
+ var _queuePosition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(address) {
4256
+ var result;
4257
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4258
+ while (1) switch (_context8.prev = _context8.next) {
4419
4259
  case 0:
4420
- _context4.next = 2;
4421
- return this.env.plygame.totalPlyUnlockedEarly(user);
4260
+ _context8.next = 2;
4261
+ return getApi('/referral/queuePosition', {
4262
+ address: address
4263
+ });
4422
4264
  case 2:
4423
- earlyUnlockedPulpAmount = _context4.sent;
4424
- return _context4.abrupt("return", new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString()));
4265
+ result = _context8.sent;
4266
+ return _context8.abrupt("return", result);
4425
4267
  case 4:
4426
4268
  case "end":
4427
- return _context4.stop();
4269
+ return _context8.stop();
4428
4270
  }
4429
- }, _callee4, this);
4271
+ }, _callee8);
4430
4272
  }));
4431
- function earlyUnlockedPulpAmount(_x3) {
4432
- return _earlyUnlockedPulpAmount.apply(this, arguments);
4273
+ function queuePosition(_x7) {
4274
+ return _queuePosition.apply(this, arguments);
4433
4275
  }
4434
- return earlyUnlockedPulpAmount;
4435
- }();
4436
- _proto.getPlyGameResultsInTransaction = /*#__PURE__*/function () {
4437
- var _getPlyGameResultsInTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(txHash) {
4438
- var _this3 = this;
4439
- var tx, i, filter, betMadeEvents;
4440
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4441
- while (1) switch (_context5.prev = _context5.next) {
4276
+ return queuePosition;
4277
+ }()
4278
+ /**
4279
+ * a way to determine qualification status of a user. null if not referred yet,
4280
+ * qualified if referred + min deposit, notQualified if referred + min deposit
4281
+ * not reached or withdrew too early
4282
+ */
4283
+ ;
4284
+ _proto.userReferralStatus =
4285
+ /*#__PURE__*/
4286
+ function () {
4287
+ var _userReferralStatus = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(userAddr) {
4288
+ var result;
4289
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
4290
+ while (1) switch (_context9.prev = _context9.next) {
4442
4291
  case 0:
4443
- _context5.next = 2;
4444
- return this._networkConnection.provider.getTransactionReceipt(txHash);
4292
+ _context9.next = 2;
4293
+ return getApi('/referral/referralStatus', {
4294
+ address: userAddr
4295
+ });
4445
4296
  case 2:
4446
- tx = _context5.sent;
4447
- i = 0;
4448
- case 4:
4449
- if (!(i < 100 && !tx)) {
4450
- _context5.next = 13;
4451
- break;
4452
- }
4453
- _context5.next = 7;
4454
- return sleep(1000);
4297
+ result = _context9.sent;
4298
+ _context9.t0 = result;
4299
+ _context9.next = _context9.t0 === -1 ? 6 : _context9.t0 === 0 ? 7 : _context9.t0 === 1 ? 8 : 9;
4300
+ break;
4301
+ case 6:
4302
+ return _context9.abrupt("return", 'notReferred');
4455
4303
  case 7:
4456
- _context5.next = 9;
4457
- return this._networkConnection.provider.getTransactionReceipt(txHash);
4304
+ return _context9.abrupt("return", 'notQualified');
4305
+ case 8:
4306
+ return _context9.abrupt("return", 'Qualified');
4458
4307
  case 9:
4459
- tx = _context5.sent;
4308
+ return _context9.abrupt("return", 'Withdrawn');
4460
4309
  case 10:
4461
- i++;
4462
- _context5.next = 4;
4463
- break;
4464
- case 13:
4465
- if (tx) {
4466
- _context5.next = 15;
4467
- break;
4468
- }
4469
- throw new Error("Transaction " + txHash + " takes too long to be mined");
4470
- case 15:
4471
- filter = this.env.plygame.filters.BetMade();
4472
- betMadeEvents = tx.logs.filter(function (log) {
4473
- return isSameAddress(log.topics[0], filter.topics[0]);
4474
- }).map(function (log) {
4475
- return _extends({}, _this3.env.plygame["interface"].parseLog(log), {
4476
- blockNumber: tx.blockNumber,
4477
- transactionHash: txHash
4478
- });
4479
- });
4480
- return _context5.abrupt("return", this.attachTimestamp(betMadeEvents.map(function (e) {
4481
- return _this3.parseBetMakeEvent(e);
4482
- })));
4483
- case 18:
4484
4310
  case "end":
4485
- return _context5.stop();
4311
+ return _context9.stop();
4486
4312
  }
4487
- }, _callee5, this);
4313
+ }, _callee9);
4488
4314
  }));
4489
- function getPlyGameResultsInTransaction(_x4) {
4490
- return _getPlyGameResultsInTransaction.apply(this, arguments);
4315
+ function userReferralStatus(_x8) {
4316
+ return _userReferralStatus.apply(this, arguments);
4491
4317
  }
4492
- return getPlyGameResultsInTransaction;
4493
- }()
4494
- /**
4495
- * Top 100 users by amount of PULP unlocked
4496
- */
4497
- ;
4498
- _proto.leaderboard =
4499
- /*#__PURE__*/
4500
- function () {
4501
- var _leaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
4502
- var _this4 = this;
4318
+ return userReferralStatus;
4319
+ }();
4320
+ _proto.isWhitelistedAddress = /*#__PURE__*/function () {
4321
+ var _isWhitelistedAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(address) {
4503
4322
  var result;
4504
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4505
- while (1) switch (_context6.prev = _context6.next) {
4323
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
4324
+ while (1) switch (_context10.prev = _context10.next) {
4506
4325
  case 0:
4507
- _context6.next = 2;
4508
- return getPaginatedApi('/plygame/leaderboard');
4326
+ _context10.next = 2;
4327
+ return this.env.referralDirectoryV2.isUserWhitelisted(address);
4509
4328
  case 2:
4510
- result = _context6.sent;
4511
- return _context6.abrupt("return", result.items.map(function (item, i) {
4512
- return {
4513
- player: item.user,
4514
- unlockedPulpAmount: new TokenAmount(_this4.pulpToken, item.unlockedAmount),
4515
- gamesPlayed: item.count
4516
- };
4517
- }));
4329
+ result = _context10.sent;
4330
+ return _context10.abrupt("return", result.eq(1));
4518
4331
  case 4:
4519
4332
  case "end":
4520
- return _context6.stop();
4333
+ return _context10.stop();
4521
4334
  }
4522
- }, _callee6);
4335
+ }, _callee10, this);
4523
4336
  }));
4524
- function leaderboard() {
4525
- return _leaderboard.apply(this, arguments);
4337
+ function isWhitelistedAddress(_x9) {
4338
+ return _isWhitelistedAddress.apply(this, arguments);
4526
4339
  }
4527
- return leaderboard;
4340
+ return isWhitelistedAddress;
4528
4341
  }();
4529
- _proto.getLastJackpotResult = /*#__PURE__*/function () {
4530
- var _getLastJackpotResult = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
4531
- var round, result;
4532
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4533
- while (1) switch (_context7.prev = _context7.next) {
4342
+ _proto.isOnAuroraPlus = /*#__PURE__*/function () {
4343
+ var _isOnAuroraPlus = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(address) {
4344
+ var resp;
4345
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
4346
+ while (1) switch (_context11.prev = _context11.next) {
4534
4347
  case 0:
4535
- _context7.t0 = ethers.BigNumber;
4536
- _context7.next = 3;
4537
- return this._networkConnection.provider.getStorageAt(this.env.plygame.address, 158);
4538
- case 3:
4539
- _context7.t1 = _context7.sent;
4540
- round = _context7.t0.from.call(_context7.t0, _context7.t1);
4541
- _context7.next = 7;
4542
- return this.env.plygame.jackpotHistory(round.sub(1));
4543
- case 7:
4544
- result = _context7.sent;
4545
- return _context7.abrupt("return", {
4546
- winner: result.winner.slice(0, 5) + '...' + result.winner.slice(-3),
4547
- amount: new TokenAmount(this.plyToken, result.amount.toString())
4348
+ _context11.next = 2;
4349
+ return axios.get(AURORA_PLUS_API_PREFIX + address);
4350
+ case 2:
4351
+ resp = _context11.sent;
4352
+ return _context11.abrupt("return", resp.data.status == 'active');
4353
+ case 4:
4354
+ case "end":
4355
+ return _context11.stop();
4356
+ }
4357
+ }, _callee11);
4358
+ }));
4359
+ function isOnAuroraPlus(_x10) {
4360
+ return _isOnAuroraPlus.apply(this, arguments);
4361
+ }
4362
+ return isOnAuroraPlus;
4363
+ }();
4364
+ _proto.isNewUserAtReferralTime = /*#__PURE__*/function () {
4365
+ var _isNewUserAtReferralTime = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(address) {
4366
+ var result;
4367
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
4368
+ while (1) switch (_context12.prev = _context12.next) {
4369
+ case 0:
4370
+ _context12.next = 2;
4371
+ return getApi('/referral/isNewUser', {
4372
+ address: address
4548
4373
  });
4549
- case 9:
4374
+ case 2:
4375
+ result = _context12.sent;
4376
+ return _context12.abrupt("return", result);
4377
+ case 4:
4550
4378
  case "end":
4551
- return _context7.stop();
4379
+ return _context12.stop();
4552
4380
  }
4553
- }, _callee7, this);
4381
+ }, _callee12);
4554
4382
  }));
4555
- function getLastJackpotResult() {
4556
- return _getLastJackpotResult.apply(this, arguments);
4383
+ function isNewUserAtReferralTime(_x11) {
4384
+ return _isNewUserAtReferralTime.apply(this, arguments);
4557
4385
  }
4558
- return getLastJackpotResult;
4386
+ return isNewUserAtReferralTime;
4559
4387
  }();
4560
- _proto.overallLeaderboard = /*#__PURE__*/function () {
4561
- var _overallLeaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
4562
- var _this5 = this;
4388
+ _proto.depositedMoreThanMinimumAmount = /*#__PURE__*/function () {
4389
+ var _depositedMoreThanMinimumAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(address) {
4563
4390
  var result;
4564
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4565
- while (1) switch (_context8.prev = _context8.next) {
4391
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
4392
+ while (1) switch (_context13.prev = _context13.next) {
4566
4393
  case 0:
4567
- _context8.next = 2;
4568
- return getPaginatedApi('/plygame/overallLeaderboard');
4394
+ _context13.next = 2;
4395
+ return getApi('/referral/depositedEnough', {
4396
+ address: address
4397
+ });
4569
4398
  case 2:
4570
- result = _context8.sent;
4571
- return _context8.abrupt("return", result.items.map(function (item) {
4572
- return {
4573
- player: item.user,
4574
- unlockedPulpAmount: new TokenAmount(_this5.pulpToken, item.unlockedAmount),
4575
- gamesPlayed: item.count
4576
- };
4577
- }));
4399
+ result = _context13.sent;
4400
+ return _context13.abrupt("return", result);
4578
4401
  case 4:
4579
4402
  case "end":
4580
- return _context8.stop();
4403
+ return _context13.stop();
4581
4404
  }
4582
- }, _callee8);
4405
+ }, _callee13);
4583
4406
  }));
4584
- function overallLeaderboard() {
4585
- return _overallLeaderboard.apply(this, arguments);
4407
+ function depositedMoreThanMinimumAmount(_x12) {
4408
+ return _depositedMoreThanMinimumAmount.apply(this, arguments);
4586
4409
  }
4587
- return overallLeaderboard;
4410
+ return depositedMoreThanMinimumAmount;
4588
4411
  }();
4589
- return PlyGameRead;
4412
+ return ReferralRead;
4590
4413
  }(BlockchainEntityRead);
4591
- var PlyGameReadWrite = /*#__PURE__*/function (_PlyGameRead) {
4592
- _inheritsLoose(PlyGameReadWrite, _PlyGameRead);
4593
- function PlyGameReadWrite() {
4594
- return _PlyGameRead.apply(this, arguments) || this;
4414
+ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
4415
+ _inheritsLoose(ReferralReadWrite, _ReferralRead);
4416
+ function ReferralReadWrite() {
4417
+ return _ReferralRead.apply(this, arguments) || this;
4595
4418
  }
4596
- var _proto2 = PlyGameReadWrite.prototype;
4419
+ var _proto2 = ReferralReadWrite.prototype;
4597
4420
  /**
4598
- * Make a single bet
4421
+ * Generate a referral code for a given address.
4422
+ *
4423
+ * Called when an user want to creates his own referral code
4599
4424
  */
4600
- _proto2.makeBetOnce =
4425
+ _proto2.registerNewReferralCode =
4601
4426
  /*#__PURE__*/
4602
4427
  function () {
4603
- var _makeBetOnce = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(amount) {
4604
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
4605
- while (1) switch (_context9.prev = _context9.next) {
4428
+ var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
4429
+ var referralCode;
4430
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
4431
+ while (1) switch (_context14.prev = _context14.next) {
4606
4432
  case 0:
4607
- return _context9.abrupt("return", this.env.plygame.connect(this._networkConnection.signer).makeBetOnce(amount.rawAmount()));
4608
- case 1:
4433
+ referralCode = ethers.ethers.utils.formatBytes32String(this.generateReferralCode());
4434
+ return _context14.abrupt("return", this.env.referralDirectoryV2.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
4435
+ case 2:
4609
4436
  case "end":
4610
- return _context9.stop();
4437
+ return _context14.stop();
4611
4438
  }
4612
- }, _callee9, this);
4439
+ }, _callee14, this);
4613
4440
  }));
4614
- function makeBetOnce(_x5) {
4615
- return _makeBetOnce.apply(this, arguments);
4441
+ function registerNewReferralCode() {
4442
+ return _registerNewReferralCode.apply(this, arguments);
4616
4443
  }
4617
- return makeBetOnce;
4618
- }();
4619
- _proto2.approve = /*#__PURE__*/function () {
4620
- var _approve = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(amount) {
4621
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
4622
- while (1) switch (_context10.prev = _context10.next) {
4444
+ return registerNewReferralCode;
4445
+ }()
4446
+ /**
4447
+ * Called when an user confirms he is referred by a specified code
4448
+ */
4449
+ ;
4450
+ _proto2.useReferralCode =
4451
+ /*#__PURE__*/
4452
+ function () {
4453
+ var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(code) {
4454
+ var referralCode;
4455
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
4456
+ while (1) switch (_context15.prev = _context15.next) {
4623
4457
  case 0:
4624
- return _context10.abrupt("return", this.env.ply.connect(this._networkConnection.signer).approve(this.env.plygame.address, amount.rawAmount()));
4625
- case 1:
4458
+ referralCode = ethers.ethers.utils.formatBytes32String(code);
4459
+ return _context15.abrupt("return", this.env.referralDirectoryV2.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
4460
+ case 2:
4626
4461
  case "end":
4627
- return _context10.stop();
4462
+ return _context15.stop();
4628
4463
  }
4629
- }, _callee10, this);
4464
+ }, _callee15, this);
4630
4465
  }));
4631
- function approve(_x6) {
4632
- return _approve.apply(this, arguments);
4466
+ function useReferralCode(_x13) {
4467
+ return _useReferralCode.apply(this, arguments);
4633
4468
  }
4634
- return approve;
4469
+ return useReferralCode;
4470
+ }()
4471
+ /**
4472
+ * Claim all unclaimed rewards for a given user
4473
+ */
4474
+ ;
4475
+ _proto2.claimReferralRewards =
4476
+ /*#__PURE__*/
4477
+ function () {
4478
+ var _claimReferralRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
4479
+ var unclaimedRewards, campaigns, tokens;
4480
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
4481
+ while (1) switch (_context16.prev = _context16.next) {
4482
+ case 0:
4483
+ _context16.t0 = this;
4484
+ _context16.next = 3;
4485
+ return this._networkConnection.signer.getAddress();
4486
+ case 3:
4487
+ _context16.t1 = _context16.sent;
4488
+ _context16.next = 6;
4489
+ return _context16.t0.referralRewards.call(_context16.t0, _context16.t1);
4490
+ case 6:
4491
+ unclaimedRewards = _context16.sent.filter(function (reward) {
4492
+ return reward.transactionHash == null;
4493
+ });
4494
+ campaigns = unclaimedRewards.map(function (reward) {
4495
+ return reward.campaign;
4496
+ });
4497
+ tokens = unclaimedRewards.map(function (reward) {
4498
+ return reward.rewardTokenAmount.token.address;
4499
+ });
4500
+ return _context16.abrupt("return", new AirdropReadWrite(this._networkConnection).redeemMultiple(campaigns, tokens));
4501
+ case 10:
4502
+ case "end":
4503
+ return _context16.stop();
4504
+ }
4505
+ }, _callee16, this);
4506
+ }));
4507
+ function claimReferralRewards() {
4508
+ return _claimReferralRewards.apply(this, arguments);
4509
+ }
4510
+ return claimReferralRewards;
4635
4511
  }();
4636
- return PlyGameReadWrite;
4637
- }(PlyGameRead);
4638
- var PlyGame = /*#__PURE__*/function (_BlockchainEntity) {
4639
- _inheritsLoose(PlyGame, _BlockchainEntity);
4640
- function PlyGame() {
4512
+ return ReferralReadWrite;
4513
+ }(ReferralRead);
4514
+ var Referral = /*#__PURE__*/function (_BlockchainEntity) {
4515
+ _inheritsLoose(Referral, _BlockchainEntity);
4516
+ function Referral() {
4641
4517
  return _BlockchainEntity.call(this) || this;
4642
4518
  }
4643
- var _proto3 = PlyGame.prototype;
4519
+ var _proto3 = Referral.prototype;
4644
4520
  _proto3.read = function read(networkConnection) {
4645
- return new PlyGameRead(networkConnection);
4521
+ return new ReferralRead(networkConnection);
4646
4522
  };
4647
4523
  _proto3.readWrite = function readWrite(networkConnection) {
4648
- return new PlyGameReadWrite(networkConnection);
4524
+ return new ReferralReadWrite(networkConnection);
4649
4525
  };
4650
- return PlyGame;
4526
+ return Referral;
4651
4527
  }(BlockchainEntity);
4652
4528
 
4653
- var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4654
- _inheritsLoose(ReferralRead, _BlockchainEntityRead);
4655
- function ReferralRead(networkConnection) {
4529
+ var StakingRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4530
+ _inheritsLoose(StakingRead, _BlockchainEntityRead);
4531
+ function StakingRead(networkConnection) {
4656
4532
  var _this;
4657
4533
  _this = _BlockchainEntityRead.call(this, networkConnection) || this;
4658
4534
  _this.env = new AuriEnv(networkConnection);
4659
4535
  return _this;
4660
4536
  }
4661
- /**
4662
- * Generate a 10-character referral code
4663
- * containing alphanumeric characters.
4664
- */
4665
- var _proto = ReferralRead.prototype;
4666
- _proto.generateReferralCode = function generateReferralCode() {
4667
- var letters = 'abcdefghijklmnopqrstuvwxyz';
4668
- var numbers = '1234567890';
4669
- var charset = letters + letters.toUpperCase() + numbers;
4670
- var R = '';
4671
- for (var i = 0; i < 10; i++) R += charset[Math.floor(Math.random() * charset.length)];
4672
- return R;
4673
- }
4674
- /**
4675
- * Get the referral code for a given address, returns empty string if not found.
4676
- *
4677
- * Called to check if a user has a referral code.
4678
- */;
4679
- _proto.getUserReferralCode =
4680
- /*#__PURE__*/
4681
- function () {
4682
- var _getUserReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(userAddr) {
4683
- var result;
4537
+ var _proto = StakingRead.prototype;
4538
+ _proto.getPLYWNEARPoolDetails = /*#__PURE__*/function () {
4539
+ var _getPLYWNEARPoolDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4540
+ var stakedLiquidity, rewardPerSeconds, stakedLiquidityAmount, totalStakeValuation, promises, i, rewardTokenAddress, rewardToken, rewardPerSecond, APYs;
4684
4541
  return _regeneratorRuntime().wrap(function _callee$(_context) {
4685
4542
  while (1) switch (_context.prev = _context.next) {
4686
4543
  case 0:
4687
4544
  _context.next = 2;
4688
- return this.env.referralDirectoryV2.userReferralCode(userAddr);
4545
+ return this.env.auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then(function (res) {
4546
+ stakedLiquidity = res.totalStake;
4547
+ rewardPerSeconds = res.rewardPerSeconds;
4548
+ });
4689
4549
  case 2:
4690
- result = _context.sent;
4691
- return _context.abrupt("return", ethers.ethers.utils.parseBytes32String(result));
4692
- case 4:
4550
+ stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity.toString());
4551
+ _context.next = 5;
4552
+ return fetchValuation(stakedLiquidityAmount, this._networkConnection.provider);
4553
+ case 5:
4554
+ totalStakeValuation = _context.sent;
4555
+ promises = []; // Calculate the reward per second in USD
4556
+ for (i = 0; i < rewardPerSeconds.length; i++) {
4557
+ rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
4558
+ rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
4559
+ rewardPerSecond = rewardPerSeconds[i];
4560
+ promises.push(fetchValuation(new TokenAmount(rewardToken, rewardPerSecond.toString()), this._networkConnection.provider));
4561
+ }
4562
+ APYs = [];
4563
+ _context.next = 11;
4564
+ return Promise.all(promises);
4565
+ case 11:
4566
+ _context.sent.forEach(function (rewardPerSecondValuation, i) {
4567
+ var rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
4568
+ var apy = calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION);
4569
+ APYs.push({
4570
+ address: rewardTokenAddress,
4571
+ apy: apy
4572
+ });
4573
+ });
4574
+ return _context.abrupt("return", {
4575
+ totalStakedLiquidity: stakedLiquidityAmount,
4576
+ APYs: APYs
4577
+ });
4578
+ case 13:
4693
4579
  case "end":
4694
4580
  return _context.stop();
4695
4581
  }
4696
4582
  }, _callee, this);
4697
4583
  }));
4698
- function getUserReferralCode(_x) {
4699
- return _getUserReferralCode.apply(this, arguments);
4584
+ function getPLYWNEARPoolDetails() {
4585
+ return _getPLYWNEARPoolDetails.apply(this, arguments);
4700
4586
  }
4701
- return getUserReferralCode;
4587
+ return getPLYWNEARPoolDetails;
4702
4588
  }()
4703
4589
  /**
4704
- * Get referral code that a user was referred by, returns empty string if not found.
4590
+ * Get amount of staked LP tokens
4705
4591
  */
4706
4592
  ;
4707
- _proto.getReferralCodeUsed =
4593
+ _proto.stakeBalanceOf =
4708
4594
  /*#__PURE__*/
4709
4595
  function () {
4710
- var _getReferralCodeUsed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(userAddr) {
4711
- var result;
4596
+ var _stakeBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(user) {
4597
+ var userInfo;
4712
4598
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4713
4599
  while (1) switch (_context2.prev = _context2.next) {
4714
4600
  case 0:
4715
4601
  _context2.next = 2;
4716
- return this.env.referralDirectoryV2.referralCodeUsed(userAddr);
4602
+ return this.env.auriFairLaunch.getUserInfo(PLYWNEAR_POOL_ID, user);
4717
4603
  case 2:
4718
- result = _context2.sent;
4719
- return _context2.abrupt("return", ethers.ethers.utils.parseBytes32String(result));
4604
+ userInfo = _context2.sent;
4605
+ return _context2.abrupt("return", new TokenAmount(PLYWNEARToken, userInfo.amount.toString()));
4720
4606
  case 4:
4721
4607
  case "end":
4722
4608
  return _context2.stop();
4723
4609
  }
4724
4610
  }, _callee2, this);
4725
4611
  }));
4726
- function getReferralCodeUsed(_x2) {
4727
- return _getReferralCodeUsed.apply(this, arguments);
4612
+ function stakeBalanceOf(_x) {
4613
+ return _stakeBalanceOf.apply(this, arguments);
4728
4614
  }
4729
- return getReferralCodeUsed;
4615
+ return stakeBalanceOf;
4730
4616
  }()
4731
4617
  /**
4732
- * Get owner of a referral code, returns zero address if not found.
4618
+ * Get amount of LP token in user wallet
4733
4619
  */
4734
4620
  ;
4735
- _proto.getReferralCodeOwner =
4621
+ _proto.LpBalanceOf =
4736
4622
  /*#__PURE__*/
4737
4623
  function () {
4738
- var _getReferralCodeOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(code) {
4739
- var referralCode;
4624
+ var _LpBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(user) {
4625
+ var lpContract, balance;
4740
4626
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4741
4627
  while (1) switch (_context3.prev = _context3.next) {
4742
4628
  case 0:
4743
- referralCode = ethers.ethers.utils.formatBytes32String(code);
4744
- return _context3.abrupt("return", this.env.referralDirectoryV2.referralCodeOwner(referralCode));
4745
- case 2:
4629
+ lpContract = new ethers.Contract(networkAddresses.tokens.PLYWNEAR, abis$8.abi, this._networkConnection.provider);
4630
+ _context3.next = 3;
4631
+ return lpContract.balanceOf(user);
4632
+ case 3:
4633
+ balance = _context3.sent;
4634
+ return _context3.abrupt("return", new TokenAmount(PLYWNEARToken, balance.toString()));
4635
+ case 5:
4746
4636
  case "end":
4747
4637
  return _context3.stop();
4748
4638
  }
4749
4639
  }, _callee3, this);
4750
4640
  }));
4751
- function getReferralCodeOwner(_x3) {
4752
- return _getReferralCodeOwner.apply(this, arguments);
4641
+ function LpBalanceOf(_x2) {
4642
+ return _LpBalanceOf.apply(this, arguments);
4753
4643
  }
4754
- return getReferralCodeOwner;
4755
- }()
4756
- /**
4757
- * Get referrals of a user, sorted descending by timestamp.
4758
- */
4759
- ;
4760
- _proto.getReferralsList =
4761
- /*#__PURE__*/
4762
- function () {
4763
- var _getReferralsList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(userAddr) {
4764
- var result, blocks, blocksTimestamp, items;
4644
+ return LpBalanceOf;
4645
+ }();
4646
+ _proto.unclaimedRewardsOf = /*#__PURE__*/function () {
4647
+ var _unclaimedRewardsOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(user) {
4648
+ var userInfo, rewards;
4765
4649
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4766
4650
  while (1) switch (_context4.prev = _context4.next) {
4767
4651
  case 0:
4768
4652
  _context4.next = 2;
4769
- return getPaginatedApi('/referral/list', {
4770
- address: userAddr
4653
+ return this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(PLYWNEAR_POOL_ID, user, {
4654
+ from: user
4771
4655
  });
4772
4656
  case 2:
4773
- result = _context4.sent;
4774
- blocks = result.items.map(function (item) {
4775
- return item.blockNumber;
4776
- });
4777
- _context4.next = 6;
4778
- return getBlocksTimestamp(this._networkConnection.provider, blocks);
4779
- case 6:
4780
- blocksTimestamp = _context4.sent;
4781
- items = result.items.map(function (item, i) {
4782
- return {
4783
- user: item.user,
4784
- timestamp: blocksTimestamp[i]
4785
- };
4786
- });
4787
- return _context4.abrupt("return", items);
4788
- case 9:
4657
+ userInfo = _context4.sent;
4658
+ rewards = userInfo.unclaimedRewards;
4659
+ return _context4.abrupt("return", rewards.map(function (reward, i) {
4660
+ return TokenAmount.fromAddressAndAmount(PLYWNEAR_REWARD_TOKENS[i], reward.toString());
4661
+ }));
4662
+ case 5:
4789
4663
  case "end":
4790
4664
  return _context4.stop();
4791
4665
  }
4792
4666
  }, _callee4, this);
4793
4667
  }));
4794
- function getReferralsList(_x4) {
4795
- return _getReferralsList.apply(this, arguments);
4668
+ function unclaimedRewardsOf(_x3) {
4669
+ return _unclaimedRewardsOf.apply(this, arguments);
4796
4670
  }
4797
- return getReferralsList;
4798
- }()
4799
- /**
4800
- * Array of rewards, sorted by time of the referral period (from latest to oldest)
4801
- */
4802
- ;
4803
- _proto.referralRewards =
4804
- /*#__PURE__*/
4805
- function () {
4806
- var _referralRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(userAddr) {
4807
- var result, items;
4671
+ return unclaimedRewardsOf;
4672
+ }();
4673
+ return StakingRead;
4674
+ }(BlockchainEntityRead);
4675
+ var StakingReadWrite = /*#__PURE__*/function (_StakingRead) {
4676
+ _inheritsLoose(StakingReadWrite, _StakingRead);
4677
+ function StakingReadWrite() {
4678
+ return _StakingRead.apply(this, arguments) || this;
4679
+ }
4680
+ var _proto2 = StakingReadWrite.prototype;
4681
+ _proto2.stake = /*#__PURE__*/function () {
4682
+ var _stake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(amount) {
4808
4683
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4809
4684
  while (1) switch (_context5.prev = _context5.next) {
4810
4685
  case 0:
4811
- _context5.next = 2;
4812
- return getPaginatedApi('/referral/rewards', {
4813
- address: userAddr
4814
- });
4815
- case 2:
4816
- result = _context5.sent;
4817
- items = result.items.map(function (item, i) {
4818
- var _item$transactionHash;
4819
- return {
4820
- campaign: item.campaign,
4821
- userAddr: userAddr,
4822
- isReferrer: item.campaign.includes('referrer'),
4823
- rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
4824
- startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
4825
- endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
4826
- transactionHash: (_item$transactionHash = item.transactionHash) != null ? _item$transactionHash : null,
4827
- refereeAddress: null
4828
- };
4829
- });
4830
- return _context5.abrupt("return", items);
4831
- case 5:
4686
+ return _context5.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).deposit(PLYWNEAR_POOL_ID, amount.rawAmount()));
4687
+ case 1:
4832
4688
  case "end":
4833
4689
  return _context5.stop();
4834
4690
  }
4835
- }, _callee5);
4691
+ }, _callee5, this);
4836
4692
  }));
4837
- function referralRewards(_x5) {
4838
- return _referralRewards.apply(this, arguments);
4693
+ function stake(_x4) {
4694
+ return _stake.apply(this, arguments);
4839
4695
  }
4840
- return referralRewards;
4841
- }()
4842
- /**
4843
- * Top 50 reward earners from the last round, sorted by token amount
4844
- */
4845
- ;
4846
- _proto.leaderboard =
4847
- /*#__PURE__*/
4848
- function () {
4849
- var _leaderboard = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(campaign) {
4850
- var result, items;
4696
+ return stake;
4697
+ }();
4698
+ _proto2.unstake = /*#__PURE__*/function () {
4699
+ var _unstake = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(amount) {
4700
+ var msgSender, amountInput, stakedAmount, unstakeAmount;
4851
4701
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4852
4702
  while (1) switch (_context6.prev = _context6.next) {
4853
4703
  case 0:
4854
4704
  _context6.next = 2;
4855
- return getPaginatedApi('/referral/leaderboard', {
4856
- campaign: campaign
4857
- });
4705
+ return this._networkConnection.signer.getAddress();
4858
4706
  case 2:
4859
- result = _context6.sent;
4860
- items = result.items.map(function (item, i) {
4861
- return {
4862
- campaign: campaign,
4863
- userAddr: item.user,
4864
- isReferrer: item.campaign.includes('referrer'),
4865
- rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
4866
- startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
4867
- endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
4868
- transactionHash: null,
4869
- refereeAddress: null
4870
- };
4871
- });
4872
- items.sort(function (a, b) {
4873
- return b.rewardTokenAmount.compare(a.rewardTokenAmount);
4874
- });
4875
- return _context6.abrupt("return", items);
4876
- case 6:
4707
+ msgSender = _context6.sent;
4708
+ amountInput = ethers.BigNumber.from(amount.rawAmount());
4709
+ _context6.t0 = ethers.BigNumber;
4710
+ _context6.next = 7;
4711
+ return this.stakeBalanceOf(msgSender);
4712
+ case 7:
4713
+ _context6.t1 = _context6.sent.rawAmount();
4714
+ stakedAmount = _context6.t0.from.call(_context6.t0, _context6.t1);
4715
+ // unstakeAmount = min(amountInput, stakedAmount - 1)
4716
+ unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
4717
+ return _context6.abrupt("return", this.env.auriFairLaunch.connect(this._networkConnection.signer).withdraw(PLYWNEAR_POOL_ID, unstakeAmount));
4718
+ case 11:
4877
4719
  case "end":
4878
4720
  return _context6.stop();
4879
4721
  }
4880
- }, _callee6);
4722
+ }, _callee6, this);
4881
4723
  }));
4882
- function leaderboard(_x6) {
4883
- return _leaderboard.apply(this, arguments);
4724
+ function unstake(_x5) {
4725
+ return _unstake.apply(this, arguments);
4884
4726
  }
4885
- return leaderboard;
4886
- }()
4727
+ return unstake;
4728
+ }();
4729
+ return StakingReadWrite;
4730
+ }(StakingRead);
4731
+ var Staking = /*#__PURE__*/function (_BlockchainEntity) {
4732
+ _inheritsLoose(Staking, _BlockchainEntity);
4733
+ function Staking() {
4734
+ return _BlockchainEntity.call(this) || this;
4735
+ }
4736
+ var _proto3 = Staking.prototype;
4737
+ _proto3.read = function read(networkConnection) {
4738
+ return new StakingRead(networkConnection);
4739
+ };
4740
+ _proto3.readWrite = function readWrite(networkConnection) {
4741
+ return new StakingReadWrite(networkConnection);
4742
+ };
4743
+ return Staking;
4744
+ }(BlockchainEntity);
4745
+
4746
+ (function (ComptrollerRewardType) {
4747
+ ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
4748
+ ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
4749
+ })(exports.ComptrollerRewardType || (exports.ComptrollerRewardType = {}));
4750
+ (function (MarketAction) {
4751
+ MarketAction[MarketAction["Deposit"] = 0] = "Deposit";
4752
+ MarketAction[MarketAction["Borrow"] = 1] = "Borrow";
4753
+ MarketAction[MarketAction["Withdraw"] = 2] = "Withdraw";
4754
+ MarketAction[MarketAction["Repay"] = 3] = "Repay";
4755
+ MarketAction[MarketAction["EnableCollateral"] = 4] = "EnableCollateral";
4756
+ MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
4757
+ })(exports.MarketAction || (exports.MarketAction = {}));
4758
+
4759
+ var MulticallRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4760
+ _inheritsLoose(MulticallRead, _BlockchainEntityRead);
4761
+ function MulticallRead(networkConnection) {
4762
+ var _this;
4763
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
4764
+ _this.multicall = new ethers.Contract(networkAddresses.misc.MULTICALL, abis$a.abi, networkConnection.provider);
4765
+ return _this;
4766
+ }
4887
4767
  /**
4888
- * current number of slots under a referral code being used that exceed minimum deposit amount
4768
+ * Run multiple calls via multicall contract
4889
4769
  */
4890
- ;
4891
- _proto.slotsInUse =
4770
+ var _proto = MulticallRead.prototype;
4771
+ _proto.aggregate =
4892
4772
  /*#__PURE__*/
4893
4773
  function () {
4894
- var _slotsInUse = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
4895
- var result;
4896
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4897
- while (1) switch (_context7.prev = _context7.next) {
4774
+ var _aggregate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(calls) {
4775
+ var txns, i, _call$contract$popula, call, txn, response, decodedReturn, _i;
4776
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4777
+ while (1) switch (_context.prev = _context.next) {
4898
4778
  case 0:
4899
- _context7.next = 2;
4900
- return getApi('/referral/slotsInUse');
4779
+ txns = []; // prepare transactions
4780
+ i = 0;
4901
4781
  case 2:
4902
- result = _context7.sent;
4903
- return _context7.abrupt("return", result);
4782
+ if (!(i < calls.length)) {
4783
+ _context.next = 11;
4784
+ break;
4785
+ }
4786
+ call = calls[i];
4787
+ _context.next = 6;
4788
+ return (_call$contract$popula = call.contract.populateTransaction)[call.method].apply(_call$contract$popula, call.args);
4789
+ case 6:
4790
+ txn = _context.sent;
4791
+ txns.push({
4792
+ target: txn.to,
4793
+ callData: txn.data
4794
+ });
4795
+ case 8:
4796
+ i++;
4797
+ _context.next = 2;
4798
+ break;
4799
+ case 11:
4800
+ _context.next = 13;
4801
+ return this.multicall.callStatic.aggregate(txns);
4802
+ case 13:
4803
+ response = _context.sent;
4804
+ // parse results
4805
+ decodedReturn = [];
4806
+ for (_i = 0; _i < calls.length; _i++) {
4807
+ decodedReturn.push(ethers.ethers.utils.defaultAbiCoder.decode(calls[_i].returnTypes, response.returnData[_i]));
4808
+ }
4809
+ return _context.abrupt("return", decodedReturn);
4810
+ case 17:
4811
+ case "end":
4812
+ return _context.stop();
4813
+ }
4814
+ }, _callee, this);
4815
+ }));
4816
+ function aggregate(_x) {
4817
+ return _aggregate.apply(this, arguments);
4818
+ }
4819
+ return aggregate;
4820
+ }();
4821
+ return MulticallRead;
4822
+ }(BlockchainEntityRead);
4823
+
4824
+ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4825
+ _inheritsLoose(MiscRead, _BlockchainEntityRead);
4826
+ function MiscRead(networkConnection) {
4827
+ var _this;
4828
+ _this = _BlockchainEntityRead.call(this, networkConnection) || this;
4829
+ _this.stakingRead = new StakingRead(networkConnection);
4830
+ _this.env = new AuriEnv(networkConnection);
4831
+ return _this;
4832
+ }
4833
+ var _proto = MiscRead.prototype;
4834
+ _proto.getUserDetails = /*#__PURE__*/function () {
4835
+ var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(userAddress) {
4836
+ var marketCount, userMarketDetails, assetsIn, totalBorrowLimit, _iterator, _step, _auToken, userMarketDetail, _moneyMarket, _yield$Promise$all, depositBalance, borrowBalance, collateralRatio, underlyingPrice, depositValues, _loop, i, accountLiquidity, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, borrowLimitMargin, maxWithdrawCap;
4837
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
4838
+ while (1) switch (_context2.prev = _context2.next) {
4839
+ case 0:
4840
+ marketCount = networkAddresses.auTokens.length;
4841
+ userMarketDetails = [];
4842
+ totalBorrowLimit = new BigNumber(0);
4843
+ _iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens);
4904
4844
  case 4:
4845
+ if ((_step = _iterator()).done) {
4846
+ _context2.next = 23;
4847
+ break;
4848
+ }
4849
+ _auToken = _step.value;
4850
+ userMarketDetail = {};
4851
+ userMarketDetails.push(userMarketDetail);
4852
+ userMarketDetail.market = _auToken.underlying;
4853
+ _moneyMarket = new MoneyMarketRead(this._networkConnection, _auToken.address, _auToken.underlying);
4854
+ _context2.next = 12;
4855
+ return Promise.all([_moneyMarket.getUserDepositBalance(userAddress), _moneyMarket.getUserBorrowBalance(userAddress), _moneyMarket.getCollateralRatio(), fetchPrice(_moneyMarket.underlying.address, this._networkConnection.provider)]);
4856
+ case 12:
4857
+ _yield$Promise$all = _context2.sent;
4858
+ depositBalance = _yield$Promise$all[0];
4859
+ borrowBalance = _yield$Promise$all[1];
4860
+ collateralRatio = _yield$Promise$all[2];
4861
+ underlyingPrice = _yield$Promise$all[3];
4862
+ userMarketDetail.depositBalance = depositBalance;
4863
+ userMarketDetail.borrowBalance = borrowBalance;
4864
+ userMarketDetail.collateralRatio = collateralRatio.toNumber();
4865
+ userMarketDetail.underlyingPrice = underlyingPrice.toString();
4866
+ case 21:
4867
+ _context2.next = 4;
4868
+ break;
4869
+ case 23:
4870
+ _context2.next = 25;
4871
+ return this.env.comptroller.getAssetsIn(userAddress);
4872
+ case 25:
4873
+ assetsIn = _context2.sent;
4874
+ depositValues = [];
4875
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
4876
+ var auToken;
4877
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
4878
+ while (1) switch (_context.prev = _context.next) {
4879
+ case 0:
4880
+ auToken = networkAddresses.auTokens[i];
4881
+ if (assetsIn.find(function (auAddress) {
4882
+ return isSameAddress(auToken.address, auAddress);
4883
+ }) !== undefined) {
4884
+ userMarketDetails[i].isCollateral = true;
4885
+ } else {
4886
+ userMarketDetails[i].isCollateral = false;
4887
+ }
4888
+ depositValues.push(calcValuation(userMarketDetails[i].depositBalance, new BigNumber(userMarketDetails[i].underlyingPrice)));
4889
+ case 3:
4890
+ case "end":
4891
+ return _context.stop();
4892
+ }
4893
+ }, _loop);
4894
+ });
4895
+ i = 0;
4896
+ case 29:
4897
+ if (!(i < marketCount)) {
4898
+ _context2.next = 34;
4899
+ break;
4900
+ }
4901
+ return _context2.delegateYield(_loop(), "t0", 31);
4902
+ case 31:
4903
+ i++;
4904
+ _context2.next = 29;
4905
+ break;
4906
+ case 34:
4907
+ totalBorrowLimit = depositValues.reduce(function (p, v, index) {
4908
+ if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
4909
+ return p;
4910
+ }, new BigNumber(0));
4911
+ _context2.next = 37;
4912
+ return this.env.comptroller.getAccountLiquidity(userAddress);
4913
+ case 37:
4914
+ accountLiquidity = _context2.sent;
4915
+ borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
4916
+ if (borrowedvaluation.lt('0.00001')) {
4917
+ // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
4918
+ borrowedvaluation = new BigNumber(0);
4919
+ }
4920
+ bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
4921
+ minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
4922
+ if (bufferedBorrowLimit.lte(borrowedvaluation)) {
4923
+ borrowableAmount = new BigNumber(0);
4924
+ } else {
4925
+ borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
4926
+ }
4927
+ for (i = 0; i < marketCount; i++) {
4928
+ auToken = networkAddresses.auTokens[i];
4929
+ moneyMarket = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
4930
+ borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
4931
+ maxWithdrawCap = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(userMarketDetails[i].underlyingPrice);
4932
+ 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());
4933
+ }
4934
+ _context2.t1 = userMarketDetails;
4935
+ _context2.t2 = {
4936
+ currency: 'USD',
4937
+ amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
4938
+ };
4939
+ _context2.next = 48;
4940
+ return new PapermillRead(this._networkConnection).getLockingDetails(userAddress);
4941
+ case 48:
4942
+ _context2.t3 = _context2.sent;
4943
+ _context2.t4 = {
4944
+ currency: 'USD',
4945
+ amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
4946
+ };
4947
+ return _context2.abrupt("return", {
4948
+ markets: _context2.t1,
4949
+ borrowLimit: _context2.t2,
4950
+ userLockingDetails: _context2.t3,
4951
+ borrowableAmount: _context2.t4
4952
+ });
4953
+ case 51:
4905
4954
  case "end":
4906
- return _context7.stop();
4955
+ return _context2.stop();
4907
4956
  }
4908
- }, _callee7);
4957
+ }, _callee, this);
4909
4958
  }));
4910
- function slotsInUse() {
4911
- return _slotsInUse.apply(this, arguments);
4959
+ function getUserDetails(_x) {
4960
+ return _getUserDetails.apply(this, arguments);
4912
4961
  }
4913
- return slotsInUse;
4962
+ return getUserDetails;
4914
4963
  }();
4915
- _proto.totalReferralSlots = function totalReferralSlots() {
4916
- return 500;
4917
- };
4918
- _proto.queuePosition = /*#__PURE__*/function () {
4919
- var _queuePosition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(address) {
4920
- var result;
4921
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4922
- while (1) switch (_context8.prev = _context8.next) {
4964
+ _proto.getTokenPrice = /*#__PURE__*/function () {
4965
+ var _getTokenPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
4966
+ var price;
4967
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
4968
+ while (1) switch (_context3.prev = _context3.next) {
4923
4969
  case 0:
4924
- _context8.next = 2;
4925
- return getApi('/referral/queuePosition', {
4926
- address: address
4927
- });
4970
+ _context3.next = 2;
4971
+ return fetchPrice(token.address, this._networkConnection.provider);
4928
4972
  case 2:
4929
- result = _context8.sent;
4930
- return _context8.abrupt("return", result);
4973
+ price = _context3.sent;
4974
+ return _context3.abrupt("return", {
4975
+ currency: 'USD',
4976
+ amount: price.toFixed(DECIMAL_PRECISION)
4977
+ });
4931
4978
  case 4:
4932
4979
  case "end":
4933
- return _context8.stop();
4980
+ return _context3.stop();
4934
4981
  }
4935
- }, _callee8);
4982
+ }, _callee2, this);
4936
4983
  }));
4937
- function queuePosition(_x7) {
4938
- return _queuePosition.apply(this, arguments);
4984
+ function getTokenPrice(_x2) {
4985
+ return _getTokenPrice.apply(this, arguments);
4939
4986
  }
4940
- return queuePosition;
4941
- }()
4987
+ return getTokenPrice;
4988
+ }();
4989
+ _proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
4990
+ var userMarketDetail = _ref.userMarketDetail,
4991
+ currentBorrowLimit = _ref.currentBorrowLimit,
4992
+ currentBorrowValuation = _ref.currentBorrowValuation,
4993
+ action = _ref.action,
4994
+ tokenAmount = _ref.tokenAmount;
4995
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
4996
+ newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
4997
+ switch (action) {
4998
+ case exports.MarketAction.EnableCollateral:
4999
+ case exports.MarketAction.DisableCollateral:
5000
+ var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
5001
+ newBorrowLimit = action == exports.MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
5002
+ break;
5003
+ case exports.MarketAction.Deposit:
5004
+ case exports.MarketAction.Withdraw:
5005
+ deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
5006
+ newBorrowLimit = action == exports.MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
5007
+ break;
5008
+ case exports.MarketAction.Borrow:
5009
+ case exports.MarketAction.Repay:
5010
+ var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
5011
+ newBorrowValuation = action == exports.MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
5012
+ break;
5013
+ }
5014
+ return {
5015
+ newBorrowLimit: {
5016
+ amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
5017
+ currency: 'USD'
5018
+ },
5019
+ newBorrowUtilization: newBorrowLimit.eq(0) ? newBorrowValuation.eq(0) ? 0 : 9999.99 : newBorrowValuation.div(newBorrowLimit).toNumber()
5020
+ };
5021
+ }
4942
5022
  /**
4943
- * a way to determine qualification status of a user. null if not referred yet,
4944
- * qualified if referred + min deposit, notQualified if referred + min deposit
4945
- * not reached or withdrew too early
4946
- */
4947
- ;
4948
- _proto.userReferralStatus =
5023
+ * Get ply circulating supply.
5024
+ * It is calculated by the total supply, minus:
5025
+ * - Ply in team multisig contract
5026
+ * - Ply in comptroller contract
5027
+ * - Ply in fairlaunch contract
5028
+ * - Ply in vesting contract
5029
+ */;
5030
+ _proto.getPlyCirculatingSupply =
4949
5031
  /*#__PURE__*/
4950
5032
  function () {
4951
- var _userReferralStatus = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(userAddr) {
4952
- var result;
4953
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
4954
- while (1) switch (_context9.prev = _context9.next) {
5033
+ var _getPlyCirculatingSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
5034
+ var multicallRead, baseBalanceOfCall, listAddrs, calls, callResults, circulatingSupply;
5035
+ return _regeneratorRuntime().wrap(function _callee3$(_context4) {
5036
+ while (1) switch (_context4.prev = _context4.next) {
4955
5037
  case 0:
4956
- _context9.next = 2;
4957
- return getApi('/referral/referralStatus', {
4958
- address: userAddr
5038
+ multicallRead = new MulticallRead(this._networkConnection);
5039
+ baseBalanceOfCall = {
5040
+ contract: this.env.ply,
5041
+ method: 'balanceOf',
5042
+ returnTypes: ['uint256']
5043
+ };
5044
+ listAddrs = [networkAddresses.misc.TEAM_MULTISIG, networkAddresses.misc.COMPTROLLER, networkAddresses.misc.AURIFAIRLAUNCH, networkAddresses.misc.PLY_TOKEN_LOCK, networkAddresses.misc.TEAM_MULTISIG_AURORA_PLUS, networkAddresses.misc.AURORA_PLUS, networkAddresses.misc.PULP_CONTRACT];
5045
+ calls = listAddrs.map(function (addr) {
5046
+ return _extends({}, baseBalanceOfCall, {
5047
+ args: [addr]
5048
+ });
4959
5049
  });
4960
- case 2:
4961
- result = _context9.sent;
4962
- _context9.t0 = result;
4963
- _context9.next = _context9.t0 === -1 ? 6 : _context9.t0 === 0 ? 7 : _context9.t0 === 1 ? 8 : 9;
4964
- break;
5050
+ _context4.next = 6;
5051
+ return multicallRead.aggregate(calls);
4965
5052
  case 6:
4966
- return _context9.abrupt("return", 'notReferred');
4967
- case 7:
4968
- return _context9.abrupt("return", 'notQualified');
4969
- case 8:
4970
- return _context9.abrupt("return", 'Qualified');
4971
- case 9:
4972
- return _context9.abrupt("return", 'Withdrawn');
4973
- case 10:
4974
- case "end":
4975
- return _context9.stop();
4976
- }
4977
- }, _callee9);
4978
- }));
4979
- function userReferralStatus(_x8) {
4980
- return _userReferralStatus.apply(this, arguments);
4981
- }
4982
- return userReferralStatus;
4983
- }();
4984
- _proto.isWhitelistedAddress = /*#__PURE__*/function () {
4985
- var _isWhitelistedAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(address) {
4986
- var result;
4987
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
4988
- while (1) switch (_context10.prev = _context10.next) {
4989
- case 0:
4990
- _context10.next = 2;
4991
- return this.env.referralDirectoryV2.isUserWhitelisted(address);
4992
- case 2:
4993
- result = _context10.sent;
4994
- return _context10.abrupt("return", result.eq(1));
4995
- case 4:
4996
- case "end":
4997
- return _context10.stop();
4998
- }
4999
- }, _callee10, this);
5000
- }));
5001
- function isWhitelistedAddress(_x9) {
5002
- return _isWhitelistedAddress.apply(this, arguments);
5003
- }
5004
- return isWhitelistedAddress;
5005
- }();
5006
- _proto.isOnAuroraPlus = /*#__PURE__*/function () {
5007
- var _isOnAuroraPlus = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(address) {
5008
- var resp;
5009
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
5010
- while (1) switch (_context11.prev = _context11.next) {
5011
- case 0:
5012
- _context11.next = 2;
5013
- return axios.get(AURORA_PLUS_API_PREFIX + address);
5014
- case 2:
5015
- resp = _context11.sent;
5016
- return _context11.abrupt("return", resp.data.status == 'active');
5017
- case 4:
5018
- case "end":
5019
- return _context11.stop();
5020
- }
5021
- }, _callee11);
5022
- }));
5023
- function isOnAuroraPlus(_x10) {
5024
- return _isOnAuroraPlus.apply(this, arguments);
5025
- }
5026
- return isOnAuroraPlus;
5027
- }();
5028
- _proto.isNewUserAtReferralTime = /*#__PURE__*/function () {
5029
- var _isNewUserAtReferralTime = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(address) {
5030
- var result;
5031
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
5032
- while (1) switch (_context12.prev = _context12.next) {
5033
- case 0:
5034
- _context12.next = 2;
5035
- return getApi('/referral/isNewUser', {
5036
- address: address
5053
+ callResults = _context4.sent;
5054
+ circulatingSupply = ethers.BigNumber.from('1' + '0'.repeat(10) + '0'.repeat(getDecimal(this.env.ply.address)));
5055
+ callResults.forEach(function (result, i) {
5056
+ circulatingSupply = circulatingSupply.sub(result[0]);
5037
5057
  });
5038
- case 2:
5039
- result = _context12.sent;
5040
- return _context12.abrupt("return", result);
5041
- case 4:
5058
+ return _context4.abrupt("return", new TokenAmount(PLYToken, circulatingSupply.toString()));
5059
+ case 10:
5042
5060
  case "end":
5043
- return _context12.stop();
5061
+ return _context4.stop();
5044
5062
  }
5045
- }, _callee12);
5063
+ }, _callee3, this);
5046
5064
  }));
5047
- function isNewUserAtReferralTime(_x11) {
5048
- return _isNewUserAtReferralTime.apply(this, arguments);
5065
+ function getPlyCirculatingSupply() {
5066
+ return _getPlyCirculatingSupply.apply(this, arguments);
5049
5067
  }
5050
- return isNewUserAtReferralTime;
5068
+ return getPlyCirculatingSupply;
5051
5069
  }();
5052
- _proto.depositedMoreThanMinimumAmount = /*#__PURE__*/function () {
5053
- var _depositedMoreThanMinimumAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(address) {
5054
- var result;
5055
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
5056
- while (1) switch (_context13.prev = _context13.next) {
5070
+ _proto.getUtilisation = /*#__PURE__*/function () {
5071
+ var _getUtilisation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(userAddr) {
5072
+ var accountDetail, sumBorrow, sumCol;
5073
+ return _regeneratorRuntime().wrap(function _callee4$(_context5) {
5074
+ while (1) switch (_context5.prev = _context5.next) {
5057
5075
  case 0:
5058
- _context13.next = 2;
5059
- return getApi('/referral/depositedEnough', {
5060
- address: address
5061
- });
5076
+ _context5.next = 2;
5077
+ return this.env.auriInternalLens.callStatic.getAccountLiquidityAccrueInterest(userAddr);
5062
5078
  case 2:
5063
- result = _context13.sent;
5064
- return _context13.abrupt("return", result);
5065
- case 4:
5079
+ accountDetail = _context5.sent;
5080
+ sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
5081
+ sumCol = new BigNumber(accountDetail.sumCollateral.toString());
5082
+ return _context5.abrupt("return", sumBorrow.dividedBy(sumCol));
5083
+ case 6:
5066
5084
  case "end":
5067
- return _context13.stop();
5085
+ return _context5.stop();
5068
5086
  }
5069
- }, _callee13);
5087
+ }, _callee4, this);
5070
5088
  }));
5071
- function depositedMoreThanMinimumAmount(_x12) {
5072
- return _depositedMoreThanMinimumAmount.apply(this, arguments);
5089
+ function getUtilisation(_x3) {
5090
+ return _getUtilisation.apply(this, arguments);
5073
5091
  }
5074
- return depositedMoreThanMinimumAmount;
5092
+ return getUtilisation;
5075
5093
  }();
5076
- return ReferralRead;
5077
- }(BlockchainEntityRead);
5078
- var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
5079
- _inheritsLoose(ReferralReadWrite, _ReferralRead);
5080
- function ReferralReadWrite() {
5081
- return _ReferralRead.apply(this, arguments) || this;
5082
- }
5083
- var _proto2 = ReferralReadWrite.prototype;
5084
- /**
5085
- * Generate a referral code for a given address.
5086
- *
5087
- * Called when an user want to creates his own referral code
5088
- */
5089
- _proto2.registerNewReferralCode =
5090
- /*#__PURE__*/
5091
- function () {
5092
- var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
5093
- var referralCode;
5094
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
5095
- while (1) switch (_context14.prev = _context14.next) {
5094
+ _proto.sneakAccounts = /*#__PURE__*/function () {
5095
+ var _sneakAccounts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(accounts, tokenAddresses, dust) {
5096
+ var _this2 = this;
5097
+ var _1E18, oracle, tokens, prices, exrate, res, _iterator2, _step2, addr, infos, i, snapshot, bal, bor, balR, borR;
5098
+ return _regeneratorRuntime().wrap(function _callee5$(_context6) {
5099
+ while (1) switch (_context6.prev = _context6.next) {
5096
5100
  case 0:
5097
- referralCode = ethers.ethers.utils.formatBytes32String(this.generateReferralCode());
5098
- return _context14.abrupt("return", this.env.referralDirectoryV2.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
5099
- case 2:
5101
+ if (dust === void 0) {
5102
+ dust = /*#__PURE__*/new BigNumber(0.1);
5103
+ }
5104
+ _1E18 = ethers.BigNumber.from(10).pow(18);
5105
+ oracle = this.env.getContract(networkAddresses.misc.oracle, AuriOracleABI.abi);
5106
+ tokens = tokenAddresses.map(function (addr) {
5107
+ return _this2.env.getContract(addr, abis$5.abi);
5108
+ });
5109
+ _context6.next = 6;
5110
+ return oracle.getUnderlyingPrices(tokenAddresses);
5111
+ case 6:
5112
+ prices = _context6.sent;
5113
+ _context6.next = 9;
5114
+ return this.env.auriInternalLens.callStatic.getExchangeRates(tokenAddresses);
5115
+ case 9:
5116
+ exrate = _context6.sent;
5117
+ res = [];
5118
+ _iterator2 = _createForOfIteratorHelperLoose(accounts);
5119
+ case 12:
5120
+ if ((_step2 = _iterator2()).done) {
5121
+ _context6.next = 33;
5122
+ break;
5123
+ }
5124
+ addr = _step2.value;
5125
+ infos = [];
5126
+ i = 0;
5127
+ case 16:
5128
+ if (!(i < tokens.length)) {
5129
+ _context6.next = 30;
5130
+ break;
5131
+ }
5132
+ _context6.next = 19;
5133
+ return tokens[i].getAccountSnapshot(addr);
5134
+ case 19:
5135
+ snapshot = _context6.sent;
5136
+ bal = snapshot[0].mul(exrate[i]).div(_1E18).mul(prices[i]).div(_1E18);
5137
+ bor = snapshot[1].mul(prices[i]).div(_1E18);
5138
+ balR = new BigNumber(bal.toString()).dividedBy(_1E18.toString());
5139
+ borR = new BigNumber(bor.toString()).dividedBy(_1E18.toString());
5140
+ if (!(balR.lte(dust) && borR.lte(dust))) {
5141
+ _context6.next = 26;
5142
+ break;
5143
+ }
5144
+ return _context6.abrupt("continue", 27);
5145
+ case 26:
5146
+ infos.push({
5147
+ token: getSymbol(tokenAddresses[i]),
5148
+ deposit: balR,
5149
+ borrow: borR
5150
+ });
5151
+ case 27:
5152
+ ++i;
5153
+ _context6.next = 16;
5154
+ break;
5155
+ case 30:
5156
+ res.push({
5157
+ address: addr,
5158
+ tokens: infos
5159
+ });
5160
+ case 31:
5161
+ _context6.next = 12;
5162
+ break;
5163
+ case 33:
5164
+ return _context6.abrupt("return", res);
5165
+ case 34:
5100
5166
  case "end":
5101
- return _context14.stop();
5167
+ return _context6.stop();
5102
5168
  }
5103
- }, _callee14, this);
5169
+ }, _callee5, this);
5104
5170
  }));
5105
- function registerNewReferralCode() {
5106
- return _registerNewReferralCode.apply(this, arguments);
5171
+ function sneakAccounts(_x4, _x5, _x6) {
5172
+ return _sneakAccounts.apply(this, arguments);
5107
5173
  }
5108
- return registerNewReferralCode;
5109
- }()
5110
- /**
5111
- * Called when an user confirms he is referred by a specified code
5112
- */
5113
- ;
5114
- _proto2.useReferralCode =
5115
- /*#__PURE__*/
5116
- function () {
5117
- var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(code) {
5118
- var referralCode;
5119
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
5120
- while (1) switch (_context15.prev = _context15.next) {
5174
+ return sneakAccounts;
5175
+ }();
5176
+ _proto.getNetApyWithoutIncentive = /*#__PURE__*/function () {
5177
+ var _getNetApyWithoutIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(userAddress) {
5178
+ var _this3 = this;
5179
+ var sum, totalSuppliedValue, totalBorrowedValue, netApy, apys, _iterator3, _step3, apy;
5180
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
5181
+ while (1) switch (_context7.prev = _context7.next) {
5121
5182
  case 0:
5122
- referralCode = ethers.ethers.utils.formatBytes32String(code);
5123
- return _context15.abrupt("return", this.env.referralDirectoryV2.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
5124
- case 2:
5183
+ sum = new BigNumber(0);
5184
+ totalSuppliedValue = new BigNumber(0);
5185
+ totalBorrowedValue = new BigNumber(0);
5186
+ netApy = new BigNumber(0);
5187
+ _context7.next = 6;
5188
+ return Promise.all(networkAddresses.auTokens.map(function (auToken) {
5189
+ var moneyMarket = new MoneyMarketRead(_this3._networkConnection, auToken.address, auToken.underlying);
5190
+ var apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
5191
+ return apyWithoutIncentive;
5192
+ }));
5193
+ case 6:
5194
+ apys = _context7.sent;
5195
+ for (_iterator3 = _createForOfIteratorHelperLoose(apys); !(_step3 = _iterator3()).done;) {
5196
+ apy = _step3.value;
5197
+ sum = sum.plus(apy.sum);
5198
+ totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
5199
+ totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
5200
+ }
5201
+ if (sum.gt(0)) {
5202
+ netApy = sum.div(totalSuppliedValue);
5203
+ } else if (sum.lt(0)) {
5204
+ netApy = sum.div(totalBorrowedValue);
5205
+ }
5206
+ return _context7.abrupt("return", netApy);
5207
+ case 10:
5125
5208
  case "end":
5126
- return _context15.stop();
5209
+ return _context7.stop();
5127
5210
  }
5128
- }, _callee15, this);
5211
+ }, _callee6);
5129
5212
  }));
5130
- function useReferralCode(_x13) {
5131
- return _useReferralCode.apply(this, arguments);
5213
+ function getNetApyWithoutIncentive(_x7) {
5214
+ return _getNetApyWithoutIncentive.apply(this, arguments);
5132
5215
  }
5133
- return useReferralCode;
5134
- }()
5135
- /**
5136
- * Claim all unclaimed rewards for a given user
5137
- */
5138
- ;
5139
- _proto2.claimReferralRewards =
5140
- /*#__PURE__*/
5141
- function () {
5142
- var _claimReferralRewards = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
5143
- var unclaimedRewards, campaigns, tokens;
5144
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
5145
- while (1) switch (_context16.prev = _context16.next) {
5216
+ return getNetApyWithoutIncentive;
5217
+ }();
5218
+ _proto.getNetApyWithIncentive = /*#__PURE__*/function () {
5219
+ var _getNetApyWithIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(userAddress) {
5220
+ var _this4 = this;
5221
+ var sum, totalSuppliedValue, totalBorrowedValue, netApy, apys, _iterator4, _step4, apy;
5222
+ return _regeneratorRuntime().wrap(function _callee7$(_context8) {
5223
+ while (1) switch (_context8.prev = _context8.next) {
5146
5224
  case 0:
5147
- _context16.t0 = this;
5148
- _context16.next = 3;
5149
- return this._networkConnection.signer.getAddress();
5150
- case 3:
5151
- _context16.t1 = _context16.sent;
5152
- _context16.next = 6;
5153
- return _context16.t0.referralRewards.call(_context16.t0, _context16.t1);
5225
+ sum = new BigNumber(0);
5226
+ totalSuppliedValue = new BigNumber(0);
5227
+ totalBorrowedValue = new BigNumber(0);
5228
+ netApy = new BigNumber(0);
5229
+ _context8.next = 6;
5230
+ return Promise.all(networkAddresses.auTokens.map(function (auToken) {
5231
+ var moneyMarket = new MoneyMarketRead(_this4._networkConnection, auToken.address, auToken.underlying);
5232
+ var apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
5233
+ return apyWithIncentive;
5234
+ }));
5154
5235
  case 6:
5155
- unclaimedRewards = _context16.sent.filter(function (reward) {
5156
- return reward.transactionHash == null;
5157
- });
5158
- campaigns = unclaimedRewards.map(function (reward) {
5159
- return reward.campaign;
5160
- });
5161
- tokens = unclaimedRewards.map(function (reward) {
5162
- return reward.rewardTokenAmount.token.address;
5163
- });
5164
- return _context16.abrupt("return", new AirdropReadWrite(this._networkConnection).redeemMultiple(campaigns, tokens));
5236
+ apys = _context8.sent;
5237
+ for (_iterator4 = _createForOfIteratorHelperLoose(apys); !(_step4 = _iterator4()).done;) {
5238
+ apy = _step4.value;
5239
+ sum = sum.plus(apy.sum);
5240
+ totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
5241
+ totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
5242
+ }
5243
+ if (sum.gt(0)) {
5244
+ netApy = sum.div(totalSuppliedValue);
5245
+ } else if (sum.lt(0)) {
5246
+ netApy = sum.div(totalBorrowedValue);
5247
+ }
5248
+ return _context8.abrupt("return", netApy);
5165
5249
  case 10:
5166
5250
  case "end":
5167
- return _context16.stop();
5251
+ return _context8.stop();
5168
5252
  }
5169
- }, _callee16, this);
5253
+ }, _callee7);
5170
5254
  }));
5171
- function claimReferralRewards() {
5172
- return _claimReferralRewards.apply(this, arguments);
5255
+ function getNetApyWithIncentive(_x8) {
5256
+ return _getNetApyWithIncentive.apply(this, arguments);
5173
5257
  }
5174
- return claimReferralRewards;
5258
+ return getNetApyWithIncentive;
5175
5259
  }();
5176
- return ReferralReadWrite;
5177
- }(ReferralRead);
5178
- var Referral = /*#__PURE__*/function (_BlockchainEntity) {
5179
- _inheritsLoose(Referral, _BlockchainEntity);
5180
- function Referral() {
5181
- return _BlockchainEntity.call(this) || this;
5182
- }
5183
- var _proto3 = Referral.prototype;
5184
- _proto3.read = function read(networkConnection) {
5185
- return new ReferralRead(networkConnection);
5186
- };
5187
- _proto3.readWrite = function readWrite(networkConnection) {
5188
- return new ReferralReadWrite(networkConnection);
5189
- };
5190
- return Referral;
5191
- }(BlockchainEntity);
5260
+ return MiscRead;
5261
+ }(BlockchainEntityRead);
5192
5262
 
5193
5263
  var NOTIFICATION_API_END_POINT = 'https://api.aurigami.finance/notification/';
5194
5264
  function postApi(_x3, _x4) {
@@ -5674,6 +5744,9 @@ exports.PapermillReadWrite = PapermillReadWrite;
5674
5744
  exports.PlyGame = PlyGame;
5675
5745
  exports.PlyGameRead = PlyGameRead;
5676
5746
  exports.PlyGameReadWrite = PlyGameReadWrite;
5747
+ exports.Pulp = Pulp;
5748
+ exports.PulpRead = PulpRead;
5749
+ exports.PulpReadWrite = PulpReadWrite;
5677
5750
  exports.REFERRAL_CAMPAIGNS = REFERRAL_CAMPAIGNS;
5678
5751
  exports.REWARD_CLAIM_START = REWARD_CLAIM_START;
5679
5752
  exports.Referral = Referral;