@aurigami/sdk 1.20.7 → 1.21.0

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.
@@ -57,7 +57,8 @@ export declare const networkAddresses: {
57
57
  }];
58
58
  readonly misc: {
59
59
  readonly COMPTROLLER: string;
60
- readonly oracle: string;
60
+ readonly DEPRECATED_OLD_ORACLE: string;
61
+ readonly PYTH_ORACLE: string;
61
62
  readonly AURIFAIRLAUNCH: string;
62
63
  readonly AURILENS: string;
63
64
  readonly ETHREPAYHELPER: string;
@@ -1,4 +1,4 @@
1
- import { AuErc20, AuriAirdrop, AuriFairLaunch, AuriInternalLens, AuriLens, AuriOracle, Comptroller, IERC20, PlyGame, PULP, ReferralDirectoryV2, PlyTokenLock } from '@aurigami/contracts/typechain';
1
+ import { AuErc20, AuriAirdrop, AuriFairLaunch, AuriInternalLens, AuriLens, AuriOracle, Comptroller, IERC20, PULP, PlyGame, PlyTokenLock, ReferralDirectoryV2 } from '@aurigami/contracts/typechain';
2
2
  import { Contract } from 'ethers';
3
3
  import { AuTokenWithUnderlying } from '../types';
4
4
  import { BlockchainEntityRead } from './BlockchainEntity';
@@ -111,7 +111,8 @@ var networkAddresses = {
111
111
  }],
