@madgallery/rbs-pm-sdk 1.0.1 → 1.0.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.
- package/README.md +7 -2
- package/SKILL.md +71 -2
- package/dist/index.d.mts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +65 -4
- package/dist/index.mjs +65 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,8 @@ console.log('Trade TX:', result.txHash);
|
|
|
51
51
|
| `getMarkets()` | 0.0001 USDC | List all active markets |
|
|
52
52
|
| `getPrices()` | 0.0001 USDC | Get current market prices |
|
|
53
53
|
| `getMarketInfo()` | 0.0001 USDC | Full market details |
|
|
54
|
-
| `getPosition()` | 0.0001 USDC | Check your
|
|
54
|
+
| `getPosition()` | 0.0001 USDC | Check your position in one market |
|
|
55
|
+
| `getPortfolio()` | 0.0001 USDC | Get all positions across all markets |
|
|
55
56
|
| `buy()` | 0.0001 + gas + amount | Buy shares (x402 + on-chain) |
|
|
56
57
|
| `sell()` | 0.0001 + gas | Sell shares (x402 + on-chain) |
|
|
57
58
|
| `redeem()` | 0.0001 + gas | Redeem winnings (x402 + on-chain) |
|
|
@@ -73,9 +74,13 @@ const prices = await client.getPrices(marketAddress);
|
|
|
73
74
|
const info = await client.getMarketInfo(marketAddress);
|
|
74
75
|
// { question, oracle, resolutionTime, resolved, ... }
|
|
75
76
|
|
|
76
|
-
// Get your position
|
|
77
|
+
// Get your position in one market
|
|
77
78
|
const position = await client.getPosition(marketAddress);
|
|
78
79
|
// { yesShares, noShares, yesSharesFormatted, noSharesFormatted }
|
|
80
|
+
|
|
81
|
+
// Get full portfolio (all positions across all markets)
|
|
82
|
+
const portfolio = await client.getPortfolio();
|
|
83
|
+
// { positions: [...], summary: { totalPositions, totalValue } }
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
### Trading
|
package/SKILL.md
CHANGED
|
@@ -22,7 +22,7 @@ npm install @madgallery/rbs-pm-sdk viem
|
|
|
22
22
|
|
|
23
23
|
## Heartbeat
|
|
24
24
|
|
|
25
|
-
Run this heartbeat check regularly to
|
|
25
|
+
Run this heartbeat check regularly to monitor wallet health, portfolio status, and discover new markets:
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
28
|
import { RBSPMClient } from '@madgallery/rbs-pm-sdk';
|
|
@@ -31,11 +31,29 @@ interface HeartbeatStatus {
|
|
|
31
31
|
healthy: boolean;
|
|
32
32
|
wallet: string;
|
|
33
33
|
balances: { mon: string; usdc: string };
|
|
34
|
+
portfolio: {
|
|
35
|
+
totalPositions: number;
|
|
36
|
+
totalValue: string;
|
|
37
|
+
positions: Array<{
|
|
38
|
+
market: string;
|
|
39
|
+
question: string;
|
|
40
|
+
value: string;
|
|
41
|
+
resolved: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
newMarkets: Array<{
|
|
45
|
+
address: string;
|
|
46
|
+
question: string;
|
|
47
|
+
yesPrice: number;
|
|
48
|
+
}>;
|
|
34
49
|
canTrade: boolean;
|
|
35
50
|
errors: string[];
|
|
36
51
|
timestamp: number;
|
|
37
52
|
}
|
|
38
53
|
|
|
54
|
+
// Track markets we've already seen
|
|
55
|
+
const knownMarkets = new Set<string>();
|
|
56
|
+
|
|
39
57
|
async function heartbeat(): Promise<HeartbeatStatus> {
|
|
40
58
|
const errors: string[] = [];
|
|
41
59
|
const timestamp = Date.now();
|
|
@@ -60,10 +78,44 @@ async function heartbeat(): Promise<HeartbeatStatus> {
|
|
|
60
78
|
errors.push(`LOW USDC: ${usdc} USDC - Cannot make API calls or trades`);
|
|
61
79
|
}
|
|
62
80
|
|
|
81
|
+
// Check portfolio health (costs 0.0001 USDC)
|
|
82
|
+
const portfolio = await client.getPortfolio();
|
|
83
|
+
const portfolioSummary = {
|
|
84
|
+
totalPositions: portfolio.summary.totalPositions,
|
|
85
|
+
totalValue: portfolio.summary.totalValue,
|
|
86
|
+
positions: portfolio.positions.map(p => ({
|
|
87
|
+
market: p.marketAddress,
|
|
88
|
+
question: p.marketQuestion,
|
|
89
|
+
value: p.totalValue,
|
|
90
|
+
resolved: p.resolved,
|
|
91
|
+
})),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Check for positions that need attention (resolved markets)
|
|
95
|
+
const resolvedPositions = portfolio.positions.filter(p => p.resolved);
|
|
96
|
+
if (resolvedPositions.length > 0) {
|
|
97
|
+
errors.push(`${resolvedPositions.length} resolved market(s) - call redeem() to collect winnings`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Discover new markets (costs 0.0001 USDC)
|
|
101
|
+
const allMarkets = await client.getMarkets();
|
|
102
|
+
const newMarkets = allMarkets
|
|
103
|
+
.filter(m => !knownMarkets.has(m.address))
|
|
104
|
+
.map(m => {
|
|
105
|
+
knownMarkets.add(m.address);
|
|
106
|
+
return {
|
|
107
|
+
address: m.address,
|
|
108
|
+
question: m.question,
|
|
109
|
+
yesPrice: m.yesPrice,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
63
113
|
return {
|
|
64
114
|
healthy: errors.length === 0,
|
|
65
115
|
wallet,
|
|
66
116
|
balances: { mon, usdc },
|
|
117
|
+
portfolio: portfolioSummary,
|
|
118
|
+
newMarkets,
|
|
67
119
|
canTrade: hasGas && hasUsdc,
|
|
68
120
|
errors,
|
|
69
121
|
timestamp,
|
|
@@ -73,6 +125,8 @@ async function heartbeat(): Promise<HeartbeatStatus> {
|
|
|
73
125
|
healthy: false,
|
|
74
126
|
wallet: 'unknown',
|
|
75
127
|
balances: { mon: '0', usdc: '0' },
|
|
128
|
+
portfolio: { totalPositions: 0, totalValue: '0', positions: [] },
|
|
129
|
+
newMarkets: [],
|
|
76
130
|
canTrade: false,
|
|
77
131
|
errors: [`HEARTBEAT FAILED: ${err}`],
|
|
78
132
|
timestamp,
|
|
@@ -85,6 +139,17 @@ setInterval(async () => {
|
|
|
85
139
|
const status = await heartbeat();
|
|
86
140
|
console.log(`[${new Date().toISOString()}] Heartbeat:`, status);
|
|
87
141
|
|
|
142
|
+
// Log portfolio summary
|
|
143
|
+
console.log(`Portfolio: ${status.portfolio.totalPositions} positions worth $${status.portfolio.totalValue}`);
|
|
144
|
+
|
|
145
|
+
// Alert on new markets
|
|
146
|
+
if (status.newMarkets.length > 0) {
|
|
147
|
+
console.log(`NEW MARKETS DISCOVERED:`);
|
|
148
|
+
for (const m of status.newMarkets) {
|
|
149
|
+
console.log(` - ${m.question} (YES: ${(m.yesPrice * 100).toFixed(1)}%)`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
88
153
|
if (!status.healthy) {
|
|
89
154
|
// Alert human operator
|
|
90
155
|
console.warn('AGENT UNHEALTHY - Notify operator:', status.errors);
|
|
@@ -283,9 +348,13 @@ All API calls require x402 micropayments (automatic):
|
|
|
283
348
|
| `getMarkets()` | 0.0001 USDC | List all markets with stats |
|
|
284
349
|
| `getPrices(market)` | 0.0001 USDC | On-chain prices |
|
|
285
350
|
| `getMarketInfo(market)` | 0.0001 USDC | Full market details |
|
|
286
|
-
| `getPosition(market)` | 0.0001 USDC | Your position |
|
|
351
|
+
| `getPosition(market)` | 0.0001 USDC | Your position in single market |
|
|
352
|
+
| `getPortfolio()` | 0.0001 USDC | Full portfolio (all positions) |
|
|
287
353
|
| `getMarketData(market)` | 0.0001 USDC | Premium analytics |
|
|
288
354
|
| `getTradeInstructions()` | 0.0001 USDC | Encoded calldata |
|
|
355
|
+
| `buy()` | 0.0001 + gas + amount | Buy shares |
|
|
356
|
+
| `sell()` | 0.0001 + gas | Sell shares |
|
|
357
|
+
| `redeem()` | 0.0001 + gas | Redeem winnings |
|
|
289
358
|
|
|
290
359
|
## Network Configuration
|
|
291
360
|
|
package/dist/index.d.mts
CHANGED
|
@@ -47,6 +47,31 @@ interface Position {
|
|
|
47
47
|
noValue: bigint;
|
|
48
48
|
totalValue: bigint;
|
|
49
49
|
}
|
|
50
|
+
/** Portfolio position for a single market */
|
|
51
|
+
interface PortfolioPosition {
|
|
52
|
+
marketAddress: `0x${string}`;
|
|
53
|
+
marketQuestion: string;
|
|
54
|
+
yesShares: bigint;
|
|
55
|
+
noShares: bigint;
|
|
56
|
+
yesSharesFormatted: string;
|
|
57
|
+
noSharesFormatted: string;
|
|
58
|
+
currentYesPrice: number;
|
|
59
|
+
currentNoPrice: number;
|
|
60
|
+
yesValue: string;
|
|
61
|
+
noValue: string;
|
|
62
|
+
totalValue: string;
|
|
63
|
+
resolved: boolean;
|
|
64
|
+
yesWins: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Full portfolio with all positions and summary */
|
|
67
|
+
interface Portfolio {
|
|
68
|
+
positions: PortfolioPosition[];
|
|
69
|
+
summary: {
|
|
70
|
+
totalPositions: number;
|
|
71
|
+
totalValue: string;
|
|
72
|
+
marketsWithPositions: number;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
50
75
|
interface MoltbookAgent {
|
|
51
76
|
id: string;
|
|
52
77
|
name: string;
|
|
@@ -324,6 +349,24 @@ declare class RBSPMClient {
|
|
|
324
349
|
* Get user's position in a market (requires x402 payment - 0.0001 USDC)
|
|
325
350
|
*/
|
|
326
351
|
getPosition(marketAddress: `0x${string}`, userAddress?: `0x${string}`): Promise<Position>;
|
|
352
|
+
/**
|
|
353
|
+
* Get full portfolio with all positions across all markets (requires x402 payment - 0.0001 USDC)
|
|
354
|
+
*
|
|
355
|
+
* Returns all markets where the user has a position, with current values and P&L.
|
|
356
|
+
* Use this for portfolio health checks and monitoring.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const portfolio = await client.getPortfolio();
|
|
361
|
+
* console.log(`Total positions: ${portfolio.summary.totalPositions}`);
|
|
362
|
+
* console.log(`Total value: $${portfolio.summary.totalValue} USDC`);
|
|
363
|
+
*
|
|
364
|
+
* for (const position of portfolio.positions) {
|
|
365
|
+
* console.log(`${position.marketQuestion}: ${position.totalValue} USDC`);
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
getPortfolio(userAddress?: `0x${string}`): Promise<Portfolio>;
|
|
327
370
|
/**
|
|
328
371
|
* Get USDC balance
|
|
329
372
|
*/
|
|
@@ -439,6 +482,26 @@ declare class RBSPMClient {
|
|
|
439
482
|
formatted: string;
|
|
440
483
|
description: string;
|
|
441
484
|
};
|
|
485
|
+
prices: {
|
|
486
|
+
raw: "100";
|
|
487
|
+
formatted: string;
|
|
488
|
+
description: string;
|
|
489
|
+
};
|
|
490
|
+
marketInfo: {
|
|
491
|
+
raw: "100";
|
|
492
|
+
formatted: string;
|
|
493
|
+
description: string;
|
|
494
|
+
};
|
|
495
|
+
position: {
|
|
496
|
+
raw: "100";
|
|
497
|
+
formatted: string;
|
|
498
|
+
description: string;
|
|
499
|
+
};
|
|
500
|
+
portfolio: {
|
|
501
|
+
raw: "100";
|
|
502
|
+
formatted: string;
|
|
503
|
+
description: string;
|
|
504
|
+
};
|
|
442
505
|
marketData: {
|
|
443
506
|
raw: "100";
|
|
444
507
|
formatted: string;
|
|
@@ -481,6 +544,7 @@ declare const API_ENDPOINTS: {
|
|
|
481
544
|
readonly x402Prices: "/functions/v1/x402-prices";
|
|
482
545
|
readonly x402MarketInfo: "/functions/v1/x402-market-info";
|
|
483
546
|
readonly x402Position: "/functions/v1/x402-position";
|
|
547
|
+
readonly x402Portfolio: "/functions/v1/x402-portfolio";
|
|
484
548
|
readonly x402MarketData: "/functions/v1/x402-market-data";
|
|
485
549
|
readonly x402AgentTrade: "/functions/v1/x402-agent-trade";
|
|
486
550
|
readonly x402Resolve: "/functions/v1/x402-resolve";
|
|
@@ -500,6 +564,7 @@ declare const X402_CONFIG: {
|
|
|
500
564
|
readonly prices: "100";
|
|
501
565
|
readonly marketInfo: "100";
|
|
502
566
|
readonly position: "100";
|
|
567
|
+
readonly portfolio: "100";
|
|
503
568
|
readonly marketData: "100";
|
|
504
569
|
readonly tradeInstructions: "100";
|
|
505
570
|
readonly resolve: "100";
|
|
@@ -901,4 +966,4 @@ declare function checkX402Balance(publicClient: {
|
|
|
901
966
|
required: bigint;
|
|
902
967
|
}>;
|
|
903
968
|
|
|
904
|
-
export { ADDRESSES, API_CONFIG, API_ENDPOINTS, type AuthResult, ERC20_ABI, LSLMSR_ABI, LSLMSR_DEPLOY_PARAMS, MONAD_TESTNET, type Market, type MarketCreateParams, type MarketCreateResult, type MarketPrices, type MoltbookAgent, type Position, type PremiumMarketData, RBSPMClient, type RBSPMConfig, type TradeQuote, type TradeResult, type X402Prices, X402_CONFIG, checkX402Balance, createX402Fetch, RBSPMClient as default };
|
|
969
|
+
export { ADDRESSES, API_CONFIG, API_ENDPOINTS, type AuthResult, ERC20_ABI, LSLMSR_ABI, LSLMSR_DEPLOY_PARAMS, MONAD_TESTNET, type Market, type MarketCreateParams, type MarketCreateResult, type MarketPrices, type MoltbookAgent, type Portfolio, type PortfolioPosition, type Position, type PremiumMarketData, RBSPMClient, type RBSPMConfig, type TradeQuote, type TradeResult, type X402Prices, X402_CONFIG, checkX402Balance, createX402Fetch, RBSPMClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,31 @@ interface Position {
|
|
|
47
47
|
noValue: bigint;
|
|
48
48
|
totalValue: bigint;
|
|
49
49
|
}
|
|
50
|
+
/** Portfolio position for a single market */
|
|
51
|
+
interface PortfolioPosition {
|
|
52
|
+
marketAddress: `0x${string}`;
|
|
53
|
+
marketQuestion: string;
|
|
54
|
+
yesShares: bigint;
|
|
55
|
+
noShares: bigint;
|
|
56
|
+
yesSharesFormatted: string;
|
|
57
|
+
noSharesFormatted: string;
|
|
58
|
+
currentYesPrice: number;
|
|
59
|
+
currentNoPrice: number;
|
|
60
|
+
yesValue: string;
|
|
61
|
+
noValue: string;
|
|
62
|
+
totalValue: string;
|
|
63
|
+
resolved: boolean;
|
|
64
|
+
yesWins: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Full portfolio with all positions and summary */
|
|
67
|
+
interface Portfolio {
|
|
68
|
+
positions: PortfolioPosition[];
|
|
69
|
+
summary: {
|
|
70
|
+
totalPositions: number;
|
|
71
|
+
totalValue: string;
|
|
72
|
+
marketsWithPositions: number;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
50
75
|
interface MoltbookAgent {
|
|
51
76
|
id: string;
|
|
52
77
|
name: string;
|
|
@@ -324,6 +349,24 @@ declare class RBSPMClient {
|
|
|
324
349
|
* Get user's position in a market (requires x402 payment - 0.0001 USDC)
|
|
325
350
|
*/
|
|
326
351
|
getPosition(marketAddress: `0x${string}`, userAddress?: `0x${string}`): Promise<Position>;
|
|
352
|
+
/**
|
|
353
|
+
* Get full portfolio with all positions across all markets (requires x402 payment - 0.0001 USDC)
|
|
354
|
+
*
|
|
355
|
+
* Returns all markets where the user has a position, with current values and P&L.
|
|
356
|
+
* Use this for portfolio health checks and monitoring.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const portfolio = await client.getPortfolio();
|
|
361
|
+
* console.log(`Total positions: ${portfolio.summary.totalPositions}`);
|
|
362
|
+
* console.log(`Total value: $${portfolio.summary.totalValue} USDC`);
|
|
363
|
+
*
|
|
364
|
+
* for (const position of portfolio.positions) {
|
|
365
|
+
* console.log(`${position.marketQuestion}: ${position.totalValue} USDC`);
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
getPortfolio(userAddress?: `0x${string}`): Promise<Portfolio>;
|
|
327
370
|
/**
|
|
328
371
|
* Get USDC balance
|
|
329
372
|
*/
|
|
@@ -439,6 +482,26 @@ declare class RBSPMClient {
|
|
|
439
482
|
formatted: string;
|
|
440
483
|
description: string;
|
|
441
484
|
};
|
|
485
|
+
prices: {
|
|
486
|
+
raw: "100";
|
|
487
|
+
formatted: string;
|
|
488
|
+
description: string;
|
|
489
|
+
};
|
|
490
|
+
marketInfo: {
|
|
491
|
+
raw: "100";
|
|
492
|
+
formatted: string;
|
|
493
|
+
description: string;
|
|
494
|
+
};
|
|
495
|
+
position: {
|
|
496
|
+
raw: "100";
|
|
497
|
+
formatted: string;
|
|
498
|
+
description: string;
|
|
499
|
+
};
|
|
500
|
+
portfolio: {
|
|
501
|
+
raw: "100";
|
|
502
|
+
formatted: string;
|
|
503
|
+
description: string;
|
|
504
|
+
};
|
|
442
505
|
marketData: {
|
|
443
506
|
raw: "100";
|
|
444
507
|
formatted: string;
|
|
@@ -481,6 +544,7 @@ declare const API_ENDPOINTS: {
|
|
|
481
544
|
readonly x402Prices: "/functions/v1/x402-prices";
|
|
482
545
|
readonly x402MarketInfo: "/functions/v1/x402-market-info";
|
|
483
546
|
readonly x402Position: "/functions/v1/x402-position";
|
|
547
|
+
readonly x402Portfolio: "/functions/v1/x402-portfolio";
|
|
484
548
|
readonly x402MarketData: "/functions/v1/x402-market-data";
|
|
485
549
|
readonly x402AgentTrade: "/functions/v1/x402-agent-trade";
|
|
486
550
|
readonly x402Resolve: "/functions/v1/x402-resolve";
|
|
@@ -500,6 +564,7 @@ declare const X402_CONFIG: {
|
|
|
500
564
|
readonly prices: "100";
|
|
501
565
|
readonly marketInfo: "100";
|
|
502
566
|
readonly position: "100";
|
|
567
|
+
readonly portfolio: "100";
|
|
503
568
|
readonly marketData: "100";
|
|
504
569
|
readonly tradeInstructions: "100";
|
|
505
570
|
readonly resolve: "100";
|
|
@@ -901,4 +966,4 @@ declare function checkX402Balance(publicClient: {
|
|
|
901
966
|
required: bigint;
|
|
902
967
|
}>;
|
|
903
968
|
|
|
904
|
-
export { ADDRESSES, API_CONFIG, API_ENDPOINTS, type AuthResult, ERC20_ABI, LSLMSR_ABI, LSLMSR_DEPLOY_PARAMS, MONAD_TESTNET, type Market, type MarketCreateParams, type MarketCreateResult, type MarketPrices, type MoltbookAgent, type Position, type PremiumMarketData, RBSPMClient, type RBSPMConfig, type TradeQuote, type TradeResult, type X402Prices, X402_CONFIG, checkX402Balance, createX402Fetch, RBSPMClient as default };
|
|
969
|
+
export { ADDRESSES, API_CONFIG, API_ENDPOINTS, type AuthResult, ERC20_ABI, LSLMSR_ABI, LSLMSR_DEPLOY_PARAMS, MONAD_TESTNET, type Market, type MarketCreateParams, type MarketCreateResult, type MarketPrices, type MoltbookAgent, type Portfolio, type PortfolioPosition, type Position, type PremiumMarketData, RBSPMClient, type RBSPMConfig, type TradeQuote, type TradeResult, type X402Prices, X402_CONFIG, checkX402Balance, createX402Fetch, RBSPMClient as default };
|
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var API_CONFIG = {
|
|
|
68
68
|
};
|
|
69
69
|
var API_ENDPOINTS = {
|
|
70
70
|
base: "https://qkcytrdhdtemyphsswou.supabase.co",
|
|
71
|
-
// Read operations (0.
|
|
71
|
+
// Read operations (0.0001 USDC each)
|
|
72
72
|
x402Markets: "/functions/v1/x402-markets",
|
|
73
73
|
// GET - list all markets
|
|
74
74
|
x402Prices: "/functions/v1/x402-prices",
|
|
@@ -77,9 +77,11 @@ var API_ENDPOINTS = {
|
|
|
77
77
|
// GET ?market=0x... - full market info
|
|
78
78
|
x402Position: "/functions/v1/x402-position",
|
|
79
79
|
// GET ?market=0x...&user=0x... - user position
|
|
80
|
+
x402Portfolio: "/functions/v1/x402-portfolio",
|
|
81
|
+
// GET ?user=0x... - full portfolio with all positions
|
|
80
82
|
x402MarketData: "/functions/v1/x402-market-data",
|
|
81
83
|
// GET ?market=0x... - premium analytics
|
|
82
|
-
// Write operations - return calldata (0.
|
|
84
|
+
// Write operations - return calldata (0.0001 USDC each)
|
|
83
85
|
x402AgentTrade: "/functions/v1/x402-agent-trade",
|
|
84
86
|
// POST - buy/sell calldata
|
|
85
87
|
x402Resolve: "/functions/v1/x402-resolve",
|
|
@@ -90,7 +92,7 @@ var API_ENDPOINTS = {
|
|
|
90
92
|
// POST - redeem calldata
|
|
91
93
|
x402Initialize: "/functions/v1/x402-initialize",
|
|
92
94
|
// POST - initialize calldata
|
|
93
|
-
// Market listing (0.
|
|
95
|
+
// Market listing (0.0001 USDC)
|
|
94
96
|
x402CreateMarket: "/functions/v1/x402-create-market",
|
|
95
97
|
// POST - list market
|
|
96
98
|
// Authentication (free - required for agent identity)
|
|
@@ -110,7 +112,9 @@ var X402_CONFIG = {
|
|
|
110
112
|
marketInfo: "100",
|
|
111
113
|
// 0.0001 USDC - full market info
|
|
112
114
|
position: "100",
|
|
113
|
-
// 0.0001 USDC - get position
|
|
115
|
+
// 0.0001 USDC - get position for single market
|
|
116
|
+
portfolio: "100",
|
|
117
|
+
// 0.0001 USDC - full portfolio (all positions)
|
|
114
118
|
marketData: "100",
|
|
115
119
|
// 0.0001 USDC - premium market data
|
|
116
120
|
tradeInstructions: "100",
|
|
@@ -1051,6 +1055,59 @@ var RBSPMClient = class {
|
|
|
1051
1055
|
totalValue: BigInt(Math.floor(parseFloat(data.position.totalValue) * 1e6))
|
|
1052
1056
|
};
|
|
1053
1057
|
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Get full portfolio with all positions across all markets (requires x402 payment - 0.0001 USDC)
|
|
1060
|
+
*
|
|
1061
|
+
* Returns all markets where the user has a position, with current values and P&L.
|
|
1062
|
+
* Use this for portfolio health checks and monitoring.
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* const portfolio = await client.getPortfolio();
|
|
1067
|
+
* console.log(`Total positions: ${portfolio.summary.totalPositions}`);
|
|
1068
|
+
* console.log(`Total value: $${portfolio.summary.totalValue} USDC`);
|
|
1069
|
+
*
|
|
1070
|
+
* for (const position of portfolio.positions) {
|
|
1071
|
+
* console.log(`${position.marketQuestion}: ${position.totalValue} USDC`);
|
|
1072
|
+
* }
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
async getPortfolio(userAddress) {
|
|
1076
|
+
const address = userAddress || this.account?.address;
|
|
1077
|
+
if (!address) {
|
|
1078
|
+
throw new Error("No address provided and no wallet configured");
|
|
1079
|
+
}
|
|
1080
|
+
const paymentFetch = this.getPaymentFetch();
|
|
1081
|
+
const response = await paymentFetch(
|
|
1082
|
+
`${this.apiUrl}${API_ENDPOINTS.x402Portfolio}?user=${address}`,
|
|
1083
|
+
{ method: "GET" }
|
|
1084
|
+
);
|
|
1085
|
+
if (response.status === 402) {
|
|
1086
|
+
throw new Error("Payment required for portfolio (0.0001 USDC)");
|
|
1087
|
+
}
|
|
1088
|
+
if (!response.ok) {
|
|
1089
|
+
throw new Error("Failed to fetch portfolio");
|
|
1090
|
+
}
|
|
1091
|
+
const data = await response.json();
|
|
1092
|
+
return {
|
|
1093
|
+
positions: data.positions.map((p) => ({
|
|
1094
|
+
marketAddress: p.marketAddress,
|
|
1095
|
+
marketQuestion: p.marketQuestion,
|
|
1096
|
+
yesShares: BigInt(p.yesShares),
|
|
1097
|
+
noShares: BigInt(p.noShares),
|
|
1098
|
+
yesSharesFormatted: p.yesSharesFormatted,
|
|
1099
|
+
noSharesFormatted: p.noSharesFormatted,
|
|
1100
|
+
currentYesPrice: p.currentYesPrice,
|
|
1101
|
+
currentNoPrice: p.currentNoPrice,
|
|
1102
|
+
yesValue: p.yesValue,
|
|
1103
|
+
noValue: p.noValue,
|
|
1104
|
+
totalValue: p.totalValue,
|
|
1105
|
+
resolved: p.resolved,
|
|
1106
|
+
yesWins: p.yesWins
|
|
1107
|
+
})),
|
|
1108
|
+
summary: data.summary
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1054
1111
|
/**
|
|
1055
1112
|
* Get USDC balance
|
|
1056
1113
|
*/
|
|
@@ -1333,6 +1390,10 @@ var RBSPMClient = class {
|
|
|
1333
1390
|
getX402Prices() {
|
|
1334
1391
|
return {
|
|
1335
1392
|
markets: { raw: X402_CONFIG.prices.markets, formatted: "0.0001 USDC", description: "List all markets" },
|
|
1393
|
+
prices: { raw: X402_CONFIG.prices.prices, formatted: "0.0001 USDC", description: "Get market prices" },
|
|
1394
|
+
marketInfo: { raw: X402_CONFIG.prices.marketInfo, formatted: "0.0001 USDC", description: "Full market info" },
|
|
1395
|
+
position: { raw: X402_CONFIG.prices.position, formatted: "0.0001 USDC", description: "Position in single market" },
|
|
1396
|
+
portfolio: { raw: X402_CONFIG.prices.portfolio, formatted: "0.0001 USDC", description: "Full portfolio (all positions)" },
|
|
1336
1397
|
marketData: { raw: X402_CONFIG.prices.marketData, formatted: "0.0001 USDC", description: "Premium market data" },
|
|
1337
1398
|
tradeInstructions: { raw: X402_CONFIG.prices.tradeInstructions, formatted: "0.0001 USDC", description: "Get trade calldata" },
|
|
1338
1399
|
createMarket: { raw: X402_CONFIG.prices.createMarket, formatted: "0.0001 USDC", description: "List market for discovery" }
|
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ var API_CONFIG = {
|
|
|
37
37
|
};
|
|
38
38
|
var API_ENDPOINTS = {
|
|
39
39
|
base: "https://qkcytrdhdtemyphsswou.supabase.co",
|
|
40
|
-
// Read operations (0.
|
|
40
|
+
// Read operations (0.0001 USDC each)
|
|
41
41
|
x402Markets: "/functions/v1/x402-markets",
|
|
42
42
|
// GET - list all markets
|
|
43
43
|
x402Prices: "/functions/v1/x402-prices",
|
|
@@ -46,9 +46,11 @@ var API_ENDPOINTS = {
|
|
|
46
46
|
// GET ?market=0x... - full market info
|
|
47
47
|
x402Position: "/functions/v1/x402-position",
|
|
48
48
|
// GET ?market=0x...&user=0x... - user position
|
|
49
|
+
x402Portfolio: "/functions/v1/x402-portfolio",
|
|
50
|
+
// GET ?user=0x... - full portfolio with all positions
|
|
49
51
|
x402MarketData: "/functions/v1/x402-market-data",
|
|
50
52
|
// GET ?market=0x... - premium analytics
|
|
51
|
-
// Write operations - return calldata (0.
|
|
53
|
+
// Write operations - return calldata (0.0001 USDC each)
|
|
52
54
|
x402AgentTrade: "/functions/v1/x402-agent-trade",
|
|
53
55
|
// POST - buy/sell calldata
|
|
54
56
|
x402Resolve: "/functions/v1/x402-resolve",
|
|
@@ -59,7 +61,7 @@ var API_ENDPOINTS = {
|
|
|
59
61
|
// POST - redeem calldata
|
|
60
62
|
x402Initialize: "/functions/v1/x402-initialize",
|
|
61
63
|
// POST - initialize calldata
|
|
62
|
-
// Market listing (0.
|
|
64
|
+
// Market listing (0.0001 USDC)
|
|
63
65
|
x402CreateMarket: "/functions/v1/x402-create-market",
|
|
64
66
|
// POST - list market
|
|
65
67
|
// Authentication (free - required for agent identity)
|
|
@@ -79,7 +81,9 @@ var X402_CONFIG = {
|
|
|
79
81
|
marketInfo: "100",
|
|
80
82
|
// 0.0001 USDC - full market info
|
|
81
83
|
position: "100",
|
|
82
|
-
// 0.0001 USDC - get position
|
|
84
|
+
// 0.0001 USDC - get position for single market
|
|
85
|
+
portfolio: "100",
|
|
86
|
+
// 0.0001 USDC - full portfolio (all positions)
|
|
83
87
|
marketData: "100",
|
|
84
88
|
// 0.0001 USDC - premium market data
|
|
85
89
|
tradeInstructions: "100",
|
|
@@ -1020,6 +1024,59 @@ var RBSPMClient = class {
|
|
|
1020
1024
|
totalValue: BigInt(Math.floor(parseFloat(data.position.totalValue) * 1e6))
|
|
1021
1025
|
};
|
|
1022
1026
|
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Get full portfolio with all positions across all markets (requires x402 payment - 0.0001 USDC)
|
|
1029
|
+
*
|
|
1030
|
+
* Returns all markets where the user has a position, with current values and P&L.
|
|
1031
|
+
* Use this for portfolio health checks and monitoring.
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* const portfolio = await client.getPortfolio();
|
|
1036
|
+
* console.log(`Total positions: ${portfolio.summary.totalPositions}`);
|
|
1037
|
+
* console.log(`Total value: $${portfolio.summary.totalValue} USDC`);
|
|
1038
|
+
*
|
|
1039
|
+
* for (const position of portfolio.positions) {
|
|
1040
|
+
* console.log(`${position.marketQuestion}: ${position.totalValue} USDC`);
|
|
1041
|
+
* }
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
async getPortfolio(userAddress) {
|
|
1045
|
+
const address = userAddress || this.account?.address;
|
|
1046
|
+
if (!address) {
|
|
1047
|
+
throw new Error("No address provided and no wallet configured");
|
|
1048
|
+
}
|
|
1049
|
+
const paymentFetch = this.getPaymentFetch();
|
|
1050
|
+
const response = await paymentFetch(
|
|
1051
|
+
`${this.apiUrl}${API_ENDPOINTS.x402Portfolio}?user=${address}`,
|
|
1052
|
+
{ method: "GET" }
|
|
1053
|
+
);
|
|
1054
|
+
if (response.status === 402) {
|
|
1055
|
+
throw new Error("Payment required for portfolio (0.0001 USDC)");
|
|
1056
|
+
}
|
|
1057
|
+
if (!response.ok) {
|
|
1058
|
+
throw new Error("Failed to fetch portfolio");
|
|
1059
|
+
}
|
|
1060
|
+
const data = await response.json();
|
|
1061
|
+
return {
|
|
1062
|
+
positions: data.positions.map((p) => ({
|
|
1063
|
+
marketAddress: p.marketAddress,
|
|
1064
|
+
marketQuestion: p.marketQuestion,
|
|
1065
|
+
yesShares: BigInt(p.yesShares),
|
|
1066
|
+
noShares: BigInt(p.noShares),
|
|
1067
|
+
yesSharesFormatted: p.yesSharesFormatted,
|
|
1068
|
+
noSharesFormatted: p.noSharesFormatted,
|
|
1069
|
+
currentYesPrice: p.currentYesPrice,
|
|
1070
|
+
currentNoPrice: p.currentNoPrice,
|
|
1071
|
+
yesValue: p.yesValue,
|
|
1072
|
+
noValue: p.noValue,
|
|
1073
|
+
totalValue: p.totalValue,
|
|
1074
|
+
resolved: p.resolved,
|
|
1075
|
+
yesWins: p.yesWins
|
|
1076
|
+
})),
|
|
1077
|
+
summary: data.summary
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1023
1080
|
/**
|
|
1024
1081
|
* Get USDC balance
|
|
1025
1082
|
*/
|
|
@@ -1302,6 +1359,10 @@ var RBSPMClient = class {
|
|
|
1302
1359
|
getX402Prices() {
|
|
1303
1360
|
return {
|
|
1304
1361
|
markets: { raw: X402_CONFIG.prices.markets, formatted: "0.0001 USDC", description: "List all markets" },
|
|
1362
|
+
prices: { raw: X402_CONFIG.prices.prices, formatted: "0.0001 USDC", description: "Get market prices" },
|
|
1363
|
+
marketInfo: { raw: X402_CONFIG.prices.marketInfo, formatted: "0.0001 USDC", description: "Full market info" },
|
|
1364
|
+
position: { raw: X402_CONFIG.prices.position, formatted: "0.0001 USDC", description: "Position in single market" },
|
|
1365
|
+
portfolio: { raw: X402_CONFIG.prices.portfolio, formatted: "0.0001 USDC", description: "Full portfolio (all positions)" },
|
|
1305
1366
|
marketData: { raw: X402_CONFIG.prices.marketData, formatted: "0.0001 USDC", description: "Premium market data" },
|
|
1306
1367
|
tradeInstructions: { raw: X402_CONFIG.prices.tradeInstructions, formatted: "0.0001 USDC", description: "Get trade calldata" },
|
|
1307
1368
|
createMarket: { raw: X402_CONFIG.prices.createMarket, formatted: "0.0001 USDC", description: "List market for discovery" }
|