nara-sdk 1.0.68 → 1.0.69
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/index.ts +4 -0
- package/package.json +1 -1
- package/src/agent_registry.ts +95 -0
package/index.ts
CHANGED
|
@@ -108,6 +108,10 @@ export {
|
|
|
108
108
|
|
|
109
109
|
// Export agent registry functions and types
|
|
110
110
|
export {
|
|
111
|
+
makeRegisterAgentIx,
|
|
112
|
+
makeRegisterAgentWithReferralIx,
|
|
113
|
+
makeSetTwitterIx,
|
|
114
|
+
makeSubmitTweetIx,
|
|
111
115
|
registerAgent,
|
|
112
116
|
registerAgentWithReferral,
|
|
113
117
|
getAgentRecord,
|
package/package.json
CHANGED
package/src/agent_registry.ts
CHANGED
|
@@ -461,6 +461,101 @@ export async function getConfig(
|
|
|
461
461
|
|
|
462
462
|
// ─── Agent CRUD ─────────────────────────────────────────────────
|
|
463
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Build a registerAgent instruction without sending it.
|
|
466
|
+
*/
|
|
467
|
+
export async function makeRegisterAgentIx(
|
|
468
|
+
connection: Connection,
|
|
469
|
+
payer: PublicKey,
|
|
470
|
+
authority: PublicKey,
|
|
471
|
+
agentId: string,
|
|
472
|
+
options?: AgentRegistryOptions
|
|
473
|
+
): Promise<TransactionInstruction> {
|
|
474
|
+
if (/[A-Z]/.test(agentId)) {
|
|
475
|
+
throw new Error(`Agent ID must not contain uppercase letters: "${agentId}"`);
|
|
476
|
+
}
|
|
477
|
+
const program = createProgram(connection, Keypair.generate(), options?.programId);
|
|
478
|
+
return program.methods
|
|
479
|
+
.registerAgent(agentId)
|
|
480
|
+
.accounts({ payer, authority } as any)
|
|
481
|
+
.instruction();
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Build a registerAgentWithReferral instruction without sending it.
|
|
486
|
+
*/
|
|
487
|
+
export async function makeRegisterAgentWithReferralIx(
|
|
488
|
+
connection: Connection,
|
|
489
|
+
payer: PublicKey,
|
|
490
|
+
authority: PublicKey,
|
|
491
|
+
agentId: string,
|
|
492
|
+
referralAgentId: string,
|
|
493
|
+
options?: AgentRegistryOptions
|
|
494
|
+
): Promise<TransactionInstruction> {
|
|
495
|
+
if (/[A-Z]/.test(agentId)) {
|
|
496
|
+
throw new Error(`Agent ID must not contain uppercase letters: "${agentId}"`);
|
|
497
|
+
}
|
|
498
|
+
const program = createProgram(connection, Keypair.generate(), options?.programId);
|
|
499
|
+
const pointMint = getPointMintPda(program.programId);
|
|
500
|
+
|
|
501
|
+
const { referralAgent, referralAuthority, referralPointAccount } =
|
|
502
|
+
await resolveReferralAccounts(connection, referralAgentId, program.programId, pointMint);
|
|
503
|
+
|
|
504
|
+
const refereeMint = getRefereeMintPda(program.programId);
|
|
505
|
+
const referralRefereeAccount = getAssociatedTokenAddressSync(
|
|
506
|
+
refereeMint, referralAuthority, true, TOKEN_2022_PROGRAM_ID
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
return program.methods
|
|
510
|
+
.registerAgentWithReferral(agentId)
|
|
511
|
+
.accounts({
|
|
512
|
+
payer,
|
|
513
|
+
authority,
|
|
514
|
+
referralAgent,
|
|
515
|
+
referralAuthority,
|
|
516
|
+
referralPointAccount,
|
|
517
|
+
referralRefereeAccount,
|
|
518
|
+
} as any)
|
|
519
|
+
.instruction();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Build a setTwitter instruction without sending it.
|
|
524
|
+
*/
|
|
525
|
+
export async function makeSetTwitterIx(
|
|
526
|
+
connection: Connection,
|
|
527
|
+
payer: PublicKey,
|
|
528
|
+
authority: PublicKey,
|
|
529
|
+
agentId: string,
|
|
530
|
+
username: string,
|
|
531
|
+
tweetUrl: string,
|
|
532
|
+
options?: AgentRegistryOptions
|
|
533
|
+
): Promise<TransactionInstruction> {
|
|
534
|
+
const program = createProgram(connection, Keypair.generate(), options?.programId);
|
|
535
|
+
return program.methods
|
|
536
|
+
.setTwitter(agentId, username, tweetUrl)
|
|
537
|
+
.accounts({ payer, authority } as any)
|
|
538
|
+
.instruction();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Build a submitTweet instruction without sending it.
|
|
543
|
+
*/
|
|
544
|
+
export async function makeSubmitTweetIx(
|
|
545
|
+
connection: Connection,
|
|
546
|
+
payer: PublicKey,
|
|
547
|
+
authority: PublicKey,
|
|
548
|
+
agentId: string,
|
|
549
|
+
tweetId: bigint,
|
|
550
|
+
options?: AgentRegistryOptions
|
|
551
|
+
): Promise<TransactionInstruction> {
|
|
552
|
+
const program = createProgram(connection, Keypair.generate(), options?.programId);
|
|
553
|
+
return program.methods
|
|
554
|
+
.submitTweet(agentId, new BN(tweetId.toString()))
|
|
555
|
+
.accounts({ payer, authority } as any)
|
|
556
|
+
.instruction();
|
|
557
|
+
}
|
|
558
|
+
|
|
464
559
|
/**
|
|
465
560
|
* Register a new agent on-chain (without referral). Charges the program's registration fee.
|
|
466
561
|
*/
|