112
112
  misc: {
113
113
  COMPTROLLER: /*#__PURE__*/MAINNET_ADDRESSES.comptroller.toLowerCase(),
114
- oracle: /*#__PURE__*/MAINNET_ADDRESSES.oracle.toLowerCase(),
114
+ DEPRECATED_OLD_ORACLE: /*#__PURE__*/MAINNET_ADDRESSES.oracle.toLowerCase(),
115
+ PYTH_ORACLE: /*#__PURE__*/MAINNET_ADDRESSES.pythOracle.toLowerCase(),
115
116
  AURIFAIRLAUNCH: /*#__PURE__*/MAINNET_ADDRESSES.fairLaunch.toLowerCase(),
116
117
  AURILENS: /*#__PURE__*/MAINNET_ADDRESSES.auriLens.toLowerCase(),
117
118
  ETHREPAYHELPER: /*#__PURE__*/MAINNET_ADDRESSES.ethRepayHelper.toLowerCase(),
@@ -1181,7 +1182,7 @@ var AuriEnv = /*#__PURE__*/function (_BlockchainEntityRead) {
1181
1182
  key: "oracle",
1182
1183
  get: function get() {
1183
1184
  if (!this._oracle) {
1184
- this._oracle = this.getContract(networkAddresses.misc.oracle, AuriOracleABI.abi);
1185
+ this._oracle = this.getContract(networkAddresses.misc.PYTH_ORACLE, AuriOracleABI.abi);
1185
1186
  }
1186
1187
  return this._oracle;
1187
1188
  }
@@ -1814,7 +1815,7 @@ function _fetchPriceFromOracle() {
1814
1815
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1815
1816
  while (1) switch (_context12.prev = _context12.next) {
1816
1817
  case 0:
1817
- oracleContract = new ethers.Contract(networkAddresses.misc.oracle, AuriOracleABI.abi, provider);
1818
+ oracleContract = new ethers.Contract(networkAddresses.misc.PYTH_ORACLE, AuriOracleABI.abi, provider);
1818
1819
  _context12.next = 3;
1819
1820
  return oracleContract.getUnderlyingPrice(auTokenAddress)["catch"](function (e) {
1820
1821
  console.log("Unable to fetch price from oracle for " + auTokenAddress);
@@ -2308,22 +2309,25 @@ function fetchHistoricalPriceFromOracle(_x7, _x8, _x9, _x10) {
2308
2309
  }
2309
2310
  function _fetchHistoricalPriceFromOracle() {
2310
2311
  _fetchHistoricalPriceFromOracle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(auTokenAddress, underlyingDecimal, provider, block) {
2311
- var oracleContract, rawPrice;
2312
+ var oracleAddress, oracleContract, rawPrice;
2312
2313
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2313
2314
  while (1) switch (_context4.prev = _context4.next) {
2314
2315
  case 0:
2315
- oracleContract = new ethers.Contract(networkAddresses.misc.oracle, AuriOracleABI.abi, provider);
2316
- _context4.next = 3;
2316
+ // from this block, we switch to use pyth
2317
+ // TODO: add to consts
2318
+ oracleAddress = block < 102438637 ? networkAddresses.misc.DEPRECATED_OLD_ORACLE : networkAddresses.misc.PYTH_ORACLE;
2319
+ oracleContract = new ethers.Contract(oracleAddress, AuriOracleABI.abi, provider);
2320
+ _context4.next = 4;
2317
2321
  return oracleContract.getUnderlyingPrice(auTokenAddress, {
2318
2322
  blockTag: block
2319
2323
  })["catch"](function (e) {
2320
2324
  console.log("Unable to fetch price from oracle for " + auTokenAddress);
2321
2325
  return ethers.BigNumber.from(0);
2322
2326
  });
2323
- case 3:
2327
+ case 4:
2324
2328
  rawPrice = _context4.sent;
2325
2329
  return _context4.abrupt("return", processPriceFromOracle$1(rawPrice, underlyingDecimal));
2326
- case 5:
2330
+ case 6:
2327
2331
  case "end":
2328
2332
  return _context4.stop();
2329
2333
  }
@@ -2922,38 +2926,15 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2922
2926
  }();
2923
2927
  _proto.getDepositMetaAPY = /*#__PURE__*/function () {
2924
2928
  var _getDepositMetaAPY = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
2925
- var _yield$Promise$all6, totalDeposited, underlyingPrice, depositMETAApy;
2926
2929
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
2927
2930
  while (1) switch (_context13.prev = _context13.next) {
2928
2931
  case 0:
2929
- _context13.next = 2;
2930
- return Promise.all([this.getTotalTokenDeposited(), fetchPrice(this.underlying.address, this._networkConnection.provider)]);
2931
- case 2:
2932
- _yield$Promise$all6 = _context13.sent;
2933
- totalDeposited = _yield$Promise$all6[0];
2934
- underlyingPrice = _yield$Promise$all6[1];
2935
- if (!isSameAddress(this.underlying.address, networkAddresses.tokens.stNEAR)) {
2936
- _context13.next = 14;
2937
- break;
2938
- }
2939
- _context13.t0 = helpers;
2940
- _context13.next = 9;
2941
- return fetchValuation(TokenAmount.fromAddressAndAmount(networkAddresses.tokens.META, '250000', false), this._networkConnection.provider);
2942
- case 9:
2943
- _context13.t1 = _context13.sent;
2944
- _context13.t2 = underlyingPrice.multipliedBy(totalDeposited.formattedAmount());
2945
- depositMETAApy = _context13.t0.calcLMRewardApr.call(_context13.t0, _context13.t1, _context13.t2, 12);
2946
- _context13.next = 15;
2947
- break;
2948
- case 14:
2949
- depositMETAApy = new BigNumber(0);
2950
- case 15:
2951
- return _context13.abrupt("return", depositMETAApy);
2952
- case 16:
2932
+ return _context13.abrupt("return", new BigNumber(0));
2933
+ case 1:
2953
2934
  case "end":
2954
2935
  return _context13.stop();
2955
2936
  }
2956
- }, _callee13, this);
2937
+ }, _callee13);
2957
2938
  }));
2958
2939
  function getDepositMetaAPY() {
2959
2940
  return _getDepositMetaAPY.apply(this, arguments);
@@ -2979,30 +2960,30 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
2979
2960
  }();
2980
2961
  _proto.getDetails = /*#__PURE__*/function () {
2981
2962
  var _getDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
2982
- var _yield$Promise$all7, totalDeposited, totalBorrowed, depositAPY, borrowAPY, collateralRatio, rewardSpeeds, _yield$Promise$all8, depositPlyAPY, borrowPlyAPY, depositNearAPY, borrowNearAPY, depositMetaAPY, staderDepositApy;
2963
+ var _yield$Promise$all6, totalDeposited, totalBorrowed, depositAPY, borrowAPY, collateralRatio, rewardSpeeds, _yield$Promise$all7, depositPlyAPY, borrowPlyAPY, depositNearAPY, borrowNearAPY, depositMetaAPY, staderDepositApy;
2983
2964
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2984
2965
  while (1) switch (_context15.prev = _context15.next) {
2985
2966
  case 0:
2986
2967
  _context15.next = 2;
2987
2968
  return Promise.all([this.getTotalTokenDeposited(), this.getTotalTokenBorrowed(), this.getDepositAPY(), this.getBorrowAPY(), this.getCollateralRatio(), this.getRewardSpeeds()]);
2988
2969
  case 2:
2989
- _yield$Promise$all7 = _context15.sent;
2990
- totalDeposited = _yield$Promise$all7[0];
2991
- totalBorrowed = _yield$Promise$all7[1];
2992
- depositAPY = _yield$Promise$all7[2];
2993
- borrowAPY = _yield$Promise$all7[3];
2994
- collateralRatio = _yield$Promise$all7[4];
2995
- rewardSpeeds = _yield$Promise$all7[5];
2970
+ _yield$Promise$all6 = _context15.sent;
2971
+ totalDeposited = _yield$Promise$all6[0];
2972
+ totalBorrowed = _yield$Promise$all6[1];
2973
+ depositAPY = _yield$Promise$all6[2];
2974
+ borrowAPY = _yield$Promise$all6[3];
2975
+ collateralRatio = _yield$Promise$all6[4];
2976
+ rewardSpeeds = _yield$Promise$all6[5];
2996
2977
  _context15.next = 11;
2997
2978
  return Promise.all([this.getDepositPlyAPY(), this.getBorrowPlyAPY(), this.getDepositNearAPY(), this.getBorrowNearAPY(), this.getDepositMetaAPY(), this.getDepositStaderAPY()]);
2998
2979
  case 11:
2999
- _yield$Promise$all8 = _context15.sent;
3000
- depositPlyAPY = _yield$Promise$all8[0];
3001
- borrowPlyAPY = _yield$Promise$all8[1];
3002
- depositNearAPY = _yield$Promise$all8[2];
3003
- borrowNearAPY = _yield$Promise$all8[3];
3004
- depositMetaAPY = _yield$Promise$all8[4];
3005
- staderDepositApy = _yield$Promise$all8[5];
2980
+ _yield$Promise$all7 = _context15.sent;
2981
+ depositPlyAPY = _yield$Promise$all7[0];
2982
+ borrowPlyAPY = _yield$Promise$all7[1];
2983
+ depositNearAPY = _yield$Promise$all7[2];
2984
+ borrowNearAPY = _yield$Promise$all7[3];
2985
+ depositMetaAPY = _yield$Promise$all7[4];
2986
+ staderDepositApy = _yield$Promise$all7[5];
3006
2987
  return _context15.abrupt("return", {
3007
2988
  auTokenAddress: this.auToken.address,
3008
2989
  totalTokenDeposited: totalDeposited,
@@ -3148,17 +3129,17 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3148
3129
  }();
3149
3130
  _proto.getDepositBorrowValue = /*#__PURE__*/function () {
3150
3131
  var _getDepositBorrowValue = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(userAddress) {
3151
- var _yield$Promise$all9, price, depositBalance, borrowBalance, suppliedValue, borrowedValue;
3132
+ var _yield$Promise$all8, price, depositBalance, borrowBalance, suppliedValue, borrowedValue;
3152
3133
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3153
3134
  while (1) switch (_context20.prev = _context20.next) {
3154
3135
  case 0:
3155
3136
  _context20.next = 2;
3156
3137
  return Promise.all([this.getUnderlyingPrice(), this.getUserDepositBalance(userAddress), this.getUserBorrowBalance(userAddress)]);
3157
3138
  case 2:
3158
- _yield$Promise$all9 = _context20.sent;
3159
- price = _yield$Promise$all9[0];
3160
- depositBalance = _yield$Promise$all9[1];
3161
- borrowBalance = _yield$Promise$all9[2];
3139
+ _yield$Promise$all8 = _context20.sent;
3140
+ price = _yield$Promise$all8[0];
3141
+ depositBalance = _yield$Promise$all8[1];
3142
+ borrowBalance = _yield$Promise$all8[2];
3162
3143
  suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
3163
3144
  borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
3164
3145
  return _context20.abrupt("return", {
@@ -3178,19 +3159,19 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3178
3159
  }();
3179
3160
  _proto.getApyWithoutIncentive = /*#__PURE__*/function () {
3180
3161
  var _getApyWithoutIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(userAddress) {
3181
- var _yield$Promise$all10, price, depositApy, borrowApy, depositBalance, borrowBalance, suppliedValue, borrowedValue, sum;
3162
+ var _yield$Promise$all9, price, depositApy, borrowApy, depositBalance, borrowBalance, suppliedValue, borrowedValue, sum;
3182
3163
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3183
3164
  while (1) switch (_context21.prev = _context21.next) {
3184
3165
  case 0:
3185
3166
  _context21.next = 2;
3186
3167
  return Promise.all([this.getUnderlyingPrice(), this.getDepositAPY(), this.getBorrowAPY(), this.getUserDepositBalance(userAddress), this.getUserBorrowBalance(userAddress)]);
3187
3168
  case 2:
3188
- _yield$Promise$all10 = _context21.sent;
3189
- price = _yield$Promise$all10[0];
3190
- depositApy = _yield$Promise$all10[1];
3191
- borrowApy = _yield$Promise$all10[2];
3192
- depositBalance = _yield$Promise$all10[3];
3193
- borrowBalance = _yield$Promise$all10[4];
3169
+ _yield$Promise$all9 = _context21.sent;
3170
+ price = _yield$Promise$all9[0];
3171
+ depositApy = _yield$Promise$all9[1];
3172
+ borrowApy = _yield$Promise$all9[2];
3173
+ depositBalance = _yield$Promise$all9[3];
3174
+ borrowBalance = _yield$Promise$all9[4];
3194
3175
  suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
3195
3176
  borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
3196
3177
  sum = calcNetApy(suppliedValue, depositApy, borrowedValue, borrowApy);
@@ -3212,24 +3193,24 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3212
3193
  }();
3213
3194
  _proto.getApyWithIncentive = /*#__PURE__*/function () {
3214
3195
  var _getApyWithIncentive = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(userAddress) {
3215
- var _yield$Promise$all11, price, depositApy, borrowApy, depositBalance, borrowBalance, nearDepositApy, plyDepositApy, metaDepositApy, nearBorrowApy, plyBorrowApy, staderDepositApy, suppliedValue, borrowedValue, totalDepositApy, totalBorrowApy, sum;
3196
+ var _yield$Promise$all10, price, depositApy, borrowApy, depositBalance, borrowBalance, nearDepositApy, plyDepositApy, metaDepositApy, nearBorrowApy, plyBorrowApy, staderDepositApy, suppliedValue, borrowedValue, totalDepositApy, totalBorrowApy, sum;
3216
3197
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3217
3198
  while (1) switch (_context22.prev = _context22.next) {
3218
3199
  case 0:
3219
3200
  _context22.next = 2;
3220
3201
  return Promise.all([this.getUnderlyingPrice(), this.getDepositAPY(), this.getBorrowAPY(), this.getUserDepositBalance(userAddress), this.getUserBorrowBalance(userAddress), this.getDepositNearAPY(), this.getDepositPlyAPY(), this.getDepositMetaAPY(), this.getBorrowNearAPY(), this.getBorrowPlyAPY()]);
3221
3202
  case 2:
3222
- _yield$Promise$all11 = _context22.sent;
3223
- price = _yield$Promise$all11[0];
3224
- depositApy = _yield$Promise$all11[1];
3225
- borrowApy = _yield$Promise$all11[2];
3226
- depositBalance = _yield$Promise$all11[3];
3227
- borrowBalance = _yield$Promise$all11[4];
3228
- nearDepositApy = _yield$Promise$all11[5];
3229
- plyDepositApy = _yield$Promise$all11[6];
3230
- metaDepositApy = _yield$Promise$all11[7];
3231
- nearBorrowApy = _yield$Promise$all11[8];
3232
- plyBorrowApy = _yield$Promise$all11[9];
3203
+ _yield$Promise$all10 = _context22.sent;
3204
+ price = _yield$Promise$all10[0];
3205
+ depositApy = _yield$Promise$all10[1];
3206
+ borrowApy = _yield$Promise$all10[2];
3207
+ depositBalance = _yield$Promise$all10[3];
3208
+ borrowBalance = _yield$Promise$all10[4];
3209
+ nearDepositApy = _yield$Promise$all10[5];
3210
+ plyDepositApy = _yield$Promise$all10[6];
3211
+ metaDepositApy = _yield$Promise$all10[7];
3212
+ nearBorrowApy = _yield$Promise$all10[8];
3213
+ plyBorrowApy = _yield$Promise$all10[9];
3233
3214
  _context22.next = 15;
3234
3215
  return this.getDepositStaderAPY();
3235
3216
  case 15:
@@ -5363,7 +5344,7 @@ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
5363
5344
  dust = /*#__PURE__*/new BigNumber(0.1);
5364
5345
  }
5365
5346
  _1E18 = ethers.BigNumber.from(10).pow(18);
5366
- oracle = this.env.getContract(networkAddresses.misc.oracle, AuriOracleABI.abi);
5347
+ oracle = this.env.oracle;
5367
5348
  tokens = tokenAddresses.map(function (addr) {
5368
5349
  return _this2.env.getContract(addr, abis$5.abi);
5369
5350
  });