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