@pioneer-platform/eth-network 8.13.13 → 8.13.15
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/CHANGELOG.md +16 -0
- package/lib/constant.d.ts +208 -0
- package/lib/constant.js +553 -0
- package/lib/etherscan-api.d.ts +58 -0
- package/lib/etherscan-api.js +103 -0
- package/lib/index.d.ts +146 -0
- package/lib/index.js +1097 -0
- package/lib/node-health.d.ts +44 -0
- package/lib/node-health.js +257 -0
- package/lib/types/client-types.d.ts +61 -0
- package/lib/types/client-types.js +8 -0
- package/lib/types/etherscan-api-types.d.ts +55 -0
- package/lib/types/etherscan-api-types.js +2 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +18 -0
- package/lib/utils.d.ts +135 -0
- package/lib/utils.js +470 -0
- package/package.json +2 -2
- package/tsconfig.json +9 -16
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTokenTransactionHistory = exports.getETHTransactionHistory = exports.getTokenBalance = exports.getGasOracle = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const lib_1 = require("@xchainjs/xchain-util/lib");
|
|
10
|
+
const getApiKeyQueryParameter = (apiKey) => (!!apiKey ? `&apiKey=${apiKey}` : '');
|
|
11
|
+
/**
|
|
12
|
+
* SafeGasPrice, ProposeGasPrice And FastGasPrice returned in string-Gwei
|
|
13
|
+
*
|
|
14
|
+
* @see https://etherscan.io/apis#gastracker
|
|
15
|
+
*
|
|
16
|
+
* @param {string} baseUrl The etherscan node url.
|
|
17
|
+
* @param {string} apiKey The etherscan API key. (optional)
|
|
18
|
+
* @returns {GasOracleResponse} LastBlock, SafeGasPrice, ProposeGasPrice, FastGasPrice
|
|
19
|
+
*/
|
|
20
|
+
const getGasOracle = (baseUrl, apiKey) => {
|
|
21
|
+
const url = baseUrl + '/api?module=gastracker&action=gasoracle';
|
|
22
|
+
return axios_1.default.get(url + getApiKeyQueryParameter(apiKey)).then((response) => response.data.result);
|
|
23
|
+
};
|
|
24
|
+
exports.getGasOracle = getGasOracle;
|
|
25
|
+
/**
|
|
26
|
+
* Get token balance
|
|
27
|
+
*
|
|
28
|
+
* @see https://etherscan.io/apis#tokens
|
|
29
|
+
*
|
|
30
|
+
* @param {string} baseUrl The etherscan node url.
|
|
31
|
+
* @param {string} address The address.
|
|
32
|
+
* @param {string} assetAddress The token contract address.
|
|
33
|
+
* @param {string} apiKey The etherscan API key. (optional)
|
|
34
|
+
* @returns {BigNumberish} The token balance
|
|
35
|
+
*/
|
|
36
|
+
const getTokenBalance = ({ baseUrl, address, assetAddress, apiKey, }) => {
|
|
37
|
+
const url = baseUrl + `/api?module=account&action=tokenbalance&contractaddress=${assetAddress}&address=${address}`;
|
|
38
|
+
return axios_1.default.get(url + getApiKeyQueryParameter(apiKey)).then((response) => response.data.result);
|
|
39
|
+
};
|
|
40
|
+
exports.getTokenBalance = getTokenBalance;
|
|
41
|
+
/**
|
|
42
|
+
* Get ETH transaction history
|
|
43
|
+
*
|
|
44
|
+
* @see https://etherscan.io/apis#accounts
|
|
45
|
+
*
|
|
46
|
+
* @param {string} baseUrl The etherscan node url.
|
|
47
|
+
* @param {string} address The address.
|
|
48
|
+
* @param {TransactionHistoryParam} params The search options.
|
|
49
|
+
* @param {string} apiKey The etherscan API key. (optional)
|
|
50
|
+
* @returns {Array<ETHTransactionInfo>} The ETH transaction history
|
|
51
|
+
*/
|
|
52
|
+
const getETHTransactionHistory = async ({ baseUrl, address, page, offset, startblock, endblock, apiKey, }) => {
|
|
53
|
+
let url = baseUrl + `/api?module=account&action=txlist&sort=desc` + getApiKeyQueryParameter(apiKey);
|
|
54
|
+
if (address)
|
|
55
|
+
url += `&address=${address}`;
|
|
56
|
+
if (offset)
|
|
57
|
+
url += `&offset=${offset}`;
|
|
58
|
+
if (page)
|
|
59
|
+
url += `&page=${page}`;
|
|
60
|
+
if (startblock)
|
|
61
|
+
url += `&startblock=${startblock}`;
|
|
62
|
+
if (endblock)
|
|
63
|
+
url += `&endblock=${endblock}`;
|
|
64
|
+
const ethTransactions = await axios_1.default.get(url).then((response) => response.data.result);
|
|
65
|
+
return (0, utils_1.filterSelfTxs)(ethTransactions)
|
|
66
|
+
.filter((tx) => !(0, lib_1.bn)(tx.value).isZero())
|
|
67
|
+
.map(utils_1.getTxFromEthTransaction);
|
|
68
|
+
};
|
|
69
|
+
exports.getETHTransactionHistory = getETHTransactionHistory;
|
|
70
|
+
/**
|
|
71
|
+
* Get token transaction history
|
|
72
|
+
*
|
|
73
|
+
* @see https://etherscan.io/apis#accounts
|
|
74
|
+
*
|
|
75
|
+
* @param {string} baseUrl The etherscan node url.
|
|
76
|
+
* @param {string} address The address.
|
|
77
|
+
* @param {TransactionHistoryParam} params The search options.
|
|
78
|
+
* @param {string} apiKey The etherscan API key. (optional)
|
|
79
|
+
* @returns {Array<Txs>} The token transaction history
|
|
80
|
+
*/
|
|
81
|
+
const getTokenTransactionHistory = async ({ baseUrl, address, assetAddress, page, offset, startblock, endblock, apiKey, }) => {
|
|
82
|
+
let url = baseUrl + `/api?module=account&action=tokentx&sort=desc` + getApiKeyQueryParameter(apiKey);
|
|
83
|
+
if (address)
|
|
84
|
+
url += `&address=${address}`;
|
|
85
|
+
if (assetAddress)
|
|
86
|
+
url += `&contractaddress=${assetAddress}`;
|
|
87
|
+
if (offset)
|
|
88
|
+
url += `&offset=${offset}`;
|
|
89
|
+
if (page)
|
|
90
|
+
url += `&page=${page}`;
|
|
91
|
+
if (startblock)
|
|
92
|
+
url += `&startblock=${startblock}`;
|
|
93
|
+
if (endblock)
|
|
94
|
+
url += `&endblock=${endblock}`;
|
|
95
|
+
const tokenTransactions = await axios_1.default.get(url).then((response) => response.data.result);
|
|
96
|
+
return (0, utils_1.filterSelfTxs)(tokenTransactions)
|
|
97
|
+
.filter((tx) => !(0, lib_1.bn)(tx.value).isZero())
|
|
98
|
+
.reduce((acc, cur) => {
|
|
99
|
+
const tx = (0, utils_1.getTxFromTokenTransaction)(cur);
|
|
100
|
+
return tx ? [...acc, tx] : acc;
|
|
101
|
+
}, []);
|
|
102
|
+
};
|
|
103
|
+
exports.getTokenTransactionHistory = getTokenTransactionHistory;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
|
+
import { TieredNode } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize the ETH network module
|
|
5
|
+
*/
|
|
6
|
+
export declare const init: (settings: any, redis?: any) => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Get registered nodes
|
|
9
|
+
*/
|
|
10
|
+
export declare const getNodes: () => TieredNode[];
|
|
11
|
+
/**
|
|
12
|
+
* Add a single node
|
|
13
|
+
*/
|
|
14
|
+
export declare const addNode: (node: any) => number;
|
|
15
|
+
/**
|
|
16
|
+
* Add multiple nodes
|
|
17
|
+
*/
|
|
18
|
+
export declare const addNodes: (nodeList: any) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Get nonce for address
|
|
21
|
+
*/
|
|
22
|
+
export declare const getNonce: (address: string) => Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Get transaction count by network
|
|
25
|
+
*/
|
|
26
|
+
export declare const getNonceByNetwork: (networkId: string, address: string) => Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Get current gas price
|
|
29
|
+
*/
|
|
30
|
+
export declare const getGasPrice: () => Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Get gas price by network - with retry logic across multiple nodes
|
|
33
|
+
*/
|
|
34
|
+
export declare const getGasPriceByNetwork: (networkId: string) => Promise<import("@ethersproject/bignumber/lib/bignumber").BigNumber>;
|
|
35
|
+
/**
|
|
36
|
+
* Estimate fee for transaction
|
|
37
|
+
*/
|
|
38
|
+
export declare const estimateFee: (asset: any, params: any) => Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Get ETH balance for address
|
|
41
|
+
*/
|
|
42
|
+
export declare const getBalance: (address: string) => Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Get balances for multiple addresses
|
|
45
|
+
*/
|
|
46
|
+
export declare const getBalances: (addresses: string[]) => Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Get ERC20 token balance
|
|
49
|
+
*/
|
|
50
|
+
export declare const getBalanceToken: (address: string, tokenAddress: string) => Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Get ERC20 allowance
|
|
53
|
+
*/
|
|
54
|
+
export declare const getAllowance: (tokenAddress: string, spender: string, sender: string) => Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Get symbol from contract address
|
|
57
|
+
*/
|
|
58
|
+
export declare const getSymbolFromContract: (contractAddress: string) => Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Get transaction by hash
|
|
61
|
+
*/
|
|
62
|
+
export declare const getTransaction: (txid: string) => Promise<{
|
|
63
|
+
tx: any;
|
|
64
|
+
receipt: any;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Broadcast signed transaction
|
|
68
|
+
*/
|
|
69
|
+
export declare const broadcast: (tx: string) => Promise<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Get ERC20 transfer data (for building unsigned transactions)
|
|
72
|
+
*/
|
|
73
|
+
export declare const getTransferData: (toAddress: string, amount: string, contractAddress: string) => string;
|
|
74
|
+
/**
|
|
75
|
+
* Encode memo data for THORChain/Maya swaps
|
|
76
|
+
*/
|
|
77
|
+
export declare const getMemoEncoded: (swap: any) => Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Get ETH balance by network - with parallel racing logic
|
|
80
|
+
*/
|
|
81
|
+
export declare const getBalanceAddressByNetwork: (networkId: string, address: string) => Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Get ERC20 token balance by network
|
|
84
|
+
*/
|
|
85
|
+
export declare const getBalanceTokenByNetwork: (networkId: string, address: string, tokenAddress: string) => Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Get all ERC20 token balances by network (returns empty array for now - requires token list)
|
|
88
|
+
*/
|
|
89
|
+
export declare const getBalanceTokensByNetwork: (networkId: string, address: string) => Promise<any[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Get ERC20 token decimals by network - CRITICAL for correct amount calculations
|
|
92
|
+
*/
|
|
93
|
+
export declare const getTokenDecimalsByNetwork: (networkId: string, tokenAddress: string) => Promise<number>;
|
|
94
|
+
/**
|
|
95
|
+
* Get comprehensive ERC20 token metadata from contract address
|
|
96
|
+
* Fetches name, symbol, decimals, and can check balance for a user address
|
|
97
|
+
*/
|
|
98
|
+
export declare const getTokenMetadata: (networkId: string, contractAddress: string, userAddress?: string) => Promise<any>;
|
|
99
|
+
/**
|
|
100
|
+
* Get token metadata by network with balance check
|
|
101
|
+
* Convenience wrapper for getTokenMetadata
|
|
102
|
+
*/
|
|
103
|
+
export declare const getTokenMetadataByNetwork: (networkId: string, contractAddress: string, userAddress?: string) => Promise<any>;
|
|
104
|
+
/**
|
|
105
|
+
* Estimate gas by network
|
|
106
|
+
*/
|
|
107
|
+
export declare const estimateGasByNetwork: (networkId: string, transaction: any) => Promise<import("@ethersproject/bignumber/lib/bignumber").BigNumber>;
|
|
108
|
+
/**
|
|
109
|
+
* Broadcast transaction by network
|
|
110
|
+
*/
|
|
111
|
+
export declare const broadcastByNetwork: (networkId: string, signedTx: string) => Promise<{
|
|
112
|
+
success: boolean;
|
|
113
|
+
txid: string;
|
|
114
|
+
transactionHash: string;
|
|
115
|
+
from: string;
|
|
116
|
+
to: string;
|
|
117
|
+
nonce: number;
|
|
118
|
+
gasLimit: string;
|
|
119
|
+
gasPrice: string;
|
|
120
|
+
chainId: number;
|
|
121
|
+
error?: undefined;
|
|
122
|
+
} | {
|
|
123
|
+
success: boolean;
|
|
124
|
+
error: any;
|
|
125
|
+
txid?: undefined;
|
|
126
|
+
transactionHash?: undefined;
|
|
127
|
+
from?: undefined;
|
|
128
|
+
to?: undefined;
|
|
129
|
+
nonce?: undefined;
|
|
130
|
+
gasLimit?: undefined;
|
|
131
|
+
gasPrice?: undefined;
|
|
132
|
+
chainId?: undefined;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Get transaction by network and txid
|
|
136
|
+
*/
|
|
137
|
+
export declare const getTransactionByNetwork: (networkId: string, txid: string) => Promise<{
|
|
138
|
+
tx: ethers.ethers.providers.TransactionResponse;
|
|
139
|
+
receipt: ethers.ethers.providers.TransactionReceipt;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Get transaction history by network
|
|
143
|
+
*/
|
|
144
|
+
export declare const getTransactionsByNetwork: (networkId: string, address: string, options?: any) => Promise<any>;
|
|
145
|
+
export declare const getBalanceAddress: (address: string) => Promise<string>;
|
|
146
|
+
export declare const getFees: (asset: any, params: any) => Promise<any>;
|