pyre-world-kit 2.0.12 → 3.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.
Files changed (53) hide show
  1. package/.prettierrc.json +6 -0
  2. package/dist/index.d.ts +38 -4
  3. package/dist/index.js +100 -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 +134 -122
  32. package/src/index.ts +127 -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
@@ -0,0 +1,331 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionProvider = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const torchsdk_1 = require("torchsdk");
6
+ const mapper_provider_1 = require("./mapper.provider");
7
+ const vanity_1 = require("../vanity");
8
+ const util_1 = require("../util");
9
+ class ActionProvider {
10
+ connection;
11
+ mapper = new mapper_provider_1.MapperProvider();
12
+ constructor(connection) {
13
+ this.connection = connection;
14
+ }
15
+ async createStronghold(params) {
16
+ return (0, torchsdk_1.buildCreateVaultTransaction)(this.connection, { creator: params.creator });
17
+ }
18
+ async coup(params) {
19
+ return (0, torchsdk_1.buildTransferAuthorityTransaction)(this.connection, {
20
+ authority: params.authority,
21
+ vault_creator: params.stronghold_creator,
22
+ new_authority: params.new_authority,
23
+ });
24
+ }
25
+ async exileAgent(params) {
26
+ return (0, torchsdk_1.buildUnlinkWalletTransaction)(this.connection, {
27
+ authority: params.authority,
28
+ vault_creator: params.stronghold_creator,
29
+ wallet_to_unlink: params.wallet_to_unlink,
30
+ });
31
+ }
32
+ async fundStronghold(params) {
33
+ return (0, torchsdk_1.buildDepositVaultTransaction)(this.connection, {
34
+ depositor: params.depositor,
35
+ vault_creator: params.stronghold_creator,
36
+ amount_sol: params.amount_sol,
37
+ });
38
+ }
39
+ async recruitAgent(params) {
40
+ return (0, torchsdk_1.buildLinkWalletTransaction)(this.connection, {
41
+ authority: params.authority,
42
+ vault_creator: params.stronghold_creator,
43
+ wallet_to_link: params.wallet_to_link,
44
+ });
45
+ }
46
+ async withdrawAssets(params) {
47
+ return (0, torchsdk_1.buildWithdrawTokensTransaction)(this.connection, {
48
+ authority: params.authority,
49
+ vault_creator: params.stronghold_creator,
50
+ mint: params.mint,
51
+ destination: params.destination,
52
+ amount: params.amount,
53
+ });
54
+ }
55
+ async withdrawFromStronghold(params) {
56
+ return (0, torchsdk_1.buildWithdrawVaultTransaction)(this.connection, {
57
+ authority: params.authority,
58
+ vault_creator: params.stronghold_creator,
59
+ amount_sol: params.amount_sol,
60
+ });
61
+ }
62
+ async getAgentLink(wallet) {
63
+ const link = await (0, torchsdk_1.getVaultWalletLink)(this.connection, wallet);
64
+ return link ? this.mapper.walletLinkToAgentLink(link) : undefined;
65
+ }
66
+ async getComms(mint, { limit, status }) {
67
+ const source = status === 'ascended' ? 'pool' : status ? 'bonding' : 'all';
68
+ const result = await (0, torchsdk_1.getMessages)(this.connection, mint, limit, { source });
69
+ return this.mapper.messagesResult(result);
70
+ }
71
+ async getDefectQuote(mint, amountTokens) {
72
+ return (0, torchsdk_1.getSellQuote)(this.connection, mint, amountTokens);
73
+ }
74
+ async getJoinQuote(mint, amountSolLamports) {
75
+ return (0, torchsdk_1.getBuyQuote)(this.connection, mint, amountSolLamports);
76
+ }
77
+ async getFaction(mint) {
78
+ const detail = await (0, torchsdk_1.getToken)(this.connection, mint);
79
+ return this.mapper.tokenDetailToFaction(detail);
80
+ }
81
+ async getFactions(params) {
82
+ const sdkParams = params
83
+ ? {
84
+ limit: params.limit,
85
+ offset: params.offset,
86
+ status: params.status ? this.mapper.tokenStatusFilter(params.status) : undefined,
87
+ sort: params.sort,
88
+ }
89
+ : undefined;
90
+ const result = await (0, torchsdk_1.getTokens)(this.connection, sdkParams);
91
+ const tokens = result.tokens.filter((t) => (0, vanity_1.isPyreMint)(t.mint));
92
+ return this.mapper.tokenListResult({
93
+ tokens: result.tokens.filter((t) => (0, vanity_1.isPyreMint)(t.mint) && !(0, util_1.isBlacklistedMint)(t.mint)),
94
+ limit: result.limit,
95
+ offset: result.offset,
96
+ total: tokens.length,
97
+ });
98
+ }
99
+ async getLinkedAgents(vaultAddress) {
100
+ const vaultPubkey = new web3_js_1.PublicKey(vaultAddress);
101
+ const filters = [
102
+ { dataSize: 81 }, // 8 + 32 + 32 + 8 + 1
103
+ { memcmp: { offset: 8, bytes: vaultPubkey.toBase58() } },
104
+ ];
105
+ const accounts = await this.connection.getProgramAccounts(torchsdk_1.PROGRAM_ID, { filters });
106
+ return accounts.map((acc) => {
107
+ const data = acc.account.data;
108
+ const wallet = new web3_js_1.PublicKey(data.subarray(40, 72)).toBase58();
109
+ const linked_at = Number(data.readBigInt64LE(72));
110
+ return {
111
+ address: acc.pubkey.toBase58(),
112
+ stronghold: vaultAddress,
113
+ wallet,
114
+ linked_at,
115
+ };
116
+ });
117
+ }
118
+ async getMembers(mint, limit) {
119
+ const mintPk = new web3_js_1.PublicKey(mint);
120
+ const [bondingCurve] = (0, vanity_1.getBondingCurvePda)(mintPk);
121
+ const [treasury] = (0, vanity_1.getTokenTreasuryPda)(mintPk);
122
+ const [treasuryLock] = (0, vanity_1.getTreasuryLockPda)(mintPk);
123
+ const excluded = new Set([
124
+ bondingCurve.toString(),
125
+ treasury.toString(),
126
+ treasuryLock.toString(),
127
+ ]);
128
+ // Fetch extra to compensate for filtered-out program accounts
129
+ const result = await (0, torchsdk_1.getHolders)(this.connection, mint, (limit ?? 10) + 5);
130
+ result.holders = result.holders.filter((h) => !excluded.has(h.address));
131
+ if (limit)
132
+ result.holders = result.holders.slice(0, limit);
133
+ return this.mapper.holdersResult(result);
134
+ }
135
+ async getStronghold(creator) {
136
+ const vault = await (0, torchsdk_1.getVault)(this.connection, creator);
137
+ return vault ? this.mapper.vaultToStronghold(vault) : undefined;
138
+ }
139
+ async getStrongholdForAgent(wallet) {
140
+ const vault = await (0, torchsdk_1.getVaultForWallet)(this.connection, wallet);
141
+ return vault ? this.mapper.vaultToStronghold(vault) : undefined;
142
+ }
143
+ async getWarChest(mint) {
144
+ const info = await (0, torchsdk_1.getLendingInfo)(this.connection, mint);
145
+ return this.mapper.lendingToWarChest(info);
146
+ }
147
+ async getWarLoan(mint, wallet) {
148
+ const pos = await (0, torchsdk_1.getLoanPosition)(this.connection, mint, wallet);
149
+ return this.mapper.loanToWarLoan(pos);
150
+ }
151
+ async getWarLoanQuote(mint, collateralAmount) {
152
+ return (0, torchsdk_1.getBorrowQuote)(this.connection, mint, collateralAmount);
153
+ }
154
+ async getWarLoansForFaction(mint) {
155
+ const result = await (0, torchsdk_1.getAllLoanPositions)(this.connection, mint);
156
+ return this.mapper.allLoansResult(result);
157
+ }
158
+ async ascend(params) {
159
+ return (0, torchsdk_1.buildMigrateTransaction)(this.connection, {
160
+ mint: params.mint,
161
+ payer: params.payer,
162
+ });
163
+ }
164
+ async claimSpoils(params) {
165
+ return (0, torchsdk_1.buildClaimProtocolRewardsTransaction)(this.connection, {
166
+ user: params.agent,
167
+ vault: params.stronghold,
168
+ });
169
+ }
170
+ async defect(params) {
171
+ if (params.ascended) {
172
+ const slippage = params.slippage_bps ?? 500;
173
+ const quote = await (0, torchsdk_1.getSellQuote)(this.connection, params.mint, params.amount_tokens);
174
+ const minOut = Math.max(1, Math.floor(quote.output_sol * (1 - slippage / 10_000)));
175
+ return (0, torchsdk_1.buildVaultSwapTransaction)(this.connection, {
176
+ mint: params.mint,
177
+ signer: params.agent,
178
+ vault_creator: params.stronghold,
179
+ amount_in: params.amount_tokens,
180
+ minimum_amount_out: minOut,
181
+ is_buy: false,
182
+ message: params.message,
183
+ });
184
+ }
185
+ return (0, torchsdk_1.buildSellTransaction)(this.connection, {
186
+ mint: params.mint,
187
+ seller: params.agent,
188
+ amount_tokens: params.amount_tokens,
189
+ slippage_bps: params.slippage_bps,
190
+ message: params.message,
191
+ vault: params.stronghold,
192
+ });
193
+ }
194
+ async fud(params) {
195
+ const MICRO_SELL_TOKENS = 100;
196
+ if (params.ascended) {
197
+ const quote = await (0, torchsdk_1.getSellQuote)(this.connection, params.mint, MICRO_SELL_TOKENS);
198
+ const minOut = Math.max(1, Math.floor(quote.output_sol * (1 - 500 / 10_000)));
199
+ return (0, torchsdk_1.buildVaultSwapTransaction)(this.connection, {
200
+ mint: params.mint,
201
+ signer: params.agent,
202
+ vault_creator: params.stronghold,
203
+ amount_in: MICRO_SELL_TOKENS,
204
+ minimum_amount_out: minOut,
205
+ is_buy: false,
206
+ message: params.message,
207
+ });
208
+ }
209
+ return (0, torchsdk_1.buildSellTransaction)(this.connection, {
210
+ mint: params.mint,
211
+ seller: params.agent,
212
+ amount_tokens: MICRO_SELL_TOKENS,
213
+ message: params.message,
214
+ vault: params.stronghold,
215
+ });
216
+ }
217
+ async join(params) {
218
+ if (params.ascended) {
219
+ const slippage = params.slippage_bps ?? 500;
220
+ const quote = await (0, torchsdk_1.getBuyQuote)(this.connection, params.mint, params.amount_sol);
221
+ const minOut = Math.max(1, Math.floor(quote.tokens_to_user * (1 - slippage / 10_000)));
222
+ const result = await (0, torchsdk_1.buildVaultSwapTransaction)(this.connection, {
223
+ mint: params.mint,
224
+ signer: params.agent,
225
+ vault_creator: params.stronghold,
226
+ amount_in: params.amount_sol,
227
+ minimum_amount_out: minOut,
228
+ is_buy: true,
229
+ message: params.message,
230
+ });
231
+ return this.mapper.buyResult(result);
232
+ }
233
+ const result = await (0, torchsdk_1.buildBuyTransaction)(this.connection, {
234
+ mint: params.mint,
235
+ buyer: params.agent,
236
+ amount_sol: params.amount_sol,
237
+ slippage_bps: params.slippage_bps,
238
+ vote: params.strategy ? this.mapper.vote(params.strategy) : undefined,
239
+ message: params.message,
240
+ vault: params.stronghold,
241
+ });
242
+ return this.mapper.buyResult(result);
243
+ }
244
+ async launch(params) {
245
+ const result = await (0, vanity_1.buildCreateFactionTransaction)(this.connection, {
246
+ creator: params.founder,
247
+ name: params.name,
248
+ symbol: params.symbol,
249
+ metadata_uri: params.metadata_uri,
250
+ sol_target: params.sol_target,
251
+ community_token: params.community_faction,
252
+ });
253
+ return this.mapper.createResult(result);
254
+ }
255
+ async message(params) {
256
+ const MICRO_BUY_LAMPORTS = 1_000_000; // 0.001 SOL
257
+ if (params.ascended) {
258
+ const quote = await (0, torchsdk_1.getBuyQuote)(this.connection, params.mint, MICRO_BUY_LAMPORTS);
259
+ const minOut = Math.max(1, Math.floor(quote.tokens_to_user * (1 - 500 / 10_000)));
260
+ const result = await (0, torchsdk_1.buildVaultSwapTransaction)(this.connection, {
261
+ mint: params.mint,
262
+ signer: params.agent,
263
+ vault_creator: params.stronghold,
264
+ amount_in: MICRO_BUY_LAMPORTS,
265
+ minimum_amount_out: minOut,
266
+ is_buy: true,
267
+ message: params.message,
268
+ });
269
+ return this.mapper.buyResult(result);
270
+ }
271
+ const result = await (0, torchsdk_1.buildBuyTransaction)(this.connection, {
272
+ mint: params.mint,
273
+ buyer: params.agent,
274
+ amount_sol: MICRO_BUY_LAMPORTS,
275
+ message: params.message,
276
+ vault: params.stronghold,
277
+ vote: params.first_buy
278
+ ? this.mapper.vote(Math.random() > 0.5 ? 'fortify' : 'scorched_earth')
279
+ : undefined,
280
+ });
281
+ return this.mapper.buyResult(result);
282
+ }
283
+ async rally(params) {
284
+ return (0, torchsdk_1.buildStarTransaction)(this.connection, {
285
+ mint: params.mint,
286
+ user: params.agent,
287
+ vault: params.stronghold,
288
+ });
289
+ }
290
+ async raze(params) {
291
+ return (0, torchsdk_1.buildReclaimFailedTokenTransaction)(this.connection, {
292
+ payer: params.payer,
293
+ mint: params.mint,
294
+ });
295
+ }
296
+ async repayWarLoan(params) {
297
+ return (0, torchsdk_1.buildRepayTransaction)(this.connection, {
298
+ mint: params.mint,
299
+ borrower: params.borrower,
300
+ sol_amount: params.sol_amount,
301
+ vault: params.stronghold,
302
+ });
303
+ }
304
+ async requestWarLoan(params) {
305
+ return (0, torchsdk_1.buildBorrowTransaction)(this.connection, {
306
+ mint: params.mint,
307
+ borrower: params.borrower,
308
+ collateral_amount: params.collateral_amount,
309
+ sol_to_borrow: params.sol_to_borrow,
310
+ vault: params.stronghold,
311
+ });
312
+ }
313
+ async siege(params) {
314
+ return (0, torchsdk_1.buildLiquidateTransaction)(this.connection, {
315
+ mint: params.mint,
316
+ liquidator: params.liquidator,
317
+ borrower: params.borrower,
318
+ vault: params.stronghold,
319
+ });
320
+ }
321
+ async tithe(params) {
322
+ return (0, torchsdk_1.buildSwapFeesToSolTransaction)(this.connection, {
323
+ mint: params.mint,
324
+ payer: params.payer,
325
+ minimum_amount_out: params.minimum_amount_out,
326
+ harvest: true,
327
+ sources: params.sources,
328
+ });
329
+ }
330
+ }
331
+ exports.ActionProvider = ActionProvider;
@@ -0,0 +1,29 @@
1
+ import { Connection } from '@solana/web3.js';
2
+ import { AgentFactionPosition, AgentProfile, AllianceCluster, FactionPower, FactionStatus, WorldEvent, WorldStats, RivalFaction } from '../types';
3
+ import { Intel } from '../types/intel.types';
4
+ import { Action } from '../types/action.types';
5
+ export declare class IntelProvider implements Intel {
6
+ private connection;
7
+ private actionProvider;
8
+ constructor(connection: Connection, actionProvider: Action);
9
+ getAgentFactions(wallet: string, factionLimit?: number): Promise<AgentFactionPosition[]>;
10
+ getAgentProfile(wallet: string): Promise<AgentProfile>;
11
+ getAgentSolLamports(wallet: string): Promise<number>;
12
+ getAllies(mints: string[], holderLimit?: number): Promise<AllianceCluster[]>;
13
+ getFactionPower(mint: string): Promise<FactionPower>;
14
+ getFactionLeaderboard({ status, limit, }: {
15
+ status?: FactionStatus;
16
+ limit?: number;
17
+ }): Promise<FactionPower[]>;
18
+ getFactionRivals(mint: string, { limit }: {
19
+ limit?: number;
20
+ }): Promise<RivalFaction[]>;
21
+ getWorldFeed({ limit, factionLimit, }: {
22
+ limit?: number;
23
+ factionLimit?: number;
24
+ }): Promise<WorldEvent[]>;
25
+ getWorldStats(): Promise<WorldStats>;
26
+ private computePowerScore;
27
+ private computePowerScoreFromSummary;
28
+ private getPyreHolders;
29
+ }