pyre-world-kit 2.0.12 → 3.0.1

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.
Files changed (53) hide show
  1. package/.prettierrc.json +6 -0
  2. package/dist/index.d.ts +46 -4
  3. package/dist/index.js +105 -85
  4. package/dist/providers/action.provider.d.ts +46 -0
  5. package/dist/providers/action.provider.js +331 -0
  6. package/dist/providers/intel.provider.d.ts +29 -0
  7. package/dist/providers/intel.provider.js +363 -0
  8. package/dist/providers/mapper.provider.d.ts +197 -0
  9. package/dist/providers/mapper.provider.js +158 -0
  10. package/dist/providers/registry.provider.d.ts +25 -0
  11. package/dist/providers/registry.provider.js +229 -0
  12. package/dist/providers/state.provider.d.ts +42 -0
  13. package/dist/providers/state.provider.js +348 -0
  14. package/dist/pyre_world.json +34 -229
  15. package/dist/types/action.types.d.ts +41 -0
  16. package/dist/types/action.types.js +2 -0
  17. package/dist/types/intel.types.d.ts +20 -0
  18. package/dist/types/intel.types.js +2 -0
  19. package/dist/types/mapper.types.d.ts +27 -0
  20. package/dist/types/mapper.types.js +22 -0
  21. package/dist/types/registry.types.d.ts +0 -0
  22. package/dist/types/registry.types.js +1 -0
  23. package/dist/types/state.types.d.ts +112 -0
  24. package/dist/types/state.types.js +2 -0
  25. package/dist/types.d.ts +8 -24
  26. package/dist/util.d.ts +29 -0
  27. package/dist/util.js +144 -0
  28. package/dist/vanity.d.ts +3 -3
  29. package/dist/vanity.js +18 -15
  30. package/package.json +4 -2
  31. package/readme.md +184 -142
  32. package/src/index.ts +133 -92
  33. package/src/providers/action.provider.ts +443 -0
  34. package/src/providers/intel.provider.ts +383 -0
  35. package/src/providers/mapper.provider.ts +195 -0
  36. package/src/providers/registry.provider.ts +277 -0
  37. package/src/providers/state.provider.ts +357 -0
  38. package/src/pyre_world.json +35 -230
  39. package/src/types/action.types.ts +76 -0
  40. package/src/types/intel.types.ts +22 -0
  41. package/src/types/mapper.types.ts +84 -0
  42. package/src/types/registry.types.ts +0 -0
  43. package/src/types/state.types.ts +144 -0
  44. package/src/types.ts +329 -333
  45. package/src/util.ts +148 -0
  46. package/src/vanity.ts +27 -14
  47. package/tests/test_e2e.ts +339 -172
  48. package/src/actions.ts +0 -719
  49. package/src/intel.ts +0 -521
  50. package/src/mappers.ts +0 -302
  51. package/src/registry.ts +0 -317
  52. package/tests/test_devnet_e2e.ts +0 -401
  53. package/tests/test_sim.ts +0 -458
