nansen-cli 1.44.0 → 1.44.2
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 +53 -0
- package/package.json +1 -1
- package/src/api.js +98 -23
- package/src/chain-ids.js +6 -0
- package/src/cli.js +55 -7
- package/src/commands/alerts.js +56 -16
- package/src/keychain.js +32 -2
- package/src/limit-order.js +218 -20
- package/src/schema.json +11 -2
- package/src/telemetry.js +15 -5
- package/src/trade-validation.js +410 -5
- package/src/trading.js +42 -11
- package/src/transfer.js +10 -4
- package/src/walletconnect-trading.js +16 -1
- package/src/walletconnect-x402.js +25 -4
- package/src/x402-evm.js +8 -4
- package/src/x402-policy.js +16 -1
- package/src/x402-svm.js +9 -7
- package/src/x402-tokens.js +7 -2
package/src/x402-evm.js
CHANGED
|
@@ -215,12 +215,16 @@ export function createEvmPaymentPayload(requirements, privateKeyHex, walletAddre
|
|
|
215
215
|
throw new Error(`Unsupported assetTransferMethod: ${method}`);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
// Token name and version from requirements.extra (set by server/facilitator)
|
|
218
|
+
// Token name and version from requirements.extra (set by server/facilitator).
|
|
219
|
+
// Both are required: the EIP-712 domain version varies by token (USDC on Base
|
|
220
|
+
// is "2", USDT0/BSC tokens are "1"), so guessing a default would silently
|
|
221
|
+
// produce an invalid signature. Refuse instead — matches the walletconnect/Privy
|
|
222
|
+
// path in buildEIP712TypedData.
|
|
219
223
|
const tokenName = extra.name;
|
|
220
|
-
const tokenVersion = extra.version
|
|
224
|
+
const tokenVersion = extra.version;
|
|
221
225
|
|
|
222
|
-
if (!tokenName) {
|
|
223
|
-
throw new Error('EIP-712 domain name missing from requirements.extra');
|
|
226
|
+
if (!tokenName || !tokenVersion) {
|
|
227
|
+
throw new Error('EIP-712 domain name/version missing from requirements.extra');
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
// Generate random nonce (32 bytes)
|
package/src/x402-policy.js
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
import { EVM_X402_TOKENS, SVM_X402_TOKENS } from './x402-tokens.js';
|
|
8
8
|
import { getWalletConfig } from './wallet.js';
|
|
9
9
|
|
|
10
|
+
// The only x402 scheme this client can honour. "exact" = a fixed-amount transfer
|
|
11
|
+
// authorization (EIP-3009 / Permit2 on EVM, SPL TransferChecked on SVM). Any other
|
|
12
|
+
// scheme must be refused before signing, not silently accepted.
|
|
13
|
+
export const SUPPORTED_X402_SCHEMES = new Set(['exact']);
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* True for the exact Solana CAIP-2 network prefix ("solana:..."), matching
|
|
12
17
|
* isSvmNetwork() in x402-svm.js. Duplicated here (rather than imported) to
|
|
@@ -36,7 +41,7 @@ export function resolveKnownToken(network, asset) {
|
|
|
36
41
|
return table.find(t => t.token.toLowerCase() === asset.toLowerCase()) || null;
|
|
37
42
|
}
|
|
38
43
|
if (isSvmNetworkString(network)) {
|
|
39
|
-
const table = SVM_X402_TOKENS['solana'
|
|
44
|
+
const table = SVM_X402_TOKENS[network]; // exact CAIP-2 key, not the bare 'solana' prefix
|
|
40
45
|
if (!table) return null;
|
|
41
46
|
return table.find(t => t.token === asset) || null;
|
|
42
47
|
}
|
|
@@ -130,6 +135,16 @@ export function resolvePayTo(requirement) {
|
|
|
130
135
|
* allowlist, per-payment USD cap. Never signs; pure decision.
|
|
131
136
|
*/
|
|
132
137
|
export function evaluatePaymentRequirement(requirement) {
|
|
138
|
+
const scheme = requirement.scheme;
|
|
139
|
+
if (!SUPPORTED_X402_SCHEMES.has(scheme)) {
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
reason:
|
|
143
|
+
`Refusing to auto-pay: unsupported payment scheme ${scheme == null ? '(missing)' : `"${scheme}"`}. ` +
|
|
144
|
+
`Only "exact" is supported. No signature was produced.`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
133
148
|
const network = requirement.network;
|
|
134
149
|
const asset = requirement.asset;
|
|
135
150
|
const payTo = resolvePayTo(requirement);
|
package/src/x402-svm.js
CHANGED
|
@@ -7,6 +7,7 @@ import crypto from 'crypto';
|
|
|
7
7
|
import { base58Encode, base58DecodePubkey } from './wallet.js';
|
|
8
8
|
import { encodeCompactU16, deriveATA as _deriveATA } from './transfer.js';
|
|
9
9
|
import { resolvePaymentAmount, resolvePayTo } from './x402-policy.js';
|
|
10
|
+
import { SOLANA_MAINNET_NETWORK } from './x402-tokens.js';
|
|
10
11
|
|
|
11
12
|
// ============= Constants =============
|
|
12
13
|
|
|
@@ -329,13 +330,14 @@ export async function fetchRecentBlockhash(rpcUrl = 'https://api.mainnet-beta.so
|
|
|
329
330
|
* Get RPC URL for a Solana network identifier.
|
|
330
331
|
*/
|
|
331
332
|
export function getSolanaRpcUrl(network) {
|
|
332
|
-
if (network
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return 'https://api.
|
|
333
|
+
if (network === SOLANA_MAINNET_NETWORK) return 'https://api.mainnet-beta.solana.com';
|
|
334
|
+
// Devnet/testnet resolve for tooling (e.g. balance checks), but the x402 pay
|
|
335
|
+
// path never reaches them: SVM_X402_TOKENS is mainnet-only, so the policy layer
|
|
336
|
+
// refuses a devnet/testnet requirement before signing. Adding a non-mainnet
|
|
337
|
+
// token entry would silently enable signing here — revisit this gate if you do.
|
|
338
|
+
if (network === 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1') return 'https://api.devnet.solana.com';
|
|
339
|
+
if (network === 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z') return 'https://api.testnet.solana.com';
|
|
340
|
+
throw new Error(`Unsupported Solana network for x402: ${network}`);
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
/**
|
package/src/x402-tokens.js
CHANGED
|
@@ -21,9 +21,14 @@ export const EVM_X402_TOKENS = {
|
|
|
21
21
|
],
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
//
|
|
24
|
+
// Canonical Solana mainnet CAIP-2 id.
|
|
25
|
+
// x402 payment tokens are mainnet mints, so mainnet is the only valid payment network.
|
|
26
|
+
export const SOLANA_MAINNET_NETWORK = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
|
|
27
|
+
|
|
28
|
+
// Known payment tokens on Solana, keyed by exact CAIP-2 network (symmetric with EVM_X402_TOKENS).
|
|
29
|
+
// Unknown or devnet/testnet solana:* ids resolve to no token and are refused by the policy.
|
|
25
30
|
export const SVM_X402_TOKENS = {
|
|
26
|
-
|
|
31
|
+
[SOLANA_MAINNET_NETWORK]: [
|
|
27
32
|
{ token: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', symbol: 'USDC', decimals: 6 },
|
|
28
33
|
],
|
|
29
34
|
};
|