@aurigami/sdk 1.4.1 → 1.4.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.
package/dist/sdk.esm.js CHANGED
@@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
2
2
  import { BigNumber as BigNumber$1, utils, Contract, ethers } from 'ethers';
3
3
  import { Logger } from 'ethers/lib/utils';
4
4
  import { Signer } from '@ethersproject/abstract-signer';
5
- import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
5
+ import fetch from 'node-fetch';
6
6
  import AuErc20ABI from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
7
7
  import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
8
8
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
@@ -52,6 +52,24 @@ function _asyncToGenerator(fn) {
52
52
  };
53
53
  }
54
54
 
55
+ function _extends() {
56
+ _extends = Object.assign || function (target) {
57
+ for (var i = 1; i < arguments.length; i++) {
58
+ var source = arguments[i];
59
+
60
+ for (var key in source) {
61
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
62
+ target[key] = source[key];
63
+ }
64
+ }
65
+ }
66
+
67
+ return target;
68
+ };
69
+
70
+ return _extends.apply(this, arguments);
71
+ }
72
+
55
73
  function _inheritsLoose(subClass, superClass) {
56
74
  subClass.prototype = Object.create(superClass.prototype);
57
75
  subClass.prototype.constructor = subClass;
@@ -999,6 +1017,52 @@ var DEPOSIT_NEAR_REWARDS_PER_WEEK = /*#__PURE__*/Object.fromEntries( /*#__PURE__
999
1017
  }));
1000
1018
  var BORROW_NEAR_REWARDS_PER_WEEK = {};
1001
1019
 
1020
+ var AURORA_API_BASE_URL = 'https://api.aurorascan.dev/api';
1021
+ function getQuery(_x, _x2, _x3) {
1022
+ return _getQuery.apply(this, arguments);
1023
+ }
1024
+
1025
+ function _getQuery() {
1026
+ _getQuery = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(module, action, params) {
1027
+ var resp;
1028
+ return runtime_1.wrap(function _callee$(_context) {
1029
+ while (1) {
1030
+ switch (_context.prev = _context.next) {
1031
+ case 0:
1032
+ if (params === void 0) {
1033
+ params = {};
1034
+ }
1035
+
1036
+ params = _extends({}, params, {
1037
+ 'module': module,
1038
+ 'action': action
1039
+ });
1040
+ _context.next = 4;
1041
+ return fetch(AURORA_API_BASE_URL + '?' + new URLSearchParams(params), {
1042
+ headers: {
1043
+ 'Content-Type': 'application/json'
1044
+ },
1045
+ method: 'GET'
1046
+ });
1047
+
1048
+ case 4:
1049
+ resp = _context.sent;
1050
+ _context.next = 7;
1051
+ return resp.json();
1052
+
1053
+ case 7:
1054
+ return _context.abrupt("return", _context.sent.result);
1055
+
1056
+ case 8:
1057
+ case "end":
1058
+ return _context.stop();
1059
+ }
1060
+ }
1061
+ }, _callee);
1062
+ }));
1063
+ return _getQuery.apply(this, arguments);
1064
+ }
1065
+
1002
1066
  var decimalRecords = {
1003
1067
  '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
1004
1068
  '0x981bd5832eab9c8f607940e0e9facbf8c09ee20a': 18,
@@ -1044,40 +1108,6 @@ function validateAndParseAddress(address) {
1044
1108
  function getDecimal(address) {
1045
1109
  return decimalRecords[address.toLowerCase()];
1046
1110
  }
1047
- function getDecimalsViaContract(_x, _x2) {
1048
- return _getDecimalsViaContract.apply(this, arguments);
1049
- }
1050
-
1051
- function _getDecimalsViaContract() {
1052
- _getDecimalsViaContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(address, provider) {
1053
- var result, token;
1054
- return runtime_1.wrap(function _callee$(_context) {
1055
- while (1) {
1056
- switch (_context.prev = _context.next) {
1057
- case 0:
1058
- result = getDecimal(address);
1059
-
1060
- if (!result) {
1061
- _context.next = 3;
1062
- break;
1063
- }
1064
-
1065
- return _context.abrupt("return", result);
1066
-
1067
- case 3:
1068
- token = new Contract(address, EIP20InterfaceABI.abi, provider);
1069
- return _context.abrupt("return", token.decimals());
1070
-
1071
- case 5:
1072
- case "end":
1073
- return _context.stop();
1074
- }
1075
- }
1076
- }, _callee);
1077
- }));
1078
- return _getDecimalsViaContract.apply(this, arguments);
1079
- }
1080
-
1081
1111
  function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1082
1112
  if (totalStakeValue.lte(0)) {
1083
1113
  return new BigNumber('999999999');
@@ -1085,113 +1115,75 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1085
1115
 
1086
1116
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
1087
1117
  }
1088
- function getBlockTimestamp(_x3, _x4) {
1118
+ function getBlockTimestamp(_x, _x2) {
1089
1119
  return _getBlockTimestamp.apply(this, arguments);
1090
1120
  }
1091
1121
 
1092
1122
  function _getBlockTimestamp() {
1093
- _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, blockNumber) {
1123
+ _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
1094
1124
  var block;
1095
- return runtime_1.wrap(function _callee2$(_context2) {
1125
+ return runtime_1.wrap(function _callee$(_context) {
1096
1126
  while (1) {
1097
- switch (_context2.prev = _context2.next) {
1127
+ switch (_context.prev = _context.next) {
1098
1128
  case 0:
1099
- _context2.next = 2;
1129
+ _context.next = 2;
1100
1130
  return provider.getBlock(blockNumber);
1101
1131
 
1102
1132
  case 2:
1103
- block = _context2.sent;
1104
- return _context2.abrupt("return", block.timestamp);
1133
+ block = _context.sent;
1134
+ return _context.abrupt("return", block.timestamp);
1105
1135
 
1106
1136
  case 4:
1107
1137
  case "end":
1108
- return _context2.stop();
1138
+ return _context.stop();
1109
1139
  }
1110
1140
  }
1111
- }, _callee2);
1141
+ }, _callee);
1112
1142
  }));
1113
1143
  return _getBlockTimestamp.apply(this, arguments);
1114
1144
  }
1115
1145
 
1116
- function getBlockBeforeTimestamp(_x5, _x6, _x7) {
1146
+ function getBlockBeforeTimestamp(_x3, _x4) {
1117
1147
  return _getBlockBeforeTimestamp.apply(this, arguments);
1118
1148
  }
1119
1149
 
1120
1150
  function _getBlockBeforeTimestamp() {
1121
- _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider, timestamp, startBlock) {
1122
- var blockThreshold, K, leftBlock, rightBlock, size, promises, i, blockTimestamps, nextLeftBlock, _i, _i2;
1123
-
1124
- return runtime_1.wrap(function _callee3$(_context3) {
1151
+ _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, timestamp) {
1152
+ var result;
1153
+ return runtime_1.wrap(function _callee2$(_context2) {
1125
1154
  while (1) {
1126
- switch (_context3.prev = _context3.next) {
1155
+ switch (_context2.prev = _context2.next) {
1127
1156
  case 0:
1128
- blockThreshold = 50 * 10;
1129
- K = 8;
1130
- leftBlock = startBlock || 1;
1131
- _context3.next = 5;
1132
- return provider.getBlockNumber();
1133
-
1134
- case 5:
1135
- rightBlock = _context3.sent;
1136
- _context3.next = 8;
1137
- return getBlockTimestamp(provider, rightBlock);
1138
-
1139
- case 8:
1140
- _context3.t0 = _context3.sent;
1141
- _context3.t1 = timestamp;
1142
-
1143
- if (!(_context3.t0 < _context3.t1)) {
1144
- _context3.next = 12;
1145
- break;
1146
- }
1157
+ _context2.next = 2;
1158
+ return getQuery('block', 'getblocknobytime', {
1159
+ 'timestamp': timestamp,
1160
+ 'closest': 'before'
1161
+ });
1147
1162
 
1148
- return _context3.abrupt("return", rightBlock);
1163
+ case 2:
1164
+ result = _context2.sent;
1165
+ _context2.t0 = parseInt(result);
1149
1166
 
1150
- case 12:
1151
- if (!(rightBlock - leftBlock >= blockThreshold)) {
1152
- _context3.next = 25;
1167
+ if (_context2.t0) {
1168
+ _context2.next = 8;
1153
1169
  break;
1154
1170
  }
1155
1171
 
1156
- size = Math.floor((rightBlock - leftBlock + 1) / K);
1157
- promises = [];
1158
-
1159
- for (i = 1; i < K; i++) {
1160
- promises.push(getBlockTimestamp(provider, leftBlock + i * size));
1161
- }
1162
-
1163
- _context3.next = 18;
1164
- return Promise.all(promises);
1165
-
1166
- case 18:
1167
- blockTimestamps = _context3.sent;
1168
- nextLeftBlock = leftBlock;
1169
-
1170
- for (_i = 1; _i < K; _i++) {
1171
- if (blockTimestamps[_i - 1] <= timestamp) {
1172
- nextLeftBlock = leftBlock + _i * size;
1173
- }
1174
- }
1175
-
1176
- for (_i2 = K - 1; _i2 >= 1; _i2--) {
1177
- if (blockTimestamps[_i2 - 1] > timestamp) {
1178
- rightBlock = leftBlock + _i2 * size - 1;
1179
- }
1180
- }
1172
+ _context2.next = 7;
1173
+ return provider.getBlockNumber();
1181
1174
 
1182
- leftBlock = nextLeftBlock;
1183
- _context3.next = 12;
1184
- break;
1175
+ case 7:
1176
+ _context2.t0 = _context2.sent;
1185
1177
 
1186
- case 25:
1187
- return _context3.abrupt("return", leftBlock);
1178
+ case 8:
1179
+ return _context2.abrupt("return", _context2.t0);
1188
1180
 
1189
- case 26:
1181
+ case 9:
1190
1182
  case "end":
1191
- return _context3.stop();
1183
+ return _context2.stop();
1192
1184
  }
1193
1185
  }
1194
- }, _callee3);
1186
+ }, _callee2);
1195
1187
  }));
1196
1188
  return _getBlockBeforeTimestamp.apply(this, arguments);
1197
1189
  }
@@ -106509,12 +106501,12 @@ var AirdropSettings = /*#__PURE__*/function () {
106509
106501
  case 2:
106510
106502
  settings = new AirdropSettings();
106511
106503
  _context.next = 5;
106512
- return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp, 63317969);
106504
+ return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp);
106513
106505
 
106514
106506
  case 5:
106515
106507
  settings.airdropStartBlock = _context.sent;
106516
106508
  _context.next = 8;
106517
- return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp, settings.airdropStartBlock);
106509
+ return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp);
106518
106510
 
