@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 +187 -0
- package/dist/index.d.mts +382 -0
- package/dist/index.d.ts +382 -0
- package/dist/index.js +641 -0
- package/dist/index.mjs +609 -0
- package/package.json +35 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
// src/client/index.ts
|
|
2
|
+
import {
|
|
3
|
+
Connection,
|
|
4
|
+
Keypair,
|
|
5
|
+
PublicKey as PublicKey2,
|
|
6
|
+
SystemProgram,
|
|
7
|
+
Transaction,
|
|
8
|
+
TransactionInstruction,
|
|
9
|
+
SYSVAR_RENT_PUBKEY
|
|
10
|
+
} from "@solana/web3.js";
|
|
11
|
+
import {
|
|
12
|
+
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2,
|
|
13
|
+
ASSOCIATED_TOKEN_PROGRAM_ID as ASSOCIATED_TOKEN_PROGRAM_ID2,
|
|
14
|
+
getAssociatedTokenAddress as getAssociatedTokenAddress2
|
|
15
|
+
} from "@solana/spl-token";
|
|
16
|
+
import BN from "bn.js";
|
|
17
|
+
import { createHash } from "crypto";
|
|
18
|
+
|
|
19
|
+
// src/types/index.ts
|
|
20
|
+
var DEVNET_CONFIG = {
|
|
21
|
+
rpcUrl: "https://api.devnet.solana.com",
|
|
22
|
+
programId: "FnBDGeXKx3CsrFqxfKrLMsuNeUmMZPP19DbLbmqj8wCZ",
|
|
23
|
+
apiUrl: "https://api.pompafly.fun",
|
|
24
|
+
wsUrl: "wss://api.pompafly.fun/ws"
|
|
25
|
+
};
|
|
26
|
+
var MAINNET_CONFIG = {
|
|
27
|
+
rpcUrl: "https://api.mainnet-beta.solana.com",
|
|
28
|
+
programId: "FnBDGeXKx3CsrFqxfKrLMsuNeUmMZPP19DbLbmqj8wCZ",
|
|
29
|
+
// Update after mainnet deploy
|
|
30
|
+
apiUrl: "https://api.pompafly.fun",
|
|
31
|
+
wsUrl: "wss://api.pompafly.fun/ws"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/utils/index.ts
|
|
35
|
+
import { PublicKey } from "@solana/web3.js";
|
|
36
|
+
import {
|
|
37
|
+
getAssociatedTokenAddress,
|
|
38
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
39
|
+
TOKEN_PROGRAM_ID
|
|
40
|
+
} from "@solana/spl-token";
|
|
41
|
+
async function derivePoolAddresses(mint, programId) {
|
|
42
|
+
const [pool, poolBump] = PublicKey.findProgramAddressSync(
|
|
43
|
+
[Buffer.from("pool"), mint.toBuffer()],
|
|
44
|
+
programId
|
|
45
|
+
);
|
|
46
|
+
const poolTokenVault = await getAssociatedTokenAddress(
|
|
47
|
+
mint,
|
|
48
|
+
pool,
|
|
49
|
+
true
|
|
50
|
+
// allowOwnerOffCurve — pool is a PDA
|
|
51
|
+
);
|
|
52
|
+
return { pool, poolBump, poolTokenVault };
|
|
53
|
+
}
|
|
54
|
+
function deriveGlobalConfig(programId) {
|
|
55
|
+
return PublicKey.findProgramAddressSync(
|
|
56
|
+
[Buffer.from("global_config")],
|
|
57
|
+
programId
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function solToLamports(sol) {
|
|
61
|
+
return Math.floor(sol * 1e9);
|
|
62
|
+
}
|
|
63
|
+
function lamportsToSol(lamports) {
|
|
64
|
+
return Number(lamports) / 1e9;
|
|
65
|
+
}
|
|
66
|
+
function tokensToBase(tokens) {
|
|
67
|
+
return Math.floor(tokens * 1e6);
|
|
68
|
+
}
|
|
69
|
+
function baseToTokens(base) {
|
|
70
|
+
return Number(base) / 1e6;
|
|
71
|
+
}
|
|
72
|
+
var PROGRAM_CONSTANTS = {
|
|
73
|
+
TOKEN_DECIMALS: 6,
|
|
74
|
+
TOTAL_SUPPLY: "1000000000000000",
|
|
75
|
+
// 1B × 10^6
|
|
76
|
+
GRADUATION_THRESHOLD_SOL: 150,
|
|
77
|
+
FEE_BPS: 100,
|
|
78
|
+
PRIORITY_WINDOW_SECONDS: 120
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/client/index.ts
|
|
82
|
+
function ixDiscriminator(namespace, name) {
|
|
83
|
+
const hash = createHash("sha256").update(`${namespace}:${name}`).digest();
|
|
84
|
+
return hash.subarray(0, 8);
|
|
85
|
+
}
|
|
86
|
+
function encodeString(s) {
|
|
87
|
+
const strBytes = Buffer.from(s, "utf8");
|
|
88
|
+
const len = Buffer.alloc(4);
|
|
89
|
+
len.writeUInt32LE(strBytes.length);
|
|
90
|
+
return Buffer.concat([len, strBytes]);
|
|
91
|
+
}
|
|
92
|
+
var PompaflyClient = class {
|
|
93
|
+
connection;
|
|
94
|
+
programId;
|
|
95
|
+
config;
|
|
96
|
+
wallet;
|
|
97
|
+
globalConfigPda;
|
|
98
|
+
constructor(options) {
|
|
99
|
+
this.config = options.config || DEVNET_CONFIG;
|
|
100
|
+
this.programId = new PublicKey2(this.config.programId);
|
|
101
|
+
this.connection = options.connection || new Connection(this.config.rpcUrl, "confirmed");
|
|
102
|
+
if (options.wallet) {
|
|
103
|
+
this.wallet = options.wallet;
|
|
104
|
+
} else if (options.keypair) {
|
|
105
|
+
const kp = options.keypair;
|
|
106
|
+
this.wallet = {
|
|
107
|
+
publicKey: kp.publicKey,
|
|
108
|
+
signTransaction: async (tx) => {
|
|
109
|
+
tx.partialSign(kp);
|
|
110
|
+
return tx;
|
|
111
|
+
},
|
|
112
|
+
signAllTransactions: async (txs) => {
|
|
113
|
+
txs.forEach((tx) => tx.partialSign(kp));
|
|
114
|
+
return txs;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error("Either wallet or keypair must be provided");
|
|
119
|
+
}
|
|
120
|
+
[this.globalConfigPda] = deriveGlobalConfig(this.programId);
|
|
121
|
+
}
|
|
122
|
+
get publicKey() {
|
|
123
|
+
return this.wallet.publicKey;
|
|
124
|
+
}
|
|
125
|
+
// ── Internal helpers ───────────────────────────────────
|
|
126
|
+
async sendTx(ix, extraSigners = []) {
|
|
127
|
+
const tx = new Transaction().add(ix);
|
|
128
|
+
tx.feePayer = this.publicKey;
|
|
129
|
+
tx.recentBlockhash = (await this.connection.getLatestBlockhash()).blockhash;
|
|
130
|
+
if (extraSigners.length > 0) {
|
|
131
|
+
tx.partialSign(...extraSigners);
|
|
132
|
+
}
|
|
133
|
+
const signed = await this.wallet.signTransaction(tx);
|
|
134
|
+
const signature = await this.connection.sendRawTransaction(
|
|
135
|
+
signed.serialize()
|
|
136
|
+
);
|
|
137
|
+
await this.connection.confirmTransaction(signature, "confirmed");
|
|
138
|
+
return signature;
|
|
139
|
+
}
|
|
140
|
+
// ════════════════════════════════════════════════════════
|
|
141
|
+
// CREATE POOL
|
|
142
|
+
// ════════════════════════════════════════════════════════
|
|
143
|
+
async createPool(name, symbol, uri, creatorXHandle, authoritySigner) {
|
|
144
|
+
const mintKeypair = Keypair.generate();
|
|
145
|
+
const { pool, poolTokenVault } = await derivePoolAddresses(mintKeypair.publicKey, this.programId);
|
|
146
|
+
const disc = ixDiscriminator("global", "initialize_pool");
|
|
147
|
+
const data = Buffer.concat([
|
|
148
|
+
disc,
|
|
149
|
+
encodeString(name),
|
|
150
|
+
encodeString(symbol),
|
|
151
|
+
encodeString(uri),
|
|
152
|
+
encodeString(creatorXHandle)
|
|
153
|
+
]);
|
|
154
|
+
const ix = new TransactionInstruction({
|
|
155
|
+
programId: this.programId,
|
|
156
|
+
keys: [
|
|
157
|
+
{ pubkey: this.globalConfigPda, isSigner: false, isWritable: true },
|
|
158
|
+
{ pubkey: mintKeypair.publicKey, isSigner: true, isWritable: true },
|
|
159
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
160
|
+
{ pubkey: poolTokenVault, isSigner: false, isWritable: true },
|
|
161
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true },
|
|
162
|
+
{ pubkey: authoritySigner.publicKey, isSigner: true, isWritable: false },
|
|
163
|
+
{ pubkey: TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
164
|
+
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
165
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
166
|
+
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }
|
|
167
|
+
],
|
|
168
|
+
data
|
|
169
|
+
});
|
|
170
|
+
const signature = await this.sendTx(ix, [mintKeypair, authoritySigner]);
|
|
171
|
+
return {
|
|
172
|
+
signature,
|
|
173
|
+
mint: mintKeypair.publicKey.toBase58(),
|
|
174
|
+
pool: pool.toBase58()
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// ════════════════════════════════════════════════════════
|
|
178
|
+
// BUY
|
|
179
|
+
// ════════════════════════════════════════════════════════
|
|
180
|
+
async buy(mint, tokenAmount, maxSlippageSol, prioritySigner) {
|
|
181
|
+
const mintPk = new PublicKey2(mint);
|
|
182
|
+
const { pool, poolTokenVault } = await derivePoolAddresses(mintPk, this.programId);
|
|
183
|
+
const buyerTokenAccount = await getAssociatedTokenAddress2(mintPk, this.publicKey);
|
|
184
|
+
const baseAmount = new BN(tokensToBase(tokenAmount));
|
|
185
|
+
const maxCost = new BN(solToLamports(maxSlippageSol));
|
|
186
|
+
const disc = ixDiscriminator("global", "buy");
|
|
187
|
+
const data = Buffer.alloc(8 + 8 + 8);
|
|
188
|
+
disc.copy(data, 0);
|
|
189
|
+
data.writeBigUInt64LE(BigInt(baseAmount.toString()), 8);
|
|
190
|
+
data.writeBigUInt64LE(BigInt(maxCost.toString()), 16);
|
|
191
|
+
const keys = [
|
|
192
|
+
{ pubkey: this.globalConfigPda, isSigner: false, isWritable: false },
|
|
193
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
194
|
+
{ pubkey: mintPk, isSigner: false, isWritable: false },
|
|
195
|
+
{ pubkey: poolTokenVault, isSigner: false, isWritable: true },
|
|
196
|
+
{ pubkey: buyerTokenAccount, isSigner: false, isWritable: true },
|
|
197
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true }
|
|
198
|
+
];
|
|
199
|
+
if (prioritySigner) {
|
|
200
|
+
keys.push({ pubkey: prioritySigner.publicKey, isSigner: true, isWritable: false });
|
|
201
|
+
}
|
|
202
|
+
keys.push(
|
|
203
|
+
{ pubkey: TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
204
|
+
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
205
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
206
|
+
);
|
|
207
|
+
const ix = new TransactionInstruction({ programId: this.programId, keys, data });
|
|
208
|
+
const signers = prioritySigner ? [prioritySigner] : [];
|
|
209
|
+
const signature = await this.sendTx(ix, signers);
|
|
210
|
+
return {
|
|
211
|
+
signature,
|
|
212
|
+
tokenAmount: baseAmount.toString(),
|
|
213
|
+
solCost: maxCost.toString()
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// ════════════════════════════════════════════════════════
|
|
217
|
+
// SELL
|
|
218
|
+
// ════════════════════════════════════════════════════════
|
|
219
|
+
async sell(mint, tokenAmount, minReturnSol = 0) {
|
|
220
|
+
const mintPk = new PublicKey2(mint);
|
|
221
|
+
const { pool, poolTokenVault } = await derivePoolAddresses(mintPk, this.programId);
|
|
222
|
+
const sellerTokenAccount = await getAssociatedTokenAddress2(mintPk, this.publicKey);
|
|
223
|
+
const baseAmount = new BN(tokensToBase(tokenAmount));
|
|
224
|
+
const minReturn = new BN(solToLamports(minReturnSol));
|
|
225
|
+
const disc = ixDiscriminator("global", "sell");
|
|
226
|
+
const data = Buffer.alloc(8 + 8 + 8);
|
|
227
|
+
disc.copy(data, 0);
|
|
228
|
+
data.writeBigUInt64LE(BigInt(baseAmount.toString()), 8);
|
|
229
|
+
data.writeBigUInt64LE(BigInt(minReturn.toString()), 16);
|
|
230
|
+
const ix = new TransactionInstruction({
|
|
231
|
+
programId: this.programId,
|
|
232
|
+
keys: [
|
|
233
|
+
{ pubkey: this.globalConfigPda, isSigner: false, isWritable: false },
|
|
234
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
235
|
+
{ pubkey: mintPk, isSigner: false, isWritable: false },
|
|
236
|
+
{ pubkey: poolTokenVault, isSigner: false, isWritable: true },
|
|
237
|
+
{ pubkey: sellerTokenAccount, isSigner: false, isWritable: true },
|
|
238
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true },
|
|
239
|
+
{ pubkey: TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
240
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
241
|
+
],
|
|
242
|
+
data
|
|
243
|
+
});
|
|
244
|
+
const signature = await this.sendTx(ix);
|
|
245
|
+
return {
|
|
246
|
+
signature,
|
|
247
|
+
tokenAmount: baseAmount.toString(),
|
|
248
|
+
solReceived: minReturn.toString()
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// ════════════════════════════════════════════════════════
|
|
252
|
+
// COLLECT FEES
|
|
253
|
+
// ════════════════════════════════════════════════════════
|
|
254
|
+
async collectFees(mint, validatorWallet, communityWallet, platformWallet) {
|
|
255
|
+
const mintPk = new PublicKey2(mint);
|
|
256
|
+
const { pool } = await derivePoolAddresses(mintPk, this.programId);
|
|
257
|
+
const disc = ixDiscriminator("global", "collect_fees");
|
|
258
|
+
const ix = new TransactionInstruction({
|
|
259
|
+
programId: this.programId,
|
|
260
|
+
keys: [
|
|
261
|
+
{ pubkey: this.globalConfigPda, isSigner: false, isWritable: false },
|
|
262
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
263
|
+
{ pubkey: new PublicKey2(validatorWallet), isSigner: false, isWritable: true },
|
|
264
|
+
{ pubkey: new PublicKey2(communityWallet), isSigner: false, isWritable: true },
|
|
265
|
+
{ pubkey: new PublicKey2(platformWallet), isSigner: false, isWritable: true },
|
|
266
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
267
|
+
],
|
|
268
|
+
data: disc
|
|
269
|
+
});
|
|
270
|
+
const signature = await this.sendTx(ix);
|
|
271
|
+
return { signature };
|
|
272
|
+
}
|
|
273
|
+
// ════════════════════════════════════════════════════════
|
|
274
|
+
// GRADUATE
|
|
275
|
+
// ════════════════════════════════════════════════════════
|
|
276
|
+
async graduate(mint) {
|
|
277
|
+
const mintPk = new PublicKey2(mint);
|
|
278
|
+
const { pool, poolTokenVault } = await derivePoolAddresses(mintPk, this.programId);
|
|
279
|
+
const disc = ixDiscriminator("global", "graduate");
|
|
280
|
+
const ix = new TransactionInstruction({
|
|
281
|
+
programId: this.programId,
|
|
282
|
+
keys: [
|
|
283
|
+
{ pubkey: this.globalConfigPda, isSigner: false, isWritable: true },
|
|
284
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
285
|
+
{ pubkey: poolTokenVault, isSigner: false, isWritable: true },
|
|
286
|
+
{ pubkey: mintPk, isSigner: false, isWritable: true },
|
|
287
|
+
{ pubkey: this.publicKey, isSigner: true, isWritable: true },
|
|
288
|
+
{ pubkey: TOKEN_PROGRAM_ID2, isSigner: false, isWritable: false },
|
|
289
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
290
|
+
],
|
|
291
|
+
data: disc
|
|
292
|
+
});
|
|
293
|
+
const signature = await this.sendTx(ix);
|
|
294
|
+
return { signature };
|
|
295
|
+
}
|
|
296
|
+
// ════════════════════════════════════════════════════════
|
|
297
|
+
// READ HELPERS
|
|
298
|
+
// ════════════════════════════════════════════════════════
|
|
299
|
+
/**
|
|
300
|
+
* Get raw account data for a pool PDA.
|
|
301
|
+
* Returns the raw bytes — use with the Anchor IDL for full deserialization,
|
|
302
|
+
* or parse manually if you know the layout.
|
|
303
|
+
*/
|
|
304
|
+
async getPoolAccountInfo(mint) {
|
|
305
|
+
const mintPk = new PublicKey2(mint);
|
|
306
|
+
const { pool } = await derivePoolAddresses(mintPk, this.programId);
|
|
307
|
+
return this.connection.getAccountInfo(pool);
|
|
308
|
+
}
|
|
309
|
+
/** Get the pool PDA address for a given mint */
|
|
310
|
+
async getPoolAddress(mint) {
|
|
311
|
+
const { pool } = await derivePoolAddresses(new PublicKey2(mint), this.programId);
|
|
312
|
+
return pool.toBase58();
|
|
313
|
+
}
|
|
314
|
+
/** Get the token vault ATA address for a pool */
|
|
315
|
+
async getPoolTokenVault(mint) {
|
|
316
|
+
const { poolTokenVault } = await derivePoolAddresses(new PublicKey2(mint), this.programId);
|
|
317
|
+
return poolTokenVault.toBase58();
|
|
318
|
+
}
|
|
319
|
+
/** Get the global config PDA address */
|
|
320
|
+
getGlobalConfigAddress() {
|
|
321
|
+
return this.globalConfigPda.toBase58();
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/api/index.ts
|
|
326
|
+
var PompaflyAPI = class {
|
|
327
|
+
baseUrl;
|
|
328
|
+
token = null;
|
|
329
|
+
constructor(config) {
|
|
330
|
+
this.baseUrl = (config || DEVNET_CONFIG).apiUrl;
|
|
331
|
+
}
|
|
332
|
+
/** Set JWT token for authenticated requests */
|
|
333
|
+
setToken(token) {
|
|
334
|
+
this.token = token;
|
|
335
|
+
}
|
|
336
|
+
/** Clear authentication */
|
|
337
|
+
clearToken() {
|
|
338
|
+
this.token = null;
|
|
339
|
+
}
|
|
340
|
+
async fetch(path, options = {}) {
|
|
341
|
+
const headers = {
|
|
342
|
+
"Content-Type": "application/json",
|
|
343
|
+
...options.headers || {}
|
|
344
|
+
};
|
|
345
|
+
if (this.token) {
|
|
346
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
347
|
+
}
|
|
348
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
349
|
+
...options,
|
|
350
|
+
headers
|
|
351
|
+
});
|
|
352
|
+
if (!res.ok) {
|
|
353
|
+
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
354
|
+
throw new Error(body.error || `API error: ${res.status}`);
|
|
355
|
+
}
|
|
356
|
+
return res.json();
|
|
357
|
+
}
|
|
358
|
+
// ── Auth ────────────────────────────────────────────────
|
|
359
|
+
/** Request a login nonce for wallet signature */
|
|
360
|
+
async getNonce(wallet) {
|
|
361
|
+
return this.fetch(
|
|
362
|
+
"/api/auth/wallet/nonce",
|
|
363
|
+
{ method: "POST", body: JSON.stringify({ wallet }) }
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
/** Verify wallet signature and get JWT */
|
|
367
|
+
async verifyWallet(wallet, signature) {
|
|
368
|
+
const res = await this.fetch("/api/auth/wallet/verify", {
|
|
369
|
+
method: "POST",
|
|
370
|
+
body: JSON.stringify({ wallet, signature })
|
|
371
|
+
});
|
|
372
|
+
if (res.data.token) {
|
|
373
|
+
this.token = res.data.token;
|
|
374
|
+
}
|
|
375
|
+
return res;
|
|
376
|
+
}
|
|
377
|
+
/** Get X OAuth login URL (must be authenticated first) */
|
|
378
|
+
getXLoginUrl() {
|
|
379
|
+
return `${this.baseUrl}/api/auth/x/login`;
|
|
380
|
+
}
|
|
381
|
+
/** Get current user profile */
|
|
382
|
+
async getMe() {
|
|
383
|
+
return this.fetch("/api/auth/me");
|
|
384
|
+
}
|
|
385
|
+
// ── Pools ──────────────────────────────────────────────
|
|
386
|
+
/** List pools with filters and sorting */
|
|
387
|
+
async getPools(params) {
|
|
388
|
+
const query = new URLSearchParams();
|
|
389
|
+
if (params?.page) query.set("page", params.page.toString());
|
|
390
|
+
if (params?.limit) query.set("limit", params.limit.toString());
|
|
391
|
+
if (params?.status) query.set("status", params.status);
|
|
392
|
+
if (params?.sort) query.set("sort", params.sort);
|
|
393
|
+
if (params?.search) query.set("search", params.search);
|
|
394
|
+
if (params?.creator) query.set("creator", params.creator);
|
|
395
|
+
return this.fetch(
|
|
396
|
+
`/api/pools?${query.toString()}`
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
/** Get pool details by mint */
|
|
400
|
+
async getPool(mint) {
|
|
401
|
+
return this.fetch(`/api/pools/${mint}`);
|
|
402
|
+
}
|
|
403
|
+
/** Get current price and curve position */
|
|
404
|
+
async getPoolPrice(mint) {
|
|
405
|
+
return this.fetch(`/api/pools/${mint}/price`);
|
|
406
|
+
}
|
|
407
|
+
/** Get top holders for a pool */
|
|
408
|
+
async getHolders(mint, limit) {
|
|
409
|
+
const query = limit ? `?limit=${limit}` : "";
|
|
410
|
+
return this.fetch(
|
|
411
|
+
`/api/pools/${mint}/holders${query}`
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
// ── Trades ─────────────────────────────────────────────
|
|
415
|
+
/** Get trade history for a pool */
|
|
416
|
+
async getTrades(mint, params) {
|
|
417
|
+
const query = new URLSearchParams();
|
|
418
|
+
if (params?.page) query.set("page", params.page.toString());
|
|
419
|
+
if (params?.limit) query.set("limit", params.limit.toString());
|
|
420
|
+
if (params?.type) query.set("type", params.type);
|
|
421
|
+
if (params?.trader) query.set("trader", params.trader);
|
|
422
|
+
return this.fetch(
|
|
423
|
+
`/api/trades/${mint}?${query.toString()}`
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
/** Get OHLCV candle data for charts */
|
|
427
|
+
async getCandles(mint, params) {
|
|
428
|
+
const query = new URLSearchParams();
|
|
429
|
+
query.set("interval", params.interval);
|
|
430
|
+
if (params.from) query.set("from", params.from.toString());
|
|
431
|
+
if (params.to) query.set("to", params.to.toString());
|
|
432
|
+
if (params.limit) query.set("limit", params.limit.toString());
|
|
433
|
+
return this.fetch(
|
|
434
|
+
`/api/trades/${mint}/candles?${query.toString()}`
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
/** Get trade history for a specific wallet */
|
|
438
|
+
async getUserTrades(wallet, params) {
|
|
439
|
+
const query = new URLSearchParams();
|
|
440
|
+
if (params?.page) query.set("page", params.page.toString());
|
|
441
|
+
if (params?.limit) query.set("limit", params.limit.toString());
|
|
442
|
+
return this.fetch(
|
|
443
|
+
`/api/trades/user/${wallet}?${query.toString()}`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
// ── Priority ───────────────────────────────────────────
|
|
447
|
+
/** Get a priority buy authorization (requires X verification) */
|
|
448
|
+
async getPriorityAuth(mint) {
|
|
449
|
+
return this.fetch("/api/priority/authorize", {
|
|
450
|
+
method: "POST",
|
|
451
|
+
body: JSON.stringify({ mint })
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
/** Check priority window status */
|
|
455
|
+
async getPriorityStatus(mint) {
|
|
456
|
+
return this.fetch(`/api/priority/status/${mint}`);
|
|
457
|
+
}
|
|
458
|
+
// ── Stats ──────────────────────────────────────────────
|
|
459
|
+
/** Get platform-wide statistics */
|
|
460
|
+
async getStats() {
|
|
461
|
+
return this.fetch("/api/stats");
|
|
462
|
+
}
|
|
463
|
+
/** Get trending pools (24h volume) */
|
|
464
|
+
async getTrending(limit) {
|
|
465
|
+
const query = limit ? `?limit=${limit}` : "";
|
|
466
|
+
return this.fetch(
|
|
467
|
+
`/api/stats/trending${query}`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
/** Get trader leaderboard */
|
|
471
|
+
async getLeaderboard(params) {
|
|
472
|
+
const query = new URLSearchParams();
|
|
473
|
+
if (params?.limit) query.set("limit", params.limit.toString());
|
|
474
|
+
if (params?.period) query.set("period", params.period);
|
|
475
|
+
return this.fetch(
|
|
476
|
+
`/api/stats/leaderboard?${query.toString()}`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
/** Get fee distribution breakdown */
|
|
480
|
+
async getFeeStats() {
|
|
481
|
+
return this.fetch("/api/stats/fees");
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/stream/index.ts
|
|
486
|
+
var PompaflyStream = class {
|
|
487
|
+
wsUrl;
|
|
488
|
+
ws = null;
|
|
489
|
+
listeners = /* @__PURE__ */ new Map();
|
|
490
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
491
|
+
reconnectAttempts = 0;
|
|
492
|
+
maxReconnectAttempts = 10;
|
|
493
|
+
reconnectDelay = 1e3;
|
|
494
|
+
autoReconnect = true;
|
|
495
|
+
isConnected = false;
|
|
496
|
+
constructor(config) {
|
|
497
|
+
this.wsUrl = (config || DEVNET_CONFIG).wsUrl;
|
|
498
|
+
this.listeners.set("price", /* @__PURE__ */ new Set());
|
|
499
|
+
this.listeners.set("trade", /* @__PURE__ */ new Set());
|
|
500
|
+
this.listeners.set("status", /* @__PURE__ */ new Set());
|
|
501
|
+
this.listeners.set("all", /* @__PURE__ */ new Set());
|
|
502
|
+
}
|
|
503
|
+
/** Connect to the WebSocket server */
|
|
504
|
+
connect() {
|
|
505
|
+
if (this.ws?.readyState === WebSocket.OPEN) return;
|
|
506
|
+
this.ws = new WebSocket(this.wsUrl);
|
|
507
|
+
this.ws.onopen = () => {
|
|
508
|
+
this.isConnected = true;
|
|
509
|
+
this.reconnectAttempts = 0;
|
|
510
|
+
if (this.subscriptions.size > 0) {
|
|
511
|
+
this.ws.send(
|
|
512
|
+
JSON.stringify({
|
|
513
|
+
type: "subscribe",
|
|
514
|
+
mints: Array.from(this.subscriptions)
|
|
515
|
+
})
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
this.ws.onmessage = (event) => {
|
|
520
|
+
try {
|
|
521
|
+
const data = JSON.parse(event.data);
|
|
522
|
+
this.handleMessage(data);
|
|
523
|
+
} catch {
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
this.ws.onclose = () => {
|
|
527
|
+
this.isConnected = false;
|
|
528
|
+
if (this.autoReconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
529
|
+
this.reconnectAttempts++;
|
|
530
|
+
const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
531
|
+
setTimeout(() => this.connect(), Math.min(delay, 3e4));
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
this.ws.onerror = () => {
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/** Disconnect from the WebSocket server */
|
|
538
|
+
disconnect() {
|
|
539
|
+
this.autoReconnect = false;
|
|
540
|
+
this.ws?.close();
|
|
541
|
+
this.ws = null;
|
|
542
|
+
this.isConnected = false;
|
|
543
|
+
}
|
|
544
|
+
/** Subscribe to real-time updates for specific token mints */
|
|
545
|
+
subscribe(mints) {
|
|
546
|
+
mints.forEach((m) => this.subscriptions.add(m));
|
|
547
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
548
|
+
this.ws.send(JSON.stringify({ type: "subscribe", mints }));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/** Unsubscribe from specific token mints */
|
|
552
|
+
unsubscribe(mints) {
|
|
553
|
+
mints.forEach((m) => this.subscriptions.delete(m));
|
|
554
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
555
|
+
this.ws.send(JSON.stringify({ type: "unsubscribe", mints }));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/** Listen for price update events */
|
|
559
|
+
onPrice(handler) {
|
|
560
|
+
return this.addListener("price", handler);
|
|
561
|
+
}
|
|
562
|
+
/** Listen for new trade events */
|
|
563
|
+
onTrade(handler) {
|
|
564
|
+
return this.addListener("trade", handler);
|
|
565
|
+
}
|
|
566
|
+
/** Listen for pool status change events */
|
|
567
|
+
onStatus(handler) {
|
|
568
|
+
return this.addListener("status", handler);
|
|
569
|
+
}
|
|
570
|
+
/** Listen for all events */
|
|
571
|
+
onAny(handler) {
|
|
572
|
+
return this.addListener("all", handler);
|
|
573
|
+
}
|
|
574
|
+
/** Check if connected */
|
|
575
|
+
get connected() {
|
|
576
|
+
return this.isConnected;
|
|
577
|
+
}
|
|
578
|
+
/** Get currently subscribed mints */
|
|
579
|
+
get subscribedMints() {
|
|
580
|
+
return Array.from(this.subscriptions);
|
|
581
|
+
}
|
|
582
|
+
// ── Internal ───────────────────────────────────────────
|
|
583
|
+
addListener(type, handler) {
|
|
584
|
+
this.listeners.get(type).add(handler);
|
|
585
|
+
return () => {
|
|
586
|
+
this.listeners.get(type).delete(handler);
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
handleMessage(data) {
|
|
590
|
+
if (!data.type) return;
|
|
591
|
+
const event = data;
|
|
592
|
+
this.listeners.get(data.type)?.forEach((fn) => fn(event));
|
|
593
|
+
this.listeners.get("all")?.forEach((fn) => fn(event));
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
export {
|
|
597
|
+
DEVNET_CONFIG,
|
|
598
|
+
MAINNET_CONFIG,
|
|
599
|
+
PROGRAM_CONSTANTS,
|
|
600
|
+
PompaflyAPI,
|
|
601
|
+
PompaflyClient,
|
|
602
|
+
PompaflyStream,
|
|
603
|
+
baseToTokens,
|
|
604
|
+
deriveGlobalConfig,
|
|
605
|
+
derivePoolAddresses,
|
|
606
|
+
lamportsToSol,
|
|
607
|
+
solToLamports,
|
|
608
|
+
tokensToBase
|
|
609
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pompafly/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the Pompafly token launchpad on Solana",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
12
|
+
"lint": "eslint src/**/*.ts",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["solana", "pompafly", "launchpad", "bonding-curve", "token", "defi"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/pompafly/sdk"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@solana/web3.js": "^1.95.0",
|
|
23
|
+
"@solana/spl-token": "^0.4.6",
|
|
24
|
+
"bn.js": "^5.2.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/bn.js": "^5.1.5",
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"tsup": "^8.2.0",
|
|
30
|
+
"typescript": "^5.5.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@solana/web3.js": "^1.90.0"
|
|
34
|
+
}
|
|
35
|
+
}
|