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