@aurigami/sdk 1.4.0 → 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/aurora-api-helpers.d.ts +1 -0
- package/dist/helpers.d.ts +1 -2
- package/dist/sdk.cjs.development.js +110 -115
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +111 -115
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/airdrop-lottery.ts +3 -5
- package/src/aurora-api-helpers.ts +15 -0
- package/src/constants.ts +1 -0
- package/src/helpers.ts +15 -53
- package/src/priceFetcher.ts +10 -6
|
@@ -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
|
|
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
|
|
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;
|
|
@@ -976,6 +994,7 @@ var networkAddresses = {
|
|
|
976
994
|
USDC: /*#__PURE__*/'0xb12bfca5a55806aaf64e99521918a4bf0fc40802'.toLowerCase(),
|
|
977
995
|
WNEAR: /*#__PURE__*/'0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase(),
|
|
978
996
|
TRI: /*#__PURE__*/'0xFa94348467f64D5A457F75F8bc40495D33c65aBB'.toLowerCase(),
|
|
997
|
+
META: /*#__PURE__*/'0xc21ff01229e982d7c8b8691163b0a3cb8f357453'.toLocaleLowerCase(),
|
|
979
998
|
AURPLY: /*#__PURE__*/dummyAddress.toLowerCase()
|
|
980
999
|
}
|
|
981
1000
|
};
|
|
@@ -1001,6 +1020,52 @@ var DEPOSIT_NEAR_REWARDS_PER_WEEK = /*#__PURE__*/Object.fromEntries( /*#__PURE__
|
|
|
1001
1020
|
}));
|
|
1002
1021
|
var BORROW_NEAR_REWARDS_PER_WEEK = {};
|
|
1003
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
|
+
|
|
1004
1069
|
var decimalRecords = {
|
|
1005
1070
|
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
|
|
1006
1071
|
'0x981bd5832eab9c8f607940e0e9facbf8c09ee20a': 18,
|
|
@@ -1046,40 +1111,6 @@ function validateAndParseAddress(address) {
|
|
|
1046
1111
|
function getDecimal(address) {
|
|
1047
1112
|
return decimalRecords[address.toLowerCase()];
|
|
1048
1113
|
}
|
|
1049
|
-
function getDecimalsViaContract(_x, _x2) {
|
|
1050
|
-
return _getDecimalsViaContract.apply(this, arguments);
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
function _getDecimalsViaContract() {
|
|
1054
|
-
_getDecimalsViaContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(address, provider) {
|
|
1055
|
-
var result, token;
|
|
1056
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1057
|
-
while (1) {
|
|
1058
|
-
switch (_context.prev = _context.next) {
|
|
1059
|
-
case 0:
|
|
1060
|
-
result = getDecimal(address);
|
|
1061
|
-
|
|
1062
|
-
if (!result) {
|
|
1063
|
-
_context.next = 3;
|
|
1064
|
-
break;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
return _context.abrupt("return", result);
|
|
1068
|
-
|
|
1069
|
-
case 3:
|
|
1070
|
-
token = new ethers.Contract(address, EIP20InterfaceABI.abi, provider);
|
|
1071
|
-
return _context.abrupt("return", token.decimals());
|
|
1072
|
-
|
|
1073
|
-
case 5:
|
|
1074
|
-
case "end":
|
|
1075
|
-
return _context.stop();
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
}, _callee);
|
|
1079
|
-
}));
|
|
1080
|
-
return _getDecimalsViaContract.apply(this, arguments);
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
1114
|
function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
|
|
1084
1115
|
if (totalStakeValue.lte(0)) {
|
|
1085
1116
|
return new BigNumber('999999999');
|
|
@@ -1087,113 +1118,75 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
|
|
|
1087
1118
|
|
|
1088
1119
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
1089
1120
|
}
|
|
1090
|
-
function getBlockTimestamp(
|
|
1121
|
+
function getBlockTimestamp(_x, _x2) {
|
|
1091
1122
|
return _getBlockTimestamp.apply(this, arguments);
|
|
1092
1123
|
}
|
|
1093
1124
|
|
|
1094
1125
|
function _getBlockTimestamp() {
|
|
1095
|
-
_getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1126
|
+
_getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
|
|
1096
1127
|
var block;
|
|
1097
|
-
return runtime_1.wrap(function
|
|
1128
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1098
1129
|
while (1) {
|
|
1099
|
-
switch (
|
|
1130
|
+
switch (_context.prev = _context.next) {
|
|
1100
1131
|
case 0:
|
|
1101
|
-
|
|
1132
|
+
_context.next = 2;
|
|
1102
1133
|
return provider.getBlock(blockNumber);
|
|
1103
1134
|
|
|
1104
1135
|
case 2:
|
|
1105
|
-
block =
|
|
1106
|
-
return
|
|
1136
|
+
block = _context.sent;
|
|
1137
|
+
return _context.abrupt("return", block.timestamp);
|
|
1107
1138
|
|
|
1108
1139
|
case 4:
|
|
1109
1140
|
case "end":
|
|
1110
|
-
return
|
|
1141
|
+
return _context.stop();
|
|
1111
1142
|
}
|
|
1112
1143
|
}
|
|
1113
|
-
},
|
|
1144
|
+
}, _callee);
|
|
1114
1145
|
}));
|
|
1115
1146
|
return _getBlockTimestamp.apply(this, arguments);
|
|
1116
1147
|
}
|
|
1117
1148
|
|
|
1118
|
-
function getBlockBeforeTimestamp(
|
|
1149
|
+
function getBlockBeforeTimestamp(_x3, _x4) {
|
|
1119
1150
|
return _getBlockBeforeTimestamp.apply(this, arguments);
|
|
1120
1151
|
}
|
|
1121
1152
|
|
|
1122
1153
|
function _getBlockBeforeTimestamp() {
|
|
1123
|
-
_getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1124
|
-
var
|
|
1125
|
-
|
|
1126
|
-
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) {
|
|
1127
1157
|
while (1) {
|
|
1128
|
-
switch (
|
|
1158
|
+
switch (_context2.prev = _context2.next) {
|
|
1129
1159
|
case 0:
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
case 5:
|
|
1137
|
-
rightBlock = _context3.sent;
|
|
1138
|
-
_context3.next = 8;
|
|
1139
|
-
return getBlockTimestamp(provider, rightBlock);
|
|
1140
|
-
|
|
1141
|
-
case 8:
|
|
1142
|
-
_context3.t0 = _context3.sent;
|
|
1143
|
-
_context3.t1 = timestamp;
|
|
1144
|
-
|
|
1145
|
-
if (!(_context3.t0 < _context3.t1)) {
|
|
1146
|
-
_context3.next = 12;
|
|
1147
|
-
break;
|
|
1148
|
-
}
|
|
1160
|
+
_context2.next = 2;
|
|
1161
|
+
return getQuery('block', 'getblocknobytime', {
|
|
1162
|
+
'timestamp': timestamp,
|
|
1163
|
+
'closest': 'before'
|
|
1164
|
+
});
|
|
1149
1165
|
|
|
1150
|
-
|
|
1166
|
+
case 2:
|
|
1167
|
+
result = _context2.sent;
|
|
1168
|
+
_context2.t0 = parseInt(result);
|
|
1151
1169
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
_context3.next = 25;
|
|
1170
|
+
if (_context2.t0) {
|
|
1171
|
+
_context2.next = 8;
|
|
1155
1172
|
break;
|
|
1156
1173
|
}
|
|
1157
1174
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
for (i = 1; i < K; i++) {
|
|
1162
|
-
promises.push(getBlockTimestamp(provider, leftBlock + i * size));
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
_context3.next = 18;
|
|
1166
|
-
return Promise.all(promises);
|
|
1167
|
-
|
|
1168
|
-
case 18:
|
|
1169
|
-
blockTimestamps = _context3.sent;
|
|
1170
|
-
nextLeftBlock = leftBlock;
|
|
1171
|
-
|
|
1172
|
-
for (_i = 1; _i < K; _i++) {
|
|
1173
|
-
if (blockTimestamps[_i - 1] <= timestamp) {
|
|
1174
|
-
nextLeftBlock = leftBlock + _i * size;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
for (_i2 = K - 1; _i2 >= 1; _i2--) {
|
|
1179
|
-
if (blockTimestamps[_i2 - 1] > timestamp) {
|
|
1180
|
-
rightBlock = leftBlock + _i2 * size - 1;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1175
|
+
_context2.next = 7;
|
|
1176
|
+
return provider.getBlockNumber();
|
|
1183
1177
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
break;
|
|
1178
|
+
case 7:
|
|
1179
|
+
_context2.t0 = _context2.sent;
|
|
1187
1180
|
|
|
1188
|
-
case
|
|
1189
|
-
return
|
|
1181
|
+
case 8:
|
|
1182
|
+
return _context2.abrupt("return", _context2.t0);
|
|
1190
1183
|
|
|
1191
|
-
case
|
|
1184
|
+
case 9:
|
|
1192
1185
|
case "end":
|
|
1193
|
-
return
|
|
1186
|
+
return _context2.stop();
|
|
1194
1187
|
}
|
|
1195
1188
|
}
|
|
1196
|
-
},
|
|
1189
|
+
}, _callee2);
|
|
1197
1190
|
}));
|
|
1198
1191
|
return _getBlockBeforeTimestamp.apply(this, arguments);
|
|
1199
1192
|
}
|
|
@@ -2223,7 +2216,7 @@ function _fetchPriceFromCoingecko() {
|
|
|
2223
2216
|
switch (_context2.prev = _context2.next) {
|
|
2224
2217
|
case 0:
|
|
2225
2218
|
_context2.t0 = id.toLowerCase();
|
|
2226
|
-
_context2.next = _context2.t0 === networkAddresses.tokens.AURORA ? 3 : _context2.t0 === networkAddresses.tokens.TRI ? 4 : 5;
|
|
2219
|
+
_context2.next = _context2.t0 === networkAddresses.tokens.AURORA ? 3 : _context2.t0 === networkAddresses.tokens.TRI ? 4 : _context2.t0 === networkAddresses.tokens.META ? 5 : 6;
|
|
2227
2220
|
break;
|
|
2228
2221
|
|
|
2229
2222
|
case 3:
|
|
@@ -2233,9 +2226,12 @@ function _fetchPriceFromCoingecko() {
|
|
|
2233
2226
|
return _context2.abrupt("return", fetchPriceFromCoingeckoAPI('trisolaris'));
|
|
2234
2227
|
|
|
2235
2228
|
case 5:
|
|
2236
|
-
|
|
2229
|
+
return _context2.abrupt("return", fetchPriceFromCoingeckoAPI('meta-pool'));
|
|
2237
2230
|
|
|
2238
2231
|
case 6:
|
|
2232
|
+
throw Error("Unknown token " + id + " in fetchPriceFromCoingecko");
|
|
2233
|
+
|
|
2234
|
+
case 7:
|
|
2239
2235
|
case "end":
|
|
2240
2236
|
return _context2.stop();
|
|
2241
2237
|
}
|
|
@@ -2449,7 +2445,7 @@ function _fetchStNEARPrice() {
|
|
|
2449
2445
|
|
|
2450
2446
|
function shouldFetchFromCoingecko(address) {
|
|
2451
2447
|
address = address.toLowerCase();
|
|
2452
|
-
return address == networkAddresses.tokens.AURORA || address == networkAddresses.tokens.TRI;
|
|
2448
|
+
return address == networkAddresses.tokens.AURORA || address == networkAddresses.tokens.TRI || address == networkAddresses.tokens.META;
|
|
2453
2449
|
}
|
|
2454
2450
|
|
|
2455
2451
|
function fetchPrice(_x11, _x12) {
|
|
@@ -2491,7 +2487,7 @@ function _fetchPrice() {
|
|
|
2491
2487
|
return _context8.abrupt("return", fetchPriceFromOracle(matchingAuToken.address, getDecimal(address), provider));
|
|
2492
2488
|
|
|
2493
2489
|
case 9:
|
|
2494
|
-
if (!isSameAddress(address, networkAddresses.tokens.
|
|
2490
|
+
if (!isSameAddress(address, networkAddresses.tokens.AURPLY)) {
|
|
2495
2491
|
_context8.next = 13;
|
|
2496
2492
|
break;
|
|
2497
2493
|
}
|
|
@@ -106508,12 +106504,12 @@ var AirdropSettings = /*#__PURE__*/function () {
|
|
|
106508
106504
|
case 2:
|
|
106509
106505
|
settings = new AirdropSettings();
|
|
106510
106506
|
_context.next = 5;
|
|
106511
|
-
return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp
|
|
106507
|
+
return getBlockBeforeTimestamp(provider, settings.airdropStartTimestamp);
|
|
106512
106508
|
|
|
106513
106509
|
case 5:
|
|
106514
106510
|
settings.airdropStartBlock = _context.sent;
|
|
106515
106511
|
_context.next = 8;
|
|
106516
|
-
return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp
|
|
106512
|
+
return getBlockBeforeTimestamp(provider, settings.airdropEndTimestamp);
|
|
106517
106513
|
|
|
106518
106514
|
case 8:
|
|
106519
106515
|
settings.airdropEndBlock = _context.sent;
|
|
@@ -106600,11 +106596,11 @@ var AirdropAuTokenKeepTracker = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
106600
106596
|
|
|
106601
106597
|
_step$value = _step.value, from = _step$value.from, to = _step$value.to, amount = _step$value.amount, blockNumber = _step$value.blockNumber;
|
|
106602
106598
|
|
|
106603
|
-
if (from
|
|
106599
|
+
if (isSameAddress(from, address)) {
|
|
106604
106600
|
balance = balance.sub(amount);
|
|
106605
106601
|
}
|
|
106606
106602
|
|
|
106607
|
-
if (to
|
|
106603
|
+
if (isSameAddress(to, address)) {
|
|
106608
106604
|
balance = balance.add(amount);
|
|
106609
106605
|
}
|
|
106610
106606
|
|
|
@@ -106971,7 +106967,6 @@ exports.getBlockBeforeTimestamp = getBlockBeforeTimestamp;
|
|
|
106971
106967
|
exports.getBlockTimestamp = getBlockTimestamp;
|
|
106972
106968
|
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
106973
106969
|
exports.getDecimal = getDecimal;
|
|
106974
|
-
exports.getDecimalsViaContract = getDecimalsViaContract;
|
|
106975
106970
|
exports.isSameAddress = isSameAddress;
|
|
106976
106971
|
exports.networkAddresses = networkAddresses;
|
|
106977
106972
|
exports.validateAndParseAddress = validateAndParseAddress;
|