pyre-world-kit 1.0.0

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/src/actions.ts ADDED
@@ -0,0 +1,523 @@
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 } from '@solana/web3.js';
9
+ import {
10
+ // Read operations
11
+ getTokens,
12
+ getToken,
13
+ getHolders,
14
+ getMessages,
15
+ getBuyQuote,
16
+ getSellQuote,
17
+ getVault,
18
+ getVaultForWallet,
19
+ getVaultWalletLink,
20
+ getLendingInfo,
21
+ getLoanPosition,
22
+ getAllLoanPositions,
23
+ // Transaction builders
24
+ buildBuyTransaction,
25
+ buildDirectBuyTransaction,
26
+ buildSellTransaction,
27
+ buildStarTransaction,
28
+ buildBorrowTransaction,
29
+ buildRepayTransaction,
30
+ buildLiquidateTransaction,
31
+ buildVaultSwapTransaction,
32
+ buildClaimProtocolRewardsTransaction,
33
+ buildCreateVaultTransaction,
34
+ buildDepositVaultTransaction,
35
+ buildWithdrawVaultTransaction,
36
+ buildLinkWalletTransaction,
37
+ buildUnlinkWalletTransaction,
38
+ buildTransferAuthorityTransaction,
39
+ buildWithdrawTokensTransaction,
40
+ buildMigrateTransaction,
41
+ buildReclaimFailedTokenTransaction,
42
+ buildHarvestFeesTransaction,
43
+ buildSwapFeesToSolTransaction,
44
+ // Utilities
45
+ verifySaid,
46
+ confirmTransaction,
47
+ } from 'torchsdk';
48
+
49
+ import type { BuyQuoteResult, SellQuoteResult, TransactionResult, SaidVerification, ConfirmResult } from 'torchsdk';
50
+
51
+ import type {
52
+ FactionListParams,
53
+ FactionListResult,
54
+ FactionDetail,
55
+ MembersResult,
56
+ CommsResult,
57
+ Stronghold,
58
+ AgentLink,
59
+ WarChest,
60
+ WarLoan,
61
+ AllWarLoansResult,
62
+ LaunchFactionParams,
63
+ JoinFactionParams,
64
+ DirectJoinFactionParams,
65
+ DefectParams,
66
+ RallyParams,
67
+ RequestWarLoanParams,
68
+ RepayWarLoanParams,
69
+ SiegeParams,
70
+ TradeOnDexParams,
71
+ ClaimSpoilsParams,
72
+ CreateStrongholdParams,
73
+ FundStrongholdParams,
74
+ WithdrawFromStrongholdParams,
75
+ RecruitAgentParams,
76
+ ExileAgentParams,
77
+ CoupParams,
78
+ WithdrawAssetsParams,
79
+ AscendParams,
80
+ RazeParams,
81
+ TitheParams,
82
+ ConvertTitheParams,
83
+ JoinFactionResult,
84
+ LaunchFactionResult,
85
+ } from './types';
86
+
87
+ import {
88
+ mapTokenListResult,
89
+ mapTokenDetailToFaction,
90
+ mapHoldersResult,
91
+ mapMessagesResult,
92
+ mapVaultToStronghold,
93
+ mapWalletLinkToAgentLink,
94
+ mapLendingToWarChest,
95
+ mapLoanToWarLoan,
96
+ mapAllLoansResult,
97
+ mapBuyResult,
98
+ mapCreateResult,
99
+ mapVote,
100
+ mapTokenStatusFilter,
101
+ } from './mappers';
102
+
103
+ import { buildCreateFactionTransaction, isPyreMint } from './vanity';
104
+
105
+ // ─── Read Operations ───────────────────────────────────────────────
106
+
107
+ /** List all factions with optional filtering and sorting */
108
+ export async function getFactions(
109
+ connection: Connection,
110
+ params?: FactionListParams,
111
+ ): Promise<FactionListResult> {
112
+ const sdkParams = params ? {
113
+ limit: params.limit,
114
+ offset: params.offset,
115
+ status: params.status ? mapTokenStatusFilter(params.status) : undefined,
116
+ sort: params.sort,
117
+ } : undefined;
118
+ const result = await getTokens(connection, sdkParams);
119
+ return mapTokenListResult(result);
120
+ }
121
+
122
+ /** Get detailed info for a single faction */
123
+ export async function getFaction(
124
+ connection: Connection,
125
+ mint: string,
126
+ ): Promise<FactionDetail> {
127
+ const detail = await getToken(connection, mint);
128
+ return mapTokenDetailToFaction(detail);
129
+ }
130
+
131
+ /** Get faction members (top holders) */
132
+ export async function getMembers(
133
+ connection: Connection,
134
+ mint: string,
135
+ limit?: number,
136
+ ): Promise<MembersResult> {
137
+ const result = await getHolders(connection, mint, limit);
138
+ return mapHoldersResult(result);
139
+ }
140
+
141
+ /** Get faction comms (trade-bundled messages) */
142
+ export async function getComms(
143
+ connection: Connection,
144
+ mint: string,
145
+ limit?: number,
146
+ ): Promise<CommsResult> {
147
+ const result = await getMessages(connection, mint, limit);
148
+ return mapMessagesResult(result);
149
+ }
150
+
151
+ /** Get a quote for joining a faction (buying tokens) */
152
+ export async function getJoinQuote(
153
+ connection: Connection,
154
+ mint: string,
155
+ amountSolLamports: number,
156
+ ): Promise<BuyQuoteResult> {
157
+ return getBuyQuote(connection, mint, amountSolLamports);
158
+ }
159
+
160
+ /** Get a quote for defecting from a faction (selling tokens) */
161
+ export async function getDefectQuote(
162
+ connection: Connection,
163
+ mint: string,
164
+ amountTokens: number,
165
+ ): Promise<SellQuoteResult> {
166
+ return getSellQuote(connection, mint, amountTokens);
167
+ }
168
+
169
+ /** Get stronghold (vault) by creator */
170
+ export async function getStronghold(
171
+ connection: Connection,
172
+ creator: string,
173
+ ): Promise<Stronghold | null> {
174
+ const vault = await getVault(connection, creator);
175
+ return vault ? mapVaultToStronghold(vault) : null;
176
+ }
177
+
178
+ /** Get stronghold for a linked agent wallet */
179
+ export async function getStrongholdForAgent(
180
+ connection: Connection,
181
+ wallet: string,
182
+ ): Promise<Stronghold | null> {
183
+ const vault = await getVaultForWallet(connection, wallet);
184
+ return vault ? mapVaultToStronghold(vault) : null;
185
+ }
186
+
187
+ /** Get agent link info for a wallet */
188
+ export async function getAgentLink(
189
+ connection: Connection,
190
+ wallet: string,
191
+ ): Promise<AgentLink | null> {
192
+ const link = await getVaultWalletLink(connection, wallet);
193
+ return link ? mapWalletLinkToAgentLink(link) : null;
194
+ }
195
+
196
+ /** Get war chest (lending info) for a faction */
197
+ export async function getWarChest(
198
+ connection: Connection,
199
+ mint: string,
200
+ ): Promise<WarChest> {
201
+ const info = await getLendingInfo(connection, mint);
202
+ return mapLendingToWarChest(info);
203
+ }
204
+
205
+ /** Get war loan position for a specific agent on a faction */
206
+ export async function getWarLoan(
207
+ connection: Connection,
208
+ mint: string,
209
+ wallet: string,
210
+ ): Promise<WarLoan> {
211
+ const pos = await getLoanPosition(connection, mint, wallet);
212
+ return mapLoanToWarLoan(pos);
213
+ }
214
+
215
+ /** Get all war loans for a faction */
216
+ export async function getAllWarLoans(
217
+ connection: Connection,
218
+ mint: string,
219
+ ): Promise<AllWarLoansResult> {
220
+ const result = await getAllLoanPositions(connection, mint);
221
+ return mapAllLoansResult(result);
222
+ }
223
+
224
+ // ─── Faction Operations (controller) ───────────────────────────────
225
+
226
+ /** Launch a new faction (create token) */
227
+ export async function launchFaction(
228
+ connection: Connection,
229
+ params: LaunchFactionParams,
230
+ ): Promise<LaunchFactionResult> {
231
+ const result = await buildCreateFactionTransaction(connection, {
232
+ creator: params.founder,
233
+ name: params.name,
234
+ symbol: params.symbol,
235
+ metadata_uri: params.metadata_uri,
236
+ sol_target: params.sol_target,
237
+ community_token: params.community_faction,
238
+ });
239
+ return mapCreateResult(result);
240
+ }
241
+
242
+ /** Join a faction via stronghold (vault-funded buy) */
243
+ export async function joinFaction(
244
+ connection: Connection,
245
+ params: JoinFactionParams,
246
+ ): Promise<JoinFactionResult> {
247
+ const result = await buildBuyTransaction(connection, {
248
+ mint: params.mint,
249
+ buyer: params.agent,
250
+ amount_sol: params.amount_sol,
251
+ slippage_bps: params.slippage_bps,
252
+ vote: params.strategy ? mapVote(params.strategy) : undefined,
253
+ message: params.message,
254
+ vault: params.stronghold,
255
+ });
256
+ return mapBuyResult(result);
257
+ }
258
+
259
+ /** Join a faction directly (no vault) */
260
+ export async function directJoinFaction(
261
+ connection: Connection,
262
+ params: DirectJoinFactionParams,
263
+ ): Promise<JoinFactionResult> {
264
+ const result = await buildDirectBuyTransaction(connection, {
265
+ mint: params.mint,
266
+ buyer: params.agent,
267
+ amount_sol: params.amount_sol,
268
+ slippage_bps: params.slippage_bps,
269
+ vote: params.strategy ? mapVote(params.strategy) : undefined,
270
+ message: params.message,
271
+ });
272
+ return mapBuyResult(result);
273
+ }
274
+
275
+ /** Defect from a faction (sell tokens) */
276
+ export async function defect(
277
+ connection: Connection,
278
+ params: DefectParams,
279
+ ): Promise<TransactionResult> {
280
+ return buildSellTransaction(connection, {
281
+ mint: params.mint,
282
+ seller: params.agent,
283
+ amount_tokens: params.amount_tokens,
284
+ slippage_bps: params.slippage_bps,
285
+ message: params.message,
286
+ vault: params.stronghold,
287
+ });
288
+ }
289
+
290
+ /** Rally support for a faction (star) */
291
+ export async function rally(
292
+ connection: Connection,
293
+ params: RallyParams,
294
+ ): Promise<TransactionResult> {
295
+ return buildStarTransaction(connection, {
296
+ mint: params.mint,
297
+ user: params.agent,
298
+ vault: params.stronghold,
299
+ });
300
+ }
301
+
302
+ /** Request a war loan (borrow SOL against token collateral) */
303
+ export async function requestWarLoan(
304
+ connection: Connection,
305
+ params: RequestWarLoanParams,
306
+ ): Promise<TransactionResult> {
307
+ return buildBorrowTransaction(connection, {
308
+ mint: params.mint,
309
+ borrower: params.borrower,
310
+ collateral_amount: params.collateral_amount,
311
+ sol_to_borrow: params.sol_to_borrow,
312
+ vault: params.stronghold,
313
+ });
314
+ }
315
+
316
+ /** Repay a war loan */
317
+ export async function repayWarLoan(
318
+ connection: Connection,
319
+ params: RepayWarLoanParams,
320
+ ): Promise<TransactionResult> {
321
+ return buildRepayTransaction(connection, {
322
+ mint: params.mint,
323
+ borrower: params.borrower,
324
+ sol_amount: params.sol_amount,
325
+ vault: params.stronghold,
326
+ });
327
+ }
328
+
329
+ /** Trade on DEX via stronghold (vault-routed Raydium swap) */
330
+ export async function tradeOnDex(
331
+ connection: Connection,
332
+ params: TradeOnDexParams,
333
+ ): Promise<TransactionResult> {
334
+ return buildVaultSwapTransaction(connection, {
335
+ mint: params.mint,
336
+ signer: params.signer,
337
+ vault_creator: params.stronghold_creator,
338
+ amount_in: params.amount_in,
339
+ minimum_amount_out: params.minimum_amount_out,
340
+ is_buy: params.is_buy,
341
+ });
342
+ }
343
+
344
+ /** Claim spoils (protocol rewards) */
345
+ export async function claimSpoils(
346
+ connection: Connection,
347
+ params: ClaimSpoilsParams,
348
+ ): Promise<TransactionResult> {
349
+ return buildClaimProtocolRewardsTransaction(connection, {
350
+ user: params.agent,
351
+ vault: params.stronghold,
352
+ });
353
+ }
354
+
355
+ // ─── Stronghold Operations (authority) ─────────────────────────────
356
+
357
+ /** Create a new stronghold (vault) */
358
+ export async function createStronghold(
359
+ connection: Connection,
360
+ params: CreateStrongholdParams,
361
+ ): Promise<TransactionResult> {
362
+ return buildCreateVaultTransaction(connection, {
363
+ creator: params.creator,
364
+ });
365
+ }
366
+
367
+ /** Fund a stronghold with SOL */
368
+ export async function fundStronghold(
369
+ connection: Connection,
370
+ params: FundStrongholdParams,
371
+ ): Promise<TransactionResult> {
372
+ return buildDepositVaultTransaction(connection, {
373
+ depositor: params.depositor,
374
+ vault_creator: params.stronghold_creator,
375
+ amount_sol: params.amount_sol,
376
+ });
377
+ }
378
+
379
+ /** Withdraw SOL from a stronghold */
380
+ export async function withdrawFromStronghold(
381
+ connection: Connection,
382
+ params: WithdrawFromStrongholdParams,
383
+ ): Promise<TransactionResult> {
384
+ return buildWithdrawVaultTransaction(connection, {
385
+ authority: params.authority,
386
+ vault_creator: params.stronghold_creator,
387
+ amount_sol: params.amount_sol,
388
+ });
389
+ }
390
+
391
+ /** Recruit an agent (link wallet to stronghold) */
392
+ export async function recruitAgent(
393
+ connection: Connection,
394
+ params: RecruitAgentParams,
395
+ ): Promise<TransactionResult> {
396
+ return buildLinkWalletTransaction(connection, {
397
+ authority: params.authority,
398
+ vault_creator: params.stronghold_creator,
399
+ wallet_to_link: params.wallet_to_link,
400
+ });
401
+ }
402
+
403
+ /** Exile an agent (unlink wallet from stronghold) */
404
+ export async function exileAgent(
405
+ connection: Connection,
406
+ params: ExileAgentParams,
407
+ ): Promise<TransactionResult> {
408
+ return buildUnlinkWalletTransaction(connection, {
409
+ authority: params.authority,
410
+ vault_creator: params.stronghold_creator,
411
+ wallet_to_unlink: params.wallet_to_unlink,
412
+ });
413
+ }
414
+
415
+ /** Coup — transfer stronghold authority */
416
+ export async function coup(
417
+ connection: Connection,
418
+ params: CoupParams,
419
+ ): Promise<TransactionResult> {
420
+ return buildTransferAuthorityTransaction(connection, {
421
+ authority: params.authority,
422
+ vault_creator: params.stronghold_creator,
423
+ new_authority: params.new_authority,
424
+ });
425
+ }
426
+
427
+ /** Withdraw token assets from stronghold */
428
+ export async function withdrawAssets(
429
+ connection: Connection,
430
+ params: WithdrawAssetsParams,
431
+ ): Promise<TransactionResult> {
432
+ return buildWithdrawTokensTransaction(connection, {
433
+ authority: params.authority,
434
+ vault_creator: params.stronghold_creator,
435
+ mint: params.mint,
436
+ destination: params.destination,
437
+ amount: params.amount,
438
+ });
439
+ }
440
+
441
+ // ─── Permissionless Operations ─────────────────────────────────────
442
+
443
+ /** Siege — liquidate an undercollateralized war loan */
444
+ export async function siege(
445
+ connection: Connection,
446
+ params: SiegeParams,
447
+ ): Promise<TransactionResult> {
448
+ return buildLiquidateTransaction(connection, {
449
+ mint: params.mint,
450
+ liquidator: params.liquidator,
451
+ borrower: params.borrower,
452
+ vault: params.stronghold,
453
+ });
454
+ }
455
+
456
+ /** Ascend — migrate a completed faction to DEX */
457
+ export async function ascend(
458
+ connection: Connection,
459
+ params: AscendParams,
460
+ ): Promise<TransactionResult> {
461
+ return buildMigrateTransaction(connection, {
462
+ mint: params.mint,
463
+ payer: params.payer,
464
+ });
465
+ }
466
+
467
+ /** Raze — reclaim a failed faction */
468
+ export async function raze(
469
+ connection: Connection,
470
+ params: RazeParams,
471
+ ): Promise<TransactionResult> {
472
+ return buildReclaimFailedTokenTransaction(connection, {
473
+ payer: params.payer,
474
+ mint: params.mint,
475
+ });
476
+ }
477
+
478
+ /** Tithe — harvest transfer fees */
479
+ export async function tithe(
480
+ connection: Connection,
481
+ params: TitheParams,
482
+ ): Promise<TransactionResult> {
483
+ return buildHarvestFeesTransaction(connection, {
484
+ mint: params.mint,
485
+ payer: params.payer,
486
+ sources: params.sources,
487
+ });
488
+ }
489
+
490
+ /** Convert tithe — swap harvested fees to SOL */
491
+ export async function convertTithe(
492
+ connection: Connection,
493
+ params: ConvertTitheParams,
494
+ ): Promise<TransactionResult> {
495
+ return buildSwapFeesToSolTransaction(connection, {
496
+ mint: params.mint,
497
+ payer: params.payer,
498
+ minimum_amount_out: params.minimum_amount_out,
499
+ harvest: params.harvest,
500
+ sources: params.sources,
501
+ });
502
+ }
503
+
504
+ // ─── SAID Operations ───────────────────────────────────────────────
505
+
506
+ /** Verify an agent's SAID reputation */
507
+ export async function verifyAgent(wallet: string): Promise<SaidVerification> {
508
+ return verifySaid(wallet);
509
+ }
510
+
511
+ /** Confirm a transaction on-chain */
512
+ export async function confirmAction(
513
+ connection: Connection,
514
+ signature: string,
515
+ wallet: string,
516
+ ): Promise<ConfirmResult> {
517
+ return confirmTransaction(connection, signature, wallet);
518
+ }
519
+
520
+ // ─── Utility ───────────────────────────────────────────────────────
521
+
522
+ /** Create an ephemeral agent keypair (memory-only, zero key management) */
523
+ export { createEphemeralAgent } from 'torchsdk';
package/src/index.ts ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Pyre Kit — Agent-first faction warfare on Torch Market
3
+ *
4
+ * Game-semantic wrapper over torchsdk. Torch Market IS the game engine.
5
+ * This kit translates protocol primitives into faction warfare language
6
+ * so agents think in factions, not tokens.
7
+ */
8
+
9
+ // ─── Types ─────────────────────────────────────────────────────────
10
+
11
+ export type {
12
+ // Status & enums
13
+ FactionStatus,
14
+ FactionTier,
15
+ Strategy,
16
+ AgentHealth,
17
+ // Core game types
18
+ FactionSummary,
19
+ FactionDetail,
20
+ Stronghold,
21
+ AgentLink,
22
+ Comms,
23
+ WarChest,
24
+ WarLoan,
25
+ WarLoanWithAgent,
26
+ Member,
27
+ // List results
28
+ FactionListResult,
29
+ MembersResult,
30
+ CommsResult,
31
+ AllWarLoansResult,
32
+ // Params
33
+ LaunchFactionParams,
34
+ JoinFactionParams,
35
+ DirectJoinFactionParams,
36
+ DefectParams,
37
+ RallyParams,
38
+ RequestWarLoanParams,
39
+ RepayWarLoanParams,
40
+ SiegeParams,
41
+ TradeOnDexParams,
42
+ ClaimSpoilsParams,
43
+ CreateStrongholdParams,
44
+ FundStrongholdParams,
45
+ WithdrawFromStrongholdParams,
46
+ RecruitAgentParams,
47
+ ExileAgentParams,
48
+ CoupParams,
49
+ WithdrawAssetsParams,
50
+ AscendParams,
51
+ RazeParams,
52
+ TitheParams,
53
+ ConvertTitheParams,
54
+ // Results
55
+ JoinFactionResult,
56
+ LaunchFactionResult,
57
+ TransactionResult,
58
+ EphemeralAgent,
59
+ SaidVerification,
60
+ ConfirmResult,
61
+ // List/filter params
62
+ FactionSortOption,
63
+ FactionStatusFilter,
64
+ FactionListParams,
65
+ // Intel types
66
+ FactionPower,
67
+ AllianceCluster,
68
+ RivalFaction,
69
+ AgentProfile,
70
+ AgentFactionPosition,
71
+ WorldEvent,
72
+ WorldStats,
73
+ } from './types';
74
+
75
+ // ─── Actions ───────────────────────────────────────────────────────
76
+
77
+ export {
78
+ // Read operations
79
+ getFactions,
80
+ getFaction,
81
+ getMembers,
82
+ getComms,
83
+ getJoinQuote,
84
+ getDefectQuote,
85
+ getStronghold,
86
+ getStrongholdForAgent,
87
+ getAgentLink,
88
+ getWarChest,
89
+ getWarLoan,
90
+ getAllWarLoans,
91
+ // Faction operations
92
+ launchFaction,
93
+ joinFaction,
94
+ directJoinFaction,
95
+ defect,
96
+ rally,
97
+ requestWarLoan,
98
+ repayWarLoan,
99
+ tradeOnDex,
100
+ claimSpoils,
101
+ // Stronghold operations
102
+ createStronghold,
103
+ fundStronghold,
104
+ withdrawFromStronghold,
105
+ recruitAgent,
106
+ exileAgent,
107
+ coup,
108
+ withdrawAssets,
109
+ // Permissionless operations
110
+ siege,
111
+ ascend,
112
+ raze,
113
+ tithe,
114
+ convertTithe,
115
+ // SAID operations
116
+ verifyAgent,
117
+ confirmAction,
118
+ // Utility
119
+ createEphemeralAgent,
120
+ } from './actions';
121
+
122
+ // ─── Intel ─────────────────────────────────────────────────────────
123
+
124
+ export {
125
+ getFactionPower,
126
+ getFactionLeaderboard,
127
+ detectAlliances,
128
+ getFactionRivals,
129
+ getAgentProfile,
130
+ getAgentFactions,
131
+ getWorldFeed,
132
+ getWorldStats,
133
+ } from './intel';
134
+
135
+ // ─── Vanity ─────────────────────────────────────────────────────────
136
+
137
+ export { isPyreMint, grindPyreMint } from './vanity';
138
+
139
+ // ─── Re-export torchsdk constants for convenience ──────────────────
140
+
141
+ export { PROGRAM_ID, LAMPORTS_PER_SOL, TOKEN_MULTIPLIER, TOTAL_SUPPLY } from 'torchsdk';