@trustwallet/cli 0.6.4 → 0.6.5
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/commands/init.d.ts.map +1 -1
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/index.js +178 -164
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6D1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqf3D"}
|
package/dist/index.js
CHANGED
|
@@ -463,6 +463,7 @@ __export(dist_exports, {
|
|
|
463
463
|
getChainByEvmId: () => getChainByEvmId,
|
|
464
464
|
getChainById: () => getChainById,
|
|
465
465
|
getChainDomainId: () => getChainDomainId,
|
|
466
|
+
getChainMapKey: () => getChainMapKey,
|
|
466
467
|
getEVMChains: () => getEVMChains,
|
|
467
468
|
getExplorerTxUrl: () => getExplorerTxUrl,
|
|
468
469
|
getNativeAddressPlaceholder: () => getNativeAddressPlaceholder,
|
|
@@ -502,12 +503,19 @@ function getEVMChains() {
|
|
|
502
503
|
function isChainSupported(chainKey) {
|
|
503
504
|
return chainKey.toLowerCase() in CHAINS;
|
|
504
505
|
}
|
|
505
|
-
function
|
|
506
|
+
function getChainMapKey(chainKey) {
|
|
506
507
|
const lower = chainKey.toLowerCase();
|
|
507
508
|
if (CHAINS[lower]) return lower;
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
509
|
+
const entry = Object.entries(CHAINS).find(([, c]) => c.id === lower);
|
|
510
|
+
return entry?.[0];
|
|
511
|
+
}
|
|
512
|
+
function getChainDomainId(chainKey) {
|
|
513
|
+
const lower = chainKey.toLowerCase();
|
|
514
|
+
const chain = CHAINS[lower];
|
|
515
|
+
if (chain) return chain.id;
|
|
516
|
+
const entry = Object.entries(CHAINS).find(([, c]) => c.id === lower);
|
|
517
|
+
if (!entry) throw new Error(`Unsupported chain: ${chainKey}`);
|
|
518
|
+
return entry[1].id;
|
|
511
519
|
}
|
|
512
520
|
function getExplorerTxUrl(chainKey, txHash) {
|
|
513
521
|
const chain = getChainById(chainKey);
|
|
@@ -547,18 +555,19 @@ function resolveToken(token, chainKey) {
|
|
|
547
555
|
}
|
|
548
556
|
const upperToken = token.toUpperCase();
|
|
549
557
|
const chainConfig = getChainById(chainKey);
|
|
558
|
+
const mapKey = getChainMapKey(chainKey) ?? chainKey.toLowerCase();
|
|
559
|
+
const isBsc = mapKey === "bsc";
|
|
560
|
+
const chainTokens = COMMON_TOKENS[mapKey];
|
|
561
|
+
if (chainTokens?.[upperToken]) {
|
|
562
|
+
const decimals = isBsc && BSC_18_DECIMAL_TOKENS.has(upperToken) ? 18 : TOKEN_DECIMALS[upperToken] ?? 18;
|
|
563
|
+
return { address: chainTokens[upperToken], decimals };
|
|
564
|
+
}
|
|
550
565
|
if (NATIVE_SYMBOLS.has(upperToken) || chainConfig && upperToken === chainConfig.symbol.toUpperCase()) {
|
|
551
566
|
return {
|
|
552
567
|
address: getNativeAddressPlaceholder(chainKey),
|
|
553
568
|
decimals: chainConfig?.decimals ?? 18
|
|
554
569
|
};
|
|
555
570
|
}
|
|
556
|
-
const chainTokens = COMMON_TOKENS[chainKey.toLowerCase()];
|
|
557
|
-
const isBsc = chainKey.toLowerCase() === "bsc" || chainKey.toLowerCase() === "smartchain";
|
|
558
|
-
if (chainTokens?.[upperToken]) {
|
|
559
|
-
const decimals = isBsc && BSC_18_DECIMAL_TOKENS.has(upperToken) ? 18 : TOKEN_DECIMALS[upperToken] ?? 18;
|
|
560
|
-
return { address: chainTokens[upperToken], decimals };
|
|
561
|
-
}
|
|
562
571
|
if (upperToken.startsWith("USDC")) {
|
|
563
572
|
const addr = chainTokens?.["USDC.e"] || chainTokens?.["USDC"] || token;
|
|
564
573
|
return { address: addr, decimals: isBsc ? 18 : 6 };
|
|
@@ -1073,7 +1082,8 @@ var init_dist2 = __esm({
|
|
|
1073
1082
|
"USDC.e": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
|
|
1074
1083
|
DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
1075
1084
|
WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
1076
|
-
WBTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
|
|
1085
|
+
WBTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
1086
|
+
ARB: "0x912CE59144191C1204E64559FE8253a0e49E6548"
|
|
1077
1087
|
},
|
|
1078
1088
|
polygon: {
|
|
1079
1089
|
USDT: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
|
@@ -1089,6 +1099,7 @@ var init_dist2 = __esm({
|
|
|
1089
1099
|
BUSD: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
|
|
1090
1100
|
DAI: "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3",
|
|
1091
1101
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
1102
|
+
ETH: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
|
|
1092
1103
|
TWT: "0x4B0F1812e5Df2A09796481Ff14017e6005508003"
|
|
1093
1104
|
},
|
|
1094
1105
|
base: {
|
|
@@ -1109,7 +1120,8 @@ var init_dist2 = __esm({
|
|
|
1109
1120
|
USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
1110
1121
|
"USDC.e": "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
1111
1122
|
DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
1112
|
-
WETH: "0x4200000000000000000000000000000000000006"
|
|
1123
|
+
WETH: "0x4200000000000000000000000000000000000006",
|
|
1124
|
+
OP: "0x4200000000000000000000000000000000000042"
|
|
1113
1125
|
},
|
|
1114
1126
|
tron: {
|
|
1115
1127
|
USDT: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -2735,7 +2747,7 @@ var init_dist5 = __esm({
|
|
|
2735
2747
|
};
|
|
2736
2748
|
});
|
|
2737
2749
|
}
|
|
2738
|
-
async getTrendingTokens(limit = 20) {
|
|
2750
|
+
async getTrendingTokens(limit = 20, sort = "percent_change_24h") {
|
|
2739
2751
|
const knownAssets = [
|
|
2740
2752
|
"c60",
|
|
2741
2753
|
"c501",
|
|
@@ -2763,7 +2775,8 @@ var init_dist5 = __esm({
|
|
|
2763
2775
|
assets: knownAssets
|
|
2764
2776
|
});
|
|
2765
2777
|
const tickers = response.tickers || [];
|
|
2766
|
-
|
|
2778
|
+
const sortKey = sort === "market_cap" ? "market_cap" : sort === "volume_24h" ? "volume_24h" : "change_24h";
|
|
2779
|
+
return tickers.sort((a, b) => (b[sortKey] ?? 0) - (a[sortKey] ?? 0)).slice(0, limit).map((t) => {
|
|
2767
2780
|
const coinId = t.id ? parseInt(t.id.replace(/^c/, ""), 10) : NaN;
|
|
2768
2781
|
const chain = !isNaN(coinId) ? coinTypeToChainKey(coinId) || "" : "";
|
|
2769
2782
|
return {
|
|
@@ -2775,7 +2788,7 @@ var init_dist5 = __esm({
|
|
|
2775
2788
|
priceUsd: t.price,
|
|
2776
2789
|
priceChange24h: t.change_24h,
|
|
2777
2790
|
marketCapUsd: t.market_cap,
|
|
2778
|
-
volume24hUsd:
|
|
2791
|
+
volume24hUsd: t.volume_24h
|
|
2779
2792
|
};
|
|
2780
2793
|
});
|
|
2781
2794
|
}
|
|
@@ -12177,7 +12190,89 @@ function info(message) {
|
|
|
12177
12190
|
console.log(import_chalk.default.cyan(message));
|
|
12178
12191
|
}
|
|
12179
12192
|
|
|
12193
|
+
// src/config-loader.ts
|
|
12194
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
12195
|
+
init_dist2();
|
|
12196
|
+
init_dist4();
|
|
12197
|
+
init_dist();
|
|
12198
|
+
async function getCredentials() {
|
|
12199
|
+
const envAccessId = process.env.TWAK_ACCESS_ID;
|
|
12200
|
+
const envSecret = process.env.TWAK_HMAC_SECRET;
|
|
12201
|
+
if (envAccessId && envSecret) {
|
|
12202
|
+
return { accessId: envAccessId, hmacSecret: envSecret };
|
|
12203
|
+
}
|
|
12204
|
+
const credManager = new CredentialManager();
|
|
12205
|
+
const credentials = await credManager.load();
|
|
12206
|
+
if (credentials) {
|
|
12207
|
+
return { accessId: credentials.accessId, hmacSecret: credentials.hmacSecret };
|
|
12208
|
+
}
|
|
12209
|
+
console.error(import_chalk2.default.red("No API credentials found."));
|
|
12210
|
+
console.error(import_chalk2.default.dim("Set TWAK_ACCESS_ID and TWAK_HMAC_SECRET environment variables, then run `twak init`"));
|
|
12211
|
+
process.exit(1);
|
|
12212
|
+
}
|
|
12213
|
+
async function getClient() {
|
|
12214
|
+
const creds = await getCredentials();
|
|
12215
|
+
return createTwakClient({ ...creds });
|
|
12216
|
+
}
|
|
12217
|
+
async function ensureTrustSDK() {
|
|
12218
|
+
const creds = await getCredentials();
|
|
12219
|
+
await initTrustSDK({
|
|
12220
|
+
accessId: creds.accessId,
|
|
12221
|
+
hmacSecret: creds.hmacSecret,
|
|
12222
|
+
naasSessionId: process.env.TWAK_NAAS_SESSION_ID
|
|
12223
|
+
});
|
|
12224
|
+
return creds;
|
|
12225
|
+
}
|
|
12226
|
+
async function registerWalletWithBackend(creds, provider) {
|
|
12227
|
+
const accounts = [];
|
|
12228
|
+
for (const key of Object.keys(CHAINS)) {
|
|
12229
|
+
const chain = getChainById(key);
|
|
12230
|
+
if (!chain) continue;
|
|
12231
|
+
try {
|
|
12232
|
+
const address = await provider.getAddress(key);
|
|
12233
|
+
if (address) accounts.push({ coin: chain.coinId, address });
|
|
12234
|
+
} catch {
|
|
12235
|
+
}
|
|
12236
|
+
}
|
|
12237
|
+
if (accounts.length > 0) {
|
|
12238
|
+
await registerDeviceAndWallet(creds, accounts);
|
|
12239
|
+
}
|
|
12240
|
+
}
|
|
12241
|
+
async function resolvePassword(opts) {
|
|
12242
|
+
if (opts?.password) {
|
|
12243
|
+
process.stderr.write(
|
|
12244
|
+
import_chalk2.default.yellow("Note: --password is visible in shell history. Use `twak wallet keychain save` or TWAK_WALLET_PASSWORD instead.\n")
|
|
12245
|
+
);
|
|
12246
|
+
return opts.password;
|
|
12247
|
+
}
|
|
12248
|
+
if (process.env.TWAK_WALLET_PASSWORD) return process.env.TWAK_WALLET_PASSWORD;
|
|
12249
|
+
const kc = new KeychainManager();
|
|
12250
|
+
const stored = await kc.getWalletPassword();
|
|
12251
|
+
if (stored) return stored;
|
|
12252
|
+
throw new Error(
|
|
12253
|
+
"No wallet password found. Provide --password, set TWAK_WALLET_PASSWORD, or run `twak wallet keychain save --password <pw>`"
|
|
12254
|
+
);
|
|
12255
|
+
}
|
|
12256
|
+
|
|
12257
|
+
// ../wallet/dist/index.mjs
|
|
12258
|
+
init_dist3();
|
|
12259
|
+
|
|
12260
|
+
// ../walletconnect/dist/index.mjs
|
|
12261
|
+
init_dist3();
|
|
12262
|
+
|
|
12180
12263
|
// src/commands/init.ts
|
|
12264
|
+
async function tryRegisterWallet() {
|
|
12265
|
+
const store = new WalletConfigStore();
|
|
12266
|
+
if (!await store.exists()) return;
|
|
12267
|
+
try {
|
|
12268
|
+
const creds = await ensureTrustSDK();
|
|
12269
|
+
const password = await resolvePassword();
|
|
12270
|
+
const provider = await AgentWalletProvider.fromStorage(password);
|
|
12271
|
+
await registerWalletWithBackend(creds, provider);
|
|
12272
|
+
info("Wallet registered with backend");
|
|
12273
|
+
} catch {
|
|
12274
|
+
}
|
|
12275
|
+
}
|
|
12181
12276
|
function registerInitCommand(program2) {
|
|
12182
12277
|
program2.command("init").description("Initialize twak configuration").option("--api-key <key>", "TWAK API access ID (prefer TWAK_ACCESS_ID env var)").option("--api-secret <secret>", "TWAK HMAC secret (prefer TWAK_HMAC_SECRET env var)").option("--wc-project-id <id>", "WalletConnect project ID").action(async (opts) => {
|
|
12183
12278
|
const credManager = new CredentialManager();
|
|
@@ -12191,6 +12286,7 @@ function registerInitCommand(program2) {
|
|
|
12191
12286
|
walletConnectProjectId: opts.wcProjectId
|
|
12192
12287
|
});
|
|
12193
12288
|
success("Credentials saved to ~/.twak/credentials.json");
|
|
12289
|
+
await tryRegisterWallet();
|
|
12194
12290
|
info("\nNext step: create a wallet with `twak wallet create --password <pw>`");
|
|
12195
12291
|
return;
|
|
12196
12292
|
}
|
|
@@ -12204,6 +12300,7 @@ function registerInitCommand(program2) {
|
|
|
12204
12300
|
walletConnectProjectId: envWcId
|
|
12205
12301
|
});
|
|
12206
12302
|
success("Credentials saved from environment variables to ~/.twak/credentials.json");
|
|
12303
|
+
await tryRegisterWallet();
|
|
12207
12304
|
info("\nNext step: create a wallet with `twak wallet create --password <pw>`");
|
|
12208
12305
|
return;
|
|
12209
12306
|
}
|
|
@@ -12226,7 +12323,7 @@ function registerInitCommand(program2) {
|
|
|
12226
12323
|
}
|
|
12227
12324
|
|
|
12228
12325
|
// src/commands/auth.ts
|
|
12229
|
-
var
|
|
12326
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
12230
12327
|
init_dist();
|
|
12231
12328
|
function registerAuthCommand(program2) {
|
|
12232
12329
|
const auth = program2.command("auth").description("Manage authentication");
|
|
@@ -12249,89 +12346,17 @@ function registerAuthCommand(program2) {
|
|
|
12249
12346
|
if (opts.json) {
|
|
12250
12347
|
output({ configured, source, accessId }, true);
|
|
12251
12348
|
} else {
|
|
12252
|
-
console.log(` ${
|
|
12253
|
-
console.log(` ${
|
|
12254
|
-
if (accessId) console.log(` ${
|
|
12349
|
+
console.log(` ${import_chalk3.default.dim("Status")} ${configured ? import_chalk3.default.green("configured") : import_chalk3.default.yellow("not configured")}`);
|
|
12350
|
+
console.log(` ${import_chalk3.default.dim("Source")} ${source}`);
|
|
12351
|
+
if (accessId) console.log(` ${import_chalk3.default.dim("Access ID")} ${accessId}...`);
|
|
12255
12352
|
if (!configured) info("\nRun `twak init` to set up credentials.");
|
|
12256
12353
|
}
|
|
12257
12354
|
});
|
|
12258
12355
|
}
|
|
12259
12356
|
|
|
12260
|
-
// ../wallet/dist/index.mjs
|
|
12261
|
-
init_dist3();
|
|
12262
|
-
|
|
12263
|
-
// ../walletconnect/dist/index.mjs
|
|
12264
|
-
init_dist3();
|
|
12265
|
-
|
|
12266
12357
|
// src/commands/wallet.ts
|
|
12267
12358
|
init_dist();
|
|
12268
12359
|
var import_chalk5 = __toESM(require("chalk"));
|
|
12269
|
-
|
|
12270
|
-
// src/config-loader.ts
|
|
12271
|
-
var import_chalk3 = __toESM(require("chalk"));
|
|
12272
|
-
init_dist2();
|
|
12273
|
-
init_dist4();
|
|
12274
|
-
init_dist();
|
|
12275
|
-
async function getCredentials() {
|
|
12276
|
-
const envAccessId = process.env.TWAK_ACCESS_ID;
|
|
12277
|
-
const envSecret = process.env.TWAK_HMAC_SECRET;
|
|
12278
|
-
if (envAccessId && envSecret) {
|
|
12279
|
-
return { accessId: envAccessId, hmacSecret: envSecret };
|
|
12280
|
-
}
|
|
12281
|
-
const credManager = new CredentialManager();
|
|
12282
|
-
const credentials = await credManager.load();
|
|
12283
|
-
if (credentials) {
|
|
12284
|
-
return { accessId: credentials.accessId, hmacSecret: credentials.hmacSecret };
|
|
12285
|
-
}
|
|
12286
|
-
console.error(import_chalk3.default.red("No API credentials found."));
|
|
12287
|
-
console.error(import_chalk3.default.dim("Set TWAK_ACCESS_ID and TWAK_HMAC_SECRET environment variables, then run `twak init`"));
|
|
12288
|
-
process.exit(1);
|
|
12289
|
-
}
|
|
12290
|
-
async function getClient() {
|
|
12291
|
-
const creds = await getCredentials();
|
|
12292
|
-
return createTwakClient({ ...creds });
|
|
12293
|
-
}
|
|
12294
|
-
async function ensureTrustSDK() {
|
|
12295
|
-
const creds = await getCredentials();
|
|
12296
|
-
await initTrustSDK({
|
|
12297
|
-
accessId: creds.accessId,
|
|
12298
|
-
hmacSecret: creds.hmacSecret,
|
|
12299
|
-
naasSessionId: process.env.TWAK_NAAS_SESSION_ID
|
|
12300
|
-
});
|
|
12301
|
-
return creds;
|
|
12302
|
-
}
|
|
12303
|
-
async function registerWalletWithBackend(creds, provider) {
|
|
12304
|
-
const accounts = [];
|
|
12305
|
-
for (const key of Object.keys(CHAINS)) {
|
|
12306
|
-
const chain = getChainById(key);
|
|
12307
|
-
if (!chain) continue;
|
|
12308
|
-
try {
|
|
12309
|
-
const address = await provider.getAddress(key);
|
|
12310
|
-
if (address) accounts.push({ coin: chain.coinId, address });
|
|
12311
|
-
} catch {
|
|
12312
|
-
}
|
|
12313
|
-
}
|
|
12314
|
-
if (accounts.length > 0) {
|
|
12315
|
-
await registerDeviceAndWallet(creds, accounts);
|
|
12316
|
-
}
|
|
12317
|
-
}
|
|
12318
|
-
async function resolvePassword(opts) {
|
|
12319
|
-
if (opts?.password) {
|
|
12320
|
-
process.stderr.write(
|
|
12321
|
-
import_chalk3.default.yellow("Note: --password is visible in shell history. Use `twak wallet keychain save` or TWAK_WALLET_PASSWORD instead.\n")
|
|
12322
|
-
);
|
|
12323
|
-
return opts.password;
|
|
12324
|
-
}
|
|
12325
|
-
if (process.env.TWAK_WALLET_PASSWORD) return process.env.TWAK_WALLET_PASSWORD;
|
|
12326
|
-
const kc = new KeychainManager();
|
|
12327
|
-
const stored = await kc.getWalletPassword();
|
|
12328
|
-
if (stored) return stored;
|
|
12329
|
-
throw new Error(
|
|
12330
|
-
"No wallet password found. Provide --password, set TWAK_WALLET_PASSWORD, or run `twak wallet keychain save --password <pw>`"
|
|
12331
|
-
);
|
|
12332
|
-
}
|
|
12333
|
-
|
|
12334
|
-
// src/commands/wallet.ts
|
|
12335
12360
|
init_dist2();
|
|
12336
12361
|
|
|
12337
12362
|
// src/branding.ts
|
|
@@ -13587,9 +13612,9 @@ function registerAlertCommand(program2) {
|
|
|
13587
13612
|
}
|
|
13588
13613
|
const condition = aboveProvided ? "above" : "below";
|
|
13589
13614
|
const targetPrice = parseFloat(aboveProvided ? opts.above : opts.below);
|
|
13590
|
-
if (isNaN(targetPrice)) {
|
|
13591
|
-
error("Price must be a
|
|
13592
|
-
if (opts.json) output({ error: "Price must be a
|
|
13615
|
+
if (isNaN(targetPrice) || targetPrice <= 0) {
|
|
13616
|
+
error("Price must be a positive number");
|
|
13617
|
+
if (opts.json) output({ error: "Price must be a positive number" }, true);
|
|
13593
13618
|
process.exitCode = 1;
|
|
13594
13619
|
return;
|
|
13595
13620
|
}
|
|
@@ -13663,50 +13688,12 @@ function registerAlertCommand(program2) {
|
|
|
13663
13688
|
init_dist2();
|
|
13664
13689
|
|
|
13665
13690
|
// ../transactions/dist/index.mjs
|
|
13691
|
+
init_dist2();
|
|
13666
13692
|
function toRFC3339(value) {
|
|
13667
13693
|
const d = new Date(value);
|
|
13668
13694
|
if (!isNaN(d.getTime())) return d.toISOString();
|
|
13669
13695
|
return value;
|
|
13670
13696
|
}
|
|
13671
|
-
var BLOCKSCOUT_HOSTS = {
|
|
13672
|
-
ethereum: "https://eth.blockscout.com",
|
|
13673
|
-
base: "https://base.blockscout.com",
|
|
13674
|
-
bsc: "https://bsc.blockscout.com",
|
|
13675
|
-
polygon: "https://polygon.blockscout.com",
|
|
13676
|
-
arbitrum: "https://arbitrum.blockscout.com",
|
|
13677
|
-
optimism: "https://optimism.blockscout.com",
|
|
13678
|
-
avalanche: "https://avalanche.blockscout.com",
|
|
13679
|
-
fantom: "https://fantom.blockscout.com",
|
|
13680
|
-
linea: "https://explorer.linea.build",
|
|
13681
|
-
scroll: "https://scroll.blockscout.com",
|
|
13682
|
-
blast: "https://blast.blockscout.com",
|
|
13683
|
-
celo: "https://celo.blockscout.com"
|
|
13684
|
-
};
|
|
13685
|
-
async function getHistoryFromExplorer(address, chain, limit) {
|
|
13686
|
-
const host = BLOCKSCOUT_HOSTS[chain.toLowerCase()];
|
|
13687
|
-
if (!host) return [];
|
|
13688
|
-
const url = `${host}/api/v2/addresses/${address}/transactions`;
|
|
13689
|
-
const resp = await fetch(url, { signal: AbortSignal.timeout(15e3) });
|
|
13690
|
-
if (!resp.ok) {
|
|
13691
|
-
if (resp.status === 404) return [];
|
|
13692
|
-
throw new Error(`Blockscout ${chain} returned ${resp.status}`);
|
|
13693
|
-
}
|
|
13694
|
-
const data = await resp.json();
|
|
13695
|
-
if (!Array.isArray(data.items)) return [];
|
|
13696
|
-
return data.items.slice(0, limit).map((tx) => ({
|
|
13697
|
-
id: tx.hash,
|
|
13698
|
-
hash: tx.hash,
|
|
13699
|
-
chain,
|
|
13700
|
-
type: tx.tx_types?.[0] ?? (tx.to?.is_contract ? "contract" : "transfer"),
|
|
13701
|
-
status: tx.status === "ok" ? "confirmed" : "failed",
|
|
13702
|
-
from: tx.from?.hash ?? tx.from,
|
|
13703
|
-
to: tx.to?.hash ?? tx.to,
|
|
13704
|
-
amount: tx.value,
|
|
13705
|
-
fee: tx.fee?.value ?? "0",
|
|
13706
|
-
date: tx.timestamp,
|
|
13707
|
-
metadata: { blockNumber: tx.block, nonce: tx.nonce }
|
|
13708
|
-
}));
|
|
13709
|
-
}
|
|
13710
13697
|
var TransactionService = class {
|
|
13711
13698
|
constructor(client) {
|
|
13712
13699
|
this.client = client;
|
|
@@ -13714,36 +13701,32 @@ var TransactionService = class {
|
|
|
13714
13701
|
async getHistory(params) {
|
|
13715
13702
|
const from = params.from ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
13716
13703
|
const to = params.to ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
13704
|
+
const chainId = params.chain ? getChainById(params.chain)?.id ?? params.chain : void 0;
|
|
13717
13705
|
const query = new URLSearchParams();
|
|
13718
13706
|
query.set("address", params.address);
|
|
13719
13707
|
if (params.asset) query.set("asset", params.asset);
|
|
13720
|
-
if (
|
|
13708
|
+
if (chainId) query.set("chain", chainId);
|
|
13721
13709
|
query.set("from", toRFC3339(from));
|
|
13722
13710
|
query.set("to", toRFC3339(to));
|
|
13723
13711
|
if (params.limit) query.set("limit", params.limit.toString());
|
|
13724
13712
|
if (params.txType) query.set("tx_type", params.txType);
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
|
|
13729
|
-
|
|
13730
|
-
|
|
13731
|
-
|
|
13732
|
-
return response.data || [];
|
|
13733
|
-
} catch (err) {
|
|
13734
|
-
const statusCode = err.statusCode;
|
|
13735
|
-
if (statusCode !== 403 && statusCode !== 401 && statusCode !== 400) throw err;
|
|
13736
|
-
if (params.chain) {
|
|
13737
|
-
return getHistoryFromExplorer(params.address, params.chain, params.limit || 20);
|
|
13738
|
-
}
|
|
13739
|
-
throw err;
|
|
13740
|
-
}
|
|
13713
|
+
const response = await this.client.gateway(
|
|
13714
|
+
"GET",
|
|
13715
|
+
"/v1/txhub/txs",
|
|
13716
|
+
void 0,
|
|
13717
|
+
query.toString()
|
|
13718
|
+
);
|
|
13719
|
+
return response.data || [];
|
|
13741
13720
|
}
|
|
13742
13721
|
async getBulkHistory(params) {
|
|
13743
13722
|
const from = params.from ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
13744
13723
|
const to = params.to ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
13724
|
+
const addresses = params.addresses.map((a) => ({
|
|
13725
|
+
...a,
|
|
13726
|
+
chain: getChainById(a.chain)?.id ?? a.chain
|
|
13727
|
+
}));
|
|
13745
13728
|
const response = await this.client.gateway("POST", "/v1/txhub/bulk_history", {
|
|
13746
|
-
addresses
|
|
13729
|
+
addresses,
|
|
13747
13730
|
from: toRFC3339(from),
|
|
13748
13731
|
to: toRFC3339(to),
|
|
13749
13732
|
...params.nextToken ? { next_token: params.nextToken } : {}
|
|
@@ -13751,11 +13734,12 @@ var TransactionService = class {
|
|
|
13751
13734
|
return response.data || [];
|
|
13752
13735
|
}
|
|
13753
13736
|
async getByHash(hash, chain) {
|
|
13737
|
+
const chainId = getChainById(chain)?.id ?? chain;
|
|
13754
13738
|
return this.client.gateway(
|
|
13755
13739
|
"GET",
|
|
13756
13740
|
`/v1/txhub/txs/${hash}`,
|
|
13757
13741
|
void 0,
|
|
13758
|
-
`chain=${
|
|
13742
|
+
`chain=${chainId}`
|
|
13759
13743
|
);
|
|
13760
13744
|
}
|
|
13761
13745
|
async getSwapHistory(params) {
|
|
@@ -13780,7 +13764,16 @@ function registerQueryCommand(program2) {
|
|
|
13780
13764
|
const client = await getClient();
|
|
13781
13765
|
const swapClient = new SwapClient(client);
|
|
13782
13766
|
const tokens = token.split(",").map((t) => t.trim()).filter(Boolean);
|
|
13783
|
-
const resolveChain = (t) =>
|
|
13767
|
+
const resolveChain = (t) => {
|
|
13768
|
+
if (opts.chain) return opts.chain;
|
|
13769
|
+
const bySymbol = Object.entries(CHAINS).find(([, c]) => c.symbol.toUpperCase() === t.toUpperCase())?.[0];
|
|
13770
|
+
if (bySymbol) return bySymbol;
|
|
13771
|
+
const upper = t.toUpperCase();
|
|
13772
|
+
for (const [chainKey, chainTokens] of Object.entries(COMMON_TOKENS)) {
|
|
13773
|
+
if (Object.prototype.hasOwnProperty.call(chainTokens, upper)) return chainKey;
|
|
13774
|
+
}
|
|
13775
|
+
return "ethereum";
|
|
13776
|
+
};
|
|
13784
13777
|
if (tokens.length > 1) {
|
|
13785
13778
|
const assetIds = [];
|
|
13786
13779
|
const tokenMeta = [];
|
|
@@ -13935,12 +13928,33 @@ function registerQueryCommand(program2) {
|
|
|
13935
13928
|
handleError(err, opts.json);
|
|
13936
13929
|
}
|
|
13937
13930
|
});
|
|
13938
|
-
program2.command("tx <hash>").description("Get transaction details").requiredOption("--chain <name>", "Chain name").option("--json", "JSON output").action(async (hash, opts) => {
|
|
13931
|
+
program2.command("tx <hash>").description("Get transaction details by hash (on-chain RPC lookup)").requiredOption("--chain <name>", "Chain name").option("--address <address>", "Wallet address (auto-detected from wallet if omitted)").option("--password <pw>", "Wallet password (for auto-detecting address)").option("--json", "JSON output").action(async (hash, opts) => {
|
|
13939
13932
|
try {
|
|
13940
|
-
|
|
13941
|
-
|
|
13942
|
-
|
|
13943
|
-
|
|
13933
|
+
let address = opts.address;
|
|
13934
|
+
if (!address) {
|
|
13935
|
+
try {
|
|
13936
|
+
await ensureTrustSDK();
|
|
13937
|
+
const password = await resolvePassword(opts);
|
|
13938
|
+
const provider = await AgentWalletProvider.fromStorage(password);
|
|
13939
|
+
address = await provider.getAddress(opts.chain);
|
|
13940
|
+
} catch {
|
|
13941
|
+
}
|
|
13942
|
+
}
|
|
13943
|
+
if (address) {
|
|
13944
|
+
await ensureTrustSDK();
|
|
13945
|
+
const blockchainClient = new BlockchainClient();
|
|
13946
|
+
const status = await blockchainClient.findTransactionStatus(opts.chain, address, hash);
|
|
13947
|
+
output({
|
|
13948
|
+
hash,
|
|
13949
|
+
chain: opts.chain,
|
|
13950
|
+
...status
|
|
13951
|
+
}, opts.json);
|
|
13952
|
+
} else {
|
|
13953
|
+
const client = await getClient();
|
|
13954
|
+
const service = new TransactionService(client);
|
|
13955
|
+
const result = await service.getByHash(hash, opts.chain);
|
|
13956
|
+
output(result, opts.json);
|
|
13957
|
+
}
|
|
13944
13958
|
} catch (err) {
|
|
13945
13959
|
handleError(err, opts.json);
|
|
13946
13960
|
}
|
|
@@ -14064,7 +14078,8 @@ function registerQueryCommand(program2) {
|
|
|
14064
14078
|
const sort = opts.sort ? sortMap[opts.sort] ?? opts.sort : "percent_change_24h";
|
|
14065
14079
|
tokens = await service.getAssetListings({ categoryId, sort, limit: parseInt(opts.limit, 10) });
|
|
14066
14080
|
} else {
|
|
14067
|
-
|
|
14081
|
+
const sort = opts.sort ? sortMap[opts.sort] ?? opts.sort : "percent_change_24h";
|
|
14082
|
+
tokens = await service.getTrendingTokens(parseInt(opts.limit, 10), sort);
|
|
14068
14083
|
}
|
|
14069
14084
|
const seen = /* @__PURE__ */ new Map();
|
|
14070
14085
|
for (const t of tokens) {
|
|
@@ -18378,13 +18393,12 @@ var TransferActionProvider = class extends ActionProvider {
|
|
|
18378
18393
|
to: external_exports.string().describe("Destination address or ENS name (e.g., vitalik.eth)"),
|
|
18379
18394
|
amount: external_exports.string().describe('Amount in human-readable format (e.g., "1.5", "0.01")'),
|
|
18380
18395
|
token: external_exports.string().optional().describe("ERC-20 token contract address (omit for native token)"),
|
|
18381
|
-
decimals: external_exports.coerce.number().optional().default(18).describe("Token decimals (default 18, use 6 for USDC/USDT)")
|
|
18382
|
-
skipSafetyCheck: external_exports.boolean().optional().default(false).describe("Skip USD-value safety limit (default: false)")
|
|
18396
|
+
decimals: external_exports.coerce.number().optional().default(18).describe("Token decimals (default 18, use 6 for USDC/USDT)")
|
|
18383
18397
|
}),
|
|
18384
18398
|
invoke: async (_ctx, input) => {
|
|
18385
18399
|
const signer = this.walletProvider;
|
|
18386
18400
|
if (!signer) return { success: false, error: "No wallet provider configured" };
|
|
18387
|
-
if (
|
|
18401
|
+
if (this.priceLookup) {
|
|
18388
18402
|
try {
|
|
18389
18403
|
const evmId2 = extractEvmChainId(input.chainId);
|
|
18390
18404
|
const chain = getChainById(evmId2) ?? getChainByEvmId(evmId2);
|
|
@@ -18396,7 +18410,7 @@ var TransferActionProvider = class extends ActionProvider {
|
|
|
18396
18410
|
if (usdValue > this.maxTransferUsd) {
|
|
18397
18411
|
return {
|
|
18398
18412
|
success: false,
|
|
18399
|
-
error: `Transfer value ~$${usdValue.toFixed(2)} USD exceeds safety limit of $${this.maxTransferUsd}.
|
|
18413
|
+
error: `Transfer value ~$${usdValue.toFixed(2)} USD exceeds safety limit of $${this.maxTransferUsd}. Use the CLI with --skip-safety-check to override.`
|
|
18400
18414
|
};
|
|
18401
18415
|
}
|
|
18402
18416
|
}
|
|
@@ -28145,7 +28159,7 @@ var crypto3 = __toESM(require("crypto"));
|
|
|
28145
28159
|
// package.json
|
|
28146
28160
|
var package_default = {
|
|
28147
28161
|
name: "@trustwallet/cli",
|
|
28148
|
-
version: "0.6.
|
|
28162
|
+
version: "0.6.5",
|
|
28149
28163
|
description: "TWAK CLI \u2014 command-line interface for Trust Wallet Agent Kit",
|
|
28150
28164
|
main: "dist/index.js",
|
|
28151
28165
|
types: "dist/index.d.ts",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustwallet/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "TWAK CLI — command-line interface for Trust Wallet Agent Kit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "8.5.1",
|
|
29
29
|
"typescript": "5.7.3",
|
|
30
|
-
"@twak/
|
|
31
|
-
"@twak/
|
|
32
|
-
"@twak/
|
|
33
|
-
"@twak/
|
|
34
|
-
"@twak/storage": "0.6.
|
|
35
|
-
"@twak/
|
|
36
|
-
"@twak/swap": "0.6.
|
|
37
|
-
"@twak/transactions": "0.6.
|
|
38
|
-
"@twak/wallet": "0.6.
|
|
39
|
-
"@twak/
|
|
40
|
-
"@twak/
|
|
30
|
+
"@twak/actions": "0.6.5",
|
|
31
|
+
"@twak/blockchain": "0.6.5",
|
|
32
|
+
"@twak/core": "0.6.5",
|
|
33
|
+
"@twak/security": "0.6.5",
|
|
34
|
+
"@twak/storage": "0.6.5",
|
|
35
|
+
"@twak/mcp": "0.6.5",
|
|
36
|
+
"@twak/swap": "0.6.5",
|
|
37
|
+
"@twak/transactions": "0.6.5",
|
|
38
|
+
"@twak/wallet-core": "0.6.5",
|
|
39
|
+
"@twak/walletconnect": "0.6.5",
|
|
40
|
+
"@twak/wallet": "0.6.5"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|