@pompafly/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,187 @@
1
+ # @pompafly/sdk
2
+
3
+ TypeScript SDK for the Pompafly token launchpad on Solana.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @pompafly/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Frontend (Next.js + Wallet Adapter)
14
+
15
+ ```typescript
16
+ import { PompaflyClient, PompaflyAPI, PompaflyStream, DEVNET_CONFIG } from "@pompafly/sdk";
17
+ import { useAnchorWallet } from "@solana/wallet-adapter-react";
18
+
19
+ // Transaction client
20
+ const wallet = useAnchorWallet();
21
+ const client = new PompaflyClient({ wallet, config: DEVNET_CONFIG });
22
+
23
+ // REST API
24
+ const api = new PompaflyAPI(DEVNET_CONFIG);
25
+
26
+ // Real-time stream
27
+ const stream = new PompaflyStream(DEVNET_CONFIG);
28
+ ```
29
+
30
+ ### Backend (Node.js + Keypair)
31
+
32
+ ```typescript
33
+ import { PompaflyClient, DEVNET_CONFIG } from "@pompafly/sdk";
34
+ import { Keypair } from "@solana/web3.js";
35
+
36
+ const keypair = Keypair.fromSecretKey(/* your secret key */);
37
+ const client = new PompaflyClient({ keypair, config: DEVNET_CONFIG });
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Browse Pools
43
+
44
+ ```typescript
45
+ // List trending pools
46
+ const { data: pools } = await api.getPools({ sort: "volume", status: "active" });
47
+
48
+ // Search by name
49
+ const { data: results } = await api.getPools({ search: "DOGE" });
50
+
51
+ // Get pool details
52
+ const { data: pool } = await api.getPool("mint_address_here");
53
+
54
+ // Get current price
55
+ const { data: price } = await api.getPoolPrice("mint_address_here");
56
+ ```
57
+
58
+ ### Buy Tokens
59
+
60
+ ```typescript
61
+ // Buy 100 tokens with 1 SOL max slippage
62
+ const result = await client.buy("mint_address", 100, 1.0);
63
+ console.log("Signature:", result.signature);
64
+
65
+ // Priority buy (during 120s window, requires auth)
66
+ const { data: auth } = await api.getPriorityAuth("mint_address");
67
+ const result = await client.buy("mint_address", 100, 1.0, prioritySignerKeypair);
68
+ ```
69
+
70
+ ### Sell Tokens
71
+
72
+ ```typescript
73
+ // Sell 50 tokens, accept any return
74
+ const result = await client.sell("mint_address", 50);
75
+
76
+ // Sell with minimum return of 0.5 SOL
77
+ const result = await client.sell("mint_address", 50, 0.5);
78
+ ```
79
+
80
+ ### Create a Token
81
+
82
+ ```typescript
83
+ const result = await client.createPool(
84
+ "My Token", // name
85
+ "MYTKN", // symbol
86
+ "https://meta.json", // metadata URI
87
+ "myxhandle", // X handle
88
+ authorityKeypair // backend co-signer
89
+ );
90
+ console.log("Mint:", result.mint);
91
+ console.log("Pool:", result.pool);
92
+ ```
93
+
94
+ ### Real-Time Price Feed
95
+
96
+ ```typescript
97
+ const stream = new PompaflyStream();
98
+ stream.connect();
99
+
100
+ // Subscribe to specific tokens
101
+ stream.subscribe(["mint1", "mint2"]);
102
+
103
+ // Listen for price updates
104
+ const unsub = stream.onPrice((event) => {
105
+ console.log(`${event.mint}: ${event.data.currentPrice}`);
106
+ });
107
+
108
+ // Listen for trades
109
+ stream.onTrade((event) => {
110
+ console.log(`${event.data.type}: ${event.data.tokenAmount} tokens`);
111
+ });
112
+
113
+ // Cleanup
114
+ unsub(); // remove listener
115
+ stream.unsubscribe(["mint1"]);
116
+ stream.disconnect();
117
+ ```
118
+
119
+ ### Authentication Flow
120
+
121
+ ```typescript
122
+ // 1. Get nonce
123
+ const { data: { nonce, message } } = await api.getNonce(wallet.publicKey.toBase58());
124
+
125
+ // 2. Sign with wallet (frontend)
126
+ const signature = await wallet.signMessage(new TextEncoder().encode(message));
127
+
128
+ // 3. Verify and get JWT
129
+ const { data: { token, user } } = await api.verifyWallet(
130
+ wallet.publicKey.toBase58(),
131
+ bs58.encode(signature)
132
+ );
133
+ // JWT is automatically stored in the API client
134
+
135
+ // 4. Link X account (redirects to Twitter OAuth)
136
+ window.location.href = api.getXLoginUrl();
137
+ ```
138
+
139
+ ### Charts
140
+
141
+ ```typescript
142
+ // Get 1-hour candles for the last 24 hours
143
+ const { data: candles } = await api.getCandles("mint_address", {
144
+ interval: "1h",
145
+ from: Math.floor(Date.now() / 1000) - 86400,
146
+ limit: 24,
147
+ });
148
+ ```
149
+
150
+ ### Platform Stats
151
+
152
+ ```typescript
153
+ const { data: stats } = await api.getStats();
154
+ console.log("Total pools:", stats.totalPoolsCreated);
155
+ console.log("Graduation rate:", stats.graduationRate);
156
+
157
+ const { data: trending } = await api.getTrending(10);
158
+ ```
159
+
160
+ ## Utilities
161
+
162
+ ```typescript
163
+ import { solToLamports, lamportsToSol, tokensToBase, baseToTokens } from "@pompafly/sdk";
164
+
165
+ solToLamports(1.5); // 1500000000
166
+ lamportsToSol(1500000000); // 1.5
167
+ tokensToBase(100); // 100000000
168
+ baseToTokens(100000000); // 100
169
+ ```
170
+
171
+ ## Configuration
172
+
173
+ ```typescript
174
+ import { DEVNET_CONFIG, MAINNET_CONFIG } from "@pompafly/sdk";
175
+
176
+ // Or custom config
177
+ const config = {
178
+ rpcUrl: "https://my-rpc.com",
179
+ programId: "FnBDGeXKx3CsrFqxfKrLMsuNeUmMZPP19DbLbmqj8wCZ",
180
+ apiUrl: "https://api.pompafly.fun",
181
+ wsUrl: "wss://api.pompafly.fun/ws",
182
+ };
183
+ ```
184
+
185
+ ## License
186
+
187
+ MIT
@@ -0,0 +1,382 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { PublicKey, Keypair, Connection } from '@solana/web3.js';
3
+
4
+ interface PompaflyConfig {
5
+ /** Solana RPC endpoint URL */
6
+ rpcUrl: string;
7
+ /** Pompafly program ID */
8
+ programId: string;
9
+ /** Backend API base URL */
10
+ apiUrl: string;
11
+ /** WebSocket URL for real-time feeds */
12
+ wsUrl: string;
13
+ }
14
+ declare const DEVNET_CONFIG: PompaflyConfig;
15
+ declare const MAINNET_CONFIG: PompaflyConfig;
16
+ /** Compatible with @solana/wallet-adapter AnchorWallet interface */
17
+ interface WalletAdapter {
18
+ publicKey: PublicKey;
19
+ signTransaction: <T extends _solana_web3_js.Transaction | _solana_web3_js.VersionedTransaction>(tx: T) => Promise<T>;
20
+ signAllTransactions: <T extends _solana_web3_js.Transaction | _solana_web3_js.VersionedTransaction>(txs: T[]) => Promise<T[]>;
21
+ }
22
+ interface Pool {
23
+ mint: string;
24
+ poolAddress: string;
25
+ creator: string;
26
+ creatorXHandle: string;
27
+ name: string;
28
+ symbol: string;
29
+ uri: string;
30
+ status: "active" | "graduating" | "graduated";
31
+ totalSupply: string;
32
+ supplySold: string;
33
+ solBalance: string;
34
+ currentPrice: string;
35
+ marketCap: string;
36
+ progressPercent: number;
37
+ priorityWindowEnd: string;
38
+ graduatedAt: string | null;
39
+ totalTrades: number;
40
+ totalVolumeSol: string;
41
+ holderCount: number;
42
+ createdAt: string;
43
+ }
44
+ interface PoolPrice {
45
+ currentPrice: string;
46
+ marketCap: string;
47
+ solBalance: string;
48
+ supplySold: string;
49
+ progressPercent: number;
50
+ graduationThreshold: string;
51
+ isPriorityWindow: boolean;
52
+ status: string;
53
+ }
54
+ interface PoolListParams {
55
+ page?: number;
56
+ limit?: number;
57
+ status?: "active" | "graduating" | "graduated";
58
+ sort?: "newest" | "oldest" | "volume" | "marketcap" | "graduating";
59
+ search?: string;
60
+ creator?: string;
61
+ }
62
+ interface Trade {
63
+ pool: string;
64
+ mint: string;
65
+ trader: string;
66
+ type: "buy" | "sell";
67
+ tokenAmount: string;
68
+ solAmount: string;
69
+ fee: string;
70
+ price: string;
71
+ txSignature: string;
72
+ timestamp: string;
73
+ }
74
+ interface TradeListParams {
75
+ page?: number;
76
+ limit?: number;
77
+ type?: "buy" | "sell";
78
+ trader?: string;
79
+ }
80
+ interface Candle {
81
+ timestamp: number;
82
+ open: number;
83
+ high: number;
84
+ low: number;
85
+ close: number;
86
+ volume: number;
87
+ tradeCount: number;
88
+ }
89
+ type CandleInterval = "1m" | "5m" | "15m" | "1h" | "4h" | "1d";
90
+ interface CandleParams {
91
+ interval: CandleInterval;
92
+ from?: number;
93
+ to?: number;
94
+ limit?: number;
95
+ }
96
+ interface User {
97
+ wallet: string;
98
+ xHandle: string;
99
+ xVerified: boolean;
100
+ isCreator: boolean;
101
+ totalTrades: number;
102
+ totalVolumeSol: string;
103
+ createdAt: string;
104
+ }
105
+ interface PlatformStats {
106
+ totalPoolsCreated: number;
107
+ totalPoolsGraduated: number;
108
+ graduationRate: string;
109
+ activePoolsCount: number;
110
+ totalUsers: number;
111
+ totalTrades: number;
112
+ totalVolumeSol: string;
113
+ totalFeesCollected: string;
114
+ }
115
+ interface TrendingPool {
116
+ mint: string;
117
+ name: string;
118
+ symbol: string;
119
+ creatorXHandle: string;
120
+ status: string;
121
+ volume24h: string;
122
+ trades24h: number;
123
+ currentPrice: string;
124
+ marketCap: string;
125
+ progressPercent: number;
126
+ }
127
+ interface TxResult {
128
+ signature: string;
129
+ slot?: number;
130
+ }
131
+ interface BuyResult extends TxResult {
132
+ tokenAmount: string;
133
+ solCost: string;
134
+ }
135
+ interface SellResult extends TxResult {
136
+ tokenAmount: string;
137
+ solReceived: string;
138
+ }
139
+ interface CreatePoolResult extends TxResult {
140
+ mint: string;
141
+ pool: string;
142
+ }
143
+ interface ApiResponse<T> {
144
+ success: boolean;
145
+ data: T;
146
+ error?: string;
147
+ code?: string;
148
+ }
149
+ interface PaginatedResponse<T> extends ApiResponse<T[]> {
150
+ pagination: {
151
+ total: number;
152
+ page: number;
153
+ limit: number;
154
+ pages: number;
155
+ };
156
+ }
157
+ interface PriceEvent {
158
+ type: "price";
159
+ mint: string;
160
+ data: PoolPrice;
161
+ }
162
+ interface TradeEvent {
163
+ type: "trade";
164
+ mint: string;
165
+ data: Trade;
166
+ }
167
+ interface StatusEvent {
168
+ type: "status";
169
+ mint: string;
170
+ data: {
171
+ oldStatus: string;
172
+ newStatus: string;
173
+ };
174
+ }
175
+ type StreamEvent = PriceEvent | TradeEvent | StatusEvent;
176
+ type StreamEventHandler = (event: StreamEvent) => void;
177
+
178
+ /**
179
+ * ─────────────────────────────────────────────────────────────
180
+ * PompaflyClient — on-chain transaction builder
181
+ *
182
+ * Builds and sends Solana transactions for the Pompafly program.
183
+ * No dependency on anchor.Program — uses raw instruction encoding.
184
+ *
185
+ * Usage with wallet adapter (frontend):
186
+ * const client = new PompaflyClient({ wallet });
187
+ *
188
+ * Usage with keypair (backend/scripts):
189
+ * const client = new PompaflyClient({ keypair });
190
+ * ─────────────────────────────────────────────────────────────
191
+ */
192
+ interface ClientOptions {
193
+ wallet?: WalletAdapter;
194
+ keypair?: Keypair;
195
+ config?: PompaflyConfig;
196
+ connection?: Connection;
197
+ }
198
+ declare class PompaflyClient {
199
+ readonly connection: Connection;
200
+ readonly programId: PublicKey;
201
+ readonly config: PompaflyConfig;
202
+ private wallet;
203
+ private globalConfigPda;
204
+ constructor(options: ClientOptions);
205
+ get publicKey(): PublicKey;
206
+ private sendTx;
207
+ createPool(name: string, symbol: string, uri: string, creatorXHandle: string, authoritySigner: Keypair): Promise<CreatePoolResult>;
208
+ buy(mint: string | PublicKey, tokenAmount: number, maxSlippageSol: number, prioritySigner?: Keypair): Promise<BuyResult>;
209
+ sell(mint: string | PublicKey, tokenAmount: number, minReturnSol?: number): Promise<SellResult>;
210
+ collectFees(mint: string | PublicKey, validatorWallet: string | PublicKey, communityWallet: string | PublicKey, platformWallet: string | PublicKey): Promise<TxResult>;
211
+ graduate(mint: string | PublicKey): Promise<TxResult>;
212
+ /**
213
+ * Get raw account data for a pool PDA.
214
+ * Returns the raw bytes — use with the Anchor IDL for full deserialization,
215
+ * or parse manually if you know the layout.
216
+ */
217
+ getPoolAccountInfo(mint: string | PublicKey): Promise<_solana_web3_js.AccountInfo<Buffer<ArrayBufferLike>> | null>;
218
+ /** Get the pool PDA address for a given mint */
219
+ getPoolAddress(mint: string | PublicKey): Promise<string>;
220
+ /** Get the token vault ATA address for a pool */
221
+ getPoolTokenVault(mint: string | PublicKey): Promise<string>;
222
+ /** Get the global config PDA address */
223
+ getGlobalConfigAddress(): string;
224
+ }
225
+
226
+ /**
227
+ * ─────────────────────────────────────────────────────────────
228
+ * PompaflyAPI — REST API client
229
+ *
230
+ * Wraps all backend endpoints with typed responses.
231
+ * Handles JWT auth automatically after login.
232
+ *
233
+ * Usage:
234
+ * const api = new PompaflyAPI();
235
+ * const pools = await api.getPools({ sort: "trending" });
236
+ * await api.login(wallet, signature);
237
+ * const me = await api.getMe();
238
+ * ─────────────────────────────────────────────────────────────
239
+ */
240
+ declare class PompaflyAPI {
241
+ private baseUrl;
242
+ private token;
243
+ constructor(config?: PompaflyConfig);
244
+ /** Set JWT token for authenticated requests */
245
+ setToken(token: string): void;
246
+ /** Clear authentication */
247
+ clearToken(): void;
248
+ private fetch;
249
+ /** Request a login nonce for wallet signature */
250
+ getNonce(wallet: string): Promise<ApiResponse<{
251
+ nonce: string;
252
+ message: string;
253
+ }>>;
254
+ /** Verify wallet signature and get JWT */
255
+ verifyWallet(wallet: string, signature: string): Promise<ApiResponse<{
256
+ token: string;
257
+ user: User;
258
+ }>>;
259
+ /** Get X OAuth login URL (must be authenticated first) */
260
+ getXLoginUrl(): string;
261
+ /** Get current user profile */
262
+ getMe(): Promise<ApiResponse<User>>;
263
+ /** List pools with filters and sorting */
264
+ getPools(params?: PoolListParams): Promise<PaginatedResponse<Pool>>;
265
+ /** Get pool details by mint */
266
+ getPool(mint: string): Promise<ApiResponse<Pool>>;
267
+ /** Get current price and curve position */
268
+ getPoolPrice(mint: string): Promise<ApiResponse<PoolPrice>>;
269
+ /** Get top holders for a pool */
270
+ getHolders(mint: string, limit?: number): Promise<ApiResponse<{
271
+ holders: any[];
272
+ totalHolders: number;
273
+ }>>;
274
+ /** Get trade history for a pool */
275
+ getTrades(mint: string, params?: TradeListParams): Promise<PaginatedResponse<Trade>>;
276
+ /** Get OHLCV candle data for charts */
277
+ getCandles(mint: string, params: CandleParams): Promise<ApiResponse<Candle[]>>;
278
+ /** Get trade history for a specific wallet */
279
+ getUserTrades(wallet: string, params?: {
280
+ page?: number;
281
+ limit?: number;
282
+ }): Promise<PaginatedResponse<Trade>>;
283
+ /** Get a priority buy authorization (requires X verification) */
284
+ getPriorityAuth(mint: string): Promise<ApiResponse<{
285
+ signature: string;
286
+ pool: string;
287
+ wallet: string;
288
+ expiresAt: number;
289
+ }>>;
290
+ /** Check priority window status */
291
+ getPriorityStatus(mint: string): Promise<ApiResponse<{
292
+ isActive: boolean;
293
+ endsAt: string;
294
+ remainingSeconds: number;
295
+ }>>;
296
+ /** Get platform-wide statistics */
297
+ getStats(): Promise<ApiResponse<PlatformStats>>;
298
+ /** Get trending pools (24h volume) */
299
+ getTrending(limit?: number): Promise<ApiResponse<TrendingPool[]>>;
300
+ /** Get trader leaderboard */
301
+ getLeaderboard(params?: {
302
+ limit?: number;
303
+ period?: string;
304
+ }): Promise<ApiResponse<any[]>>;
305
+ /** Get fee distribution breakdown */
306
+ getFeeStats(): Promise<ApiResponse<any>>;
307
+ }
308
+
309
+ declare class PompaflyStream {
310
+ private wsUrl;
311
+ private ws;
312
+ private listeners;
313
+ private subscriptions;
314
+ private reconnectAttempts;
315
+ private maxReconnectAttempts;
316
+ private reconnectDelay;
317
+ private autoReconnect;
318
+ private isConnected;
319
+ constructor(config?: PompaflyConfig);
320
+ /** Connect to the WebSocket server */
321
+ connect(): void;
322
+ /** Disconnect from the WebSocket server */
323
+ disconnect(): void;
324
+ /** Subscribe to real-time updates for specific token mints */
325
+ subscribe(mints: string[]): void;
326
+ /** Unsubscribe from specific token mints */
327
+ unsubscribe(mints: string[]): void;
328
+ /** Listen for price update events */
329
+ onPrice(handler: (event: PriceEvent) => void): () => void;
330
+ /** Listen for new trade events */
331
+ onTrade(handler: (event: TradeEvent) => void): () => void;
332
+ /** Listen for pool status change events */
333
+ onStatus(handler: (event: StatusEvent) => void): () => void;
334
+ /** Listen for all events */
335
+ onAny(handler: StreamEventHandler): () => void;
336
+ /** Check if connected */
337
+ get connected(): boolean;
338
+ /** Get currently subscribed mints */
339
+ get subscribedMints(): string[];
340
+ private addListener;
341
+ private handleMessage;
342
+ }
343
+
344
+ /**
345
+ * Derive all PDAs for a given mint and program ID.
346
+ * Call once per pool, cache the result.
347
+ */
348
+ declare function derivePoolAddresses(mint: PublicKey, programId: PublicKey): Promise<{
349
+ pool: PublicKey;
350
+ poolBump: number;
351
+ poolTokenVault: PublicKey;
352
+ }>;
353
+ /**
354
+ * Derive the global config PDA.
355
+ */
356
+ declare function deriveGlobalConfig(programId: PublicKey): [PublicKey, number];
357
+ /**
358
+ * Convert SOL to lamports.
359
+ */
360
+ declare function solToLamports(sol: number): number;
361
+ /**
362
+ * Convert lamports to SOL.
363
+ */
364
+ declare function lamportsToSol(lamports: number | string): number;
365
+ /**
366
+ * Convert token amount to base units (6 decimals).
367
+ */
368
+ declare function tokensToBase(tokens: number): number;
369
+ /**
370
+ * Convert base units to token amount (6 decimals).
371
+ */
372
+ declare function baseToTokens(base: number | string): number;
373
+ /** Re-export program constants */
374
+ declare const PROGRAM_CONSTANTS: {
375
+ readonly TOKEN_DECIMALS: 6;
376
+ readonly TOTAL_SUPPLY: "1000000000000000";
377
+ readonly GRADUATION_THRESHOLD_SOL: 150;
378
+ readonly FEE_BPS: 100;
379
+ readonly PRIORITY_WINDOW_SECONDS: 120;
380
+ };
381
+
382
+ export { type ApiResponse, type BuyResult, type Candle, type CandleInterval, type CandleParams, type ClientOptions, type CreatePoolResult, DEVNET_CONFIG, MAINNET_CONFIG, PROGRAM_CONSTANTS, type PaginatedResponse, type PlatformStats, PompaflyAPI, PompaflyClient, type PompaflyConfig, PompaflyStream, type Pool, type PoolListParams, type PoolPrice, type PriceEvent, type SellResult, type StatusEvent, type StreamEvent, type StreamEventHandler, type Trade, type TradeEvent, type TradeListParams, type TrendingPool, type TxResult, type User, type WalletAdapter, baseToTokens, deriveGlobalConfig, derivePoolAddresses, lamportsToSol, solToLamports, tokensToBase };