viem 0.1.23 → 0.2.0-0-2-0.20230328T054201
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/accounts/package.json +4 -0
- package/dist/abi.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/accounts/index.d.ts +90 -0
- package/dist/accounts/index.js +152 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/index.mjs +152 -0
- package/dist/accounts/index.mjs.map +1 -0
- package/dist/{chain-ec8c485d.d.ts → chain-40443542.d.ts} +1 -1
- package/dist/{chain-1b53ef88.d.ts → chain-4af995bf.d.ts} +77 -36
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/chunk-43HQD3IL.js +31 -0
- package/dist/chunk-43HQD3IL.js.map +1 -0
- package/dist/{chunk-HRVPAYH7.mjs → chunk-DFMQLPHS.mjs} +2 -2
- package/dist/chunk-DFMQLPHS.mjs.map +1 -0
- package/dist/{chunk-66PXETQB.js → chunk-FZPFAAOJ.js} +19 -19
- package/dist/chunk-FZPFAAOJ.js.map +1 -0
- package/dist/{chunk-JG6MI5ZV.mjs → chunk-HYEOQX7O.mjs} +1106 -199
- package/dist/chunk-HYEOQX7O.mjs.map +1 -0
- package/dist/{chunk-Z54YSSBJ.js → chunk-OW7TKT7L.js} +1168 -261
- package/dist/chunk-OW7TKT7L.js.map +1 -0
- package/dist/chunk-UK6FAD4V.mjs +31 -0
- package/dist/chunk-UK6FAD4V.mjs.map +1 -0
- package/dist/contract.d.ts +9 -7
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-a28317a9.d.ts → createClient-1f19be8d.d.ts} +24 -10
- package/dist/{createPublicClient-b250a534.d.ts → createPublicClient-fd8b1349.d.ts} +229 -242
- package/dist/{eip1193-4f4e240c.d.ts → eip1193-210ab776.d.ts} +1 -1
- package/dist/{encodeFunctionResult-1f324375.d.ts → encodeFunctionResult-a252fba1.d.ts} +1 -1
- package/dist/{encodePacked-d5d5264a.d.ts → encodePacked-a9464e97.d.ts} +1 -1
- package/dist/ens.d.ts +6 -4
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +5 -6
- package/dist/ethers.js +7 -5
- package/dist/ethers.js.map +1 -1
- package/dist/ethers.mjs +7 -5
- package/dist/ethers.mjs.map +1 -1
- package/dist/{formatAbiItem-15e8817d.d.ts → formatAbiItem-6ed70dbd.d.ts} +1 -1
- package/dist/{getAbiItem-3e809ff9.d.ts → getAbiItem-1ff0f41a.d.ts} +1 -1
- package/dist/index.d.ts +22 -14
- package/dist/index.js +136 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -43
- package/dist/index.mjs.map +1 -1
- package/dist/parseAccount-8e131c73.d.ts +6 -0
- package/dist/{parseGwei-bd0eea6c.d.ts → parseGwei-5e2a8e87.d.ts} +95 -15
- package/dist/public.d.ts +6 -4
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/test-e28db435.d.ts +198 -0
- package/dist/test.d.ts +11 -11
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/typedData-848139b1.d.ts +93 -0
- package/dist/utils/index.d.ts +22 -30
- package/dist/utils/index.js +26 -2
- package/dist/utils/index.mjs +29 -5
- package/dist/wallet.d.ts +6 -4
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/window.d.ts +2 -2
- package/package.json +10 -2
- package/dist/chunk-66PXETQB.js.map +0 -1
- package/dist/chunk-HRVPAYH7.mjs.map +0 -1
- package/dist/chunk-JG6MI5ZV.mjs.map +0 -1
- package/dist/chunk-Z54YSSBJ.js.map +0 -1
- package/dist/test-2bd23d7e.d.ts +0 -205
@@ -25,7 +25,7 @@ var package_default = {
|
|
25
25
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
26
26
|
bench: "vitest bench --no-threads",
|
27
27
|
"bench:ci": "CI=true vitest bench --no-threads",
|
28
|
-
build: "tsup",
|
28
|
+
build: "tsup && size-limit",
|
29
29
|
changeset: "changeset",
|
30
30
|
"changeset:release": "pnpm build && changeset publish",
|
31
31
|
"changeset:version": "changeset version && pnpm install --lockfile-only",
|
@@ -53,6 +53,7 @@ var package_default = {
|
|
53
53
|
entry: [
|
54
54
|
"src/index.ts",
|
55
55
|
"src/abi.ts",
|
56
|
+
"src/accounts/index.ts",
|
56
57
|
"src/chains.ts",
|
57
58
|
"src/contract.ts",
|
58
59
|
"src/ens.ts",
|
@@ -66,6 +67,7 @@ var package_default = {
|
|
66
67
|
},
|
67
68
|
files: [
|
68
69
|
"/abi",
|
70
|
+
"/accounts",
|
69
71
|
"/dist",
|
70
72
|
"/chains",
|
71
73
|
"/contract",
|
@@ -88,6 +90,11 @@ var package_default = {
|
|
88
90
|
module: "./dist/abi.mts",
|
89
91
|
default: "./dist/abi.js"
|
90
92
|
},
|
93
|
+
"./accounts": {
|
94
|
+
types: "./dist/accounts/index.d.ts",
|
95
|
+
module: "./dist/accounts/index.mts",
|
96
|
+
default: "./dist/accounts/index.js"
|
97
|
+
},
|
91
98
|
"./chains": {
|
92
99
|
types: "./dist/chains.d.ts",
|
93
100
|
module: "./dist/chains.mts",
|
@@ -142,6 +149,8 @@ var package_default = {
|
|
142
149
|
dependencies: {
|
143
150
|
"@noble/hashes": "^1.1.2",
|
144
151
|
"@noble/secp256k1": "^1.7.1",
|
152
|
+
"@scure/bip32": "^1.2.0",
|
153
|
+
"@scure/bip39": "^1.1.1",
|
145
154
|
"@wagmi/chains": "~0.2.11",
|
146
155
|
abitype: "~0.7.1",
|
147
156
|
"idna-uts46-hx": "^4.1.2",
|
@@ -154,6 +163,7 @@ var package_default = {
|
|
154
163
|
"@adraffy/ens-normalize": "^1.8.9",
|
155
164
|
"@changesets/changelog-github": "^0.4.5",
|
156
165
|
"@changesets/cli": "^2.23.2",
|
166
|
+
"@size-limit/preset-big-lib": "^8.2.4",
|
157
167
|
"@types/dedent": "^0.7.0",
|
158
168
|
"@types/fs-extra": "^9.0.13",
|
159
169
|
"@types/node": "^17.0.45",
|
@@ -171,6 +181,7 @@ var package_default = {
|
|
171
181
|
rimraf: "^4.1.2",
|
172
182
|
rome: "^11.0.0",
|
173
183
|
"simple-git-hooks": "^2.8.1",
|
184
|
+
"size-limit": "^8.2.4",
|
174
185
|
tsup: "^6.6.0",
|
175
186
|
typescript: "^4.9.4",
|
176
187
|
vite: "^4.1.4",
|
@@ -189,6 +200,11 @@ var package_default = {
|
|
189
200
|
"wallet",
|
190
201
|
"web3"
|
191
202
|
],
|
203
|
+
"size-limit": [
|
204
|
+
{
|
205
|
+
path: "dist/index.js"
|
206
|
+
}
|
207
|
+
],
|
192
208
|
"simple-git-hooks": {
|
193
209
|
"pre-commit": "pnpm format && pnpm lint:fix"
|
194
210
|
},
|
@@ -218,7 +234,9 @@ var BaseError = class extends Error {
|
|
218
234
|
shortMessage || "An error occurred.",
|
219
235
|
"",
|
220
236
|
...args.metaMessages ? [...args.metaMessages, ""] : [],
|
221
|
-
...docsPath6 ? [
|
237
|
+
...docsPath6 ? [
|
238
|
+
`Docs: https://viem.sh${docsPath6}.html${args.docsSlug ? `#${args.docsSlug}` : ""}`
|
239
|
+
] : [],
|
222
240
|
...details ? [`Details: ${details}`] : [],
|
223
241
|
`Version: ${getVersion()}`
|
224
242
|
].join("\n");
|
@@ -519,6 +537,23 @@ var UnsupportedPackedAbiType = class extends BaseError {
|
|
519
537
|
}
|
520
538
|
};
|
521
539
|
|
540
|
+
// src/errors/account.ts
|
541
|
+
var AccountNotFoundError = class extends BaseError {
|
542
|
+
constructor({ docsPath: docsPath6 } = {}) {
|
543
|
+
super(
|
544
|
+
[
|
545
|
+
"Could not find an Account to execute with this Action.",
|
546
|
+
"Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the WalletClient."
|
547
|
+
].join("\n"),
|
548
|
+
{
|
549
|
+
docsPath: docsPath6,
|
550
|
+
docsSlug: "account"
|
551
|
+
}
|
552
|
+
);
|
553
|
+
__publicField(this, "name", "AccountNotFoundError");
|
554
|
+
}
|
555
|
+
};
|
556
|
+
|
522
557
|
// src/errors/address.ts
|
523
558
|
var InvalidAddressError = class extends BaseError {
|
524
559
|
constructor({ address }) {
|
@@ -583,6 +618,23 @@ var ChainMismatchError = class extends BaseError {
|
|
583
618
|
__publicField(this, "name", "ChainMismatchError");
|
584
619
|
}
|
585
620
|
};
|
621
|
+
var ChainNotFoundError = class extends BaseError {
|
622
|
+
constructor() {
|
623
|
+
super(
|
624
|
+
[
|
625
|
+
"No chain was provided to the request.",
|
626
|
+
"Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."
|
627
|
+
].join("\n")
|
628
|
+
);
|
629
|
+
__publicField(this, "name", "ChainNotFoundError");
|
630
|
+
}
|
631
|
+
};
|
632
|
+
var InvalidChainIdError = class extends BaseError {
|
633
|
+
constructor({ chainId }) {
|
634
|
+
super(`Chain ID "${chainId}" is invalid.`);
|
635
|
+
__publicField(this, "name", "InvalidChainIdError");
|
636
|
+
}
|
637
|
+
};
|
586
638
|
|
587
639
|
// src/constants/abis.ts
|
588
640
|
var multicall3Abi = [
|
@@ -697,6 +749,69 @@ var FeeConflictError = class extends BaseError {
|
|
697
749
|
__publicField(this, "name", "FeeConflictError");
|
698
750
|
}
|
699
751
|
};
|
752
|
+
var InvalidLegacyVError = class extends BaseError {
|
753
|
+
constructor({ v }) {
|
754
|
+
super(`Invalid \`v\` value "${v}". Expected 27 or 28.`);
|
755
|
+
__publicField(this, "name", "InvalidLegacyVError");
|
756
|
+
}
|
757
|
+
};
|
758
|
+
var InvalidSerializableTransactionError = class extends BaseError {
|
759
|
+
constructor({ transaction }) {
|
760
|
+
super("Cannot infer a transaction type from provided transaction.", {
|
761
|
+
metaMessages: [
|
762
|
+
"Provided Transaction:",
|
763
|
+
"{",
|
764
|
+
prettyPrint(transaction),
|
765
|
+
"}",
|
766
|
+
"",
|
767
|
+
"To infer the type, either provide:",
|
768
|
+
"- a `type` to the Transaction, or",
|
769
|
+
"- an EIP-1559 Transaction with `maxFeePerGas`, or",
|
770
|
+
"- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
|
771
|
+
"- a Legacy Transaction with `gasPrice`"
|
772
|
+
]
|
773
|
+
});
|
774
|
+
__publicField(this, "name", "InvalidSerializableTransactionError");
|
775
|
+
}
|
776
|
+
};
|
777
|
+
var InvalidSerializedTransactionTypeError = class extends BaseError {
|
778
|
+
constructor({ serializedType }) {
|
779
|
+
super(`Serialized transaction type "${serializedType}" is invalid.`);
|
780
|
+
__publicField(this, "name", "InvalidSerializedTransactionType");
|
781
|
+
__publicField(this, "serializedType");
|
782
|
+
this.serializedType = serializedType;
|
783
|
+
}
|
784
|
+
};
|
785
|
+
var InvalidSerializedTransactionError = class extends BaseError {
|
786
|
+
constructor({
|
787
|
+
attributes,
|
788
|
+
serializedTransaction,
|
789
|
+
type
|
790
|
+
}) {
|
791
|
+
const missing = Object.entries(attributes).map(([key, value]) => typeof value === "undefined" ? key : void 0).filter(Boolean);
|
792
|
+
super(`Invalid serialized transaction of type "${type}" was provided.`, {
|
793
|
+
metaMessages: [
|
794
|
+
`Serialized Transaction: "${serializedTransaction}"`,
|
795
|
+
missing.length > 0 ? `Missing Attributes: ${missing.join(", ")}` : ""
|
796
|
+
].filter(Boolean)
|
797
|
+
});
|
798
|
+
__publicField(this, "name", "InvalidSerializedTransactionError");
|
799
|
+
__publicField(this, "serializedTransaction");
|
800
|
+
__publicField(this, "type");
|
801
|
+
this.serializedTransaction = serializedTransaction;
|
802
|
+
this.type = type;
|
803
|
+
}
|
804
|
+
};
|
805
|
+
var InvalidStorageKeySizeError = class extends BaseError {
|
806
|
+
constructor({ storageKey }) {
|
807
|
+
super(
|
808
|
+
`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor(
|
809
|
+
(storageKey.length - 2) / 2
|
810
|
+
)} bytes.`
|
811
|
+
);
|
812
|
+
__publicField(this, "name", "InvalidStorageKeySizeError");
|
813
|
+
}
|
814
|
+
};
|
700
815
|
var TransactionExecutionError = class extends BaseError {
|
701
816
|
constructor(cause, {
|
702
817
|
account,
|
@@ -713,7 +828,7 @@ var TransactionExecutionError = class extends BaseError {
|
|
713
828
|
}) {
|
714
829
|
const prettyArgs = prettyPrint({
|
715
830
|
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
716
|
-
from: account
|
831
|
+
from: account?.address,
|
717
832
|
to,
|
718
833
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
719
834
|
data,
|
@@ -778,7 +893,7 @@ var WaitForTransactionReceiptTimeoutError = class extends BaseError {
|
|
778
893
|
// src/errors/contract.ts
|
779
894
|
var CallExecutionError = class extends BaseError {
|
780
895
|
constructor(cause, {
|
781
|
-
account,
|
896
|
+
account: account_,
|
782
897
|
docsPath: docsPath6,
|
783
898
|
chain,
|
784
899
|
data,
|
@@ -790,6 +905,7 @@ var CallExecutionError = class extends BaseError {
|
|
790
905
|
to,
|
791
906
|
value
|
792
907
|
}) {
|
908
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
793
909
|
const prettyArgs = prettyPrint({
|
794
910
|
from: account?.address,
|
795
911
|
to,
|
@@ -1032,7 +1148,7 @@ var EstimateGasExecutionError = class extends BaseError {
|
|
1032
1148
|
value
|
1033
1149
|
}) {
|
1034
1150
|
const prettyArgs = prettyPrint({
|
1035
|
-
from: account
|
1151
|
+
from: account?.address,
|
1036
1152
|
to,
|
1037
1153
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
1038
1154
|
data,
|
@@ -1921,6 +2037,11 @@ var getEventSelector = (event) => hashFunction(event);
|
|
1921
2037
|
// src/utils/hash/getFunctionSelector.ts
|
1922
2038
|
var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
|
1923
2039
|
|
2040
|
+
// src/utils/hash/isHash.ts
|
2041
|
+
function isHash(hash2) {
|
2042
|
+
return hash2.startsWith("0x") && size(hash2) === 32;
|
2043
|
+
}
|
2044
|
+
|
1924
2045
|
// src/utils/address/isAddress.ts
|
1925
2046
|
var addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
1926
2047
|
function isAddress(address) {
|
@@ -2828,19 +2949,11 @@ function formatAbiItemWithArgs({
|
|
2828
2949
|
).join(", ")})`;
|
2829
2950
|
}
|
2830
2951
|
|
2831
|
-
// src/utils/
|
2832
|
-
function
|
2833
|
-
if (typeof account === "string")
|
2834
|
-
if (!isAddress(account))
|
2835
|
-
throw new InvalidAddressError({ address: account });
|
2952
|
+
// src/accounts/utils/parseAccount.ts
|
2953
|
+
function parseAccount(account) {
|
2954
|
+
if (typeof account === "string")
|
2836
2955
|
return { address: account, type: "json-rpc" };
|
2837
|
-
|
2838
|
-
if (!isAddress(account.address))
|
2839
|
-
throw new InvalidAddressError({ address: account.address });
|
2840
|
-
return {
|
2841
|
-
...account,
|
2842
|
-
type: "local"
|
2843
|
-
};
|
2956
|
+
return account;
|
2844
2957
|
}
|
2845
2958
|
|
2846
2959
|
// src/utils/promise/withCache.ts
|
@@ -3507,15 +3620,224 @@ ${messageBytes.length}`
|
|
3507
3620
|
return keccak256(concat([prefixBytes, messageBytes]), to_);
|
3508
3621
|
}
|
3509
3622
|
|
3623
|
+
// src/utils/typedData.ts
|
3624
|
+
function validateTypedData({
|
3625
|
+
domain,
|
3626
|
+
message,
|
3627
|
+
primaryType,
|
3628
|
+
types: types_
|
3629
|
+
}) {
|
3630
|
+
const types = types_;
|
3631
|
+
const validateData = (struct, value_) => {
|
3632
|
+
for (const param of struct) {
|
3633
|
+
const { name, type: type_ } = param;
|
3634
|
+
const type = type_;
|
3635
|
+
const value = value_[name];
|
3636
|
+
const integerMatch = type.match(integerRegex);
|
3637
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
3638
|
+
const [_type, base, size_] = integerMatch;
|
3639
|
+
numberToHex(value, {
|
3640
|
+
signed: base === "int",
|
3641
|
+
size: parseInt(size_) / 8
|
3642
|
+
});
|
3643
|
+
}
|
3644
|
+
if (type === "address" && typeof value === "string" && !isAddress(value))
|
3645
|
+
throw new InvalidAddressError({ address: value });
|
3646
|
+
const bytesMatch = type.match(bytesRegex);
|
3647
|
+
if (bytesMatch) {
|
3648
|
+
const [_type, size_] = bytesMatch;
|
3649
|
+
if (size_ && size(value) !== parseInt(size_))
|
3650
|
+
throw new BytesSizeMismatchError({
|
3651
|
+
expectedSize: parseInt(size_),
|
3652
|
+
givenSize: size(value)
|
3653
|
+
});
|
3654
|
+
}
|
3655
|
+
const struct2 = types[type];
|
3656
|
+
if (struct2)
|
3657
|
+
validateData(struct2, value);
|
3658
|
+
}
|
3659
|
+
};
|
3660
|
+
if (types["EIP712Domain"] && domain)
|
3661
|
+
validateData(types["EIP712Domain"], domain);
|
3662
|
+
if (primaryType !== "EIP712Domain") {
|
3663
|
+
const type = types[primaryType];
|
3664
|
+
validateData(type, message);
|
3665
|
+
}
|
3666
|
+
}
|
3667
|
+
|
3668
|
+
// src/utils/signature/hashTypedData.ts
|
3669
|
+
function hashTypedData({
|
3670
|
+
domain: domain_,
|
3671
|
+
message,
|
3672
|
+
primaryType,
|
3673
|
+
types: types_
|
3674
|
+
}) {
|
3675
|
+
const domain = typeof domain_ === "undefined" ? {} : domain_;
|
3676
|
+
const types = {
|
3677
|
+
EIP712Domain: [
|
3678
|
+
domain?.name && { name: "name", type: "string" },
|
3679
|
+
domain?.version && { name: "version", type: "string" },
|
3680
|
+
domain?.chainId && { name: "chainId", type: "uint256" },
|
3681
|
+
domain?.verifyingContract && {
|
3682
|
+
name: "verifyingContract",
|
3683
|
+
type: "address"
|
3684
|
+
},
|
3685
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
3686
|
+
].filter(Boolean),
|
3687
|
+
...types_
|
3688
|
+
};
|
3689
|
+
validateTypedData({
|
3690
|
+
domain,
|
3691
|
+
message,
|
3692
|
+
primaryType,
|
3693
|
+
types
|
3694
|
+
});
|
3695
|
+
let parts = ["0x1901"];
|
3696
|
+
if (domain)
|
3697
|
+
parts.push(
|
3698
|
+
hashDomain({
|
3699
|
+
domain,
|
3700
|
+
types
|
3701
|
+
})
|
3702
|
+
);
|
3703
|
+
if (primaryType !== "EIP712Domain") {
|
3704
|
+
parts.push(
|
3705
|
+
hashStruct({
|
3706
|
+
data: message,
|
3707
|
+
primaryType,
|
3708
|
+
types
|
3709
|
+
})
|
3710
|
+
);
|
3711
|
+
}
|
3712
|
+
return keccak256(concat(parts));
|
3713
|
+
}
|
3714
|
+
function hashDomain({
|
3715
|
+
domain,
|
3716
|
+
types
|
3717
|
+
}) {
|
3718
|
+
return hashStruct({
|
3719
|
+
data: domain,
|
3720
|
+
primaryType: "EIP712Domain",
|
3721
|
+
types
|
3722
|
+
});
|
3723
|
+
}
|
3724
|
+
function hashStruct({
|
3725
|
+
data,
|
3726
|
+
primaryType,
|
3727
|
+
types
|
3728
|
+
}) {
|
3729
|
+
const encoded = encodeData({
|
3730
|
+
data,
|
3731
|
+
primaryType,
|
3732
|
+
types
|
3733
|
+
});
|
3734
|
+
return keccak256(encoded);
|
3735
|
+
}
|
3736
|
+
function encodeData({
|
3737
|
+
data,
|
3738
|
+
primaryType,
|
3739
|
+
types
|
3740
|
+
}) {
|
3741
|
+
let encodedTypes = [{ type: "bytes32" }];
|
3742
|
+
const encodedValues = [hashType({ primaryType, types })];
|
3743
|
+
for (const field of types[primaryType]) {
|
3744
|
+
const [type, value] = encodeField({
|
3745
|
+
types,
|
3746
|
+
name: field.name,
|
3747
|
+
type: field.type,
|
3748
|
+
value: data[field.name]
|
3749
|
+
});
|
3750
|
+
encodedTypes.push(type);
|
3751
|
+
encodedValues.push(value);
|
3752
|
+
}
|
3753
|
+
return encodeAbiParameters(encodedTypes, encodedValues);
|
3754
|
+
}
|
3755
|
+
function hashType({
|
3756
|
+
primaryType,
|
3757
|
+
types
|
3758
|
+
}) {
|
3759
|
+
const encodedHashType = toHex(encodeType({ primaryType, types }));
|
3760
|
+
return keccak256(encodedHashType);
|
3761
|
+
}
|
3762
|
+
function encodeType({
|
3763
|
+
primaryType,
|
3764
|
+
types
|
3765
|
+
}) {
|
3766
|
+
let result = "";
|
3767
|
+
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
3768
|
+
unsortedDeps.delete(primaryType);
|
3769
|
+
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
3770
|
+
for (const type of deps) {
|
3771
|
+
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
3772
|
+
}
|
3773
|
+
return result;
|
3774
|
+
}
|
3775
|
+
function findTypeDependencies({
|
3776
|
+
primaryType: primaryType_,
|
3777
|
+
types
|
3778
|
+
}, results = /* @__PURE__ */ new Set()) {
|
3779
|
+
const match = primaryType_.match(/^\w*/u);
|
3780
|
+
const primaryType = match?.[0];
|
3781
|
+
if (results.has(primaryType) || types[primaryType] === void 0) {
|
3782
|
+
return results;
|
3783
|
+
}
|
3784
|
+
results.add(primaryType);
|
3785
|
+
for (const field of types[primaryType]) {
|
3786
|
+
findTypeDependencies({ primaryType: field.type, types }, results);
|
3787
|
+
}
|
3788
|
+
return results;
|
3789
|
+
}
|
3790
|
+
function encodeField({
|
3791
|
+
types,
|
3792
|
+
name,
|
3793
|
+
type,
|
3794
|
+
value
|
3795
|
+
}) {
|
3796
|
+
if (types[type] !== void 0) {
|
3797
|
+
return [
|
3798
|
+
{ type: "bytes32" },
|
3799
|
+
keccak256(encodeData({ data: value, primaryType: type, types }))
|
3800
|
+
];
|
3801
|
+
}
|
3802
|
+
if (type === "bytes") {
|
3803
|
+
const prepend = value.length % 2 ? "0" : "";
|
3804
|
+
value = `0x${prepend + value.slice(2)}`;
|
3805
|
+
return [{ type: "bytes32" }, keccak256(value)];
|
3806
|
+
}
|
3807
|
+
if (type === "string")
|
3808
|
+
return [{ type: "bytes32" }, keccak256(toHex(value))];
|
3809
|
+
if (type.lastIndexOf("]") === type.length - 1) {
|
3810
|
+
const parsedType = type.slice(0, type.lastIndexOf("["));
|
3811
|
+
const typeValuePairs = value.map(
|
3812
|
+
(item) => encodeField({
|
3813
|
+
name,
|
3814
|
+
type: parsedType,
|
3815
|
+
types,
|
3816
|
+
value: item
|
3817
|
+
})
|
3818
|
+
);
|
3819
|
+
return [
|
3820
|
+
{ type: "bytes32" },
|
3821
|
+
keccak256(
|
3822
|
+
encodeAbiParameters(
|
3823
|
+
typeValuePairs.map(([t]) => t),
|
3824
|
+
typeValuePairs.map(([, v]) => v)
|
3825
|
+
)
|
3826
|
+
)
|
3827
|
+
];
|
3828
|
+
}
|
3829
|
+
return [{ type }, value];
|
3830
|
+
}
|
3831
|
+
|
3510
3832
|
// src/utils/signature/recoverAddress.ts
|
3511
|
-
|
3512
|
-
function recoverAddress({
|
3833
|
+
async function recoverAddress({
|
3513
3834
|
hash: hash2,
|
3514
3835
|
signature
|
3515
3836
|
}) {
|
3516
3837
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
3517
3838
|
const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
|
3518
3839
|
const v = hexToNumber(`0x${signatureHex.slice(130)}`);
|
3840
|
+
const { recoverPublicKey } = await import("@noble/secp256k1");
|
3519
3841
|
const publicKey = toHex(
|
3520
3842
|
recoverPublicKey(
|
3521
3843
|
hashHex.substring(2),
|
@@ -3528,28 +3850,75 @@ function recoverAddress({
|
|
3528
3850
|
}
|
3529
3851
|
|
3530
3852
|
// src/utils/signature/recoverMessageAddress.ts
|
3531
|
-
function recoverMessageAddress({
|
3853
|
+
async function recoverMessageAddress({
|
3532
3854
|
message,
|
3533
3855
|
signature
|
3534
3856
|
}) {
|
3535
3857
|
return recoverAddress({ hash: hashMessage(message), signature });
|
3536
3858
|
}
|
3537
3859
|
|
3860
|
+
// src/utils/signature/recoverTypedDataAddress.ts
|
3861
|
+
async function recoverTypedDataAddress({
|
3862
|
+
domain,
|
3863
|
+
message,
|
3864
|
+
primaryType,
|
3865
|
+
signature,
|
3866
|
+
types
|
3867
|
+
}) {
|
3868
|
+
return recoverAddress({
|
3869
|
+
hash: hashTypedData({
|
3870
|
+
domain,
|
3871
|
+
message,
|
3872
|
+
primaryType,
|
3873
|
+
types
|
3874
|
+
}),
|
3875
|
+
signature
|
3876
|
+
});
|
3877
|
+
}
|
3878
|
+
|
3538
3879
|
// src/utils/signature/verifyMessage.ts
|
3539
|
-
function verifyMessage({
|
3880
|
+
async function verifyMessage({
|
3540
3881
|
address,
|
3541
3882
|
message,
|
3542
3883
|
signature
|
3543
3884
|
}) {
|
3544
3885
|
return isAddressEqual(
|
3545
3886
|
getAddress(address),
|
3546
|
-
recoverMessageAddress({ message, signature })
|
3887
|
+
await recoverMessageAddress({ message, signature })
|
3888
|
+
);
|
3889
|
+
}
|
3890
|
+
|
3891
|
+
// src/utils/signature/verifyTypedData.ts
|
3892
|
+
async function verifyTypedData({
|
3893
|
+
address,
|
3894
|
+
domain,
|
3895
|
+
message,
|
3896
|
+
primaryType,
|
3897
|
+
signature,
|
3898
|
+
types
|
3899
|
+
}) {
|
3900
|
+
return isAddressEqual(
|
3901
|
+
getAddress(address),
|
3902
|
+
await recoverTypedDataAddress({
|
3903
|
+
domain,
|
3904
|
+
message,
|
3905
|
+
primaryType,
|
3906
|
+
signature,
|
3907
|
+
types
|
3908
|
+
})
|
3547
3909
|
);
|
3548
3910
|
}
|
3549
3911
|
|
3550
3912
|
// src/utils/transaction/assertRequest.ts
|
3551
3913
|
function assertRequest(args) {
|
3552
|
-
const {
|
3914
|
+
const {
|
3915
|
+
account: account_,
|
3916
|
+
gasPrice,
|
3917
|
+
maxFeePerGas,
|
3918
|
+
maxPriorityFeePerGas,
|
3919
|
+
to
|
3920
|
+
} = args;
|
3921
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
3553
3922
|
if (account && !isAddress(account.address))
|
3554
3923
|
throw new InvalidAddressError({ address: account.address });
|
3555
3924
|
if (to && !isAddress(to))
|
@@ -3562,10 +3931,36 @@ function assertRequest(args) {
|
|
3562
3931
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
3563
3932
|
}
|
3564
3933
|
|
3934
|
+
// src/utils/transaction/getSerializedTransactionType.ts
|
3935
|
+
function getSerializedTransactionType(serializedTransaction) {
|
3936
|
+
const serializedType = sliceHex(serializedTransaction, 0, 1);
|
3937
|
+
if (serializedType === "0x02")
|
3938
|
+
return "eip1559";
|
3939
|
+
if (serializedType === "0x01")
|
3940
|
+
return "eip2930";
|
3941
|
+
if (serializedType !== "0x" && hexToNumber(serializedType) >= 192)
|
3942
|
+
return "legacy";
|
3943
|
+
throw new InvalidSerializedTransactionTypeError({ serializedType });
|
3944
|
+
}
|
3945
|
+
|
3946
|
+
// src/utils/transaction/getTransactionType.ts
|
3947
|
+
function getTransactionType(transaction) {
|
3948
|
+
if (transaction.type)
|
3949
|
+
return transaction.type;
|
3950
|
+
if ("maxFeePerGas" in transaction || "maxPriorityFeePerGas" in transaction)
|
3951
|
+
return "eip1559";
|
3952
|
+
if ("gasPrice" in transaction) {
|
3953
|
+
if ("accessList" in transaction)
|
3954
|
+
return "eip2930";
|
3955
|
+
return "legacy";
|
3956
|
+
}
|
3957
|
+
throw new InvalidSerializableTransactionError({ transaction });
|
3958
|
+
}
|
3959
|
+
|
3565
3960
|
// src/actions/public/call.ts
|
3566
3961
|
async function call(client, args) {
|
3567
3962
|
const {
|
3568
|
-
account,
|
3963
|
+
account: account_,
|
3569
3964
|
blockNumber,
|
3570
3965
|
blockTag = "latest",
|
3571
3966
|
accessList,
|
@@ -3579,6 +3974,7 @@ async function call(client, args) {
|
|
3579
3974
|
value,
|
3580
3975
|
...rest
|
3581
3976
|
} = args;
|
3977
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
3582
3978
|
try {
|
3583
3979
|
assertRequest(args);
|
3584
3980
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
@@ -3612,6 +4008,7 @@ async function call(client, args) {
|
|
3612
4008
|
} catch (err) {
|
3613
4009
|
throw getCallError(err, {
|
3614
4010
|
...args,
|
4011
|
+
account,
|
3615
4012
|
chain: client.chain
|
3616
4013
|
});
|
3617
4014
|
}
|
@@ -3625,6 +4022,7 @@ async function simulateContract(client, {
|
|
3625
4022
|
functionName,
|
3626
4023
|
...callRequest
|
3627
4024
|
}) {
|
4025
|
+
const account = callRequest.account ? parseAccount(callRequest.account) : void 0;
|
3628
4026
|
const calldata = encodeFunctionData({
|
3629
4027
|
abi,
|
3630
4028
|
args,
|
@@ -3659,7 +4057,7 @@ async function simulateContract(client, {
|
|
3659
4057
|
args,
|
3660
4058
|
docsPath: "/docs/contract/simulateContract",
|
3661
4059
|
functionName,
|
3662
|
-
sender:
|
4060
|
+
sender: account?.address
|
3663
4061
|
});
|
3664
4062
|
}
|
3665
4063
|
}
|
@@ -3751,9 +4149,13 @@ async function createContractEventFilter(client, {
|
|
3751
4149
|
|
3752
4150
|
// src/actions/public/estimateGas.ts
|
3753
4151
|
async function estimateGas(client, args) {
|
4152
|
+
if (!args.account)
|
4153
|
+
throw new AccountNotFoundError({
|
4154
|
+
docsPath: "/docs/actions/public/estimateGas"
|
4155
|
+
});
|
4156
|
+
const account = parseAccount(args.account);
|
3754
4157
|
try {
|
3755
4158
|
const {
|
3756
|
-
account,
|
3757
4159
|
accessList,
|
3758
4160
|
blockNumber,
|
3759
4161
|
blockTag = "latest",
|
@@ -3766,7 +4168,7 @@ async function estimateGas(client, args) {
|
|
3766
4168
|
to,
|
3767
4169
|
value,
|
3768
4170
|
...rest
|
3769
|
-
} =
|
4171
|
+
} = account.type === "local" ? await prepareRequest(client, args) : args;
|
3770
4172
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
3771
4173
|
assertRequest(args);
|
3772
4174
|
const formatter = client.chain?.formatters?.transactionRequest;
|
@@ -3797,6 +4199,7 @@ async function estimateGas(client, args) {
|
|
3797
4199
|
} catch (err) {
|
3798
4200
|
throw getEstimateGasError(err, {
|
3799
4201
|
...args,
|
4202
|
+
account,
|
3800
4203
|
chain: client.chain
|
3801
4204
|
});
|
3802
4205
|
}
|
@@ -3810,6 +4213,7 @@ async function estimateContractGas(client, {
|
|
3810
4213
|
functionName,
|
3811
4214
|
...request
|
3812
4215
|
}) {
|
4216
|
+
const account = parseAccount(request.account);
|
3813
4217
|
const data = encodeFunctionData({
|
3814
4218
|
abi,
|
3815
4219
|
args,
|
@@ -3829,7 +4233,7 @@ async function estimateContractGas(client, {
|
|
3829
4233
|
args,
|
3830
4234
|
docsPath: "/docs/contract/simulateContract",
|
3831
4235
|
functionName,
|
3832
|
-
sender:
|
4236
|
+
sender: account?.address
|
3833
4237
|
});
|
3834
4238
|
}
|
3835
4239
|
}
|
@@ -4320,6 +4724,7 @@ async function waitForTransactionReceipt(client, {
|
|
4320
4724
|
const unwatch = watchBlockNumber(client, {
|
4321
4725
|
emitMissed: true,
|
4322
4726
|
emitOnBegin: true,
|
4727
|
+
poll: true,
|
4323
4728
|
pollingInterval,
|
4324
4729
|
async onBlockNumber(blockNumber) {
|
4325
4730
|
const done = async (fn) => {
|
@@ -4412,47 +4817,79 @@ function watchBlockNumber(client, {
|
|
4412
4817
|
emitMissed = false,
|
4413
4818
|
onBlockNumber,
|
4414
4819
|
onError,
|
4820
|
+
poll: poll_,
|
4415
4821
|
pollingInterval = client.pollingInterval
|
4416
4822
|
}) {
|
4417
|
-
const
|
4418
|
-
"watchBlockNumber",
|
4419
|
-
client.uid,
|
4420
|
-
emitOnBegin,
|
4421
|
-
emitMissed,
|
4422
|
-
pollingInterval
|
4423
|
-
]);
|
4823
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
4424
4824
|
let prevBlockNumber;
|
4425
|
-
|
4426
|
-
observerId
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4825
|
+
const pollBlockNumber = () => {
|
4826
|
+
const observerId = JSON.stringify([
|
4827
|
+
"watchBlockNumber",
|
4828
|
+
client.uid,
|
4829
|
+
emitOnBegin,
|
4830
|
+
emitMissed,
|
4831
|
+
pollingInterval
|
4832
|
+
]);
|
4833
|
+
return observe(
|
4834
|
+
observerId,
|
4835
|
+
{ onBlockNumber, onError },
|
4836
|
+
(emit) => poll(
|
4837
|
+
async () => {
|
4838
|
+
try {
|
4839
|
+
const blockNumber = await getBlockNumber(client, { maxAge: 0 });
|
4840
|
+
if (prevBlockNumber) {
|
4841
|
+
if (blockNumber === prevBlockNumber)
|
4842
|
+
return;
|
4843
|
+
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
4844
|
+
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
|
4845
|
+
emit.onBlockNumber(i, prevBlockNumber);
|
4846
|
+
prevBlockNumber = i;
|
4847
|
+
}
|
4439
4848
|
}
|
4440
4849
|
}
|
4850
|
+
if (!prevBlockNumber || blockNumber > prevBlockNumber) {
|
4851
|
+
emit.onBlockNumber(blockNumber, prevBlockNumber);
|
4852
|
+
prevBlockNumber = blockNumber;
|
4853
|
+
}
|
4854
|
+
} catch (err) {
|
4855
|
+
emit.onError?.(err);
|
4441
4856
|
}
|
4442
|
-
|
4443
|
-
|
4857
|
+
},
|
4858
|
+
{
|
4859
|
+
emitOnBegin,
|
4860
|
+
interval: pollingInterval
|
4861
|
+
}
|
4862
|
+
)
|
4863
|
+
);
|
4864
|
+
};
|
4865
|
+
const subscribeBlockNumber = () => {
|
4866
|
+
let active = true;
|
4867
|
+
let unsubscribe = () => active = false;
|
4868
|
+
(async () => {
|
4869
|
+
try {
|
4870
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
4871
|
+
params: ["newHeads"],
|
4872
|
+
onData(data) {
|
4873
|
+
if (!active)
|
4874
|
+
return;
|
4875
|
+
const blockNumber = hexToBigInt(data.result?.number);
|
4876
|
+
onBlockNumber(blockNumber, prevBlockNumber);
|
4444
4877
|
prevBlockNumber = blockNumber;
|
4878
|
+
},
|
4879
|
+
onError(error) {
|
4880
|
+
onError?.(error);
|
4445
4881
|
}
|
4446
|
-
}
|
4447
|
-
|
4448
|
-
|
4449
|
-
|
4450
|
-
{
|
4451
|
-
|
4452
|
-
interval: pollingInterval
|
4882
|
+
});
|
4883
|
+
unsubscribe = unsubscribe_;
|
4884
|
+
if (!active)
|
4885
|
+
unsubscribe();
|
4886
|
+
} catch (err) {
|
4887
|
+
onError?.(err);
|
4453
4888
|
}
|
4454
|
-
)
|
4455
|
-
|
4889
|
+
})();
|
4890
|
+
return unsubscribe;
|
4891
|
+
};
|
4892
|
+
return enablePolling ? pollBlockNumber() : subscribeBlockNumber();
|
4456
4893
|
}
|
4457
4894
|
|
4458
4895
|
// src/actions/public/watchBlocks.ts
|
@@ -4463,61 +4900,93 @@ function watchBlocks(client, {
|
|
4463
4900
|
onBlock,
|
4464
4901
|
onError,
|
4465
4902
|
includeTransactions = false,
|
4903
|
+
poll: poll_,
|
4466
4904
|
pollingInterval = client.pollingInterval
|
4467
4905
|
}) {
|
4468
|
-
const
|
4469
|
-
"watchBlocks",
|
4470
|
-
client.uid,
|
4471
|
-
emitMissed,
|
4472
|
-
emitOnBegin,
|
4473
|
-
includeTransactions,
|
4474
|
-
pollingInterval
|
4475
|
-
]);
|
4906
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
4476
4907
|
let prevBlock;
|
4477
|
-
|
4478
|
-
observerId
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4492
|
-
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4908
|
+
const pollBlocks = () => {
|
4909
|
+
const observerId = JSON.stringify([
|
4910
|
+
"watchBlocks",
|
4911
|
+
client.uid,
|
4912
|
+
emitMissed,
|
4913
|
+
emitOnBegin,
|
4914
|
+
includeTransactions,
|
4915
|
+
pollingInterval
|
4916
|
+
]);
|
4917
|
+
return observe(
|
4918
|
+
observerId,
|
4919
|
+
{ onBlock, onError },
|
4920
|
+
(emit) => poll(
|
4921
|
+
async () => {
|
4922
|
+
try {
|
4923
|
+
const block = await getBlock(client, {
|
4924
|
+
blockTag,
|
4925
|
+
includeTransactions
|
4926
|
+
});
|
4927
|
+
if (block.number && prevBlock?.number) {
|
4928
|
+
if (block.number === prevBlock.number)
|
4929
|
+
return;
|
4930
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
4931
|
+
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
4932
|
+
const block2 = await getBlock(client, {
|
4933
|
+
blockNumber: i,
|
4934
|
+
includeTransactions
|
4935
|
+
});
|
4936
|
+
emit.onBlock(block2, prevBlock);
|
4937
|
+
prevBlock = block2;
|
4938
|
+
}
|
4498
4939
|
}
|
4499
4940
|
}
|
4941
|
+
if (
|
4942
|
+
// If no previous block exists, emit.
|
4943
|
+
!prevBlock?.number || // If the block tag is "pending" with no block number, emit.
|
4944
|
+
blockTag === "pending" && !block?.number || // If the next block number is greater than the previous block number, emit.
|
4945
|
+
// We don't want to emit blocks in the past.
|
4946
|
+
block.number && block.number > prevBlock.number
|
4947
|
+
) {
|
4948
|
+
emit.onBlock(block, prevBlock);
|
4949
|
+
prevBlock = block;
|
4950
|
+
}
|
4951
|
+
} catch (err) {
|
4952
|
+
emit.onError?.(err);
|
4500
4953
|
}
|
4501
|
-
|
4502
|
-
|
4503
|
-
|
4504
|
-
|
4505
|
-
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
4954
|
+
},
|
4955
|
+
{
|
4956
|
+
emitOnBegin,
|
4957
|
+
interval: pollingInterval
|
4958
|
+
}
|
4959
|
+
)
|
4960
|
+
);
|
4961
|
+
};
|
4962
|
+
const subscribeBlocks = () => {
|
4963
|
+
let active = true;
|
4964
|
+
let unsubscribe = () => active = false;
|
4965
|
+
(async () => {
|
4966
|
+
try {
|
4967
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
4968
|
+
params: ["newHeads"],
|
4969
|
+
onData(data) {
|
4970
|
+
if (!active)
|
4971
|
+
return;
|
4972
|
+
const block = data.result;
|
4973
|
+
onBlock(block, prevBlock);
|
4509
4974
|
prevBlock = block;
|
4975
|
+
},
|
4976
|
+
onError(error) {
|
4977
|
+
onError?.(error);
|
4510
4978
|
}
|
4511
|
-
}
|
4512
|
-
|
4513
|
-
|
4514
|
-
|
4515
|
-
{
|
4516
|
-
|
4517
|
-
interval: pollingInterval
|
4979
|
+
});
|
4980
|
+
unsubscribe = unsubscribe_;
|
4981
|
+
if (!active)
|
4982
|
+
unsubscribe();
|
4983
|
+
} catch (err) {
|
4984
|
+
onError?.(err);
|
4518
4985
|
}
|
4519
|
-
)
|
4520
|
-
|
4986
|
+
})();
|
4987
|
+
return unsubscribe;
|
4988
|
+
};
|
4989
|
+
return enablePolling ? pollBlocks() : subscribeBlocks();
|
4521
4990
|
}
|
4522
4991
|
|
4523
4992
|
// src/actions/public/watchContractEvent.ts
|
@@ -4688,50 +5157,81 @@ function watchPendingTransactions(client, {
|
|
4688
5157
|
batch = true,
|
4689
5158
|
onError,
|
4690
5159
|
onTransactions,
|
5160
|
+
poll: poll_,
|
4691
5161
|
pollingInterval = client.pollingInterval
|
4692
5162
|
}) {
|
4693
|
-
const
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4707
|
-
|
4708
|
-
|
4709
|
-
|
4710
|
-
|
5163
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
5164
|
+
const pollPendingTransactions = () => {
|
5165
|
+
const observerId = JSON.stringify([
|
5166
|
+
"watchPendingTransactions",
|
5167
|
+
client.uid,
|
5168
|
+
batch,
|
5169
|
+
pollingInterval
|
5170
|
+
]);
|
5171
|
+
return observe(observerId, { onTransactions, onError }, (emit) => {
|
5172
|
+
let filter;
|
5173
|
+
const unwatch = poll(
|
5174
|
+
async () => {
|
5175
|
+
try {
|
5176
|
+
if (!filter) {
|
5177
|
+
try {
|
5178
|
+
filter = await createPendingTransactionFilter(client);
|
5179
|
+
return;
|
5180
|
+
} catch (err) {
|
5181
|
+
unwatch();
|
5182
|
+
throw err;
|
5183
|
+
}
|
4711
5184
|
}
|
5185
|
+
const hashes = await getFilterChanges(client, { filter });
|
5186
|
+
if (hashes.length === 0)
|
5187
|
+
return;
|
5188
|
+
if (batch)
|
5189
|
+
emit.onTransactions(hashes);
|
5190
|
+
else
|
5191
|
+
hashes.forEach((hash2) => emit.onTransactions([hash2]));
|
5192
|
+
} catch (err) {
|
5193
|
+
emit.onError?.(err);
|
4712
5194
|
}
|
4713
|
-
|
4714
|
-
|
4715
|
-
|
4716
|
-
|
4717
|
-
emit.onTransactions(hashes);
|
4718
|
-
else
|
4719
|
-
hashes.forEach((hash2) => emit.onTransactions([hash2]));
|
4720
|
-
} catch (err) {
|
4721
|
-
emit.onError?.(err);
|
5195
|
+
},
|
5196
|
+
{
|
5197
|
+
emitOnBegin: true,
|
5198
|
+
interval: pollingInterval
|
4722
5199
|
}
|
4723
|
-
|
4724
|
-
{
|
4725
|
-
|
4726
|
-
|
5200
|
+
);
|
5201
|
+
return async () => {
|
5202
|
+
if (filter)
|
5203
|
+
await uninstallFilter(client, { filter });
|
5204
|
+
unwatch();
|
5205
|
+
};
|
5206
|
+
});
|
5207
|
+
};
|
5208
|
+
const subscribePendingTransactions = () => {
|
5209
|
+
let active = true;
|
5210
|
+
let unsubscribe = () => active = false;
|
5211
|
+
(async () => {
|
5212
|
+
try {
|
5213
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
5214
|
+
params: ["newPendingTransactions"],
|
5215
|
+
onData(data) {
|
5216
|
+
if (!active)
|
5217
|
+
return;
|
5218
|
+
const transaction = data.result;
|
5219
|
+
onTransactions([transaction]);
|
5220
|
+
},
|
5221
|
+
onError(error) {
|
5222
|
+
onError?.(error);
|
5223
|
+
}
|
5224
|
+
});
|
5225
|
+
unsubscribe = unsubscribe_;
|
5226
|
+
if (!active)
|
5227
|
+
unsubscribe();
|
5228
|
+
} catch (err) {
|
5229
|
+
onError?.(err);
|
4727
5230
|
}
|
4728
|
-
);
|
4729
|
-
return
|
4730
|
-
|
4731
|
-
|
4732
|
-
unwatch();
|
4733
|
-
};
|
4734
|
-
});
|
5231
|
+
})();
|
5232
|
+
return unsubscribe;
|
5233
|
+
};
|
5234
|
+
return enablePolling ? pollPendingTransactions() : subscribePendingTransactions();
|
4735
5235
|
}
|
4736
5236
|
|
4737
5237
|
// src/actions/test/dropTransaction.ts
|
@@ -4980,7 +5480,12 @@ async function addChain(client, { chain }) {
|
|
4980
5480
|
}
|
4981
5481
|
|
4982
5482
|
// src/actions/wallet/deployContract.ts
|
4983
|
-
function deployContract(walletClient, {
|
5483
|
+
function deployContract(walletClient, {
|
5484
|
+
abi,
|
5485
|
+
args,
|
5486
|
+
bytecode,
|
5487
|
+
...request
|
5488
|
+
}) {
|
4984
5489
|
const calldata = encodeDeployData({
|
4985
5490
|
abi,
|
4986
5491
|
args,
|
@@ -5021,10 +5526,9 @@ async function requestPermissions(client, permissions) {
|
|
5021
5526
|
// src/actions/wallet/sendTransaction.ts
|
5022
5527
|
async function sendTransaction(client, args) {
|
5023
5528
|
const {
|
5024
|
-
account,
|
5529
|
+
account: account_ = client.account,
|
5025
5530
|
chain = client.chain,
|
5026
5531
|
accessList,
|
5027
|
-
assertChain = true,
|
5028
5532
|
data,
|
5029
5533
|
gas,
|
5030
5534
|
gasPrice,
|
@@ -5035,13 +5539,20 @@ async function sendTransaction(client, args) {
|
|
5035
5539
|
value,
|
5036
5540
|
...rest
|
5037
5541
|
} = args;
|
5542
|
+
if (!account_)
|
5543
|
+
throw new AccountNotFoundError({
|
5544
|
+
docsPath: "/docs/actions/wallet/sendTransaction"
|
5545
|
+
});
|
5546
|
+
const account = parseAccount(account_);
|
5038
5547
|
try {
|
5039
5548
|
assertRequest(args);
|
5040
|
-
const
|
5041
|
-
if (
|
5042
|
-
|
5549
|
+
const chainId = await getChainId(client);
|
5550
|
+
if (chain !== null && chainId !== chain?.id) {
|
5551
|
+
if (!chain)
|
5552
|
+
throw new ChainNotFoundError();
|
5553
|
+
throw new ChainMismatchError({ chain, currentChainId: chainId });
|
5554
|
+
}
|
5043
5555
|
if (account.type === "local") {
|
5044
|
-
const chainId = chain?.id ?? currentChainId;
|
5045
5556
|
const request2 = await prepareRequest(client, {
|
5046
5557
|
account,
|
5047
5558
|
accessList,
|
@@ -5090,15 +5601,28 @@ async function sendTransaction(client, args) {
|
|
5090
5601
|
params: [request]
|
5091
5602
|
});
|
5092
5603
|
} catch (err) {
|
5093
|
-
throw getTransactionError(err,
|
5604
|
+
throw getTransactionError(err, {
|
5605
|
+
...args,
|
5606
|
+
account,
|
5607
|
+
chain: args.chain || void 0
|
5608
|
+
});
|
5094
5609
|
}
|
5095
5610
|
}
|
5096
5611
|
|
5097
5612
|
// src/actions/wallet/signMessage.ts
|
5098
|
-
async function signMessage(client, {
|
5613
|
+
async function signMessage(client, {
|
5614
|
+
account: account_ = client.account,
|
5615
|
+
data,
|
5616
|
+
message
|
5617
|
+
}) {
|
5618
|
+
if (!account_)
|
5619
|
+
throw new AccountNotFoundError({
|
5620
|
+
docsPath: "/docs/actions/wallet/signMessage"
|
5621
|
+
});
|
5622
|
+
const account = parseAccount(account_);
|
5099
5623
|
const message_ = message || data;
|
5100
5624
|
if (account.type === "local")
|
5101
|
-
return account.signMessage(message_);
|
5625
|
+
return account.signMessage({ message: message_ });
|
5102
5626
|
return client.request({
|
5103
5627
|
method: "personal_sign",
|
5104
5628
|
params: [toHex(message_), account.address]
|
@@ -5107,12 +5631,17 @@ async function signMessage(client, { account, data, message }) {
|
|
5107
5631
|
|
5108
5632
|
// src/actions/wallet/signTypedData.ts
|
5109
5633
|
async function signTypedData(client, {
|
5110
|
-
account,
|
5634
|
+
account: account_ = client.account,
|
5111
5635
|
domain,
|
5112
5636
|
message,
|
5113
5637
|
primaryType,
|
5114
5638
|
types: types_
|
5115
5639
|
}) {
|
5640
|
+
if (!account_)
|
5641
|
+
throw new AccountNotFoundError({
|
5642
|
+
docsPath: "/docs/actions/wallet/signTypedData"
|
5643
|
+
});
|
5644
|
+
const account = parseAccount(account_);
|
5116
5645
|
const types = {
|
5117
5646
|
EIP712Domain: [
|
5118
5647
|
domain?.name && { name: "name", type: "string" },
|
@@ -5148,47 +5677,6 @@ async function signTypedData(client, {
|
|
5148
5677
|
params: [account.address, typedData]
|
5149
5678
|
});
|
5150
5679
|
}
|
5151
|
-
function validateTypedData({
|
5152
|
-
domain,
|
5153
|
-
message,
|
5154
|
-
primaryType,
|
5155
|
-
types: types_
|
5156
|
-
}) {
|
5157
|
-
const types = types_;
|
5158
|
-
const validateData = (struct, value_) => {
|
5159
|
-
for (const param of struct) {
|
5160
|
-
const { name, type: type_ } = param;
|
5161
|
-
const type2 = type_;
|
5162
|
-
const value = value_[name];
|
5163
|
-
const integerMatch = type2.match(integerRegex);
|
5164
|
-
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
5165
|
-
const [_type, base, size_] = integerMatch;
|
5166
|
-
numberToHex(value, {
|
5167
|
-
signed: base === "int",
|
5168
|
-
size: parseInt(size_) / 8
|
5169
|
-
});
|
5170
|
-
}
|
5171
|
-
if (type2 === "address" && typeof value === "string" && !isAddress(value))
|
5172
|
-
throw new InvalidAddressError({ address: value });
|
5173
|
-
const bytesMatch = type2.match(bytesRegex);
|
5174
|
-
if (bytesMatch) {
|
5175
|
-
const [_type, size_] = bytesMatch;
|
5176
|
-
if (size_ && size(value) !== parseInt(size_))
|
5177
|
-
throw new BytesSizeMismatchError({
|
5178
|
-
expectedSize: parseInt(size_),
|
5179
|
-
givenSize: size(value)
|
5180
|
-
});
|
5181
|
-
}
|
5182
|
-
const struct2 = types[type2];
|
5183
|
-
if (struct2)
|
5184
|
-
validateData(struct2, value);
|
5185
|
-
}
|
5186
|
-
};
|
5187
|
-
if (types["EIP712Domain"] && domain)
|
5188
|
-
validateData(types["EIP712Domain"], domain);
|
5189
|
-
const type = types[primaryType];
|
5190
|
-
validateData(type, message);
|
5191
|
-
}
|
5192
5680
|
|
5193
5681
|
// src/actions/wallet/switchChain.ts
|
5194
5682
|
async function switchChain(client, { id: id2 }) {
|
@@ -5262,7 +5750,17 @@ function parseGwei(ether, unit = "wei") {
|
|
5262
5750
|
// src/utils/transaction/prepareRequest.ts
|
5263
5751
|
var defaultTip = parseGwei("1.5");
|
5264
5752
|
async function prepareRequest(client, args) {
|
5265
|
-
const {
|
5753
|
+
const {
|
5754
|
+
account: account_,
|
5755
|
+
gas,
|
5756
|
+
gasPrice,
|
5757
|
+
maxFeePerGas,
|
5758
|
+
maxPriorityFeePerGas,
|
5759
|
+
nonce
|
5760
|
+
} = args;
|
5761
|
+
if (!account_)
|
5762
|
+
throw new AccountNotFoundError();
|
5763
|
+
const account = parseAccount(account_);
|
5266
5764
|
const block = await getBlock(client, { blockTag: "latest" });
|
5267
5765
|
const request = { ...args, from: account.address };
|
5268
5766
|
if (typeof nonce === "undefined")
|
@@ -5299,6 +5797,400 @@ async function prepareRequest(client, args) {
|
|
5299
5797
|
return request;
|
5300
5798
|
}
|
5301
5799
|
|
5800
|
+
// src/utils/transaction/assertTransaction.ts
|
5801
|
+
function assertTransactionEIP1559(transaction) {
|
5802
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5803
|
+
if (chainId <= 0)
|
5804
|
+
throw new InvalidChainIdError({ chainId });
|
5805
|
+
if (to && !isAddress(to))
|
5806
|
+
throw new InvalidAddressError({ address: to });
|
5807
|
+
if (gasPrice)
|
5808
|
+
throw new BaseError(
|
5809
|
+
"`gasPrice` is not a valid EIP-1559 Transaction attribute."
|
5810
|
+
);
|
5811
|
+
if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n)
|
5812
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
5813
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
5814
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
5815
|
+
}
|
5816
|
+
function assertTransactionEIP2930(transaction) {
|
5817
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5818
|
+
if (chainId <= 0)
|
5819
|
+
throw new InvalidChainIdError({ chainId });
|
5820
|
+
if (to && !isAddress(to))
|
5821
|
+
throw new InvalidAddressError({ address: to });
|
5822
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5823
|
+
throw new BaseError(
|
5824
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute."
|
5825
|
+
);
|
5826
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5827
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5828
|
+
}
|
5829
|
+
function assertTransactionLegacy(transaction) {
|
5830
|
+
const {
|
5831
|
+
chainId,
|
5832
|
+
maxPriorityFeePerGas,
|
5833
|
+
gasPrice,
|
5834
|
+
maxFeePerGas,
|
5835
|
+
to,
|
5836
|
+
accessList
|
5837
|
+
} = transaction;
|
5838
|
+
if (to && !isAddress(to))
|
5839
|
+
throw new InvalidAddressError({ address: to });
|
5840
|
+
if (typeof chainId !== "undefined" && chainId <= 0)
|
5841
|
+
throw new InvalidChainIdError({ chainId });
|
5842
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5843
|
+
throw new BaseError(
|
5844
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute."
|
5845
|
+
);
|
5846
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5847
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5848
|
+
if (accessList)
|
5849
|
+
throw new BaseError(
|
5850
|
+
"`accessList` is not a valid Legacy Transaction attribute."
|
5851
|
+
);
|
5852
|
+
}
|
5853
|
+
|
5854
|
+
// src/utils/transaction/parseTransaction.ts
|
5855
|
+
function parseTransaction(serializedTransaction) {
|
5856
|
+
const type = getSerializedTransactionType(serializedTransaction);
|
5857
|
+
if (type === "eip1559")
|
5858
|
+
return parseTransactionEIP1559(
|
5859
|
+
serializedTransaction
|
5860
|
+
);
|
5861
|
+
if (type === "eip2930")
|
5862
|
+
return parseTransactionEIP2930(
|
5863
|
+
serializedTransaction
|
5864
|
+
);
|
5865
|
+
return parseTransactionLegacy(
|
5866
|
+
serializedTransaction
|
5867
|
+
);
|
5868
|
+
}
|
5869
|
+
function parseTransactionEIP1559(serializedTransaction) {
|
5870
|
+
const transactionArray = fromRlp(
|
5871
|
+
`0x${serializedTransaction.slice(4)}`,
|
5872
|
+
"hex"
|
5873
|
+
);
|
5874
|
+
const [
|
5875
|
+
chainId,
|
5876
|
+
nonce,
|
5877
|
+
maxPriorityFeePerGas,
|
5878
|
+
maxFeePerGas,
|
5879
|
+
gas,
|
5880
|
+
to,
|
5881
|
+
value,
|
5882
|
+
data,
|
5883
|
+
accessList,
|
5884
|
+
v,
|
5885
|
+
r,
|
5886
|
+
s
|
5887
|
+
] = transactionArray;
|
5888
|
+
if (!(transactionArray.length === 9 || transactionArray.length === 12))
|
5889
|
+
throw new InvalidSerializedTransactionError({
|
5890
|
+
attributes: {
|
5891
|
+
chainId,
|
5892
|
+
nonce,
|
5893
|
+
maxPriorityFeePerGas,
|
5894
|
+
maxFeePerGas,
|
5895
|
+
gas,
|
5896
|
+
to,
|
5897
|
+
value,
|
5898
|
+
data,
|
5899
|
+
accessList,
|
5900
|
+
...transactionArray.length > 9 ? {
|
5901
|
+
v,
|
5902
|
+
r,
|
5903
|
+
s
|
5904
|
+
} : {}
|
5905
|
+
},
|
5906
|
+
serializedTransaction,
|
5907
|
+
type: "eip1559"
|
5908
|
+
});
|
5909
|
+
let transaction = {
|
5910
|
+
chainId: hexToNumber(chainId),
|
5911
|
+
type: "eip1559"
|
5912
|
+
};
|
5913
|
+
if (isHex(to) && to !== "0x")
|
5914
|
+
transaction.to = to;
|
5915
|
+
if (isHex(gas) && gas !== "0x")
|
5916
|
+
transaction.gas = hexToBigInt(gas);
|
5917
|
+
if (isHex(data) && data !== "0x")
|
5918
|
+
transaction.data = data;
|
5919
|
+
if (isHex(nonce) && nonce !== "0x")
|
5920
|
+
transaction.nonce = hexToNumber(nonce);
|
5921
|
+
if (isHex(value) && value !== "0x")
|
5922
|
+
transaction.value = hexToBigInt(value);
|
5923
|
+
if (isHex(maxFeePerGas) && maxFeePerGas !== "0x")
|
5924
|
+
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas);
|
5925
|
+
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== "0x")
|
5926
|
+
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas);
|
5927
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5928
|
+
transaction.accessList = parseAccessList(accessList);
|
5929
|
+
assertTransactionEIP1559(transaction);
|
5930
|
+
const signature = transactionArray.length === 12 ? parseEIP155Signature(transactionArray) : void 0;
|
5931
|
+
return { ...signature, ...transaction };
|
5932
|
+
}
|
5933
|
+
function parseTransactionEIP2930(serializedTransaction) {
|
5934
|
+
const transactionArray = fromRlp(
|
5935
|
+
`0x${serializedTransaction.slice(4)}`,
|
5936
|
+
"hex"
|
5937
|
+
);
|
5938
|
+
const [chainId, nonce, gasPrice, gas, to, value, data, accessList, v, r, s] = transactionArray;
|
5939
|
+
if (!(transactionArray.length === 8 || transactionArray.length === 11))
|
5940
|
+
throw new InvalidSerializedTransactionError({
|
5941
|
+
attributes: {
|
5942
|
+
chainId,
|
5943
|
+
nonce,
|
5944
|
+
gasPrice,
|
5945
|
+
gas,
|
5946
|
+
to,
|
5947
|
+
value,
|
5948
|
+
data,
|
5949
|
+
accessList,
|
5950
|
+
...transactionArray.length > 8 ? {
|
5951
|
+
v,
|
5952
|
+
r,
|
5953
|
+
s
|
5954
|
+
} : {}
|
5955
|
+
},
|
5956
|
+
serializedTransaction,
|
5957
|
+
type: "eip2930"
|
5958
|
+
});
|
5959
|
+
let transaction = {
|
5960
|
+
chainId: hexToNumber(chainId),
|
5961
|
+
type: "eip2930"
|
5962
|
+
};
|
5963
|
+
if (isHex(to) && to !== "0x")
|
5964
|
+
transaction.to = to;
|
5965
|
+
if (isHex(gas) && gas !== "0x")
|
5966
|
+
transaction.gas = hexToBigInt(gas);
|
5967
|
+
if (isHex(data) && data !== "0x")
|
5968
|
+
transaction.data = data;
|
5969
|
+
if (isHex(nonce) && nonce !== "0x")
|
5970
|
+
transaction.nonce = hexToNumber(nonce);
|
5971
|
+
if (isHex(value) && value !== "0x")
|
5972
|
+
transaction.value = hexToBigInt(value);
|
5973
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
5974
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
5975
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5976
|
+
transaction.accessList = parseAccessList(accessList);
|
5977
|
+
assertTransactionEIP2930(transaction);
|
5978
|
+
const signature = transactionArray.length === 11 ? parseEIP155Signature(transactionArray) : void 0;
|
5979
|
+
return { ...signature, ...transaction };
|
5980
|
+
}
|
5981
|
+
function parseTransactionLegacy(serializedTransaction) {
|
5982
|
+
const transactionArray = fromRlp(serializedTransaction, "hex");
|
5983
|
+
const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] = transactionArray;
|
5984
|
+
if (!(transactionArray.length === 6 || transactionArray.length === 9))
|
5985
|
+
throw new InvalidSerializedTransactionError({
|
5986
|
+
attributes: {
|
5987
|
+
nonce,
|
5988
|
+
gasPrice,
|
5989
|
+
gas,
|
5990
|
+
to,
|
5991
|
+
value,
|
5992
|
+
data,
|
5993
|
+
...transactionArray.length > 6 ? {
|
5994
|
+
v: chainIdOrV_,
|
5995
|
+
r,
|
5996
|
+
s
|
5997
|
+
} : {}
|
5998
|
+
},
|
5999
|
+
serializedTransaction,
|
6000
|
+
type: "legacy"
|
6001
|
+
});
|
6002
|
+
let transaction = {
|
6003
|
+
type: "legacy"
|
6004
|
+
};
|
6005
|
+
if (isHex(to) && to !== "0x")
|
6006
|
+
transaction.to = to;
|
6007
|
+
if (isHex(gas) && gas !== "0x")
|
6008
|
+
transaction.gas = hexToBigInt(gas);
|
6009
|
+
if (isHex(data) && data !== "0x")
|
6010
|
+
transaction.data = data;
|
6011
|
+
if (isHex(nonce) && nonce !== "0x")
|
6012
|
+
transaction.nonce = hexToNumber(nonce);
|
6013
|
+
if (isHex(value) && value !== "0x")
|
6014
|
+
transaction.value = hexToBigInt(value);
|
6015
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
6016
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
6017
|
+
assertTransactionLegacy(transaction);
|
6018
|
+
if (transactionArray.length === 6)
|
6019
|
+
return transaction;
|
6020
|
+
const chainIdOrV = isHex(chainIdOrV_) && chainIdOrV_ !== "0x" ? hexToBigInt(chainIdOrV_) : 0n;
|
6021
|
+
if (s === "0x" && r === "0x") {
|
6022
|
+
if (chainIdOrV > 0)
|
6023
|
+
transaction.chainId = Number(chainIdOrV);
|
6024
|
+
return transaction;
|
6025
|
+
}
|
6026
|
+
const v = chainIdOrV;
|
6027
|
+
let chainId = Number((v - 35n) / 2n);
|
6028
|
+
if (chainId > 0)
|
6029
|
+
transaction.chainId = chainId;
|
6030
|
+
else if (v !== 27n && v !== 28n)
|
6031
|
+
throw new InvalidLegacyVError({ v });
|
6032
|
+
transaction.v = v;
|
6033
|
+
transaction.s = s;
|
6034
|
+
transaction.r = r;
|
6035
|
+
return transaction;
|
6036
|
+
}
|
6037
|
+
function parseAccessList(accessList_) {
|
6038
|
+
let accessList = [];
|
6039
|
+
for (let i = 0; i < accessList_.length; i++) {
|
6040
|
+
const [address, storageKeys] = accessList_[i];
|
6041
|
+
if (!isAddress(address))
|
6042
|
+
throw new InvalidAddressError({ address });
|
6043
|
+
accessList.push({
|
6044
|
+
address,
|
6045
|
+
storageKeys: storageKeys.map((key) => isHash(key) ? key : trim(key))
|
6046
|
+
});
|
6047
|
+
}
|
6048
|
+
return accessList;
|
6049
|
+
}
|
6050
|
+
function parseEIP155Signature(transactionArray) {
|
6051
|
+
const signature = transactionArray.slice(-3);
|
6052
|
+
const v = signature[0] === "0x" || hexToBigInt(signature[0]) === 0n ? 27n : 28n;
|
6053
|
+
return {
|
6054
|
+
r: padHex(signature[1], { size: 32 }),
|
6055
|
+
s: padHex(signature[2], { size: 32 }),
|
6056
|
+
v,
|
6057
|
+
yParity: v === 27n ? 0 : 1
|
6058
|
+
};
|
6059
|
+
}
|
6060
|
+
|
6061
|
+
// src/utils/transaction/serializeTransaction.ts
|
6062
|
+
function serializeTransaction(transaction, signature) {
|
6063
|
+
const type = getTransactionType(transaction);
|
6064
|
+
if (type === "eip1559")
|
6065
|
+
return serializeTransactionEIP1559(
|
6066
|
+
transaction,
|
6067
|
+
signature
|
6068
|
+
);
|
6069
|
+
if (type === "eip2930")
|
6070
|
+
return serializeTransactionEIP2930(
|
6071
|
+
transaction,
|
6072
|
+
signature
|
6073
|
+
);
|
6074
|
+
return serializeTransactionLegacy(
|
6075
|
+
transaction,
|
6076
|
+
signature
|
6077
|
+
);
|
6078
|
+
}
|
6079
|
+
function serializeTransactionEIP1559(transaction, signature) {
|
6080
|
+
const {
|
6081
|
+
chainId,
|
6082
|
+
gas,
|
6083
|
+
nonce,
|
6084
|
+
to,
|
6085
|
+
value,
|
6086
|
+
maxFeePerGas,
|
6087
|
+
maxPriorityFeePerGas,
|
6088
|
+
accessList,
|
6089
|
+
data
|
6090
|
+
} = transaction;
|
6091
|
+
assertTransactionEIP1559(transaction);
|
6092
|
+
const serializedAccessList = serializeAccessList(accessList);
|
6093
|
+
const serializedTransaction = [
|
6094
|
+
toHex(chainId),
|
6095
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6096
|
+
typeof maxPriorityFeePerGas !== "undefined" ? toHex(maxPriorityFeePerGas) : "0x",
|
6097
|
+
typeof maxFeePerGas !== "undefined" ? toHex(maxFeePerGas) : "0x",
|
6098
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6099
|
+
to ?? "0x",
|
6100
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6101
|
+
data ?? "0x",
|
6102
|
+
serializedAccessList
|
6103
|
+
];
|
6104
|
+
if (signature)
|
6105
|
+
serializedTransaction.push(
|
6106
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6107
|
+
// yParity
|
6108
|
+
signature.r,
|
6109
|
+
signature.s
|
6110
|
+
);
|
6111
|
+
return concatHex([
|
6112
|
+
"0x02",
|
6113
|
+
toRlp(serializedTransaction)
|
6114
|
+
]);
|
6115
|
+
}
|
6116
|
+
function serializeTransactionEIP2930(transaction, signature) {
|
6117
|
+
const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
|
6118
|
+
assertTransactionEIP2930(transaction);
|
6119
|
+
const serializedAccessList = serializeAccessList(accessList);
|
6120
|
+
const serializedTransaction = [
|
6121
|
+
toHex(chainId),
|
6122
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6123
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6124
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6125
|
+
to ?? "0x",
|
6126
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6127
|
+
data ?? "0x",
|
6128
|
+
serializedAccessList
|
6129
|
+
];
|
6130
|
+
if (signature)
|
6131
|
+
serializedTransaction.push(
|
6132
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6133
|
+
// yParity
|
6134
|
+
signature.r,
|
6135
|
+
signature.s
|
6136
|
+
);
|
6137
|
+
return concatHex([
|
6138
|
+
"0x01",
|
6139
|
+
toRlp(serializedTransaction)
|
6140
|
+
]);
|
6141
|
+
}
|
6142
|
+
function serializeTransactionLegacy(transaction, signature) {
|
6143
|
+
const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
|
6144
|
+
assertTransactionLegacy(transaction);
|
6145
|
+
let serializedTransaction = [
|
6146
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6147
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6148
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6149
|
+
to ?? "0x",
|
6150
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6151
|
+
data ?? "0x"
|
6152
|
+
];
|
6153
|
+
if (signature) {
|
6154
|
+
let v = 27n + (signature.v === 27n ? 0n : 1n);
|
6155
|
+
if (chainId > 0)
|
6156
|
+
v = BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
|
6157
|
+
else if (signature.v !== v)
|
6158
|
+
throw new InvalidLegacyVError({ v: signature.v });
|
6159
|
+
serializedTransaction = [
|
6160
|
+
...serializedTransaction,
|
6161
|
+
toHex(v),
|
6162
|
+
signature.r,
|
6163
|
+
signature.s
|
6164
|
+
];
|
6165
|
+
} else if (chainId > 0) {
|
6166
|
+
serializedTransaction = [
|
6167
|
+
...serializedTransaction,
|
6168
|
+
toHex(chainId),
|
6169
|
+
"0x",
|
6170
|
+
"0x"
|
6171
|
+
];
|
6172
|
+
}
|
6173
|
+
return toRlp(serializedTransaction);
|
6174
|
+
}
|
6175
|
+
function serializeAccessList(accessList) {
|
6176
|
+
if (!accessList || accessList.length === 0)
|
6177
|
+
return [];
|
6178
|
+
let serializedAccessList = [];
|
6179
|
+
for (let i = 0; i < accessList.length; i++) {
|
6180
|
+
const { address, storageKeys } = accessList[i];
|
6181
|
+
for (let j = 0; j < storageKeys.length; j++) {
|
6182
|
+
if (storageKeys[j].length - 2 !== 64) {
|
6183
|
+
throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
|
6184
|
+
}
|
6185
|
+
}
|
6186
|
+
if (!isAddress(address)) {
|
6187
|
+
throw new InvalidAddressError({ address });
|
6188
|
+
}
|
6189
|
+
serializedAccessList.push([address, storageKeys]);
|
6190
|
+
}
|
6191
|
+
return serializedAccessList;
|
6192
|
+
}
|
6193
|
+
|
5302
6194
|
// src/utils/unit/formatUnits.ts
|
5303
6195
|
function formatUnits(value, decimals) {
|
5304
6196
|
let display = value.toString();
|
@@ -5354,11 +6246,13 @@ export {
|
|
5354
6246
|
InvalidAddressError,
|
5355
6247
|
BlockNotFoundError,
|
5356
6248
|
ChainDoesNotSupportContract,
|
6249
|
+
InvalidChainIdError,
|
5357
6250
|
multicall3Abi,
|
5358
6251
|
panicReasons,
|
5359
6252
|
etherUnits,
|
5360
6253
|
gweiUnits,
|
5361
6254
|
weiUnits,
|
6255
|
+
InvalidLegacyVError,
|
5362
6256
|
TransactionExecutionError,
|
5363
6257
|
TransactionNotFoundError,
|
5364
6258
|
TransactionReceiptNotFoundError,
|
@@ -5453,7 +6347,9 @@ export {
|
|
5453
6347
|
keccak256,
|
5454
6348
|
getEventSelector,
|
5455
6349
|
getFunctionSelector,
|
6350
|
+
isHash,
|
5456
6351
|
isAddress,
|
6352
|
+
checksumAddress,
|
5457
6353
|
getAddress,
|
5458
6354
|
getContractAddress2 as getContractAddress,
|
5459
6355
|
getCreateAddress,
|
@@ -5481,7 +6377,7 @@ export {
|
|
5481
6377
|
parseAbiItem,
|
5482
6378
|
parseAbiParameter,
|
5483
6379
|
parseAbiParameters,
|
5484
|
-
|
6380
|
+
parseAccount,
|
5485
6381
|
isDeterministicError,
|
5486
6382
|
buildRequest,
|
5487
6383
|
defineChain,
|
@@ -5507,10 +6403,16 @@ export {
|
|
5507
6403
|
getSocket,
|
5508
6404
|
rpc,
|
5509
6405
|
hashMessage,
|
6406
|
+
validateTypedData,
|
6407
|
+
hashTypedData,
|
5510
6408
|
recoverAddress,
|
5511
6409
|
recoverMessageAddress,
|
6410
|
+
recoverTypedDataAddress,
|
5512
6411
|
verifyMessage,
|
6412
|
+
verifyTypedData,
|
5513
6413
|
assertRequest,
|
6414
|
+
getSerializedTransactionType,
|
6415
|
+
getTransactionType,
|
5514
6416
|
call,
|
5515
6417
|
simulateContract,
|
5516
6418
|
createPendingTransactionFilter,
|
@@ -5588,9 +6490,14 @@ export {
|
|
5588
6490
|
parseUnits,
|
5589
6491
|
parseGwei,
|
5590
6492
|
prepareRequest,
|
6493
|
+
assertTransactionEIP1559,
|
6494
|
+
assertTransactionEIP2930,
|
6495
|
+
assertTransactionLegacy,
|
6496
|
+
parseTransaction,
|
6497
|
+
serializeTransaction,
|
5591
6498
|
formatUnits,
|
5592
6499
|
formatEther,
|
5593
6500
|
formatGwei,
|
5594
6501
|
parseEther
|
5595
6502
|
};
|
5596
|
-
//# sourceMappingURL=chunk-
|
6503
|
+
//# sourceMappingURL=chunk-HYEOQX7O.mjs.map
|