@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.
@@ -0,0 +1 @@
1
+ export declare function getQuery(module: string, action: string, params?: Record<string, any>): Promise<any>;
package/dist/helpers.d.ts CHANGED
@@ -7,7 +7,6 @@ export declare const isSameAddress: (address1: Address, address2: Address) => bo
7
7
  export declare const getCurrentTimestamp: () => number;
8
8
  export declare function validateAndParseAddress(address: Address): Address;
9
9
  export declare function getDecimal(address: Address): number;
10
- export declare function getDecimalsViaContract(address: Address, provider: Provider): Promise<number>;
11
10
  export declare function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNumber, frequencyPerYear: number): BigNumber;
12
11
  export declare function getBlockTimestamp(provider: Provider, blockNumber: number): Promise<number>;
13
- export declare function getBlockBeforeTimestamp(provider: Provider, timestamp: number, startBlock?: number): Promise<number>;
12
+ export declare function getBlockBeforeTimestamp(provider: Provider, timestamp: number): Promise<number>;
@@ -8,7 +8,7 @@ var BigNumber = _interopDefault(require('bignumber.js'));
8
8
  var ethers = require('ethers');
9
9
  var utils = require('ethers/lib/utils');
10
10
  var abstractSigner = require('@ethersproject/abstract-signer');
11
- var EIP20InterfaceABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json'));
11
+ var fetch = _interopDefault(require('node-fetch'));
12
12
  var AuErc20ABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json'));
13
13
  var AuETHABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json'));
14
14
  var ComptrollerABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json'));
@@ -58,6 +58,24 @@ function _asyncToGenerator(fn) {
58
58
  };
59
59
  }
60
60
 
