@toruslabs/ethereum-controllers 8.17.1 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs/Account/AccountTrackerController.js +15 -7
- package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +22 -26
- package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.cjs/Eip5792/walletSendCalls.js +6 -7
- package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.cjs/Gas/GasFeeController.js +2 -2
- package/dist/lib.cjs/Keyring/KeyringController.js +68 -41
- package/dist/lib.cjs/Message/utils.js +14 -16
- package/dist/lib.cjs/Network/NetworkController.js +7 -9
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +373 -285
- package/dist/lib.cjs/Network/createJsonRpcClient.js +21 -21
- package/dist/lib.cjs/Nfts/NftHandler.js +54 -12
- package/dist/lib.cjs/Nfts/NftsController.js +1 -4
- package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
- package/dist/lib.cjs/Tokens/TokenHandler.js +39 -7
- package/dist/lib.cjs/Tokens/TokensController.js +15 -7
- package/dist/lib.cjs/Transaction/TransactionController.js +17 -20
- package/dist/lib.cjs/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.cjs/Transaction/TransactionUtils.js +44 -39
- package/dist/lib.cjs/index.js +9 -0
- package/dist/lib.cjs/types/Account/AccountTrackerController.d.ts +1 -1
- package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +4 -6
- package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +1 -1
- package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +1 -1
- package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +4 -4
- package/dist/lib.cjs/types/Network/NetworkController.d.ts +1 -1
- package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +28 -90
- package/dist/lib.cjs/types/Network/createJsonRpcClient.d.ts +4 -4
- package/dist/lib.cjs/types/Network/index.d.ts +5 -0
- package/dist/lib.cjs/types/Network/interfaces.d.ts +58 -0
- package/dist/lib.cjs/types/Nfts/NftHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Nfts/NftsController.d.ts +0 -1
- package/dist/lib.cjs/types/Tokens/TokenHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Tokens/TokensController.d.ts +1 -1
- package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +11 -3
- package/dist/lib.cjs/types/index.d.ts +1 -3
- package/dist/lib.cjs/types/utils/abis.d.ts +544 -99
- package/dist/lib.cjs/types/utils/eip5792Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/eip7702Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/interfaces.d.ts +207 -4
- package/dist/lib.cjs/types/utils/transaction.d.ts +1 -1
- package/dist/lib.cjs/types/utils/viem.d.ts +8 -0
- package/dist/lib.cjs/utils/abis.js +12 -0
- package/dist/lib.cjs/utils/conversionUtils.js +3 -4
- package/dist/lib.cjs/utils/helpers.js +8 -7
- package/dist/lib.cjs/utils/transaction.js +7 -11
- package/dist/lib.cjs/utils/viem.js +214 -0
- package/dist/lib.esm/Account/AccountTrackerController.js +15 -7
- package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +24 -28
- package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.esm/Eip5792/walletSendCalls.js +6 -7
- package/dist/lib.esm/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.esm/Gas/GasFeeController.js +2 -2
- package/dist/lib.esm/Keyring/KeyringController.js +68 -42
- package/dist/lib.esm/Message/utils.js +14 -16
- package/dist/lib.esm/Network/NetworkController.js +8 -10
- package/dist/lib.esm/Network/createEthereumMiddleware.js +387 -290
- package/dist/lib.esm/Network/createJsonRpcClient.js +22 -22
- package/dist/lib.esm/Nfts/NftHandler.js +54 -12
- package/dist/lib.esm/Nfts/NftsController.js +1 -4
- package/dist/lib.esm/Preferences/PreferencesController.js +2 -2
- package/dist/lib.esm/Tokens/TokenHandler.js +39 -7
- package/dist/lib.esm/Tokens/TokensController.js +15 -7
- package/dist/lib.esm/Transaction/TransactionController.js +18 -21
- package/dist/lib.esm/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.esm/Transaction/TransactionUtils.js +44 -40
- package/dist/lib.esm/index.js +4 -3
- package/dist/lib.esm/utils/abis.js +12 -0
- package/dist/lib.esm/utils/conversionUtils.js +3 -4
- package/dist/lib.esm/utils/helpers.js +8 -7
- package/dist/lib.esm/utils/interfaces.js +64 -0
- package/dist/lib.esm/utils/transaction.js +7 -11
- package/dist/lib.esm/utils/viem.js +214 -0
- package/package.json +14 -19
- package/dist/ethereumControllers.umd.min.js +0 -2
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -50
|
@@ -2,15 +2,25 @@ import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts
|
|
|
2
2
|
import { BASE_TX_EVENT_TYPE, BaseBlockTrackerState, BaseControllerEvents, BaseFormattedTransactionActivity, BaseTokenInfo, BaseTransactionEvents, MESSAGE_EVENTS, MessageStatus, NetworkConfig, NetworkState, PaymentTransaction, PollingBlockTrackerConfig, PopupWhitelabelData, ProviderConfig, TRANSACTION_TYPE, TransactionMeta, TransactionState, TransactionStatus, TX_CONFIRMED_EVENT_TYPE, TX_DROPPED_EVENT_TYPE, TX_EVENTS, TX_FAILED_EVENT_TYPE, TX_WARNING_EVENT_TYPE, User } from "@toruslabs/base-controllers";
|
|
3
3
|
import { JRPCRequest, Json } from "@web3auth/auth";
|
|
4
4
|
import { MutexInterface } from "async-mutex";
|
|
5
|
-
import { AccessList, TypedDataDomain, TypedDataField } from "ethers";
|
|
6
5
|
import { ToBiconomySmartAccountParameters, toEcdsaKernelSmartAccount, ToLightSmartAccountParameters, ToNexusSmartAccountParameters, toSafeSmartAccount, toSimpleSmartAccount, toTrustSmartAccount } from "permissionless/accounts";
|
|
7
|
-
import { Client, Hex, WalletClient } from "viem";
|
|
6
|
+
import { Client, Hex, Signature, WalletClient } from "viem";
|
|
8
7
|
import { createBundlerClient, createPaymasterClient, SmartAccount, UserOperationReceipt, WebAuthnAccount } from "viem/account-abstraction";
|
|
9
8
|
import { METHOD_TYPES, SMART_ACCOUNT, TRANSACTION_ENVELOPE_TYPES } from "./constants";
|
|
10
9
|
import { NestedTransactionMetadata } from "./eip5792Types";
|
|
11
10
|
import { Authorization } from "./eip7702Types";
|
|
12
11
|
export type { BatchTransactionParams, NestedTransactionMetadata, TransactionBatchRequest, TransactionBatchSingleRequest } from "./eip5792Types";
|
|
13
12
|
export type { Authorization, Eip7702Params, Eip7702WalletGetUpgradeStatusResponse, SignedAuthorization } from "./eip7702Types";
|
|
13
|
+
export type TypedDataField = {
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
export type TypedDataDomain = {
|
|
18
|
+
name?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
chainId?: number | string;
|
|
21
|
+
verifyingContract?: string;
|
|
22
|
+
salt?: string;
|
|
23
|
+
};
|
|
14
24
|
export type CustomTokenInfo = BaseTokenInfo & {
|
|
15
25
|
erc20: boolean;
|
|
16
26
|
customTokenId?: string;
|
|
@@ -61,6 +71,7 @@ export interface Message extends AbstractMessage {
|
|
|
61
71
|
messageParams: MessageParams;
|
|
62
72
|
}
|
|
63
73
|
export type SignTypedDataMessageV4 = {
|
|
74
|
+
primaryType: string;
|
|
64
75
|
types: Record<string, TypedDataField[]>;
|
|
65
76
|
domain: TypedDataDomain;
|
|
66
77
|
message: Record<string, unknown>;
|
|
@@ -219,7 +230,7 @@ export interface TransactionReceipt {
|
|
|
219
230
|
}
|
|
220
231
|
export type BlockTag = "earliest" | "finalized" | "safe" | "latest" | "pending";
|
|
221
232
|
export type BlockParams = string | BlockTag;
|
|
222
|
-
export interface TransactionRPCMeta {
|
|
233
|
+
export interface TransactionRPCMeta extends Record<string, unknown> {
|
|
223
234
|
v: string;
|
|
224
235
|
r: string;
|
|
225
236
|
s: string;
|
|
@@ -493,7 +504,7 @@ export type AccountAbstractionMultiChainConfig = {
|
|
|
493
504
|
smartAccountConfig?: SmartAccountConfig;
|
|
494
505
|
}[];
|
|
495
506
|
};
|
|
496
|
-
export interface UserOperationGas {
|
|
507
|
+
export interface UserOperationGas extends Record<string, string> {
|
|
497
508
|
callGasLimit: string;
|
|
498
509
|
preVerificationGas: string;
|
|
499
510
|
verificationGasLimit: string;
|
|
@@ -504,3 +515,195 @@ export interface UserOperationGas {
|
|
|
504
515
|
* Type Def for function to query the deployment bytecode of an address. (eth_getCode)
|
|
505
516
|
*/
|
|
506
517
|
export type GetEthCodeFn = (address: `0x${string}`, chainId: `0x${string}`) => Promise<`0x${string}`>;
|
|
518
|
+
/**
|
|
519
|
+
* A [[HexString]] whose length is even, which ensures it is a valid
|
|
520
|
+
* representation of binary data.
|
|
521
|
+
*/
|
|
522
|
+
export type DataHexString = Hex;
|
|
523
|
+
/**
|
|
524
|
+
* An object that can be used to represent binary data.
|
|
525
|
+
*/
|
|
526
|
+
export type BytesLike = DataHexString | Uint8Array;
|
|
527
|
+
/**
|
|
528
|
+
* A BLOb object that can be passed for [[link-eip-4844]]
|
|
529
|
+
* transactions.
|
|
530
|
+
*
|
|
531
|
+
* It may have had its commitment and proof already provided
|
|
532
|
+
* or rely on an attached [[KzgLibrary]] to compute them.
|
|
533
|
+
*/
|
|
534
|
+
export type BlobLike = BytesLike | {
|
|
535
|
+
data: BytesLike;
|
|
536
|
+
proof: BytesLike;
|
|
537
|
+
commitment: BytesLike;
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* A KZG Library with the necessary functions to compute
|
|
541
|
+
* BLOb commitments and proofs.
|
|
542
|
+
*/
|
|
543
|
+
export interface KzgLibrary {
|
|
544
|
+
blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
|
|
545
|
+
computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* A KZG Library with any of the various API configurations.
|
|
549
|
+
* As the library is still experimental and the API is not
|
|
550
|
+
* stable, depending on the version used the method names and
|
|
551
|
+
* signatures are still in flux.
|
|
552
|
+
*
|
|
553
|
+
* This allows any of the versions to be passed into Transaction
|
|
554
|
+
* while providing a stable external API.
|
|
555
|
+
*/
|
|
556
|
+
export type KzgLibraryLike = KzgLibrary | {
|
|
557
|
+
blobToKZGCommitment: (blob: string) => string;
|
|
558
|
+
computeBlobKZGProof: (blob: string, commitment: string) => string;
|
|
559
|
+
} | {
|
|
560
|
+
blobToKzgCommitment: (blob: string) => string | Uint8Array;
|
|
561
|
+
computeBlobProof: (blob: string, commitment: string) => string | Uint8Array;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Any type that can be used where a numeric value is needed.
|
|
565
|
+
*/
|
|
566
|
+
export type Numeric = number | bigint;
|
|
567
|
+
/**
|
|
568
|
+
* Any type that can be used where a big number is needed.
|
|
569
|
+
*/
|
|
570
|
+
export type BigNumberish = string | Numeric;
|
|
571
|
+
/**
|
|
572
|
+
* A SignatureLike
|
|
573
|
+
*
|
|
574
|
+
* @_docloc: api/crypto:Signing
|
|
575
|
+
*/
|
|
576
|
+
export type SignatureLike = Signature | string | {
|
|
577
|
+
r: string;
|
|
578
|
+
s: string;
|
|
579
|
+
v: BigNumberish;
|
|
580
|
+
yParity?: 0 | 1;
|
|
581
|
+
yParityAndS?: string;
|
|
582
|
+
} | {
|
|
583
|
+
r: string;
|
|
584
|
+
yParityAndS: string;
|
|
585
|
+
yParity?: 0 | 1;
|
|
586
|
+
s?: string;
|
|
587
|
+
v?: number;
|
|
588
|
+
} | {
|
|
589
|
+
r: string;
|
|
590
|
+
s: string;
|
|
591
|
+
yParity: 0 | 1;
|
|
592
|
+
v?: BigNumberish;
|
|
593
|
+
yParityAndS?: string;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* A **TransactionLike** is an object which is appropriate as a loose
|
|
597
|
+
* input for many operations which will populate missing properties of
|
|
598
|
+
* a transaction.
|
|
599
|
+
*/
|
|
600
|
+
/**
|
|
601
|
+
* A single [[AccessList]] entry of storage keys (slots) for an address.
|
|
602
|
+
*/
|
|
603
|
+
export type AccessListEntry = {
|
|
604
|
+
address: string;
|
|
605
|
+
storageKeys: Array<string>;
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
* An ordered collection of [[AccessList]] entries.
|
|
609
|
+
*/
|
|
610
|
+
export type AccessList = Array<AccessListEntry>;
|
|
611
|
+
/**
|
|
612
|
+
* Any ethers-supported access list structure.
|
|
613
|
+
*/
|
|
614
|
+
export type AccessListish = AccessList | Array<[string, Array<string>]> | Record<string, Array<string>>;
|
|
615
|
+
export interface AuthorizationLike {
|
|
616
|
+
address: string;
|
|
617
|
+
nonce: bigint;
|
|
618
|
+
chainId: bigint;
|
|
619
|
+
signature: SignatureLike;
|
|
620
|
+
}
|
|
621
|
+
export interface TransactionLike<A = string> {
|
|
622
|
+
/**
|
|
623
|
+
* The type.
|
|
624
|
+
*/
|
|
625
|
+
type?: null | number;
|
|
626
|
+
/**
|
|
627
|
+
* The recipient address or ``null`` for an ``init`` transaction.
|
|
628
|
+
*/
|
|
629
|
+
to?: null | A;
|
|
630
|
+
/**
|
|
631
|
+
* The sender.
|
|
632
|
+
*/
|
|
633
|
+
from?: null | A;
|
|
634
|
+
/**
|
|
635
|
+
* The nonce.
|
|
636
|
+
*/
|
|
637
|
+
nonce?: null | number;
|
|
638
|
+
/**
|
|
639
|
+
* The maximum amount of gas that can be used.
|
|
640
|
+
*/
|
|
641
|
+
gasLimit?: null | BigNumberish;
|
|
642
|
+
/**
|
|
643
|
+
* The gas price for legacy and berlin transactions.
|
|
644
|
+
*/
|
|
645
|
+
gasPrice?: null | BigNumberish;
|
|
646
|
+
/**
|
|
647
|
+
* The maximum priority fee per gas for london transactions.
|
|
648
|
+
*/
|
|
649
|
+
maxPriorityFeePerGas?: null | BigNumberish;
|
|
650
|
+
/**
|
|
651
|
+
* The maximum total fee per gas for london transactions.
|
|
652
|
+
*/
|
|
653
|
+
maxFeePerGas?: null | BigNumberish;
|
|
654
|
+
/**
|
|
655
|
+
* The data.
|
|
656
|
+
*/
|
|
657
|
+
data?: null | string;
|
|
658
|
+
/**
|
|
659
|
+
* The value (in wei) to send.
|
|
660
|
+
*/
|
|
661
|
+
value?: null | BigNumberish;
|
|
662
|
+
/**
|
|
663
|
+
* The chain ID the transaction is valid on.
|
|
664
|
+
*/
|
|
665
|
+
chainId?: null | BigNumberish;
|
|
666
|
+
/**
|
|
667
|
+
* The transaction hash.
|
|
668
|
+
*/
|
|
669
|
+
hash?: null | string;
|
|
670
|
+
/**
|
|
671
|
+
* The signature provided by the sender.
|
|
672
|
+
*/
|
|
673
|
+
signature?: null | SignatureLike;
|
|
674
|
+
/**
|
|
675
|
+
* The access list for berlin and london transactions.
|
|
676
|
+
*/
|
|
677
|
+
accessList?: null | AccessListish;
|
|
678
|
+
/**
|
|
679
|
+
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
680
|
+
*/
|
|
681
|
+
maxFeePerBlobGas?: null | BigNumberish;
|
|
682
|
+
/**
|
|
683
|
+
* The versioned hashes (see [[link-eip-4844]]).
|
|
684
|
+
*/
|
|
685
|
+
blobVersionedHashes?: null | Array<string>;
|
|
686
|
+
/**
|
|
687
|
+
* The blobs (if any) attached to this transaction (see [[link-eip-4844]]).
|
|
688
|
+
*/
|
|
689
|
+
blobs?: null | Array<BlobLike>;
|
|
690
|
+
/**
|
|
691
|
+
* An external library for computing the KZG commitments and
|
|
692
|
+
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
693
|
+
*
|
|
694
|
+
* This is generally ``null``, unless you are creating BLOb
|
|
695
|
+
* transactions.
|
|
696
|
+
*/
|
|
697
|
+
kzg?: null | KzgLibraryLike;
|
|
698
|
+
/**
|
|
699
|
+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
|
|
700
|
+
*
|
|
701
|
+
* For networks that use EIP-7594, this property is required to
|
|
702
|
+
* serialize the sidecar correctly.
|
|
703
|
+
*/
|
|
704
|
+
blobWrapperVersion?: null | number;
|
|
705
|
+
/**
|
|
706
|
+
* The [[link-eip-7702]] authorizations (if any).
|
|
707
|
+
*/
|
|
708
|
+
authorizationList?: null | Array<AuthorizationLike>;
|
|
709
|
+
}
|
|
@@ -3,4 +3,4 @@ import { JRPCRequest } from "@web3auth/auth";
|
|
|
3
3
|
* Transaction decoder for analytics.
|
|
4
4
|
* Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
|
|
5
5
|
*/
|
|
6
|
-
export declare const transactionDecoder: (req: JRPCRequest<unknown>, chainId: string) => [string, string]
|
|
6
|
+
export declare const transactionDecoder: (req: JRPCRequest<unknown>, chainId: string) => Promise<[sender: string, txHash: string]>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TransactionSerializable } from "viem";
|
|
2
|
+
import { TransactionLike } from "./interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Prepare transaction params for signing.
|
|
5
|
+
* @param tx - The transaction to prepare.
|
|
6
|
+
* @returns The prepared transaction.
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareViemTx(tx: TransactionLike): TransactionSerializable;
|
|
@@ -9,6 +9,7 @@ const erc20Abi = [{
|
|
|
9
9
|
type: "string"
|
|
10
10
|
}],
|
|
11
11
|
payable: false,
|
|
12
|
+
stateMutability: "view",
|
|
12
13
|
type: "function"
|
|
13
14
|
}, {
|
|
14
15
|
constant: false,
|
|
@@ -25,6 +26,7 @@ const erc20Abi = [{
|
|
|
25
26
|
type: "bool"
|
|
26
27
|
}],
|
|
27
28
|
payable: false,
|
|
29
|
+
stateMutability: "nonpayable",
|
|
28
30
|
type: "function"
|
|
29
31
|
}, {
|
|
30
32
|
constant: true,
|
|
@@ -35,6 +37,7 @@ const erc20Abi = [{
|
|
|
35
37
|
type: "uint256"
|
|
36
38
|
}],
|
|
37
39
|
payable: false,
|
|
40
|
+
stateMutability: "view",
|
|
38
41
|
type: "function"
|
|
39
42
|
}, {
|
|
40
43
|
constant: false,
|
|
@@ -54,6 +57,7 @@ const erc20Abi = [{
|
|
|
54
57
|
type: "bool"
|
|
55
58
|
}],
|
|
56
59
|
payable: false,
|
|
60
|
+
stateMutability: "nonpayable",
|
|
57
61
|
type: "function"
|
|
58
62
|
}, {
|
|
59
63
|
constant: true,
|
|
@@ -64,6 +68,7 @@ const erc20Abi = [{
|
|
|
64
68
|
type: "uint256"
|
|
65
69
|
}],
|
|
66
70
|
payable: false,
|
|
71
|
+
stateMutability: "view",
|
|
67
72
|
type: "function"
|
|
68
73
|
}, {
|
|
69
74
|
constant: true,
|
|
@@ -77,6 +82,7 @@ const erc20Abi = [{
|
|
|
77
82
|
type: "uint256"
|
|
78
83
|
}],
|
|
79
84
|
payable: false,
|
|
85
|
+
stateMutability: "view",
|
|
80
86
|
type: "function"
|
|
81
87
|
}, {
|
|
82
88
|
constant: true,
|
|
@@ -87,6 +93,7 @@ const erc20Abi = [{
|
|
|
87
93
|
type: "string"
|
|
88
94
|
}],
|
|
89
95
|
payable: false,
|
|
96
|
+
stateMutability: "view",
|
|
90
97
|
type: "function"
|
|
91
98
|
}, {
|
|
92
99
|
constant: false,
|
|
@@ -103,6 +110,7 @@ const erc20Abi = [{
|
|
|
103
110
|
type: "bool"
|
|
104
111
|
}],
|
|
105
112
|
payable: false,
|
|
113
|
+
stateMutability: "nonpayable",
|
|
106
114
|
type: "function"
|
|
107
115
|
}, {
|
|
108
116
|
constant: false,
|
|
@@ -122,6 +130,7 @@ const erc20Abi = [{
|
|
|
122
130
|
type: "bool"
|
|
123
131
|
}],
|
|
124
132
|
payable: false,
|
|
133
|
+
stateMutability: "nonpayable",
|
|
125
134
|
type: "function"
|
|
126
135
|
}, {
|
|
127
136
|
constant: true,
|
|
@@ -138,6 +147,7 @@ const erc20Abi = [{
|
|
|
138
147
|
type: "uint256"
|
|
139
148
|
}],
|
|
140
149
|
payable: false,
|
|
150
|
+
stateMutability: "view",
|
|
141
151
|
type: "function"
|
|
142
152
|
}, {
|
|
143
153
|
inputs: [{
|
|
@@ -153,9 +163,11 @@ const erc20Abi = [{
|
|
|
153
163
|
name: "_tokenSymbol",
|
|
154
164
|
type: "string"
|
|
155
165
|
}],
|
|
166
|
+
stateMutability: "nonpayable",
|
|
156
167
|
type: "constructor"
|
|
157
168
|
}, {
|
|
158
169
|
payable: false,
|
|
170
|
+
stateMutability: "nonpayable",
|
|
159
171
|
type: "fallback"
|
|
160
172
|
}];
|
|
161
173
|
const erc721Abi = [{
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty');
|
|
4
4
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
5
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
|
-
var
|
|
6
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
7
7
|
var bignumber_js = require('bignumber.js');
|
|
8
|
-
var BN = require('bn.js');
|
|
9
8
|
|
|
10
9
|
const _excluded = ["aBase", "bBase"],
|
|
11
10
|
_excluded2 = ["aBase", "bBase"],
|
|
@@ -16,7 +15,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new bignumber_js.BigNumber("1000000000");
|
|
|
16
15
|
const BIG_NUMBER_ETH_MULTIPLIER = new bignumber_js.BigNumber("1");
|
|
17
16
|
// Setter Maps
|
|
18
17
|
const toBigNumber = {
|
|
19
|
-
hex: n => new bignumber_js.BigNumber(
|
|
18
|
+
hex: n => new bignumber_js.BigNumber(metadataHelpers.remove0x(n), 16),
|
|
20
19
|
dec: n => new bignumber_js.BigNumber(String(n), 10),
|
|
21
20
|
BN: n => new bignumber_js.BigNumber(n.toString(16), 16)
|
|
22
21
|
};
|
|
@@ -33,7 +32,7 @@ const toSpecifiedDenomination = {
|
|
|
33
32
|
const baseChange = {
|
|
34
33
|
hex: n => n.toString(16),
|
|
35
34
|
dec: n => new bignumber_js.BigNumber(n).toString(10),
|
|
36
|
-
BN: n => new
|
|
35
|
+
BN: n => new bignumber_js.BigNumber(n.toString(16))
|
|
37
36
|
};
|
|
38
37
|
// Utility function for checking base types
|
|
39
38
|
const isValidBase = base => Number.isInteger(base) && base > 1;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
|
-
var util = require('@ethereumjs/util');
|
|
5
4
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
5
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
6
6
|
var bignumber_js = require('bignumber.js');
|
|
7
7
|
var log = require('loglevel');
|
|
8
|
+
var viem = require('viem');
|
|
8
9
|
var TransactionUtils = require('../Transaction/TransactionUtils.js');
|
|
9
10
|
var constants = require('./constants.js');
|
|
10
11
|
|
|
11
12
|
function hexToBn(hex) {
|
|
12
|
-
return new bignumber_js.BigNumber(
|
|
13
|
+
return new bignumber_js.BigNumber(metadataHelpers.remove0x(hex), 16);
|
|
13
14
|
}
|
|
14
15
|
function BNToHex(bn) {
|
|
15
|
-
return
|
|
16
|
+
return metadataHelpers.add0x(bn.toString(16));
|
|
16
17
|
}
|
|
17
18
|
function getEtherScanHashLink(txHash, chainId) {
|
|
18
19
|
if (!constants.SUPPORTED_NETWORKS[chainId]) return "";
|
|
@@ -94,18 +95,18 @@ function formatTime(time) {
|
|
|
94
95
|
}
|
|
95
96
|
function isAddressByChainId(address, _chainId) {
|
|
96
97
|
// TOOD: add rsk network checks.
|
|
97
|
-
return
|
|
98
|
+
return viem.isAddress(address);
|
|
98
99
|
}
|
|
99
100
|
function toChecksumAddressByChainId(address, chainId) {
|
|
100
101
|
// TOOD: add rsk network checks.
|
|
101
102
|
if (!isAddressByChainId(address)) return address;
|
|
102
|
-
return
|
|
103
|
+
return viem.getAddress(address);
|
|
103
104
|
}
|
|
104
105
|
const GAS_LIMITS = {
|
|
105
106
|
// maximum gasLimit of a simple send
|
|
106
|
-
SIMPLE:
|
|
107
|
+
SIMPLE: viem.toHex(21000),
|
|
107
108
|
// a base estimate for token transfers.
|
|
108
|
-
BASE_TOKEN_ESTIMATE:
|
|
109
|
+
BASE_TOKEN_ESTIMATE: viem.toHex(100000)
|
|
109
110
|
};
|
|
110
111
|
function bnLessThan(a, b) {
|
|
111
112
|
if (a === null || a === undefined || b === null || b === undefined) {
|
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var tx = require('@ethereumjs/tx');
|
|
5
|
-
var util = require('@ethereumjs/util');
|
|
3
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
6
4
|
var log = require('loglevel');
|
|
5
|
+
var viem = require('viem');
|
|
7
6
|
var constants = require('./constants.js');
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Transaction decoder for analytics.
|
|
11
10
|
* Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
|
|
12
11
|
*/
|
|
13
|
-
const transactionDecoder = (req, chainId) => {
|
|
12
|
+
const transactionDecoder = async (req, chainId) => {
|
|
14
13
|
let sender = "";
|
|
15
14
|
let txHash = "";
|
|
16
15
|
try {
|
|
17
16
|
if (req.method === constants.METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
|
|
18
17
|
const rawTx = req.params[0];
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
chainId
|
|
23
|
-
}, common.Mainnet)
|
|
18
|
+
const normalizedRawTx = metadataHelpers.add0x(rawTx);
|
|
19
|
+
sender = await viem.recoverTransactionAddress({
|
|
20
|
+
serializedTransaction: normalizedRawTx
|
|
24
21
|
});
|
|
25
|
-
|
|
26
|
-
txHash = util.bytesToHex(tx$1.hash());
|
|
22
|
+
txHash = viem.keccak256(normalizedRawTx);
|
|
27
23
|
} else if (req.method === constants.METHOD_TYPES.ETH_SEND_USER_OPERATION) {
|
|
28
24
|
const userOpReq = req;
|
|
29
25
|
sender = userOpReq.params.map(p => p.sender).join(",");
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
|
|
5
|
+
// viem's serializeTransaction infers tx type via `if (transaction.type)` which is
|
|
6
|
+
// falsy for type 0 (legacy). Map numeric types to string names so the check passes,
|
|
7
|
+
// and strip undefined/null fields that also break viem's type inference.
|
|
8
|
+
const VIEM_TX_TYPE_NAMES = {
|
|
9
|
+
0: "legacy",
|
|
10
|
+
1: "eip2930",
|
|
11
|
+
2: "eip1559",
|
|
12
|
+
3: "eip4844",
|
|
13
|
+
4: "eip7702"
|
|
14
|
+
};
|
|
15
|
+
const VIEM_QUANTITY_FIELDS = ["gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "maxFeePerBlobGas", "value"];
|
|
16
|
+
function toViemQuantity(value) {
|
|
17
|
+
if (typeof value === "bigint") return value;
|
|
18
|
+
if (typeof value === "number") return BigInt(value);
|
|
19
|
+
if (typeof value === "string" && viem.isHex(value)) return BigInt(value);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function toViemNumber(value) {
|
|
23
|
+
if (typeof value === "number") return value;
|
|
24
|
+
if (typeof value === "bigint") return Number(value);
|
|
25
|
+
if (typeof value === "string" && viem.isHex(value)) return Number(value);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function toViemHex(value) {
|
|
29
|
+
if (typeof value === "string" && viem.isHex(value)) return value;
|
|
30
|
+
if (value instanceof Uint8Array) return viem.toHex(value);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
function toViemAddress(value) {
|
|
34
|
+
if (typeof value === "string" && viem.isAddress(value)) return value;
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function toViemHexArray(value) {
|
|
38
|
+
if (!Array.isArray(value)) return undefined;
|
|
39
|
+
const normalized = [];
|
|
40
|
+
for (const item of value) {
|
|
41
|
+
const hex = toViemHex(item);
|
|
42
|
+
if (!hex) return undefined;
|
|
43
|
+
normalized.push(hex);
|
|
44
|
+
}
|
|
45
|
+
return normalized;
|
|
46
|
+
}
|
|
47
|
+
function toViemAccessList(value) {
|
|
48
|
+
if (!value) return undefined;
|
|
49
|
+
const accessList = [];
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
for (const entry of value) {
|
|
52
|
+
if (Array.isArray(entry)) {
|
|
53
|
+
const [addressLike, storageKeysLike] = entry;
|
|
54
|
+
const address = toViemAddress(addressLike);
|
|
55
|
+
const storageKeys = toViemHexArray(storageKeysLike);
|
|
56
|
+
if (!address || !storageKeys) return undefined;
|
|
57
|
+
accessList.push({
|
|
58
|
+
address,
|
|
59
|
+
storageKeys
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (typeof entry === "object" && entry !== null) {
|
|
64
|
+
const address = toViemAddress(entry.address);
|
|
65
|
+
const storageKeys = toViemHexArray(entry.storageKeys);
|
|
66
|
+
if (!address || !storageKeys) return undefined;
|
|
67
|
+
accessList.push({
|
|
68
|
+
address,
|
|
69
|
+
storageKeys
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return accessList;
|
|
76
|
+
}
|
|
77
|
+
if (typeof value === "object") {
|
|
78
|
+
for (const [addressLike, storageKeysLike] of Object.entries(value)) {
|
|
79
|
+
const address = toViemAddress(addressLike);
|
|
80
|
+
const storageKeys = toViemHexArray(storageKeysLike);
|
|
81
|
+
if (!address || !storageKeys) return undefined;
|
|
82
|
+
accessList.push({
|
|
83
|
+
address,
|
|
84
|
+
storageKeys
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return accessList;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
function toViemAuthorizationList(value) {
|
|
92
|
+
if (!value) return undefined;
|
|
93
|
+
const authorizationList = [];
|
|
94
|
+
for (const authorization of value) {
|
|
95
|
+
const address = toViemAddress(authorization.address);
|
|
96
|
+
const chainId = toViemNumber(authorization.chainId);
|
|
97
|
+
const nonce = toViemNumber(authorization.nonce);
|
|
98
|
+
if (!address || typeof chainId === "undefined" || typeof nonce === "undefined") {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const normalizedAuthorization = {
|
|
102
|
+
address,
|
|
103
|
+
chainId,
|
|
104
|
+
nonce
|
|
105
|
+
};
|
|
106
|
+
const signature = authorization.signature;
|
|
107
|
+
if (typeof signature === "string" && viem.isHex(signature)) {
|
|
108
|
+
const parsed = viem.parseSignature(signature);
|
|
109
|
+
normalizedAuthorization.r = parsed.r;
|
|
110
|
+
normalizedAuthorization.s = parsed.s;
|
|
111
|
+
normalizedAuthorization.yParity = parsed.yParity;
|
|
112
|
+
} else if (typeof signature === "object" && signature !== null) {
|
|
113
|
+
const r = toViemHex(signature.r);
|
|
114
|
+
const s = toViemHex(signature.s);
|
|
115
|
+
const yParity = toViemNumber(signature.yParity);
|
|
116
|
+
const vRaw = signature.v;
|
|
117
|
+
const v = typeof vRaw === "bigint" ? vRaw : typeof vRaw === "number" ? BigInt(vRaw) : typeof vRaw === "string" && viem.isHex(vRaw) ? BigInt(vRaw) : undefined;
|
|
118
|
+
if (r && s) {
|
|
119
|
+
normalizedAuthorization.r = r;
|
|
120
|
+
normalizedAuthorization.s = s;
|
|
121
|
+
}
|
|
122
|
+
if (typeof yParity !== "undefined") {
|
|
123
|
+
normalizedAuthorization.yParity = yParity;
|
|
124
|
+
}
|
|
125
|
+
if (typeof v !== "undefined") {
|
|
126
|
+
normalizedAuthorization.v = v;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
authorizationList.push(normalizedAuthorization);
|
|
130
|
+
}
|
|
131
|
+
return authorizationList;
|
|
132
|
+
}
|
|
133
|
+
function toViemBlobs(value) {
|
|
134
|
+
if (!value) return undefined;
|
|
135
|
+
const blobs = [];
|
|
136
|
+
for (const blob of value) {
|
|
137
|
+
if (typeof blob === "string" || blob instanceof Uint8Array) {
|
|
138
|
+
const normalizedBlob = toViemHex(blob);
|
|
139
|
+
if (!normalizedBlob) return undefined;
|
|
140
|
+
blobs.push(normalizedBlob);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (typeof blob === "object" && blob !== null) {
|
|
144
|
+
const normalizedBlob = toViemHex(blob.data);
|
|
145
|
+
if (!normalizedBlob) return undefined;
|
|
146
|
+
blobs.push(normalizedBlob);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
return blobs;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Prepare transaction params for signing.
|
|
155
|
+
* @param tx - The transaction to prepare.
|
|
156
|
+
* @returns The prepared transaction.
|
|
157
|
+
*/
|
|
158
|
+
function prepareViemTx(tx) {
|
|
159
|
+
var _input$gas;
|
|
160
|
+
const input = tx;
|
|
161
|
+
const prepared = {};
|
|
162
|
+
const txType = typeof input.type === "number" ? VIEM_TX_TYPE_NAMES[input.type] : input.type;
|
|
163
|
+
if (typeof txType === "string") {
|
|
164
|
+
prepared.type = txType;
|
|
165
|
+
}
|
|
166
|
+
// For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper).
|
|
167
|
+
// ref: https://github.com/wevm/viem/blob/b3af510a6e2e45526e2bb10298b7fc1f178a73a3/src/accounts/utils/signTransaction.ts#L56
|
|
168
|
+
if (prepared.type === "eip4844") {
|
|
169
|
+
prepared.sidecars = false;
|
|
170
|
+
}
|
|
171
|
+
const chainId = toViemNumber(input.chainId);
|
|
172
|
+
if (typeof chainId !== "undefined") {
|
|
173
|
+
prepared.chainId = chainId;
|
|
174
|
+
}
|
|
175
|
+
const nonce = toViemNumber(input.nonce);
|
|
176
|
+
if (typeof nonce !== "undefined") {
|
|
177
|
+
prepared.nonce = nonce;
|
|
178
|
+
}
|
|
179
|
+
const gas = toViemQuantity((_input$gas = input.gas) !== null && _input$gas !== void 0 ? _input$gas : input.gasLimit);
|
|
180
|
+
if (typeof gas !== "undefined") {
|
|
181
|
+
prepared.gas = gas;
|
|
182
|
+
}
|
|
183
|
+
for (const field of VIEM_QUANTITY_FIELDS) {
|
|
184
|
+
const value = toViemQuantity(input[field]);
|
|
185
|
+
if (typeof value !== "undefined") {
|
|
186
|
+
prepared[field] = value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (typeof input.to === "string") {
|
|
190
|
+
prepared.to = input.to;
|
|
191
|
+
}
|
|
192
|
+
if (typeof input.data === "string") {
|
|
193
|
+
prepared.data = input.data;
|
|
194
|
+
}
|
|
195
|
+
const accessList = toViemAccessList(input.accessList);
|
|
196
|
+
if (accessList) {
|
|
197
|
+
prepared.accessList = accessList;
|
|
198
|
+
}
|
|
199
|
+
const authorizationList = toViemAuthorizationList(input.authorizationList);
|
|
200
|
+
if (authorizationList) {
|
|
201
|
+
prepared.authorizationList = authorizationList;
|
|
202
|
+
}
|
|
203
|
+
const blobVersionedHashes = toViemHexArray(input.blobVersionedHashes);
|
|
204
|
+
if (blobVersionedHashes) {
|
|
205
|
+
prepared.blobVersionedHashes = blobVersionedHashes;
|
|
206
|
+
}
|
|
207
|
+
const blobs = toViemBlobs(input.blobs);
|
|
208
|
+
if (blobs) {
|
|
209
|
+
prepared.blobs = blobs;
|
|
210
|
+
}
|
|
211
|
+
return prepared;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
exports.prepareViemTx = prepareViemTx;
|