pnp-sdk 0.1.0

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 ADDED
@@ -0,0 +1,125 @@
1
+ # @pnp-sdk
2
+
3
+ Production-ready SDK skeleton for Solana markets: create market, trade, and redeem position.
4
+
5
+ NOTE: Instruction builders are placeholders. Provide your program IDL or Borsh layouts to wire real data.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i @pnp-sdk
11
+ ```
12
+
13
+ ## Usage (Node)
14
+
15
+ ### Environment Setup
16
+
17
+ Create a `.env` file with the following variables:
18
+
19
+ ```env
20
+ # Solana RPC URL (mainnet, devnet, testnet, or local)
21
+ RPC_URL=https://api.devnet.solana.com
22
+
23
+ # Wallet private key (as Base58 string or array)
24
+ WALLET_SECRET_BASE58=YourBase58EncodedPrivateKeyHere
25
+ # OR as array
26
+ WALLET_SECRET_ARRAY=[38,217,47,162,6,...] # your array of numbers
27
+
28
+ # Program ID is embedded in the program IDL; no env needed
29
+
30
+ # Optional: Mint addresses for market creation
31
+ BASE_MINT=YourBaseMintAddressHere
32
+ QUOTE_MINT=YourQuoteMintAddressHere
33
+ ```
34
+
35
+ ### With Base58 Private Key
36
+
37
+ ```ts
38
+ import { PNPClient } from "@pnp-sdk";
39
+ import bs58 from "bs58";
40
+ import * as dotenv from "dotenv";
41
+
42
+ dotenv.config();
43
+
44
+ const maybePk = process.env.WALLET_SECRET_BASE58 ? bs58.decode(process.env.WALLET_SECRET_BASE58) : undefined;
45
+ const client = new PNPClient(process.env.RPC_URL!, maybePk);
46
+
47
+ // Read-only
48
+ const global = await client.fetchGlobalConfig();
49
+ // With private key present, you can access write modules:
50
+ // await client.trading!.buyTokensUsdc(...)
51
+ ```
52
+
53
+ ### With Private Key Array
54
+
55
+ ```ts
56
+ import { PNPClient } from "@pnp-sdk";
57
+ import * as dotenv from "dotenv";
58
+
59
+ dotenv.config();
60
+
61
+ const privateKeyArray = JSON.parse(process.env.WALLET_SECRET_ARRAY!);
62
+ const privateKeyBytes = new Uint8Array(privateKeyArray);
63
+ const client = new PNPClient(process.env.RPC_URL!, privateKeyBytes);
64
+ ```
65
+
66
+ ## Development
67
+
68
+ - Build: `npm run build`
69
+ - Test: `npm test`
70
+ - Typecheck: `npm run typecheck`
71
+
72
+ ## REST API Server
73
+
74
+ The SDK includes an Express server implementation that allows you to create markets via HTTP endpoints:
75
+
76
+ ```bash
77
+ # Start the API server
78
+ npm run api:server
79
+
80
+ # Access the API at http://localhost:3000
81
+ ```
82
+
83
+ ### API Endpoints
84
+
85
+ - `GET /health` - Health check endpoint
86
+ - `POST /create-market` - Create a new market
87
+ - Request body: `{ "question": "Your market question here" }`
88
+
89
+ ### Command Line Interface
90
+
91
+ You can also create markets directly from the command line:
92
+
93
+ ```bash
94
+ # Create a market with a specific question
95
+ npm run api:server "Will this market prediction come true?"
96
+ ```
97
+
98
+ ### Example Response
99
+
100
+ ```json
101
+ {
102
+ "success": true,
103
+ "txSignature": "2NPJ3NCuP1EZpN8DAwyjUgKJbRNZ6ZzmLSz8gXq3wMARMjeY3Y8xpGKUQo4hjiP7eoqAa6bHLNvWUbHMRGZ1sk9n",
104
+ "market": "CL9tjeJL38C3KyVvUxSHiiMzfvvB6gNn6TCweE9TH45t",
105
+ "yesTokenMint": "BzPKqzBNKw3hjj7BNn6oT7GXG3LKv7R1mFQby5bAYvdG",
106
+ "noTokenMint": "5ctuKQpZMQ2HoMvjXZHxAT3QxCN5mq8Ss1U5YCvFg8aZ",
107
+ "marketDetails": {
108
+ "id": "42",
109
+ "question": "Will this market prediction come true?",
110
+ "creator": "BUbQNJKKRvZesSPbgJyw1nHDRNMn7demZjcaqWpLXcFe",
111
+ "initialLiquidity": "50000000",
112
+ "marketReserves": "50000000",
113
+ "yesTokenSupply": "50000000",
114
+ "noTokenSupply": "50000000",
115
+ "endTime": "2025-08-27T19:12:28.000Z",
116
+ "resolved": false
117
+ }
118
+ }
119
+ ```
120
+
121
+ ## Next steps
122
+
123
+ - Replace placeholder instruction data encodings with your program's IDL/Borsh schemas.
124
+ - Add account metas per instruction (vaults, ATAs, mints, PDAs).
125
+ - Expand tests to integration against `solana-test-validator`.