106519
106511
  case 8:
106520
106512
  settings.airdropEndBlock = _context.sent;
@@ -106601,11 +106593,11 @@ var AirdropAuTokenKeepTracker = /*#__PURE__*/function (_BlockchainEntityRead) {
106601
106593
 
106602
106594
  _step$value = _step.value, from = _step$value.from, to = _step$value.to, amount = _step$value.amount, blockNumber = _step$value.blockNumber;
106603
106595
 
106604
- if (from == address) {
106596
+ if (isSameAddress(from, address)) {
106605
106597
  balance = balance.sub(amount);
106606
106598
  }
106607
106599
 
106608
- if (to == address) {
106600
+ if (isSameAddress(to, address)) {
106609
106601
  balance = balance.add(amount);
106610
106602
  }
106611
106603
 
@@ -106914,5 +106906,5 @@ BigNumber.config({
106914
106906
  DECIMAL_PLACES: 50
106915
106907
  });
106916
106908
 
106917
- export { AIRDROP_END_TIMESTAMP, AIRDROP_KEEP_THRESHOLD, AIRDROP_START_TIMESTAMP, AURORA_CHAINID, AURPLYToken, Airdrop, AirdropRead, AirdropReadWrite, AurPlyPid, BORROW_LIMIT_BUFFER, BORROW_NEAR_REWARDS_PER_WEEK, BlockchainEntity, BlockchainEntityRead, BlockchainEntityReadWrite, ComptrollerRewardType, DECIMAL_PRECISION, DEPOSIT_NEAR_REWARDS_PER_WEEK, ETHAddress, INF, MarketAction, MoneyMarket, MoneyMarketRead, MoneyMarketReadWrite, ONE_DAY, ONE_YEAR, PLYToken, REWARDCLAIMSTART, SDK, SdkRead, SdkReadWrite, Token, TokenAmount, TransferEventQuery, calcLMRewardApr, calcValuation, decimalFactor, dummyAddress, dummyMarketAddress, dummyPly, dummyPlyAurora, dummyToken, dummyTokenAmount, dummyTokenAmount2, dummyTokenAmount3, dummyUserMarketDetails, dummyZeroTokenAmount, fetchLPPositions, fetchLPPrice, fetchPrice, fetchPriceFromCoingecko, fetchPriceFromCoingeckoAPI, fetchPriceFromOracle, fetchStNEARPrice, fetchUnderlyingTokensPrices, fetchValuation, formatObject, getBlockBeforeTimestamp, getBlockTimestamp, getCurrentTimestamp, getDecimal, getDecimalsViaContract, isSameAddress, networkAddresses, validateAndParseAddress };
106909
+ export { AIRDROP_END_TIMESTAMP, AIRDROP_KEEP_THRESHOLD, AIRDROP_START_TIMESTAMP, AURORA_CHAINID, AURPLYToken, Airdrop, AirdropRead, AirdropReadWrite, AurPlyPid, BORROW_LIMIT_BUFFER, BORROW_NEAR_REWARDS_PER_WEEK, BlockchainEntity, BlockchainEntityRead, BlockchainEntityReadWrite, ComptrollerRewardType, DECIMAL_PRECISION, DEPOSIT_NEAR_REWARDS_PER_WEEK, ETHAddress, INF, MarketAction, MoneyMarket, MoneyMarketRead, MoneyMarketReadWrite, ONE_DAY, ONE_YEAR, PLYToken, REWARDCLAIMSTART, SDK, SdkRead, SdkReadWrite, Token, TokenAmount, TransferEventQuery, calcLMRewardApr, calcValuation, decimalFactor, dummyAddress, dummyMarketAddress, dummyPly, dummyPlyAurora, dummyToken, dummyTokenAmount, dummyTokenAmount2, dummyTokenAmount3, dummyUserMarketDetails, dummyZeroTokenAmount, fetchLPPositions, fetchLPPrice, fetchPrice, fetchPriceFromCoingecko, fetchPriceFromCoingeckoAPI, fetchPriceFromOracle, fetchStNEARPrice, fetchUnderlyingTokensPrices, fetchValuation, formatObject, getBlockBeforeTimestamp, getBlockTimestamp, getCurrentTimestamp, getDecimal, isSameAddress, networkAddresses, validateAndParseAddress };
106918
106910
  //# sourceMappingURL=sdk.esm.js.map