61
+ function _extends() {
62
+ _extends = Object.assign || function (target) {
63
+ for (var i = 1; i < arguments.length; i++) {
64
+ var source = arguments[i];
65
+
66
+ for (var key in source) {
67
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
68
+ target[key] = source[key];
69
+ }
70
+ }
71
+ }
72
+
73
+ return target;
74
+ };
75
+
76
+ return _extends.apply(this, arguments);
77
+ }
78
+
61
79
  function _inheritsLoose(subClass, superClass) {
62
80
  subClass.prototype = Object.create(superClass.prototype);
63
81
  subClass.prototype.constructor = subClass;
@@ -1002,6 +1020,58 @@ var DEPOSIT_NEAR_REWARDS_PER_WEEK = /*#__PURE__*/Object.fromEntries( /*#__PURE__
1002
1020
  }));
1003
1021
  var BORROW_NEAR_REWARDS_PER_WEEK = {};
1004
1022
 
1023
+ var AURORA_API_BASE_URL = 'https://api.aurorascan.dev/api';
1024
+ function getQuery(_x, _x2, _x3) {
1025
+ return _getQuery.apply(this, arguments);
1026
+ }
1027
+
1028
+ function _getQuery() {
1029
+ _getQuery = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(module, action, params) {
1030
+ var resp;
1031
+ return runtime_1.wrap(function _callee$(_context) {
1032
+ while (1) {
1033
+ switch (_context.prev = _context.next) {
1034
+ case 0:
1035
+ if (params === void 0) {
1036
+ params = {};
1037
+ }
1038
+
1039
+ if (!globalThis.fetch) {
1040
+ Object.assign(globalThis, {
1041
+ fetch: fetch
1042
+ });
1043
+ }
1044
+
1045
+ params = _extends({}, params, {
1046
+ 'module': module,
1047
+ 'action': action
1048
+ });
1049
+ _context.next = 5;
1050
+ return globalThis.fetch(AURORA_API_BASE_URL + '?' + new URLSearchParams(params), {
1051
+ headers: {
1052
+ 'Content-Type': 'application/json'
1053
+ },
1054
+ method: 'GET'
1055
+ });
1056
+
1057
+ case 5:
1058
+ resp = _context.sent;
1059
+ _context.next = 8;
1060
+ return resp.json();
1061
+
1062
+ case 8:
1063
+ return _context.abrupt("return", _context.sent.result);
1064
+
1065
+ case 9:
1066
+ case "end":
1067
+ return _context.stop();
1068
+ }
1069
+ }
1070
+ }, _callee);
1071
+ }));
1072
+ return _getQuery.apply(this, arguments);
1073
+ }
1074
+
1005
1075
  var decimalRecords = {
1006
1076
  '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
1007
1077
  '0x981bd5832eab9c8f607940e0e9facbf8c09ee20a': 18,
@@ -1047,40 +1117,6 @@ function validateAndParseAddress(address) {
1047
1117
  function getDecimal(address) {
1048
1118
  return decimalRecords[address.toLowerCase()];
1049
1119
  }
1050
- function getDecimalsViaContract(_x, _x2) {
1051
- return _getDecimalsViaContract.apply(this, arguments);
1052
- }
1053
-
1054
- function _getDecimalsViaContract() {
1055
- _getDecimalsViaContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(address, provider) {
1056
- var result, token;
1057
- return runtime_1.wrap(function _callee$(_context) {
1058
- while (1) {
1059
- switch (_context.prev = _context.next) {
1060
- case 0:
1061
- result = getDecimal(address);
1062
-
1063
- if (!result) {
1064
- _context.next = 3;
1065
- break;
1066
- }
1067
-
1068
- return _context.abrupt("return", result);
1069
-
1070
- case 3:
1071
- token = new ethers.Contract(address, EIP20InterfaceABI.abi, provider);
1072
- return _context.abrupt("return", token.decimals());
1073
-
1074
- case 5:
1075
- case "end":
1076
- return _context.stop();
1077
- }
1078
- }
1079
- }, _callee);
1080
- }));
1081
- return _getDecimalsViaContract.apply(this, arguments);
1082
- }
1083
-
1084
1120
  function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1085
1121
  if (totalStakeValue.lte(0)) {
1086
1122
  return new BigNumber('999999999');
@@ -1088,113 +1124,75 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1088
1124
 
1089
1125
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
1090
1126
  }
1091
- function getBlockTimestamp(_x3, _x4) {
1127
+ function getBlockTimestamp(_x, _x2) {
1092
1128
  return _getBlockTimestamp.apply(this, arguments);
1093
1129
  }
1094
1130
 
1095
1131
  function _getBlockTimestamp() {
1096
- _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, blockNumber) {
1132
+ _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
1097
1133
  var block;
1098
- return runtime_1.wrap(function _callee2$(_context2) {
1134
+ return runtime_1.wrap(function _callee$(_context) {
1099
1135
  while (1) {
1100
- switch (_context2.prev = _context2.next) {
1136
+ switch (_context.prev = _context.next) {
1101
1137
  case 0:
1102
- _context2.next = 2;
1138
+ _context.next = 2;
1103
1139
  return provider.getBlock(blockNumber);
1104
1140
 
1105
1141
  case 2:
1106
- block = _context2.sent;
1107
- return _context2.abrupt("return", block.timestamp);
1142
+ block = _context.sent;
1143
+ return _context.abrupt("return", block.timestamp);
1108
1144
 
1109
1145
  case 4:
1110
1146
  case "end":
1111
- return _context2.stop();
1147
+ return _context.stop();
1112
1148
  }
1113
1149
  }
1114
- }, _callee2);
1150
+ }, _callee);
1115
1151
  }));
1116
1152
  return _getBlockTimestamp.apply(this, arguments);
1117
1153
  }
1118
1154
 
1119
- function getBlockBeforeTimestamp(_x5, _x6, _x7) {
1155
+ function getBlockBeforeTimestamp(_x3, _x4) {
1120
1156
  return _getBlockBeforeTimestamp.apply(this, arguments);
1121
1157
  }
1122
1158
 
1123
1159
  function _getBlockBeforeTimestamp() {
1124
- _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider, timestamp, startBlock) {
1125
- var blockThreshold, K, leftBlock, rightBlock, size, promises, i, blockTimestamps, nextLeftBlock, _i, _i2;
1126
-
1127
- return runtime_1.wrap(function _callee3$(_context3) {
1160
+ _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, timestamp) {
1161
+ var result;
1162
+ return runtime_1.wrap(function _callee2$(_context2) {
1128
1163
  while (1) {
1129
- switch (_context3.prev = _context3.next) {
1164
+ switch (_context2.prev = _context2.next) {
1130
1165
  case 0:
1131
- blockThreshold = 50 * 10;
1132
- K = 8;
1133
- leftBlock = startBlock || 1;
1134
- _context3.next = 5;
1135
- return provider.getBlockNumber();
1136
-
1137
- case 5:
1138
- rightBlock = _context3.sent;
1139
- _context3.next = 8;
1140
- return getBlockTimestamp(provider, rightBlock);
1141
-
1142
- case 8:
1143
- _context3.t0 = _context3.sent;
1144
- _context3.t1 = timestamp;
1145
-
1146
- if (!(_context3.t0 < _context3.t1)) {
1147
- _context3.next = 12;
1148
- break;
1149
- }
1166
+ _context2.next = 2;
1167
+ return getQuery('block', 'getblocknobytime', {
1168
+ 'timestamp': timestamp,
1169
+ 'closest': 'before'
1170
+ });
1150
1171
 
1151
- return _context3.abrupt("return", rightBlock);
1172
+ case 2:
1173
+ result = _context2.sent;
1174
+ _context2.t0 = parseInt(result);
1152
1175
 
1153
- case 12:
1154
- if (!(rightBlock - leftBlock >= blockThreshold)) {
1155
- _context3.next = 25;
1176
+ if (_context2.t0) {
1177
+ _context2.next = 8;
1156
1178
  break;
1157
1179
  }
1158
1180
 
1159
- size = Math.floor((rightBlock - leftBlock + 1) / K);
1160
- promises = [];
1161
-
1162
- for (i = 1; i < K; i++) {
1163
- promises.push(getBlockTimestamp(provider, leftBlock + i * size));
1164
- }
1165
-
1166
- _context3.next = 18;
1167
- return Promise.all(promises);
1168
-
1169
- case 18:
1170
- blockTimestamps = _context3.sent;
1171
- nextLeftBlock = leftBlock;
1172
-
1173
- for (_i = 1; _i < K; _i++) {
1174
- if (blockTimestamps[_i - 1] <= timestamp) {
1175
- nextLeftBlock = leftBlock + _i * size;
1176
- }
1177
- }
1178
-
1179
- for (_i2 = K - 1; _i2 >= 1; _i2--) {
1180
- if (blockTimestamps[_i2 - 1] > timestamp) {
1181
- rightBlock = leftBlock + _i2 * size - 1;
1182
- }
1183
- }
1181
+ _context2.next = 7;
1182
+ return provider.getBlockNumber();
1184
1183
 
1185
- leftBlock = nextLeftBlock;
1186
- _context3.next = 12;
1187
- break;
1184
+ case 7:
1185
+ _context2.t0 = _context2.sent;
1188
1186
 
1189
- case 25:
1190
- return _context3.abrupt("return", leftBlock);
1187
+ case 8:
1188
+ return _context2.abrupt("return", _context2.t0);
1191
1189
 
1192
- case 26:
1190
+ case 9:
1193
1191
  case "end":
1194
- return _context3.stop();
1192
+ return _context2.stop();
1195
1193
  }
1196
1194
  }
1197
- }, _callee3);
1195
+ }, _callee2);
1198
1196
  }));
1199
1197
  return _getBlockBeforeTimestamp.apply(this, arguments);
1200
1198
  }
@@ -106512,12 +106510,12 @@ var AirdropSettings = /*#__PURE__*/function () {
106512
106510
  case 2:
106513
106511
  settings = new AirdropSettings();
106514
106512
  _context.next = 5;
106515
- return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp, 63317969);
106513
+ return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp);
106516
106514
 
106517
106515
  case 5:
106518
106516
  settings.airdropStartBlock = _context.sent;
106519
106517
  _context.next = 8;
106520
- return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp, settings.airdropStartBlock);
106518
+ return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp);
106521
106519
 
