pyre-world-kit 2.0.1 → 2.0.3

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/intel.d.ts CHANGED
@@ -43,7 +43,7 @@ export declare function getAgentProfile(connection: Connection, wallet: string):
43
43
  /**
44
44
  * List all factions an agent holds tokens in.
45
45
  *
46
- * Checks top factions for this wallet's holdings.
46
+ * Scans the wallet's token accounts directly, then matches against known factions.
47
47
  */
48
48
  export declare function getAgentFactions(connection: Connection, wallet: string, factionLimit?: number): Promise<AgentFactionPosition[]>;
49
49
  /**
package/dist/intel.js CHANGED
@@ -5,6 +5,39 @@
5
5
  * Game-specific utility functions that compose torchsdk reads into
6
6
  * strategic intelligence. Agents use these to reason about the world.
7
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
+ })();
8
41
  Object.defineProperty(exports, "__esModule", { value: true });
9
42
  exports.getFactionPower = getFactionPower;
10
43
  exports.getFactionLeaderboard = getFactionLeaderboard;
@@ -195,32 +228,50 @@ async function getAgentProfile(connection, wallet) {
195
228
  /**
196
229
  * List all factions an agent holds tokens in.
197
230
  *
198
- * Checks top factions for this wallet's holdings.
231
+ * Scans the wallet's token accounts directly, then matches against known factions.
199
232
  */
200
233
  async function getAgentFactions(connection, wallet, factionLimit = 50) {
234
+ const { TOKEN_2022_PROGRAM_ID } = await Promise.resolve().then(() => __importStar(require('@solana/spl-token')));
235
+ const walletPk = new web3_js_1.PublicKey(wallet);
236
+ // Get all Token-2022 accounts for this wallet
237
+ const tokenAccounts = await connection.getParsedTokenAccountsByOwner(walletPk, {
238
+ programId: TOKEN_2022_PROGRAM_ID,
239
+ });
240
+ // Filter to pyre mints with non-zero balance
241
+ const heldMints = tokenAccounts.value
242
+ .map(a => ({
243
+ mint: a.account.data.parsed.info.mint,
244
+ balance: Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0),
245
+ }))
246
+ .filter(a => a.balance > 0 && (0, vanity_1.isPyreMint)(a.mint));
247
+ if (heldMints.length === 0)
248
+ return [];
249
+ // Fetch faction metadata for held mints
201
250
  const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: factionLimit });
202
- const pyreFactions = allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint));
251
+ const factionMap = new Map(allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint)).map(t => [t.mint, t]));
203
252
  const positions = [];
204
- // Check each faction for this holder
205
- await Promise.all(pyreFactions.map(async (faction) => {
253
+ for (const { mint, balance } of heldMints) {
254
+ const faction = factionMap.get(mint);
255
+ if (!faction)
256
+ continue;
257
+ // Get holder percentage from holders list
258
+ let percentage = 0;
206
259
  try {
207
- const holders = await getPyreHolders(connection, faction.mint, 100);
260
+ const holders = await getPyreHolders(connection, mint, 100);
208
261
  const holding = holders.holders.find(h => h.address === wallet);
209
- if (holding && holding.balance > 0) {
210
- positions.push({
211
- mint: faction.mint,
212
- name: faction.name,
213
- symbol: faction.symbol,
214
- balance: holding.balance,
215
- percentage: holding.percentage,
216
- value_sol: holding.balance * faction.price_sol,
217
- });
218
- }
262
+ if (holding)
263
+ percentage = holding.percentage;
219
264
  }
220
- catch {
221
- // Skip factions we can't read
222
- }
223
- }));
265
+ catch { }
266
+ positions.push({
267
+ mint,
268
+ name: faction.name,
269
+ symbol: faction.symbol,
270
+ balance,
271
+ percentage,
272
+ value_sol: balance * faction.price_sol,
273
+ });
274
+ }
224
275
  positions.sort((a, b) => b.value_sol - a.value_sol);
