nansen-cli 1.36.2 → 1.38.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/CHANGELOG.md +42 -0
- package/README.md +2 -1
- package/package.json +1 -1
- package/skills/nansen-trading/SKILL.md +2 -0
- package/skills/nansen-wallet-keychain-migration/SKILL.md +14 -12
- package/src/api.js +11 -0
- package/src/cli.js +122 -58
- package/src/cost-cache.js +19 -1
- package/src/doctor.js +480 -0
- package/src/keychain.js +46 -0
- package/src/perp.js +134 -5
- package/src/schema.json +93 -0
- package/src/telemetry.js +59 -2
- package/src/trade-validation.js +441 -0
- package/src/trading.js +387 -18
- package/src/update-check.js +45 -24
- package/src/walletconnect-trading.js +11 -7
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { wcExec } from './walletconnect-exec.js';
|
|
12
12
|
import { base58Encode } from './wallet.js';
|
|
13
|
+
import { encodeApproveCalldata } from './trade-validation.js';
|
|
13
14
|
|
|
14
15
|
const SOLANA_MAINNET_CHAIN = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
|
|
15
16
|
|
|
@@ -104,19 +105,22 @@ export async function sendTransactionViaWalletConnect(txData, timeoutMs = 120000
|
|
|
104
105
|
/**
|
|
105
106
|
* Send an ERC-20 approval via WalletConnect.
|
|
106
107
|
*
|
|
107
|
-
* Builds approve(spender,
|
|
108
|
+
* Builds approve(spender, amount) calldata and delegates to sendTransactionViaWalletConnect.
|
|
109
|
+
* The amount is scoped to the swap's input (passed by the caller) so a bad quote
|
|
110
|
+
* can drain at most one trade, not the wallet's full token balance.
|
|
108
111
|
*
|
|
109
112
|
* @param {string} tokenAddress - ERC-20 token contract
|
|
110
113
|
* @param {string} spenderAddress - Approval target (e.g. DEX router)
|
|
111
114
|
* @param {number} chainId - EIP-155 chain ID
|
|
115
|
+
* @param {bigint|string|number} amount - Allowance to grant, in base units
|
|
116
|
+
* @param {bigint|string|number} [maxAllowance] - Hard cap from persisted request intent
|
|
112
117
|
* @returns {{ txHash?: string, signedTransaction?: string }}
|
|
113
118
|
*/
|
|
114
|
-
export async function sendApprovalViaWalletConnect(tokenAddress, spenderAddress, chainId) {
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
+ MAX_UINT256_HEX;
|
|
119
|
+
export async function sendApprovalViaWalletConnect(tokenAddress, spenderAddress, chainId, amount, maxAllowance) {
|
|
120
|
+
// encodeApproveCalldata enforces a valid 20-byte spender, a bounded (< MAX)
|
|
121
|
+
// amount within the request cap, and exactly-68-byte calldata — so a
|
|
122
|
+
// malformed or tampered spender/amount can't reshape the ABI word layout.
|
|
123
|
+
const data = encodeApproveCalldata(spenderAddress, amount, { maxAllowance });
|
|
120
124
|
|
|
121
125
|
return sendTransactionViaWalletConnect({
|
|
122
126
|
to: tokenAddress,
|