viem 0.0.1-alpha.34 → 0.0.1-alpha.36
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/README.md +132 -0
- package/abi/package.json +4 -0
- package/dist/abi.d.ts +5 -0
- package/dist/abi.js +11 -0
- package/dist/abi.js.map +1 -0
- package/dist/abi.mjs +11 -0
- package/dist/abi.mjs.map +1 -0
- package/dist/{chain-4a0d4164.d.ts → chain-a34aa9a2.d.ts} +65 -63
- package/dist/{chain-ce6e149c.d.ts → chain-b1229232.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-EJEZIHXK.js → chunk-4AEFOF5R.js} +21 -23
- package/dist/chunk-4AEFOF5R.js.map +1 -0
- package/dist/{chunk-VP57P6CD.mjs → chunk-AXATFOBJ.mjs} +1885 -146
- package/dist/chunk-AXATFOBJ.mjs.map +1 -0
- package/dist/{chunk-KQQLLKZV.mjs → chunk-CUT73KXY.mjs} +3 -5
- package/dist/{chunk-KQQLLKZV.mjs.map → chunk-CUT73KXY.mjs.map} +1 -1
- package/dist/{chunk-F76TECTY.js → chunk-KXGQFW2R.js} +1907 -168
- package/dist/chunk-KXGQFW2R.js.map +1 -0
- package/dist/contract.d.ts +7 -8
- package/dist/contract.js +2 -6
- package/dist/contract.mjs +15 -19
- package/dist/{createClient-8a8b4bf4.d.ts → createClient-8024655d.d.ts} +3 -11
- package/dist/{createPublicClient-b5afe6b8.d.ts → createPublicClient-f283b09d.d.ts} +155 -39
- package/dist/{eip1193-8c021438.d.ts → eip1193-a4f254d2.d.ts} +12 -2
- package/dist/{getAbiItem-d7aa40b1.d.ts → encodeFunctionResult-c3d6c7ea.d.ts} +3 -25
- package/dist/ens.d.ts +4 -5
- package/dist/ens.js +3 -4
- package/dist/ens.js.map +1 -1
- package/dist/ens.mjs +2 -3
- package/dist/ens.mjs.map +1 -1
- package/dist/{formatAbiItem-6e00e5e6.d.ts → formatAbiItem-d79cb207.d.ts} +1 -1
- package/dist/getAbiItem-48e793da.d.ts +22 -0
- package/dist/index.d.ts +27 -17
- package/dist/index.js +89 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -88
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-ce3a9dfa.d.ts → parseGwei-5dc2744d.d.ts} +11 -23
- package/dist/public.d.ts +6 -7
- package/dist/public.js +2 -3
- package/dist/public.mjs +1 -2
- package/dist/{test-5d5828c9.d.ts → test-f8bc2fa7.d.ts} +9 -17
- package/dist/test.d.ts +5 -5
- package/dist/test.js +2 -3
- package/dist/test.mjs +1 -2
- package/dist/utils/index.d.ts +27 -18
- package/dist/utils/index.js +2 -4
- package/dist/utils/index.mjs +11 -13
- package/dist/wallet.d.ts +5 -5
- package/dist/wallet.js +2 -3
- package/dist/wallet.mjs +5 -6
- package/dist/window.d.ts +2 -2
- package/package.json +8 -2
- package/dist/chunk-7ALCXZ5K.js +0 -1216
- package/dist/chunk-7ALCXZ5K.js.map +0 -1
- package/dist/chunk-EBLS4P77.js +0 -265
- package/dist/chunk-EBLS4P77.js.map +0 -1
- package/dist/chunk-EJEZIHXK.js.map +0 -1
- package/dist/chunk-F76TECTY.js.map +0 -1
- package/dist/chunk-IUCGWGPX.js +0 -197
- package/dist/chunk-IUCGWGPX.js.map +0 -1
- package/dist/chunk-NMET3ZHG.mjs +0 -265
- package/dist/chunk-NMET3ZHG.mjs.map +0 -1
- package/dist/chunk-TNN5X44H.mjs +0 -197
- package/dist/chunk-TNN5X44H.mjs.map +0 -1
- package/dist/chunk-VHZHROXW.mjs +0 -1216
- package/dist/chunk-VHZHROXW.mjs.map +0 -1
- package/dist/chunk-VP57P6CD.mjs.map +0 -1
- package/dist/wallet-5ab86528.d.ts +0 -115
@@ -9,7 +9,7 @@ var __publicField = (obj, key, value) => {
|
|
9
9
|
var package_default = {
|
10
10
|
name: "viem",
|
11
11
|
description: "TypeScript Interface for Ethereum",
|
12
|
-
version: "0.0.1-alpha.
|
12
|
+
version: "0.0.1-alpha.36",
|
13
13
|
scripts: {
|
14
14
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
15
15
|
bench: "vitest bench --no-threads",
|
@@ -40,6 +40,7 @@ var package_default = {
|
|
40
40
|
tsup: {
|
41
41
|
entry: [
|
42
42
|
"src/index.ts",
|
43
|
+
"src/abi.ts",
|
43
44
|
"src/chains.ts",
|
44
45
|
"src/contract.ts",
|
45
46
|
"src/ens.ts",
|
@@ -51,6 +52,7 @@ var package_default = {
|
|
51
52
|
]
|
52
53
|
},
|
53
54
|
files: [
|
55
|
+
"/abi",
|
54
56
|
"/dist",
|
55
57
|
"/chains",
|
56
58
|
"/contract",
|
@@ -67,6 +69,11 @@ var package_default = {
|
|
67
69
|
module: "./dist/index.mts",
|
68
70
|
default: "./dist/index.js"
|
69
71
|
},
|
72
|
+
"./abi": {
|
73
|
+
types: "./dist/abi.d.ts",
|
74
|
+
module: "./dist/abi.mts",
|
75
|
+
default: "./dist/abi.js"
|
76
|
+
},
|
70
77
|
"./chains": {
|
71
78
|
types: "./dist/chains.d.ts",
|
72
79
|
module: "./dist/chains.mts",
|
@@ -116,7 +123,7 @@ var package_default = {
|
|
116
123
|
dependencies: {
|
117
124
|
"@noble/hashes": "^1.1.2",
|
118
125
|
"@wagmi/chains": "~0.2.8",
|
119
|
-
abitype: "~0.
|
126
|
+
abitype: "~0.5.0",
|
120
127
|
"idna-uts46-hx": "^4.1.2",
|
121
128
|
"isomorphic-ws": "^5.0.0",
|
122
129
|
ws: "^8.12.0"
|
@@ -268,6 +275,16 @@ var AbiEncodingArrayLengthMismatchError = class extends BaseError {
|
|
268
275
|
__publicField(this, "name", "AbiEncodingArrayLengthMismatchError");
|
269
276
|
}
|
270
277
|
};
|
278
|
+
var AbiEncodingBytesSizeMismatchError = class extends BaseError {
|
279
|
+
constructor({ expectedSize, value }) {
|
280
|
+
super(
|
281
|
+
`Size of bytes "${value}" (bytes${size(
|
282
|
+
value
|
283
|
+
)}) does not match expected size (bytes${expectedSize}).`
|
284
|
+
);
|
285
|
+
__publicField(this, "name", "AbiEncodingBytesSizeMismatchError");
|
286
|
+
}
|
287
|
+
};
|
271
288
|
var AbiEncodingLengthMismatchError = class extends BaseError {
|
272
289
|
constructor({
|
273
290
|
expectedLength,
|
@@ -489,6 +506,23 @@ var ChainDoesNotSupportContract = class extends BaseError {
|
|
489
506
|
__publicField(this, "name", "ChainDoesNotSupportContract");
|
490
507
|
}
|
491
508
|
};
|
509
|
+
var ChainMismatchError = class extends BaseError {
|
510
|
+
constructor({
|
511
|
+
chain,
|
512
|
+
currentChainId
|
513
|
+
}) {
|
514
|
+
super(
|
515
|
+
`The current chain (id: ${currentChainId}) does not match the chain passed to the request (id: ${chain.id} \u2013 ${chain.name}).`,
|
516
|
+
{
|
517
|
+
metaMessages: [
|
518
|
+
`Current Chain ID: ${currentChainId}`,
|
519
|
+
`Expected Chain ID: ${chain.id} \u2013 ${chain.name}`
|
520
|
+
]
|
521
|
+
}
|
522
|
+
);
|
523
|
+
__publicField(this, "name", "ChainMismatchError");
|
524
|
+
}
|
525
|
+
};
|
492
526
|
|
493
527
|
// src/constants/abis.ts
|
494
528
|
var multicall3Abi = [
|
@@ -568,6 +602,20 @@ var solidityPanic = {
|
|
568
602
|
type: "error"
|
569
603
|
};
|
570
604
|
|
605
|
+
// src/constants/unit.ts
|
606
|
+
var etherUnits = {
|
607
|
+
gwei: 9,
|
608
|
+
wei: 18
|
609
|
+
};
|
610
|
+
var gweiUnits = {
|
611
|
+
ether: -9,
|
612
|
+
wei: 9
|
613
|
+
};
|
614
|
+
var weiUnits = {
|
615
|
+
ether: -18,
|
616
|
+
gwei: -9
|
617
|
+
};
|
618
|
+
|
571
619
|
// src/errors/transaction.ts
|
572
620
|
function prettyPrint(args) {
|
573
621
|
const entries = Object.entries(args).map(([key, value]) => {
|
@@ -578,10 +626,21 @@ function prettyPrint(args) {
|
|
578
626
|
const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
|
579
627
|
return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
|
580
628
|
}
|
629
|
+
var FeeConflictError = class extends BaseError {
|
630
|
+
constructor() {
|
631
|
+
super(
|
632
|
+
[
|
633
|
+
"Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
|
634
|
+
"Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
|
635
|
+
].join("\n")
|
636
|
+
);
|
637
|
+
__publicField(this, "name", "FeeConflictError");
|
638
|
+
}
|
639
|
+
};
|
581
640
|
var TransactionExecutionError = class extends BaseError {
|
582
641
|
constructor(cause, {
|
642
|
+
account,
|
583
643
|
docsPath: docsPath5,
|
584
|
-
from,
|
585
644
|
chain,
|
586
645
|
data,
|
587
646
|
gas,
|
@@ -593,7 +652,8 @@ var TransactionExecutionError = class extends BaseError {
|
|
593
652
|
value
|
594
653
|
}) {
|
595
654
|
const prettyArgs = prettyPrint({
|
596
|
-
|
655
|
+
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
656
|
+
from: account.address,
|
597
657
|
to,
|
598
658
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
599
659
|
data,
|
@@ -658,8 +718,8 @@ var WaitForTransactionReceiptTimeoutError = class extends BaseError {
|
|
658
718
|
// src/errors/contract.ts
|
659
719
|
var CallExecutionError = class extends BaseError {
|
660
720
|
constructor(cause, {
|
721
|
+
account,
|
661
722
|
docsPath: docsPath5,
|
662
|
-
from,
|
663
723
|
chain,
|
664
724
|
data,
|
665
725
|
gas,
|
@@ -671,7 +731,7 @@ var CallExecutionError = class extends BaseError {
|
|
671
731
|
value
|
672
732
|
}) {
|
673
733
|
const prettyArgs = prettyPrint({
|
674
|
-
from,
|
734
|
+
from: account?.address,
|
675
735
|
to,
|
676
736
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
677
737
|
data,
|
@@ -885,8 +945,8 @@ var OffsetOutOfBoundsError = class extends BaseError {
|
|
885
945
|
// src/errors/estimateGas.ts
|
886
946
|
var EstimateGasExecutionError = class extends BaseError {
|
887
947
|
constructor(cause, {
|
948
|
+
account,
|
888
949
|
docsPath: docsPath5,
|
889
|
-
from,
|
890
950
|
chain,
|
891
951
|
data,
|
892
952
|
gas,
|
@@ -898,7 +958,7 @@ var EstimateGasExecutionError = class extends BaseError {
|
|
898
958
|
value
|
899
959
|
}) {
|
900
960
|
const prettyArgs = prettyPrint({
|
901
|
-
from,
|
961
|
+
from: account.address,
|
902
962
|
to,
|
903
963
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
904
964
|
data,
|
@@ -1517,11 +1577,6 @@ function stringToHex(value) {
|
|
1517
1577
|
|
1518
1578
|
// src/utils/encoding/toBytes.ts
|
1519
1579
|
var encoder = new TextEncoder();
|
1520
|
-
function boolToBytes(value) {
|
1521
|
-
const bytes = new Uint8Array(1);
|
1522
|
-
bytes[0] = Number(value);
|
1523
|
-
return bytes;
|
1524
|
-
}
|
1525
1580
|
function toBytes(value) {
|
1526
1581
|
if (typeof value === "number" || typeof value === "bigint")
|
1527
1582
|
return numberToBytes(value);
|
@@ -1531,6 +1586,11 @@ function toBytes(value) {
|
|
1531
1586
|
return hexToBytes(value);
|
1532
1587
|
return stringToBytes(value);
|
1533
1588
|
}
|
1589
|
+
function boolToBytes(value) {
|
1590
|
+
const bytes = new Uint8Array(1);
|
1591
|
+
bytes[0] = Number(value);
|
1592
|
+
return bytes;
|
1593
|
+
}
|
1534
1594
|
function hexToBytes(hex_) {
|
1535
1595
|
let hex = hex_.slice(2);
|
1536
1596
|
if (hex.length % 2)
|
@@ -1541,7 +1601,7 @@ function hexToBytes(hex_) {
|
|
1541
1601
|
const hexByte = hex.slice(start, start + 2);
|
1542
1602
|
const byte = Number.parseInt(hexByte, 16);
|
1543
1603
|
if (Number.isNaN(byte) || byte < 0)
|
1544
|
-
throw new
|
1604
|
+
throw new BaseError(`Invalid byte sequence ("${hexByte}" in "${hex}").`);
|
1545
1605
|
bytes[index] = byte;
|
1546
1606
|
}
|
1547
1607
|
return bytes;
|
@@ -1847,8 +1907,8 @@ function isAddressEqual(a, b) {
|
|
1847
1907
|
return a.toLowerCase() === b.toLowerCase();
|
1848
1908
|
}
|
1849
1909
|
|
1850
|
-
// src/utils/abi/
|
1851
|
-
function
|
1910
|
+
// src/utils/abi/encodeAbiParameters.ts
|
1911
|
+
function encodeAbiParameters(params, values) {
|
1852
1912
|
if (params.length !== values.length)
|
1853
1913
|
throw new AbiEncodingLengthMismatchError({
|
1854
1914
|
expectedLength: params.length,
|
@@ -1898,13 +1958,13 @@ function prepareParam({
|
|
1898
1958
|
return encodeNumber(value, { signed });
|
1899
1959
|
}
|
1900
1960
|
if (param.type.startsWith("bytes")) {
|
1901
|
-
return
|
1961
|
+
return encodeBytes(value, { param });
|
1902
1962
|
}
|
1903
1963
|
if (param.type === "string") {
|
1904
1964
|
return encodeString(value);
|
1905
1965
|
}
|
1906
1966
|
throw new InvalidAbiEncodingTypeError(param.type, {
|
1907
|
-
docsPath: "/docs/contract/
|
1967
|
+
docsPath: "/docs/contract/encodeAbiParameters"
|
1908
1968
|
});
|
1909
1969
|
}
|
1910
1970
|
function encodeParams(preparedParams) {
|
@@ -1932,6 +1992,8 @@ function encodeParams(preparedParams) {
|
|
1932
1992
|
return concat([...staticParams, ...dynamicParams]);
|
1933
1993
|
}
|
1934
1994
|
function encodeAddress(value) {
|
1995
|
+
if (!isAddress(value))
|
1996
|
+
throw new InvalidAddressError({ address: value });
|
1935
1997
|
return { dynamic: false, encoded: padHex(value.toLowerCase()) };
|
1936
1998
|
}
|
1937
1999
|
function encodeArray(value, {
|
@@ -1972,13 +2034,17 @@ function encodeArray(value, {
|
|
1972
2034
|
encoded: concat(preparedParams.map(({ encoded }) => encoded))
|
1973
2035
|
};
|
1974
2036
|
}
|
1975
|
-
function
|
2037
|
+
function encodeBytes(value, { param }) {
|
1976
2038
|
const [_, size_] = param.type.split("bytes");
|
1977
2039
|
if (!size_) {
|
1978
2040
|
const partsLength = Math.floor(size(value) / 32);
|
1979
2041
|
const parts = [];
|
1980
2042
|
for (let i = 0; i < partsLength + 1; i++) {
|
1981
|
-
parts.push(
|
2043
|
+
parts.push(
|
2044
|
+
padHex(slice(value, i * 32, (i + 1) * 32), {
|
2045
|
+
dir: "right"
|
2046
|
+
})
|
2047
|
+
);
|
1982
2048
|
}
|
1983
2049
|
return {
|
1984
2050
|
dynamic: true,
|
@@ -1988,6 +2054,11 @@ function toBytes2(value, { param }) {
|
|
1988
2054
|
])
|
1989
2055
|
};
|
1990
2056
|
}
|
2057
|
+
if (size(value) !== parseInt(size_))
|
2058
|
+
throw new AbiEncodingBytesSizeMismatchError({
|
2059
|
+
expectedSize: parseInt(size_),
|
2060
|
+
value
|
2061
|
+
});
|
1991
2062
|
return { dynamic: false, encoded: padHex(value, { dir: "right" }) };
|
1992
2063
|
}
|
1993
2064
|
function encodeBool(value) {
|
@@ -2038,19 +2109,16 @@ function getArrayComponents(type) {
|
|
2038
2109
|
) : void 0;
|
2039
2110
|
}
|
2040
2111
|
|
2041
|
-
// src/utils/abi/
|
2042
|
-
function
|
2112
|
+
// src/utils/abi/decodeAbiParameters.ts
|
2113
|
+
function decodeAbiParameters(params, data) {
|
2043
2114
|
if (data === "0x" && params.length > 0)
|
2044
2115
|
throw new AbiDecodingZeroDataError();
|
2045
2116
|
if (size(data) % 32 !== 0)
|
2046
2117
|
throw new AbiDecodingDataSizeInvalidError(size(data));
|
2047
|
-
|
2118
|
+
return decodeParams({
|
2048
2119
|
data,
|
2049
2120
|
params
|
2050
2121
|
});
|
2051
|
-
if (values.length === 0)
|
2052
|
-
return void 0;
|
2053
|
-
return values;
|
2054
2122
|
}
|
2055
2123
|
function decodeParams({
|
2056
2124
|
data,
|
@@ -2087,7 +2155,7 @@ function decodeParam({
|
|
2087
2155
|
return decodeString(data, { position });
|
2088
2156
|
}
|
2089
2157
|
if (param.type.startsWith("bytes")) {
|
2090
|
-
return
|
2158
|
+
return decodeBytes(data, { param, position });
|
2091
2159
|
}
|
2092
2160
|
let value = slice(data, position, position + 32);
|
2093
2161
|
if (param.type.startsWith("uint") || param.type.startsWith("int")) {
|
@@ -2100,7 +2168,7 @@ function decodeParam({
|
|
2100
2168
|
return decodeBool(value);
|
2101
2169
|
}
|
2102
2170
|
throw new InvalidAbiDecodingTypeError(param.type, {
|
2103
|
-
docsPath: "/docs/contract/
|
2171
|
+
docsPath: "/docs/contract/decodeAbiParameters"
|
2104
2172
|
});
|
2105
2173
|
}
|
2106
2174
|
function decodeAddress(value) {
|
@@ -2160,7 +2228,7 @@ function decodeArray(data, {
|
|
2160
2228
|
function decodeBool(value) {
|
2161
2229
|
return { consumed: 32, value: hexToBool(value) };
|
2162
2230
|
}
|
2163
|
-
function
|
2231
|
+
function decodeBytes(data, { param, position }) {
|
2164
2232
|
const [_, size2] = param.type.split("bytes");
|
2165
2233
|
if (!size2) {
|
2166
2234
|
const offset = hexToNumber(slice(data, position, position + 32));
|
@@ -2272,7 +2340,7 @@ function decodeErrorResult({
|
|
2272
2340
|
});
|
2273
2341
|
return {
|
2274
2342
|
abiItem,
|
2275
|
-
args: "inputs" in abiItem && abiItem.inputs && abiItem.inputs.length > 0 ?
|
2343
|
+
args: "inputs" in abiItem && abiItem.inputs && abiItem.inputs.length > 0 ? decodeAbiParameters(abiItem.inputs, slice(data, 4)) : void 0,
|
2276
2344
|
errorName: abiItem.name
|
2277
2345
|
};
|
2278
2346
|
}
|
@@ -2309,7 +2377,7 @@ function decodeEventLog({
|
|
2309
2377
|
}
|
2310
2378
|
if (data && data !== "0x") {
|
2311
2379
|
const params = inputs.filter((x) => !("indexed" in x && x.indexed));
|
2312
|
-
const decodedData =
|
2380
|
+
const decodedData = decodeAbiParameters(params, data);
|
2313
2381
|
if (decodedData) {
|
2314
2382
|
if (isUnnamed)
|
2315
2383
|
args = [...args, ...decodedData];
|
@@ -2328,7 +2396,7 @@ function decodeEventLog({
|
|
2328
2396
|
function decodeTopic({ param, value }) {
|
2329
2397
|
if (param.type === "string" || param.type === "bytes" || param.type === "tuple" || param.type.match(/^(.*)\[(\d+)?\]$/))
|
2330
2398
|
return value;
|
2331
|
-
const decodedArg =
|
2399
|
+
const decodedArg = decodeAbiParameters([param], value) || [];
|
2332
2400
|
return decodedArg[0];
|
2333
2401
|
}
|
2334
2402
|
|
@@ -2344,7 +2412,7 @@ function decodeFunctionData({ abi, data }) {
|
|
2344
2412
|
});
|
2345
2413
|
return {
|
2346
2414
|
functionName: description.name,
|
2347
|
-
args: "inputs" in description && description.inputs && description.inputs.length > 0 ?
|
2415
|
+
args: "inputs" in description && description.inputs && description.inputs.length > 0 ? decodeAbiParameters(description.inputs, slice(data, 4)) : void 0
|
2348
2416
|
};
|
2349
2417
|
}
|
2350
2418
|
|
@@ -2437,7 +2505,7 @@ function decodeFunctionResult({
|
|
2437
2505
|
throw new AbiFunctionNotFoundError(functionName, { docsPath });
|
2438
2506
|
if (!("outputs" in description))
|
2439
2507
|
throw new AbiFunctionOutputsNotFoundError(functionName, { docsPath });
|
2440
|
-
const values =
|
2508
|
+
const values = decodeAbiParameters(description.outputs, data);
|
2441
2509
|
if (values && values.length > 1)
|
2442
2510
|
return values;
|
2443
2511
|
if (values && values.length === 1)
|
@@ -2463,10 +2531,10 @@ function encodeDeployData({
|
|
2463
2531
|
throw new AbiConstructorParamsNotFoundError({ docsPath: docsPath2 });
|
2464
2532
|
if (!description.inputs || description.inputs.length === 0)
|
2465
2533
|
throw new AbiConstructorParamsNotFoundError({ docsPath: docsPath2 });
|
2466
|
-
const data =
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2534
|
+
const data = encodeAbiParameters(
|
2535
|
+
description.inputs,
|
2536
|
+
args
|
2537
|
+
);
|
2470
2538
|
return concatHex([bytecode, data]);
|
2471
2539
|
}
|
2472
2540
|
|
@@ -2486,7 +2554,7 @@ function encodeErrorResult({ abi, errorName, args }) {
|
|
2486
2554
|
if (args && args.length > 0) {
|
2487
2555
|
if (!("inputs" in description && description.inputs))
|
2488
2556
|
throw new AbiErrorInputsNotFoundError(errorName, { docsPath: docsPath3 });
|
2489
|
-
data =
|
2557
|
+
data = encodeAbiParameters(description.inputs, args);
|
2490
2558
|
}
|
2491
2559
|
return concatHex([signature, data]);
|
2492
2560
|
}
|
@@ -2519,7 +2587,7 @@ function encodeArg({
|
|
2519
2587
|
return keccak256(toBytes(value));
|
2520
2588
|
if (param.type === "tuple" || param.type.match(/^(.*)\[(\d+)?\]$/))
|
2521
2589
|
throw new FilterTypeNotSupportedError(param.type);
|
2522
|
-
return
|
2590
|
+
return encodeAbiParameters([param], [value]);
|
2523
2591
|
}
|
2524
2592
|
|
2525
2593
|
// src/utils/abi/encodeFunctionData.ts
|
@@ -2535,10 +2603,10 @@ function encodeFunctionData({ abi, args, functionName }) {
|
|
2535
2603
|
});
|
2536
2604
|
const definition = formatAbiItem(description);
|
2537
2605
|
const signature = getFunctionSelector(definition);
|
2538
|
-
const data = "inputs" in description && description.inputs ?
|
2539
|
-
|
2540
|
-
|
2541
|
-
|
2606
|
+
const data = "inputs" in description && description.inputs ? encodeAbiParameters(
|
2607
|
+
description.inputs,
|
2608
|
+
args ?? []
|
2609
|
+
) : void 0;
|
2542
2610
|
return concatHex([signature, data ?? "0x"]);
|
2543
2611
|
}
|
2544
2612
|
|
@@ -2559,7 +2627,7 @@ function encodeFunctionResult({
|
|
2559
2627
|
let values = Array.isArray(result) ? result : [result];
|
2560
2628
|
if (description.outputs.length === 0 && !values[0])
|
2561
2629
|
values = [];
|
2562
|
-
return
|
2630
|
+
return encodeAbiParameters(description.outputs, values);
|
2563
2631
|
}
|
2564
2632
|
|
2565
2633
|
// src/utils/abi/formatAbiItemWithArgs.ts
|
@@ -2580,18 +2648,33 @@ function formatAbiItemWithArgs({
|
|
2580
2648
|
).join(", ")})`;
|
2581
2649
|
}
|
2582
2650
|
|
2651
|
+
// src/utils/account.ts
|
2652
|
+
function getAccount(account) {
|
2653
|
+
if (typeof account === "string") {
|
2654
|
+
if (!isAddress(account))
|
2655
|
+
throw new InvalidAddressError({ address: account });
|
2656
|
+
return { address: account, type: "json-rpc" };
|
2657
|
+
}
|
2658
|
+
if (!isAddress(account.address))
|
2659
|
+
throw new InvalidAddressError({ address: account.address });
|
2660
|
+
return {
|
2661
|
+
...account,
|
2662
|
+
type: "externally-owned"
|
2663
|
+
};
|
2664
|
+
}
|
2665
|
+
|
2583
2666
|
// src/utils/promise/withCache.ts
|
2584
2667
|
var promiseCache = /* @__PURE__ */ new Map();
|
2585
2668
|
var responseCache = /* @__PURE__ */ new Map();
|
2586
|
-
function getCache(
|
2587
|
-
const buildCache = (
|
2588
|
-
clear: () => cache.delete(
|
2589
|
-
get: () => cache.get(
|
2590
|
-
set: (data) => cache.set(
|
2669
|
+
function getCache(cacheKey2) {
|
2670
|
+
const buildCache = (cacheKey3, cache) => ({
|
2671
|
+
clear: () => cache.delete(cacheKey3),
|
2672
|
+
get: () => cache.get(cacheKey3),
|
2673
|
+
set: (data) => cache.set(cacheKey3, data)
|
2591
2674
|
});
|
2592
|
-
const promise = buildCache(
|
2675
|
+
const promise = buildCache(cacheKey2, promiseCache);
|
2593
2676
|
const response = buildCache(
|
2594
|
-
|
2677
|
+
cacheKey2,
|
2595
2678
|
responseCache
|
2596
2679
|
);
|
2597
2680
|
return {
|
@@ -2603,8 +2686,8 @@ function getCache(cacheKey) {
|
|
2603
2686
|
response
|
2604
2687
|
};
|
2605
2688
|
}
|
2606
|
-
async function withCache(fn, { cacheKey, maxAge = Infinity }) {
|
2607
|
-
const cache = getCache(
|
2689
|
+
async function withCache(fn, { cacheKey: cacheKey2, maxAge = Infinity }) {
|
2690
|
+
const cache = getCache(cacheKey2);
|
2608
2691
|
const response = cache.response.get();
|
2609
2692
|
if (response && maxAge > 0) {
|
2610
2693
|
const age = (/* @__PURE__ */ new Date()).getTime() - response.created.getTime();
|
@@ -2792,6 +2875,7 @@ function formatTransaction(transaction) {
|
|
2792
2875
|
const transaction_ = {
|
2793
2876
|
...transaction,
|
2794
2877
|
blockNumber: transaction.blockNumber ? BigInt(transaction.blockNumber) : null,
|
2878
|
+
chainId: transaction.chainId ? hexToNumber(transaction.chainId) : void 0,
|
2795
2879
|
gas: transaction.gas ? BigInt(transaction.gas) : void 0,
|
2796
2880
|
gasPrice: transaction.gasPrice ? BigInt(transaction.gasPrice) : void 0,
|
2797
2881
|
maxFeePerGas: transaction.maxFeePerGas ? BigInt(transaction.maxFeePerGas) : void 0,
|
@@ -2912,24 +2996,11 @@ var defineTransactionRequest = defineFormatter({
|
|
2912
2996
|
format: formatTransactionRequest
|
2913
2997
|
});
|
2914
2998
|
|
2915
|
-
// src/utils/errors/assertRequest.ts
|
2916
|
-
function assertRequest(args) {
|
2917
|
-
const { from, maxFeePerGas, maxPriorityFeePerGas, to } = args;
|
2918
|
-
if (from && !isAddress(from))
|
2919
|
-
throw new InvalidAddressError({ address: from });
|
2920
|
-
if (to && !isAddress(to))
|
2921
|
-
throw new InvalidAddressError({ address: to });
|
2922
|
-
if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n)
|
2923
|
-
throw new FeeCapTooHighError({ maxFeePerGas });
|
2924
|
-
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
2925
|
-
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
2926
|
-
}
|
2927
|
-
|
2928
2999
|
// src/utils/errors/getNodeError.ts
|
2929
3000
|
function containsNodeError(err) {
|
2930
3001
|
return err instanceof TransactionRejectedRpcError || err instanceof InvalidInputRpcError || err instanceof RpcError && err.code === ExecutionRevertedError.code;
|
2931
3002
|
}
|
2932
|
-
function getNodeError(err, args
|
3003
|
+
function getNodeError(err, args) {
|
2933
3004
|
const message = err.details.toLowerCase();
|
2934
3005
|
if (FeeCapTooHighError.nodeMessage.test(message))
|
2935
3006
|
return new FeeCapTooHighError({
|
@@ -3215,81 +3286,1681 @@ var rpc = {
|
|
3215
3286
|
webSocketAsync
|
3216
3287
|
};
|
3217
3288
|
|
3218
|
-
// src/utils/
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
};
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3229
|
-
|
3230
|
-
};
|
3289
|
+
// src/utils/transaction/assertRequest.ts
|
3290
|
+
function assertRequest(args) {
|
3291
|
+
const { account, gasPrice, maxFeePerGas, maxPriorityFeePerGas, to } = args;
|
3292
|
+
if (account && !isAddress(account.address))
|
3293
|
+
throw new InvalidAddressError({ address: account.address });
|
3294
|
+
if (to && !isAddress(to))
|
3295
|
+
throw new InvalidAddressError({ address: to });
|
3296
|
+
if (typeof gasPrice !== "undefined" && (typeof maxFeePerGas !== "undefined" || typeof maxPriorityFeePerGas !== "undefined"))
|
3297
|
+
throw new FeeConflictError();
|
3298
|
+
if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n)
|
3299
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
3300
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
3301
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
3302
|
+
}
|
3231
3303
|
|
3232
|
-
// src/
|
3233
|
-
function
|
3234
|
-
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3304
|
+
// src/actions/public/call.ts
|
3305
|
+
async function call(client, args) {
|
3306
|
+
const {
|
3307
|
+
account,
|
3308
|
+
blockNumber,
|
3309
|
+
blockTag = "latest",
|
3310
|
+
accessList,
|
3311
|
+
data,
|
3312
|
+
gas,
|
3313
|
+
gasPrice,
|
3314
|
+
maxFeePerGas,
|
3315
|
+
maxPriorityFeePerGas,
|
3316
|
+
nonce,
|
3317
|
+
to,
|
3318
|
+
value,
|
3319
|
+
...rest
|
3320
|
+
} = args;
|
3321
|
+
try {
|
3322
|
+
assertRequest(args);
|
3323
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3324
|
+
const formatter = client.chain?.formatters?.transactionRequest;
|
3325
|
+
const request_ = format3(
|
3326
|
+
{
|
3327
|
+
from: account?.address,
|
3328
|
+
accessList,
|
3329
|
+
data,
|
3330
|
+
gas,
|
3331
|
+
gasPrice,
|
3332
|
+
maxFeePerGas,
|
3333
|
+
maxPriorityFeePerGas,
|
3334
|
+
nonce,
|
3335
|
+
to,
|
3336
|
+
value,
|
3337
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
3338
|
+
...extract(rest, { formatter })
|
3339
|
+
},
|
3340
|
+
{
|
3341
|
+
formatter: formatter || formatTransactionRequest
|
3342
|
+
}
|
3343
|
+
);
|
3344
|
+
const response = await client.request({
|
3345
|
+
method: "eth_call",
|
3346
|
+
params: [request_, blockNumberHex || blockTag]
|
3347
|
+
});
|
3348
|
+
if (response === "0x")
|
3349
|
+
return { data: void 0 };
|
3350
|
+
return { data: response };
|
3351
|
+
} catch (err) {
|
3352
|
+
throw getCallError(err, {
|
3353
|
+
...args,
|
3354
|
+
chain: client.chain
|
3355
|
+
});
|
3356
|
+
}
|
3245
3357
|
}
|
3246
3358
|
|
3247
|
-
// src/
|
3248
|
-
function
|
3249
|
-
|
3359
|
+
// src/actions/public/simulateContract.ts
|
3360
|
+
async function simulateContract(client, {
|
3361
|
+
abi,
|
3362
|
+
address,
|
3363
|
+
args,
|
3364
|
+
functionName,
|
3365
|
+
...callRequest
|
3366
|
+
}) {
|
3367
|
+
const calldata = encodeFunctionData({
|
3368
|
+
abi,
|
3369
|
+
args,
|
3370
|
+
functionName
|
3371
|
+
});
|
3372
|
+
try {
|
3373
|
+
const { data } = await call(client, {
|
3374
|
+
data: calldata,
|
3375
|
+
to: address,
|
3376
|
+
...callRequest
|
3377
|
+
});
|
3378
|
+
const result = decodeFunctionResult({
|
3379
|
+
abi,
|
3380
|
+
args,
|
3381
|
+
functionName,
|
3382
|
+
data: data || "0x"
|
3383
|
+
});
|
3384
|
+
return {
|
3385
|
+
result,
|
3386
|
+
request: {
|
3387
|
+
abi,
|
3388
|
+
address,
|
3389
|
+
args,
|
3390
|
+
functionName,
|
3391
|
+
...callRequest
|
3392
|
+
}
|
3393
|
+
};
|
3394
|
+
} catch (err) {
|
3395
|
+
throw getContractError(err, {
|
3396
|
+
abi,
|
3397
|
+
address,
|
3398
|
+
args,
|
3399
|
+
docsPath: "/docs/contract/simulateContract",
|
3400
|
+
functionName,
|
3401
|
+
sender: callRequest.account?.address
|
3402
|
+
});
|
3403
|
+
}
|
3250
3404
|
}
|
3251
3405
|
|
3252
|
-
// src/
|
3253
|
-
function
|
3254
|
-
|
3406
|
+
// src/actions/public/createPendingTransactionFilter.ts
|
3407
|
+
async function createPendingTransactionFilter(client) {
|
3408
|
+
const id2 = await client.request({
|
3409
|
+
method: "eth_newPendingTransactionFilter"
|
3410
|
+
});
|
3411
|
+
return { id: id2, type: "transaction" };
|
3255
3412
|
}
|
3256
3413
|
|
3257
|
-
// src/
|
3258
|
-
function
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3414
|
+
// src/actions/public/createBlockFilter.ts
|
3415
|
+
async function createBlockFilter(client) {
|
3416
|
+
const id2 = await client.request({
|
3417
|
+
method: "eth_newBlockFilter"
|
3418
|
+
});
|
3419
|
+
return { id: id2, type: "block" };
|
3420
|
+
}
|
3421
|
+
|
3422
|
+
// src/actions/public/createEventFilter.ts
|
3423
|
+
async function createEventFilter(client, {
|
3424
|
+
address,
|
3425
|
+
args,
|
3426
|
+
event,
|
3427
|
+
fromBlock,
|
3428
|
+
toBlock
|
3429
|
+
} = {}) {
|
3430
|
+
let topics = [];
|
3431
|
+
if (event)
|
3432
|
+
topics = encodeEventTopics({
|
3433
|
+
abi: [event],
|
3434
|
+
eventName: event.name,
|
3435
|
+
args
|
3436
|
+
});
|
3437
|
+
const id2 = await client.request({
|
3438
|
+
method: "eth_newFilter",
|
3439
|
+
params: [
|
3440
|
+
{
|
3441
|
+
address,
|
3442
|
+
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
3443
|
+
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
|
3444
|
+
...topics.length ? { topics } : {}
|
3445
|
+
}
|
3446
|
+
]
|
3447
|
+
});
|
3448
|
+
return {
|
3449
|
+
abi: event ? [event] : void 0,
|
3450
|
+
args,
|
3451
|
+
eventName: event ? event.name : void 0,
|
3452
|
+
id: id2,
|
3453
|
+
type: "event"
|
3454
|
+
};
|
3455
|
+
}
|
3456
|
+
|
3457
|
+
// src/actions/public/createContractEventFilter.ts
|
3458
|
+
async function createContractEventFilter(client, {
|
3459
|
+
address,
|
3460
|
+
abi,
|
3461
|
+
args,
|
3462
|
+
eventName,
|
3463
|
+
fromBlock,
|
3464
|
+
toBlock
|
3465
|
+
}) {
|
3466
|
+
const topics = eventName ? encodeEventTopics({
|
3467
|
+
abi,
|
3468
|
+
args,
|
3469
|
+
eventName
|
3470
|
+
}) : void 0;
|
3471
|
+
const id2 = await client.request({
|
3472
|
+
method: "eth_newFilter",
|
3473
|
+
params: [
|
3474
|
+
{
|
3475
|
+
address,
|
3476
|
+
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
3477
|
+
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
|
3478
|
+
topics
|
3479
|
+
}
|
3480
|
+
]
|
3481
|
+
});
|
3482
|
+
return {
|
3483
|
+
abi,
|
3484
|
+
args,
|
3485
|
+
eventName,
|
3486
|
+
id: id2,
|
3487
|
+
type: "event"
|
3488
|
+
};
|
3489
|
+
}
|
3490
|
+
|
3491
|
+
// src/actions/public/estimateGas.ts
|
3492
|
+
async function estimateGas(client, args) {
|
3493
|
+
try {
|
3494
|
+
const {
|
3495
|
+
account,
|
3496
|
+
accessList,
|
3497
|
+
blockNumber,
|
3498
|
+
blockTag = "latest",
|
3499
|
+
data,
|
3500
|
+
gas,
|
3501
|
+
gasPrice,
|
3502
|
+
maxFeePerGas,
|
3503
|
+
maxPriorityFeePerGas,
|
3504
|
+
nonce,
|
3505
|
+
to,
|
3506
|
+
value,
|
3507
|
+
...rest
|
3508
|
+
} = args.account.type === "externally-owned" ? await prepareRequest(client, args) : args;
|
3509
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3510
|
+
assertRequest(args);
|
3511
|
+
const formatter = client.chain?.formatters?.transactionRequest;
|
3512
|
+
const request = format3(
|
3513
|
+
{
|
3514
|
+
from: account.address,
|
3515
|
+
accessList,
|
3516
|
+
data,
|
3517
|
+
gas,
|
3518
|
+
gasPrice,
|
3519
|
+
maxFeePerGas,
|
3520
|
+
maxPriorityFeePerGas,
|
3521
|
+
nonce,
|
3522
|
+
to,
|
3523
|
+
value,
|
3524
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
3525
|
+
...extract(rest, { formatter })
|
3526
|
+
},
|
3527
|
+
{
|
3528
|
+
formatter: formatter || formatTransactionRequest
|
3529
|
+
}
|
3530
|
+
);
|
3531
|
+
const balance = await client.request({
|
3532
|
+
method: "eth_estimateGas",
|
3533
|
+
params: [request, blockNumberHex || blockTag]
|
3534
|
+
});
|
3535
|
+
return BigInt(balance);
|
3536
|
+
} catch (err) {
|
3537
|
+
throw getEstimateGasError(err, {
|
3538
|
+
...args,
|
3539
|
+
chain: client.chain
|
3540
|
+
});
|
3541
|
+
}
|
3542
|
+
}
|
3543
|
+
|
3544
|
+
// src/actions/public/estimateContractGas.ts
|
3545
|
+
async function estimateContractGas(client, {
|
3546
|
+
abi,
|
3547
|
+
address,
|
3548
|
+
args,
|
3549
|
+
functionName,
|
3550
|
+
...request
|
3551
|
+
}) {
|
3552
|
+
const data = encodeFunctionData({
|
3553
|
+
abi,
|
3554
|
+
args,
|
3555
|
+
functionName
|
3556
|
+
});
|
3557
|
+
try {
|
3558
|
+
const gas = await estimateGas(client, {
|
3559
|
+
data,
|
3560
|
+
to: address,
|
3561
|
+
...request
|
3562
|
+
});
|
3563
|
+
return gas;
|
3564
|
+
} catch (err) {
|
3565
|
+
throw getContractError(err, {
|
3566
|
+
abi,
|
3567
|
+
address,
|
3568
|
+
args,
|
3569
|
+
docsPath: "/docs/contract/simulateContract",
|
3570
|
+
functionName,
|
3571
|
+
sender: request.account?.address
|
3572
|
+
});
|
3573
|
+
}
|
3574
|
+
}
|
3575
|
+
|
3576
|
+
// src/actions/public/getBalance.ts
|
3577
|
+
async function getBalance(client, { address, blockNumber, blockTag = "latest" }) {
|
3578
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3579
|
+
const balance = await client.request({
|
3580
|
+
method: "eth_getBalance",
|
3581
|
+
params: [address, blockNumberHex || blockTag]
|
3582
|
+
});
|
3583
|
+
return BigInt(balance);
|
3584
|
+
}
|
3585
|
+
|
3586
|
+
// src/actions/public/getBlock.ts
|
3587
|
+
async function getBlock(client, {
|
3588
|
+
blockHash,
|
3589
|
+
blockNumber,
|
3590
|
+
blockTag = "latest",
|
3591
|
+
includeTransactions = false
|
3592
|
+
} = {}) {
|
3593
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
3594
|
+
let block = null;
|
3595
|
+
if (blockHash) {
|
3596
|
+
block = await client.request({
|
3597
|
+
method: "eth_getBlockByHash",
|
3598
|
+
params: [blockHash, includeTransactions]
|
3599
|
+
});
|
3273
3600
|
} else {
|
3274
|
-
|
3601
|
+
block = await client.request({
|
3602
|
+
method: "eth_getBlockByNumber",
|
3603
|
+
params: [blockNumberHex || blockTag, includeTransactions]
|
3604
|
+
});
|
3275
3605
|
}
|
3276
|
-
|
3606
|
+
if (!block)
|
3607
|
+
throw new BlockNotFoundError({ blockHash, blockNumber });
|
3608
|
+
return format3(block, {
|
3609
|
+
formatter: client.chain?.formatters?.block || formatBlock
|
3610
|
+
});
|
3277
3611
|
}
|
3278
3612
|
|
3279
|
-
// src/
|
3280
|
-
|
3281
|
-
|
3613
|
+
// src/actions/public/getBlockNumber.ts
|
3614
|
+
var cacheKey = (id2) => `blockNumber.${id2}`;
|
3615
|
+
function getBlockNumberCache(id2) {
|
3616
|
+
return getCache(cacheKey(id2));
|
3617
|
+
}
|
3618
|
+
async function getBlockNumber(client, { maxAge = client.pollingInterval } = {}) {
|
3619
|
+
const blockNumberHex = await withCache(
|
3620
|
+
() => client.request({
|
3621
|
+
method: "eth_blockNumber"
|
3622
|
+
}),
|
3623
|
+
{ cacheKey: cacheKey(client.uid), maxAge }
|
3624
|
+
);
|
3625
|
+
return BigInt(blockNumberHex);
|
3282
3626
|
}
|
3283
3627
|
|
3284
|
-
// src/
|
3285
|
-
function
|
3286
|
-
|
3628
|
+
// src/actions/public/getBlockTransactionCount.ts
|
3629
|
+
async function getBlockTransactionCount(client, {
|
3630
|
+
blockHash,
|
3631
|
+
blockNumber,
|
3632
|
+
blockTag = "latest"
|
3633
|
+
} = {}) {
|
3634
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
3635
|
+
let count = null;
|
3636
|
+
if (blockHash) {
|
3637
|
+
count = await client.request({
|
3638
|
+
method: "eth_getBlockTransactionCountByHash",
|
3639
|
+
params: [blockHash]
|
3640
|
+
});
|
3641
|
+
} else {
|
3642
|
+
count = await client.request({
|
3643
|
+
method: "eth_getBlockTransactionCountByNumber",
|
3644
|
+
params: [blockNumberHex || blockTag]
|
3645
|
+
});
|
3646
|
+
}
|
3647
|
+
return hexToNumber(count);
|
3287
3648
|
}
|
3288
3649
|
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3650
|
+
// src/actions/public/getBytecode.ts
|
3651
|
+
async function getBytecode(client, { address, blockNumber, blockTag = "latest" }) {
|
3652
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
3653
|
+
const hex = await client.request({
|
3654
|
+
method: "eth_getCode",
|
3655
|
+
params: [address, blockNumberHex || blockTag]
|
3656
|
+
});
|
3657
|
+
if (hex === "0x")
|
3658
|
+
return void 0;
|
3659
|
+
return hex;
|
3660
|
+
}
|
3661
|
+
|
3662
|
+
// src/actions/public/getChainId.ts
|
3663
|
+
async function getChainId(client) {
|
3664
|
+
const chainIdHex = await client.request({ method: "eth_chainId" });
|
3665
|
+
return hexToNumber(chainIdHex);
|
3666
|
+
}
|
3667
|
+
|
3668
|
+
// src/actions/public/getFeeHistory.ts
|
3669
|
+
async function getFeeHistory(client, {
|
3670
|
+
blockCount,
|
3671
|
+
blockNumber,
|
3672
|
+
blockTag = "latest",
|
3673
|
+
rewardPercentiles
|
3674
|
+
}) {
|
3675
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3676
|
+
const feeHistory = await client.request({
|
3677
|
+
method: "eth_feeHistory",
|
3678
|
+
params: [
|
3679
|
+
numberToHex(blockCount),
|
3680
|
+
blockNumberHex || blockTag,
|
3681
|
+
rewardPercentiles
|
3682
|
+
]
|
3683
|
+
});
|
3684
|
+
return formatFeeHistory(feeHistory);
|
3685
|
+
}
|
3686
|
+
|
3687
|
+
// src/actions/public/getFilterChanges.ts
|
3688
|
+
async function getFilterChanges(client, { filter }) {
|
3689
|
+
const logs = await client.request({
|
3690
|
+
method: "eth_getFilterChanges",
|
3691
|
+
params: [filter.id]
|
3692
|
+
});
|
3693
|
+
return logs.map((log) => {
|
3694
|
+
if (typeof log === "string")
|
3695
|
+
return log;
|
3696
|
+
const { eventName, args } = "abi" in filter && filter.abi ? decodeEventLog({
|
3697
|
+
abi: filter.abi,
|
3698
|
+
data: log.data,
|
3699
|
+
topics: log.topics
|
3700
|
+
}) : { eventName: void 0, args: void 0 };
|
3701
|
+
return formatLog(log, { args, eventName });
|
3702
|
+
});
|
3703
|
+
}
|
3704
|
+
|
3705
|
+
// src/actions/public/getFilterLogs.ts
|
3706
|
+
async function getFilterLogs(client, { filter }) {
|
3707
|
+
const logs = await client.request({
|
3708
|
+
method: "eth_getFilterLogs",
|
3709
|
+
params: [filter.id]
|
3710
|
+
});
|
3711
|
+
return logs.map((log) => {
|
3712
|
+
const { eventName, args } = "abi" in filter && filter.abi ? decodeEventLog({
|
3713
|
+
abi: filter.abi,
|
3714
|
+
data: log.data,
|
3715
|
+
topics: log.topics
|
3716
|
+
}) : { eventName: void 0, args: void 0 };
|
3717
|
+
return formatLog(log, { args, eventName });
|
3718
|
+
});
|
3719
|
+
}
|
3720
|
+
|
3721
|
+
// src/actions/public/getGasPrice.ts
|
3722
|
+
async function getGasPrice(client) {
|
3723
|
+
const gasPrice = await client.request({
|
3724
|
+
method: "eth_gasPrice"
|
3725
|
+
});
|
3726
|
+
return BigInt(gasPrice);
|
3727
|
+
}
|
3728
|
+
|
3729
|
+
// src/actions/public/getLogs.ts
|
3730
|
+
async function getLogs(client, {
|
3731
|
+
address,
|
3732
|
+
blockHash,
|
3733
|
+
fromBlock,
|
3734
|
+
toBlock,
|
3735
|
+
event,
|
3736
|
+
args
|
3737
|
+
} = {}) {
|
3738
|
+
let topics = [];
|
3739
|
+
if (event)
|
3740
|
+
topics = encodeEventTopics({
|
3741
|
+
abi: [event],
|
3742
|
+
eventName: event.name,
|
3743
|
+
args
|
3744
|
+
});
|
3745
|
+
let logs;
|
3746
|
+
if (blockHash) {
|
3747
|
+
logs = await client.request({
|
3748
|
+
method: "eth_getLogs",
|
3749
|
+
params: [{ address, topics, blockHash }]
|
3750
|
+
});
|
3751
|
+
} else {
|
3752
|
+
logs = await client.request({
|
3753
|
+
method: "eth_getLogs",
|
3754
|
+
params: [
|
3755
|
+
{
|
3756
|
+
address,
|
3757
|
+
topics,
|
3758
|
+
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
3759
|
+
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock
|
3760
|
+
}
|
3761
|
+
]
|
3762
|
+
});
|
3763
|
+
}
|
3764
|
+
return logs.map((log) => {
|
3765
|
+
const { eventName, args: args2 } = event ? decodeEventLog({
|
3766
|
+
abi: [event],
|
3767
|
+
data: log.data,
|
3768
|
+
topics: log.topics
|
3769
|
+
}) : { eventName: void 0, args: void 0 };
|
3770
|
+
return formatLog(log, { args: args2, eventName });
|
3771
|
+
});
|
3772
|
+
}
|
3773
|
+
|
3774
|
+
// src/actions/public/getStorageAt.ts
|
3775
|
+
async function getStorageAt(client, { address, blockNumber, blockTag = "latest", slot }) {
|
3776
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
3777
|
+
const data = await client.request({
|
3778
|
+
method: "eth_getStorageAt",
|
3779
|
+
params: [address, slot, blockNumberHex || blockTag]
|
3780
|
+
});
|
3781
|
+
return data;
|
3782
|
+
}
|
3783
|
+
|
3784
|
+
// src/actions/public/getTransaction.ts
|
3785
|
+
async function getTransaction(client, {
|
3786
|
+
blockHash,
|
3787
|
+
blockNumber,
|
3788
|
+
blockTag = "latest",
|
3789
|
+
hash: hash2,
|
3790
|
+
index
|
3791
|
+
}) {
|
3792
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
3793
|
+
let transaction = null;
|
3794
|
+
if (hash2) {
|
3795
|
+
transaction = await client.request({
|
3796
|
+
method: "eth_getTransactionByHash",
|
3797
|
+
params: [hash2]
|
3798
|
+
});
|
3799
|
+
} else if (blockHash) {
|
3800
|
+
transaction = await client.request({
|
3801
|
+
method: "eth_getTransactionByBlockHashAndIndex",
|
3802
|
+
params: [blockHash, numberToHex(index)]
|
3803
|
+
});
|
3804
|
+
} else if (blockNumberHex || blockTag) {
|
3805
|
+
transaction = await client.request({
|
3806
|
+
method: "eth_getTransactionByBlockNumberAndIndex",
|
3807
|
+
params: [blockNumberHex || blockTag, numberToHex(index)]
|
3808
|
+
});
|
3809
|
+
}
|
3810
|
+
if (!transaction)
|
3811
|
+
throw new TransactionNotFoundError({
|
3812
|
+
blockHash,
|
3813
|
+
blockNumber,
|
3814
|
+
blockTag,
|
3815
|
+
hash: hash2,
|
3816
|
+
index
|
3817
|
+
});
|
3818
|
+
return format3(transaction, {
|
3819
|
+
formatter: client.chain?.formatters?.transaction || formatTransaction
|
3820
|
+
});
|
3821
|
+
}
|
3822
|
+
|
3823
|
+
// src/actions/public/getTransactionConfirmations.ts
|
3824
|
+
async function getTransactionConfirmations(client, { hash: hash2, transactionReceipt }) {
|
3825
|
+
const [blockNumber, transaction] = await Promise.all([
|
3826
|
+
getBlockNumber(client),
|
3827
|
+
hash2 ? getTransaction(client, { hash: hash2 }) : void 0
|
3828
|
+
]);
|
3829
|
+
const transactionBlockNumber = transactionReceipt?.blockNumber || transaction?.blockNumber;
|
3830
|
+
if (!transactionBlockNumber)
|
3831
|
+
return 0n;
|
3832
|
+
return blockNumber - transactionBlockNumber + 1n;
|
3833
|
+
}
|
3834
|
+
|
3835
|
+
// src/actions/public/getTransactionCount.ts
|
3836
|
+
async function getTransactionCount(client, { address, blockTag = "latest", blockNumber }) {
|
3837
|
+
const count = await client.request({
|
3838
|
+
method: "eth_getTransactionCount",
|
3839
|
+
params: [address, blockNumber ? numberToHex(blockNumber) : blockTag]
|
3840
|
+
});
|
3841
|
+
return hexToNumber(count);
|
3842
|
+
}
|
3843
|
+
|
3844
|
+
// src/actions/public/getTransactionReceipt.ts
|
3845
|
+
async function getTransactionReceipt(client, { hash: hash2 }) {
|
3846
|
+
const receipt = await client.request({
|
3847
|
+
method: "eth_getTransactionReceipt",
|
3848
|
+
params: [hash2]
|
3849
|
+
});
|
3850
|
+
if (!receipt)
|
3851
|
+
throw new TransactionReceiptNotFoundError({ hash: hash2 });
|
3852
|
+
return format3(receipt, {
|
3853
|
+
formatter: client.chain?.formatters?.transactionReceipt || formatTransactionReceipt
|
3854
|
+
});
|
3855
|
+
}
|
3856
|
+
|
3857
|
+
// src/actions/public/readContract.ts
|
3858
|
+
async function readContract(client, {
|
3859
|
+
abi,
|
3860
|
+
address,
|
3861
|
+
args,
|
3862
|
+
functionName,
|
3863
|
+
...callRequest
|
3864
|
+
}) {
|
3865
|
+
const calldata = encodeFunctionData({
|
3866
|
+
abi,
|
3867
|
+
args,
|
3868
|
+
functionName
|
3869
|
+
});
|
3870
|
+
try {
|
3871
|
+
const { data } = await call(client, {
|
3872
|
+
data: calldata,
|
3873
|
+
to: address,
|
3874
|
+
...callRequest
|
3875
|
+
});
|
3876
|
+
return decodeFunctionResult({
|
3877
|
+
abi,
|
3878
|
+
args,
|
3879
|
+
functionName,
|
3880
|
+
data: data || "0x"
|
3881
|
+
});
|
3882
|
+
} catch (err) {
|
3883
|
+
throw getContractError(err, {
|
3884
|
+
abi,
|
3885
|
+
address,
|
3886
|
+
args,
|
3887
|
+
docsPath: "/docs/contract/readContract",
|
3888
|
+
functionName
|
3889
|
+
});
|
3890
|
+
}
|
3891
|
+
}
|
3892
|
+
|
3893
|
+
// src/actions/public/multicall.ts
|
3894
|
+
async function multicall(client, args) {
|
3895
|
+
const {
|
3896
|
+
allowFailure = true,
|
3897
|
+
blockNumber,
|
3898
|
+
blockTag,
|
3899
|
+
contracts,
|
3900
|
+
multicallAddress
|
3901
|
+
} = args;
|
3902
|
+
const calls = contracts.map(({ abi, address, args: args2, functionName }) => {
|
3903
|
+
try {
|
3904
|
+
const callData = encodeFunctionData({
|
3905
|
+
abi,
|
3906
|
+
args: args2,
|
3907
|
+
functionName
|
3908
|
+
});
|
3909
|
+
return {
|
3910
|
+
allowFailure: true,
|
3911
|
+
callData,
|
3912
|
+
target: address
|
3913
|
+
};
|
3914
|
+
} catch (err) {
|
3915
|
+
const error = getContractError(err, {
|
3916
|
+
abi,
|
3917
|
+
address,
|
3918
|
+
args: args2,
|
3919
|
+
docsPath: "/docs/contract/multicall",
|
3920
|
+
functionName
|
3921
|
+
});
|
3922
|
+
if (!allowFailure)
|
3923
|
+
throw error;
|
3924
|
+
return {
|
3925
|
+
allowFailure: true,
|
3926
|
+
callData: "0x",
|
3927
|
+
target: address
|
3928
|
+
};
|
3929
|
+
}
|
3930
|
+
});
|
3931
|
+
const results = await readContract(client, {
|
3932
|
+
abi: multicall3Abi,
|
3933
|
+
address: multicallAddress,
|
3934
|
+
args: [calls],
|
3935
|
+
blockNumber,
|
3936
|
+
blockTag,
|
3937
|
+
functionName: "aggregate3"
|
3938
|
+
});
|
3939
|
+
return results.map(({ returnData, success }, i) => {
|
3940
|
+
const { callData } = calls[i];
|
3941
|
+
const { abi, address, functionName, args: args2 } = contracts[i];
|
3942
|
+
try {
|
3943
|
+
if (callData === "0x")
|
3944
|
+
throw new AbiDecodingZeroDataError();
|
3945
|
+
if (!success)
|
3946
|
+
throw new RawContractError({ data: returnData });
|
3947
|
+
const result = decodeFunctionResult({
|
3948
|
+
abi,
|
3949
|
+
data: returnData,
|
3950
|
+
functionName
|
3951
|
+
});
|
3952
|
+
return { result, status: "success" };
|
3953
|
+
} catch (err) {
|
3954
|
+
const error = getContractError(err, {
|
3955
|
+
abi,
|
3956
|
+
address,
|
3957
|
+
args: args2,
|
3958
|
+
docsPath: "/docs/contract/multicall",
|
3959
|
+
functionName
|
3960
|
+
});
|
3961
|
+
if (!allowFailure)
|
3962
|
+
throw error;
|
3963
|
+
return { error, result: void 0, status: "failure" };
|
3964
|
+
}
|
3965
|
+
});
|
3966
|
+
}
|
3967
|
+
|
3968
|
+
// src/actions/public/uninstallFilter.ts
|
3969
|
+
async function uninstallFilter(client, { filter }) {
|
3970
|
+
return client.request({
|
3971
|
+
method: "eth_uninstallFilter",
|
3972
|
+
params: [filter.id]
|
3973
|
+
});
|
3974
|
+
}
|
3975
|
+
|
3976
|
+
// src/utils/observe.ts
|
3977
|
+
var listenersCache = /* @__PURE__ */ new Map();
|
3978
|
+
var cleanupCache = /* @__PURE__ */ new Map();
|
3979
|
+
var callbackCount = 0;
|
3980
|
+
function observe(observerId, callbacks, fn) {
|
3981
|
+
const callbackId = ++callbackCount;
|
3982
|
+
const getListeners = () => listenersCache.get(observerId) || [];
|
3983
|
+
const unsubscribe = () => {
|
3984
|
+
const listeners2 = getListeners();
|
3985
|
+
listenersCache.set(
|
3986
|
+
observerId,
|
3987
|
+
listeners2.filter((cb) => cb.id !== callbackId)
|
3988
|
+
);
|
3989
|
+
};
|
3990
|
+
const unwatch = () => {
|
3991
|
+
const cleanup2 = cleanupCache.get(observerId);
|
3992
|
+
if (getListeners().length === 1 && cleanup2)
|
3993
|
+
cleanup2();
|
3994
|
+
unsubscribe();
|
3995
|
+
};
|
3996
|
+
const listeners = getListeners();
|
3997
|
+
listenersCache.set(observerId, [
|
3998
|
+
...listeners,
|
3999
|
+
{ id: callbackId, fns: callbacks }
|
4000
|
+
]);
|
4001
|
+
if (listeners && listeners.length > 0)
|
4002
|
+
return unwatch;
|
4003
|
+
let emit = {};
|
4004
|
+
for (const key in callbacks) {
|
4005
|
+
emit[key] = (...args) => {
|
4006
|
+
const listeners2 = getListeners();
|
4007
|
+
if (listeners2.length === 0)
|
4008
|
+
return;
|
4009
|
+
listeners2.forEach((listener) => listener.fns[key]?.(...args));
|
4010
|
+
};
|
4011
|
+
}
|
4012
|
+
const cleanup = fn(emit);
|
4013
|
+
if (typeof cleanup === "function")
|
4014
|
+
cleanupCache.set(observerId, cleanup);
|
4015
|
+
return unwatch;
|
4016
|
+
}
|
4017
|
+
|
4018
|
+
// src/actions/public/waitForTransactionReceipt.ts
|
4019
|
+
async function waitForTransactionReceipt(client, {
|
4020
|
+
confirmations = 1,
|
4021
|
+
hash: hash2,
|
4022
|
+
onReplaced,
|
4023
|
+
pollingInterval = client.pollingInterval,
|
4024
|
+
timeout
|
4025
|
+
}) {
|
4026
|
+
const observerId = JSON.stringify([
|
4027
|
+
"waitForTransactionReceipt",
|
4028
|
+
client.uid,
|
4029
|
+
hash2
|
4030
|
+
]);
|
4031
|
+
let transaction;
|
4032
|
+
let replacedTransaction;
|
4033
|
+
let receipt;
|
4034
|
+
return new Promise((resolve, reject) => {
|
4035
|
+
if (timeout)
|
4036
|
+
setTimeout(
|
4037
|
+
() => reject(new WaitForTransactionReceiptTimeoutError({ hash: hash2 })),
|
4038
|
+
timeout
|
4039
|
+
);
|
4040
|
+
const unobserve = observe(
|
4041
|
+
observerId,
|
4042
|
+
{ onReplaced, resolve, reject },
|
4043
|
+
(emit) => {
|
4044
|
+
const unwatch = watchBlockNumber(client, {
|
4045
|
+
emitMissed: true,
|
4046
|
+
emitOnBegin: true,
|
4047
|
+
pollingInterval,
|
4048
|
+
async onBlockNumber(blockNumber) {
|
4049
|
+
const done = async (fn) => {
|
4050
|
+
unwatch();
|
4051
|
+
fn();
|
4052
|
+
unobserve();
|
4053
|
+
};
|
4054
|
+
try {
|
4055
|
+
if (receipt) {
|
4056
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
4057
|
+
return;
|
4058
|
+
done(() => emit.resolve(receipt));
|
4059
|
+
return;
|
4060
|
+
}
|
4061
|
+
transaction = await getTransaction(client, { hash: hash2 });
|
4062
|
+
receipt = await getTransactionReceipt(client, { hash: hash2 });
|
4063
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
4064
|
+
return;
|
4065
|
+
done(() => emit.resolve(receipt));
|
4066
|
+
} catch (err) {
|
4067
|
+
if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
|
4068
|
+
replacedTransaction = transaction;
|
4069
|
+
const block = await getBlock(client, {
|
4070
|
+
blockNumber,
|
4071
|
+
includeTransactions: true
|
4072
|
+
});
|
4073
|
+
const replacementTransaction = block.transactions.find(
|
4074
|
+
({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
|
4075
|
+
);
|
4076
|
+
if (!replacementTransaction)
|
4077
|
+
return;
|
4078
|
+
receipt = await getTransactionReceipt(client, {
|
4079
|
+
hash: replacementTransaction.hash
|
4080
|
+
});
|
4081
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
4082
|
+
return;
|
4083
|
+
let reason = "replaced";
|
4084
|
+
if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
|
4085
|
+
reason = "repriced";
|
4086
|
+
} else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
|
4087
|
+
reason = "cancelled";
|
4088
|
+
}
|
4089
|
+
done(() => {
|
4090
|
+
emit.onReplaced?.({
|
4091
|
+
reason,
|
4092
|
+
replacedTransaction,
|
4093
|
+
transaction: replacementTransaction,
|
4094
|
+
transactionReceipt: receipt
|
4095
|
+
});
|
4096
|
+
emit.resolve(receipt);
|
4097
|
+
});
|
4098
|
+
} else {
|
4099
|
+
done(() => emit.reject(err));
|
4100
|
+
}
|
4101
|
+
}
|
4102
|
+
}
|
4103
|
+
});
|
4104
|
+
return unwatch;
|
4105
|
+
}
|
4106
|
+
);
|
4107
|
+
});
|
4108
|
+
}
|
4109
|
+
|
4110
|
+
// src/utils/poll.ts
|
4111
|
+
function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
|
4112
|
+
let active = true;
|
4113
|
+
const unwatch = () => active = false;
|
4114
|
+
const watch = async () => {
|
4115
|
+
let data;
|
4116
|
+
if (emitOnBegin)
|
4117
|
+
data = await fn({ unpoll: unwatch });
|
4118
|
+
const initialWait = await initialWaitTime?.(data) ?? interval;
|
4119
|
+
await wait(initialWait);
|
4120
|
+
const poll2 = async () => {
|
4121
|
+
if (!active)
|
4122
|
+
return;
|
4123
|
+
await fn({ unpoll: unwatch });
|
4124
|
+
await wait(interval);
|
4125
|
+
poll2();
|
4126
|
+
};
|
4127
|
+
poll2();
|
4128
|
+
};
|
4129
|
+
watch();
|
4130
|
+
return unwatch;
|
4131
|
+
}
|
4132
|
+
|
4133
|
+
// src/actions/public/watchBlockNumber.ts
|
4134
|
+
function watchBlockNumber(client, {
|
4135
|
+
emitOnBegin = false,
|
4136
|
+
emitMissed = false,
|
4137
|
+
onBlockNumber,
|
4138
|
+
onError,
|
4139
|
+
pollingInterval = client.pollingInterval
|
4140
|
+
}) {
|
4141
|
+
const observerId = JSON.stringify([
|
4142
|
+
"watchBlockNumber",
|
4143
|
+
client.uid,
|
4144
|
+
emitOnBegin,
|
4145
|
+
emitMissed,
|
4146
|
+
pollingInterval
|
4147
|
+
]);
|
4148
|
+
let prevBlockNumber;
|
4149
|
+
return observe(
|
4150
|
+
observerId,
|
4151
|
+
{ onBlockNumber, onError },
|
4152
|
+
(emit) => poll(
|
4153
|
+
async () => {
|
4154
|
+
try {
|
4155
|
+
const blockNumber = await getBlockNumber(client, { maxAge: 0 });
|
4156
|
+
if (prevBlockNumber) {
|
4157
|
+
if (blockNumber === prevBlockNumber)
|
4158
|
+
return;
|
4159
|
+
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
4160
|
+
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
|
4161
|
+
emit.onBlockNumber(i, prevBlockNumber);
|
4162
|
+
prevBlockNumber = i;
|
4163
|
+
}
|
4164
|
+
}
|
4165
|
+
}
|
4166
|
+
prevBlockNumber = blockNumber;
|
4167
|
+
emit.onBlockNumber(blockNumber, prevBlockNumber);
|
4168
|
+
} catch (err) {
|
4169
|
+
emit.onError?.(err);
|
4170
|
+
}
|
4171
|
+
},
|
4172
|
+
{
|
4173
|
+
emitOnBegin,
|
4174
|
+
interval: pollingInterval
|
4175
|
+
}
|
4176
|
+
)
|
4177
|
+
);
|
4178
|
+
}
|
4179
|
+
|
4180
|
+
// src/actions/public/watchBlocks.ts
|
4181
|
+
function watchBlocks(client, {
|
4182
|
+
blockTag = "latest",
|
4183
|
+
emitMissed = false,
|
4184
|
+
emitOnBegin = false,
|
4185
|
+
onBlock,
|
4186
|
+
onError,
|
4187
|
+
includeTransactions = false,
|
4188
|
+
pollingInterval = client.pollingInterval
|
4189
|
+
}) {
|
4190
|
+
const observerId = JSON.stringify([
|
4191
|
+
"watchBlocks",
|
4192
|
+
client.uid,
|
4193
|
+
emitMissed,
|
4194
|
+
emitOnBegin,
|
4195
|
+
includeTransactions,
|
4196
|
+
pollingInterval
|
4197
|
+
]);
|
4198
|
+
let prevBlock;
|
4199
|
+
return observe(
|
4200
|
+
observerId,
|
4201
|
+
{ onBlock, onError },
|
4202
|
+
(emit) => poll(
|
4203
|
+
async () => {
|
4204
|
+
try {
|
4205
|
+
const block = await getBlock(client, {
|
4206
|
+
blockTag,
|
4207
|
+
includeTransactions
|
4208
|
+
});
|
4209
|
+
if (block.number && prevBlock?.number) {
|
4210
|
+
if (block.number === prevBlock.number)
|
4211
|
+
return;
|
4212
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
4213
|
+
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
4214
|
+
const block2 = await getBlock(client, {
|
4215
|
+
blockNumber: i,
|
4216
|
+
includeTransactions
|
4217
|
+
});
|
4218
|
+
emit.onBlock(block2, prevBlock);
|
4219
|
+
prevBlock = block2;
|
4220
|
+
}
|
4221
|
+
}
|
4222
|
+
}
|
4223
|
+
emit.onBlock(block, prevBlock);
|
4224
|
+
prevBlock = block;
|
4225
|
+
} catch (err) {
|
4226
|
+
emit.onError?.(err);
|
4227
|
+
}
|
4228
|
+
},
|
4229
|
+
{
|
4230
|
+
emitOnBegin,
|
4231
|
+
interval: pollingInterval
|
4232
|
+
}
|
4233
|
+
)
|
4234
|
+
);
|
4235
|
+
}
|
4236
|
+
|
4237
|
+
// src/actions/public/watchContractEvent.ts
|
4238
|
+
function watchContractEvent(client, {
|
4239
|
+
abi,
|
4240
|
+
address,
|
4241
|
+
args,
|
4242
|
+
batch = true,
|
4243
|
+
eventName,
|
4244
|
+
onError,
|
4245
|
+
onLogs,
|
4246
|
+
pollingInterval = client.pollingInterval
|
4247
|
+
}) {
|
4248
|
+
const observerId = JSON.stringify([
|
4249
|
+
"watchContractEvent",
|
4250
|
+
address,
|
4251
|
+
args,
|
4252
|
+
batch,
|
4253
|
+
client.uid,
|
4254
|
+
eventName,
|
4255
|
+
pollingInterval
|
4256
|
+
]);
|
4257
|
+
return observe(observerId, { onLogs, onError }, (emit) => {
|
4258
|
+
let currentBlockNumber;
|
4259
|
+
let filter;
|
4260
|
+
let initialized = false;
|
4261
|
+
const unwatch = poll(
|
4262
|
+
async () => {
|
4263
|
+
if (!initialized) {
|
4264
|
+
try {
|
4265
|
+
filter = await createContractEventFilter(client, {
|
4266
|
+
abi,
|
4267
|
+
address,
|
4268
|
+
args,
|
4269
|
+
eventName
|
4270
|
+
});
|
4271
|
+
} catch {
|
4272
|
+
}
|
4273
|
+
initialized = true;
|
4274
|
+
return;
|
4275
|
+
}
|
4276
|
+
try {
|
4277
|
+
let logs;
|
4278
|
+
if (filter) {
|
4279
|
+
logs = await getFilterChanges(client, { filter });
|
4280
|
+
} else {
|
4281
|
+
const blockNumber = await getBlockNumber(client);
|
4282
|
+
if (currentBlockNumber && currentBlockNumber !== blockNumber) {
|
4283
|
+
logs = await getLogs(client, {
|
4284
|
+
address,
|
4285
|
+
args,
|
4286
|
+
fromBlock: blockNumber,
|
4287
|
+
toBlock: blockNumber,
|
4288
|
+
event: getAbiItem({
|
4289
|
+
abi,
|
4290
|
+
name: eventName
|
4291
|
+
})
|
4292
|
+
});
|
4293
|
+
} else {
|
4294
|
+
logs = [];
|
4295
|
+
}
|
4296
|
+
currentBlockNumber = blockNumber;
|
4297
|
+
}
|
4298
|
+
if (logs.length === 0)
|
4299
|
+
return;
|
4300
|
+
if (batch)
|
4301
|
+
emit.onLogs(logs);
|
4302
|
+
else
|
4303
|
+
logs.forEach((log) => emit.onLogs([log]));
|
4304
|
+
} catch (err) {
|
4305
|
+
emit.onError?.(err);
|
4306
|
+
}
|
4307
|
+
},
|
4308
|
+
{
|
4309
|
+
emitOnBegin: true,
|
4310
|
+
interval: pollingInterval
|
4311
|
+
}
|
4312
|
+
);
|
4313
|
+
return async () => {
|
4314
|
+
if (filter)
|
4315
|
+
await uninstallFilter(client, { filter });
|
4316
|
+
unwatch();
|
4317
|
+
};
|
4318
|
+
});
|
4319
|
+
}
|
4320
|
+
|
4321
|
+
// src/actions/public/watchEvent.ts
|
4322
|
+
function watchEvent(client, {
|
4323
|
+
address,
|
4324
|
+
args,
|
4325
|
+
batch = true,
|
4326
|
+
event,
|
4327
|
+
onError,
|
4328
|
+
onLogs,
|
4329
|
+
pollingInterval = client.pollingInterval
|
4330
|
+
}) {
|
4331
|
+
const observerId = JSON.stringify([
|
4332
|
+
"watchEvent",
|
4333
|
+
address,
|
4334
|
+
args,
|
4335
|
+
batch,
|
4336
|
+
client.uid,
|
4337
|
+
event,
|
4338
|
+
pollingInterval
|
4339
|
+
]);
|
4340
|
+
return observe(observerId, { onLogs, onError }, (emit) => {
|
4341
|
+
let currentBlockNumber;
|
4342
|
+
let filter;
|
4343
|
+
let initialized = false;
|
4344
|
+
const unwatch = poll(
|
4345
|
+
async () => {
|
4346
|
+
if (!initialized) {
|
4347
|
+
try {
|
4348
|
+
filter = await createEventFilter(client, {
|
4349
|
+
address,
|
4350
|
+
args,
|
4351
|
+
event
|
4352
|
+
});
|
4353
|
+
} catch {
|
4354
|
+
}
|
4355
|
+
initialized = true;
|
4356
|
+
return;
|
4357
|
+
}
|
4358
|
+
try {
|
4359
|
+
let logs;
|
4360
|
+
if (filter) {
|
4361
|
+
logs = await getFilterChanges(client, { filter });
|
4362
|
+
} else {
|
4363
|
+
const blockNumber = await getBlockNumber(client);
|
4364
|
+
if (currentBlockNumber && currentBlockNumber !== blockNumber) {
|
4365
|
+
logs = await getLogs(client, {
|
4366
|
+
address,
|
4367
|
+
args,
|
4368
|
+
fromBlock: blockNumber,
|
4369
|
+
toBlock: blockNumber,
|
4370
|
+
event
|
4371
|
+
});
|
4372
|
+
} else {
|
4373
|
+
logs = [];
|
4374
|
+
}
|
4375
|
+
currentBlockNumber = blockNumber;
|
4376
|
+
}
|
4377
|
+
if (logs.length === 0)
|
4378
|
+
return;
|
4379
|
+
if (batch)
|
4380
|
+
emit.onLogs(logs);
|
4381
|
+
else
|
4382
|
+
logs.forEach((log) => emit.onLogs([log]));
|
4383
|
+
} catch (err) {
|
4384
|
+
emit.onError?.(err);
|
4385
|
+
}
|
4386
|
+
},
|
4387
|
+
{
|
4388
|
+
emitOnBegin: true,
|
4389
|
+
interval: pollingInterval
|
4390
|
+
}
|
4391
|
+
);
|
4392
|
+
return async () => {
|
4393
|
+
if (filter)
|
4394
|
+
await uninstallFilter(client, { filter });
|
4395
|
+
unwatch();
|
4396
|
+
};
|
4397
|
+
});
|
4398
|
+
}
|
4399
|
+
|
4400
|
+
// src/actions/public/watchPendingTransactions.ts
|
4401
|
+
function watchPendingTransactions(client, {
|
4402
|
+
batch = true,
|
4403
|
+
onError,
|
4404
|
+
onTransactions,
|
4405
|
+
pollingInterval = client.pollingInterval
|
4406
|
+
}) {
|
4407
|
+
const observerId = JSON.stringify([
|
4408
|
+
"watchPendingTransactions",
|
4409
|
+
client.uid,
|
4410
|
+
batch,
|
4411
|
+
pollingInterval
|
4412
|
+
]);
|
4413
|
+
return observe(observerId, { onTransactions, onError }, (emit) => {
|
4414
|
+
let filter;
|
4415
|
+
const unwatch = poll(
|
4416
|
+
async () => {
|
4417
|
+
try {
|
4418
|
+
if (!filter) {
|
4419
|
+
try {
|
4420
|
+
filter = await createPendingTransactionFilter(client);
|
4421
|
+
return;
|
4422
|
+
} catch (err) {
|
4423
|
+
unwatch();
|
4424
|
+
throw err;
|
4425
|
+
}
|
4426
|
+
}
|
4427
|
+
const hashes = await getFilterChanges(client, { filter });
|
4428
|
+
if (hashes.length === 0)
|
4429
|
+
return;
|
4430
|
+
if (batch)
|
4431
|
+
emit.onTransactions(hashes);
|
4432
|
+
else
|
4433
|
+
hashes.forEach((hash2) => emit.onTransactions([hash2]));
|
4434
|
+
} catch (err) {
|
4435
|
+
emit.onError?.(err);
|
4436
|
+
}
|
4437
|
+
},
|
4438
|
+
{
|
4439
|
+
emitOnBegin: true,
|
4440
|
+
interval: pollingInterval
|
4441
|
+
}
|
4442
|
+
);
|
4443
|
+
return async () => {
|
4444
|
+
if (filter)
|
4445
|
+
await uninstallFilter(client, { filter });
|
4446
|
+
unwatch();
|
4447
|
+
};
|
4448
|
+
});
|
4449
|
+
}
|
4450
|
+
|
4451
|
+
// src/actions/test/dropTransaction.ts
|
4452
|
+
async function dropTransaction(client, { hash: hash2 }) {
|
4453
|
+
return await client.request({
|
4454
|
+
method: `${client.mode}_dropTransaction`,
|
4455
|
+
params: [hash2]
|
4456
|
+
});
|
4457
|
+
}
|
4458
|
+
|
4459
|
+
// src/actions/test/getAutomine.ts
|
4460
|
+
async function getAutomine(client) {
|
4461
|
+
return await client.request({
|
4462
|
+
method: `${client.mode}_getAutomine`
|
4463
|
+
});
|
4464
|
+
}
|
4465
|
+
|
4466
|
+
// src/actions/test/getTxpoolContent.ts
|
4467
|
+
async function getTxpoolContent(client) {
|
4468
|
+
return await client.request({
|
4469
|
+
method: "txpool_content"
|
4470
|
+
});
|
4471
|
+
}
|
4472
|
+
|
4473
|
+
// src/actions/test/getTxpoolStatus.ts
|
4474
|
+
async function getTxpoolStatus(client) {
|
4475
|
+
const { pending, queued } = await client.request({
|
4476
|
+
method: "txpool_status"
|
4477
|
+
});
|
4478
|
+
return {
|
4479
|
+
pending: hexToNumber(pending),
|
4480
|
+
queued: hexToNumber(queued)
|
4481
|
+
};
|
4482
|
+
}
|
4483
|
+
|
4484
|
+
// src/actions/test/impersonateAccount.ts
|
4485
|
+
async function impersonateAccount(client, { address }) {
|
4486
|
+
return await client.request({
|
4487
|
+
method: `${client.mode}_impersonateAccount`,
|
4488
|
+
params: [address]
|
4489
|
+
});
|
4490
|
+
}
|
4491
|
+
|
4492
|
+
// src/actions/test/increaseTime.ts
|
4493
|
+
async function increaseTime(client, { seconds }) {
|
4494
|
+
return await client.request({
|
4495
|
+
method: "evm_increaseTime",
|
4496
|
+
params: [numberToHex(seconds)]
|
4497
|
+
});
|
4498
|
+
}
|
4499
|
+
|
4500
|
+
// src/actions/test/inspectTxpool.ts
|
4501
|
+
async function inspectTxpool(client) {
|
4502
|
+
return await client.request({
|
4503
|
+
method: "txpool_inspect"
|
4504
|
+
});
|
4505
|
+
}
|
4506
|
+
|
4507
|
+
// src/actions/test/mine.ts
|
4508
|
+
async function mine(client, { blocks, interval }) {
|
4509
|
+
return await client.request({
|
4510
|
+
method: `${client.mode}_mine`,
|
4511
|
+
params: [numberToHex(blocks), numberToHex(interval || 0)]
|
4512
|
+
});
|
4513
|
+
}
|
4514
|
+
|
4515
|
+
// src/actions/test/removeBlockTimestampInterval.ts
|
4516
|
+
async function removeBlockTimestampInterval(client) {
|
4517
|
+
return await client.request({
|
4518
|
+
method: `${client.mode}_removeBlockTimestampInterval`
|
4519
|
+
});
|
4520
|
+
}
|
4521
|
+
|
4522
|
+
// src/actions/test/reset.ts
|
4523
|
+
async function reset(client, { blockNumber, jsonRpcUrl } = {}) {
|
4524
|
+
return await client.request({
|
4525
|
+
method: `${client.mode}_reset`,
|
4526
|
+
params: [{ forking: { blockNumber: Number(blockNumber), jsonRpcUrl } }]
|
4527
|
+
});
|
4528
|
+
}
|
4529
|
+
|
4530
|
+
// src/actions/test/revert.ts
|
4531
|
+
async function revert(client, { id: id2 }) {
|
4532
|
+
return await client.request({
|
4533
|
+
method: "evm_revert",
|
4534
|
+
params: [id2]
|
4535
|
+
});
|
4536
|
+
}
|
4537
|
+
|
4538
|
+
// src/actions/test/sendUnsignedTransaction.ts
|
4539
|
+
async function sendUnsignedTransaction(client, request) {
|
4540
|
+
const request_ = formatTransactionRequest(request);
|
4541
|
+
const hash2 = await client.request({
|
4542
|
+
method: "eth_sendUnsignedTransaction",
|
4543
|
+
params: [request_]
|
4544
|
+
});
|
4545
|
+
return hash2;
|
4546
|
+
}
|
4547
|
+
|
4548
|
+
// src/actions/test/setAutomine.ts
|
4549
|
+
async function setAutomine(client, enabled) {
|
4550
|
+
return await client.request({
|
4551
|
+
method: "evm_setAutomine",
|
4552
|
+
params: [enabled]
|
4553
|
+
});
|
4554
|
+
}
|
4555
|
+
|
4556
|
+
// src/actions/test/setBalance.ts
|
4557
|
+
async function setBalance(client, { address, value }) {
|
4558
|
+
return await client.request({
|
4559
|
+
method: `${client.mode}_setBalance`,
|
4560
|
+
params: [address, numberToHex(value)]
|
4561
|
+
});
|
4562
|
+
}
|
4563
|
+
|
4564
|
+
// src/actions/test/setBlockGasLimit.ts
|
4565
|
+
async function setBlockGasLimit(client, { gasLimit }) {
|
4566
|
+
return await client.request({
|
4567
|
+
method: "evm_setBlockGasLimit",
|
4568
|
+
params: [numberToHex(gasLimit)]
|
4569
|
+
});
|
4570
|
+
}
|
4571
|
+
|
4572
|
+
// src/actions/test/setBlockTimestampInterval.ts
|
4573
|
+
async function setBlockTimestampInterval(client, { interval }) {
|
4574
|
+
return await client.request({
|
4575
|
+
method: `${client.mode}_setBlockTimestampInterval`,
|
4576
|
+
params: [interval]
|
4577
|
+
});
|
4578
|
+
}
|
4579
|
+
|
4580
|
+
// src/actions/test/setCode.ts
|
4581
|
+
async function setCode(client, { address, bytecode }) {
|
4582
|
+
return await client.request({
|
4583
|
+
method: `${client.mode}_setCode`,
|
4584
|
+
params: [address, bytecode]
|
4585
|
+
});
|
4586
|
+
}
|
4587
|
+
|
4588
|
+
// src/actions/test/setCoinbase.ts
|
4589
|
+
async function setCoinbase(client, { address }) {
|
4590
|
+
return await client.request({
|
4591
|
+
method: `${client.mode}_setCoinbase`,
|
4592
|
+
params: [address]
|
4593
|
+
});
|
4594
|
+
}
|
4595
|
+
|
4596
|
+
// src/actions/test/setIntervalMining.ts
|
4597
|
+
async function setIntervalMining(client, { interval }) {
|
4598
|
+
return await client.request({
|
4599
|
+
method: "evm_setIntervalMining",
|
4600
|
+
params: [interval]
|
4601
|
+
});
|
4602
|
+
}
|
4603
|
+
|
4604
|
+
// src/actions/test/setLoggingEnabled.ts
|
4605
|
+
async function setLoggingEnabled(client, enabled) {
|
4606
|
+
return await client.request({
|
4607
|
+
method: `${client.mode}_setLoggingEnabled`,
|
4608
|
+
params: [enabled]
|
4609
|
+
});
|
4610
|
+
}
|
4611
|
+
|
4612
|
+
// src/actions/test/setMinGasPrice.ts
|
4613
|
+
async function setMinGasPrice(client, { gasPrice }) {
|
4614
|
+
return await client.request({
|
4615
|
+
method: `${client.mode}_setMinGasPrice`,
|
4616
|
+
params: [numberToHex(gasPrice)]
|
4617
|
+
});
|
4618
|
+
}
|
4619
|
+
|
4620
|
+
// src/actions/test/setNextBlockBaseFeePerGas.ts
|
4621
|
+
async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
|
4622
|
+
return await client.request({
|
4623
|
+
method: `${client.mode}_setNextBlockBaseFeePerGas`,
|
4624
|
+
params: [numberToHex(baseFeePerGas)]
|
4625
|
+
});
|
4626
|
+
}
|
4627
|
+
|
4628
|
+
// src/actions/test/setNextBlockTimestamp.ts
|
4629
|
+
async function setNextBlockTimestamp(client, { timestamp }) {
|
4630
|
+
return await client.request({
|
4631
|
+
method: "evm_setNextBlockTimestamp",
|
4632
|
+
params: [numberToHex(timestamp)]
|
4633
|
+
});
|
4634
|
+
}
|
4635
|
+
|
4636
|
+
// src/actions/test/setNonce.ts
|
4637
|
+
async function setNonce(client, { address, nonce }) {
|
4638
|
+
return await client.request({
|
4639
|
+
method: `${client.mode}_setNonce`,
|
4640
|
+
params: [address, numberToHex(nonce)]
|
4641
|
+
});
|
4642
|
+
}
|
4643
|
+
|
4644
|
+
// src/actions/test/setRpcUrl.ts
|
4645
|
+
async function setRpcUrl(client, jsonRpcUrl) {
|
4646
|
+
return await client.request({
|
4647
|
+
method: `${client.mode}_setRpcUrl`,
|
4648
|
+
params: [jsonRpcUrl]
|
4649
|
+
});
|
4650
|
+
}
|
4651
|
+
|
4652
|
+
// src/actions/test/setStorageAt.ts
|
4653
|
+
async function setStorageAt(client, { address, index, value }) {
|
4654
|
+
return await client.request({
|
4655
|
+
method: `${client.mode}_setStorageAt`,
|
4656
|
+
params: [
|
4657
|
+
address,
|
4658
|
+
typeof index === "number" ? numberToHex(index) : index,
|
4659
|
+
value
|
4660
|
+
]
|
4661
|
+
});
|
4662
|
+
}
|
4663
|
+
|
4664
|
+
// src/actions/test/snapshot.ts
|
4665
|
+
async function snapshot(client) {
|
4666
|
+
return await client.request({
|
4667
|
+
method: "evm_snapshot"
|
4668
|
+
});
|
4669
|
+
}
|
4670
|
+
|
4671
|
+
// src/actions/test/stopImpersonatingAccount.ts
|
4672
|
+
async function stopImpersonatingAccount(client, { address }) {
|
4673
|
+
return await client.request({
|
4674
|
+
method: `${client.mode}_stopImpersonatingAccount`,
|
4675
|
+
params: [address]
|
4676
|
+
});
|
4677
|
+
}
|
4678
|
+
|
4679
|
+
// src/actions/wallet/addChain.ts
|
4680
|
+
async function addChain(client, { chain }) {
|
4681
|
+
const { id: id2, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
|
4682
|
+
await client.request({
|
4683
|
+
method: "wallet_addEthereumChain",
|
4684
|
+
params: [
|
4685
|
+
{
|
4686
|
+
chainId: numberToHex(id2),
|
4687
|
+
chainName: name,
|
4688
|
+
nativeCurrency,
|
4689
|
+
rpcUrls: rpcUrls.default.http,
|
4690
|
+
blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
|
4691
|
+
}
|
4692
|
+
]
|
4693
|
+
});
|
4694
|
+
}
|
4695
|
+
|
4696
|
+
// src/actions/wallet/deployContract.ts
|
4697
|
+
function deployContract(walletClient, { abi, args, bytecode, ...request }) {
|
4698
|
+
const calldata = encodeDeployData({
|
4699
|
+
abi,
|
4700
|
+
args,
|
4701
|
+
bytecode
|
4702
|
+
});
|
4703
|
+
return sendTransaction(walletClient, {
|
4704
|
+
...request,
|
4705
|
+
data: calldata
|
4706
|
+
});
|
4707
|
+
}
|
4708
|
+
|
4709
|
+
// src/actions/wallet/getAddresses.ts
|
4710
|
+
async function getAddresses(client) {
|
4711
|
+
const addresses = await client.request({ method: "eth_accounts" });
|
4712
|
+
return addresses.map((address) => checksumAddress(address));
|
4713
|
+
}
|
4714
|
+
|
4715
|
+
// src/actions/wallet/getPermissions.ts
|
4716
|
+
async function getPermissions(client) {
|
4717
|
+
const permissions = await client.request({ method: "wallet_getPermissions" });
|
4718
|
+
return permissions;
|
4719
|
+
}
|
4720
|
+
|
4721
|
+
// src/actions/wallet/requestAddresses.ts
|
4722
|
+
async function requestAddresses(client) {
|
4723
|
+
const addresses = await client.request({ method: "eth_requestAccounts" });
|
4724
|
+
return addresses.map((address) => getAddress(address));
|
4725
|
+
}
|
4726
|
+
|
4727
|
+
// src/actions/wallet/requestPermissions.ts
|
4728
|
+
async function requestPermissions(client, permissions) {
|
4729
|
+
return client.request({
|
4730
|
+
method: "wallet_requestPermissions",
|
4731
|
+
params: [permissions]
|
4732
|
+
});
|
4733
|
+
}
|
4734
|
+
|
4735
|
+
// src/actions/wallet/sendTransaction.ts
|
4736
|
+
async function sendTransaction(client, args) {
|
4737
|
+
const {
|
4738
|
+
account,
|
4739
|
+
chain,
|
4740
|
+
accessList,
|
4741
|
+
assertChain = true,
|
4742
|
+
data,
|
4743
|
+
gas,
|
4744
|
+
gasPrice,
|
4745
|
+
maxFeePerGas,
|
4746
|
+
maxPriorityFeePerGas,
|
4747
|
+
nonce,
|
4748
|
+
to,
|
4749
|
+
value,
|
4750
|
+
...rest
|
4751
|
+
} = args;
|
4752
|
+
try {
|
4753
|
+
assertRequest(args);
|
4754
|
+
const currentChainId = await getChainId(client);
|
4755
|
+
if (assertChain && chain && currentChainId !== chain?.id)
|
4756
|
+
throw new ChainMismatchError({ chain, currentChainId });
|
4757
|
+
if (account.type === "externally-owned") {
|
4758
|
+
const chainId = chain?.id ?? currentChainId;
|
4759
|
+
const request2 = await prepareRequest(client, {
|
4760
|
+
account,
|
4761
|
+
accessList,
|
4762
|
+
chain,
|
4763
|
+
data,
|
4764
|
+
gas,
|
4765
|
+
gasPrice,
|
4766
|
+
maxFeePerGas,
|
4767
|
+
maxPriorityFeePerGas,
|
4768
|
+
nonce,
|
4769
|
+
to,
|
4770
|
+
value,
|
4771
|
+
...rest
|
4772
|
+
});
|
4773
|
+
const signedRequest = await account.signTransaction({
|
4774
|
+
chainId,
|
4775
|
+
...request2
|
4776
|
+
});
|
4777
|
+
return await client.request({
|
4778
|
+
method: "eth_sendRawTransaction",
|
4779
|
+
params: [signedRequest]
|
4780
|
+
});
|
4781
|
+
}
|
4782
|
+
const formatter = chain?.formatters?.transactionRequest;
|
4783
|
+
const request = format3(
|
4784
|
+
{
|
4785
|
+
accessList,
|
4786
|
+
data,
|
4787
|
+
from: account.address,
|
4788
|
+
gas,
|
4789
|
+
gasPrice,
|
4790
|
+
maxFeePerGas,
|
4791
|
+
maxPriorityFeePerGas,
|
4792
|
+
nonce,
|
4793
|
+
to,
|
4794
|
+
value,
|
4795
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
4796
|
+
...extract(rest, { formatter })
|
4797
|
+
},
|
4798
|
+
{
|
4799
|
+
formatter: formatter || formatTransactionRequest
|
4800
|
+
}
|
4801
|
+
);
|
4802
|
+
return await client.request({
|
4803
|
+
method: "eth_sendTransaction",
|
4804
|
+
params: [request]
|
4805
|
+
});
|
4806
|
+
} catch (err) {
|
4807
|
+
throw getTransactionError(err, args);
|
4808
|
+
}
|
4809
|
+
}
|
4810
|
+
|
4811
|
+
// src/actions/wallet/signMessage.ts
|
4812
|
+
async function signMessage(client, { account, data }) {
|
4813
|
+
if (account.type === "externally-owned")
|
4814
|
+
return account.signMessage(data);
|
4815
|
+
return client.request({
|
4816
|
+
method: "personal_sign",
|
4817
|
+
params: [toHex(data), account.address]
|
4818
|
+
});
|
4819
|
+
}
|
4820
|
+
|
4821
|
+
// src/actions/wallet/switchChain.ts
|
4822
|
+
async function switchChain(client, { id: id2 }) {
|
4823
|
+
await client.request({
|
4824
|
+
method: "wallet_switchEthereumChain",
|
4825
|
+
params: [
|
4826
|
+
{
|
4827
|
+
chainId: numberToHex(id2)
|
4828
|
+
}
|
4829
|
+
]
|
4830
|
+
});
|
4831
|
+
}
|
4832
|
+
|
4833
|
+
// src/actions/wallet/watchAsset.ts
|
4834
|
+
async function watchAsset(client, params) {
|
4835
|
+
const added = await client.request({
|
4836
|
+
method: "wallet_watchAsset",
|
4837
|
+
params: [params]
|
4838
|
+
});
|
4839
|
+
return added;
|
4840
|
+
}
|
4841
|
+
|
4842
|
+
// src/actions/wallet/writeContract.ts
|
4843
|
+
async function writeContract(client, {
|
4844
|
+
abi,
|
4845
|
+
address,
|
4846
|
+
args,
|
4847
|
+
functionName,
|
4848
|
+
...request
|
4849
|
+
}) {
|
4850
|
+
const data = encodeFunctionData({
|
4851
|
+
abi,
|
4852
|
+
args,
|
4853
|
+
functionName
|
4854
|
+
});
|
4855
|
+
const hash2 = await sendTransaction(client, {
|
4856
|
+
data,
|
4857
|
+
to: address,
|
4858
|
+
...request
|
4859
|
+
});
|
4860
|
+
return hash2;
|
4861
|
+
}
|
4862
|
+
|
4863
|
+
// src/utils/unit/parseUnit.ts
|
4864
|
+
function parseUnit(value, decimals) {
|
4865
|
+
let [integer, fraction = "0"] = value.split(".");
|
4866
|
+
const negative = integer.startsWith("-");
|
4867
|
+
if (negative)
|
4868
|
+
integer = integer.slice(1);
|
4869
|
+
fraction = fraction.replace(/(0+)$/, "");
|
4870
|
+
if (decimals === 0) {
|
4871
|
+
integer = `${Math.round(Number(`${integer}.${fraction}`))}`;
|
4872
|
+
fraction = "";
|
4873
|
+
} else if (fraction.length > decimals) {
|
4874
|
+
const [before, after] = [
|
4875
|
+
fraction.slice(0, decimals),
|
4876
|
+
fraction.slice(decimals)
|
4877
|
+
];
|
4878
|
+
fraction = `${/^0+$/.test(before) ? before.slice(0, before.length - 1) : ""}${Math.round(Number(`${before}.${after}`))}`;
|
4879
|
+
} else {
|
4880
|
+
fraction = fraction.padEnd(decimals, "0");
|
4881
|
+
}
|
4882
|
+
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
4883
|
+
}
|
4884
|
+
|
4885
|
+
// src/utils/unit/parseGwei.ts
|
4886
|
+
function parseGwei(ether, unit = "wei") {
|
4887
|
+
return parseUnit(ether, gweiUnits[unit]);
|
4888
|
+
}
|
4889
|
+
|
4890
|
+
// src/utils/transaction/prepareRequest.ts
|
4891
|
+
var defaultTip = parseGwei("1.5");
|
4892
|
+
async function prepareRequest(client, args) {
|
4893
|
+
const { account, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce } = args;
|
4894
|
+
const block = await getBlock(client, { blockTag: "latest" });
|
4895
|
+
const request = { ...args, from: account.address };
|
4896
|
+
if (typeof nonce === "undefined")
|
4897
|
+
request.nonce = await getTransactionCount(client, {
|
4898
|
+
address: account.address,
|
4899
|
+
blockTag: "pending"
|
4900
|
+
});
|
4901
|
+
if (block.baseFeePerGas) {
|
4902
|
+
if (typeof gasPrice !== "undefined")
|
4903
|
+
throw new BaseError("Chain does not support legacy `gasPrice`.");
|
4904
|
+
if (typeof maxFeePerGas === "undefined") {
|
4905
|
+
request.maxPriorityFeePerGas = maxPriorityFeePerGas ?? defaultTip;
|
4906
|
+
request.maxFeePerGas = block.baseFeePerGas * 120n / 100n + request.maxPriorityFeePerGas;
|
4907
|
+
} else {
|
4908
|
+
if (typeof maxPriorityFeePerGas === "undefined" && maxFeePerGas < defaultTip)
|
4909
|
+
throw new BaseError(
|
4910
|
+
"`maxFeePerGas` cannot be less than the default `maxPriorityFeePerGas` (1.5 gwei)."
|
4911
|
+
);
|
4912
|
+
request.maxFeePerGas = maxFeePerGas;
|
4913
|
+
request.maxPriorityFeePerGas = maxPriorityFeePerGas ?? defaultTip;
|
4914
|
+
}
|
4915
|
+
} else {
|
4916
|
+
if (typeof maxFeePerGas !== "undefined" || typeof maxPriorityFeePerGas !== "undefined")
|
4917
|
+
throw new BaseError("Chain does not support EIP-1559 fees.");
|
4918
|
+
if (typeof gasPrice === "undefined")
|
4919
|
+
request.gasPrice = await getGasPrice(client) * 120n / 100n;
|
4920
|
+
}
|
4921
|
+
if (typeof gas === "undefined")
|
4922
|
+
request.gas = await estimateGas(client, {
|
4923
|
+
...request,
|
4924
|
+
account: { address: account.address, type: "json-rpc" }
|
4925
|
+
});
|
4926
|
+
assertRequest(request);
|
4927
|
+
return request;
|
4928
|
+
}
|
4929
|
+
|
4930
|
+
// src/utils/unit/formatUnit.ts
|
4931
|
+
function formatUnit(value, decimals) {
|
4932
|
+
let display = value.toString();
|
4933
|
+
const negative = display.startsWith("-");
|
4934
|
+
if (negative)
|
4935
|
+
display = display.slice(1);
|
4936
|
+
display = display.padStart(decimals, "0");
|
4937
|
+
let [integer, fraction] = [
|
4938
|
+
display.slice(0, display.length - decimals),
|
4939
|
+
display.slice(display.length - decimals)
|
4940
|
+
];
|
4941
|
+
fraction = fraction.replace(/(0+)$/, "");
|
4942
|
+
return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
|
4943
|
+
}
|
4944
|
+
|
4945
|
+
// src/utils/unit/formatEther.ts
|
4946
|
+
function formatEther(wei, unit = "wei") {
|
4947
|
+
return formatUnit(wei, etherUnits[unit]);
|
4948
|
+
}
|
4949
|
+
|
4950
|
+
// src/utils/unit/formatGwei.ts
|
4951
|
+
function formatGwei(wei, unit = "wei") {
|
4952
|
+
return formatUnit(wei, gweiUnits[unit]);
|
4953
|
+
}
|
4954
|
+
|
4955
|
+
// src/utils/unit/parseEther.ts
|
4956
|
+
function parseEther(ether, unit = "wei") {
|
4957
|
+
return parseUnit(ether, etherUnits[unit]);
|
4958
|
+
}
|
4959
|
+
|
4960
|
+
export {
|
4961
|
+
BaseError,
|
4962
|
+
AbiConstructorNotFoundError,
|
4963
|
+
AbiConstructorParamsNotFoundError,
|
3293
4964
|
AbiDecodingDataSizeInvalidError,
|
3294
4965
|
AbiDecodingZeroDataError,
|
3295
4966
|
AbiEncodingArrayLengthMismatchError,
|
@@ -3311,6 +4982,9 @@ export {
|
|
3311
4982
|
ChainDoesNotSupportContract,
|
3312
4983
|
multicall3Abi,
|
3313
4984
|
panicReasons,
|
4985
|
+
etherUnits,
|
4986
|
+
gweiUnits,
|
4987
|
+
weiUnits,
|
3314
4988
|
TransactionExecutionError,
|
3315
4989
|
TransactionNotFoundError,
|
3316
4990
|
TransactionReceiptNotFoundError,
|
@@ -3379,8 +5053,8 @@ export {
|
|
3379
5053
|
toHex,
|
3380
5054
|
numberToHex,
|
3381
5055
|
stringToHex,
|
3382
|
-
boolToBytes,
|
3383
5056
|
toBytes,
|
5057
|
+
boolToBytes,
|
3384
5058
|
hexToBytes,
|
3385
5059
|
numberToBytes,
|
3386
5060
|
stringToBytes,
|
@@ -3404,14 +5078,13 @@ export {
|
|
3404
5078
|
getEventSelector,
|
3405
5079
|
getFunctionSelector,
|
3406
5080
|
isAddress,
|
3407
|
-
checksumAddress,
|
3408
5081
|
getAddress,
|
3409
5082
|
getContractAddress2 as getContractAddress,
|
3410
5083
|
getCreateAddress,
|
3411
5084
|
getCreate2Address,
|
3412
5085
|
isAddressEqual,
|
3413
|
-
|
3414
|
-
|
5086
|
+
encodeAbiParameters,
|
5087
|
+
decodeAbiParameters,
|
3415
5088
|
formatAbiItem,
|
3416
5089
|
decodeErrorResult,
|
3417
5090
|
decodeEventLog,
|
@@ -3424,9 +5097,7 @@ export {
|
|
3424
5097
|
encodeFunctionData,
|
3425
5098
|
encodeFunctionResult,
|
3426
5099
|
formatAbiItemWithArgs,
|
3427
|
-
|
3428
|
-
withCache,
|
3429
|
-
wait,
|
5100
|
+
getAccount,
|
3430
5101
|
isDeterministicError,
|
3431
5102
|
buildRequest,
|
3432
5103
|
defineChain,
|
@@ -3438,13 +5109,9 @@ export {
|
|
3438
5109
|
formatBlock,
|
3439
5110
|
defineBlock,
|
3440
5111
|
extract,
|
3441
|
-
formatFeeHistory,
|
3442
|
-
formatLog,
|
3443
|
-
formatTransactionReceipt,
|
3444
5112
|
defineTransactionReceipt,
|
3445
5113
|
formatTransactionRequest,
|
3446
5114
|
defineTransactionRequest,
|
3447
|
-
assertRequest,
|
3448
5115
|
containsNodeError,
|
3449
5116
|
getNodeError,
|
3450
5117
|
getCallError,
|
@@ -3454,14 +5121,86 @@ export {
|
|
3454
5121
|
stringify,
|
3455
5122
|
getSocket,
|
3456
5123
|
rpc,
|
3457
|
-
|
3458
|
-
|
3459
|
-
|
5124
|
+
assertRequest,
|
5125
|
+
call,
|
5126
|
+
simulateContract,
|
5127
|
+
createPendingTransactionFilter,
|
5128
|
+
createBlockFilter,
|
5129
|
+
createEventFilter,
|
5130
|
+
createContractEventFilter,
|
5131
|
+
estimateGas,
|
5132
|
+
estimateContractGas,
|
5133
|
+
getBalance,
|
5134
|
+
getBlock,
|
5135
|
+
getBlockNumberCache,
|
5136
|
+
getBlockNumber,
|
5137
|
+
getBlockTransactionCount,
|
5138
|
+
getBytecode,
|
5139
|
+
getChainId,
|
5140
|
+
getFeeHistory,
|
5141
|
+
getFilterChanges,
|
5142
|
+
getFilterLogs,
|
5143
|
+
getGasPrice,
|
5144
|
+
getLogs,
|
5145
|
+
getStorageAt,
|
5146
|
+
getTransaction,
|
5147
|
+
getTransactionConfirmations,
|
5148
|
+
getTransactionCount,
|
5149
|
+
getTransactionReceipt,
|
5150
|
+
readContract,
|
5151
|
+
multicall,
|
5152
|
+
uninstallFilter,
|
5153
|
+
waitForTransactionReceipt,
|
5154
|
+
watchBlockNumber,
|
5155
|
+
watchBlocks,
|
5156
|
+
watchContractEvent,
|
5157
|
+
watchEvent,
|
5158
|
+
watchPendingTransactions,
|
5159
|
+
dropTransaction,
|
5160
|
+
getAutomine,
|
5161
|
+
getTxpoolContent,
|
5162
|
+
getTxpoolStatus,
|
5163
|
+
impersonateAccount,
|
5164
|
+
increaseTime,
|
5165
|
+
inspectTxpool,
|
5166
|
+
mine,
|
5167
|
+
removeBlockTimestampInterval,
|
5168
|
+
reset,
|
5169
|
+
revert,
|
5170
|
+
sendUnsignedTransaction,
|
5171
|
+
setAutomine,
|
5172
|
+
setBalance,
|
5173
|
+
setBlockGasLimit,
|
5174
|
+
setBlockTimestampInterval,
|
5175
|
+
setCode,
|
5176
|
+
setCoinbase,
|
5177
|
+
setIntervalMining,
|
5178
|
+
setLoggingEnabled,
|
5179
|
+
setMinGasPrice,
|
5180
|
+
setNextBlockBaseFeePerGas,
|
5181
|
+
setNextBlockTimestamp,
|
5182
|
+
setNonce,
|
5183
|
+
setRpcUrl,
|
5184
|
+
setStorageAt,
|
5185
|
+
snapshot,
|
5186
|
+
stopImpersonatingAccount,
|
5187
|
+
addChain,
|
5188
|
+
deployContract,
|
5189
|
+
getAddresses,
|
5190
|
+
getPermissions,
|
5191
|
+
requestAddresses,
|
5192
|
+
requestPermissions,
|
5193
|
+
sendTransaction,
|
5194
|
+
signMessage,
|
5195
|
+
switchChain,
|
5196
|
+
watchAsset,
|
5197
|
+
writeContract,
|
5198
|
+
parseUnit,
|
5199
|
+
parseGwei,
|
5200
|
+
prepareRequest,
|
3460
5201
|
formatUnit,
|
3461
5202
|
formatEther,
|
3462
5203
|
formatGwei,
|
3463
|
-
|
3464
|
-
parseEther,
|
3465
|
-
parseGwei
|
5204
|
+
parseEther
|
3466
5205
|
};
|
3467
|
-
//# sourceMappingURL=chunk-
|
5206
|
+
//# sourceMappingURL=chunk-AXATFOBJ.mjs.map
|