@clawcard/cli 3.0.13 → 3.0.14
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 +85 -33
- package/src/index.js +2 -2
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -571,48 +571,100 @@ export async function agentWalletTransactionsCmd(options) {
|
|
|
571
571
|
}
|
|
572
572
|
|
|
573
573
|
export async function agentWalletFundCmd(options) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (options.
|
|
577
|
-
|
|
578
|
-
|
|
574
|
+
// JSON mode — pass through to API directly
|
|
575
|
+
if (options.json) {
|
|
576
|
+
if (!options.amount) return output({ success: false, error: "--amount required" }, true);
|
|
577
|
+
const agentId = await getAgentId();
|
|
578
|
+
try {
|
|
579
|
+
const result = await walletFund(agentId, options.amount);
|
|
580
|
+
return output(result, true);
|
|
581
|
+
} catch (err) {
|
|
582
|
+
return output({ success: false, error: err.message }, true);
|
|
583
|
+
}
|
|
579
584
|
}
|
|
580
585
|
|
|
586
|
+
// Interactive wizard
|
|
587
|
+
const prompts = await import("@clack/prompts");
|
|
581
588
|
const agentId = await getAgentId();
|
|
589
|
+
|
|
590
|
+
console.log();
|
|
591
|
+
console.log(` ${orange.bold("Fund Your Agent's Wallet")}`);
|
|
592
|
+
console.log();
|
|
593
|
+
console.log(chalk.dim(" Your agent's wallet uses USDC (a stablecoin pegged to $1) on the Base network."));
|
|
594
|
+
console.log(chalk.dim(" To send USDC, your wallet also needs a tiny bit of ETH for transaction fees."));
|
|
595
|
+
console.log(chalk.dim(" $1 of ETH covers thousands of transactions."));
|
|
596
|
+
console.log();
|
|
597
|
+
|
|
598
|
+
// Step 1: What to buy
|
|
599
|
+
const asset = await prompts.select({
|
|
600
|
+
message: "What would you like to purchase?",
|
|
601
|
+
options: [
|
|
602
|
+
{ value: "eth", label: "ETH (for gas fees)", hint: "buy this first — $1-2 is plenty" },
|
|
603
|
+
{ value: "usdc", label: "USDC (spending money)", hint: "your agent uses this to pay for things" },
|
|
604
|
+
],
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
if (prompts.isCancel(asset)) return;
|
|
608
|
+
|
|
609
|
+
// Step 2: Amount
|
|
610
|
+
const defaultAmount = asset === "eth" ? "2" : "10";
|
|
611
|
+
const amountInput = await prompts.text({
|
|
612
|
+
message: `How much $ of ${asset === "eth" ? "ETH" : "USDC"} do you want to buy?`,
|
|
613
|
+
placeholder: defaultAmount,
|
|
614
|
+
defaultValue: defaultAmount,
|
|
615
|
+
validate: (v) => {
|
|
616
|
+
const n = parseFloat(v);
|
|
617
|
+
if (isNaN(n) || n < 1) return "Minimum is $1.00";
|
|
618
|
+
},
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
if (prompts.isCancel(amountInput)) return;
|
|
622
|
+
|
|
623
|
+
const amount = parseFloat(amountInput);
|
|
624
|
+
|
|
625
|
+
// Step 3: Open Coinbase
|
|
626
|
+
const s = prompts.spinner();
|
|
627
|
+
s.start("Preparing Coinbase checkout...");
|
|
628
|
+
|
|
582
629
|
try {
|
|
583
|
-
const result = await walletFund(agentId,
|
|
584
|
-
|
|
630
|
+
const result = await walletFund(agentId, String(amount));
|
|
631
|
+
s.stop("");
|
|
585
632
|
|
|
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();
|
|
633
|
+
if (!result.success) {
|
|
634
|
+
console.log(` Error: ${result.error}`);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
598
637
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
638
|
+
// Swap the default asset in the URL if they chose ETH
|
|
639
|
+
let url = result.url;
|
|
640
|
+
if (asset === "eth") {
|
|
641
|
+
url = url.replace("defaultAsset=USDC", "defaultAsset=ETH");
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
console.log();
|
|
645
|
+
console.log(` ${chalk.green("Opening Coinbase...")} Buy $${amount.toFixed(2)} of ${asset === "eth" ? "ETH" : "USDC"}`);
|
|
646
|
+
console.log();
|
|
647
|
+
console.log(` ${orange(url)}`);
|
|
648
|
+
console.log();
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
const { default: open } = await import("open");
|
|
652
|
+
await open(url);
|
|
653
|
+
} catch {}
|
|
654
|
+
|
|
655
|
+
console.log(chalk.dim(` After purchasing, wait ~30 seconds for it to arrive.`));
|
|
656
|
+
console.log();
|
|
657
|
+
|
|
658
|
+
// Prompt for next step
|
|
659
|
+
if (asset === "eth") {
|
|
660
|
+
console.log(` ${orange("Next step:")} Run this command again and choose USDC to add spending money.`);
|
|
611
661
|
} else {
|
|
612
|
-
console.log(`
|
|
662
|
+
console.log(` ${orange("Verify your balance:")}`);
|
|
663
|
+
console.log(` ${chalk.dim("$ clawcard agent wallet balance --json")}`);
|
|
613
664
|
}
|
|
665
|
+
console.log();
|
|
614
666
|
} catch (err) {
|
|
615
|
-
|
|
667
|
+
s.stop("Failed");
|
|
616
668
|
console.log(` Error: ${err.message}`);
|
|
617
669
|
}
|
|
618
670
|
}
|
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");
|