pyre-world-kit 3.0.4 → 3.0.5
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/package.json +1 -1
- package/dist/actions.d.ts +0 -102
- package/dist/actions.js +0 -488
- package/dist/intel.d.ts +0 -85
- package/dist/intel.js +0 -464
- package/dist/mappers.d.ts +0 -31
- package/dist/mappers.js +0 -258
- package/dist/registry.d.ts +0 -27
- package/dist/registry.js +0 -248
package/dist/intel.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pyre Kit Intel
|
|
3
|
-
*
|
|
4
|
-
* Game-specific utility functions that compose torchsdk reads into
|
|
5
|
-
* strategic intelligence. Agents use these to reason about the world.
|
|
6
|
-
*/
|
|
7
|
-
import { Connection } from '@solana/web3.js';
|
|
8
|
-
import type { FactionPower, AllianceCluster, RivalFaction, AgentProfile, AgentFactionPosition, WorldEvent, WorldStats, FactionStatus } from './types';
|
|
9
|
-
/**
|
|
10
|
-
* Calculate a faction's power score.
|
|
11
|
-
*
|
|
12
|
-
* Score = (market_cap_sol * 0.4) + (members * 0.2) + (war_chest_sol * 0.2)
|
|
13
|
-
* + (rallies * 0.1) + (progress * 0.1)
|
|
14
|
-
*
|
|
15
|
-
* Normalized to make comparison easy. Higher = stronger.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getFactionPower(connection: Connection, mint: string): Promise<FactionPower>;
|
|
18
|
-
/**
|
|
19
|
-
* Ranked leaderboard of all factions by power score.
|
|
20
|
-
*/
|
|
21
|
-
export declare function getFactionLeaderboard(connection: Connection, opts?: {
|
|
22
|
-
status?: FactionStatus;
|
|
23
|
-
limit?: number;
|
|
24
|
-
}): Promise<FactionPower[]>;
|
|
25
|
-
/**
|
|
26
|
-
* Detect alliances: factions with shared members.
|
|
27
|
-
*
|
|
28
|
-
* Given a set of faction mints, finds wallets holding multiple faction tokens.
|
|
29
|
-
* Returns alliance clusters showing which factions share members.
|
|
30
|
-
*/
|
|
31
|
-
export declare function detectAlliances(connection: Connection, mints: string[], holderLimit?: number): Promise<AllianceCluster[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Find rival factions based on recent defection activity.
|
|
34
|
-
*
|
|
35
|
-
* Looks at recent sell messages to detect agents who have defected
|
|
36
|
-
* from or to this faction.
|
|
37
|
-
*/
|
|
38
|
-
export declare function getFactionRivals(connection: Connection, mint: string, limit?: number): Promise<RivalFaction[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Build an aggregate profile for an agent wallet.
|
|
41
|
-
*/
|
|
42
|
-
export declare function getAgentProfile(connection: Connection, wallet: string): Promise<AgentProfile>;
|
|
43
|
-
/**
|
|
44
|
-
* List all factions an agent holds tokens in.
|
|
45
|
-
*
|
|
46
|
-
* Scans both the wallet's and vault's Token-2022 accounts, merging balances.
|
|
47
|
-
* Agents may hold tokens directly (no vault) or via stronghold (vault).
|
|
48
|
-
*/
|
|
49
|
-
export declare function getAgentFactions(connection: Connection, wallet: string, factionLimit?: number): Promise<AgentFactionPosition[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Aggregated recent activity across ALL factions.
|
|
52
|
-
*
|
|
53
|
-
* The "Bloomberg terminal" feed — launches, joins, defections, rallies.
|
|
54
|
-
*/
|
|
55
|
-
export declare function getWorldFeed(connection: Connection, opts?: {
|
|
56
|
-
limit?: number;
|
|
57
|
-
factionLimit?: number;
|
|
58
|
-
}): Promise<WorldEvent[]>;
|
|
59
|
-
/**
|
|
60
|
-
* Global stats: total factions, total agents, total SOL locked.
|
|
61
|
-
*/
|
|
62
|
-
export declare function getWorldStats(connection: Connection): Promise<WorldStats>;
|
|
63
|
-
/**
|
|
64
|
-
* Get total SOL balance in lamports for an agent: vault + wallet.
|
|
65
|
-
* Checks vault first (where most SOL flows), falls back to wallet if no vault.
|
|
66
|
-
* Returns the combined balance so P&L captures all SOL movement.
|
|
67
|
-
*/
|
|
68
|
-
export declare function getAgentSolLamports(connection: Connection, wallet: string): Promise<number>;
|
|
69
|
-
/**
|
|
70
|
-
* Start tracking P&L for a single action/tick.
|
|
71
|
-
*
|
|
72
|
-
* Snapshots wallet + vault SOL before the action. Call `finish()` after
|
|
73
|
-
* to get the diff. Covers both vault and wallet flows so no SOL is missed.
|
|
74
|
-
*
|
|
75
|
-
* Usage:
|
|
76
|
-
* const pnl = await startVaultPnlTracker(connection, wallet)
|
|
77
|
-
* // ... do action ...
|
|
78
|
-
* const { spent, received } = await pnl.finish()
|
|
79
|
-
*/
|
|
80
|
-
export declare function startVaultPnlTracker(connection: Connection, wallet: string): Promise<{
|
|
81
|
-
finish: () => Promise<{
|
|
82
|
-
spent: number;
|
|
83
|
-
received: number;
|
|
84
|
-
}>;
|
|
85
|
-
}>;
|
package/dist/intel.js
DELETED
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Pyre Kit Intel
|
|
4
|
-
*
|
|
5
|
-
* Game-specific utility functions that compose torchsdk reads into
|
|
6
|
-
* strategic intelligence. Agents use these to reason about the world.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getFactionPower = getFactionPower;
|
|
43
|
-
exports.getFactionLeaderboard = getFactionLeaderboard;
|
|
44
|
-
exports.detectAlliances = detectAlliances;
|
|
45
|
-
exports.getFactionRivals = getFactionRivals;
|
|
46
|
-
exports.getAgentProfile = getAgentProfile;
|
|
47
|
-
exports.getAgentFactions = getAgentFactions;
|
|
48
|
-
exports.getWorldFeed = getWorldFeed;
|
|
49
|
-
exports.getWorldStats = getWorldStats;
|
|
50
|
-
exports.getAgentSolLamports = getAgentSolLamports;
|
|
51
|
-
exports.startVaultPnlTracker = startVaultPnlTracker;
|
|
52
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
53
|
-
const torchsdk_1 = require("torchsdk");
|
|
54
|
-
const mappers_1 = require("./mappers");
|
|
55
|
-
const vanity_1 = require("./vanity");
|
|
56
|
-
// ─── Faction Power & Rankings ──────────────────────────────────────
|
|
57
|
-
/**
|
|
58
|
-
* Calculate a faction's power score.
|
|
59
|
-
*
|
|
60
|
-
* Score = (market_cap_sol * 0.4) + (members * 0.2) + (war_chest_sol * 0.2)
|
|
61
|
-
* + (rallies * 0.1) + (progress * 0.1)
|
|
62
|
-
*
|
|
63
|
-
* Normalized to make comparison easy. Higher = stronger.
|
|
64
|
-
*/
|
|
65
|
-
async function getFactionPower(connection, mint) {
|
|
66
|
-
const t = await (0, torchsdk_1.getToken)(connection, mint);
|
|
67
|
-
const score = computePowerScore(t);
|
|
68
|
-
return {
|
|
69
|
-
mint: t.mint,
|
|
70
|
-
name: t.name,
|
|
71
|
-
symbol: t.symbol,
|
|
72
|
-
score,
|
|
73
|
-
market_cap_sol: t.market_cap_sol,
|
|
74
|
-
members: t.holders ?? 0,
|
|
75
|
-
war_chest_sol: t.treasury_sol_balance,
|
|
76
|
-
rallies: t.stars,
|
|
77
|
-
progress_percent: t.progress_percent,
|
|
78
|
-
status: (0, mappers_1.mapFactionStatus)(t.status),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Ranked leaderboard of all factions by power score.
|
|
83
|
-
*/
|
|
84
|
-
async function getFactionLeaderboard(connection, opts) {
|
|
85
|
-
// Fetch all tokens (up to 1000)
|
|
86
|
-
const statusMap = {
|
|
87
|
-
rising: 'bonding',
|
|
88
|
-
ready: 'complete',
|
|
89
|
-
ascended: 'migrated',
|
|
90
|
-
razed: 'reclaimed',
|
|
91
|
-
};
|
|
92
|
-
const sdkStatus = opts?.status ? statusMap[opts.status] : 'all';
|
|
93
|
-
// Fetch more than requested to account for non-pyre tokens being filtered out
|
|
94
|
-
const fetchLimit = Math.min((opts?.limit ?? 20) * 3, 100);
|
|
95
|
-
const result = await (0, torchsdk_1.getTokens)(connection, { limit: fetchLimit, status: sdkStatus });
|
|
96
|
-
const pyreFactions = result.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint));
|
|
97
|
-
const powers = pyreFactions.map((t) => ({
|
|
98
|
-
mint: t.mint,
|
|
99
|
-
name: t.name,
|
|
100
|
-
symbol: t.symbol,
|
|
101
|
-
score: computePowerScoreFromSummary(t),
|
|
102
|
-
market_cap_sol: t.market_cap_sol,
|
|
103
|
-
members: t.holders ?? 0,
|
|
104
|
-
war_chest_sol: 0, // Not available in summary
|
|
105
|
-
rallies: 0, // Not available in summary
|
|
106
|
-
progress_percent: t.progress_percent,
|
|
107
|
-
status: (0, mappers_1.mapFactionStatus)(t.status),
|
|
108
|
-
}));
|
|
109
|
-
powers.sort((a, b) => b.score - a.score);
|
|
110
|
-
return powers;
|
|
111
|
-
}
|
|
112
|
-
// ─── Alliance & Rivalry Detection ──────────────────────────────────
|
|
113
|
-
/**
|
|
114
|
-
* Detect alliances: factions with shared members.
|
|
115
|
-
*
|
|
116
|
-
* Given a set of faction mints, finds wallets holding multiple faction tokens.
|
|
117
|
-
* Returns alliance clusters showing which factions share members.
|
|
118
|
-
*/
|
|
119
|
-
async function detectAlliances(connection, mints, holderLimit = 50) {
|
|
120
|
-
// Fetch holders for each faction in parallel
|
|
121
|
-
const holdersPerFaction = await Promise.all(mints.map(async (mint) => {
|
|
122
|
-
const result = await getPyreHolders(connection, mint, holderLimit);
|
|
123
|
-
return { mint, holders: new Set(result.holders.map(h => h.address)) };
|
|
124
|
-
}));
|
|
125
|
-
// Find overlapping holders between faction pairs
|
|
126
|
-
const clusters = [];
|
|
127
|
-
for (let i = 0; i < holdersPerFaction.length; i++) {
|
|
128
|
-
for (let j = i + 1; j < holdersPerFaction.length; j++) {
|
|
129
|
-
const a = holdersPerFaction[i];
|
|
130
|
-
const b = holdersPerFaction[j];
|
|
131
|
-
const shared = [...a.holders].filter(h => b.holders.has(h));
|
|
132
|
-
if (shared.length > 0) {
|
|
133
|
-
const minSize = Math.min(a.holders.size, b.holders.size);
|
|
134
|
-
clusters.push({
|
|
135
|
-
factions: [a.mint, b.mint],
|
|
136
|
-
shared_members: shared.length,
|
|
137
|
-
overlap_percent: minSize > 0 ? (shared.length / minSize) * 100 : 0,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
clusters.sort((a, b) => b.shared_members - a.shared_members);
|
|
143
|
-
return clusters;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Find rival factions based on recent defection activity.
|
|
147
|
-
*
|
|
148
|
-
* Looks at recent sell messages to detect agents who have defected
|
|
149
|
-
* from or to this faction.
|
|
150
|
-
*/
|
|
151
|
-
async function getFactionRivals(connection, mint, limit = 50) {
|
|
152
|
-
// Get recent messages (sells include defection messages)
|
|
153
|
-
const msgs = await (0, torchsdk_1.getMessages)(connection, mint, limit);
|
|
154
|
-
const defectors = new Set(msgs.messages.map(m => m.sender));
|
|
155
|
-
// For each defector, check what other factions they hold
|
|
156
|
-
// This is a heuristic — we look at the messages to find patterns
|
|
157
|
-
// In practice, agents would track this over time
|
|
158
|
-
const rivalCounts = new Map();
|
|
159
|
-
// Get all factions to cross-reference
|
|
160
|
-
const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: 20, sort: 'volume' });
|
|
161
|
-
for (const faction of allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint))) {
|
|
162
|
-
if (faction.mint === mint)
|
|
163
|
-
continue;
|
|
164
|
-
const holders = await getPyreHolders(connection, faction.mint, 50);
|
|
165
|
-
const holderAddrs = new Set(holders.holders.map(h => h.address));
|
|
166
|
-
const overlap = [...defectors].filter(d => holderAddrs.has(d)).length;
|
|
167
|
-
if (overlap > 0) {
|
|
168
|
-
rivalCounts.set(faction.mint, {
|
|
169
|
-
in: overlap, // Agents from this faction who also hold rival
|
|
170
|
-
out: overlap,
|
|
171
|
-
...(rivalCounts.get(faction.mint) ?? {}),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const rivals = [];
|
|
176
|
-
for (const [rivalMint, counts] of rivalCounts) {
|
|
177
|
-
const faction = allFactions.tokens.find(t => t.mint === rivalMint);
|
|
178
|
-
if (faction) {
|
|
179
|
-
rivals.push({
|
|
180
|
-
mint: rivalMint,
|
|
181
|
-
name: faction.name,
|
|
182
|
-
symbol: faction.symbol,
|
|
183
|
-
defections_in: counts.in,
|
|
184
|
-
defections_out: counts.out,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
rivals.sort((a, b) => (b.defections_in + b.defections_out) - (a.defections_in + a.defections_out));
|
|
189
|
-
return rivals;
|
|
190
|
-
}
|
|
191
|
-
// ─── Agent Intelligence ────────────────────────────────────────────
|
|
192
|
-
/**
|
|
193
|
-
* Build an aggregate profile for an agent wallet.
|
|
194
|
-
*/
|
|
195
|
-
async function getAgentProfile(connection, wallet) {
|
|
196
|
-
// Fetch stronghold and SAID verification in parallel
|
|
197
|
-
const [vault, said] = await Promise.all([
|
|
198
|
-
(0, torchsdk_1.getVaultForWallet)(connection, wallet).catch(() => null),
|
|
199
|
-
(0, torchsdk_1.verifySaid)(wallet).catch(() => null),
|
|
200
|
-
]);
|
|
201
|
-
// Get factions this agent holds — requires scanning
|
|
202
|
-
// For now, check top factions for this holder
|
|
203
|
-
const factions = await getAgentFactions(connection, wallet);
|
|
204
|
-
// Find factions this wallet created
|
|
205
|
-
const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: 100 });
|
|
206
|
-
const founded = allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint))
|
|
207
|
-
.filter(t => t.mint) // TokenSummary doesn't have creator, so we skip for now
|
|
208
|
-
.map(t => t.mint);
|
|
209
|
-
const totalValue = factions.reduce((sum, f) => sum + f.value_sol, 0);
|
|
210
|
-
return {
|
|
211
|
-
wallet,
|
|
212
|
-
stronghold: vault ? {
|
|
213
|
-
address: vault.address,
|
|
214
|
-
creator: vault.creator,
|
|
215
|
-
authority: vault.authority,
|
|
216
|
-
sol_balance: vault.sol_balance,
|
|
217
|
-
total_deposited: vault.total_deposited,
|
|
218
|
-
total_withdrawn: vault.total_withdrawn,
|
|
219
|
-
total_spent: vault.total_spent,
|
|
220
|
-
total_received: vault.total_received,
|
|
221
|
-
linked_agents: vault.linked_wallets,
|
|
222
|
-
created_at: vault.created_at,
|
|
223
|
-
} : null,
|
|
224
|
-
factions_joined: factions,
|
|
225
|
-
factions_founded: [], // Would need per-token creator lookup
|
|
226
|
-
said_verification: said,
|
|
227
|
-
total_value_sol: totalValue + (vault?.sol_balance ?? 0),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* List all factions an agent holds tokens in.
|
|
232
|
-
*
|
|
233
|
-
* Scans both the wallet's and vault's Token-2022 accounts, merging balances.
|
|
234
|
-
* Agents may hold tokens directly (no vault) or via stronghold (vault).
|
|
235
|
-
*/
|
|
236
|
-
async function getAgentFactions(connection, wallet, factionLimit = 50) {
|
|
237
|
-
const { TOKEN_2022_PROGRAM_ID } = await Promise.resolve().then(() => __importStar(require('@solana/spl-token')));
|
|
238
|
-
const walletPk = new web3_js_1.PublicKey(wallet);
|
|
239
|
-
// Scan wallet token accounts
|
|
240
|
-
const walletAccounts = await connection.getParsedTokenAccountsByOwner(walletPk, {
|
|
241
|
-
programId: TOKEN_2022_PROGRAM_ID,
|
|
242
|
-
});
|
|
243
|
-
// Scan vault token accounts if a vault exists
|
|
244
|
-
let vaultAccounts = { context: walletAccounts.context, value: [] };
|
|
245
|
-
try {
|
|
246
|
-
const vault = await (0, torchsdk_1.getVaultForWallet)(connection, wallet);
|
|
247
|
-
if (!vault)
|
|
248
|
-
throw new Error('no vault');
|
|
249
|
-
const vaultPk = new web3_js_1.PublicKey(vault.address);
|
|
250
|
-
vaultAccounts = await connection.getParsedTokenAccountsByOwner(vaultPk, {
|
|
251
|
-
programId: TOKEN_2022_PROGRAM_ID,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
catch { }
|
|
255
|
-
// Merge balances from both sources (wallet + vault)
|
|
256
|
-
const balanceMap = new Map();
|
|
257
|
-
for (const a of [...walletAccounts.value, ...vaultAccounts.value]) {
|
|
258
|
-
const mint = a.account.data.parsed.info.mint;
|
|
259
|
-
const balance = Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0);
|
|
260
|
-
if (balance > 0 && (0, vanity_1.isPyreMint)(mint)) {
|
|
261
|
-
balanceMap.set(mint, (balanceMap.get(mint) ?? 0) + balance);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (balanceMap.size === 0)
|
|
265
|
-
return [];
|
|
266
|
-
// Fetch faction metadata for held mints
|
|
267
|
-
const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: factionLimit });
|
|
268
|
-
const factionMap = new Map(allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint)).map(t => [t.mint, t]));
|
|
269
|
-
const positions = [];
|
|
270
|
-
for (const [mint, balance] of balanceMap) {
|
|
271
|
-
const faction = factionMap.get(mint);
|
|
272
|
-
if (!faction)
|
|
273
|
-
continue;
|
|
274
|
-
// balance / 1B total supply
|
|
275
|
-
const percentage = (balance / 1_000_000_000) * 100;
|
|
276
|
-
positions.push({
|
|
277
|
-
mint,
|
|
278
|
-
name: faction.name,
|
|
279
|
-
symbol: faction.symbol,
|
|
280
|
-
balance,
|
|
281
|
-
percentage,
|
|
282
|
-
value_sol: balance * faction.price_sol,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
positions.sort((a, b) => b.value_sol - a.value_sol);
|
|
286
|
-
return positions;
|
|
287
|
-
}
|
|
288
|
-
// ─── World State ───────────────────────────────────────────────────
|
|
289
|
-
/**
|
|
290
|
-
* Aggregated recent activity across ALL factions.
|
|
291
|
-
*
|
|
292
|
-
* The "Bloomberg terminal" feed — launches, joins, defections, rallies.
|
|
293
|
-
*/
|
|
294
|
-
async function getWorldFeed(connection, opts) {
|
|
295
|
-
const factionLimit = opts?.factionLimit ?? 20;
|
|
296
|
-
const msgLimit = opts?.limit ?? 5;
|
|
297
|
-
const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: factionLimit, sort: 'newest' });
|
|
298
|
-
const events = [];
|
|
299
|
-
// Add launch events for each faction
|
|
300
|
-
for (const faction of allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint))) {
|
|
301
|
-
events.push({
|
|
302
|
-
type: 'launch',
|
|
303
|
-
faction_mint: faction.mint,
|
|
304
|
-
faction_name: faction.name,
|
|
305
|
-
timestamp: faction.created_at,
|
|
306
|
-
});
|
|
307
|
-
// Map status to events
|
|
308
|
-
if (faction.status === 'migrated') {
|
|
309
|
-
events.push({
|
|
310
|
-
type: 'ascend',
|
|
311
|
-
faction_mint: faction.mint,
|
|
312
|
-
faction_name: faction.name,
|
|
313
|
-
timestamp: faction.last_activity_at,
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
else if (faction.status === 'reclaimed') {
|
|
317
|
-
events.push({
|
|
318
|
-
type: 'raze',
|
|
319
|
-
faction_mint: faction.mint,
|
|
320
|
-
faction_name: faction.name,
|
|
321
|
-
timestamp: faction.last_activity_at,
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
// Get recent messages from top factions (messages = trade activity)
|
|
326
|
-
const topFactions = allFactions.tokens.slice(0, 10);
|
|
327
|
-
await Promise.all(topFactions.map(async (faction) => {
|
|
328
|
-
try {
|
|
329
|
-
const msgs = await (0, torchsdk_1.getMessages)(connection, faction.mint, msgLimit);
|
|
330
|
-
for (const msg of msgs.messages) {
|
|
331
|
-
events.push({
|
|
332
|
-
type: 'join', // Messages are trade-bundled, most are buys
|
|
333
|
-
faction_mint: faction.mint,
|
|
334
|
-
faction_name: faction.name,
|
|
335
|
-
agent: msg.sender,
|
|
336
|
-
timestamp: msg.timestamp,
|
|
337
|
-
signature: msg.signature,
|
|
338
|
-
message: msg.memo,
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
catch {
|
|
343
|
-
// Skip factions with no messages
|
|
344
|
-
}
|
|
345
|
-
}));
|
|
346
|
-
events.sort((a, b) => b.timestamp - a.timestamp);
|
|
347
|
-
return events.slice(0, opts?.limit ?? 100);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Global stats: total factions, total agents, total SOL locked.
|
|
351
|
-
*/
|
|
352
|
-
async function getWorldStats(connection) {
|
|
353
|
-
const all = await (0, torchsdk_1.getTokens)(connection, { limit: 200, status: 'all' });
|
|
354
|
-
const pyreAll = all.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint));
|
|
355
|
-
const pyreRising = pyreAll.filter(t => t.status === 'bonding');
|
|
356
|
-
const pyreAscended = pyreAll.filter(t => t.status === 'migrated');
|
|
357
|
-
const allFactions = [...pyreRising, ...pyreAscended];
|
|
358
|
-
const totalSolLocked = allFactions.reduce((sum, t) => sum + t.market_cap_sol, 0);
|
|
359
|
-
// Find most powerful
|
|
360
|
-
let mostPowerful = null;
|
|
361
|
-
let maxScore = 0;
|
|
362
|
-
for (const t of allFactions) {
|
|
363
|
-
const score = computePowerScoreFromSummary(t);
|
|
364
|
-
if (score > maxScore) {
|
|
365
|
-
maxScore = score;
|
|
366
|
-
mostPowerful = {
|
|
367
|
-
mint: t.mint,
|
|
368
|
-
name: t.name,
|
|
369
|
-
symbol: t.symbol,
|
|
370
|
-
score,
|
|
371
|
-
market_cap_sol: t.market_cap_sol,
|
|
372
|
-
members: t.holders ?? 0,
|
|
373
|
-
war_chest_sol: 0,
|
|
374
|
-
rallies: 0,
|
|
375
|
-
progress_percent: t.progress_percent,
|
|
376
|
-
status: (0, mappers_1.mapFactionStatus)(t.status),
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
total_factions: pyreAll.length,
|
|
382
|
-
rising_factions: pyreRising.length,
|
|
383
|
-
ascended_factions: pyreAscended.length,
|
|
384
|
-
total_sol_locked: totalSolLocked,
|
|
385
|
-
most_powerful: mostPowerful,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
/** Fetch holders excluding program-owned accounts (bonding curve, treasury, treasury lock) */
|
|
389
|
-
async function getPyreHolders(connection, mint, limit) {
|
|
390
|
-
const mintPk = new web3_js_1.PublicKey(mint);
|
|
391
|
-
const [bondingCurve] = (0, vanity_1.getBondingCurvePda)(mintPk);
|
|
392
|
-
const [treasury] = (0, vanity_1.getTokenTreasuryPda)(mintPk);
|
|
393
|
-
const [treasuryLock] = (0, vanity_1.getTreasuryLockPda)(mintPk);
|
|
394
|
-
const excluded = new Set([bondingCurve.toString(), treasury.toString(), treasuryLock.toString()]);
|
|
395
|
-
const result = await (0, torchsdk_1.getHolders)(connection, mint, limit + 5);
|
|
396
|
-
result.holders = result.holders.filter(h => !excluded.has(h.address)).slice(0, limit);
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
// ─── Vault P&L ────────────────────────────────────────────────────
|
|
400
|
-
/**
|
|
401
|
-
* Get total SOL balance in lamports for an agent: vault + wallet.
|
|
402
|
-
* Checks vault first (where most SOL flows), falls back to wallet if no vault.
|
|
403
|
-
* Returns the combined balance so P&L captures all SOL movement.
|
|
404
|
-
*/
|
|
405
|
-
async function getAgentSolLamports(connection, wallet) {
|
|
406
|
-
const walletPk = new web3_js_1.PublicKey(wallet);
|
|
407
|
-
let total = 0;
|
|
408
|
-
try {
|
|
409
|
-
total += await connection.getBalance(walletPk);
|
|
410
|
-
}
|
|
411
|
-
catch { }
|
|
412
|
-
try {
|
|
413
|
-
const vault = await (0, torchsdk_1.getVaultForWallet)(connection, wallet);
|
|
414
|
-
if (vault)
|
|
415
|
-
total += Math.round(vault.sol_balance * 1e9);
|
|
416
|
-
}
|
|
417
|
-
catch { }
|
|
418
|
-
return total;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Start tracking P&L for a single action/tick.
|
|
422
|
-
*
|
|
423
|
-
* Snapshots wallet + vault SOL before the action. Call `finish()` after
|
|
424
|
-
* to get the diff. Covers both vault and wallet flows so no SOL is missed.
|
|
425
|
-
*
|
|
426
|
-
* Usage:
|
|
427
|
-
* const pnl = await startVaultPnlTracker(connection, wallet)
|
|
428
|
-
* // ... do action ...
|
|
429
|
-
* const { spent, received } = await pnl.finish()
|
|
430
|
-
*/
|
|
431
|
-
async function startVaultPnlTracker(connection, wallet) {
|
|
432
|
-
const before = await getAgentSolLamports(connection, wallet);
|
|
433
|
-
return {
|
|
434
|
-
async finish() {
|
|
435
|
-
const after = await getAgentSolLamports(connection, wallet);
|
|
436
|
-
const diff = after - before;
|
|
437
|
-
return {
|
|
438
|
-
spent: diff < 0 ? Math.abs(diff) : 0,
|
|
439
|
-
received: diff > 0 ? diff : 0,
|
|
440
|
-
};
|
|
441
|
-
},
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
// ─── Internal Helpers ──────────────────────────────────────────────
|
|
445
|
-
function computePowerScore(t) {
|
|
446
|
-
const mcWeight = 0.4;
|
|
447
|
-
const memberWeight = 0.2;
|
|
448
|
-
const chestWeight = 0.2;
|
|
449
|
-
const rallyWeight = 0.1;
|
|
450
|
-
const progressWeight = 0.1;
|
|
451
|
-
return ((t.market_cap_sol * mcWeight) +
|
|
452
|
-
((t.holders ?? 0) * memberWeight) +
|
|
453
|
-
(t.treasury_sol_balance * chestWeight) +
|
|
454
|
-
(t.stars * rallyWeight) +
|
|
455
|
-
(t.progress_percent * progressWeight));
|
|
456
|
-
}
|
|
457
|
-
function computePowerScoreFromSummary(t) {
|
|
458
|
-
const mcWeight = 0.4;
|
|
459
|
-
const memberWeight = 0.2;
|
|
460
|
-
const progressWeight = 0.1;
|
|
461
|
-
return ((t.market_cap_sol * mcWeight) +
|
|
462
|
-
((t.holders ?? 0) * memberWeight) +
|
|
463
|
-
(t.progress_percent * progressWeight));
|
|
464
|
-
}
|
package/dist/mappers.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pyre Kit Mappers
|
|
3
|
-
*
|
|
4
|
-
* Internal mapping functions between Torch SDK types and Pyre game types.
|
|
5
|
-
*/
|
|
6
|
-
import type { TokenStatus, TokenSummary, TokenDetail, TokenStatusFilter, VaultInfo, VaultWalletLinkInfo, TokenMessage, LendingInfo, LoanPositionInfo, LoanPositionWithKey, Holder, HoldersResult, MessagesResult, TokenListResult, AllLoanPositionsResult, BuyTransactionResult, CreateTokenResult } from 'torchsdk';
|
|
7
|
-
import type { FactionStatus, FactionTier, FactionStatusFilter, Strategy, FactionSummary, FactionDetail, Stronghold, AgentLink, Comms, WarChest, WarLoan, WarLoanWithAgent, Member, FactionListResult, MembersResult, CommsResult, AllWarLoansResult, JoinFactionResult, LaunchFactionResult } from './types';
|
|
8
|
-
export declare function mapFactionStatus(status: TokenStatus): FactionStatus;
|
|
9
|
-
export declare function mapTokenStatus(status: FactionStatus): TokenStatus;
|
|
10
|
-
export declare function mapTokenStatusFilter(status: FactionStatusFilter): TokenStatusFilter;
|
|
11
|
-
/** Map SOL target to faction tier */
|
|
12
|
-
export declare function mapFactionTier(sol_target: number): FactionTier;
|
|
13
|
-
/** Infer tier from sol_target in SOL (not lamports) */
|
|
14
|
-
export declare function mapFactionTierFromSol(sol_target: number): FactionTier;
|
|
15
|
-
export declare function mapStrategy(vote: 'burn' | 'return'): Strategy;
|
|
16
|
-
export declare function mapVote(strategy: Strategy): 'burn' | 'return';
|
|
17
|
-
export declare function mapTokenSummaryToFaction(t: TokenSummary): FactionSummary;
|
|
18
|
-
export declare function mapTokenDetailToFaction(t: TokenDetail): FactionDetail;
|
|
19
|
-
export declare function mapVaultToStronghold(v: VaultInfo): Stronghold;
|
|
20
|
-
export declare function mapWalletLinkToAgentLink(l: VaultWalletLinkInfo): AgentLink;
|
|
21
|
-
export declare function mapTokenMessageToComms(m: TokenMessage): Comms;
|
|
22
|
-
export declare function mapLendingToWarChest(l: LendingInfo): WarChest;
|
|
23
|
-
export declare function mapLoanToWarLoan(l: LoanPositionInfo): WarLoan;
|
|
24
|
-
export declare function mapLoanWithKeyToWarLoan(l: LoanPositionWithKey): WarLoanWithAgent;
|
|
25
|
-
export declare function mapHolderToMember(h: Holder): Member;
|
|
26
|
-
export declare function mapTokenListResult(r: TokenListResult): FactionListResult;
|
|
27
|
-
export declare function mapHoldersResult(r: HoldersResult): MembersResult;
|
|
28
|
-
export declare function mapMessagesResult(r: MessagesResult): CommsResult;
|
|
29
|
-
export declare function mapAllLoansResult(r: AllLoanPositionsResult): AllWarLoansResult;
|
|
30
|
-
export declare function mapBuyResult(r: BuyTransactionResult): JoinFactionResult;
|
|
31
|
-
export declare function mapCreateResult(r: CreateTokenResult): LaunchFactionResult;
|