@pioneer-platform/eth-network 8.1.48 → 8.1.57
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/lib/constant.d.ts +190 -0
- package/lib/constant.js +525 -0
- package/lib/etherscan-api.d.ts +1 -1
- package/lib/etherscan-api.js +36 -30
- package/lib/index.js +161 -603
- package/lib/types/client-types.d.ts +8 -8
- package/lib/types/etherscan-api-types.d.ts +5 -5
- package/lib/types/index.js +6 -2
- package/lib/utils.d.ts +4 -4
- package/lib/utils.js +43 -30
- package/package.json +7 -7
package/lib/etherscan-api.js
CHANGED
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
15
|
function step(op) {
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (_) try {
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
20
|
switch (op[0]) {
|
@@ -35,12 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
36
|
}
|
37
37
|
};
|
38
|
-
var
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
40
|
+
if (ar || !(i in from)) {
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
42
|
+
ar[i] = from[i];
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
44
46
|
};
|
45
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
46
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
@@ -50,7 +52,7 @@ exports.getTokenTransactionHistory = exports.getETHTransactionHistory = exports.
|
|
50
52
|
var axios_1 = __importDefault(require("axios"));
|
51
53
|
var utils_1 = require("./utils");
|
52
54
|
var lib_1 = require("@xchainjs/xchain-util/lib");
|
53
|
-
var getApiKeyQueryParameter = function (apiKey) { return (!!apiKey ? "&apiKey="
|
55
|
+
var getApiKeyQueryParameter = function (apiKey) { return (!!apiKey ? "&apiKey=".concat(apiKey) : ''); };
|
54
56
|
/**
|
55
57
|
* SafeGasPrice, ProposeGasPrice And FastGasPrice returned in string-Gwei
|
56
58
|
*
|
@@ -60,10 +62,11 @@ var getApiKeyQueryParameter = function (apiKey) { return (!!apiKey ? "&apiKey="
|
|
60
62
|
* @param {string} apiKey The etherscan API key. (optional)
|
61
63
|
* @returns {GasOracleResponse} LastBlock, SafeGasPrice, ProposeGasPrice, FastGasPrice
|
62
64
|
*/
|
63
|
-
|
65
|
+
var getGasOracle = function (baseUrl, apiKey) {
|
64
66
|
var url = baseUrl + '/api?module=gastracker&action=gasoracle';
|
65
67
|
return axios_1.default.get(url + getApiKeyQueryParameter(apiKey)).then(function (response) { return response.data.result; });
|
66
68
|
};
|
69
|
+
exports.getGasOracle = getGasOracle;
|
67
70
|
/**
|
68
71
|
* Get token balance
|
69
72
|
*
|
@@ -75,11 +78,12 @@ exports.getGasOracle = function (baseUrl, apiKey) {
|
|
75
78
|
* @param {string} apiKey The etherscan API key. (optional)
|
76
79
|
* @returns {BigNumberish} The token balance
|
77
80
|
*/
|
78
|
-
|
81
|
+
var getTokenBalance = function (_a) {
|
79
82
|
var baseUrl = _a.baseUrl, address = _a.address, assetAddress = _a.assetAddress, apiKey = _a.apiKey;
|
80
|
-
var url = baseUrl +
|
83
|
+
var url = baseUrl + "/api?module=account&action=tokenbalance&contractaddress=".concat(assetAddress, "&address=").concat(address);
|
81
84
|
return axios_1.default.get(url + getApiKeyQueryParameter(apiKey)).then(function (response) { return response.data.result; });
|
82
85
|
};
|
86
|
+
exports.getTokenBalance = getTokenBalance;
|
83
87
|
/**
|
84
88
|
* Get ETH transaction history
|
85
89
|
*
|
@@ -91,7 +95,7 @@ exports.getTokenBalance = function (_a) {
|
|
91
95
|
* @param {string} apiKey The etherscan API key. (optional)
|
92
96
|
* @returns {Array<ETHTransactionInfo>} The ETH transaction history
|
93
97
|
*/
|
94
|
-
|
98
|
+
var getETHTransactionHistory = function (_a) {
|
95
99
|
var baseUrl = _a.baseUrl, address = _a.address, page = _a.page, offset = _a.offset, startblock = _a.startblock, endblock = _a.endblock, apiKey = _a.apiKey;
|
96
100
|
return __awaiter(void 0, void 0, void 0, function () {
|
97
101
|
var url, ethTransactions;
|
@@ -100,25 +104,26 @@ exports.getETHTransactionHistory = function (_a) {
|
|
100
104
|
case 0:
|
101
105
|
url = baseUrl + "/api?module=account&action=txlist&sort=desc" + getApiKeyQueryParameter(apiKey);
|
102
106
|
if (address)
|
103
|
-
url += "&address="
|
107
|
+
url += "&address=".concat(address);
|
104
108
|
if (offset)
|
105
|
-
url += "&offset="
|
109
|
+
url += "&offset=".concat(offset);
|
106
110
|
if (page)
|
107
|
-
url += "&page="
|
111
|
+
url += "&page=".concat(page);
|
108
112
|
if (startblock)
|
109
|
-
url += "&startblock="
|
113
|
+
url += "&startblock=".concat(startblock);
|
110
114
|
if (endblock)
|
111
|
-
url += "&endblock="
|
115
|
+
url += "&endblock=".concat(endblock);
|
112
116
|
return [4 /*yield*/, axios_1.default.get(url).then(function (response) { return response.data.result; })];
|
113
117
|
case 1:
|
114
118
|
ethTransactions = _b.sent();
|
115
|
-
return [2 /*return*/, utils_1.filterSelfTxs(ethTransactions)
|
116
|
-
.filter(function (tx) { return !lib_1.bn(tx.value).isZero(); })
|
119
|
+
return [2 /*return*/, (0, utils_1.filterSelfTxs)(ethTransactions)
|
120
|
+
.filter(function (tx) { return !(0, lib_1.bn)(tx.value).isZero(); })
|
117
121
|
.map(utils_1.getTxFromEthTransaction)];
|
118
122
|
}
|
119
123
|
});
|
120
124
|
});
|
121
125
|
};
|
126
|
+
exports.getETHTransactionHistory = getETHTransactionHistory;
|
122
127
|
/**
|
123
128
|
* Get token transaction history
|
124
129
|
*
|
@@ -130,7 +135,7 @@ exports.getETHTransactionHistory = function (_a) {
|
|
130
135
|
* @param {string} apiKey The etherscan API key. (optional)
|
131
136
|
* @returns {Array<Tx>} The token transaction history
|
132
137
|
*/
|
133
|
-
|
138
|
+
var getTokenTransactionHistory = function (_a) {
|
134
139
|
var baseUrl = _a.baseUrl, address = _a.address, assetAddress = _a.assetAddress, page = _a.page, offset = _a.offset, startblock = _a.startblock, endblock = _a.endblock, apiKey = _a.apiKey;
|
135
140
|
return __awaiter(void 0, void 0, void 0, function () {
|
136
141
|
var url, tokenTransactions;
|
@@ -139,27 +144,28 @@ exports.getTokenTransactionHistory = function (_a) {
|
|
139
144
|
case 0:
|
140
145
|
url = baseUrl + "/api?module=account&action=tokentx&sort=desc" + getApiKeyQueryParameter(apiKey);
|
141
146
|
if (address)
|
142
|
-
url += "&address="
|
147
|
+
url += "&address=".concat(address);
|
143
148
|
if (assetAddress)
|
144
|
-
url += "&contractaddress="
|
149
|
+
url += "&contractaddress=".concat(assetAddress);
|
145
150
|
if (offset)
|
146
|
-
url += "&offset="
|
151
|
+
url += "&offset=".concat(offset);
|
147
152
|
if (page)
|
148
|
-
url += "&page="
|
153
|
+
url += "&page=".concat(page);
|
149
154
|
if (startblock)
|
150
|
-
url += "&startblock="
|
155
|
+
url += "&startblock=".concat(startblock);
|
151
156
|
if (endblock)
|
152
|
-
url += "&endblock="
|
157
|
+
url += "&endblock=".concat(endblock);
|
153
158
|
return [4 /*yield*/, axios_1.default.get(url).then(function (response) { return response.data.result; })];
|
154
159
|
case 1:
|
155
160
|
tokenTransactions = _b.sent();
|
156
|
-
return [2 /*return*/, utils_1.filterSelfTxs(tokenTransactions)
|
157
|
-
.filter(function (tx) { return !lib_1.bn(tx.value).isZero(); })
|
161
|
+
return [2 /*return*/, (0, utils_1.filterSelfTxs)(tokenTransactions)
|
162
|
+
.filter(function (tx) { return !(0, lib_1.bn)(tx.value).isZero(); })
|
158
163
|
.reduce(function (acc, cur) {
|
159
|
-
var tx = utils_1.getTxFromTokenTransaction(cur);
|
160
|
-
return tx ?
|
164
|
+
var tx = (0, utils_1.getTxFromTokenTransaction)(cur);
|
165
|
+
return tx ? __spreadArray(__spreadArray([], acc, true), [tx], false) : acc;
|
161
166
|
}, [])];
|
162
167
|
}
|
163
168
|
});
|
164
169
|
});
|
165
170
|
};
|
171
|
+
exports.getTokenTransactionHistory = getTokenTransactionHistory;
|