package/src/actions.ts DELETED
@@ -1,719 +0,0 @@
1
- /**
2
- * Pyre Kit Actions
3
- *
4
- * Thin wrappers that call torchsdk functions and map params/results
5
- * into game-semantic Pyre types. No new on-chain logic.
6
- */
7
-
8
- import { Connection, PublicKey, type GetProgramAccountsFilter } from '@solana/web3.js';
9
- import {
10
- // Read operations
11
- getTokens,
12
- getToken,
13
- getHolders,
14
- getMessages,
15
- getBuyQuote,
16
- getSellQuote,
17
- getBorrowQuote,
18
- getVault,
19
- getVaultForWallet,
20
- getVaultWalletLink,
21
- getLendingInfo,
22
- getLoanPosition,
23
- getAllLoanPositions,
24
- // PDA derivation
25
- getRaydiumMigrationAccounts,
26
- // Transaction builders
27
- buildBuyTransaction,
28
- buildDirectBuyTransaction,
29
- buildSellTransaction,
30
- buildStarTransaction,
31
- buildBorrowTransaction,
32
- buildRepayTransaction,
33
- buildLiquidateTransaction,
34
- buildVaultSwapTransaction,
35
- buildClaimProtocolRewardsTransaction,
36
- buildCreateVaultTransaction,
37
- buildDepositVaultTransaction,
38
- buildWithdrawVaultTransaction,
39
- buildLinkWalletTransaction,
40
- buildUnlinkWalletTransaction,
41
- buildTransferAuthorityTransaction,
42
- buildWithdrawTokensTransaction,
43
- buildMigrateTransaction,
44
- buildReclaimFailedTokenTransaction,
45
- buildHarvestFeesTransaction,
46
- buildSwapFeesToSolTransaction,
47
- // Utilities
48
- verifySaid,
49
- confirmTransaction,
50
- PROGRAM_ID,
51
- } from 'torchsdk';
52
-
53
- import type { BuyQuoteResult, SellQuoteResult, TransactionResult, SaidVerification, ConfirmResult } from 'torchsdk';
54
-
55
- import type {
56
- FactionListParams,
57
- FactionListResult,
58
- FactionDetail,
59
- MembersResult,
60
- CommsResult,
61
- Stronghold,
62
- AgentLink,
63
- WarChest,
64
- WarLoan,
65
- WarLoanQuote,
66
- AllWarLoansResult,
67
- LaunchFactionParams,
68
- JoinFactionParams,
69
- DirectJoinFactionParams,
70
- DefectParams,
71
- MessageFactionParams,
72
- FudFactionParams,
73
- RallyParams,
74
- RequestWarLoanParams,
75
- RepayWarLoanParams,
76
- SiegeParams,
77
- TradeOnDexParams,
78
- ClaimSpoilsParams,
79
- CreateStrongholdParams,
80
- FundStrongholdParams,
81
- WithdrawFromStrongholdParams,
82
- RecruitAgentParams,
83
- ExileAgentParams,
84
- CoupParams,
85
- WithdrawAssetsParams,
86
- AscendParams,
87
- RazeParams,
88
- TitheParams,
89
- ConvertTitheParams,
90
- JoinFactionResult,
91
- LaunchFactionResult,
92
- FactionStatus,
93
- } from './types';
94
-
95
- import {
96
- mapTokenListResult,
97
- mapTokenDetailToFaction,
98
- mapHoldersResult,
99
- mapMessagesResult,
100
- mapVaultToStronghold,
101
- mapWalletLinkToAgentLink,
102
- mapLendingToWarChest,
103
- mapLoanToWarLoan,
104
- mapAllLoansResult,
105
- mapBuyResult,
106
- mapCreateResult,
107
- mapVote,
108
- mapTokenStatusFilter,
109
- } from './mappers';
110
-
111
- import { buildCreateFactionTransaction, isPyreMint, getBondingCurvePda, getTokenTreasuryPda, getTreasuryLockPda } from './vanity';
112
-
113
- // ─── Blacklist ──────────────────────────────────────────────────────
114
- // Mints from previous swarm runs. Agents should skip these and only
115
- // interact with freshly launched factions.
116
-
117
- const DEFAULT_BLACKLIST = [
118
- 'E1SgYPW6JXhw5BabrvJkr6L2PyvfFenYaoCTePazyNpy','6jWsyDC87RmfrZZRjuxSAxvUxE665HGZwZ2Z8j5z9epy',
119
- '6J8PLgFxHb98cNURP2Yt2SKwgnUeEXpN6Us2kxaMz1py','5A297UyPQstxWpJyydDnFvn2zN8whCEYdqvnfB5bF9py',
120
- '8XdWfSKLJusAcRrYzK3bWJ7dy46AkbU8qxF3B55uSfpy','7ZYrKcJbFFbG36keCYRvfc1j1HScQmJW1zRV3wVVD4py',
121
- 'ERQPyG2oqx5bdyuY2Nnm5ZbZY2zcB46TfUxqpzYWH5py','JCvpK3kTnh2EdQG71mqE8ZXcvzLU5EJNG5vgGZme4wpy',
122
- '9RDFkGSjKpjHtXZ25uuug2MN5P7oSjzkLg16HcrKy3py','2kWcX1ZetV4jUtBPbKKk265q4gS4nuut2kc1MbaZDfpy',
123
- '3r9FnQim6GToR7NkY5om8igUNu7gfpq5fk2qtv3bV5py','2498F79s1Ghyj3J4VhV1qy5hhznnM53ZwzTXM9iscopy',
124
- '5VpotyDyc8QKKqLuzu8pfhtEa9gsRG1ww58DbqJUgTpy','GXi1opahTkavPfAqfUhkoUJRBjPoAmAMVW87kdbDwNpy',
125
- 'GKFAokGiyhXGXxUPgwQEo8fE5nBjRdJcVX6LVj7SgPpy','EKFVwfNk1xzqhpyFJSMNw8KDcLRemvqxiGoSyfRtBspy',
126
- 'GsZLHVt3mTwus5krUcifBWS52xMQSuXSy3RpPhEFtvpy','9azKjXnt2w4RB5ykVcyaicWSssmxoapZ9SSQLMZc4Epy',
127
- 'BaLwryyMrqhtsMrELkrTSdWF9UYuNdjW4413hrQqbtpy','5p9ibszMVe79mm95M8uubS6WttXem2xZfh3mWmBdvUpy',
128
- 'CTvoAmTggJcBTnbxcfy91Y1c6t6fU5xq3SRtYh3TgEpy','2kqVCdQS9KSv2kxLiytGZfcLsx5xwKQT6rHTg4V18hpy',
129
- 'zV7XZcvY8DVk4scKUiw7GGN4L3eBPSXuD7Q1NPxfspy','3UhzKfdU1wgnEN2VCykRURw88qVVqeu3ejRkUnjmhRpy',
130
- 'FRaS3dAdr1zo6u811XBVGUp9K2mSdQ2yG8qW4qP5hapy','4NHzWVP7hzZhd9LhTrbyxzsSnT8EmNSYVP1DpAKXHYpy',
131
- 'Yt2rdfp6uzS7L52df3LPmetLoy3GvKChYJ4Lmvk6gpy','9Ejju29KHPWMpda4WpFsJ6ZDHVUqNWyMZHteEisgw9py',
132
- '2zPC4A7WR2cMNDfBzERp49fEbTBCyqXPKhcrgz3hWcpy','7jBAriydb1qRy7Wg4WAz8woHP4pVxZJSnF7vw95tVQpy',
133
- 'HvPWKuMFpG3zAdkPMbaadyo78VoJbAMtpXaBYMK1Aqpy','GyNw9bkqz2rhR66Xx7P4p11PFBrjPi2r6XoCg5gPAdpy',
134
- '6HveNEes9xtkkchb76JgjWWQ61sbXjESy2vr3A7Maipy','8E3GETvTkTTaCLpzkyHJTnuNMfmGvzUEgAYnurZuLZpy',
135
- 'AeApaJqppwjW9S2KeZGPZpmg1kAdxZHkFRnXPZc8Kjpy','8FfteyAMQm96upu4w6cJvE5T8RcMKRf5keJMdXbukXpy',
136
- 'BrEj2Q9XE13WesRU1u8USiprv2DkpBcJfaqQeqQ6grpy','Dtki37mAB3DiTW1bp8LnZQyv54UuC68Yo5pGZkPdVSpy',
137
- '77UzTntZ7ThyXhN4hVvSx7m6tjit8uCw6U2LVQHPSqpy','ASV9kiC6vEpZy3X7xVExuyG257KHKd3Hutbji8AVRUpy',
138
- 'Fc1V6KcxSriJkUNeDLqz8w5Sm4mp1s8gxornZVLcHEpy','FEizyHEUoYenqfpF87kqiGnq3w1R2TReodEfsnTrrfpy',
139
- 'DmwgcVHoJxKeRiij5LtedY9LWDpqoqa3hGfUyVgBkgpy','GUGz1Em5KZ57aKFqEBSd4Y4Vb6WxBd3H2b16fPCC6upy',
140
- '6ZWY3Bau5zw1j7vMQQ1czSw4rjBJrExHQ8Renor2vLpy',
141
- // wave 3
142
- '4LyPhwUCZNLEp45RsGWdwtkX5tb3wmwydBKEu1V7fxpy','FYw8FZKzG6vVweUMQgSXBrY9ViHgquWyN4x5QthaK3py',
143
- 'DhFhRRpRMkPi2Vz3kErZWHNmWqxgQm5YwXT5pFpgVKpy','6GLqPmACtuDi4LcMtVpFK43sYkG8yVouYiDfdfBSSVpy',
144
- '8YYYewvvCTGPZ2UddgrD6oWUZD7CYXe3DBbA9GBkapy','FpQT2uDi3oxEpnayKHAUCcWXVhtDaZCb85e7nZzoCUpy',
145
- '5EWX6grTtA46FQUHGC1kogCW3CsnVfXNvVgrYVtwvRpy','8HSvBFkr6gu9qtbMKcTAZSjzkj4Ag1d1wkdiaMDHHapy',
146
- '2hgo2kdtNNQGNuvfEPSfydWDqfhSwfbFTzgeVb758wpy','DKvaEayFig3RHQ9rXHnCKBjvMnJCstzuBmSe77Ybf6py',
147
- 'Cws3YSPxWYxzrEEfguLi3p13ea2vPNi42mjJwwSMTTpy','GodcBg2dLzrypiYH5Aqo2bTJ7KiZa5G5XSDwNQ74iYpy',
148
- '46tUp7tMEhpLeenPXQwvzP8H8V5M4F63vi4M9k4bbbpy','a5iH2Soh5c8X81vTVbKZq7A7yPckhFdN1amv1Q2tapy',
149
- '2zTGWtQeJ5GtdHu888QikPzKkyHJPWVFYtoQjNeJJ7py','HNnpL7z1GKsXuxaEHs2a52zW7tTUjU4dZnrSEf8ZsMpy',
150
- 'EASit9Yrj1SBg6xchFxDSwVV9Rz11RKdDpB4tcNsekpy','F7VcdtqsXV6nkDL3yk6esUBu9qGvka4EY9XNTQ7PmZpy',
151
- '3huHC9Co5dy5Z5U6H8Vf7aVTcuukpKeUr8rDQx8s5Zpy','97ymhwybP8Jh45VcYBJY1pwQ5xkPLX15u7Tg3P7TG7py',
152
- '92fMEzcYdcoEXX8A5T8i8vfz2S96P39abzoXXuBghfpy','2ZeQsU13WjgX2152qV3wyzxURjLg7GwfXznAiA99Jjpy',
153
- 'FuUHck8jqaXxGiTuLym4gYXJQrueyEsgd8AMUQx2fMpy','trTuaGATQZwUeYkYTeyJfQnGGnKRvAriAZRgBWg7Epy',
154
- 'HEhemzeszztaFzFYR9DjpNwdhghVDD1y7cHxP93EPZpy','obuf6MkL1ev6WuUDDjH3bq2q6Ryr6MBNMRsA6dEW4py',
155
- '76ruUbqBpqSKsysoPesDrpaLsDSahWWphQmXrswiLbpy','4ci4scCevt5tXCxkGr5xHoWyaeQY1dahp5nFsTnfYApy',
156
- 'shzuPKgqedBxJmxdrRyWAtajG3hSNyLr72SufvmEvpy',
157
- ];
158
-
159
- const BLACKLISTED_MINTS = new Set<string>(DEFAULT_BLACKLIST);
160
-
161
- /** Add mints to the blacklist (call at startup with old mints) */
162
- export function blacklistMints(mints: string[]): void {
163
- for (const m of mints) BLACKLISTED_MINTS.add(m);
164
- }
165
-
166
- /** Check if a mint is blacklisted */
167
- export function isBlacklistedMint(mint: string): boolean {
168
- return BLACKLISTED_MINTS.has(mint);
169
- }
170
-
171
- /** Get all blacklisted mints */
172
- export function getBlacklistedMints(): string[] {
173
- return Array.from(BLACKLISTED_MINTS);
174
- }
175
-
176
- // ─── Read Operations ───────────────────────────────────────────────
177
-
178
- /** List all factions with optional filtering and sorting */
179
- export async function getFactions(
180
- connection: Connection,
181
- params?: FactionListParams,
182
- ): Promise<FactionListResult> {
183
- const sdkParams = params ? {
184
- limit: params.limit,
185
- offset: params.offset,
186
- status: params.status ? mapTokenStatusFilter(params.status) : undefined,
187
- sort: params.sort,
188
- } : undefined;
189
- const result = await getTokens(connection, sdkParams);
190
- return mapTokenListResult(result);
191
- }
192
-
193
- /** Get detailed info for a single faction */
194
- export async function getFaction(
195
- connection: Connection,
196
- mint: string,
197
- ): Promise<FactionDetail> {
198
- const detail = await getToken(connection, mint);
199
- return mapTokenDetailToFaction(detail);
200
- }
201
-
202
- /** Get faction members (top holders, excluding program-owned accounts) */
203
- export async function getMembers(
204
- connection: Connection,
205
- mint: string,
206
- limit?: number,
207
- ): Promise<MembersResult> {
208
- const mintPk = new PublicKey(mint);
209
- const [bondingCurve] = getBondingCurvePda(mintPk);
210
- const [treasury] = getTokenTreasuryPda(mintPk);
211
- const [treasuryLock] = getTreasuryLockPda(mintPk);
212
- const excluded = new Set([
213
- bondingCurve.toString(),
214
- treasury.toString(),
215
- treasuryLock.toString(),
216
- ]);
217
-
218
- // Fetch extra to compensate for filtered-out program accounts
219
- const result = await getHolders(connection, mint, (limit ?? 10) + 5);
220
- result.holders = result.holders.filter(h => !excluded.has(h.address));
221
- if (limit) result.holders = result.holders.slice(0, limit);
222
- return mapHoldersResult(result);
223
- }
224
-
225
- /** Get faction comms (trade-bundled messages, including post-ascension DEX messages) */
226
- export async function getComms(
227
- connection: Connection,
228
- mint: string,
229
- limit?: number,
230
- status?: FactionStatus,
231
- ): Promise<CommsResult> {
232
- // Non-ascended: bonding curve only (1 RPC call)
233
- // Ascended: pool only (1 RPC call) — bonding curve is stale post-migration
234
- const source = status === 'ascended' ? 'pool' : status ? 'bonding' : 'all';
235
- const result = await getMessages(connection, mint, limit, { source });
236
- return mapMessagesResult(result);
237
- }
238
-
239
- /** Get a quote for joining a faction (buying tokens) */
240
- export async function getJoinQuote(
241
- connection: Connection,
242
- mint: string,
243
- amountSolLamports: number,
244
- ): Promise<BuyQuoteResult> {
245
- return getBuyQuote(connection, mint, amountSolLamports);
246
- }
247
-
248
- /** Get a quote for defecting from a faction (selling tokens) */
249
- export async function getDefectQuote(
250
- connection: Connection,
251
- mint: string,
252
- amountTokens: number,
253
- ): Promise<SellQuoteResult> {
254
- return getSellQuote(connection, mint, amountTokens);
255
- }
256
-
257
- /** Get stronghold (vault) by creator */
258
- export async function getStronghold(
259
- connection: Connection,
260
- creator: string,
261
- ): Promise<Stronghold | null> {
262
- const vault = await getVault(connection, creator);
263
- return vault ? mapVaultToStronghold(vault) : null;
264
- }
265
-
266
- /** Get stronghold for a linked agent wallet */
267
- export async function getStrongholdForAgent(
268
- connection: Connection,
269
- wallet: string,
270
- ): Promise<Stronghold | null> {
271
- const vault = await getVaultForWallet(connection, wallet);
272
- return vault ? mapVaultToStronghold(vault) : null;
273
- }
274
-
275
- /** Get agent link info for a wallet */
276
- export async function getAgentLink(
277
- connection: Connection,
278
- wallet: string,
279
- ): Promise<AgentLink | null> {
280
- const link = await getVaultWalletLink(connection, wallet);
281
- return link ? mapWalletLinkToAgentLink(link) : null;
282
- }
283
-
284
- /** Get all linked agents for a vault (via getProgramAccounts) */
285
- export async function getLinkedAgents(
286
- connection: Connection,
287
- vaultAddress: string,
288
- ): Promise<AgentLink[]> {
289
- // VaultWalletLink account layout: 8-byte discriminator + 32-byte vault + 32-byte wallet + 8-byte linked_at + 1-byte bump
290
- const DISCRIMINATOR = Buffer.from([111, 59, 70, 89, 148, 117, 217, 156]); // sha256("account:VaultWalletLink")[0..8]
291
- const vaultPubkey = new PublicKey(vaultAddress);
292
-
293
- const filters: GetProgramAccountsFilter[] = [
294
- { dataSize: 81 }, // 8 + 32 + 32 + 8 + 1
295
- { memcmp: { offset: 8, bytes: vaultPubkey.toBase58() } },
296
- ];
297
-
298
- const accounts = await connection.getProgramAccounts(PROGRAM_ID, { filters });
299
-
300
- return accounts.map((acc) => {
301
- const data = acc.account.data;
302
- const wallet = new PublicKey(data.subarray(40, 72)).toBase58();
303
- const linked_at = Number(data.readBigInt64LE(72));
304
- return {
305
- address: acc.pubkey.toBase58(),
306
- stronghold: vaultAddress,
307
- wallet,
308
- linked_at,
309
- };
310
- });
311
- }
312
-
313
- /** Get war chest (lending info) for a faction */
314
- export async function getWarChest(
315
- connection: Connection,
316
- mint: string,
317
- ): Promise<WarChest> {
318
- const info = await getLendingInfo(connection, mint);
319
- return mapLendingToWarChest(info);
320
- }
321
-
322
- /** Get war loan position for a specific agent on a faction */
323
- export async function getWarLoan(
324
- connection: Connection,
325
- mint: string,
326
- wallet: string,
327
- ): Promise<WarLoan> {
328
- const pos = await getLoanPosition(connection, mint, wallet);
329
- return mapLoanToWarLoan(pos);
330
- }
331
-
332
- /** Get all war loans for a faction */
333
- export async function getAllWarLoans(
334
- connection: Connection,
335
- mint: string,
336
- ): Promise<AllWarLoansResult> {
337
- const result = await getAllLoanPositions(connection, mint);
338
- return mapAllLoansResult(result);
339
- }
340
-
341
- /** Compute max borrowable SOL for a given collateral amount */
342
- export async function getMaxWarLoan(
343
- connection: Connection,
344
- mint: string,
345
- collateralAmount: number,
346
- ): Promise<WarLoanQuote> {
347
- return getBorrowQuote(connection, mint, collateralAmount);
348
- }
349
-
350
- // ─── Faction Operations (controller) ───────────────────────────────
351
-
352
- /** Launch a new faction (create token) */
353
- export async function launchFaction(
354
- connection: Connection,
355
- params: LaunchFactionParams,
356
- ): Promise<LaunchFactionResult> {
357
- const result = await buildCreateFactionTransaction(connection, {
358
- creator: params.founder,
359
- name: params.name,
360
- symbol: params.symbol,
361
- metadata_uri: params.metadata_uri,
362
- sol_target: params.sol_target,
363
- community_token: params.community_faction,
364
- });
365
- return mapCreateResult(result);
366
- }
367
-
368
- /** Join a faction via stronghold (vault-funded buy) */
369
- export async function joinFaction(
370
- connection: Connection,
371
- params: JoinFactionParams,
372
- ): Promise<JoinFactionResult> {
373
- const result = await buildBuyTransaction(connection, {
374
- mint: params.mint,
375
- buyer: params.agent,
376
- amount_sol: params.amount_sol,
377
- slippage_bps: params.slippage_bps,
378
- vote: params.strategy ? mapVote(params.strategy) : undefined,
379
- message: params.message,
380
- vault: params.stronghold,
381
- });
382
- return mapBuyResult(result);
383
- }
384
-
385
- /** Join a faction directly (no vault) */
386
- export async function directJoinFaction(
387
- connection: Connection,
388
- params: DirectJoinFactionParams,
389
- ): Promise<JoinFactionResult> {
390
- const result = await buildDirectBuyTransaction(connection, {
391
- mint: params.mint,
392
- buyer: params.agent,
393
- amount_sol: params.amount_sol,
394
- slippage_bps: params.slippage_bps,
395
- vote: params.strategy ? mapVote(params.strategy) : undefined,
396
- message: params.message,
397
- });
398
- return mapBuyResult(result);
399
- }
400
-
401
- /** Defect from a faction (sell tokens) */
402
- export async function defect(
403
- connection: Connection,
404
- params: DefectParams,
405
- ): Promise<TransactionResult> {
406
- return buildSellTransaction(connection, {
407
- mint: params.mint,
408
- seller: params.agent,
409
- amount_tokens: params.amount_tokens,
410
- slippage_bps: params.slippage_bps,
411
- message: params.message,
412
- vault: params.stronghold,
413
- });
414
- }
415
-
416
- /** "Said in" — micro buy (0.001 SOL) + message. Routes through bonding curve or DEX automatically. */
417
- export async function messageFaction(
418
- connection: Connection,
419
- params: MessageFactionParams,
420
- ): Promise<TransactionResult> {
421
- const MICRO_BUY_LAMPORTS = 1_000_000; // 0.001 SOL
422
- if (params.ascended) {
423
- return buildVaultSwapTransaction(connection, {
424
- mint: params.mint,
425
- signer: params.agent,
426
- vault_creator: params.stronghold,
427
- amount_in: MICRO_BUY_LAMPORTS,
428
- minimum_amount_out: 1,
429
- is_buy: true,
430
- message: params.message,
431
- });
432
- }
433
- const result = await buildBuyTransaction(connection, {
434
- mint: params.mint,
435
- buyer: params.agent,
436
- amount_sol: MICRO_BUY_LAMPORTS,
437
- message: params.message,
438
- vault: params.stronghold,
439
- vote: params.first_buy ? mapVote(Math.random() > 0.5 ? 'fortify' : 'scorched_earth') : undefined,
440
- });
441
- return mapBuyResult(result);
442
- }
443
-
444
- /** "Argued in" — micro sell (100 tokens) + negative message. Routes through bonding curve or DEX automatically. */
445
- export async function fudFaction(
446
- connection: Connection,
447
- params: FudFactionParams,
448
- ): Promise<TransactionResult> {
449
- const MICRO_SELL_TOKENS = 100;
450
- if (params.ascended) {
451
- return buildVaultSwapTransaction(connection, {
452
- mint: params.mint,
453
- signer: params.agent,
454
- vault_creator: params.stronghold,
455
- amount_in: MICRO_SELL_TOKENS,
456
- minimum_amount_out: 1,
457
- is_buy: false,
458
- message: params.message,
459
- });
460
- }
461
- return buildSellTransaction(connection, {
462
- mint: params.mint,
463
- seller: params.agent,
464
- amount_tokens: MICRO_SELL_TOKENS,
465
- message: params.message,
466
- vault: params.stronghold,
467
- });
468
- }
469
-
470
- /** Rally support for a faction (star) */
471
- export async function rally(
472
- connection: Connection,
473
- params: RallyParams,
474
- ): Promise<TransactionResult> {
475
- return buildStarTransaction(connection, {
476
- mint: params.mint,
477
- user: params.agent,
478
- vault: params.stronghold,
479
- });
480
- }
481
-
482
- /** Request a war loan (borrow SOL against token collateral) */
483
- export async function requestWarLoan(
484
- connection: Connection,
485
- params: RequestWarLoanParams,
486
- ): Promise<TransactionResult> {
487
- return buildBorrowTransaction(connection, {
488
- mint: params.mint,
489
- borrower: params.borrower,
490
- collateral_amount: params.collateral_amount,
491
- sol_to_borrow: params.sol_to_borrow,
492
- vault: params.stronghold,
493
- });
494
- }
495
-
496
- /** Repay a war loan */
497
- export async function repayWarLoan(
498
- connection: Connection,
499
- params: RepayWarLoanParams,
500
- ): Promise<TransactionResult> {
501
- return buildRepayTransaction(connection, {
502
- mint: params.mint,
503
- borrower: params.borrower,
504
- sol_amount: params.sol_amount,
505
- vault: params.stronghold,
506
- });
507
- }
508
-
509
- /** Trade on DEX via stronghold (vault-routed Raydium swap) */
510
- export async function tradeOnDex(
511
- connection: Connection,
512
- params: TradeOnDexParams,
513
- ): Promise<TransactionResult> {
514
- return buildVaultSwapTransaction(connection, {
515
- mint: params.mint,
516
- signer: params.signer,
517
- vault_creator: params.stronghold_creator,
518
- amount_in: params.amount_in,
519
- minimum_amount_out: params.minimum_amount_out,
520
- is_buy: params.is_buy,
521
- message: params.message,
522
- });
523
- }
524
-
525
- /** Claim spoils (protocol rewards) */
526
- export async function claimSpoils(
527
- connection: Connection,
528
- params: ClaimSpoilsParams,
529
- ): Promise<TransactionResult> {
530
- return buildClaimProtocolRewardsTransaction(connection, {
531
- user: params.agent,
532
- vault: params.stronghold,
533
- });
534
- }
535
-
536
- // ─── Stronghold Operations (authority) ─────────────────────────────
537
-
538
- /** Create a new stronghold (vault) */
539
- export async function createStronghold(
540
- connection: Connection,
541
- params: CreateStrongholdParams,
542
- ): Promise<TransactionResult> {
543
- return buildCreateVaultTransaction(connection, {
544
- creator: params.creator,
545
- });
546
- }
547
-
548
- /** Fund a stronghold with SOL */
549
- export async function fundStronghold(
550
- connection: Connection,
551
- params: FundStrongholdParams,
552
- ): Promise<TransactionResult> {
553
- return buildDepositVaultTransaction(connection, {
554
- depositor: params.depositor,
555
- vault_creator: params.stronghold_creator,
556
- amount_sol: params.amount_sol,
557
- });
558
- }
559
-
560
- /** Withdraw SOL from a stronghold */
561
- export async function withdrawFromStronghold(
562
- connection: Connection,
563
- params: WithdrawFromStrongholdParams,
564
- ): Promise<TransactionResult> {
565
- return buildWithdrawVaultTransaction(connection, {
566
- authority: params.authority,
567
- vault_creator: params.stronghold_creator,
568
- amount_sol: params.amount_sol,
569
- });
570
- }
571
-
572
- /** Recruit an agent (link wallet to stronghold) */
573
- export async function recruitAgent(
574
- connection: Connection,
575
- params: RecruitAgentParams,
576
- ): Promise<TransactionResult> {
577
- return buildLinkWalletTransaction(connection, {
578
- authority: params.authority,
579
- vault_creator: params.stronghold_creator,
580
- wallet_to_link: params.wallet_to_link,
581
- });
582
- }
583
-
584
- /** Exile an agent (unlink wallet from stronghold) */
585
- export async function exileAgent(
586
- connection: Connection,
587
- params: ExileAgentParams,
588
- ): Promise<TransactionResult> {
589
- return buildUnlinkWalletTransaction(connection, {
590
- authority: params.authority,
591
- vault_creator: params.stronghold_creator,
592
- wallet_to_unlink: params.wallet_to_unlink,
593
- });
594
- }
595
-
596
- /** Coup — transfer stronghold authority */
597
- export async function coup(
598
- connection: Connection,
599
- params: CoupParams,
600
- ): Promise<TransactionResult> {
601
- return buildTransferAuthorityTransaction(connection, {
602
- authority: params.authority,
603
- vault_creator: params.stronghold_creator,
604
- new_authority: params.new_authority,
605
- });
606
- }
607
-
608
- /** Withdraw token assets from stronghold */
609
- export async function withdrawAssets(
610
- connection: Connection,
611
- params: WithdrawAssetsParams,
612
- ): Promise<TransactionResult> {
613
- return buildWithdrawTokensTransaction(connection, {
614
- authority: params.authority,
615
- vault_creator: params.stronghold_creator,
616
- mint: params.mint,
617
- destination: params.destination,
618
- amount: params.amount,
619
- });
620
- }
621
-
622
- // ─── Permissionless Operations ─────────────────────────────────────
623
-
624
- /** Siege — liquidate an undercollateralized war loan */
625
- export async function siege(
626
- connection: Connection,
627
- params: SiegeParams,
628
- ): Promise<TransactionResult> {
629
- return buildLiquidateTransaction(connection, {
630
- mint: params.mint,
631
- liquidator: params.liquidator,
632
- borrower: params.borrower,
633
- vault: params.stronghold,
634
- });
635
- }
636
-
637
- /** Ascend — migrate a completed faction to DEX */
638
- export async function ascend(
639
- connection: Connection,
640
- params: AscendParams,
641
- ): Promise<TransactionResult> {
642
- return buildMigrateTransaction(connection, {
643
- mint: params.mint,
644
- payer: params.payer,
645
- });
646
- }
647
-
648
- /** Raze — reclaim a failed faction */
649
- export async function raze(
650
- connection: Connection,
651
- params: RazeParams,
652
- ): Promise<TransactionResult> {
653
- return buildReclaimFailedTokenTransaction(connection, {
654
- payer: params.payer,
655
- mint: params.mint,
656
- });
657
- }
658
-
659
- /** Tithe — harvest transfer fees */
660
- export async function tithe(
661
- connection: Connection,
662
- params: TitheParams,
663
- ): Promise<TransactionResult> {
664
- return buildHarvestFeesTransaction(connection, {
665
- mint: params.mint,
666
- payer: params.payer,
667
- sources: params.sources,
668
- });
669
- }
670
-
671
- /** Convert tithe — swap harvested fees to SOL */
672
- export async function convertTithe(
673
- connection: Connection,
674
- params: ConvertTitheParams,
675
- ): Promise<TransactionResult> {
676
- return buildSwapFeesToSolTransaction(connection, {
677
- mint: params.mint,
678
- payer: params.payer,
679
- minimum_amount_out: params.minimum_amount_out,
680
- harvest: params.harvest,
681
- sources: params.sources,
682
- });
683
- }
684
-
685
- // ─── SAID Operations ───────────────────────────────────────────────
686
-
687
- /** Verify an agent's SAID reputation */
688
- export async function verifyAgent(wallet: string): Promise<SaidVerification> {
689
- return verifySaid(wallet);
690
- }
691
-
692
- /** Confirm a transaction on-chain */
693
- export async function confirmAction(
694
- connection: Connection,
695
- signature: string,
696
- wallet: string,
697
- ): Promise<ConfirmResult> {
698
- return confirmTransaction(connection, signature, wallet);
699
- }
700
-
701
- // ─── Utility ───────────────────────────────────────────────────────
702
-
703
- /** Create an ephemeral agent keypair (memory-only, zero key management) */
704
- export { createEphemeralAgent } from 'torchsdk';
705
-
706
- /** Get the Raydium pool state PDA for an ascended faction's DEX pool */
707
- export function getDexPool(mint: string): PublicKey {
708
- const { poolState } = getRaydiumMigrationAccounts(new PublicKey(mint));
709
- return poolState;
710
- }
711
-
712
- /** Get Raydium pool vault addresses for an ascended faction */
713
- export function getDexVaults(mint: string): { solVault: string; tokenVault: string } {
714
- const accts = getRaydiumMigrationAccounts(new PublicKey(mint));
715
- return {
716
- solVault: (accts.isWsolToken0 ? accts.token0Vault : accts.token1Vault).toString(),
717
- tokenVault: (accts.isWsolToken0 ? accts.token1Vault : accts.token0Vault).toString(),
718
- };
719
- }