@clawcard/cli 3.0.13 → 3.0.15
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/package.json +1 -1
- package/src/commands/agent.js +94 -36
- package/src/index.js +2 -2
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -63,6 +63,9 @@ export async function agentInfoCmd(options) {
|
|
|
63
63
|
if (wallet) {
|
|
64
64
|
console.log(` Wallet: ${orange(wallet.address)} ${chalk.dim("(Base)")}`);
|
|
65
65
|
console.log(` USDC: ${chalk.green(wallet.balanceUsdc + " USDC")}`);
|
|
66
|
+
if (wallet.balanceEth) {
|
|
67
|
+
console.log(` ETH: ${chalk.dim(wallet.balanceEth + " ETH (gas)")}`);
|
|
68
|
+
}
|
|
66
69
|
} else {
|
|
67
70
|
console.log(` Wallet: ${chalk.dim("none — run: clawcard agent wallet")}`);
|
|
68
71
|
}
|
|
@@ -414,7 +417,8 @@ export async function agentWalletCmd(options) {
|
|
|
414
417
|
console.log();
|
|
415
418
|
console.log(` Address: ${orange(wallet.address)}`);
|
|
416
419
|
console.log(` Network: Base`);
|
|
417
|
-
console.log(`
|
|
420
|
+
console.log(` USDC: ${chalk.green(wallet.balanceUsdc + " USDC")}`);
|
|
421
|
+
console.log(` ETH: ${chalk.dim((wallet.balanceEth || "0.000000") + " ETH (gas)")}`);
|
|
418
422
|
console.log(` Status: ${wallet.status}`);
|
|
419
423
|
console.log();
|
|
420
424
|
return;
|
|
@@ -449,7 +453,8 @@ export async function agentWalletCmd(options) {
|
|
|
449
453
|
console.log();
|
|
450
454
|
console.log(` Address: ${orange(wallet.address)}`);
|
|
451
455
|
console.log(` Network: Base`);
|
|
452
|
-
console.log(`
|
|
456
|
+
console.log(` USDC: ${wallet.balanceUsdc} USDC`);
|
|
457
|
+
console.log(` ETH: ${wallet.balanceEth || "0.000000"} ETH (gas)`);
|
|
453
458
|
console.log(` Status: ${wallet.status}`);
|
|
454
459
|
console.log();
|
|
455
460
|
console.log(chalk.dim(" Fund via FIAT balance or send USDC directly to the address above."));
|
|
@@ -473,7 +478,8 @@ export async function agentWalletBalanceCmd(options) {
|
|
|
473
478
|
|
|
474
479
|
console.log();
|
|
475
480
|
console.log(` USDC Balance: ${chalk.green(wallet.balanceUsdc + " USDC")}`);
|
|
476
|
-
console.log(`
|
|
481
|
+
console.log(` ETH (gas): ${chalk.dim((wallet.balanceEth || "0.000000") + " ETH")}`);
|
|
482
|
+
console.log(` FIAT Budget: ${chalk.green("$" + fiatBudget.toFixed(2))} ${chalk.dim("(for cards)")}`);
|
|
477
483
|
console.log(` Effective: ${chalk.green("~$" + effective.toFixed(2))} ${chalk.dim("total spending power")}`);
|
|
478
484
|
console.log();
|
|
479
485
|
} catch (err) {
|
|
@@ -571,48 +577,100 @@ export async function agentWalletTransactionsCmd(options) {
|
|
|
571
577
|
}
|
|
572
578
|
|
|
573
579
|
export async function agentWalletFundCmd(options) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (options.
|
|
577
|
-
|
|
578
|
-
|
|
580
|
+
// JSON mode — pass through to API directly
|
|
581
|
+
if (options.json) {
|
|
582
|
+
if (!options.amount) return output({ success: false, error: "--amount required" }, true);
|
|
583
|
+
const agentId = await getAgentId();
|
|
584
|
+
try {
|
|
585
|
+
const result = await walletFund(agentId, options.amount);
|
|
586
|
+
return output(result, true);
|
|
587
|
+
} catch (err) {
|
|
588
|
+
return output({ success: false, error: err.message }, true);
|
|
589
|
+
}
|
|
579
590
|
}
|
|
580
591
|
|
|
592
|
+
// Interactive wizard
|
|
593
|
+
const prompts = await import("@clack/prompts");
|
|
581
594
|
const agentId = await getAgentId();
|
|
595
|
+
|
|
596
|
+
console.log();
|
|
597
|
+
console.log(` ${orange.bold("Fund Your Agent's Wallet")}`);
|
|
598
|
+
console.log();
|
|
599
|
+
console.log(chalk.dim(" Your agent's wallet uses USDC (a stablecoin pegged to $1) on the Base network."));
|
|
600
|
+
console.log(chalk.dim(" To send USDC, your wallet also needs a tiny bit of ETH for transaction fees."));
|
|
601
|
+
console.log(chalk.dim(" $1 of ETH covers thousands of transactions."));
|
|
602
|
+
console.log();
|
|
603
|
+
|
|
604
|
+
// Step 1: What to buy
|
|
605
|
+
const asset = await prompts.select({
|
|
606
|
+
message: "What would you like to purchase?",
|
|
607
|
+
options: [
|
|
608
|
+
{ value: "eth", label: "ETH (for gas fees)", hint: "buy this first — $1-2 is plenty" },
|
|
609
|
+
{ value: "usdc", label: "USDC (spending money)", hint: "your agent uses this to pay for things" },
|
|
610
|
+
],
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
if (prompts.isCancel(asset)) return;
|
|
614
|
+
|
|
615
|
+
// Step 2: Amount
|
|
616
|
+
const defaultAmount = asset === "eth" ? "2" : "10";
|
|
617
|
+
const amountInput = await prompts.text({
|
|
618
|
+
message: `How much $ of ${asset === "eth" ? "ETH" : "USDC"} do you want to buy?`,
|
|
619
|
+
placeholder: defaultAmount,
|
|
620
|
+
defaultValue: defaultAmount,
|
|
621
|
+
validate: (v) => {
|
|
622
|
+
const n = parseFloat(v);
|
|
623
|
+
if (isNaN(n) || n < 1) return "Minimum is $1.00";
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
if (prompts.isCancel(amountInput)) return;
|
|
628
|
+
|
|
629
|
+
const amount = parseFloat(amountInput);
|
|
630
|
+
|
|
631
|
+
// Step 3: Open Coinbase
|
|
632
|
+
const s = prompts.spinner();
|
|
633
|
+
s.start("Preparing Coinbase checkout...");
|
|
634
|
+
|
|
582
635
|
try {
|
|
583
|
-
const result = await walletFund(agentId,
|
|
584
|
-
|
|
636
|
+
const result = await walletFund(agentId, String(amount));
|
|
637
|
+
s.stop("");
|
|
585
638
|
|
|
586
|
-
if (result.success) {
|
|
587
|
-
console.log();
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
console.log(` ${result.instructions}`);
|
|
591
|
-
console.log();
|
|
592
|
-
console.log(` ${orange(result.url)}`);
|
|
593
|
-
console.log();
|
|
594
|
-
console.log(chalk.dim(` Important: Buy USDC for spending, plus ~$1 of ETH for gas fees.`));
|
|
595
|
-
console.log(chalk.dim(` $1 of ETH covers thousands of transactions on Base.`));
|
|
596
|
-
console.log(chalk.dim(` Or send USDC + ETH directly to ${result.walletAddress} on Base.`));
|
|
597
|
-
console.log();
|
|
639
|
+
if (!result.success) {
|
|
640
|
+
console.log(` Error: ${result.error}`);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
598
643
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
644
|
+
// Swap the default asset in the URL if they chose ETH
|
|
645
|
+
let url = result.url;
|
|
646
|
+
if (asset === "eth") {
|
|
647
|
+
url = url.replace("defaultAsset=USDC", "defaultAsset=ETH");
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
console.log();
|
|
651
|
+
console.log(` ${chalk.green("Opening Coinbase...")} Buy $${amount.toFixed(2)} of ${asset === "eth" ? "ETH" : "USDC"}`);
|
|
652
|
+
console.log();
|
|
653
|
+
console.log(` ${orange(url)}`);
|
|
654
|
+
console.log();
|
|
655
|
+
|
|
656
|
+
try {
|
|
657
|
+
const { default: open } = await import("open");
|
|
658
|
+
await open(url);
|
|
659
|
+
} catch {}
|
|
660
|
+
|
|
661
|
+
console.log(chalk.dim(` After purchasing, wait ~30 seconds for it to arrive.`));
|
|
662
|
+
console.log();
|
|
663
|
+
|
|
664
|
+
// Prompt for next step
|
|
665
|
+
if (asset === "eth") {
|
|
666
|
+
console.log(` ${orange("Next step:")} Run this command again and choose USDC to add spending money.`);
|
|
611
667
|
} else {
|
|
612
|
-
console.log(`
|
|
668
|
+
console.log(` ${orange("Verify your balance:")}`);
|
|
669
|
+
console.log(` ${chalk.dim("$ clawcard agent wallet balance --json")}`);
|
|
613
670
|
}
|
|
671
|
+
console.log();
|
|
614
672
|
} catch (err) {
|
|
615
|
-
|
|
673
|
+
s.stop("Failed");
|
|
616
674
|
console.log(` Error: ${err.message}`);
|
|
617
675
|
}
|
|
618
676
|
}
|
package/src/index.js
CHANGED
|
@@ -248,8 +248,8 @@ agentWallet
|
|
|
248
248
|
});
|
|
249
249
|
agentWallet
|
|
250
250
|
.command("fund")
|
|
251
|
-
.description("Fund wallet
|
|
252
|
-
.
|
|
251
|
+
.description("Fund wallet — buy USDC and ETH via Coinbase")
|
|
252
|
+
.option("--amount <dollars>", "Amount in dollars (skips wizard)")
|
|
253
253
|
.option("--json", "Output as JSON")
|
|
254
254
|
.action(async (options) => {
|
|
255
255
|
const { agentWalletFundCmd } = await import("./commands/agent.js");
|