225
276
  return positions;
226
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pyre-world-kit",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Agent-first faction warfare kit — game-semantic wrapper over torchsdk",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "@solana/spl-token": "^0.4.6",
16
16
  "@solana/web3.js": "^1.98.4",
17
17
  "bs58": "^6.0.0",
18
- "torchsdk": "^3.7.36"
18
+ "torchsdk": "^3.7.37"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^22.15.0",
package/src/intel.ts CHANGED
@@ -245,39 +245,60 @@ export async function getAgentProfile(
245
245
  /**
246
246
  * List all factions an agent holds tokens in.
247
247
  *
248
- * Checks top factions for this wallet's holdings.
248
+ * Scans the wallet's token accounts directly, then matches against known factions.
249
249
  */
250
250
  export async function getAgentFactions(
251
251
  connection: Connection,
252
252
  wallet: string,
253
253
  factionLimit = 50,
254
254
  ): Promise<AgentFactionPosition[]> {
255
- const allFactions = await getTokens(connection, { limit: factionLimit });
256
- const pyreFactions = allFactions.tokens.filter(t => isPyreMint(t.mint));
257
- const positions: AgentFactionPosition[] = [];
255
+ const { TOKEN_2022_PROGRAM_ID } = await import('@solana/spl-token');
256
+ const walletPk = new PublicKey(wallet);
258
257
 
259
- // Check each faction for this holder
260
- await Promise.all(
261
- pyreFactions.map(async (faction) => {
262
- try {
263
- const holders = await getPyreHolders(connection, faction.mint, 100);
264
- const holding = holders.holders.find(h => h.address === wallet);
265
- if (holding && holding.balance > 0) {
266
- positions.push({
267
- mint: faction.mint,
268
- name: faction.name,
269
- symbol: faction.symbol,
270
- balance: holding.balance,
271
- percentage: holding.percentage,
272
- value_sol: holding.balance * faction.price_sol,
273
- });
274
- }
275
- } catch {
276
- // Skip factions we can't read
277
- }
278
- })
258
+ // Get all Token-2022 accounts for this wallet
259
+ const tokenAccounts = await connection.getParsedTokenAccountsByOwner(walletPk, {
260
+ programId: TOKEN_2022_PROGRAM_ID,
261
+ });
262
+
263
+ // Filter to pyre mints with non-zero balance
264
+ const heldMints = tokenAccounts.value
265
+ .map(a => ({
266
+ mint: a.account.data.parsed.info.mint as string,
267
+ balance: Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0),
268
+ }))
269
+ .filter(a => a.balance > 0 && isPyreMint(a.mint));
270
+
271
+ if (heldMints.length === 0) return [];
272
+
273
+ // Fetch faction metadata for held mints
274
+ const allFactions = await getTokens(connection, { limit: factionLimit });
275
+ const factionMap = new Map(
276
+ allFactions.tokens.filter(t => isPyreMint(t.mint)).map(t => [t.mint, t])
279
277
  );
280
278
 
279
+ const positions: AgentFactionPosition[] = [];
280
+ for (const { mint, balance } of heldMints) {
281
+ const faction = factionMap.get(mint);
282
+ if (!faction) continue;
283
+
284
+ // Get holder percentage from holders list
285
+ let percentage = 0;
286
+ try {
287
+ const holders = await getPyreHolders(connection, mint, 100);
288
+ const holding = holders.holders.find(h => h.address === wallet);
289
+ if (holding) percentage = holding.percentage;
290
+ } catch {}
291
+
292
+ positions.push({
293
+ mint,
294
+ name: faction.name,
295
+ symbol: faction.symbol,
296
+ balance,
297
+ percentage,
298
+ value_sol: balance * faction.price_sol,
299
+ });
300
+ }
301
+
281
302
  positions.sort((a, b) => b.value_sol - a.value_sol);
282
303
  return positions;
283
304
  }