pyre-world-kit 1.0.23 → 2.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/dist/index.d.ts +2 -1
- package/dist/index.js +16 -1
- package/dist/pyre_world.json +706 -0
- package/dist/registry.d.ts +27 -0
- package/dist/registry.js +243 -0
- package/dist/types.d.ts +75 -0
- package/package.json +1 -1
- package/src/index.ts +26 -0
- package/src/pyre_world.json +706 -0
- package/src/registry.ts +312 -0
- package/src/types.ts +84 -0
package/src/registry.ts
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pyre World Agent Registry
|
|
3
|
+
*
|
|
4
|
+
* On-chain agent identity and state persistence.
|
|
5
|
+
* Agents checkpoint their action distributions and personality summaries
|
|
6
|
+
* so any machine with the wallet key can reconstruct the agent.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
Connection,
|
|
11
|
+
PublicKey,
|
|
12
|
+
Transaction,
|
|
13
|
+
SystemProgram,
|
|
14
|
+
} from '@solana/web3.js';
|
|
15
|
+
import { BN, Program, AnchorProvider, type Wallet } from '@coral-xyz/anchor';
|
|
16
|
+
import type { TransactionResult } from 'torchsdk';
|
|
17
|
+
import type {
|
|
18
|
+
RegistryProfile,
|
|
19
|
+
RegistryWalletLink,
|
|
20
|
+
RegisterAgentParams,
|
|
21
|
+
CheckpointParams,
|
|
22
|
+
LinkAgentWalletParams,
|
|
23
|
+
UnlinkAgentWalletParams,
|
|
24
|
+
TransferAgentAuthorityParams,
|
|
25
|
+
} from './types';
|
|
26
|
+
|
|
27
|
+
import idl from './pyre_world.json';
|
|
28
|
+
|
|
29
|
+
// ─── Program ID ─────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
export const REGISTRY_PROGRAM_ID = new PublicKey(idl.address);
|
|
32
|
+
|
|
33
|
+
// ─── PDA Seeds ──────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
const AGENT_SEED = 'pyre_agent';
|
|
36
|
+
const AGENT_WALLET_SEED = 'pyre_agent_wallet';
|
|
37
|
+
|
|
38
|
+
// ─── PDA Helpers ────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
export function getAgentProfilePda(creator: PublicKey): [PublicKey, number] {
|
|
41
|
+
return PublicKey.findProgramAddressSync(
|
|
42
|
+
[Buffer.from(AGENT_SEED), creator.toBuffer()],
|
|
43
|
+
REGISTRY_PROGRAM_ID,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getAgentWalletLinkPda(wallet: PublicKey): [PublicKey, number] {
|
|
48
|
+
return PublicKey.findProgramAddressSync(
|
|
49
|
+
[Buffer.from(AGENT_WALLET_SEED), wallet.toBuffer()],
|
|
50
|
+
REGISTRY_PROGRAM_ID,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ─── Anchor Program Helper ──────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
function makeDummyProvider(connection: Connection, payer: PublicKey): AnchorProvider {
|
|
57
|
+
const dummyWallet = {
|
|
58
|
+
publicKey: payer,
|
|
59
|
+
signTransaction: async (t: Transaction) => t,
|
|
60
|
+
signAllTransactions: async (t: Transaction[]) => t,
|
|
61
|
+
};
|
|
62
|
+
return new AnchorProvider(connection, dummyWallet as unknown as Wallet, {});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function finalizeTransaction(
|
|
66
|
+
connection: Connection,
|
|
67
|
+
tx: Transaction,
|
|
68
|
+
feePayer: PublicKey,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
71
|
+
tx.recentBlockhash = blockhash;
|
|
72
|
+
tx.feePayer = feePayer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getProgram(connection: Connection, payer: PublicKey): Program {
|
|
76
|
+
const provider = makeDummyProvider(connection, payer);
|
|
77
|
+
return new Program(idl as any, provider);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── Read Operations ────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
/** Fetch an agent's on-chain registry profile by creator wallet */
|
|
83
|
+
export async function getRegistryProfile(
|
|
84
|
+
connection: Connection,
|
|
85
|
+
creator: string,
|
|
86
|
+
): Promise<RegistryProfile | null> {
|
|
87
|
+
const creatorPk = new PublicKey(creator);
|
|
88
|
+
const [profilePda] = getAgentProfilePda(creatorPk);
|
|
89
|
+
const program = getProgram(connection, creatorPk);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const account = await (program.account as any).agentProfile.fetch(profilePda);
|
|
93
|
+
return {
|
|
94
|
+
address: profilePda.toBase58(),
|
|
95
|
+
creator: account.creator.toBase58(),
|
|
96
|
+
authority: account.authority.toBase58(),
|
|
97
|
+
linked_wallet: account.linkedWallet.toBase58(),
|
|
98
|
+
personality_summary: account.personalitySummary,
|
|
99
|
+
last_checkpoint: account.lastCheckpoint.toNumber(),
|
|
100
|
+
joins: account.joins.toNumber(),
|
|
101
|
+
defects: account.defects.toNumber(),
|
|
102
|
+
rallies: account.rallies.toNumber(),
|
|
103
|
+
launches: account.launches.toNumber(),
|
|
104
|
+
messages: account.messages.toNumber(),
|
|
105
|
+
fuds: account.fuds.toNumber(),
|
|
106
|
+
infiltrates: account.infiltrates.toNumber(),
|
|
107
|
+
reinforces: account.reinforces.toNumber(),
|
|
108
|
+
war_loans: account.warLoans.toNumber(),
|
|
109
|
+
repay_loans: account.repayLoans.toNumber(),
|
|
110
|
+
sieges: account.sieges.toNumber(),
|
|
111
|
+
ascends: account.ascends.toNumber(),
|
|
112
|
+
razes: account.razes.toNumber(),
|
|
113
|
+
tithes: account.tithes.toNumber(),
|
|
114
|
+
created_at: account.createdAt.toNumber(),
|
|
115
|
+
bump: account.bump,
|
|
116
|
+
};
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Fetch a wallet link by wallet address (reverse lookup: wallet → profile) */
|
|
123
|
+
export async function getRegistryWalletLink(
|
|
124
|
+
connection: Connection,
|
|
125
|
+
wallet: string,
|
|
126
|
+
): Promise<RegistryWalletLink | null> {
|
|
127
|
+
const walletPk = new PublicKey(wallet);
|
|
128
|
+
const [linkPda] = getAgentWalletLinkPda(walletPk);
|
|
129
|
+
const program = getProgram(connection, walletPk);
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const account = await (program.account as any).agentWalletLink.fetch(linkPda);
|
|
133
|
+
return {
|
|
134
|
+
address: linkPda.toBase58(),
|
|
135
|
+
profile: account.profile.toBase58(),
|
|
136
|
+
wallet: account.wallet.toBase58(),
|
|
137
|
+
linked_at: account.linkedAt.toNumber(),
|
|
138
|
+
bump: account.bump,
|
|
139
|
+
};
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ─── Transaction Builders ───────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
/** Register a new agent profile and auto-link the creator's wallet */
|
|
148
|
+
export async function buildRegisterAgentTransaction(
|
|
149
|
+
connection: Connection,
|
|
150
|
+
params: RegisterAgentParams,
|
|
151
|
+
): Promise<TransactionResult> {
|
|
152
|
+
const creator = new PublicKey(params.creator);
|
|
153
|
+
const [profile] = getAgentProfilePda(creator);
|
|
154
|
+
const [walletLink] = getAgentWalletLinkPda(creator);
|
|
155
|
+
const program = getProgram(connection, creator);
|
|
156
|
+
|
|
157
|
+
const tx = new Transaction();
|
|
158
|
+
const ix = await (program.methods.register() as any)
|
|
159
|
+
.accounts({
|
|
160
|
+
creator,
|
|
161
|
+
profile,
|
|
162
|
+
walletLink,
|
|
163
|
+
systemProgram: SystemProgram.programId,
|
|
164
|
+
})
|
|
165
|
+
.instruction();
|
|
166
|
+
|
|
167
|
+
tx.add(ix);
|
|
168
|
+
await finalizeTransaction(connection, tx, creator);
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
transaction: tx,
|
|
172
|
+
message: `Register agent profile [${profile.toBase58()}]`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Checkpoint agent action counters and personality summary */
|
|
177
|
+
export async function buildCheckpointTransaction(
|
|
178
|
+
connection: Connection,
|
|
179
|
+
params: CheckpointParams,
|
|
180
|
+
): Promise<TransactionResult> {
|
|
181
|
+
const signer = new PublicKey(params.signer);
|
|
182
|
+
const creatorPk = new PublicKey(params.creator);
|
|
183
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
184
|
+
const program = getProgram(connection, signer);
|
|
185
|
+
|
|
186
|
+
const args = {
|
|
187
|
+
joins: new BN(params.joins),
|
|
188
|
+
defects: new BN(params.defects),
|
|
189
|
+
rallies: new BN(params.rallies),
|
|
190
|
+
launches: new BN(params.launches),
|
|
191
|
+
messages: new BN(params.messages),
|
|
192
|
+
fuds: new BN(params.fuds),
|
|
193
|
+
infiltrates: new BN(params.infiltrates),
|
|
194
|
+
reinforces: new BN(params.reinforces),
|
|
195
|
+
warLoans: new BN(params.war_loans),
|
|
196
|
+
repayLoans: new BN(params.repay_loans),
|
|
197
|
+
sieges: new BN(params.sieges),
|
|
198
|
+
ascends: new BN(params.ascends),
|
|
199
|
+
razes: new BN(params.razes),
|
|
200
|
+
tithes: new BN(params.tithes),
|
|
201
|
+
personalitySummary: params.personality_summary,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const tx = new Transaction();
|
|
205
|
+
const ix = await (program.methods.checkpoint(args) as any)
|
|
206
|
+
.accounts({
|
|
207
|
+
signer,
|
|
208
|
+
profile,
|
|
209
|
+
})
|
|
210
|
+
.instruction();
|
|
211
|
+
|
|
212
|
+
tx.add(ix);
|
|
213
|
+
await finalizeTransaction(connection, tx, signer);
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
transaction: tx,
|
|
217
|
+
message: `Checkpoint agent [${profile.toBase58()}]`,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Link a new wallet to an agent profile (authority only) */
|
|
222
|
+
export async function buildLinkAgentWalletTransaction(
|
|
223
|
+
connection: Connection,
|
|
224
|
+
params: LinkAgentWalletParams,
|
|
225
|
+
): Promise<TransactionResult> {
|
|
226
|
+
const authority = new PublicKey(params.authority);
|
|
227
|
+
const creatorPk = new PublicKey(params.creator);
|
|
228
|
+
const walletToLink = new PublicKey(params.wallet_to_link);
|
|
229
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
230
|
+
const [walletLink] = getAgentWalletLinkPda(walletToLink);
|
|
231
|
+
const program = getProgram(connection, authority);
|
|
232
|
+
|
|
233
|
+
const tx = new Transaction();
|
|
234
|
+
const ix = await (program.methods.linkWallet() as any)
|
|
235
|
+
.accounts({
|
|
236
|
+
authority,
|
|
237
|
+
profile,
|
|
238
|
+
walletToLink,
|
|
239
|
+
walletLink,
|
|
240
|
+
systemProgram: SystemProgram.programId,
|
|
241
|
+
})
|
|
242
|
+
.instruction();
|
|
243
|
+
|
|
244
|
+
tx.add(ix);
|
|
245
|
+
await finalizeTransaction(connection, tx, authority);
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
transaction: tx,
|
|
249
|
+
message: `Link wallet ${walletToLink.toBase58()} to agent [${profile.toBase58()}]`,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Unlink the current wallet from an agent profile (authority only) */
|
|
254
|
+
export async function buildUnlinkAgentWalletTransaction(
|
|
255
|
+
connection: Connection,
|
|
256
|
+
params: UnlinkAgentWalletParams,
|
|
257
|
+
): Promise<TransactionResult> {
|
|
258
|
+
const authority = new PublicKey(params.authority);
|
|
259
|
+
const creatorPk = new PublicKey(params.creator);
|
|
260
|
+
const walletToUnlink = new PublicKey(params.wallet_to_unlink);
|
|
261
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
262
|
+
const [walletLink] = getAgentWalletLinkPda(walletToUnlink);
|
|
263
|
+
const program = getProgram(connection, authority);
|
|
264
|
+
|
|
265
|
+
const tx = new Transaction();
|
|
266
|
+
const ix = await (program.methods.unlinkWallet() as any)
|
|
267
|
+
.accounts({
|
|
268
|
+
authority,
|
|
269
|
+
profile,
|
|
270
|
+
walletToUnlink,
|
|
271
|
+
walletLink,
|
|
272
|
+
systemProgram: SystemProgram.programId,
|
|
273
|
+
})
|
|
274
|
+
.instruction();
|
|
275
|
+
|
|
276
|
+
tx.add(ix);
|
|
277
|
+
await finalizeTransaction(connection, tx, authority);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
transaction: tx,
|
|
281
|
+
message: `Unlink wallet ${walletToUnlink.toBase58()} from agent [${profile.toBase58()}]`,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Transfer agent profile authority to a new wallet */
|
|
286
|
+
export async function buildTransferAgentAuthorityTransaction(
|
|
287
|
+
connection: Connection,
|
|
288
|
+
params: TransferAgentAuthorityParams,
|
|
289
|
+
): Promise<TransactionResult> {
|
|
290
|
+
const authority = new PublicKey(params.authority);
|
|
291
|
+
const creatorPk = new PublicKey(params.creator);
|
|
292
|
+
const newAuthority = new PublicKey(params.new_authority);
|
|
293
|
+
const [profile] = getAgentProfilePda(creatorPk);
|
|
294
|
+
const program = getProgram(connection, authority);
|
|
295
|
+
|
|
296
|
+
const tx = new Transaction();
|
|
297
|
+
const ix = await (program.methods.transferAuthority() as any)
|
|
298
|
+
.accounts({
|
|
299
|
+
authority,
|
|
300
|
+
profile,
|
|
301
|
+
newAuthority,
|
|
302
|
+
})
|
|
303
|
+
.instruction();
|
|
304
|
+
|
|
305
|
+
tx.add(ix);
|
|
306
|
+
await finalizeTransaction(connection, tx, authority);
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
transaction: tx,
|
|
310
|
+
message: `Transfer agent authority to ${newAuthority.toBase58()}`,
|
|
311
|
+
};
|
|
312
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -470,3 +470,87 @@ export interface WorldStats {
|
|
|
470
470
|
total_sol_locked: number;
|
|
471
471
|
most_powerful: FactionPower | null;
|
|
472
472
|
}
|
|
473
|
+
|
|
474
|
+
// ─── Registry Types (pyre_world on-chain agent identity) ──────────
|
|
475
|
+
|
|
476
|
+
/** On-chain agent profile from pyre_world registry */
|
|
477
|
+
export interface RegistryProfile {
|
|
478
|
+
address: string;
|
|
479
|
+
creator: string;
|
|
480
|
+
authority: string;
|
|
481
|
+
linked_wallet: string;
|
|
482
|
+
personality_summary: string;
|
|
483
|
+
last_checkpoint: number;
|
|
484
|
+
joins: number;
|
|
485
|
+
defects: number;
|
|
486
|
+
rallies: number;
|
|
487
|
+
launches: number;
|
|
488
|
+
messages: number;
|
|
489
|
+
fuds: number;
|
|
490
|
+
infiltrates: number;
|
|
491
|
+
reinforces: number;
|
|
492
|
+
war_loans: number;
|
|
493
|
+
repay_loans: number;
|
|
494
|
+
sieges: number;
|
|
495
|
+
ascends: number;
|
|
496
|
+
razes: number;
|
|
497
|
+
tithes: number;
|
|
498
|
+
created_at: number;
|
|
499
|
+
bump: number;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** On-chain wallet link from pyre_world registry */
|
|
503
|
+
export interface RegistryWalletLink {
|
|
504
|
+
address: string;
|
|
505
|
+
profile: string;
|
|
506
|
+
wallet: string;
|
|
507
|
+
linked_at: number;
|
|
508
|
+
bump: number;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** Params for checkpointing agent state on-chain */
|
|
512
|
+
export interface CheckpointParams {
|
|
513
|
+
signer: string;
|
|
514
|
+
creator: string;
|
|
515
|
+
joins: number;
|
|
516
|
+
defects: number;
|
|
517
|
+
rallies: number;
|
|
518
|
+
launches: number;
|
|
519
|
+
messages: number;
|
|
520
|
+
fuds: number;
|
|
521
|
+
infiltrates: number;
|
|
522
|
+
reinforces: number;
|
|
523
|
+
war_loans: number;
|
|
524
|
+
repay_loans: number;
|
|
525
|
+
sieges: number;
|
|
526
|
+
ascends: number;
|
|
527
|
+
razes: number;
|
|
528
|
+
tithes: number;
|
|
529
|
+
personality_summary: string;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** Params for registering a new agent */
|
|
533
|
+
export interface RegisterAgentParams {
|
|
534
|
+
creator: string;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Params for linking a wallet to an agent profile */
|
|
538
|
+
export interface LinkAgentWalletParams {
|
|
539
|
+
authority: string;
|
|
540
|
+
creator: string;
|
|
541
|
+
wallet_to_link: string;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** Params for unlinking a wallet from an agent profile */
|
|
545
|
+
export interface UnlinkAgentWalletParams {
|
|
546
|
+
authority: string;
|
|
547
|
+
creator: string;
|
|
548
|
+
wallet_to_unlink: string;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Params for transferring agent profile authority */
|
|
552
|
+
export interface TransferAgentAuthorityParams {
|
|
553
|
+
authority: string;
|
|
554
|
+
creator: string;
|
|
555
|
+
new_authority: string;
|
|
556
|
+
}
|