pyre-world-kit 2.0.5 → 2.0.7
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 +2 -1
- package/dist/intel.js +27 -12
- package/package.json +1 -1
- package/src/intel.ts +26 -12
package/dist/intel.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ export declare function getAgentProfile(connection: Connection, wallet: string):
|
|
|
43
43
|
/**
|
|
44
44
|
* List all factions an agent holds tokens in.
|
|
45
45
|
*
|
|
46
|
-
* Scans the wallet's
|
|
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).
|
|
47
48
|
*/
|
|
48
49
|
export declare function getAgentFactions(connection: Connection, wallet: string, factionLimit?: number): Promise<AgentFactionPosition[]>;
|
|
49
50
|
/**
|
package/dist/intel.js
CHANGED
|
@@ -228,29 +228,44 @@ async function getAgentProfile(connection, wallet) {
|
|
|
228
228
|
/**
|
|
229
229
|
* List all factions an agent holds tokens in.
|
|
230
230
|
*
|
|
231
|
-
* Scans the wallet's
|
|
231
|
+
* Scans both the wallet's and vault's Token-2022 accounts, merging balances.
|
|
232
|
+
* Agents may hold tokens directly (no vault) or via stronghold (vault).
|
|
232
233
|
*/
|
|
233
234
|
async function getAgentFactions(connection, wallet, factionLimit = 50) {
|
|
234
235
|
const { TOKEN_2022_PROGRAM_ID } = await Promise.resolve().then(() => __importStar(require('@solana/spl-token')));
|
|
235
236
|
const walletPk = new web3_js_1.PublicKey(wallet);
|
|
236
|
-
//
|
|
237
|
-
const
|
|
237
|
+
// Scan wallet token accounts
|
|
238
|
+
const walletAccounts = await connection.getParsedTokenAccountsByOwner(walletPk, {
|
|
238
239
|
programId: TOKEN_2022_PROGRAM_ID,
|
|
239
240
|
});
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
241
|
+
// Scan vault token accounts if a vault exists
|
|
242
|
+
let vaultAccounts = { context: walletAccounts.context, value: [] };
|
|
243
|
+
try {
|
|
244
|
+
const vault = await (0, torchsdk_1.getVaultForWallet)(connection, wallet);
|
|
245
|
+
if (!vault)
|
|
246
|
+
throw new Error('no vault');
|
|
247
|
+
const vaultPk = new web3_js_1.PublicKey(vault.address);
|
|
248
|
+
vaultAccounts = await connection.getParsedTokenAccountsByOwner(vaultPk, {
|
|
249
|
+
programId: TOKEN_2022_PROGRAM_ID,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
catch { }
|
|
253
|
+
// Merge balances from both sources (wallet + vault)
|
|
254
|
+
const balanceMap = new Map();
|
|
255
|
+
for (const a of [...walletAccounts.value, ...vaultAccounts.value]) {
|
|
256
|
+
const mint = a.account.data.parsed.info.mint;
|
|
257
|
+
const balance = Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0);
|
|
258
|
+
if (balance > 0 && (0, vanity_1.isPyreMint)(mint)) {
|
|
259
|
+
balanceMap.set(mint, (balanceMap.get(mint) ?? 0) + balance);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (balanceMap.size === 0)
|
|
248
263
|
return [];
|
|
249
264
|
// Fetch faction metadata for held mints
|
|
250
265
|
const allFactions = await (0, torchsdk_1.getTokens)(connection, { limit: factionLimit });
|
|
251
266
|
const factionMap = new Map(allFactions.tokens.filter(t => (0, vanity_1.isPyreMint)(t.mint)).map(t => [t.mint, t]));
|
|
252
267
|
const positions = [];
|
|
253
|
-
for (const
|
|
268
|
+
for (const [mint, balance] of balanceMap) {
|
|
254
269
|
const faction = factionMap.get(mint);
|
|
255
270
|
if (!faction)
|
|
256
271
|
continue;
|
package/package.json
CHANGED
package/src/intel.ts
CHANGED
|
@@ -245,7 +245,8 @@ export async function getAgentProfile(
|
|
|
245
245
|
/**
|
|
246
246
|
* List all factions an agent holds tokens in.
|
|
247
247
|
*
|
|
248
|
-
* Scans the wallet's
|
|
248
|
+
* Scans both the wallet's and vault's Token-2022 accounts, merging balances.
|
|
249
|
+
* Agents may hold tokens directly (no vault) or via stronghold (vault).
|
|
249
250
|
*/
|
|
250
251
|
export async function getAgentFactions(
|
|
251
252
|
connection: Connection,
|
|
@@ -255,20 +256,33 @@ export async function getAgentFactions(
|
|
|
255
256
|
const { TOKEN_2022_PROGRAM_ID } = await import('@solana/spl-token');
|
|
256
257
|
const walletPk = new PublicKey(wallet);
|
|
257
258
|
|
|
258
|
-
//
|
|
259
|
-
const
|
|
259
|
+
// Scan wallet token accounts
|
|
260
|
+
const walletAccounts = await connection.getParsedTokenAccountsByOwner(walletPk, {
|
|
260
261
|
programId: TOKEN_2022_PROGRAM_ID,
|
|
261
262
|
});
|
|
262
263
|
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
264
|
+
// Scan vault token accounts if a vault exists
|
|
265
|
+
let vaultAccounts: typeof walletAccounts = { context: walletAccounts.context, value: [] };
|
|
266
|
+
try {
|
|
267
|
+
const vault = await getVaultForWallet(connection, wallet);
|
|
268
|
+
if (!vault) throw new Error('no vault');
|
|
269
|
+
const vaultPk = new PublicKey(vault.address);
|
|
270
|
+
vaultAccounts = await connection.getParsedTokenAccountsByOwner(vaultPk, {
|
|
271
|
+
programId: TOKEN_2022_PROGRAM_ID,
|
|
272
|
+
});
|
|
273
|
+
} catch {}
|
|
274
|
+
|
|
275
|
+
// Merge balances from both sources (wallet + vault)
|
|
276
|
+
const balanceMap = new Map<string, number>();
|
|
277
|
+
for (const a of [...walletAccounts.value, ...vaultAccounts.value]) {
|
|
278
|
+
const mint = a.account.data.parsed.info.mint as string;
|
|
279
|
+
const balance = Number(a.account.data.parsed.info.tokenAmount.uiAmount ?? 0);
|
|
280
|
+
if (balance > 0 && isPyreMint(mint)) {
|
|
281
|
+
balanceMap.set(mint, (balanceMap.get(mint) ?? 0) + balance);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
270
284
|
|
|
271
|
-
if (
|
|
285
|
+
if (balanceMap.size === 0) return [];
|
|
272
286
|
|
|
273
287
|
// Fetch faction metadata for held mints
|
|
274
288
|
const allFactions = await getTokens(connection, { limit: factionLimit });
|
|
@@ -277,7 +291,7 @@ export async function getAgentFactions(
|
|
|
277
291
|
);
|
|
278
292
|
|
|
279
293
|
const positions: AgentFactionPosition[] = [];
|
|
280
|
-
for (const
|
|
294
|
+
for (const [mint, balance] of balanceMap) {
|
|
281
295
|
const faction = factionMap.get(mint);
|
|
282
296
|
if (!faction) continue;
|
|
283
297
|
|