@madgallery/rbs-pm-sdk 1.0.4 → 1.0.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/SKILL.md +141 -160
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -1,193 +1,100 @@
|
|
|
1
1
|
# RBS Prediction Market Agent Skill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Trade on prediction markets using AI agents on Monad blockchain.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## For Humans: How to Use This Agent
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
>
|
|
11
|
-
> 1. **MON** for gas fees - Get from https://faucet.monad.xyz
|
|
12
|
-
> 2. **USDC** for trading, API calls, and liquidity - Minimum 10 USDC buffer required
|
|
13
|
-
>
|
|
14
|
-
> Please provide me with a private key as the `PRIVATE_KEY` environment variable.
|
|
15
|
-
> The wallet should have at least 0.1 MON and **10 USDC** to operate properly."
|
|
9
|
+
### Step 1: Fund a Wallet
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
Your agent needs a Monad testnet wallet. Set it up:
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
1. Create a new wallet (or use an existing one)
|
|
14
|
+
2. Get **MON** for gas: https://faucet.monad.xyz
|
|
15
|
+
3. Get **USDC** for trading: minimum **10 USDC** required
|
|
16
|
+
4. Set the private key as environment variable: `PRIVATE_KEY=0x...`
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
1. Every API call costs **0.0001 USDC** (paid via x402 protocol)
|
|
23
|
-
2. The SDK signs a USDC `TransferWithAuthorization` using your private key
|
|
24
|
-
3. The payment is verified and settled by the x402 facilitator
|
|
25
|
-
4. You receive the API response
|
|
18
|
+
### Step 2: Talk to Your Agent
|
|
26
19
|
|
|
27
|
-
|
|
20
|
+
Once funded, just talk to your agent naturally:
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Check if x402 payments are configured
|
|
36
|
-
console.log('x402 Enabled:', client.hasPaymentCapability()); // true
|
|
37
|
-
```
|
|
22
|
+
**Check Status:**
|
|
23
|
+
- "What's my balance?"
|
|
24
|
+
- "Show me my portfolio"
|
|
25
|
+
- "Am I ready to trade?"
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
**Explore Markets:**
|
|
28
|
+
- "What prediction markets are available?"
|
|
29
|
+
- "Show me the hottest markets"
|
|
30
|
+
- "What's the price on [market question]?"
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
**Trading:**
|
|
33
|
+
- "Buy $5 of YES on [market]"
|
|
34
|
+
- "I think [event] will happen - bet $10 on it"
|
|
35
|
+
- "Sell my position on [market]"
|
|
36
|
+
- "What positions do I have?"
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
**After Resolution:**
|
|
39
|
+
- "Check if any of my markets resolved"
|
|
40
|
+
- "Redeem my winnings"
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
**Market Creation:**
|
|
43
|
+
- "Create a market about [topic]"
|
|
44
|
+
- "I want to make a prediction market for [event]"
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
import { RBSPMClient } from '@madgallery/rbs-pm-sdk';
|
|
46
|
+
### Example Conversations
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
wallet: string;
|
|
55
|
-
balances: { mon: string; usdc: string };
|
|
56
|
-
portfolio: {
|
|
57
|
-
totalPositions: number;
|
|
58
|
-
totalValue: string;
|
|
59
|
-
positions: Array<{
|
|
60
|
-
market: string;
|
|
61
|
-
question: string;
|
|
62
|
-
value: string;
|
|
63
|
-
resolved: boolean;
|
|
64
|
-
}>;
|
|
65
|
-
};
|
|
66
|
-
newMarkets: Array<{
|
|
67
|
-
address: string;
|
|
68
|
-
question: string;
|
|
69
|
-
yesPrice: number;
|
|
70
|
-
}>;
|
|
71
|
-
canTrade: boolean;
|
|
72
|
-
errors: string[];
|
|
73
|
-
timestamp: number;
|
|
74
|
-
}
|
|
48
|
+
```
|
|
49
|
+
Human: What's my balance?
|
|
75
50
|
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
Agent: Your wallet 0x742d...3a91 has:
|
|
52
|
+
- 0.5 MON (gas)
|
|
53
|
+
- 47.32 USDC (trading balance)
|
|
54
|
+
You're ready to trade!
|
|
55
|
+
```
|
|
78
56
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const timestamp = Date.now();
|
|
57
|
+
```
|
|
58
|
+
Human: What markets can I trade on?
|
|
82
59
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
Agent: I found 3 active markets:
|
|
61
|
+
1. "Will ETH hit $5,000 by March 2026?" - YES: 35%, NO: 65%
|
|
62
|
+
2. "Will Bitcoin exceed $100k in Q1 2026?" - YES: 72%, NO: 28%
|
|
63
|
+
3. "Will SpaceX launch Starship before April?" - YES: 85%, NO: 15%
|
|
87
64
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const mon = await client.getMONBalance();
|
|
65
|
+
Which one interests you?
|
|
66
|
+
```
|
|
91
67
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const hasUsdc = parseFloat(usdc) >= 10; // 10 USDC minimum liquidity buffer
|
|
68
|
+
```
|
|
69
|
+
Human: I think Bitcoin will hit 100k. Bet $10 on it.
|
|
95
70
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
errors.push(`LOW USDC: ${usdc} USDC - Need minimum 10 USDC liquidity buffer`);
|
|
101
|
-
}
|
|
71
|
+
Agent: Placing bet on "Will Bitcoin exceed $100k in Q1 2026?"
|
|
72
|
+
- Side: YES (currently 72%)
|
|
73
|
+
- Amount: $10 USDC
|
|
74
|
+
- Estimated shares: 13.89 YES tokens
|
|
102
75
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
totalPositions: portfolio.summary.totalPositions,
|
|
107
|
-
totalValue: portfolio.summary.totalValue,
|
|
108
|
-
positions: portfolio.positions.map(p => ({
|
|
109
|
-
market: p.marketAddress,
|
|
110
|
-
question: p.marketQuestion,
|
|
111
|
-
value: p.totalValue,
|
|
112
|
-
resolved: p.resolved,
|
|
113
|
-
})),
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Check for positions that need attention (resolved markets)
|
|
117
|
-
const resolvedPositions = portfolio.positions.filter(p => p.resolved);
|
|
118
|
-
if (resolvedPositions.length > 0) {
|
|
119
|
-
errors.push(`${resolvedPositions.length} resolved market(s) - call redeem() to collect winnings`);
|
|
120
|
-
}
|
|
76
|
+
Transaction submitted: 0x7a3f...
|
|
77
|
+
✓ Bought 13.89 YES shares for $10 USDC
|
|
78
|
+
```
|
|
121
79
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const newMarkets = allMarkets
|
|
125
|
-
.filter(m => !knownMarkets.has(m.address))
|
|
126
|
-
.map(m => {
|
|
127
|
-
knownMarkets.add(m.address);
|
|
128
|
-
return {
|
|
129
|
-
address: m.address,
|
|
130
|
-
question: m.question,
|
|
131
|
-
yesPrice: m.yesPrice,
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
healthy: errors.length === 0,
|
|
137
|
-
wallet,
|
|
138
|
-
balances: { mon, usdc },
|
|
139
|
-
portfolio: portfolioSummary,
|
|
140
|
-
newMarkets,
|
|
141
|
-
canTrade: hasGas && hasUsdc,
|
|
142
|
-
errors,
|
|
143
|
-
timestamp,
|
|
144
|
-
};
|
|
145
|
-
} catch (err) {
|
|
146
|
-
return {
|
|
147
|
-
healthy: false,
|
|
148
|
-
wallet: 'unknown',
|
|
149
|
-
balances: { mon: '0', usdc: '0' },
|
|
150
|
-
portfolio: { totalPositions: 0, totalValue: '0', positions: [] },
|
|
151
|
-
newMarkets: [],
|
|
152
|
-
canTrade: false,
|
|
153
|
-
errors: [`HEARTBEAT FAILED: ${err}`],
|
|
154
|
-
timestamp,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
80
|
+
```
|
|
81
|
+
Human: Show me my portfolio
|
|
158
82
|
|
|
159
|
-
|
|
160
|
-
let heartbeatCount = 0;
|
|
83
|
+
Agent: Your portfolio across all markets:
|
|
161
84
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
console.log(`[${new Date().toISOString()}] Heartbeat #${heartbeatCount}:`, status);
|
|
85
|
+
1. "Will Bitcoin exceed $100k in Q1 2026?"
|
|
86
|
+
- 13.89 YES shares worth $10.42
|
|
87
|
+
- Current price: 75% (you bought at 72%)
|
|
88
|
+
- Unrealized P&L: +$0.42
|
|
167
89
|
|
|
168
|
-
|
|
169
|
-
|
|
90
|
+
Total value: $10.42 USDC
|
|
91
|
+
```
|
|
170
92
|
|
|
171
|
-
|
|
172
|
-
if (status.newMarkets.length > 0) {
|
|
173
|
-
console.log(`NEW MARKETS DISCOVERED:`);
|
|
174
|
-
for (const m of status.newMarkets) {
|
|
175
|
-
console.log(` - ${m.question} (YES: ${(m.yesPrice * 100).toFixed(1)}%)`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
93
|
+
---
|
|
178
94
|
|
|
179
|
-
|
|
180
|
-
// Alert human operator
|
|
181
|
-
console.warn('AGENT UNHEALTHY - Notify operator:', status.errors);
|
|
182
|
-
}
|
|
95
|
+
## For Agents: Technical Reference
|
|
183
96
|
|
|
184
|
-
|
|
185
|
-
if (heartbeatCount % 10 === 0 && status.canTrade) {
|
|
186
|
-
console.log(`\n=== MARKET CREATION CYCLE (every 10 heartbeats) ===`);
|
|
187
|
-
await createInterestingMarket();
|
|
188
|
-
}
|
|
189
|
-
}, 10 * 60 * 1000);
|
|
190
|
-
```
|
|
97
|
+
This section contains implementation details for AI agents using the SDK programmatically.
|
|
191
98
|
|
|
192
99
|
## Market Creation
|
|
193
100
|
|
|
@@ -357,6 +264,80 @@ const txHash = await client.redeem(marketAddress);
|
|
|
357
264
|
console.log(`Redeem tx: ${txHash}`);
|
|
358
265
|
```
|
|
359
266
|
|
|
267
|
+
## Heartbeat Monitoring
|
|
268
|
+
|
|
269
|
+
Run this heartbeat check regularly to monitor wallet health, portfolio status, and discover new markets:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { RBSPMClient } from '@madgallery/rbs-pm-sdk';
|
|
273
|
+
|
|
274
|
+
interface HeartbeatStatus {
|
|
275
|
+
healthy: boolean;
|
|
276
|
+
wallet: string;
|
|
277
|
+
balances: { mon: string; usdc: string };
|
|
278
|
+
portfolio: { totalPositions: number; totalValue: string };
|
|
279
|
+
newMarkets: Array<{ address: string; question: string; yesPrice: number }>;
|
|
280
|
+
canTrade: boolean;
|
|
281
|
+
errors: string[];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const knownMarkets = new Set<string>();
|
|
285
|
+
|
|
286
|
+
async function heartbeat(): Promise<HeartbeatStatus> {
|
|
287
|
+
const errors: string[] = [];
|
|
288
|
+
const client = new RBSPMClient({
|
|
289
|
+
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
const wallet = client.getAddress();
|
|
293
|
+
const usdc = await client.getUSDCBalance();
|
|
294
|
+
const mon = await client.getMONBalance();
|
|
295
|
+
|
|
296
|
+
const hasGas = parseFloat(mon) >= 0.01;
|
|
297
|
+
const hasUsdc = parseFloat(usdc) >= 10; // 10 USDC minimum
|
|
298
|
+
|
|
299
|
+
if (!hasGas) errors.push(`LOW GAS: ${mon} MON`);
|
|
300
|
+
if (!hasUsdc) errors.push(`LOW USDC: ${usdc} - need 10 minimum`);
|
|
301
|
+
|
|
302
|
+
// Check portfolio (0.0001 USDC)
|
|
303
|
+
const portfolio = await client.getPortfolio();
|
|
304
|
+
|
|
305
|
+
// Discover new markets (0.0001 USDC)
|
|
306
|
+
const allMarkets = await client.getMarkets();
|
|
307
|
+
const newMarkets = allMarkets
|
|
308
|
+
.filter(m => !knownMarkets.has(m.address))
|
|
309
|
+
.map(m => {
|
|
310
|
+
knownMarkets.add(m.address);
|
|
311
|
+
return { address: m.address, question: m.question, yesPrice: m.yesPrice };
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
healthy: errors.length === 0,
|
|
316
|
+
wallet,
|
|
317
|
+
balances: { mon, usdc },
|
|
318
|
+
portfolio: {
|
|
319
|
+
totalPositions: portfolio.summary.totalPositions,
|
|
320
|
+
totalValue: portfolio.summary.totalValue,
|
|
321
|
+
},
|
|
322
|
+
newMarkets,
|
|
323
|
+
canTrade: hasGas && hasUsdc,
|
|
324
|
+
errors,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Run every 10 minutes, create market every 10 cycles
|
|
329
|
+
let heartbeatCount = 0;
|
|
330
|
+
setInterval(async () => {
|
|
331
|
+
heartbeatCount++;
|
|
332
|
+
const status = await heartbeat();
|
|
333
|
+
console.log(`Heartbeat #${heartbeatCount}:`, status);
|
|
334
|
+
|
|
335
|
+
if (heartbeatCount % 10 === 0 && status.canTrade) {
|
|
336
|
+
await createInterestingMarket();
|
|
337
|
+
}
|
|
338
|
+
}, 10 * 60 * 1000);
|
|
339
|
+
```
|
|
340
|
+
|
|
360
341
|
## Trading Strategy Template
|
|
361
342
|
|
|
362
343
|
```typescript
|