|
1 | | -# Forecast Leverage SDK |
| 1 | +# Forecast Protocol SDK |
2 | 2 |
|
3 | | -Add leverage to Polymarket trading. Target-based UX, comprehensive validation, production-ready. |
| 3 | +TypeScript SDK for integrating leveraged prediction market trading via Forecast Protocol. |
4 | 4 |
|
5 | | -```typescript |
6 | | -const position = await sdk.openTargetPosition({ |
7 | | - marketConditionId: '0x...', |
8 | | - longYes: true, |
9 | | - currentPrice: 0.40, // 40¢ |
10 | | - targetPrice: 0.44, // 44¢ |
11 | | - timeframeSeconds: 3600, |
12 | | - capitalUSDC: 1000, |
13 | | - maxSlippageBps: 100 |
14 | | -}); |
15 | | -// Returns: 8.2x leverage, $25 fees, +$305 PnL at target |
16 | | -``` |
17 | | - |
18 | | -## Install |
| 5 | +## Installation |
19 | 6 |
|
20 | 7 | ```bash |
21 | | -npm install @forecast-protocol/leverage-sdk |
| 8 | +npm install @forecast-protocol/sdk |
22 | 9 | ``` |
23 | 10 |
|
24 | | -## Quick Start |
| 11 | +## Usage |
25 | 12 |
|
26 | 13 | ```typescript |
27 | | -import { ForecastLeverageSDK } from '@forecast-protocol/leverage-sdk'; |
| 14 | +import { ForecastLeverageSDK } from '@forecast-protocol/sdk'; |
28 | 15 |
|
29 | 16 | const sdk = new ForecastLeverageSDK( |
30 | 17 | rpcUrl, |
31 | 18 | privateKey, |
32 | 19 | protocolAddress, |
33 | 20 | usdcAddress, |
34 | 21 | ctfAddress, |
35 | | - polymarketCreds, |
36 | | - funderAddress |
| 22 | + polymarketFunderAddress |
37 | 23 | ); |
38 | 24 |
|
39 | | -// Simulate first (recommended) |
40 | | -const preview = await sdk.simulatePosition(params); |
41 | | -console.log(`${preview.effectiveLeverage}x leverage, $${preview.fees.total} fees`); |
| 25 | +await sdk.setupPolymarket(); |
42 | 26 |
|
43 | | -// Execute |
44 | | -const position = await sdk.openTargetPosition(params); |
45 | | - |
46 | | -// Close |
47 | | -await sdk.closePosition(position.legIds); |
| 27 | +const position = await sdk.openTargetPosition({ |
| 28 | + marketConditionId: '0x...', |
| 29 | + longYes: true, |
| 30 | + currentPrice: 0.40, |
| 31 | + targetPrice: 0.44, |
| 32 | + timeframeSeconds: 3600, |
| 33 | + capitalUSDC: 1000, |
| 34 | + maxSlippageBps: 100 |
| 35 | +}); |
48 | 36 | ``` |
49 | 37 |
|
50 | | -## Examples |
51 | | - |
52 | | -- [Basic Usage](examples/basic.ts) - Open and close a position |
53 | | -- [Simulation](examples/simulation.ts) - Test without real transactions |
54 | | -- [Error Handling](examples/errors.ts) - Handle all error cases |
55 | | -- [UI Integration](examples/ui.ts) - React component example |
56 | | - |
57 | 38 | ## Documentation |
58 | 39 |
|
59 | | -- [API Reference](docs/API.md) - Complete method documentation |
60 | | -- [Error Handling](docs/ERRORS.md) - Error types and handling |
61 | | -- [Testing](docs/TESTING.md) - Test your integration |
| 40 | +See [INTEGRATION_GUIDE.md](./INTEGRATION_GUIDE.md) for complete integration instructions. |
62 | 41 |
|
63 | | -## Error Handling |
| 42 | +## Testing |
64 | 43 |
|
65 | | -```typescript |
66 | | -try { |
67 | | - await sdk.openTargetPosition(params); |
68 | | -} catch (error) { |
69 | | - if (error instanceof ValidationError) { |
70 | | - // Bad input - fix parameters |
71 | | - } else if (error instanceof PolymarketError) { |
72 | | - // Order failed - check liquidity |
73 | | - } else if (error instanceof ProtocolError) { |
74 | | - // Protocol issue - check network |
75 | | - } |
76 | | -} |
| 44 | +```bash |
| 45 | +npm test |
77 | 46 | ``` |
78 | 47 |
|
79 | | -## Features |
80 | | - |
81 | | -- **Target-Based UX**: Users specify price targets, not leverage multiples |
82 | | -- **Comprehensive Validation**: All inputs validated before execution |
83 | | -- **Simulation Mode**: Test without blockchain transactions |
84 | | -- **Type-Safe**: Full TypeScript support |
85 | | -- **Error Handling**: Custom error classes for each failure type |
86 | | -- **Production-Ready**: Battle-tested, 98% test coverage |
87 | | - |
88 | | -## Network Support |
89 | | - |
90 | | -- Polygon Mainnet |
91 | | -- Local forks (for testing) |
92 | | - |
93 | | -## Requirements |
94 | | - |
95 | | -- Node.js >=18 |
96 | | -- Polymarket API credentials |
97 | | -- USDC balance |
98 | | -- MATIC for gas |
99 | | - |
100 | | -## Links |
101 | | - |
102 | | -- [GitHub](https://github.com/Genmin/forecast-leverage-sdk) |
103 | | -- [Issues](https://github.com/Genmin/forecast-leverage-sdk/issues) |
104 | | -- [Protocol Docs](https://docs.forecast.com) |
105 | | -- [Discord](https://discord.gg/forecast) |
106 | | - |
107 | 48 | ## License |
108 | 49 |
|
109 | 50 | MIT |
0 commit comments