106522
106520
  case 8:
106523
106521
  settings.airdropEndBlock = _context.sent;
@@ -106604,11 +106602,11 @@ var AirdropAuTokenKeepTracker = /*#__PURE__*/function (_BlockchainEntityRead) {
106604
106602
 
106605
106603
  _step$value = _step.value, from = _step$value.from, to = _step$value.to, amount = _step$value.amount, blockNumber = _step$value.blockNumber;
106606
106604
 
106607
- if (from == address) {
106605
+ if (isSameAddress(from, address)) {
106608
106606
  balance = balance.sub(amount);
106609
106607
  }
106610
106608
 
106611
- if (to == address) {
106609
+ if (isSameAddress(to, address)) {
106612
106610
  balance = balance.add(amount);
106613
106611
  }
106614
106612
 
@@ -106975,7 +106973,6 @@ exports.getBlockBeforeTimestamp = getBlockBeforeTimestamp;
106975
106973
  exports.getBlockTimestamp = getBlockTimestamp;
106976
106974
  exports.getCurrentTimestamp = getCurrentTimestamp;
106977
106975
  exports.getDecimal = getDecimal;
106978
- exports.getDecimalsViaContract = getDecimalsViaContract;
106979
106976
  exports.isSameAddress = isSameAddress;
106980
106977
  exports.networkAddresses = networkAddresses;
106981
106978
  exports.validateAndParseAddress = validateAndParseAddress;