@deserialize/multi-vm-wallet 1.4.12 → 1.5.1
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/.claude/settings.local.json +7 -1
- package/BUILD_OPTIMIZATION_PLAN.md +640 -0
- package/BUILD_RESULTS.md +282 -0
- package/BUN_MIGRATION.md +415 -0
- package/CHANGELOG_SECURITY.md +573 -0
- package/IMPLEMENTATION_SUMMARY.md +494 -0
- package/SECURITY_AUDIT.md +1124 -0
- package/bun.lock +553 -0
- package/dist/IChainWallet.js +0 -5
- package/dist/bip32Old.js +0 -885
- package/dist/bip32Small.js +0 -79
- package/dist/bipTest.js +0 -362
- package/dist/constant.js +0 -17
- package/dist/english.js +0 -1
- package/dist/evm/aa-service/index.d.ts +0 -5
- package/dist/evm/aa-service/index.js +0 -14
- package/dist/evm/aa-service/lib/account-adapter.d.ts +0 -22
- package/dist/evm/aa-service/lib/account-adapter.js +0 -24
- package/dist/evm/aa-service/lib/kernel-account.d.ts +0 -30
- package/dist/evm/aa-service/lib/kernel-account.js +2 -67
- package/dist/evm/aa-service/lib/kernel-modules.d.ts +0 -177
- package/dist/evm/aa-service/lib/kernel-modules.js +4 -202
- package/dist/evm/aa-service/lib/session-keys.d.ts +0 -118
- package/dist/evm/aa-service/lib/session-keys.js +7 -151
- package/dist/evm/aa-service/lib/type.d.ts +0 -55
- package/dist/evm/aa-service/lib/type.js +0 -10
- package/dist/evm/aa-service/services/account-abstraction.d.ts +0 -426
- package/dist/evm/aa-service/services/account-abstraction.js +0 -461
- package/dist/evm/aa-service/services/bundler.d.ts +0 -6
- package/dist/evm/aa-service/services/bundler.js +0 -54
- package/dist/evm/evm.d.ts +10 -67
- package/dist/evm/evm.js +339 -102
- package/dist/evm/index.js +0 -3
- package/dist/evm/script.js +3 -17
- package/dist/evm/smartWallet.d.ts +0 -173
- package/dist/evm/smartWallet.js +0 -206
- package/dist/evm/smartWallet.types.d.ts +0 -6
- package/dist/evm/smartWallet.types.js +0 -8
- package/dist/evm/transaction.utils.d.ts +0 -242
- package/dist/evm/transaction.utils.js +4 -320
- package/dist/evm/transactionParsing.d.ts +0 -11
- package/dist/evm/transactionParsing.js +28 -147
- package/dist/evm/utils.d.ts +0 -46
- package/dist/evm/utils.js +1 -57
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers/index.js +8 -44
- package/dist/helpers/routeScan.js +0 -1
- package/dist/index.js +0 -1
- package/dist/old.js +0 -884
- package/dist/price.js +0 -1
- package/dist/price.types.js +0 -2
- package/dist/rate-limiter.d.ts +28 -0
- package/dist/rate-limiter.js +95 -0
- package/dist/retry-logic.d.ts +14 -0
- package/dist/retry-logic.js +120 -0
- package/dist/savings/index.d.ts +1 -0
- package/dist/savings/index.js +16 -2
- package/dist/savings/saving-manager.d.ts +46 -0
- package/dist/savings/saving-manager.js +176 -0
- package/dist/savings/savings-operations.d.ts +39 -0
- package/dist/savings/savings-operations.js +141 -0
- package/dist/savings/smart-savings.d.ts +0 -63
- package/dist/savings/smart-savings.js +0 -78
- package/dist/savings/types.d.ts +0 -69
- package/dist/savings/types.js +0 -7
- package/dist/savings/validation.d.ts +9 -0
- package/dist/savings/validation.js +85 -0
- package/dist/svm/constant.js +0 -1
- package/dist/svm/index.js +0 -1
- package/dist/svm/svm.d.ts +7 -13
- package/dist/svm/svm.js +262 -46
- package/dist/svm/transactionParsing.d.ts +0 -7
- package/dist/svm/transactionParsing.js +3 -41
- package/dist/svm/transactionSender.js +0 -9
- package/dist/svm/utils.d.ts +0 -12
- package/dist/svm/utils.js +9 -60
- package/dist/test.d.ts +0 -4
- package/dist/test.js +15 -95
- package/dist/transaction-utils.d.ts +38 -0
- package/dist/transaction-utils.js +168 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.js +0 -1
- package/dist/utils.js +0 -1
- package/dist/vm-validation.d.ts +11 -0
- package/dist/vm-validation.js +151 -0
- package/dist/vm.d.ts +14 -16
- package/dist/vm.js +64 -53
- package/dist/walletBip32.d.ts +2 -0
- package/dist/walletBip32.js +31 -66
- package/package.json +9 -4
- package/test-discovery.ts +235 -0
- package/test-pocket-discovery.ts +84 -0
- package/tsconfig.json +18 -11
- package/tsconfig.prod.json +10 -0
- package/utils/IChainWallet.ts +2 -0
- package/utils/evm/evm.ts +560 -39
- package/utils/rate-limiter.ts +179 -0
- package/utils/retry-logic.ts +271 -0
- package/utils/savings/EXAMPLES.md +883 -0
- package/utils/savings/SECURITY.md +731 -0
- package/utils/savings/index.ts +1 -1
- package/utils/savings/saving-manager.ts +656 -0
- package/utils/savings/savings-operations.ts +509 -0
- package/utils/savings/validation.ts +187 -0
- package/utils/svm/svm.ts +467 -20
- package/utils/test.ts +26 -3
- package/utils/transaction-utils.ts +394 -0
- package/utils/types.ts +100 -0
- package/utils/vm-validation.ts +280 -0
- package/utils/vm.ts +202 -24
- package/utils/walletBip32.ts +63 -3
- package/dist/IChainWallet.js.map +0 -1
- package/dist/bip32.d.ts +0 -9
- package/dist/bip32.js +0 -172
- package/dist/bip32.js.map +0 -1
- package/dist/bip32Old.js.map +0 -1
- package/dist/bip32Small.js.map +0 -1
- package/dist/bipTest.js.map +0 -1
- package/dist/constant.js.map +0 -1
- package/dist/english.js.map +0 -1
- package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +0 -20
- package/dist/evm/SMART_WALLET_EXAMPLES.js +0 -451
- package/dist/evm/SMART_WALLET_EXAMPLES.js.map +0 -1
- package/dist/evm/aa-service/index.js.map +0 -1
- package/dist/evm/aa-service/lib/account-adapter.js.map +0 -1
- package/dist/evm/aa-service/lib/kernel-account.js.map +0 -1
- package/dist/evm/aa-service/lib/kernel-modules.js.map +0 -1
- package/dist/evm/aa-service/lib/session-keys.js.map +0 -1
- package/dist/evm/aa-service/lib/type.js.map +0 -1
- package/dist/evm/aa-service/services/account-abstraction.js.map +0 -1
- package/dist/evm/aa-service/services/bundler.js.map +0 -1
- package/dist/evm/evm.js.map +0 -1
- package/dist/evm/index.js.map +0 -1
- package/dist/evm/script.js.map +0 -1
- package/dist/evm/smartWallet.js.map +0 -1
- package/dist/evm/smartWallet.types.js.map +0 -1
- package/dist/evm/transaction.utils.js.map +0 -1
- package/dist/evm/transactionParsing.js.map +0 -1
- package/dist/evm/utils.js.map +0 -1
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/routeScan.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/old.js.map +0 -1
- package/dist/price.js.map +0 -1
- package/dist/price.types.js.map +0 -1
- package/dist/privacy/artifact-manager.d.ts +0 -117
- package/dist/privacy/artifact-manager.js +0 -251
- package/dist/privacy/artifact-manager.js.map +0 -1
- package/dist/privacy/broadcaster-client.d.ts +0 -166
- package/dist/privacy/broadcaster-client.js +0 -261
- package/dist/privacy/broadcaster-client.js.map +0 -1
- package/dist/privacy/index.d.ts +0 -34
- package/dist/privacy/index.js +0 -56
- package/dist/privacy/index.js.map +0 -1
- package/dist/privacy/network-config.d.ts +0 -57
- package/dist/privacy/network-config.js +0 -118
- package/dist/privacy/network-config.js.map +0 -1
- package/dist/privacy/poi-helper.d.ts +0 -161
- package/dist/privacy/poi-helper.js +0 -249
- package/dist/privacy/poi-helper.js.map +0 -1
- package/dist/privacy/railgun-engine.d.ts +0 -135
- package/dist/privacy/railgun-engine.js +0 -205
- package/dist/privacy/railgun-engine.js.map +0 -1
- package/dist/privacy/railgun-privacy-wallet.d.ts +0 -288
- package/dist/privacy/railgun-privacy-wallet.js +0 -539
- package/dist/privacy/railgun-privacy-wallet.js.map +0 -1
- package/dist/privacy/types.d.ts +0 -229
- package/dist/privacy/types.js +0 -26
- package/dist/privacy/types.js.map +0 -1
- package/dist/savings/index.js.map +0 -1
- package/dist/savings/saving-actions.d.ts +0 -0
- package/dist/savings/saving-actions.js +0 -78
- package/dist/savings/saving-actions.js.map +0 -1
- package/dist/savings/savings-manager.d.ts +0 -126
- package/dist/savings/savings-manager.js +0 -234
- package/dist/savings/savings-manager.js.map +0 -1
- package/dist/savings/smart-savings.js.map +0 -1
- package/dist/savings/types.js.map +0 -1
- package/dist/svm/constant.js.map +0 -1
- package/dist/svm/index.js.map +0 -1
- package/dist/svm/svm.js.map +0 -1
- package/dist/svm/transactionParsing.js.map +0 -1
- package/dist/svm/transactionSender.js.map +0 -1
- package/dist/svm/utils.js.map +0 -1
- package/dist/test.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/dist/vm.js.map +0 -1
- package/dist/walletBip32.js.map +0 -1
- package/utils/savings/saving-actions.ts +0 -92
- package/utils/savings/savings-manager.ts +0 -271
|
@@ -15,34 +15,21 @@ exports.determineTransactionAssetType = determineTransactionAssetType;
|
|
|
15
15
|
exports.parseTypedDataMessage = parseTypedDataMessage;
|
|
16
16
|
exports.isEqualCaseInsensitive = isEqualCaseInsensitive;
|
|
17
17
|
const viem_1 = require("viem");
|
|
18
|
-
// ============================================================================
|
|
19
|
-
// Types & Constants
|
|
20
|
-
// ============================================================================
|
|
21
|
-
/**
|
|
22
|
-
* Enum representing different transaction types
|
|
23
|
-
*/
|
|
24
18
|
var TransactionType;
|
|
25
19
|
(function (TransactionType) {
|
|
26
|
-
// Token operations
|
|
27
20
|
TransactionType["tokenMethodApprove"] = "approve";
|
|
28
21
|
TransactionType["tokenMethodSetApprovalForAll"] = "setApprovalForAll";
|
|
29
22
|
TransactionType["tokenMethodTransfer"] = "transfer";
|
|
30
23
|
TransactionType["tokenMethodTransferFrom"] = "transferFrom";
|
|
31
24
|
TransactionType["tokenMethodIncreaseAllowance"] = "increaseAllowance";
|
|
32
25
|
TransactionType["tokenMethodSafeTransferFrom"] = "safeTransferFrom";
|
|
33
|
-
// Contract operations
|
|
34
26
|
TransactionType["contractInteraction"] = "contractInteraction";
|
|
35
27
|
TransactionType["deployContract"] = "deployContract";
|
|
36
|
-
// Simple transfers
|
|
37
28
|
TransactionType["simpleSend"] = "simpleSend";
|
|
38
|
-
// Special operations
|
|
39
29
|
TransactionType["cancel"] = "cancel";
|
|
40
30
|
TransactionType["retry"] = "retry";
|
|
41
31
|
TransactionType["swap"] = "swap";
|
|
42
32
|
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
43
|
-
/**
|
|
44
|
-
* Enum representing asset types
|
|
45
|
-
*/
|
|
46
33
|
var AssetType;
|
|
47
34
|
(function (AssetType) {
|
|
48
35
|
AssetType["native"] = "NATIVE";
|
|
@@ -50,9 +37,6 @@ var AssetType;
|
|
|
50
37
|
AssetType["NFT"] = "NFT";
|
|
51
38
|
AssetType["unknown"] = "UNKNOWN";
|
|
52
39
|
})(AssetType || (exports.AssetType = AssetType = {}));
|
|
53
|
-
/**
|
|
54
|
-
* Enum representing token standards
|
|
55
|
-
*/
|
|
56
40
|
var TokenStandard;
|
|
57
41
|
(function (TokenStandard) {
|
|
58
42
|
TokenStandard["ERC20"] = "ERC20";
|
|
@@ -60,12 +44,6 @@ var TokenStandard;
|
|
|
60
44
|
TokenStandard["ERC1155"] = "ERC1155";
|
|
61
45
|
TokenStandard["none"] = "none";
|
|
62
46
|
})(TokenStandard || (exports.TokenStandard = TokenStandard = {}));
|
|
63
|
-
// ============================================================================
|
|
64
|
-
// ABIs
|
|
65
|
-
// ============================================================================
|
|
66
|
-
/**
|
|
67
|
-
* ERC20 token ABI (essential methods only)
|
|
68
|
-
*/
|
|
69
47
|
const ERC20_ABI = (0, viem_1.parseAbi)([
|
|
70
48
|
'function approve(address spender, uint256 amount) returns (bool)',
|
|
71
49
|
'function transfer(address to, uint256 amount) returns (bool)',
|
|
@@ -76,9 +54,6 @@ const ERC20_ABI = (0, viem_1.parseAbi)([
|
|
|
76
54
|
'function symbol() view returns (string)',
|
|
77
55
|
'function balanceOf(address account) view returns (uint256)',
|
|
78
56
|
]);
|
|
79
|
-
/**
|
|
80
|
-
* ERC721 token ABI (essential methods only)
|
|
81
|
-
*/
|
|
82
57
|
const ERC721_ABI = (0, viem_1.parseAbi)([
|
|
83
58
|
'function approve(address to, uint256 tokenId)',
|
|
84
59
|
'function setApprovalForAll(address operator, bool approved)',
|
|
@@ -87,31 +62,19 @@ const ERC721_ABI = (0, viem_1.parseAbi)([
|
|
|
87
62
|
'function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)',
|
|
88
63
|
'function supportsInterface(bytes4 interfaceId) view returns (bool)',
|
|
89
64
|
]);
|
|
90
|
-
/**
|
|
91
|
-
* ERC1155 token ABI (essential methods only)
|
|
92
|
-
*/
|
|
93
65
|
const ERC1155_ABI = (0, viem_1.parseAbi)([
|
|
94
66
|
'function setApprovalForAll(address operator, bool approved)',
|
|
95
67
|
'function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data)',
|
|
96
68
|
'function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data)',
|
|
97
69
|
'function supportsInterface(bytes4 interfaceId) view returns (bool)',
|
|
98
70
|
]);
|
|
99
|
-
/**
|
|
100
|
-
* USDC (Fiat Token V2) specific methods
|
|
101
|
-
*/
|
|
102
71
|
const FIAT_TOKEN_V2_ABI = (0, viem_1.parseAbi)([
|
|
103
72
|
'function increaseAllowance(address spender, uint256 increment) returns (bool)',
|
|
104
73
|
'function decreaseAllowance(address spender, uint256 decrement) returns (bool)',
|
|
105
74
|
]);
|
|
106
|
-
/**
|
|
107
|
-
* Permit2 contract ABI
|
|
108
|
-
*/
|
|
109
75
|
const PERMIT2_ABI = (0, viem_1.parseAbi)([
|
|
110
76
|
'function approve(address token, address spender, uint160 amount, uint48 expiration)',
|
|
111
77
|
]);
|
|
112
|
-
/**
|
|
113
|
-
* List of transaction types that can be inferred from transaction data
|
|
114
|
-
*/
|
|
115
78
|
const INFERRABLE_TRANSACTION_TYPES = [
|
|
116
79
|
TransactionType.tokenMethodApprove,
|
|
117
80
|
TransactionType.tokenMethodSetApprovalForAll,
|
|
@@ -121,88 +84,28 @@ const INFERRABLE_TRANSACTION_TYPES = [
|
|
|
121
84
|
TransactionType.contractInteraction,
|
|
122
85
|
TransactionType.simpleSend,
|
|
123
86
|
];
|
|
124
|
-
/**
|
|
125
|
-
* List of approval method names
|
|
126
|
-
*/
|
|
127
87
|
const APPROVAL_METHOD_NAMES = [
|
|
128
88
|
'approve',
|
|
129
89
|
'setApprovalForAll',
|
|
130
90
|
'increaseAllowance',
|
|
131
91
|
'decreaseAllowance',
|
|
132
92
|
];
|
|
133
|
-
/**
|
|
134
|
-
* Interface IDs for token standards (EIP-165)
|
|
135
|
-
*/
|
|
136
93
|
const INTERFACE_IDS = {
|
|
137
94
|
ERC721: '0x80ac58cd',
|
|
138
95
|
ERC1155: '0xd9b67a26',
|
|
139
96
|
ERC165: '0x01ffc9a7',
|
|
140
97
|
};
|
|
141
|
-
// ============================================================================
|
|
142
|
-
// Gas Fee Utilities
|
|
143
|
-
// ============================================================================
|
|
144
|
-
/**
|
|
145
|
-
* Determines if a transaction uses EIP-1559 gas fields
|
|
146
|
-
*
|
|
147
|
-
* EIP-1559 transactions use maxFeePerGas and maxPriorityFeePerGas instead of gasPrice
|
|
148
|
-
*
|
|
149
|
-
* @param transactionMeta - Transaction metadata to check
|
|
150
|
-
* @returns True if transaction uses valid EIP-1559 fields
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const isEIP1559 = isEIP1559Transaction({
|
|
155
|
-
* txParams: {
|
|
156
|
-
* maxFeePerGas: '0x59682f00',
|
|
157
|
-
* maxPriorityFeePerGas: '0x3b9aca00'
|
|
158
|
-
* }
|
|
159
|
-
* });
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
98
|
function isEIP1559Transaction(transactionMeta) {
|
|
163
99
|
const { maxFeePerGas, maxPriorityFeePerGas } = transactionMeta.txParams;
|
|
164
100
|
return ((0, viem_1.isHex)(String(maxFeePerGas ?? '')) &&
|
|
165
101
|
(0, viem_1.isHex)(String(maxPriorityFeePerGas ?? '')));
|
|
166
102
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Determines if a transaction uses legacy gas fields (gasPrice)
|
|
169
|
-
*
|
|
170
|
-
* Legacy transactions use gasPrice instead of EIP-1559 fields
|
|
171
|
-
*
|
|
172
|
-
* @param transactionMeta - Transaction metadata to check
|
|
173
|
-
* @returns True if transaction uses valid legacy gas fields
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const isLegacy = isLegacyTransaction({
|
|
178
|
-
* txParams: {
|
|
179
|
-
* gasPrice: '0x3b9aca00'
|
|
180
|
-
* }
|
|
181
|
-
* });
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
103
|
function isLegacyTransaction(transactionMeta) {
|
|
185
104
|
const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = transactionMeta.txParams;
|
|
186
105
|
return (typeof maxFeePerGas === 'undefined' &&
|
|
187
106
|
typeof maxPriorityFeePerGas === 'undefined' &&
|
|
188
107
|
(typeof gasPrice === 'undefined' || (0, viem_1.isHex)(String(gasPrice))));
|
|
189
108
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Checks if transaction gas fees match dApp suggested fees
|
|
192
|
-
*
|
|
193
|
-
* Useful for determining if the user has modified the dApp's suggested gas fees
|
|
194
|
-
*
|
|
195
|
-
* @param transactionMeta - Transaction metadata to check
|
|
196
|
-
* @returns True if txParams match dappSuggestedGasFees
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* const isUnmodified = txParamsAreDappSuggested({
|
|
201
|
-
* txParams: { gasPrice: '0x3b9aca00' },
|
|
202
|
-
* dappSuggestedGasFees: { gasPrice: '0x3b9aca00' }
|
|
203
|
-
* });
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
109
|
function txParamsAreDappSuggested(transactionMeta) {
|
|
207
110
|
const { gasPrice, maxPriorityFeePerGas, maxFeePerGas } = transactionMeta.txParams;
|
|
208
111
|
const suggested = transactionMeta.dappSuggestedGasFees;
|
|
@@ -214,26 +117,6 @@ function txParamsAreDappSuggested(transactionMeta) {
|
|
|
214
117
|
suggested.maxPriorityFeePerGas === maxPriorityFeePerGas &&
|
|
215
118
|
suggested.maxFeePerGas === maxFeePerGas));
|
|
216
119
|
}
|
|
217
|
-
// ============================================================================
|
|
218
|
-
// Transaction Data Parsing
|
|
219
|
-
// ============================================================================
|
|
220
|
-
/**
|
|
221
|
-
* Attempts to decode transaction data using standard token ABIs
|
|
222
|
-
*
|
|
223
|
-
* Tries to decode the data against ERC20, ERC721, ERC1155, USDC, and Permit2 ABIs
|
|
224
|
-
*
|
|
225
|
-
* @param data - Encoded transaction data
|
|
226
|
-
* @returns Decoded function data or undefined if decoding fails
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* const parsed = parseStandardTokenTransactionData('0xa9059cbb...');
|
|
231
|
-
* if (parsed) {
|
|
232
|
-
* console.log('Function:', parsed.functionName);
|
|
233
|
-
* console.log('Args:', parsed.args);
|
|
234
|
-
* }
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
120
|
function parseStandardTokenTransactionData(data) {
|
|
238
121
|
const abis = [
|
|
239
122
|
ERC20_ABI,
|
|
@@ -247,48 +130,13 @@ function parseStandardTokenTransactionData(data) {
|
|
|
247
130
|
return (0, viem_1.decodeFunctionData)({ abi, data });
|
|
248
131
|
}
|
|
249
132
|
catch {
|
|
250
|
-
// Continue to next ABI
|
|
251
133
|
}
|
|
252
134
|
}
|
|
253
135
|
return undefined;
|
|
254
136
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Checks if transaction has meaningful data
|
|
257
|
-
*
|
|
258
|
-
* @param transactionData - Transaction data field
|
|
259
|
-
* @returns True if data exists and is not empty
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* ```typescript
|
|
263
|
-
* hasTransactionData('0x') // false
|
|
264
|
-
* hasTransactionData('0xa9059cbb...') // true
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
137
|
function hasTransactionData(transactionData) {
|
|
268
138
|
return Boolean(transactionData?.length && transactionData.toLowerCase() !== '0x');
|
|
269
139
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Parses approval transaction data to extract relevant information
|
|
272
|
-
*
|
|
273
|
-
* Supports:
|
|
274
|
-
* - ERC20: approve, increaseAllowance
|
|
275
|
-
* - ERC721/ERC1155: setApprovalForAll
|
|
276
|
-
* - Permit2: approve
|
|
277
|
-
* - USDC: increaseAllowance
|
|
278
|
-
*
|
|
279
|
-
* @param data - Transaction data to parse
|
|
280
|
-
* @returns Parsed approval data or undefined if not an approval transaction
|
|
281
|
-
*
|
|
282
|
-
* @example
|
|
283
|
-
* ```typescript
|
|
284
|
-
* const approval = parseApprovalTransactionData('0x095ea7b3...');
|
|
285
|
-
* if (approval) {
|
|
286
|
-
* console.log('Spender:', approval.spender);
|
|
287
|
-
* console.log('Amount:', approval.amountOrTokenId);
|
|
288
|
-
* console.log('Is approval for all?', approval.isApproveAll);
|
|
289
|
-
* }
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
140
|
function parseApprovalTransactionData(data) {
|
|
293
141
|
const decoded = parseStandardTokenTransactionData(data);
|
|
294
142
|
if (!decoded)
|
|
@@ -297,22 +145,18 @@ function parseApprovalTransactionData(data) {
|
|
|
297
145
|
if (!functionName || !APPROVAL_METHOD_NAMES.includes(functionName)) {
|
|
298
146
|
return undefined;
|
|
299
147
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
args?.
|
|
303
|
-
args?.
|
|
304
|
-
args?.addedValue; // ERC-20 increaseAllowance
|
|
148
|
+
const rawAmountOrTokenId = args?._value ??
|
|
149
|
+
args?.increment ??
|
|
150
|
+
args?.amount ??
|
|
151
|
+
args?.addedValue;
|
|
305
152
|
const amountOrTokenId = rawAmountOrTokenId
|
|
306
153
|
? BigInt(rawAmountOrTokenId.toString())
|
|
307
154
|
: undefined;
|
|
308
|
-
// Extract spender address
|
|
309
155
|
const spender = args?.spender ??
|
|
310
156
|
args?._spender ??
|
|
311
157
|
args?.[0];
|
|
312
|
-
// Check if it's an approval for all (ERC721/ERC1155)
|
|
313
158
|
const isApproveAll = functionName === 'setApprovalForAll' && args?._approved === true;
|
|
314
159
|
const isRevokeAll = functionName === 'setApprovalForAll' && args?._approved === false;
|
|
315
|
-
// Extract token address for Permit2
|
|
316
160
|
const tokenAddress = functionName === 'approve' ? args?.token : undefined;
|
|
317
161
|
return {
|
|
318
162
|
amountOrTokenId,
|
|
@@ -323,24 +167,6 @@ function parseApprovalTransactionData(data) {
|
|
|
323
167
|
spender,
|
|
324
168
|
};
|
|
325
169
|
}
|
|
326
|
-
// ============================================================================
|
|
327
|
-
// Contract Utilities
|
|
328
|
-
// ============================================================================
|
|
329
|
-
/**
|
|
330
|
-
* Reads an address to determine if it's a contract
|
|
331
|
-
*
|
|
332
|
-
* @param client - Viem public client
|
|
333
|
-
* @param address - Address to check
|
|
334
|
-
* @returns Contract code and whether it's a contract address
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```typescript
|
|
338
|
-
* const { isContractAddress, contractCode } = await readAddressAsContract(
|
|
339
|
-
* client,
|
|
340
|
-
* '0x...'
|
|
341
|
-
* );
|
|
342
|
-
* ```
|
|
343
|
-
*/
|
|
344
170
|
async function readAddressAsContract(client, address) {
|
|
345
171
|
try {
|
|
346
172
|
const code = await client.getCode({ address });
|
|
@@ -358,23 +184,8 @@ async function readAddressAsContract(client, address) {
|
|
|
358
184
|
};
|
|
359
185
|
}
|
|
360
186
|
}
|
|
361
|
-
/**
|
|
362
|
-
* Determines the token standard by checking EIP-165 interface support
|
|
363
|
-
*
|
|
364
|
-
* @param client - Viem public client
|
|
365
|
-
* @param address - Token contract address
|
|
366
|
-
* @returns Token standard (ERC721, ERC1155, ERC20, or none)
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```typescript
|
|
370
|
-
* const standard = await getTokenStandard(client, '0x...');
|
|
371
|
-
* console.log('Token standard:', standard); // 'ERC721'
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
187
|
async function getTokenStandard(client, address) {
|
|
375
|
-
// Try ERC165 supportsInterface for ERC721/ERC1155
|
|
376
188
|
try {
|
|
377
|
-
// Check ERC721
|
|
378
189
|
const isERC721 = await client.readContract({
|
|
379
190
|
address,
|
|
380
191
|
abi: (0, viem_1.parseAbi)(['function supportsInterface(bytes4) view returns (bool)']),
|
|
@@ -383,7 +194,6 @@ async function getTokenStandard(client, address) {
|
|
|
383
194
|
});
|
|
384
195
|
if (isERC721)
|
|
385
196
|
return TokenStandard.ERC721;
|
|
386
|
-
// Check ERC1155
|
|
387
197
|
const isERC1155 = await client.readContract({
|
|
388
198
|
address,
|
|
389
199
|
abi: (0, viem_1.parseAbi)(['function supportsInterface(bytes4) view returns (bool)']),
|
|
@@ -394,9 +204,7 @@ async function getTokenStandard(client, address) {
|
|
|
394
204
|
return TokenStandard.ERC1155;
|
|
395
205
|
}
|
|
396
206
|
catch {
|
|
397
|
-
// Not ERC721/ERC1155, try ERC20
|
|
398
207
|
}
|
|
399
|
-
// Try ERC20 by checking for decimals function
|
|
400
208
|
try {
|
|
401
209
|
await client.readContract({
|
|
402
210
|
address,
|
|
@@ -406,35 +214,15 @@ async function getTokenStandard(client, address) {
|
|
|
406
214
|
return TokenStandard.ERC20;
|
|
407
215
|
}
|
|
408
216
|
catch {
|
|
409
|
-
// Not a recognized token standard
|
|
410
217
|
}
|
|
411
218
|
return TokenStandard.none;
|
|
412
219
|
}
|
|
413
|
-
/**
|
|
414
|
-
* Gets token details including standard, decimals, symbol, and balance
|
|
415
|
-
*
|
|
416
|
-
* @param client - Viem public client
|
|
417
|
-
* @param address - Token contract address
|
|
418
|
-
* @param holderAddress - Optional address to check balance for
|
|
419
|
-
* @returns Token details
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* ```typescript
|
|
423
|
-
* const details = await getTokenStandardAndDetails(
|
|
424
|
-
* client,
|
|
425
|
-
* '0x...', // token address
|
|
426
|
-
* '0x...' // holder address
|
|
427
|
-
* );
|
|
428
|
-
* console.log(details.symbol, details.decimals, details.balance);
|
|
429
|
-
* ```
|
|
430
|
-
*/
|
|
431
220
|
async function getTokenStandardAndDetails(client, address, holderAddress) {
|
|
432
221
|
const standard = await getTokenStandard(client, address);
|
|
433
222
|
if (standard === TokenStandard.none) {
|
|
434
223
|
return { standard };
|
|
435
224
|
}
|
|
436
225
|
const details = { standard };
|
|
437
|
-
// Get ERC20 details
|
|
438
226
|
if (standard === TokenStandard.ERC20) {
|
|
439
227
|
try {
|
|
440
228
|
const contract = (0, viem_1.getContract)({
|
|
@@ -459,50 +247,18 @@ async function getTokenStandardAndDetails(client, address, holderAddress) {
|
|
|
459
247
|
}
|
|
460
248
|
return details;
|
|
461
249
|
}
|
|
462
|
-
// ============================================================================
|
|
463
|
-
// Transaction Type Determination
|
|
464
|
-
// ============================================================================
|
|
465
|
-
/**
|
|
466
|
-
* Determines the type of transaction by analyzing its parameters
|
|
467
|
-
*
|
|
468
|
-
* This function analyzes the transaction to determine if it's:
|
|
469
|
-
* - A contract deployment
|
|
470
|
-
* - A token transfer/approval
|
|
471
|
-
* - A contract interaction
|
|
472
|
-
* - A simple ETH transfer
|
|
473
|
-
*
|
|
474
|
-
* @param txParams - Transaction parameters
|
|
475
|
-
* @param client - Viem public client
|
|
476
|
-
* @returns Transaction type and contract code
|
|
477
|
-
*
|
|
478
|
-
* @example
|
|
479
|
-
* ```typescript
|
|
480
|
-
* const result = await determineTransactionType(
|
|
481
|
-
* {
|
|
482
|
-
* from: '0x...',
|
|
483
|
-
* to: '0x...',
|
|
484
|
-
* data: '0xa9059cbb...'
|
|
485
|
-
* },
|
|
486
|
-
* client
|
|
487
|
-
* );
|
|
488
|
-
* console.log('Transaction type:', result.type);
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
250
|
async function determineTransactionType(txParams, client) {
|
|
492
251
|
const { data, to, value } = txParams;
|
|
493
|
-
// Contract deployment (no 'to' address)
|
|
494
252
|
if (data && !to) {
|
|
495
253
|
return {
|
|
496
254
|
type: TransactionType.deployContract,
|
|
497
255
|
contractCode: null,
|
|
498
256
|
};
|
|
499
257
|
}
|
|
500
|
-
// Check if 'to' is a contract
|
|
501
258
|
if (to) {
|
|
502
259
|
const { contractCode, isContractAddress } = await readAddressAsContract(client, to);
|
|
503
260
|
if (isContractAddress) {
|
|
504
261
|
const hasValue = value && BigInt(value) !== 0n;
|
|
505
|
-
// Try to parse the transaction data
|
|
506
262
|
let functionName = '';
|
|
507
263
|
try {
|
|
508
264
|
const parsed = data ? parseStandardTokenTransactionData(data) : undefined;
|
|
@@ -513,7 +269,6 @@ async function determineTransactionType(txParams, client) {
|
|
|
513
269
|
catch (error) {
|
|
514
270
|
console.debug('Failed to parse transaction data:', error);
|
|
515
271
|
}
|
|
516
|
-
// Check if it's a known token method
|
|
517
272
|
const tokenMethodName = [
|
|
518
273
|
TransactionType.tokenMethodApprove,
|
|
519
274
|
TransactionType.tokenMethodSetApprovalForAll,
|
|
@@ -522,57 +277,29 @@ async function determineTransactionType(txParams, client) {
|
|
|
522
277
|
TransactionType.tokenMethodIncreaseAllowance,
|
|
523
278
|
TransactionType.tokenMethodSafeTransferFrom,
|
|
524
279
|
].find((methodName) => methodName.toLowerCase() === functionName.toLowerCase());
|
|
525
|
-
// Return token method if found and no ETH value
|
|
526
280
|
if (data && tokenMethodName && !hasValue) {
|
|
527
281
|
return {
|
|
528
282
|
type: tokenMethodName,
|
|
529
283
|
contractCode,
|
|
530
284
|
};
|
|
531
285
|
}
|
|
532
|
-
// Otherwise it's a general contract interaction
|
|
533
286
|
return {
|
|
534
287
|
type: TransactionType.contractInteraction,
|
|
535
288
|
contractCode,
|
|
536
289
|
};
|
|
537
290
|
}
|
|
538
291
|
}
|
|
539
|
-
// Simple ETH transfer
|
|
540
292
|
return {
|
|
541
293
|
type: TransactionType.simpleSend,
|
|
542
294
|
contractCode: null,
|
|
543
295
|
};
|
|
544
296
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Determines the asset type and token standard for a transaction
|
|
547
|
-
*
|
|
548
|
-
* This function analyzes the transaction to determine what type of asset
|
|
549
|
-
* is being transferred and what standard it follows (if applicable)
|
|
550
|
-
*
|
|
551
|
-
* @param txMeta - Transaction metadata
|
|
552
|
-
* @param client - Viem public client
|
|
553
|
-
* @returns Asset type and token standard
|
|
554
|
-
*
|
|
555
|
-
* @example
|
|
556
|
-
* ```typescript
|
|
557
|
-
* const { assetType, tokenStandard } = await determineTransactionAssetType(
|
|
558
|
-
* txMeta,
|
|
559
|
-
* client
|
|
560
|
-
* );
|
|
561
|
-
*
|
|
562
|
-
* if (assetType === AssetType.token) {
|
|
563
|
-
* console.log('ERC20 token transfer');
|
|
564
|
-
* }
|
|
565
|
-
* ```
|
|
566
|
-
*/
|
|
567
297
|
async function determineTransactionAssetType(txMeta, client) {
|
|
568
|
-
// Use existing type if it's already inferrable
|
|
569
298
|
let inferrableType = txMeta.type;
|
|
570
299
|
if (txMeta.type && !INFERRABLE_TRANSACTION_TYPES.includes(txMeta.type)) {
|
|
571
|
-
// Get an inferrable type for special transactions (like swaps)
|
|
572
300
|
const result = await determineTransactionType(txMeta.txParams, client);
|
|
573
301
|
inferrableType = result.type;
|
|
574
302
|
}
|
|
575
|
-
// Check if it's a token method
|
|
576
303
|
const isTokenMethod = [
|
|
577
304
|
TransactionType.tokenMethodApprove,
|
|
578
305
|
TransactionType.tokenMethodSetApprovalForAll,
|
|
@@ -580,7 +307,6 @@ async function determineTransactionAssetType(txMeta, client) {
|
|
|
580
307
|
TransactionType.tokenMethodTransferFrom,
|
|
581
308
|
TransactionType.tokenMethodIncreaseAllowance,
|
|
582
309
|
].includes(inferrableType);
|
|
583
|
-
// Try to get token standard for token methods or contract interactions
|
|
584
310
|
if (isTokenMethod || inferrableType === TransactionType.contractInteraction) {
|
|
585
311
|
if (txMeta.txParams.to) {
|
|
586
312
|
try {
|
|
@@ -595,58 +321,27 @@ async function determineTransactionAssetType(txMeta, client) {
|
|
|
595
321
|
}
|
|
596
322
|
}
|
|
597
323
|
catch {
|
|
598
|
-
// Failed to get token details, continue
|
|
599
324
|
}
|
|
600
325
|
}
|
|
601
326
|
}
|
|
602
|
-
// Contract interaction with unknown asset type
|
|
603
327
|
if (inferrableType === TransactionType.contractInteraction) {
|
|
604
328
|
return {
|
|
605
329
|
assetType: AssetType.unknown,
|
|
606
330
|
tokenStandard: TokenStandard.none,
|
|
607
331
|
};
|
|
608
332
|
}
|
|
609
|
-
// Native ETH transfer
|
|
610
333
|
return {
|
|
611
334
|
assetType: AssetType.native,
|
|
612
335
|
tokenStandard: TokenStandard.none,
|
|
613
336
|
};
|
|
614
337
|
}
|
|
615
|
-
// ============================================================================
|
|
616
|
-
// Typed Data Parsing
|
|
617
|
-
// ============================================================================
|
|
618
|
-
/**
|
|
619
|
-
* Regex to extract large number values from typed data messages
|
|
620
|
-
* Handles cases where JSON.parse would lose precision
|
|
621
|
-
*/
|
|
622
338
|
const REGEX_MESSAGE_VALUE_LARGE = /"message"\s*:\s*\{[^}]*"value"\s*:\s*(\d{15,})/u;
|
|
623
|
-
/**
|
|
624
|
-
* Extracts large number value from a stringified message
|
|
625
|
-
*
|
|
626
|
-
* @param dataToParse - Stringified data to parse
|
|
627
|
-
* @returns Extracted large number or undefined
|
|
628
|
-
*/
|
|
629
339
|
function extractLargeMessageValue(dataToParse) {
|
|
630
340
|
if (typeof dataToParse !== 'string') {
|
|
631
341
|
return undefined;
|
|
632
342
|
}
|
|
633
343
|
return dataToParse.match(REGEX_MESSAGE_VALUE_LARGE)?.[1];
|
|
634
344
|
}
|
|
635
|
-
/**
|
|
636
|
-
* Parses typed data message while preserving large number precision
|
|
637
|
-
*
|
|
638
|
-
* JSON.parse can lose precision for numbers > Number.MAX_SAFE_INTEGER
|
|
639
|
-
* This function extracts large values and preserves them as strings
|
|
640
|
-
*
|
|
641
|
-
* @param dataToParse - Data to parse (object or string)
|
|
642
|
-
* @returns Parsed data with preserved precision
|
|
643
|
-
*
|
|
644
|
-
* @example
|
|
645
|
-
* ```typescript
|
|
646
|
-
* const parsed = parseTypedDataMessage(signatureRequest.data);
|
|
647
|
-
* console.log(parsed.message.value); // Preserved as string
|
|
648
|
-
* ```
|
|
649
|
-
*/
|
|
650
345
|
function parseTypedDataMessage(dataToParse) {
|
|
651
346
|
const result = typeof dataToParse === 'object'
|
|
652
347
|
? dataToParse
|
|
@@ -657,17 +352,6 @@ function parseTypedDataMessage(dataToParse) {
|
|
|
657
352
|
}
|
|
658
353
|
return result;
|
|
659
354
|
}
|
|
660
|
-
// ============================================================================
|
|
661
|
-
// Helper Utilities
|
|
662
|
-
// ============================================================================
|
|
663
|
-
/**
|
|
664
|
-
* Case-insensitive string comparison
|
|
665
|
-
*
|
|
666
|
-
* @param str1 - First string
|
|
667
|
-
* @param str2 - Second string
|
|
668
|
-
* @returns True if strings are equal (case-insensitive)
|
|
669
|
-
*/
|
|
670
355
|
function isEqualCaseInsensitive(str1, str2) {
|
|
671
356
|
return str1.toLowerCase() === str2.toLowerCase();
|
|
672
357
|
}
|
|
673
|
-
//# sourceMappingURL=transaction.utils.js.map
|
|
@@ -40,16 +40,5 @@ export interface TransactionHistoryOptions {
|
|
|
40
40
|
includeTokenTransfers?: boolean;
|
|
41
41
|
includeNFTTransfers?: boolean;
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Fetches and parses transaction history for an EVM wallet address
|
|
45
|
-
* @param client - Viem public client
|
|
46
|
-
* @param walletAddress - Ethereum address
|
|
47
|
-
* @param options - Optional parameters for filtering and features
|
|
48
|
-
* @returns Array of parsed transaction history items
|
|
49
|
-
*/
|
|
50
43
|
export declare function getEVMTransactionHistory(client: PublicClient, walletAddress: Address, options?: TransactionHistoryOptions): Promise<EVMTransactionHistoryItem[]>;
|
|
51
|
-
/**
|
|
52
|
-
* Alternative function that uses Etherscan-like API
|
|
53
|
-
* This is the recommended approach for production use
|
|
54
|
-
*/
|
|
55
44
|
export declare function getEVMTransactionHistoryWithAPI(client: PublicClient, walletAddress: Address, apiEndpoint: string, apiKey: string, options?: TransactionHistoryOptions): Promise<EVMTransactionHistoryItem[]>;
|