@aurigami/sdk 1.4.1 → 1.4.3

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,58 @@ 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
+ if (!globalThis.fetch) {
1037
+ Object.assign(globalThis, {
1038
+ fetch: fetch
1039
+ });
1040
+ }
1041
+
1042
+ params = _extends({}, params, {
1043
+ 'module': module,
1044
+ 'action': action
1045
+ });
1046
+ _context.next = 5;
1047
+ return globalThis.fetch(AURORA_API_BASE_URL + '?' + new URLSearchParams(params), {
1048
+ headers: {
1049
+ 'Content-Type': 'application/json'
1050
+ },
1051
+ method: 'GET'
1052
+ });
1053
+
1054
+ case 5:
1055
+ resp = _context.sent;
1056
+ _context.next = 8;
1057
+ return resp.json();
1058
+
1059
+ case 8:
1060
+ return _context.abrupt("return", _context.sent.result);
1061
+
1062
+ case 9:
1063
+ case "end":
1064
+ return _context.stop();
1065
+ }
1066
+ }
1067
+ }, _callee);
1068
+ }));
1069
+ return _getQuery.apply(this, arguments);
1070
+ }
1071
+
1002
1072
  var decimalRecords = {
1003
1073
  '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
1004
1074
  '0x981bd5832eab9c8f607940e0e9facbf8c09ee20a': 18,
@@ -1044,40 +1114,6 @@ function validateAndParseAddress(address) {
1044
1114
  function getDecimal(address) {
1045
1115
  return decimalRecords[address.toLowerCase()];
1046
1116
  }
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
1117
  function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1082
1118
  if (totalStakeValue.lte(0)) {
1083
1119
  return new BigNumber('999999999');
@@ -1085,113 +1121,75 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1085
1121
 
1086
1122
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
1087
1123
  }
1088
- function getBlockTimestamp(_x3, _x4) {
1124
+ function getBlockTimestamp(_x, _x2) {
1089
1125
  return _getBlockTimestamp.apply(this, arguments);
1090
1126
  }
1091
1127
 
1092
1128
  function _getBlockTimestamp() {
1093
- _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, blockNumber) {
1129
+ _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
1094
1130
  var block;
1095
- return runtime_1.wrap(function _callee2$(_context2) {
1131
+ return runtime_1.wrap(function _callee$(_context) {
1096
1132
  while (1) {
1097
- switch (_context2.prev = _context2.next) {
1133
+ switch (_context.prev = _context.next) {
1098
1134
  case 0:
1099
- _context2.next = 2;
1135
+ _context.next = 2;
1100
1136
  return provider.getBlock(blockNumber);
1101
1137
 
1102
1138
  case 2:
1103
- block = _context2.sent;
1104
- return _context2.abrupt("return", block.timestamp);
1139
+ block = _context.sent;
1140
+ return _context.abrupt("return", block.timestamp);
1105
1141
 
1106
1142
  case 4:
1107
1143
  case "end":
1108
- return _context2.stop();
1144
+ return _context.stop();
1109
1145
  }
1110
1146
  }
1111
- }, _callee2);
1147
+ }, _callee);
1112
1148
  }));
1113
1149
  return _getBlockTimestamp.apply(this, arguments);
1114
1150
  }
1115
1151
 
1116
- function getBlockBeforeTimestamp(_x5, _x6, _x7) {
1152
+ function getBlockBeforeTimestamp(_x3, _x4) {
1117
1153
  return _getBlockBeforeTimestamp.apply(this, arguments);
1118
1154
  }
1119
1155
 
1120
1156
  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) {
1157
+ _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, timestamp) {
1158
+ var result;
1159
+ return runtime_1.wrap(function _callee2$(_context2) {
1125
1160
  while (1) {
1126
- switch (_context3.prev = _context3.next) {
1161
+ switch (_context2.prev = _context2.next) {
1127
1162
  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
- }
1163
+ _context2.next = 2;
1164
+ return getQuery('block', 'getblocknobytime', {
1165
+ 'timestamp': timestamp,
1166
+ 'closest': 'before'
1167
+ });
1147
1168
 
1148
- return _context3.abrupt("return", rightBlock);
1169
+ case 2:
1170
+ result = _context2.sent;
1171
+ _context2.t0 = parseInt(result);
1149
1172
 
1150
- case 12:
1151
- if (!(rightBlock - leftBlock >= blockThreshold)) {
1152
- _context3.next = 25;
1173
+ if (_context2.t0) {
1174
+ _context2.next = 8;
1153
1175
  break;
1154
1176
  }
1155
1177
 
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
- }
1178
+ _context2.next = 7;
1179
+ return provider.getBlockNumber();
1181
1180
 
1182
- leftBlock = nextLeftBlock;
1183
- _context3.next = 12;
1184
- break;
1181
+ case 7:
1182
+ _context2.t0 = _context2.sent;
1185
1183
 
1186
- case 25:
1187
- return _context3.abrupt("return", leftBlock);
1184
+ case 8:
1185
+ return _context2.abrupt("return", _context2.t0);
1188
1186
 
1189
- case 26:
1187
+ case 9:
1190
1188
  case "end":
1191
- return _context3.stop();
1189
+ return _context2.stop();
1192
1190
  }
1193
1191
  }
1194
- }, _callee3);
1192
+ }, _callee2);
1195
1193
  }));
1196
1194
  return _getBlockBeforeTimestamp.apply(this, arguments);
1197
1195
  }
@@ -106509,12 +106507,12 @@ var AirdropSettings = /*#__PURE__*/function () {
106509
106507
  case 2:
106510
106508
  settings = new AirdropSettings();
106511
106509
  _context.next = 5;
106512
- return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp, 63317969);
106510
+ return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp);
106513
106511
 
106514
106512
  case 5:
106515
106513
  settings.airdropStartBlock = _context.sent;
106516
106514
  _context.next = 8;
106517
- return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp, settings.airdropStartBlock);
106515
+ return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp);
106518
106516
 
106519
106517
  case 8:
106520
106518
  settings.airdropEndBlock = _context.sent;
@@ -106601,11 +106599,11 @@ var AirdropAuTokenKeepTracker = /*#__PURE__*/function (_BlockchainEntityRead) {
106601
106599
 
106602
106600
  _step$value = _step.value, from = _step$value.from, to = _step$value.to, amount = _step$value.amount, blockNumber = _step$value.blockNumber;
106603
106601
 
106604
- if (from == address) {
106602
+ if (isSameAddress(from, address)) {
106605
106603
  balance = balance.sub(amount);
106606
106604
  }
106607
106605
 
106608
- if (to == address) {
106606
+ if (isSameAddress(to, address)) {
106609
106607
  balance = balance.add(amount);
106610
106608
  }
106611
106609
 
@@ -106914,5 +106912,5 @@ BigNumber.config({
106914
106912
  DECIMAL_PLACES: 50
106915
106913
  });
106916
106914
 
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 };
106915
+ 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
106916
  //# sourceMappingURL=sdk.esm.js.map