@pioneer-platform/eth-network 8.1.49 → 8.1.58
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 +145 -587
- 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
@@ -1,33 +1,33 @@
|
|
1
1
|
import { ethers, BigNumber } from 'ethers';
|
2
2
|
import { BaseAmount } from '@xchainjs/xchain-util';
|
3
3
|
import * as C from '@xchainjs/xchain-client';
|
4
|
-
export
|
4
|
+
export type Address = string;
|
5
5
|
export declare enum Network {
|
6
6
|
TEST = "ropsten",
|
7
7
|
MAIN = "homestead"
|
8
8
|
}
|
9
|
-
export
|
9
|
+
export type ClientUrl = {
|
10
10
|
testnet: string;
|
11
11
|
mainnet: string;
|
12
12
|
};
|
13
|
-
export
|
13
|
+
export type ExplorerUrl = {
|
14
14
|
testnet: string;
|
15
15
|
mainnet: string;
|
16
16
|
};
|
17
|
-
export
|
17
|
+
export type TxOverrides = {
|
18
18
|
nonce?: ethers.BigNumberish;
|
19
19
|
gasLimit: ethers.BigNumberish;
|
20
20
|
gasPrice?: ethers.BigNumberish;
|
21
21
|
data?: ethers.BytesLike;
|
22
22
|
value?: ethers.BigNumberish;
|
23
23
|
};
|
24
|
-
export
|
24
|
+
export type InfuraCreds = {
|
25
25
|
projectId: string;
|
26
26
|
projectSecret?: string;
|
27
27
|
};
|
28
|
-
export
|
29
|
-
export
|
30
|
-
export
|
28
|
+
export type GasPrices = Record<C.FeeOptionKey, BaseAmount>;
|
29
|
+
export type FeesParams = C.FeesParams & C.TxParams;
|
30
|
+
export type FeesWithGasPricesAndLimits = {
|
31
31
|
fees: C.Fees;
|
32
32
|
gasPrices: GasPrices;
|
33
33
|
gasLimit: BigNumber;
|
@@ -1,14 +1,14 @@
|
|
1
|
-
export
|
1
|
+
export type GasOracleResponse = {
|
2
2
|
LastBlock: string;
|
3
3
|
SafeGasPrice: string;
|
4
4
|
ProposeGasPrice: string;
|
5
5
|
FastGasPrice: string;
|
6
6
|
};
|
7
|
-
export
|
7
|
+
export type TokenBalanceParam = {
|
8
8
|
address: string;
|
9
9
|
assetAddress: string;
|
10
10
|
};
|
11
|
-
export
|
11
|
+
export type TransactionHistoryParam = {
|
12
12
|
address?: string;
|
13
13
|
assetAddress?: string;
|
14
14
|
page?: number;
|
@@ -16,7 +16,7 @@ export declare type TransactionHistoryParam = {
|
|
16
16
|
startblock?: number;
|
17
17
|
endblock?: number;
|
18
18
|
};
|
19
|
-
export
|
19
|
+
export type TokenTransactionInfo = {
|
20
20
|
blockNumber: string;
|
21
21
|
timeStamp: string;
|
22
22
|
hash: string;
|
@@ -37,7 +37,7 @@ export declare type TokenTransactionInfo = {
|
|
37
37
|
input: string;
|
38
38
|
confirmations: string;
|
39
39
|
};
|
40
|
-
export
|
40
|
+
export type ETHTransactionInfo = {
|
41
41
|
blockNumber: string;
|
42
42
|
timeStamp: string;
|
43
43
|
hash: string;
|
package/lib/types/index.js
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
8
12
|
}));
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
-
for (var p in m) if (p !== "default" && !
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
15
|
};
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
13
17
|
__exportStar(require("./etherscan-api-types"), exports);
|
package/lib/utils.d.ts
CHANGED
@@ -43,7 +43,7 @@ export declare const getTokenAddress: (asset: Asset) => string | null;
|
|
43
43
|
* @param {string|null|undefined} symbol
|
44
44
|
* @returns {boolean} `true` or `false`.
|
45
45
|
*/
|
46
|
-
export declare const validateSymbol: (symbol?: string | null
|
46
|
+
export declare const validateSymbol: (symbol?: string | null) => boolean;
|
47
47
|
/**
|
48
48
|
* Get transactions from token tx
|
49
49
|
*
|
@@ -67,19 +67,19 @@ export declare const getFee: ({ gasPrice, gasLimit }: {
|
|
67
67
|
gasPrice: BaseAmount;
|
68
68
|
gasLimit: BigNumber;
|
69
69
|
}) => BaseAmount;
|
70
|
-
export declare const estimateDefaultFeesWithGasPricesAndLimits: (asset?: Asset
|
70
|
+
export declare const estimateDefaultFeesWithGasPricesAndLimits: (asset?: Asset) => FeesWithGasPricesAndLimits;
|
71
71
|
/**
|
72
72
|
* Get the default fees.
|
73
73
|
*
|
74
74
|
* @returns {Fees} The default gas price.
|
75
75
|
*/
|
76
|
-
export declare const getDefaultFees: (asset?: Asset
|
76
|
+
export declare const getDefaultFees: (asset?: Asset) => Fees;
|
77
77
|
/**
|
78
78
|
* Get the default gas price.
|
79
79
|
*
|
80
80
|
* @returns {Fees} The default gas prices.
|
81
81
|
*/
|
82
|
-
export declare const getDefaultGasPrices: (asset?: Asset
|
82
|
+
export declare const getDefaultGasPrices: (asset?: Asset) => GasPrices;
|
83
83
|
/**
|
84
84
|
* Get address prefix based on the network.
|
85
85
|
*
|
package/lib/utils.js
CHANGED
@@ -21,7 +21,7 @@ exports.MAX_APPROVAL = ethers_1.BigNumber.from(2).pow(256).sub(1);
|
|
21
21
|
* @param {XChainNetwork} network
|
22
22
|
* @returns {EthNetwork}
|
23
23
|
*/
|
24
|
-
|
24
|
+
var xchainNetworkToEths = function (network) {
|
25
25
|
switch (network) {
|
26
26
|
// DO NOT use switch/case's default branch
|
27
27
|
// to be sure that ALL possible cases are
|
@@ -32,13 +32,14 @@ exports.xchainNetworkToEths = function (network) {
|
|
32
32
|
return types_1.Network.TEST;
|
33
33
|
}
|
34
34
|
};
|
35
|
+
exports.xchainNetworkToEths = xchainNetworkToEths;
|
35
36
|
/**
|
36
37
|
* EthNetwork -> XChainNetwork
|
37
38
|
*
|
38
39
|
* @param {EthNetwork} network
|
39
40
|
* @returns {XChainNetwork}
|
40
41
|
*/
|
41
|
-
|
42
|
+
var ethNetworkToXchains = function (network) {
|
42
43
|
switch (network) {
|
43
44
|
// DO NOT use switch/case's default branch
|
44
45
|
// to be sure that ALL possible cases are
|
@@ -49,13 +50,14 @@ exports.ethNetworkToXchains = function (network) {
|
|
49
50
|
return 'testnet';
|
50
51
|
}
|
51
52
|
};
|
53
|
+
exports.ethNetworkToXchains = ethNetworkToXchains;
|
52
54
|
/**
|
53
55
|
* Validate the given address.
|
54
56
|
*
|
55
57
|
* @param {Address} address
|
56
58
|
* @returns {boolean} `true` or `false`
|
57
59
|
*/
|
58
|
-
|
60
|
+
var validateAddress = function (address) {
|
59
61
|
try {
|
60
62
|
ethers_1.ethers.utils.getAddress(address);
|
61
63
|
return true;
|
@@ -64,13 +66,14 @@ exports.validateAddress = function (address) {
|
|
64
66
|
return false;
|
65
67
|
}
|
66
68
|
};
|
69
|
+
exports.validateAddress = validateAddress;
|
67
70
|
/**
|
68
71
|
* Get token address from asset.
|
69
72
|
*
|
70
73
|
* @param {Asset} asset
|
71
74
|
* @returns {string|null} The token address.
|
72
75
|
*/
|
73
|
-
|
76
|
+
var getTokenAddress = function (asset) {
|
74
77
|
try {
|
75
78
|
// strip 0X only - 0x is still valid
|
76
79
|
return ethers_1.ethers.utils.getAddress(asset.symbol.slice(asset.ticker.length + 1).replace(/^0X/, ''));
|
@@ -79,38 +82,40 @@ exports.getTokenAddress = function (asset) {
|
|
79
82
|
return null;
|
80
83
|
}
|
81
84
|
};
|
85
|
+
exports.getTokenAddress = getTokenAddress;
|
82
86
|
/**
|
83
87
|
* Check if the symbol is valid.
|
84
88
|
*
|
85
89
|
* @param {string|null|undefined} symbol
|
86
90
|
* @returns {boolean} `true` or `false`.
|
87
91
|
*/
|
88
|
-
|
92
|
+
var validateSymbol = function (symbol) { return (symbol ? symbol.length >= 3 : false); };
|
93
|
+
exports.validateSymbol = validateSymbol;
|
89
94
|
/**
|
90
95
|
* Get transactions from token tx
|
91
96
|
*
|
92
97
|
* @param {TokenTransactionInfo} tx
|
93
98
|
* @returns {Tx|null} The parsed transaction.
|
94
99
|
*/
|
95
|
-
|
100
|
+
var getTxFromTokenTransaction = function (tx) {
|
96
101
|
var decimals = parseInt(tx.tokenDecimal) || exports.ETH_DECIMAL;
|
97
102
|
var symbol = tx.tokenSymbol;
|
98
103
|
var address = tx.contractAddress;
|
99
|
-
if (exports.validateSymbol(symbol) && exports.validateAddress(address)) {
|
100
|
-
var tokenAsset = xchain_util_1.assetFromString(xchain_util_1.ETHChain
|
104
|
+
if ((0, exports.validateSymbol)(symbol) && (0, exports.validateAddress)(address)) {
|
105
|
+
var tokenAsset = (0, xchain_util_1.assetFromString)("".concat(xchain_util_1.ETHChain, ".").concat(symbol, "-").concat(address));
|
101
106
|
if (tokenAsset) {
|
102
107
|
return {
|
103
108
|
asset: tokenAsset,
|
104
109
|
from: [
|
105
110
|
{
|
106
111
|
from: tx.from,
|
107
|
-
amount: xchain_util_1.baseAmount(tx.value, decimals),
|
112
|
+
amount: (0, xchain_util_1.baseAmount)(tx.value, decimals),
|
108
113
|
},
|
109
114
|
],
|
110
115
|
to: [
|
111
116
|
{
|
112
117
|
to: tx.to,
|
113
|
-
amount: xchain_util_1.baseAmount(tx.value, decimals),
|
118
|
+
amount: (0, xchain_util_1.baseAmount)(tx.value, decimals),
|
114
119
|
},
|
115
120
|
],
|
116
121
|
date: new Date(parseInt(tx.timeStamp) * 1000),
|
@@ -121,25 +126,26 @@ exports.getTxFromTokenTransaction = function (tx) {
|
|
121
126
|
}
|
122
127
|
return null;
|
123
128
|
};
|
129
|
+
exports.getTxFromTokenTransaction = getTxFromTokenTransaction;
|
124
130
|
/**
|
125
131
|
* Get transactions from ETH transaction
|
126
132
|
*
|
127
133
|
* @param {ETHTransactionInfo} tx
|
128
134
|
* @returns {Tx} The parsed transaction.
|
129
135
|
*/
|
130
|
-
|
136
|
+
var getTxFromEthTransaction = function (tx) {
|
131
137
|
return {
|
132
138
|
asset: xchain_util_1.AssetETH,
|
133
139
|
from: [
|
134
140
|
{
|
135
141
|
from: tx.from,
|
136
|
-
amount: xchain_util_1.baseAmount(tx.value, exports.ETH_DECIMAL),
|
142
|
+
amount: (0, xchain_util_1.baseAmount)(tx.value, exports.ETH_DECIMAL),
|
137
143
|
},
|
138
144
|
],
|
139
145
|
to: [
|
140
146
|
{
|
141
147
|
to: tx.to,
|
142
|
-
amount: xchain_util_1.baseAmount(tx.value, exports.ETH_DECIMAL),
|
148
|
+
amount: (0, xchain_util_1.baseAmount)(tx.value, exports.ETH_DECIMAL),
|
143
149
|
},
|
144
150
|
],
|
145
151
|
date: new Date(parseInt(tx.timeStamp) * 1000),
|
@@ -147,25 +153,27 @@ exports.getTxFromEthTransaction = function (tx) {
|
|
147
153
|
hash: tx.hash,
|
148
154
|
};
|
149
155
|
};
|
156
|
+
exports.getTxFromEthTransaction = getTxFromEthTransaction;
|
150
157
|
/**
|
151
158
|
* Calculate fees by multiplying .
|
152
159
|
*
|
153
160
|
* @returns {Fees} The default gas price.
|
154
161
|
*/
|
155
|
-
|
162
|
+
var getFee = function (_a) {
|
156
163
|
var gasPrice = _a.gasPrice, gasLimit = _a.gasLimit;
|
157
|
-
return xchain_util_1.baseAmount(gasPrice.amount().multipliedBy(gasLimit.toString()), exports.ETH_DECIMAL);
|
164
|
+
return (0, xchain_util_1.baseAmount)(gasPrice.amount().multipliedBy(gasLimit.toString()), exports.ETH_DECIMAL);
|
158
165
|
};
|
159
|
-
exports.
|
166
|
+
exports.getFee = getFee;
|
167
|
+
var estimateDefaultFeesWithGasPricesAndLimits = function (asset) {
|
160
168
|
var gasPrices = {
|
161
|
-
average: xchain_util_1.baseAmount(utils_1.parseUnits(exports.DEFAULT_GAS_PRICE.toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
162
|
-
fast: xchain_util_1.baseAmount(utils_1.parseUnits((exports.DEFAULT_GAS_PRICE * 2).toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
163
|
-
fastest: xchain_util_1.baseAmount(utils_1.parseUnits((exports.DEFAULT_GAS_PRICE * 3).toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
169
|
+
average: (0, xchain_util_1.baseAmount)((0, utils_1.parseUnits)(exports.DEFAULT_GAS_PRICE.toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
170
|
+
fast: (0, xchain_util_1.baseAmount)((0, utils_1.parseUnits)((exports.DEFAULT_GAS_PRICE * 2).toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
171
|
+
fastest: (0, xchain_util_1.baseAmount)((0, utils_1.parseUnits)((exports.DEFAULT_GAS_PRICE * 3).toString(), 'gwei').toString(), exports.ETH_DECIMAL),
|
164
172
|
};
|
165
173
|
var fastGP = gasPrices.fast, fastestGP = gasPrices.fastest, averageGP = gasPrices.average;
|
166
174
|
var assetAddress;
|
167
|
-
if (asset && xchain_util_1.assetToString(asset) !== xchain_util_1.assetToString(xchain_util_1.AssetETH)) {
|
168
|
-
assetAddress = exports.getTokenAddress(asset);
|
175
|
+
if (asset && (0, xchain_util_1.assetToString)(asset) !== (0, xchain_util_1.assetToString)(xchain_util_1.AssetETH)) {
|
176
|
+
assetAddress = (0, exports.getTokenAddress)(asset);
|
169
177
|
}
|
170
178
|
var gasLimit;
|
171
179
|
if (assetAddress && assetAddress !== exports.ETHAddress) {
|
@@ -179,44 +187,48 @@ exports.estimateDefaultFeesWithGasPricesAndLimits = function (asset) {
|
|
179
187
|
gasLimit: gasLimit,
|
180
188
|
fees: {
|
181
189
|
type: 'byte',
|
182
|
-
average: exports.getFee({ gasPrice: averageGP, gasLimit: gasLimit }),
|
183
|
-
fast: exports.getFee({ gasPrice: fastGP, gasLimit: gasLimit }),
|
184
|
-
fastest: exports.getFee({ gasPrice: fastestGP, gasLimit: gasLimit }),
|
190
|
+
average: (0, exports.getFee)({ gasPrice: averageGP, gasLimit: gasLimit }),
|
191
|
+
fast: (0, exports.getFee)({ gasPrice: fastGP, gasLimit: gasLimit }),
|
192
|
+
fastest: (0, exports.getFee)({ gasPrice: fastestGP, gasLimit: gasLimit }),
|
185
193
|
},
|
186
194
|
};
|
187
195
|
};
|
196
|
+
exports.estimateDefaultFeesWithGasPricesAndLimits = estimateDefaultFeesWithGasPricesAndLimits;
|
188
197
|
/**
|
189
198
|
* Get the default fees.
|
190
199
|
*
|
191
200
|
* @returns {Fees} The default gas price.
|
192
201
|
*/
|
193
|
-
|
194
|
-
var fees = exports.estimateDefaultFeesWithGasPricesAndLimits(asset).fees;
|
202
|
+
var getDefaultFees = function (asset) {
|
203
|
+
var fees = (0, exports.estimateDefaultFeesWithGasPricesAndLimits)(asset).fees;
|
195
204
|
return fees;
|
196
205
|
};
|
206
|
+
exports.getDefaultFees = getDefaultFees;
|
197
207
|
/**
|
198
208
|
* Get the default gas price.
|
199
209
|
*
|
200
210
|
* @returns {Fees} The default gas prices.
|
201
211
|
*/
|
202
|
-
|
203
|
-
var gasPrices = exports.estimateDefaultFeesWithGasPricesAndLimits(asset).gasPrices;
|
212
|
+
var getDefaultGasPrices = function (asset) {
|
213
|
+
var gasPrices = (0, exports.estimateDefaultFeesWithGasPricesAndLimits)(asset).gasPrices;
|
204
214
|
return gasPrices;
|
205
215
|
};
|
216
|
+
exports.getDefaultGasPrices = getDefaultGasPrices;
|
206
217
|
/**
|
207
218
|
* Get address prefix based on the network.
|
208
219
|
*
|
209
220
|
* @returns {string} The address prefix based on the network.
|
210
221
|
*
|
211
222
|
**/
|
212
|
-
|
223
|
+
var getPrefix = function () { return '0x'; };
|
224
|
+
exports.getPrefix = getPrefix;
|
213
225
|
/**
|
214
226
|
* Filter self txs
|
215
227
|
*
|
216
228
|
* @returns {T[]}
|
217
229
|
*
|
218
230
|
**/
|
219
|
-
|
231
|
+
var filterSelfTxs = function (txs) {
|
220
232
|
var filterTxs = txs.filter(function (tx) { return tx.from !== tx.to; });
|
221
233
|
var selfTxs = txs.filter(function (tx) { return tx.from === tx.to; });
|
222
234
|
var _loop_1 = function () {
|
@@ -229,6 +241,7 @@ exports.filterSelfTxs = function (txs) {
|
|
229
241
|
}
|
230
242
|
return filterTxs;
|
231
243
|
};
|
244
|
+
exports.filterSelfTxs = filterSelfTxs;
|
232
245
|
exports.erc20ABI = [
|
233
246
|
{
|
234
247
|
"inputs": [],
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pioneer-platform/eth-network",
|
3
|
-
"version": "8.1.
|
3
|
+
"version": "8.1.58",
|
4
4
|
"main": "./lib/index.js",
|
5
5
|
"types": "./lib/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -15,10 +15,10 @@
|
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
17
|
"@ethersproject/providers": "^5.1.0",
|
18
|
-
"@pioneer-platform/blockbook": "^8.1.
|
19
|
-
"@pioneer-platform/loggerdog": "^8.1.
|
18
|
+
"@pioneer-platform/blockbook": "^8.1.48",
|
19
|
+
"@pioneer-platform/loggerdog": "^8.1.28",
|
20
20
|
"@xchainjs/xchain-util": "^0.2.6",
|
21
|
-
"axios": "^
|
21
|
+
"axios": "^1.3.4",
|
22
22
|
"dotenv": "^8.2.0",
|
23
23
|
"ethers": "^5.1.0",
|
24
24
|
"request-promise": "^4.2.6",
|
@@ -28,8 +28,8 @@
|
|
28
28
|
},
|
29
29
|
"devDependencies": {
|
30
30
|
"@types/node": "^13.13.48",
|
31
|
-
"ts-node": "^
|
32
|
-
"typescript": "^
|
31
|
+
"ts-node": "^10.9.1",
|
32
|
+
"typescript": "^5.0.2"
|
33
33
|
},
|
34
34
|
"description": "",
|
35
35
|
"keywords": [
|
@@ -37,5 +37,5 @@
|
|
37
37
|
],
|
38
38
|
"author": "Bithighlander <pioneer@gmail.com>",
|
39
39
|
"license": "GPL",
|
40
|
-
"gitHead": "
|
40
|
+
"gitHead": "f597e5ae9021d4f4be4fef03516e064a9bdd7af0"
|
41
41
|
}
|