@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
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import { isHexString, addHexPrefix, isValidAddress } from '@ethereumjs/util';
|
|
3
2
|
import { TRANSACTION_TYPES, TransactionStatus, randomId } from '@toruslabs/base-controllers';
|
|
3
|
+
import { add0x } from '@toruslabs/metadata-helpers';
|
|
4
4
|
import { rpcErrors } from '@web3auth/auth';
|
|
5
|
-
import { Interface } from 'ethers';
|
|
6
5
|
import log from 'loglevel';
|
|
6
|
+
import { isHex, decodeFunctionData, isAddress } from 'viem';
|
|
7
7
|
import { erc20Abi, erc721Abi, erc1155Abi } from '../utils/abis.js';
|
|
8
8
|
import { CONTRACT_TYPE_ETH, TRANSACTION_ENVELOPE_TYPES, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC1155, METHOD_TYPES } from '../utils/constants.js';
|
|
9
9
|
|
|
10
|
-
const erc20Interface = new Interface(erc20Abi);
|
|
11
|
-
const erc721Interface = new Interface(erc721Abi);
|
|
12
|
-
const erc1155Interface = new Interface(erc1155Abi);
|
|
13
|
-
|
|
14
10
|
// functions that handle normalizing of that key in txParams
|
|
15
11
|
|
|
16
12
|
const normalizers = {
|
|
17
|
-
from: (from, LowerCase = true) => LowerCase ?
|
|
18
|
-
to: (to, LowerCase = true) => LowerCase ?
|
|
19
|
-
nonce: nonce =>
|
|
20
|
-
customNonceValue: nonce =>
|
|
21
|
-
value: value =>
|
|
22
|
-
data: data =>
|
|
23
|
-
gas: gas =>
|
|
24
|
-
gasPrice: gasPrice =>
|
|
25
|
-
type:
|
|
26
|
-
maxFeePerGas:
|
|
27
|
-
maxPriorityFeePerGas:
|
|
28
|
-
callGasLimit:
|
|
29
|
-
preVerificationGas:
|
|
30
|
-
verificationGasLimit:
|
|
31
|
-
paymasterVerificationGasLimit:
|
|
32
|
-
paymasterPostOpGasLimit:
|
|
13
|
+
from: (from, LowerCase = true) => LowerCase ? add0x(from).toLowerCase() : add0x(from),
|
|
14
|
+
to: (to, LowerCase = true) => LowerCase ? add0x(to).toLowerCase() : add0x(to),
|
|
15
|
+
nonce: nonce => add0x(nonce),
|
|
16
|
+
customNonceValue: nonce => add0x(nonce),
|
|
17
|
+
value: value => add0x(value),
|
|
18
|
+
data: data => add0x(data),
|
|
19
|
+
gas: gas => add0x(gas),
|
|
20
|
+
gasPrice: gasPrice => add0x(gasPrice),
|
|
21
|
+
type: add0x,
|
|
22
|
+
maxFeePerGas: add0x,
|
|
23
|
+
maxPriorityFeePerGas: add0x,
|
|
24
|
+
callGasLimit: add0x,
|
|
25
|
+
preVerificationGas: add0x,
|
|
26
|
+
verificationGasLimit: add0x,
|
|
27
|
+
paymasterVerificationGasLimit: add0x,
|
|
28
|
+
paymasterPostOpGasLimit: add0x,
|
|
33
29
|
authorizationList: authorizationList => authorizationList
|
|
34
30
|
};
|
|
35
31
|
|
|
@@ -65,7 +61,9 @@ function transactionMatchesNetwork(transaction, chainId) {
|
|
|
65
61
|
*/
|
|
66
62
|
function isEIP1559Transaction(transaction) {
|
|
67
63
|
var _transaction$transact, _transaction$transact2;
|
|
68
|
-
|
|
64
|
+
const maxFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas;
|
|
65
|
+
const maxPriorityFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas;
|
|
66
|
+
return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && isHex(add0x(maxFeePerGas)) && isHex(add0x(maxPriorityFeePerGas));
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
/**
|
|
@@ -78,7 +76,7 @@ function isEIP1559Transaction(transaction) {
|
|
|
78
76
|
* EIP1559 fields
|
|
79
77
|
*/
|
|
80
78
|
function isLegacyTransaction(transaction) {
|
|
81
|
-
return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" ||
|
|
79
|
+
return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || isHex(add0x(transaction.transaction.gasPrice)));
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
/**
|
|
@@ -129,7 +127,7 @@ function validateFrom(txParams) {
|
|
|
129
127
|
if (!(typeof txParams.from === "string")) {
|
|
130
128
|
throw rpcErrors.invalidParams(`Invalid "from" address "${txParams.from}": not a string.`);
|
|
131
129
|
}
|
|
132
|
-
if (!
|
|
130
|
+
if (!isAddress(txParams.from)) {
|
|
133
131
|
throw rpcErrors.invalidParams('Invalid "from" address.');
|
|
134
132
|
}
|
|
135
133
|
}
|
|
@@ -144,7 +142,7 @@ function validateRecipient(txParameters) {
|
|
|
144
142
|
} else {
|
|
145
143
|
throw rpcErrors.invalidParams('Invalid "to" address.');
|
|
146
144
|
}
|
|
147
|
-
} else if (txParameters.to !== undefined && !
|
|
145
|
+
} else if (txParameters.to !== undefined && !isAddress(txParameters.to)) {
|
|
148
146
|
throw rpcErrors.invalidParams('Invalid "to" address.');
|
|
149
147
|
}
|
|
150
148
|
return txParameters;
|
|
@@ -213,10 +211,10 @@ function validateTxParameters(txParams, eip1559Compatibility = true) {
|
|
|
213
211
|
if (typeof authorization !== "object" || authorization === null) {
|
|
214
212
|
throw rpcErrors.invalidParams(`Invalid transaction params: ${key} is not an object. got: (${authorization})`);
|
|
215
213
|
}
|
|
216
|
-
if (typeof authorization.address !== "string" || !
|
|
214
|
+
if (typeof authorization.address !== "string" || !isAddress(authorization.address)) {
|
|
217
215
|
throw rpcErrors.invalidParams(`Invalid transaction params: authorization.address is not a valid address. got: (${authorization.address})`);
|
|
218
216
|
}
|
|
219
|
-
if (typeof authorization.chainId !== "string" || !
|
|
217
|
+
if (typeof authorization.chainId !== "string" || !isHex(add0x(authorization.chainId))) {
|
|
220
218
|
throw rpcErrors.invalidParams(`Invalid transaction params: authorization.chainId is not a valid hex string. got: (${authorization.chainId})`);
|
|
221
219
|
}
|
|
222
220
|
});
|
|
@@ -247,36 +245,42 @@ function getFinalStates() {
|
|
|
247
245
|
}
|
|
248
246
|
function parseStandardTokenTransactionData(data) {
|
|
249
247
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
var _txDesc$args;
|
|
249
|
+
const txDesc = decodeFunctionData({
|
|
250
|
+
abi: erc20Abi,
|
|
251
|
+
data: data
|
|
252
252
|
});
|
|
253
253
|
if (txDesc) return {
|
|
254
|
-
name: txDesc.
|
|
255
|
-
methodParams: txDesc.args
|
|
254
|
+
name: txDesc.functionName,
|
|
255
|
+
methodParams: [...((_txDesc$args = txDesc.args) !== null && _txDesc$args !== void 0 ? _txDesc$args : [])],
|
|
256
256
|
type: CONTRACT_TYPE_ERC20
|
|
257
257
|
};
|
|
258
258
|
} catch {
|
|
259
259
|
// ignore and next try to parse with erc721 ABI
|
|
260
260
|
}
|
|
261
261
|
try {
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
var _txDesc$args2;
|
|
263
|
+
const txDesc = decodeFunctionData({
|
|
264
|
+
abi: erc721Abi,
|
|
265
|
+
data: data
|
|
264
266
|
});
|
|
265
267
|
if (txDesc) return {
|
|
266
|
-
name: txDesc.
|
|
267
|
-
methodParams: txDesc.args
|
|
268
|
+
name: txDesc.functionName,
|
|
269
|
+
methodParams: [...((_txDesc$args2 = txDesc.args) !== null && _txDesc$args2 !== void 0 ? _txDesc$args2 : [])],
|
|
268
270
|
type: CONTRACT_TYPE_ERC721
|
|
269
271
|
};
|
|
270
272
|
} catch {
|
|
271
273
|
// ignore and next try to parse with erc1155 ABI
|
|
272
274
|
}
|
|
273
275
|
try {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
var _txDesc$args3;
|
|
277
|
+
const txDesc = decodeFunctionData({
|
|
278
|
+
abi: erc1155Abi,
|
|
279
|
+
data: data
|
|
276
280
|
});
|
|
277
281
|
if (txDesc) return {
|
|
278
|
-
name: txDesc.
|
|
279
|
-
methodParams: txDesc.args
|
|
282
|
+
name: txDesc.functionName,
|
|
283
|
+
methodParams: [...((_txDesc$args3 = txDesc.args) !== null && _txDesc$args3 !== void 0 ? _txDesc$args3 : [])],
|
|
280
284
|
type: CONTRACT_TYPE_ERC1155
|
|
281
285
|
};
|
|
282
286
|
} catch {
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -11,9 +11,6 @@ export { PersonalMessageController } from './Message/PersonalMessageController.j
|
|
|
11
11
|
export { SwitchChainController } from './Message/SwitchChainController.js';
|
|
12
12
|
export { TypedMessageController } from './Message/TypedMessageController.js';
|
|
13
13
|
export { normalizeMessageData, validateAddChainData, validateAddress, validateSignMessageData, validateSwitchChainData, validateTypedSignMessageDataV4 } from './Message/utils.js';
|
|
14
|
-
export { createAAMiddleware, createEip5792Middleware, createEip7702Middleware, createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
|
|
15
|
-
export { createChainIdMiddleware, createJsonRpcClient, createProviderConfigMiddleware } from './Network/createJsonRpcClient.js';
|
|
16
|
-
export { NetworkController } from './Network/NetworkController.js';
|
|
17
14
|
export { NftHandler } from './Nfts/NftHandler.js';
|
|
18
15
|
export { NftsController } from './Nfts/NftsController.js';
|
|
19
16
|
export { PreferencesController } from './Preferences/PreferencesController.js';
|
|
@@ -35,11 +32,15 @@ export { DUMMY_AUTHORIZATION_SIGNATURE, EIP_7702_METHODS, EIP_7702_PREFIX, EIP_7
|
|
|
35
32
|
export { BNToHex, GAS_LIMITS, addEtherscanTransactions, bnLessThan, formatDate, formatPastTx, formatTime, getChainType, getEthTxStatus, getEtherScanHashLink, getIpfsEndpoint, hexToBn, isAddressByChainId, sanitizeNftMetdataUrl, toChecksumAddressByChainId } from './utils/helpers.js';
|
|
36
33
|
export { TRANSACTION_CATEGORY_EIP7702 } from './utils/interfaces.js';
|
|
37
34
|
export { BiconomySmartAccount } from './AccountAbstraction/smartAccounts/BiconomySmartAccount.js';
|
|
35
|
+
export { CacheStrategy, blockTagParamIndex, cacheIdentifierForRequest, cacheTypeForMethod } from './Network/cacheIdentifier.js';
|
|
38
36
|
export { KernelSmartAccount } from './AccountAbstraction/smartAccounts/KernelSmartAccount.js';
|
|
39
37
|
export { MetamaskSmartAccount } from './AccountAbstraction/smartAccounts/MetamaskSmartAccount.js';
|
|
38
|
+
export { NetworkController } from './Network/NetworkController.js';
|
|
40
39
|
export { NexusSmartAccount } from './AccountAbstraction/smartAccounts/NexusSmartAccount.js';
|
|
41
40
|
export { SafeSmartAccount } from './AccountAbstraction/smartAccounts/SafeSmartAccount.js';
|
|
42
41
|
export { TrustSmartAccount } from './AccountAbstraction/smartAccounts/TrustSmartAccount.js';
|
|
42
|
+
export { createAAMiddleware, createEip5792Middleware, createEip7702Middleware, createEthereumMiddleware, createGetAccountsMiddleware, createGetProviderStateMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
|
|
43
|
+
export { createChainIdMiddleware, createJsonRpcClient, createProviderConfigMiddleware } from './Network/createJsonRpcClient.js';
|
|
43
44
|
export { generateBatchId, processMultipleTransactions, processSingleTransaction, validateSendCallsParams, walletSendCalls } from './Eip5792/walletSendCalls.js';
|
|
44
45
|
export { mapTransactionStatusToEip5792Status, walletGetCallsStatus } from './Eip5792/walletGetCallsStatus.js';
|
|
45
46
|
export { walletGetCapabilities } from './Eip5792/walletGetCapabilities.js';
|
|
@@ -7,6 +7,7 @@ const erc20Abi = [{
|
|
|
7
7
|
type: "string"
|
|
8
8
|
}],
|
|
9
9
|
payable: false,
|
|
10
|
+
stateMutability: "view",
|
|
10
11
|
type: "function"
|
|
11
12
|
}, {
|
|
12
13
|
constant: false,
|
|
@@ -23,6 +24,7 @@ const erc20Abi = [{
|
|
|
23
24
|
type: "bool"
|
|
24
25
|
}],
|
|
25
26
|
payable: false,
|
|
27
|
+
stateMutability: "nonpayable",
|
|
26
28
|
type: "function"
|
|
27
29
|
}, {
|
|
28
30
|
constant: true,
|
|
@@ -33,6 +35,7 @@ const erc20Abi = [{
|
|
|
33
35
|
type: "uint256"
|
|
34
36
|
}],
|
|
35
37
|
payable: false,
|
|
38
|
+
stateMutability: "view",
|
|
36
39
|
type: "function"
|
|
37
40
|
}, {
|
|
38
41
|
constant: false,
|
|
@@ -52,6 +55,7 @@ const erc20Abi = [{
|
|
|
52
55
|
type: "bool"
|
|
53
56
|
}],
|
|
54
57
|
payable: false,
|
|
58
|
+
stateMutability: "nonpayable",
|
|
55
59
|
type: "function"
|
|
56
60
|
}, {
|
|
57
61
|
constant: true,
|
|
@@ -62,6 +66,7 @@ const erc20Abi = [{
|
|
|
62
66
|
type: "uint256"
|
|
63
67
|
}],
|
|
64
68
|
payable: false,
|
|
69
|
+
stateMutability: "view",
|
|
65
70
|
type: "function"
|
|
66
71
|
}, {
|
|
67
72
|
constant: true,
|
|
@@ -75,6 +80,7 @@ const erc20Abi = [{
|
|
|
75
80
|
type: "uint256"
|
|
76
81
|
}],
|
|
77
82
|
payable: false,
|
|
83
|
+
stateMutability: "view",
|
|
78
84
|
type: "function"
|
|
79
85
|
}, {
|
|
80
86
|
constant: true,
|
|
@@ -85,6 +91,7 @@ const erc20Abi = [{
|
|
|
85
91
|
type: "string"
|
|
86
92
|
}],
|
|
87
93
|
payable: false,
|
|
94
|
+
stateMutability: "view",
|
|
88
95
|
type: "function"
|
|
89
96
|
}, {
|
|
90
97
|
constant: false,
|
|
@@ -101,6 +108,7 @@ const erc20Abi = [{
|
|
|
101
108
|
type: "bool"
|
|
102
109
|
}],
|
|
103
110
|
payable: false,
|
|
111
|
+
stateMutability: "nonpayable",
|
|
104
112
|
type: "function"
|
|
105
113
|
}, {
|
|
106
114
|
constant: false,
|
|
@@ -120,6 +128,7 @@ const erc20Abi = [{
|
|
|
120
128
|
type: "bool"
|
|
121
129
|
}],
|
|
122
130
|
payable: false,
|
|
131
|
+
stateMutability: "nonpayable",
|
|
123
132
|
type: "function"
|
|
124
133
|
}, {
|
|
125
134
|
constant: true,
|
|
@@ -136,6 +145,7 @@ const erc20Abi = [{
|
|
|
136
145
|
type: "uint256"
|
|
137
146
|
}],
|
|
138
147
|
payable: false,
|
|
148
|
+
stateMutability: "view",
|
|
139
149
|
type: "function"
|
|
140
150
|
}, {
|
|
141
151
|
inputs: [{
|
|
@@ -151,9 +161,11 @@ const erc20Abi = [{
|
|
|
151
161
|
name: "_tokenSymbol",
|
|
152
162
|
type: "string"
|
|
153
163
|
}],
|
|
164
|
+
stateMutability: "nonpayable",
|
|
154
165
|
type: "constructor"
|
|
155
166
|
}, {
|
|
156
167
|
payable: false,
|
|
168
|
+
stateMutability: "nonpayable",
|
|
157
169
|
type: "fallback"
|
|
158
170
|
}];
|
|
159
171
|
const erc721Abi = [{
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
|
|
2
2
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
3
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
-
import {
|
|
4
|
+
import { remove0x } from '@toruslabs/metadata-helpers';
|
|
5
5
|
import { BigNumber } from 'bignumber.js';
|
|
6
|
-
import BN from 'bn.js';
|
|
7
6
|
|
|
8
7
|
const _excluded = ["aBase", "bBase"],
|
|
9
8
|
_excluded2 = ["aBase", "bBase"],
|
|
@@ -15,7 +14,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber("1000000000");
|
|
|
15
14
|
const BIG_NUMBER_ETH_MULTIPLIER = new BigNumber("1");
|
|
16
15
|
// Setter Maps
|
|
17
16
|
const toBigNumber = {
|
|
18
|
-
hex: n => new BigNumber(
|
|
17
|
+
hex: n => new BigNumber(remove0x(n), 16),
|
|
19
18
|
dec: n => new BigNumber(String(n), 10),
|
|
20
19
|
BN: n => new BigNumber(n.toString(16), 16)
|
|
21
20
|
};
|
|
@@ -32,7 +31,7 @@ const toSpecifiedDenomination = {
|
|
|
32
31
|
const baseChange = {
|
|
33
32
|
hex: n => n.toString(16),
|
|
34
33
|
dec: n => new BigNumber(n).toString(10),
|
|
35
|
-
BN: n => new
|
|
34
|
+
BN: n => new BigNumber(n.toString(16))
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
// Utility function for checking base types
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import { addHexPrefix, stripHexPrefix, isValidAddress, toChecksumAddress } from '@ethereumjs/util';
|
|
3
2
|
import { TransactionStatus, formatSmallNumbers, significantDigits, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, addressSlicer } from '@toruslabs/base-controllers';
|
|
3
|
+
import { add0x, remove0x } from '@toruslabs/metadata-helpers';
|
|
4
4
|
import { BigNumber } from 'bignumber.js';
|
|
5
5
|
import log from 'loglevel';
|
|
6
|
+
import { toHex, isAddress, getAddress } from 'viem';
|
|
6
7
|
import { determineTransactionType } from '../Transaction/TransactionUtils.js';
|
|
7
8
|
import { SUPPORTED_NETWORKS, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC20, MAINNET_CHAIN_ID, TEST_CHAINS, METHOD_TYPES, CONTRACT_TYPE_ETH } from './constants.js';
|
|
8
9
|
|
|
9
10
|
function hexToBn(hex) {
|
|
10
|
-
return new BigNumber(
|
|
11
|
+
return new BigNumber(remove0x(hex), 16);
|
|
11
12
|
}
|
|
12
13
|
function BNToHex(bn) {
|
|
13
|
-
return
|
|
14
|
+
return add0x(bn.toString(16));
|
|
14
15
|
}
|
|
15
16
|
function getEtherScanHashLink(txHash, chainId) {
|
|
16
17
|
if (!SUPPORTED_NETWORKS[chainId]) return "";
|
|
@@ -93,18 +94,18 @@ function formatTime(time) {
|
|
|
93
94
|
}
|
|
94
95
|
function isAddressByChainId(address, _chainId) {
|
|
95
96
|
// TOOD: add rsk network checks.
|
|
96
|
-
return
|
|
97
|
+
return isAddress(address);
|
|
97
98
|
}
|
|
98
99
|
function toChecksumAddressByChainId(address, chainId) {
|
|
99
100
|
// TOOD: add rsk network checks.
|
|
100
101
|
if (!isAddressByChainId(address)) return address;
|
|
101
|
-
return
|
|
102
|
+
return getAddress(address);
|
|
102
103
|
}
|
|
103
104
|
const GAS_LIMITS = {
|
|
104
105
|
// maximum gasLimit of a simple send
|
|
105
|
-
SIMPLE:
|
|
106
|
+
SIMPLE: toHex(21000),
|
|
106
107
|
// a base estimate for token transfers.
|
|
107
|
-
BASE_TOKEN_ESTIMATE:
|
|
108
|
+
BASE_TOKEN_ESTIMATE: toHex(100000)
|
|
108
109
|
};
|
|
109
110
|
function bnLessThan(a, b) {
|
|
110
111
|
if (a === null || a === undefined || b === null || b === undefined) {
|
|
@@ -25,4 +25,68 @@ const TRANSACTION_CATEGORY_EIP7702 = {
|
|
|
25
25
|
* Type Def for function to query the deployment bytecode of an address. (eth_getCode)
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A [[HexString]] whose length is even, which ensures it is a valid
|
|
30
|
+
* representation of binary data.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An object that can be used to represent binary data.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A BLOb object that can be passed for [[link-eip-4844]]
|
|
39
|
+
* transactions.
|
|
40
|
+
*
|
|
41
|
+
* It may have had its commitment and proof already provided
|
|
42
|
+
* or rely on an attached [[KzgLibrary]] to compute them.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A KZG Library with the necessary functions to compute
|
|
47
|
+
* BLOb commitments and proofs.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A KZG Library with any of the various API configurations.
|
|
52
|
+
* As the library is still experimental and the API is not
|
|
53
|
+
* stable, depending on the version used the method names and
|
|
54
|
+
* signatures are still in flux.
|
|
55
|
+
*
|
|
56
|
+
* This allows any of the versions to be passed into Transaction
|
|
57
|
+
* while providing a stable external API.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Any type that can be used where a numeric value is needed.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Any type that can be used where a big number is needed.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A SignatureLike
|
|
70
|
+
*
|
|
71
|
+
* @_docloc: api/crypto:Signing
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A **TransactionLike** is an object which is appropriate as a loose
|
|
76
|
+
* input for many operations which will populate missing properties of
|
|
77
|
+
* a transaction.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A single [[AccessList]] entry of storage keys (slots) for an address.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* An ordered collection of [[AccessList]] entries.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Any ethers-supported access list structure.
|
|
90
|
+
*/
|
|
91
|
+
|
|
28
92
|
export { TRANSACTION_CATEGORY_EIP7702 };
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createTxFromRLP } from '@ethereumjs/tx';
|
|
3
|
-
import { hexToBytes, addHexPrefix, bytesToHex } from '@ethereumjs/util';
|
|
1
|
+
import { add0x } from '@toruslabs/metadata-helpers';
|
|
4
2
|
import log from 'loglevel';
|
|
3
|
+
import { recoverTransactionAddress, keccak256 } from 'viem';
|
|
5
4
|
import { METHOD_TYPES } from './constants.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Transaction decoder for analytics.
|
|
9
8
|
* Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
|
|
10
9
|
*/
|
|
11
|
-
const transactionDecoder = (req, chainId) => {
|
|
10
|
+
const transactionDecoder = async (req, chainId) => {
|
|
12
11
|
let sender = "";
|
|
13
12
|
let txHash = "";
|
|
14
13
|
try {
|
|
15
14
|
if (req.method === METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
|
|
16
15
|
const rawTx = req.params[0];
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
chainId
|
|
21
|
-
}, Mainnet)
|
|
16
|
+
const normalizedRawTx = add0x(rawTx);
|
|
17
|
+
sender = await recoverTransactionAddress({
|
|
18
|
+
serializedTransaction: normalizedRawTx
|
|
22
19
|
});
|
|
23
|
-
|
|
24
|
-
txHash = bytesToHex(tx.hash());
|
|
20
|
+
txHash = keccak256(normalizedRawTx);
|
|
25
21
|
} else if (req.method === METHOD_TYPES.ETH_SEND_USER_OPERATION) {
|
|
26
22
|
const userOpReq = req;
|
|
27
23
|
sender = userOpReq.params.map(p => p.sender).join(",");
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { isHex, parseSignature, isAddress, toHex } from 'viem';
|
|
2
|
+
|
|
3
|
+
// viem's serializeTransaction infers tx type via `if (transaction.type)` which is
|
|
4
|
+
// falsy for type 0 (legacy). Map numeric types to string names so the check passes,
|
|
5
|
+
// and strip undefined/null fields that also break viem's type inference.
|
|
6
|
+
const VIEM_TX_TYPE_NAMES = {
|
|
7
|
+
0: "legacy",
|
|
8
|
+
1: "eip2930",
|
|
9
|
+
2: "eip1559",
|
|
10
|
+
3: "eip4844",
|
|
11
|
+
4: "eip7702"
|
|
12
|
+
};
|
|
13
|
+
const VIEM_QUANTITY_FIELDS = ["gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "maxFeePerBlobGas", "value"];
|
|
14
|
+
function toViemQuantity(value) {
|
|
15
|
+
if (typeof value === "bigint") return value;
|
|
16
|
+
if (typeof value === "number") return BigInt(value);
|
|
17
|
+
if (typeof value === "string" && isHex(value)) return BigInt(value);
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
function toViemNumber(value) {
|
|
21
|
+
if (typeof value === "number") return value;
|
|
22
|
+
if (typeof value === "bigint") return Number(value);
|
|
23
|
+
if (typeof value === "string" && isHex(value)) return Number(value);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
function toViemHex(value) {
|
|
27
|
+
if (typeof value === "string" && isHex(value)) return value;
|
|
28
|
+
if (value instanceof Uint8Array) return toHex(value);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function toViemAddress(value) {
|
|
32
|
+
if (typeof value === "string" && isAddress(value)) return value;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function toViemHexArray(value) {
|
|
36
|
+
if (!Array.isArray(value)) return undefined;
|
|
37
|
+
const normalized = [];
|
|
38
|
+
for (const item of value) {
|
|
39
|
+
const hex = toViemHex(item);
|
|
40
|
+
if (!hex) return undefined;
|
|
41
|
+
normalized.push(hex);
|
|
42
|
+
}
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function toViemAccessList(value) {
|
|
46
|
+
if (!value) return undefined;
|
|
47
|
+
const accessList = [];
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
for (const entry of value) {
|
|
50
|
+
if (Array.isArray(entry)) {
|
|
51
|
+
const [addressLike, storageKeysLike] = entry;
|
|
52
|
+
const address = toViemAddress(addressLike);
|
|
53
|
+
const storageKeys = toViemHexArray(storageKeysLike);
|
|
54
|
+
if (!address || !storageKeys) return undefined;
|
|
55
|
+
accessList.push({
|
|
56
|
+
address,
|
|
57
|
+
storageKeys
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (typeof entry === "object" && entry !== null) {
|
|
62
|
+
const address = toViemAddress(entry.address);
|
|
63
|
+
const storageKeys = toViemHexArray(entry.storageKeys);
|
|
64
|
+
if (!address || !storageKeys) return undefined;
|
|
65
|
+
accessList.push({
|
|
66
|
+
address,
|
|
67
|
+
storageKeys
|
|
68
|
+
});
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return accessList;
|
|
74
|
+
}
|
|
75
|
+
if (typeof value === "object") {
|
|
76
|
+
for (const [addressLike, storageKeysLike] of Object.entries(value)) {
|
|
77
|
+
const address = toViemAddress(addressLike);
|
|
78
|
+
const storageKeys = toViemHexArray(storageKeysLike);
|
|
79
|
+
if (!address || !storageKeys) return undefined;
|
|
80
|
+
accessList.push({
|
|
81
|
+
address,
|
|
82
|
+
storageKeys
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return accessList;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
function toViemAuthorizationList(value) {
|
|
90
|
+
if (!value) return undefined;
|
|
91
|
+
const authorizationList = [];
|
|
92
|
+
for (const authorization of value) {
|
|
93
|
+
const address = toViemAddress(authorization.address);
|
|
94
|
+
const chainId = toViemNumber(authorization.chainId);
|
|
95
|
+
const nonce = toViemNumber(authorization.nonce);
|
|
96
|
+
if (!address || typeof chainId === "undefined" || typeof nonce === "undefined") {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const normalizedAuthorization = {
|
|
100
|
+
address,
|
|
101
|
+
chainId,
|
|
102
|
+
nonce
|
|
103
|
+
};
|
|
104
|
+
const signature = authorization.signature;
|
|
105
|
+
if (typeof signature === "string" && isHex(signature)) {
|
|
106
|
+
const parsed = parseSignature(signature);
|
|
107
|
+
normalizedAuthorization.r = parsed.r;
|
|
108
|
+
normalizedAuthorization.s = parsed.s;
|
|
109
|
+
normalizedAuthorization.yParity = parsed.yParity;
|
|
110
|
+
} else if (typeof signature === "object" && signature !== null) {
|
|
111
|
+
const r = toViemHex(signature.r);
|
|
112
|
+
const s = toViemHex(signature.s);
|
|
113
|
+
const yParity = toViemNumber(signature.yParity);
|
|
114
|
+
const vRaw = signature.v;
|
|
115
|
+
const v = typeof vRaw === "bigint" ? vRaw : typeof vRaw === "number" ? BigInt(vRaw) : typeof vRaw === "string" && isHex(vRaw) ? BigInt(vRaw) : undefined;
|
|
116
|
+
if (r && s) {
|
|
117
|
+
normalizedAuthorization.r = r;
|
|
118
|
+
normalizedAuthorization.s = s;
|
|
119
|
+
}
|
|
120
|
+
if (typeof yParity !== "undefined") {
|
|
121
|
+
normalizedAuthorization.yParity = yParity;
|
|
122
|
+
}
|
|
123
|
+
if (typeof v !== "undefined") {
|
|
124
|
+
normalizedAuthorization.v = v;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
authorizationList.push(normalizedAuthorization);
|
|
128
|
+
}
|
|
129
|
+
return authorizationList;
|
|
130
|
+
}
|
|
131
|
+
function toViemBlobs(value) {
|
|
132
|
+
if (!value) return undefined;
|
|
133
|
+
const blobs = [];
|
|
134
|
+
for (const blob of value) {
|
|
135
|
+
if (typeof blob === "string" || blob instanceof Uint8Array) {
|
|
136
|
+
const normalizedBlob = toViemHex(blob);
|
|
137
|
+
if (!normalizedBlob) return undefined;
|
|
138
|
+
blobs.push(normalizedBlob);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (typeof blob === "object" && blob !== null) {
|
|
142
|
+
const normalizedBlob = toViemHex(blob.data);
|
|
143
|
+
if (!normalizedBlob) return undefined;
|
|
144
|
+
blobs.push(normalizedBlob);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
return blobs;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Prepare transaction params for signing.
|
|
154
|
+
* @param tx - The transaction to prepare.
|
|
155
|
+
* @returns The prepared transaction.
|
|
156
|
+
*/
|
|
157
|
+
function prepareViemTx(tx) {
|
|
158
|
+
var _input$gas;
|
|
159
|
+
const input = tx;
|
|
160
|
+
const prepared = {};
|
|
161
|
+
const txType = typeof input.type === "number" ? VIEM_TX_TYPE_NAMES[input.type] : input.type;
|
|
162
|
+
if (typeof txType === "string") {
|
|
163
|
+
prepared.type = txType;
|
|
164
|
+
}
|
|
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
|
+
export { prepareViemTx };
|