essential-eth 0.9.2-beta.1 → 0.9.2-beta.3
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/cjs/classes/Contract.js +139 -0
- package/dist/cjs/classes/test/Contract/crv-abi.js +488 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +453 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +526 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +42 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +121 -0
- package/dist/cjs/classes/utils/clean-block.js +160 -0
- package/dist/cjs/classes/utils/clean-log.js +39 -0
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +53 -0
- package/dist/cjs/classes/utils/clean-transaction.js +54 -0
- package/dist/cjs/classes/utils/encode-decode-transaction.js +175 -0
- package/dist/cjs/classes/utils/fetchers.js +85 -0
- package/dist/cjs/classes/utils/hex-to-decimal.js +24 -0
- package/dist/cjs/classes/utils/prepare-transaction.js +47 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.umd.js +2 -0
- package/dist/cjs/index.umd.js.map +1 -0
- package/dist/cjs/logger/logger.js +37 -0
- package/dist/cjs/logger/package-version.d.ts +1 -0
- package/dist/cjs/logger/package-version.js +5 -0
- package/dist/cjs/providers/AlchemyProvider.js +11 -0
- package/dist/cjs/providers/BaseProvider.js +514 -0
- package/dist/cjs/providers/FallthroughProvider.js +74 -0
- package/dist/cjs/providers/JsonRpcProvider.js +46 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +152 -0
- package/dist/cjs/providers/test/mock-of.js +12 -0
- package/dist/cjs/providers/test/rpc-urls.js +25 -0
- package/dist/cjs/providers/utils/chains-info.js +71 -0
- package/dist/cjs/shared/tiny-big/helpers.js +97 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +101 -0
- package/dist/cjs/shared/validate-type.js +9 -0
- package/dist/cjs/types/Block.types.js +2 -0
- package/dist/cjs/types/Contract.types.js +2 -0
- package/dist/cjs/types/FeeData.types.js +2 -0
- package/dist/cjs/types/Filter.types.js +2 -0
- package/dist/cjs/types/Network.types.js +2 -0
- package/dist/cjs/types/Transaction.types.js +2 -0
- package/dist/cjs/utils/bytes.js +711 -0
- package/dist/cjs/utils/compute-address.js +34 -0
- package/dist/cjs/utils/compute-public-key.js +26 -0
- package/dist/cjs/utils/ether-to-gwei.js +35 -0
- package/dist/cjs/utils/ether-to-wei.js +35 -0
- package/dist/cjs/utils/gwei-to-ether.js +35 -0
- package/dist/cjs/utils/hash-message.js +30 -0
- package/dist/cjs/utils/is-address.js +39 -0
- package/dist/cjs/utils/keccak256.js +31 -0
- package/dist/cjs/utils/solidity-keccak256.js +138 -0
- package/dist/cjs/utils/split-signature.js +163 -0
- package/dist/cjs/utils/to-checksum-address.js +46 -0
- package/dist/cjs/utils/to-utf8-bytes.js +21 -0
- package/dist/cjs/utils/wei-to-ether.js +45 -0
- package/dist/esm/classes/Contract.d.ts +11 -0
- package/dist/esm/classes/Contract.js +58 -0
- package/dist/esm/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/crv-abi.js +470 -0
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/ens-abi.js +435 -0
- package/dist/esm/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/fei-abi.js +521 -0
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/foo-abi.js +33 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.js +116 -0
- package/dist/esm/classes/utils/clean-block.d.ts +2 -0
- package/dist/esm/classes/utils/clean-block.js +35 -0
- package/dist/esm/classes/utils/clean-log.d.ts +2 -0
- package/dist/esm/classes/utils/clean-log.js +28 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.js +37 -0
- package/dist/esm/classes/utils/clean-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction.js +36 -0
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +4 -0
- package/dist/esm/classes/utils/encode-decode-transaction.js +132 -0
- package/dist/esm/classes/utils/fetchers.d.ts +15 -0
- package/dist/esm/classes/utils/fetchers.js +37 -0
- package/dist/esm/classes/utils/hex-to-decimal.d.ts +1 -0
- package/dist/esm/classes/utils/hex-to-decimal.js +3 -0
- package/dist/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/prepare-transaction.js +36 -0
- package/dist/{index.d.ts → esm/index.d.ts} +24 -25
- package/dist/esm/index.js +19 -0
- package/dist/esm/logger/logger.d.ts +11 -0
- package/dist/esm/logger/logger.js +34 -0
- package/dist/esm/logger/package-version.d.ts +1 -0
- package/dist/esm/logger/package-version.js +1 -0
- package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
- package/dist/esm/providers/AlchemyProvider.js +7 -0
- package/dist/esm/providers/BaseProvider.d.ts +26 -0
- package/dist/esm/providers/BaseProvider.js +137 -0
- package/dist/esm/providers/FallthroughProvider.d.ts +11 -0
- package/dist/esm/providers/FallthroughProvider.js +50 -0
- package/dist/esm/providers/JsonRpcProvider.d.ts +7 -0
- package/dist/esm/providers/JsonRpcProvider.js +15 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
- package/dist/esm/providers/test/mock-of.d.ts +2 -0
- package/dist/esm/providers/test/mock-of.js +1 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +12 -0
- package/dist/esm/providers/test/rpc-urls.js +19 -0
- package/dist/esm/providers/utils/chains-info.d.ts +24 -0
- package/dist/esm/providers/utils/chains-info.js +67 -0
- package/dist/esm/shared/tiny-big/helpers.d.ts +1 -0
- package/dist/esm/shared/tiny-big/helpers.js +58 -0
- package/dist/esm/shared/tiny-big/tiny-big.d.ts +10 -0
- package/dist/esm/shared/tiny-big/tiny-big.js +45 -0
- package/dist/esm/shared/validate-type.d.ts +3 -0
- package/dist/esm/shared/validate-type.js +5 -0
- package/dist/esm/types/Block.types.d.ts +40 -0
- package/dist/esm/types/Block.types.js +1 -0
- package/dist/esm/types/Contract.types.d.ts +24 -0
- package/dist/esm/types/Contract.types.js +1 -0
- package/dist/esm/types/FeeData.types.d.ts +7 -0
- package/dist/esm/types/FeeData.types.js +1 -0
- package/dist/esm/types/Filter.types.d.ts +12 -0
- package/dist/esm/types/Filter.types.js +1 -0
- package/dist/esm/types/Network.types.d.ts +5 -0
- package/dist/esm/types/Network.types.js +1 -0
- package/dist/esm/types/Transaction.types.d.ts +113 -0
- package/dist/esm/types/Transaction.types.js +1 -0
- package/dist/esm/utils/bytes.d.ts +40 -0
- package/dist/esm/utils/bytes.js +245 -0
- package/dist/esm/utils/compute-address.d.ts +1 -0
- package/dist/esm/utils/compute-address.js +12 -0
- package/dist/esm/utils/compute-public-key.d.ts +2 -0
- package/dist/esm/utils/compute-public-key.js +6 -0
- package/dist/esm/utils/ether-to-gwei.d.ts +3 -0
- package/dist/esm/utils/ether-to-gwei.js +7 -0
- package/dist/esm/utils/ether-to-wei.d.ts +3 -0
- package/dist/esm/utils/ether-to-wei.js +7 -0
- package/dist/esm/utils/gwei-to-ether.d.ts +3 -0
- package/dist/esm/utils/gwei-to-ether.js +7 -0
- package/dist/esm/utils/hash-message.d.ts +2 -0
- package/dist/esm/utils/hash-message.js +14 -0
- package/dist/esm/utils/is-address.d.ts +1 -0
- package/dist/esm/utils/is-address.js +12 -0
- package/dist/esm/utils/keccak256.d.ts +2 -0
- package/dist/esm/utils/keccak256.js +13 -0
- package/dist/esm/utils/solidity-keccak256.d.ts +2 -0
- package/dist/esm/utils/solidity-keccak256.js +85 -0
- package/dist/esm/utils/split-signature.d.ts +2 -0
- package/dist/esm/utils/split-signature.js +126 -0
- package/dist/esm/utils/to-checksum-address.d.ts +1 -0
- package/dist/esm/utils/to-checksum-address.js +25 -0
- package/dist/esm/utils/to-utf8-bytes.d.ts +1 -0
- package/dist/esm/utils/to-utf8-bytes.js +3 -0
- package/dist/esm/utils/wei-to-ether.d.ts +3 -0
- package/dist/esm/utils/wei-to-ether.js +16 -0
- package/package.json +16 -14
- package/readme.md +2 -2
- package/dist/essential-eth.esm.mjs +0 -2
- package/dist/essential-eth.esm.mjs.map +0 -1
- package/dist/essential-eth.js +0 -2
- package/dist/essential-eth.js.map +0 -1
- package/dist/essential-eth.modern.mjs +0 -2
- package/dist/essential-eth.modern.mjs.map +0 -1
- package/dist/essential-eth.umd.js +0 -2
- package/dist/essential-eth.umd.js.map +0 -1
- package/dist/logger/package-version.d.ts +0 -1
- /package/dist/{classes → cjs/classes}/Contract.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/test/Contract/crv-abi.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/test/Contract/ens-abi.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/test/Contract/fei-abi.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/test/Contract/foo-abi.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/test/Contract/uniswap-abi.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/clean-block.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/clean-log.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/clean-transaction-receipt.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/clean-transaction.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/encode-decode-transaction.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/fetchers.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/hex-to-decimal.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/utils/prepare-transaction.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/logger.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/AlchemyProvider.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/BaseProvider.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/FallthroughProvider.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/JsonRpcProvider.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/test/json-rpc-provider/get-logs/mocks.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/test/mock-of.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/test/rpc-urls.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/utils/chains-info.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/tiny-big/helpers.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/tiny-big/tiny-big.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/validate-type.d.ts +0 -0
- /package/dist/{types → cjs/types}/Block.types.d.ts +0 -0
- /package/dist/{types → cjs/types}/Contract.types.d.ts +0 -0
- /package/dist/{types → cjs/types}/FeeData.types.d.ts +0 -0
- /package/dist/{types → cjs/types}/Filter.types.d.ts +0 -0
- /package/dist/{types → cjs/types}/Network.types.d.ts +0 -0
- /package/dist/{types → cjs/types}/Transaction.types.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/bytes.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/compute-address.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/compute-public-key.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/ether-to-gwei.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/ether-to-wei.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/gwei-to-ether.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/hash-message.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/is-address.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/keccak256.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/solidity-keccak256.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/split-signature.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/to-checksum-address.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/to-utf8-bytes.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/wei-to-ether.d.ts +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
+
import { cleanTransaction } from './clean-transaction';
|
|
4
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
+
export function cleanBlock(block, returnTransactionObjects) {
|
|
6
|
+
const cleanedBlock = { ...block };
|
|
7
|
+
Object.keys(block).forEach((key) => {
|
|
8
|
+
if (!block[key])
|
|
9
|
+
return;
|
|
10
|
+
switch (key) {
|
|
11
|
+
case 'difficulty':
|
|
12
|
+
case 'totalDifficulty':
|
|
13
|
+
case 'gasLimit':
|
|
14
|
+
case 'gasUsed':
|
|
15
|
+
case 'size':
|
|
16
|
+
case 'timestamp':
|
|
17
|
+
case 'baseFeePerGas':
|
|
18
|
+
cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
|
|
19
|
+
break;
|
|
20
|
+
case 'number':
|
|
21
|
+
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
22
|
+
break;
|
|
23
|
+
case 'miner':
|
|
24
|
+
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (returnTransactionObjects) {
|
|
29
|
+
const txns = block.transactions;
|
|
30
|
+
txns.forEach((transaction, index) => {
|
|
31
|
+
cleanedBlock.transactions[index] = cleanTransaction(transaction);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return cleanedBlock;
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
2
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
+
export function cleanLog(log, receiptLog) {
|
|
4
|
+
const cleanedLog = {
|
|
5
|
+
...log,
|
|
6
|
+
};
|
|
7
|
+
Object.keys(log).forEach((key) => {
|
|
8
|
+
switch (key) {
|
|
9
|
+
case 'address':
|
|
10
|
+
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
11
|
+
break;
|
|
12
|
+
case 'blockNumber':
|
|
13
|
+
case 'logIndex':
|
|
14
|
+
case 'transactionIndex':
|
|
15
|
+
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
16
|
+
break;
|
|
17
|
+
case 'removed':
|
|
18
|
+
if (receiptLog) {
|
|
19
|
+
delete cleanedLog[key];
|
|
20
|
+
}
|
|
21
|
+
else if (log[key] == null) {
|
|
22
|
+
cleanedLog[key] === false;
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return cleanedLog;
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
+
import { cleanLog } from './clean-log';
|
|
4
|
+
import { cleanTransaction } from './clean-transaction';
|
|
5
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
6
|
+
export function cleanTransactionReceipt(transactionReceipt) {
|
|
7
|
+
const cleanedTransaction = cleanTransaction(transactionReceipt);
|
|
8
|
+
const cleanedTransactionReceipt = {
|
|
9
|
+
...cleanedTransaction,
|
|
10
|
+
};
|
|
11
|
+
Object.keys(transactionReceipt).forEach((key) => {
|
|
12
|
+
if (!transactionReceipt[key])
|
|
13
|
+
return;
|
|
14
|
+
switch (key) {
|
|
15
|
+
case 'status':
|
|
16
|
+
cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
|
|
17
|
+
break;
|
|
18
|
+
case 'contractAddress':
|
|
19
|
+
if (transactionReceipt[key]) {
|
|
20
|
+
cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
case 'cumulativeGasUsed':
|
|
24
|
+
case 'effectiveGasPrice':
|
|
25
|
+
case 'gasUsed':
|
|
26
|
+
cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
|
|
27
|
+
break;
|
|
28
|
+
case 'logs':
|
|
29
|
+
transactionReceipt[key].forEach((log, index) => {
|
|
30
|
+
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
cleanedTransactionReceipt.byzantium =
|
|
35
|
+
cleanedTransactionReceipt.blockNumber >= 4370000;
|
|
36
|
+
return cleanedTransactionReceipt;
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
4
|
+
export function cleanTransaction(transaction) {
|
|
5
|
+
const cleanedTransaction = {
|
|
6
|
+
...transaction,
|
|
7
|
+
};
|
|
8
|
+
Object.keys(transaction).forEach((key) => {
|
|
9
|
+
if (!transaction[key])
|
|
10
|
+
return;
|
|
11
|
+
switch (key) {
|
|
12
|
+
case 'blockNumber':
|
|
13
|
+
case 'chainId':
|
|
14
|
+
case 'transactionIndex':
|
|
15
|
+
case 'type':
|
|
16
|
+
case 'v':
|
|
17
|
+
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
18
|
+
break;
|
|
19
|
+
case 'from':
|
|
20
|
+
case 'to':
|
|
21
|
+
if (transaction[key]) {
|
|
22
|
+
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
case 'value':
|
|
26
|
+
case 'gas':
|
|
27
|
+
case 'gasPrice':
|
|
28
|
+
case 'maxFeePerGas':
|
|
29
|
+
case 'maxPriorityFeePerGas':
|
|
30
|
+
case 'nonce':
|
|
31
|
+
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return cleanedTransaction;
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { JSONABIArgument } from '../../types/Contract.types';
|
|
2
|
+
export declare const hexFalse: string;
|
|
3
|
+
export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
|
|
4
|
+
export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig | (string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig)[];
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Keccak } from 'sha3';
|
|
2
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
4
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
+
export const hexFalse = '0'.repeat(64);
|
|
6
|
+
const hexTrue = '0'.repeat(63) + '1';
|
|
7
|
+
function hexToUtf8(hex) {
|
|
8
|
+
let str = '';
|
|
9
|
+
let i = 0;
|
|
10
|
+
const l = hex.length;
|
|
11
|
+
if (hex.substring(0, 2) === '0x') {
|
|
12
|
+
i = 2;
|
|
13
|
+
}
|
|
14
|
+
for (; i < l; i += 2) {
|
|
15
|
+
const code = parseInt(hex.substr(i, 2), 16);
|
|
16
|
+
if (code === 0)
|
|
17
|
+
continue;
|
|
18
|
+
str += String.fromCharCode(code);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(escape(str));
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function expandType(type) {
|
|
28
|
+
if (type === 'uint[]') {
|
|
29
|
+
return 'uint256[]';
|
|
30
|
+
}
|
|
31
|
+
else if (type === 'int[]') {
|
|
32
|
+
return 'int256[]';
|
|
33
|
+
}
|
|
34
|
+
return type;
|
|
35
|
+
}
|
|
36
|
+
export function encodeData(jsonABIArgument, args) {
|
|
37
|
+
const hash = new Keccak(256);
|
|
38
|
+
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
|
|
39
|
+
const functionHash = hash.update(functionString).digest('hex');
|
|
40
|
+
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
41
|
+
let shouldValidateInputLength = true;
|
|
42
|
+
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
43
|
+
shouldValidateInputLength = false;
|
|
44
|
+
}
|
|
45
|
+
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
46
|
+
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
47
|
+
}
|
|
48
|
+
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
49
|
+
if (input.type.includes('[')) {
|
|
50
|
+
const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1];
|
|
51
|
+
args.forEach((arg) => {
|
|
52
|
+
acc = acc.concat([[arg, basicType]]);
|
|
53
|
+
});
|
|
54
|
+
return acc;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return acc.concat([[args[i], input.type]]);
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
61
|
+
let rawArg = arg;
|
|
62
|
+
switch (inputType) {
|
|
63
|
+
case 'bool':
|
|
64
|
+
return arg ? hexTrue : hexFalse;
|
|
65
|
+
case 'address':
|
|
66
|
+
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
if (inputType.startsWith('bytes')) {
|
|
70
|
+
const argEncoded = rawArg
|
|
71
|
+
.split('')
|
|
72
|
+
.map((character) => character.charCodeAt(0).toString(16))
|
|
73
|
+
.join('');
|
|
74
|
+
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
75
|
+
return paddedEncodedArg;
|
|
76
|
+
}
|
|
77
|
+
else if (inputType === 'uint256') {
|
|
78
|
+
const argEncoded = BigInt(arg).toString(16);
|
|
79
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
80
|
+
return paddedEncodedArg;
|
|
81
|
+
}
|
|
82
|
+
else if (inputType.startsWith('uint')) {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const argEncoded = rawArg.toString(16);
|
|
90
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
91
|
+
return paddedEncodedArg;
|
|
92
|
+
});
|
|
93
|
+
const functionEncoded = functionHash.slice(0, 8);
|
|
94
|
+
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
98
|
+
const rawOutputs = jsonABIArgument.outputs;
|
|
99
|
+
const slicedResponse = nodeResponse.slice(2);
|
|
100
|
+
if (jsonABIArgument?.outputs?.length === 1 &&
|
|
101
|
+
jsonABIArgument.outputs[0].type === 'string') {
|
|
102
|
+
const [hexOffset, responseData] = [
|
|
103
|
+
slicedResponse.slice(0, 64),
|
|
104
|
+
slicedResponse.slice(64),
|
|
105
|
+
];
|
|
106
|
+
const decimalOffset = Number(hexToDecimal(`0x${hexOffset}`));
|
|
107
|
+
const hexLength = responseData.slice(0, decimalOffset * 2);
|
|
108
|
+
const decimalLength = Number(hexToDecimal(`0x${hexLength}`));
|
|
109
|
+
const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
|
|
110
|
+
return hexToUtf8(hexToDecode);
|
|
111
|
+
}
|
|
112
|
+
const encodedOutputs = slicedResponse.match(/.{1,64}/g);
|
|
113
|
+
const outputs = (encodedOutputs || []).map((output, i) => {
|
|
114
|
+
const outputType = (rawOutputs || [])[i].type;
|
|
115
|
+
switch (outputType) {
|
|
116
|
+
case 'bool':
|
|
117
|
+
return output === hexTrue;
|
|
118
|
+
case 'address':
|
|
119
|
+
return toChecksumAddress(`0x${output.slice(24)}`);
|
|
120
|
+
case 'uint256':
|
|
121
|
+
case 'uint120':
|
|
122
|
+
return tinyBig(hexToDecimal(`0x${output}`));
|
|
123
|
+
case 'bytes32':
|
|
124
|
+
return `0x${output}`;
|
|
125
|
+
case 'uint8':
|
|
126
|
+
return Number(hexToDecimal(`0x${output}`));
|
|
127
|
+
default:
|
|
128
|
+
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return outputs.length === 1 ? outputs[0] : outputs;
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function buildFetchInit<T>(body: T): {
|
|
2
|
+
method: string;
|
|
3
|
+
headers: {
|
|
4
|
+
'Content-Type': string;
|
|
5
|
+
};
|
|
6
|
+
body: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
9
|
+
export type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
|
|
10
|
+
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
11
|
+
jsonrpc: string;
|
|
12
|
+
id: number;
|
|
13
|
+
method: RPCMethodName;
|
|
14
|
+
params: unknown[];
|
|
15
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import unfetch from 'isomorphic-unfetch';
|
|
2
|
+
export function buildFetchInit(body) {
|
|
3
|
+
return {
|
|
4
|
+
method: 'POST',
|
|
5
|
+
headers: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
},
|
|
8
|
+
body: JSON.stringify(body),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function post(url, body) {
|
|
12
|
+
return unfetch(url, buildFetchInit(body))
|
|
13
|
+
.then(async (r) => {
|
|
14
|
+
const t = await r.text();
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(t);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.then((response) => {
|
|
23
|
+
const result = response?.result;
|
|
24
|
+
if (!result) {
|
|
25
|
+
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
26
|
+
}
|
|
27
|
+
return response.result;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function buildRPCPostBody(method, params) {
|
|
31
|
+
return {
|
|
32
|
+
jsonrpc: '2.0',
|
|
33
|
+
id: 1,
|
|
34
|
+
method,
|
|
35
|
+
params,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hexToDecimal(hex: string): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { TinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
+
import { hexlify } from '../../utils/bytes';
|
|
4
|
+
export function prepareTransaction(transaction) {
|
|
5
|
+
const preparedTransaction = {
|
|
6
|
+
...transaction,
|
|
7
|
+
};
|
|
8
|
+
Object.keys(transaction).forEach((key) => {
|
|
9
|
+
switch (key) {
|
|
10
|
+
case 'gas':
|
|
11
|
+
case 'gasPrice':
|
|
12
|
+
case 'nonce':
|
|
13
|
+
case 'maxFeePerGas':
|
|
14
|
+
case 'maxPriorityFeePerGas':
|
|
15
|
+
case 'value': {
|
|
16
|
+
const value = transaction[key];
|
|
17
|
+
if (value instanceof TinyBig) {
|
|
18
|
+
preparedTransaction[key] = value.toHexString();
|
|
19
|
+
}
|
|
20
|
+
else if (value instanceof Big) {
|
|
21
|
+
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
22
|
+
}
|
|
23
|
+
else if (typeof transaction[key] === 'number')
|
|
24
|
+
preparedTransaction[key] =
|
|
25
|
+
'0x' + transaction[key].toString(16);
|
|
26
|
+
else
|
|
27
|
+
preparedTransaction[key] = transaction[key].toString();
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'data':
|
|
31
|
+
preparedTransaction[key] = hexlify(transaction[key]);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return preparedTransaction;
|
|
36
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
export { Contract, BaseContract } from './classes/Contract';
|
|
2
|
-
export { AlchemyProvider } from './providers/AlchemyProvider';
|
|
3
|
-
export { FallthroughProvider, ConstructorOptions, } from './providers/FallthroughProvider';
|
|
4
|
-
export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
|
|
5
|
-
export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
6
|
-
export { BlockResponse, RPCBlock, BlockTag } from './types/Block.types';
|
|
7
|
-
export { ContractTypes, JSONABI, JSONABIArgument, } from './types/Contract.types';
|
|
8
|
-
export { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
9
|
-
export { Network } from './types/Network.types';
|
|
10
|
-
export { TransactionResponse, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, RPCLog, Log, BlockTransactionResponse, } from './types/Transaction.types';
|
|
11
|
-
export { computeAddress } from './utils/compute-address';
|
|
12
|
-
export { computePublicKey } from './utils/compute-public-key';
|
|
13
|
-
export { etherToGwei } from './utils/ether-to-gwei';
|
|
14
|
-
export { etherToWei } from './utils/ether-to-wei';
|
|
15
|
-
export { gweiToEther } from './utils/gwei-to-ether';
|
|
16
|
-
export { hashMessage } from './utils/hash-message';
|
|
17
|
-
export { isAddress } from './utils/is-address';
|
|
18
|
-
export { splitSignature } from './utils/split-signature';
|
|
19
|
-
export { toChecksumAddress } from './utils/to-checksum-address';
|
|
20
|
-
export { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
21
|
-
export { weiToEther } from './utils/wei-to-ether';
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export * from './utils/solidity-keccak256';
|
|
1
|
+
export { Contract, BaseContract } from './classes/Contract';
|
|
2
|
+
export { AlchemyProvider } from './providers/AlchemyProvider';
|
|
3
|
+
export { FallthroughProvider, ConstructorOptions, } from './providers/FallthroughProvider';
|
|
4
|
+
export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
|
|
5
|
+
export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
6
|
+
export { BlockResponse, RPCBlock, BlockTag } from './types/Block.types';
|
|
7
|
+
export { ContractTypes, JSONABI, JSONABIArgument, } from './types/Contract.types';
|
|
8
|
+
export { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
9
|
+
export { Network } from './types/Network.types';
|
|
10
|
+
export { TransactionResponse, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, RPCLog, Log, BlockTransactionResponse, } from './types/Transaction.types';
|
|
11
|
+
export { computeAddress } from './utils/compute-address';
|
|
12
|
+
export { computePublicKey } from './utils/compute-public-key';
|
|
13
|
+
export { etherToGwei } from './utils/ether-to-gwei';
|
|
14
|
+
export { etherToWei } from './utils/ether-to-wei';
|
|
15
|
+
export { gweiToEther } from './utils/gwei-to-ether';
|
|
16
|
+
export { hashMessage } from './utils/hash-message';
|
|
17
|
+
export { isAddress } from './utils/is-address';
|
|
18
|
+
export { splitSignature } from './utils/split-signature';
|
|
19
|
+
export { toChecksumAddress } from './utils/to-checksum-address';
|
|
20
|
+
export { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
21
|
+
export { weiToEther } from './utils/wei-to-ether';
|
|
22
|
+
export { Bytes, BytesLike, BytesLikeWithNumber, DataOptions, Hexable, SignatureLike, Signature, isBytesLike, isBytes, arrayify, concat, stripZeros, zeroPad, isHexString, hexlify, hexDataLength, hexDataSlice, hexConcat, hexValue, hexStripZeros, hexZeroPad, } from './utils/bytes';
|
|
23
|
+
export { keccak256 } from './utils/keccak256';
|
|
24
|
+
export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { Contract, BaseContract } from './classes/Contract';
|
|
2
|
+
export { AlchemyProvider } from './providers/AlchemyProvider';
|
|
3
|
+
export { FallthroughProvider, } from './providers/FallthroughProvider';
|
|
4
|
+
export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
|
|
5
|
+
export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
6
|
+
export { computeAddress } from './utils/compute-address';
|
|
7
|
+
export { computePublicKey } from './utils/compute-public-key';
|
|
8
|
+
export { etherToGwei } from './utils/ether-to-gwei';
|
|
9
|
+
export { etherToWei } from './utils/ether-to-wei';
|
|
10
|
+
export { gweiToEther } from './utils/gwei-to-ether';
|
|
11
|
+
export { hashMessage } from './utils/hash-message';
|
|
12
|
+
export { isAddress } from './utils/is-address';
|
|
13
|
+
export { splitSignature } from './utils/split-signature';
|
|
14
|
+
export { toChecksumAddress } from './utils/to-checksum-address';
|
|
15
|
+
export { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
16
|
+
export { weiToEther } from './utils/wei-to-ether';
|
|
17
|
+
export { isBytesLike, isBytes, arrayify, concat, stripZeros, zeroPad, isHexString, hexlify, hexDataLength, hexDataSlice, hexConcat, hexValue, hexStripZeros, hexZeroPad, } from './utils/bytes';
|
|
18
|
+
export { keccak256 } from './utils/keccak256';
|
|
19
|
+
export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class Logger {
|
|
2
|
+
private packageVersion;
|
|
3
|
+
constructor();
|
|
4
|
+
throwError(message: string, args: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}): never;
|
|
7
|
+
throwArgumentError(message: string, arg: string, value: any): never;
|
|
8
|
+
checkSafeUint53(value: number, message?: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const logger: Logger;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { version } from './package-version';
|
|
2
|
+
class Logger {
|
|
3
|
+
packageVersion;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.packageVersion = version;
|
|
6
|
+
}
|
|
7
|
+
throwError(message, args) {
|
|
8
|
+
const argsLength = Object.keys(args).length;
|
|
9
|
+
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
10
|
+
}
|
|
11
|
+
throwArgumentError(message, arg, value) {
|
|
12
|
+
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
13
|
+
}
|
|
14
|
+
checkSafeUint53(value, message = 'value not safe') {
|
|
15
|
+
if (typeof value !== 'number') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
19
|
+
this.throwError(message, {
|
|
20
|
+
operation: 'checkSafeInteger',
|
|
21
|
+
fault: 'out-of-safe-range',
|
|
22
|
+
value: value,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (value % 1) {
|
|
26
|
+
this.throwError(message, {
|
|
27
|
+
operation: 'checkSafeInteger',
|
|
28
|
+
fault: 'non-integer',
|
|
29
|
+
value: value,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const logger = new Logger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.9.2-beta.3";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.9.2-beta.3';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
import type { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
|
+
import type { FeeData } from '../types/FeeData.types';
|
|
4
|
+
import type { Filter, FilterByBlockHash } from '../types/Filter.types';
|
|
5
|
+
import type { Network } from '../types/Network.types';
|
|
6
|
+
import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
|
|
7
|
+
export declare abstract class BaseProvider {
|
|
8
|
+
abstract selectRpcUrl(): string;
|
|
9
|
+
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
10
|
+
readonly _rpcUrls: string[];
|
|
11
|
+
protected _post: (body: Record<string, unknown>) => Promise<any>;
|
|
12
|
+
constructor(rpcUrls: string[]);
|
|
13
|
+
getNetwork(): Promise<Network>;
|
|
14
|
+
getBlockNumber(): Promise<number>;
|
|
15
|
+
getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
16
|
+
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
17
|
+
getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
|
|
18
|
+
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
19
|
+
getGasPrice(): Promise<TinyBig>;
|
|
20
|
+
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
21
|
+
getCode(address: string, blockTag?: BlockTag): Promise<string>;
|
|
22
|
+
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
23
|
+
getFeeData(): Promise<FeeData>;
|
|
24
|
+
getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
|
|
25
|
+
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
|
|
26
|
+
}
|