pyre-world-kit 1.0.4 → 1.0.6
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/dist/actions.js +65 -23
- package/package.json +1 -1
- package/src/actions.ts +75 -27
package/dist/actions.js
CHANGED
|
@@ -61,7 +61,38 @@ async function getFactions(connection, params) {
|
|
|
61
61
|
sort: params.sort,
|
|
62
62
|
} : undefined;
|
|
63
63
|
const result = await (0, torchsdk_1.getTokens)(connection, sdkParams);
|
|
64
|
-
|
|
64
|
+
const listResult = (0, mappers_1.mapTokenListResult)(result);
|
|
65
|
+
// Enrich ascended factions with live pool price (list endpoint only has stale bonding curve mcap)
|
|
66
|
+
const ascended = listResult.factions.filter(f => f.status === 'ascended');
|
|
67
|
+
if (ascended.length > 0) {
|
|
68
|
+
await Promise.all(ascended.map(async (faction) => {
|
|
69
|
+
try {
|
|
70
|
+
const mint = new web3_js_1.PublicKey(faction.mint);
|
|
71
|
+
const raydium = (0, torchsdk_1.getRaydiumMigrationAccounts)(mint);
|
|
72
|
+
const [vault0Info, vault1Info] = await Promise.all([
|
|
73
|
+
connection.getTokenAccountBalance(raydium.token0Vault),
|
|
74
|
+
connection.getTokenAccountBalance(raydium.token1Vault),
|
|
75
|
+
]);
|
|
76
|
+
const vault0 = Number(vault0Info.value.amount);
|
|
77
|
+
const vault1 = Number(vault1Info.value.amount);
|
|
78
|
+
const solReserves = raydium.isWsolToken0 ? vault0 : vault1;
|
|
79
|
+
const tokenReserves = raydium.isWsolToken0 ? vault1 : vault0;
|
|
80
|
+
if (tokenReserves > 0) {
|
|
81
|
+
// solReserves in lamports, tokenReserves in base units (10^6)
|
|
82
|
+
const LAMPORTS = 1_000_000_000;
|
|
83
|
+
const TOKEN_MUL = 1_000_000;
|
|
84
|
+
const priceInSol = (solReserves * TOKEN_MUL) / (tokenReserves * LAMPORTS);
|
|
85
|
+
const TOTAL_SUPPLY = 1_000_000_000 * TOKEN_MUL;
|
|
86
|
+
faction.price_sol = priceInSol;
|
|
87
|
+
faction.market_cap_sol = (priceInSol * TOTAL_SUPPLY) / TOKEN_MUL;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Pool may not exist yet — keep stale values
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
return listResult;
|
|
65
96
|
}
|
|
66
97
|
/** Get detailed info for a single faction */
|
|
67
98
|
async function getFaction(connection, mint) {
|
|
@@ -76,25 +107,25 @@ async function getMembers(connection, mint, limit) {
|
|
|
76
107
|
/** Get faction comms (trade-bundled messages, including post-ascension DEX messages) */
|
|
77
108
|
async function getComms(connection, mint, limit) {
|
|
78
109
|
const safeLimit = Math.min(limit || 50, 100);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
110
|
+
const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
111
|
+
// Fetch bonding curve messages AND pool state messages in parallel
|
|
112
|
+
const bondingCommsPromise = (0, torchsdk_1.getMessages)(connection, mint, safeLimit)
|
|
113
|
+
.then(r => (0, mappers_1.mapMessagesResult)(r))
|
|
114
|
+
.catch(() => ({ comms: [], total: 0 }));
|
|
115
|
+
const poolCommsPromise = (async () => {
|
|
116
|
+
try {
|
|
117
|
+
const mintPubkey = new web3_js_1.PublicKey(mint);
|
|
118
|
+
const { poolState } = (0, torchsdk_1.getRaydiumMigrationAccounts)(mintPubkey);
|
|
119
|
+
const signatures = await connection.getSignaturesForAddress(poolState, { limit: Math.min(safeLimit, 50) }, 'confirmed');
|
|
120
|
+
if (signatures.length === 0)
|
|
121
|
+
return { comms: [], total: 0 };
|
|
88
122
|
const txs = await connection.getParsedTransactions(signatures.map(s => s.signature), { maxSupportedTransactionVersion: 0 });
|
|
89
|
-
const
|
|
90
|
-
const existingSigs = new Set(commsResult.comms.map(c => c.signature));
|
|
123
|
+
const comms = [];
|
|
91
124
|
for (let i = 0; i < txs.length; i++) {
|
|
92
125
|
const tx = txs[i];
|
|
93
126
|
if (!tx?.meta || tx.meta.err)
|
|
94
127
|
continue;
|
|
95
128
|
const sig = signatures[i];
|
|
96
|
-
if (existingSigs.has(sig.signature))
|
|
97
|
-
continue;
|
|
98
129
|
// Check top-level and inner instructions for memo
|
|
99
130
|
const allInstructions = [
|
|
100
131
|
...tx.transaction.message.instructions,
|
|
@@ -119,7 +150,7 @@ async function getComms(connection, mint, limit) {
|
|
|
119
150
|
}
|
|
120
151
|
if (memoText && memoText.trim()) {
|
|
121
152
|
const sender = tx.transaction.message.accountKeys[0]?.pubkey?.toString() || 'Unknown';
|
|
122
|
-
|
|
153
|
+
comms.push({
|
|
123
154
|
signature: sig.signature,
|
|
124
155
|
memo: memoText.trim(),
|
|
125
156
|
sender,
|
|
@@ -130,16 +161,27 @@ async function getComms(connection, mint, limit) {
|
|
|
130
161
|
}
|
|
131
162
|
}
|
|
132
163
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
164
|
+
return { comms, total: comms.length };
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return { comms: [], total: 0 };
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
170
|
+
const [bondingResult, poolResult] = await Promise.all([bondingCommsPromise, poolCommsPromise]);
|
|
171
|
+
// Merge, dedupe by signature, sort newest first, trim to limit
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
const allComms = [];
|
|
174
|
+
for (const c of [...bondingResult.comms, ...poolResult.comms]) {
|
|
175
|
+
if (!seen.has(c.signature)) {
|
|
176
|
+
seen.add(c.signature);
|
|
177
|
+
allComms.push(c);
|
|
137
178
|
}
|
|
138
179
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
180
|
+
allComms.sort((a, b) => b.timestamp - a.timestamp);
|
|
181
|
+
return {
|
|
182
|
+
comms: allComms.slice(0, safeLimit),
|
|
183
|
+
total: allComms.length,
|
|
184
|
+
};
|
|
143
185
|
}
|
|
144
186
|
/** Get a quote for joining a faction (buying tokens) */
|
|
145
187
|
async function getJoinQuote(connection, mint, amountSolLamports) {
|
package/package.json
CHANGED
package/src/actions.ts
CHANGED
|
@@ -119,7 +119,39 @@ export async function getFactions(
|
|
|
119
119
|
sort: params.sort,
|
|
120
120
|
} : undefined;
|
|
121
121
|
const result = await getTokens(connection, sdkParams);
|
|
122
|
-
|
|
122
|
+
const listResult = mapTokenListResult(result);
|
|
123
|
+
|
|
124
|
+
// Enrich ascended factions with live pool price (list endpoint only has stale bonding curve mcap)
|
|
125
|
+
const ascended = listResult.factions.filter(f => f.status === 'ascended');
|
|
126
|
+
if (ascended.length > 0) {
|
|
127
|
+
await Promise.all(ascended.map(async (faction) => {
|
|
128
|
+
try {
|
|
129
|
+
const mint = new PublicKey(faction.mint);
|
|
130
|
+
const raydium = getRaydiumMigrationAccounts(mint);
|
|
131
|
+
const [vault0Info, vault1Info] = await Promise.all([
|
|
132
|
+
connection.getTokenAccountBalance(raydium.token0Vault),
|
|
133
|
+
connection.getTokenAccountBalance(raydium.token1Vault),
|
|
134
|
+
]);
|
|
135
|
+
const vault0 = Number(vault0Info.value.amount);
|
|
136
|
+
const vault1 = Number(vault1Info.value.amount);
|
|
137
|
+
const solReserves = raydium.isWsolToken0 ? vault0 : vault1;
|
|
138
|
+
const tokenReserves = raydium.isWsolToken0 ? vault1 : vault0;
|
|
139
|
+
if (tokenReserves > 0) {
|
|
140
|
+
// solReserves in lamports, tokenReserves in base units (10^6)
|
|
141
|
+
const LAMPORTS = 1_000_000_000;
|
|
142
|
+
const TOKEN_MUL = 1_000_000;
|
|
143
|
+
const priceInSol = (solReserves * TOKEN_MUL) / (tokenReserves * LAMPORTS);
|
|
144
|
+
const TOTAL_SUPPLY = 1_000_000_000 * TOKEN_MUL;
|
|
145
|
+
faction.price_sol = priceInSol;
|
|
146
|
+
faction.market_cap_sol = (priceInSol * TOTAL_SUPPLY) / TOKEN_MUL;
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
// Pool may not exist yet — keep stale values
|
|
150
|
+
}
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return listResult;
|
|
123
155
|
}
|
|
124
156
|
|
|
125
157
|
/** Get detailed info for a single faction */
|
|
@@ -148,37 +180,38 @@ export async function getComms(
|
|
|
148
180
|
limit?: number,
|
|
149
181
|
): Promise<CommsResult> {
|
|
150
182
|
const safeLimit = Math.min(limit || 50, 100);
|
|
183
|
+
const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
184
|
+
|
|
185
|
+
// Fetch bonding curve messages AND pool state messages in parallel
|
|
186
|
+
const bondingCommsPromise = getMessages(connection, mint, safeLimit)
|
|
187
|
+
.then(r => mapMessagesResult(r))
|
|
188
|
+
.catch(() => ({ comms: [], total: 0 } as CommsResult));
|
|
189
|
+
|
|
190
|
+
const poolCommsPromise = (async (): Promise<CommsResult> => {
|
|
191
|
+
try {
|
|
192
|
+
const mintPubkey = new PublicKey(mint);
|
|
193
|
+
const { poolState } = getRaydiumMigrationAccounts(mintPubkey);
|
|
194
|
+
|
|
195
|
+
const signatures = await connection.getSignaturesForAddress(
|
|
196
|
+
poolState,
|
|
197
|
+
{ limit: Math.min(safeLimit, 50) },
|
|
198
|
+
'confirmed',
|
|
199
|
+
);
|
|
151
200
|
|
|
152
|
-
|
|
153
|
-
const result = await getMessages(connection, mint, safeLimit);
|
|
154
|
-
const commsResult = mapMessagesResult(result);
|
|
155
|
-
|
|
156
|
-
// Also scan Raydium pool state for post-ascension DEX messages
|
|
157
|
-
try {
|
|
158
|
-
const mintPubkey = new PublicKey(mint);
|
|
159
|
-
const { poolState } = getRaydiumMigrationAccounts(mintPubkey);
|
|
160
|
-
|
|
161
|
-
const signatures = await connection.getSignaturesForAddress(
|
|
162
|
-
poolState,
|
|
163
|
-
{ limit: Math.min(safeLimit, 50) },
|
|
164
|
-
'confirmed',
|
|
165
|
-
);
|
|
201
|
+
if (signatures.length === 0) return { comms: [], total: 0 };
|
|
166
202
|
|
|
167
|
-
if (signatures.length > 0) {
|
|
168
203
|
const txs = await connection.getParsedTransactions(
|
|
169
204
|
signatures.map(s => s.signature),
|
|
170
205
|
{ maxSupportedTransactionVersion: 0 },
|
|
171
206
|
);
|
|
172
207
|
|
|
173
|
-
const
|
|
174
|
-
const existingSigs = new Set(commsResult.comms.map(c => c.signature));
|
|
208
|
+
const comms: CommsResult['comms'] = [];
|
|
175
209
|
|
|
176
210
|
for (let i = 0; i < txs.length; i++) {
|
|
177
211
|
const tx = txs[i];
|
|
178
212
|
if (!tx?.meta || tx.meta.err) continue;
|
|
179
213
|
|
|
180
214
|
const sig = signatures[i];
|
|
181
|
-
if (existingSigs.has(sig.signature)) continue;
|
|
182
215
|
|
|
183
216
|
// Check top-level and inner instructions for memo
|
|
184
217
|
const allInstructions = [
|
|
@@ -205,7 +238,7 @@ export async function getComms(
|
|
|
205
238
|
|
|
206
239
|
if (memoText && memoText.trim()) {
|
|
207
240
|
const sender = tx.transaction.message.accountKeys[0]?.pubkey?.toString() || 'Unknown';
|
|
208
|
-
|
|
241
|
+
comms.push({
|
|
209
242
|
signature: sig.signature,
|
|
210
243
|
memo: memoText.trim(),
|
|
211
244
|
sender,
|
|
@@ -217,16 +250,31 @@ export async function getComms(
|
|
|
217
250
|
}
|
|
218
251
|
}
|
|
219
252
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
253
|
+
return { comms, total: comms.length };
|
|
254
|
+
} catch {
|
|
255
|
+
return { comms: [], total: 0 };
|
|
256
|
+
}
|
|
257
|
+
})();
|
|
258
|
+
|
|
259
|
+
const [bondingResult, poolResult] = await Promise.all([bondingCommsPromise, poolCommsPromise]);
|
|
260
|
+
|
|
261
|
+
// Merge, dedupe by signature, sort newest first, trim to limit
|
|
262
|
+
const seen = new Set<string>();
|
|
263
|
+
const allComms: CommsResult['comms'] = [];
|
|
264
|
+
|
|
265
|
+
for (const c of [...bondingResult.comms, ...poolResult.comms]) {
|
|
266
|
+
if (!seen.has(c.signature)) {
|
|
267
|
+
seen.add(c.signature);
|
|
268
|
+
allComms.push(c);
|
|
224
269
|
}
|
|
225
|
-
} catch {
|
|
226
|
-
// Pool may not exist for non-ascended factions — ignore
|
|
227
270
|
}
|
|
228
271
|
|
|
229
|
-
|
|
272
|
+
allComms.sort((a, b) => b.timestamp - a.timestamp);
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
comms: allComms.slice(0, safeLimit),
|
|
276
|
+
total: allComms.length,
|
|
277
|
+
};
|
|
230
278
|
}
|
|
231
279
|
|
|
232
280
|
/** Get a quote for joining a faction (buying tokens) */
|