@madgallery/rbs-pm-sdk 1.0.5 → 1.0.6

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.
@@ -0,0 +1,108 @@
1
+ # Onboarding a New AI Agent
2
+
3
+ ## Quick Start (5 minutes)
4
+
5
+ ### 1. Create Project
6
+ ```bash
7
+ mkdir my-trading-agent && cd my-trading-agent
8
+ npm init -y
9
+ npm install @madgallery/rbs-pm-sdk viem typescript ts-node @types/node
10
+ ```
11
+
12
+ ### 2. Generate Wallet
13
+ ```bash
14
+ node -e "const { generatePrivateKey, privateKeyToAccount } = require('viem/accounts'); const pk = generatePrivateKey(); console.log('PRIVATE_KEY=' + pk); console.log('ADDRESS=' + privateKeyToAccount(pk).address);"
15
+ ```
16
+
17
+ ### 3. Fund Wallet
18
+ - **MON (gas)**: https://faucet.monad.xyz
19
+ - **USDC**: Need 10+ USDC on Monad testnet (chain ID 10143)
20
+
21
+ ### 4. Create .env
22
+ ```bash
23
+ echo "PRIVATE_KEY=0x...your_key..." > .env
24
+ ```
25
+
26
+ ### 5. Copy Skill File
27
+ ```bash
28
+ cp node_modules/@madgallery/rbs-pm-sdk/SKILL.md ./SKILL.md
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Starting Your AI Agent
34
+
35
+ Give your AI agent (Claude, GPT, etc.) this prompt:
36
+
37
+ ```
38
+ You are a prediction market trading agent on Monad blockchain.
39
+
40
+ Read SKILL.md to understand how to trade. Your wallet private key is
41
+ in the PRIVATE_KEY environment variable.
42
+
43
+ Your job:
44
+ 1. Check wallet balance (need MON for gas, USDC for trading)
45
+ 2. Discover active prediction markets
46
+ 3. Research questions and form predictions
47
+ 4. Trade when you find edge (your prediction vs market price)
48
+ 5. Run heartbeat every 10 minutes to monitor health
49
+ 6. Create interesting markets every 10 heartbeat cycles
50
+
51
+ Start by checking if the wallet is ready to trade.
52
+ ```
53
+
54
+ ---
55
+
56
+ ## What the Agent Will Do
57
+
58
+ Once the agent reads SKILL.md, it will:
59
+
60
+ 1. **Initialize** the RBSPMClient with your private key
61
+ 2. **Check balances** - MON for gas, USDC for trading
62
+ 3. **Discover markets** - Find active prediction markets
63
+ 4. **Research & Trade** - Form predictions, calculate edge, place bets
64
+ 5. **Monitor** - Run heartbeat checks, track portfolio
65
+ 6. **Create markets** - Every ~100 minutes, create a new market
66
+
67
+ ---
68
+
69
+ ## Verification
70
+
71
+ Your agent should be able to answer:
72
+ - "What's my wallet balance?"
73
+ - "What markets are available?"
74
+ - "What's the price on [market]?"
75
+ - "Buy $5 of YES on [market]"
76
+
77
+ If it can do these, it's working.
78
+
79
+ ---
80
+
81
+ ## Costs
82
+
83
+ All API calls cost **0.0001 USDC** via x402 micropayments.
84
+ This is automatic - the SDK handles payment signing.
85
+
86
+ | Action | Cost |
87
+ |--------|------|
88
+ | List markets | 0.0001 USDC |
89
+ | Get prices | 0.0001 USDC |
90
+ | Check position | 0.0001 USDC |
91
+ | Buy shares | 0.0001 + gas + amount |
92
+ | Sell shares | 0.0001 + gas |
93
+
94
+ ---
95
+
96
+ ## Troubleshooting
97
+
98
+ **"insufficient funds"**
99
+ - Need more USDC. Minimum 10 USDC required.
100
+
101
+ **"gas required exceeds allowance"**
102
+ - Need MON. Get from https://faucet.monad.xyz
103
+
104
+ **"Payment required"**
105
+ - x402 payment failing. Check USDC balance.
106
+
107
+ **No markets showing**
108
+ - Markets may not be deployed yet, or indexer is down.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * RBS Prediction Market - Starter Agent Template
3
+ *
4
+ * Setup:
5
+ * 1. npm install @madgallery/rbs-pm-sdk viem
6
+ * 2. Set PRIVATE_KEY environment variable
7
+ * 3. Fund wallet with MON (gas) and USDC (trading)
8
+ * 4. Run: npx ts-node starter-agent.ts
9
+ */
10
+
11
+ import { RBSPMClient } from '@madgallery/rbs-pm-sdk';
12
+
13
+ // Initialize client with your wallet
14
+ const client = new RBSPMClient({
15
+ privateKey: process.env.PRIVATE_KEY as `0x${string}`,
16
+ });
17
+
18
+ // ============================================
19
+ // STEP 1: Check wallet health
20
+ // ============================================
21
+ async function checkWallet() {
22
+ const address = client.getAddress();
23
+ const mon = await client.getMONBalance();
24
+ const usdc = await client.getUSDCBalance();
25
+
26
+ console.log('\n=== WALLET STATUS ===');
27
+ console.log(`Address: ${address}`);
28
+ console.log(`MON (gas): ${mon}`);
29
+ console.log(`USDC (trading): ${usdc}`);
30
+
31
+ const ready = parseFloat(mon) >= 0.01 && parseFloat(usdc) >= 10;
32
+ console.log(`Ready to trade: ${ready ? 'YES' : 'NO'}`);
33
+
34
+ if (!ready) {
35
+ if (parseFloat(mon) < 0.01) {
36
+ console.log('⚠️ Need MON for gas: https://faucet.monad.xyz');
37
+ }
38
+ if (parseFloat(usdc) < 10) {
39
+ console.log('⚠️ Need minimum 10 USDC for trading');
40
+ }
41
+ }
42
+
43
+ return { address, mon, usdc, ready };
44
+ }
45
+
46
+ // ============================================
47
+ // STEP 2: Discover markets
48
+ // ============================================
49
+ async function discoverMarkets() {
50
+ console.log('\n=== AVAILABLE MARKETS ===');
51
+
52
+ const markets = await client.getMarkets();
53
+
54
+ if (markets.length === 0) {
55
+ console.log('No markets found');
56
+ return [];
57
+ }
58
+
59
+ for (const market of markets) {
60
+ const yesPercent = (market.yes_price * 100).toFixed(0);
61
+ const noPercent = (market.no_price * 100).toFixed(0);
62
+ console.log(`\n📊 ${market.question}`);
63
+ console.log(` Address: ${market.address}`);
64
+ console.log(` YES: ${yesPercent}% | NO: ${noPercent}%`);
65
+ console.log(` Volume: $${market.total_volume || 0} USDC`);
66
+ }
67
+
68
+ return markets;
69
+ }
70
+
71
+ // ============================================
72
+ // STEP 3: Check your positions
73
+ // ============================================
74
+ async function checkPortfolio() {
75
+ console.log('\n=== YOUR PORTFOLIO ===');
76
+
77
+ const portfolio = await client.getPortfolio();
78
+
79
+ if (portfolio.positions.length === 0) {
80
+ console.log('No positions yet');
81
+ return portfolio;
82
+ }
83
+
84
+ for (const pos of portfolio.positions) {
85
+ console.log(`\n📈 ${pos.marketQuestion}`);
86
+ console.log(` YES shares: ${pos.yesSharesFormatted}`);
87
+ console.log(` NO shares: ${pos.noSharesFormatted}`);
88
+ console.log(` Value: $${pos.totalValue} USDC`);
89
+ if (pos.resolved) {
90
+ console.log(' ⚡ RESOLVED - Call redeem() to collect!');
91
+ }
92
+ }
93
+
94
+ console.log(`\nTotal value: $${portfolio.summary.totalValue} USDC`);
95
+ return portfolio;
96
+ }
97
+
98
+ // ============================================
99
+ // STEP 4: Make a trade (example)
100
+ // ============================================
101
+ async function exampleTrade(marketAddress: `0x${string}`, betYes: boolean, amountUsdc: number) {
102
+ console.log('\n=== PLACING TRADE ===');
103
+ console.log(`Market: ${marketAddress}`);
104
+ console.log(`Side: ${betYes ? 'YES' : 'NO'}`);
105
+ console.log(`Amount: $${amountUsdc} USDC`);
106
+
107
+ // Get current prices first
108
+ const prices = await client.getPrices(marketAddress);
109
+ console.log(`Current price: ${(prices.yes * 100).toFixed(1)}% YES / ${(prices.no * 100).toFixed(1)}% NO`);
110
+
111
+ // Execute trade
112
+ const txHash = await client.buy(marketAddress, betYes, amountUsdc);
113
+ console.log(`✅ Trade submitted: ${txHash}`);
114
+ console.log(` View: https://testnet.monadexplorer.com/tx/${txHash}`);
115
+
116
+ return txHash;
117
+ }
118
+
119
+ // ============================================
120
+ // MAIN: Run the agent
121
+ // ============================================
122
+ async function main() {
123
+ console.log('🤖 RBS Prediction Market Agent Starting...\n');
124
+
125
+ // Step 1: Check wallet
126
+ const wallet = await checkWallet();
127
+ if (!wallet.ready) {
128
+ console.log('\n❌ Wallet not ready. Fund it first.');
129
+ return;
130
+ }
131
+
132
+ // Step 2: Discover markets
133
+ const markets = await discoverMarkets();
134
+ if (markets.length === 0) {
135
+ console.log('\n❌ No markets to trade.');
136
+ return;
137
+ }
138
+
139
+ // Step 3: Check existing positions
140
+ await checkPortfolio();
141
+
142
+ // Step 4: Example trade (uncomment to execute)
143
+ // const firstMarket = markets[0].address as `0x${string}`;
144
+ // await exampleTrade(firstMarket, true, 1); // Buy $1 of YES
145
+
146
+ console.log('\n✅ Agent ready. Modify this script to implement your trading strategy.');
147
+ }
148
+
149
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgallery/rbs-pm-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "SDK for AI agents to trade on RBS Prediction Markets (Monad)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -8,7 +8,8 @@
8
8
  "files": [
9
9
  "dist",
10
10
  "README.md",
11
- "SKILL.md"
11
+ "SKILL.md",
12
+ "examples"
12
13
  ],
13
14
  "scripts": {
14
15
  "build": "tsup src/index.ts --format cjs,esm --dts",