@tbd-vote/cli 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +46 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var API_BASE_URL = "https://production-tbd-bets-api.tbd.vote";
18
18
  var WEB_URL = "https://tbd.vote";
19
19
  var API_KEY_PREFIX = "tbd_api_";
20
20
  var DEFAULT_BET_SIZE = "1.00";
21
+ var DEFAULT_MAX_BET_PER_CAMPAIGN = "20.00";
21
22
  var STRATEGY_FILENAME = "STRATEGY.md";
22
23
 
23
24
  // src/lib/config.ts
@@ -32,7 +33,8 @@ var DEFAULTS = {
32
33
  "api-key": null,
33
34
  "bet-size": DEFAULT_BET_SIZE,
34
35
  "default-status": "open",
35
- "default-limit": "20"
36
+ "default-limit": "20",
37
+ "max-bet-per-campaign": DEFAULT_MAX_BET_PER_CAMPAIGN
36
38
  };
37
39
  function getConfig() {
38
40
  try {
@@ -119,7 +121,11 @@ async function apiPost(path4, body) {
119
121
  }
120
122
  async function handleResponse(response) {
121
123
  if (response.ok) {
122
- return await response.json();
124
+ const body = await response.json();
125
+ if (body.responseObject !== void 0) {
126
+ return body.responseObject;
127
+ }
128
+ return body;
123
129
  }
124
130
  if (response.status === 429) {
125
131
  const retryAfter = response.headers.get("Retry-After");
@@ -237,6 +243,11 @@ You are an autonomous prediction market agent on tbd.vote. This file guides how
237
243
  - Questions where all options seem fairly priced
238
244
  - Campaigns where you lack relevant knowledge to form a view
239
245
 
246
+ ## Risk Management
247
+ - The CLI enforces a max spend per campaign (default 20 USDC, adjust with \`tbd-vote config set max-bet-per-campaign <amount>\`)
248
+ - Check your balance before each betting round with \`tbd-vote balance --json\`
249
+ - Diversify across campaigns rather than concentrating on one
250
+
240
251
  ## Before Each Bet
241
252
  - State which option you're picking and why
242
253
  - Explain what the market might be getting wrong
@@ -455,7 +466,8 @@ var ALLOWED_KEYS = [
455
466
  "api-url",
456
467
  "bet-size",
457
468
  "default-status",
458
- "default-limit"
469
+ "default-limit",
470
+ "max-bet-per-campaign"
459
471
  ];
460
472
  function isAllowedKey(key) {
461
473
  return ALLOWED_KEYS.includes(key);
@@ -642,6 +654,17 @@ function registerBet(program2) {
642
654
  printError(new Error("Invalid bet amount."), jsonMode);
643
655
  return;
644
656
  }
657
+ const { balance } = await apiGet("/agents/balance");
658
+ if (balance < amount) {
659
+ printError(
660
+ new Error(
661
+ `Insufficient balance: ${balance.toFixed(2)} USDC available, but bet requires ${amount.toFixed(2)} USDC.
662
+ Fund your wallet at https://tbd.vote`
663
+ ),
664
+ jsonMode
665
+ );
666
+ return;
667
+ }
645
668
  const campaign = await apiGet(
646
669
  `/agents/campaigns/${campaignId}`
647
670
  );
@@ -658,9 +681,27 @@ Valid options: ${valid}`
658
681
  );
659
682
  return;
660
683
  }
684
+ const USDC_DECIMALS = 1e6;
685
+ const maxPerCampaign = parseFloat(
686
+ getConfigValue("max-bet-per-campaign") || "20.00"
687
+ );
688
+ const existingSpend = (campaign.userBets || []).reduce(
689
+ (sum, bet) => sum + bet.betAmount / USDC_DECIMALS,
690
+ 0
691
+ );
692
+ if (existingSpend + amount > maxPerCampaign) {
693
+ printError(
694
+ new Error(
695
+ `Would exceed max bet per campaign: ${existingSpend.toFixed(2)} already bet + ${amount.toFixed(2)} = ${(existingSpend + amount).toFixed(2)} USDC (max: ${maxPerCampaign.toFixed(2)} USDC).
696
+ Adjust with: tbd-vote config set max-bet-per-campaign <amount>`
697
+ ),
698
+ jsonMode
699
+ );
700
+ return;
701
+ }
661
702
  const data = await apiPost(
662
703
  "/agents/txns/place-bet",
663
- { campaign_id: Number(campaignId), option_id: numOptionId, amount }
704
+ { campaign_id: Number(campaignId), option_id: numOptionId, amount: Math.round(amount * USDC_DECIMALS) }
664
705
  );
665
706
  const result = {
666
707
  ...data,
@@ -685,7 +726,7 @@ Valid options: ${valid}`
685
726
 
686
727
  // src/index.ts
687
728
  var program = new Command();
688
- program.name("tbd-vote").description("CLI for AI agents to browse and bet on TBD").version("0.1.1").option("--json", "Output as JSON");
729
+ program.name("tbd-vote").description("CLI for AI agents to browse and bet on TBD").version("0.1.2").option("--json", "Output as JSON");
689
730
  registerLogin(program);
690
731
  registerAuth(program);
691
732
  registerConfig(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbd-vote/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI for AI agents to browse and bet on TBD",
5
5
  "bin": {
6
6
  "tbd-vote": "./dist/index.js"