nara-sdk 1.0.67 → 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 +123 -14
- package/src/idls/nara_agent_registry.json +20 -4
- package/src/idls/nara_agent_registry.ts +20 -4
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
|
*/
|
|
@@ -468,20 +563,24 @@ export async function registerAgent(
|
|
|
468
563
|
connection: Connection,
|
|
469
564
|
wallet: Keypair,
|
|
470
565
|
agentId: string,
|
|
471
|
-
options?: AgentRegistryOptions
|
|
566
|
+
options?: AgentRegistryOptions,
|
|
567
|
+
payer?: Keypair
|
|
472
568
|
): Promise<{ signature: string; agentPubkey: PublicKey }> {
|
|
473
569
|
if (/[A-Z]/.test(agentId)) {
|
|
474
570
|
throw new Error(`Agent ID must not contain uppercase letters: "${agentId}"`);
|
|
475
571
|
}
|
|
476
|
-
const
|
|
572
|
+
const payerKp = payer ?? wallet;
|
|
573
|
+
const program = createProgram(connection, payerKp, options?.programId);
|
|
477
574
|
|
|
478
575
|
const ix = await program.methods
|
|
479
576
|
.registerAgent(agentId)
|
|
480
577
|
.accounts({
|
|
578
|
+
payer: payerKp.publicKey,
|
|
481
579
|
authority: wallet.publicKey,
|
|
482
580
|
} as any)
|
|
483
581
|
.instruction();
|
|
484
|
-
const
|
|
582
|
+
const signers = payer && !payer.publicKey.equals(wallet.publicKey) ? [wallet] : [];
|
|
583
|
+
const signature = await sendTx(connection, payerKp, [ix], signers);
|
|
485
584
|
|
|
486
585
|
const agentPubkey = getAgentPda(program.programId, agentId);
|
|
487
586
|
return { signature, agentPubkey };
|
|
@@ -496,12 +595,14 @@ export async function registerAgentWithReferral(
|
|
|
496
595
|
wallet: Keypair,
|
|
497
596
|
agentId: string,
|
|
498
597
|
referralAgentId: string,
|
|
499
|
-
options?: AgentRegistryOptions
|
|
598
|
+
options?: AgentRegistryOptions,
|
|
599
|
+
payer?: Keypair
|
|
500
600
|
): Promise<{ signature: string; agentPubkey: PublicKey }> {
|
|
501
601
|
if (/[A-Z]/.test(agentId)) {
|
|
502
602
|
throw new Error(`Agent ID must not contain uppercase letters: "${agentId}"`);
|
|
503
603
|
}
|
|
504
|
-
const
|
|
604
|
+
const payerKp = payer ?? wallet;
|
|
605
|
+
const program = createProgram(connection, payerKp, options?.programId);
|
|
505
606
|
const pointMint = getPointMintPda(program.programId);
|
|
506
607
|
|
|
507
608
|
const { referralAgent, referralAuthority, referralPointAccount } =
|
|
@@ -515,6 +616,7 @@ export async function registerAgentWithReferral(
|
|
|
515
616
|
const ix = await program.methods
|
|
516
617
|
.registerAgentWithReferral(agentId)
|
|
517
618
|
.accounts({
|
|
619
|
+
payer: payerKp.publicKey,
|
|
518
620
|
authority: wallet.publicKey,
|
|
519
621
|
referralAgent,
|
|
520
622
|
referralAuthority,
|
|
@@ -522,7 +624,8 @@ export async function registerAgentWithReferral(
|
|
|
522
624
|
referralRefereeAccount,
|
|
523
625
|
} as any)
|
|
524
626
|
.instruction();
|
|
525
|
-
const
|
|
627
|
+
const signers = payer && !payer.publicKey.equals(wallet.publicKey) ? [wallet] : [];
|
|
628
|
+
const signature = await sendTx(connection, payerKp, [ix], signers);
|
|
526
629
|
|
|
527
630
|
const agentPubkey = getAgentPda(program.programId, agentId);
|
|
528
631
|
return { signature, agentPubkey };
|
|
@@ -1357,14 +1460,17 @@ export async function setTwitter(
|
|
|
1357
1460
|
agentId: string,
|
|
1358
1461
|
username: string,
|
|
1359
1462
|
tweetUrl: string,
|
|
1360
|
-
options?: AgentRegistryOptions
|
|
1463
|
+
options?: AgentRegistryOptions,
|
|
1464
|
+
payer?: Keypair
|
|
1361
1465
|
): Promise<string> {
|
|
1362
|
-
const
|
|
1466
|
+
const payerKp = payer ?? wallet;
|
|
1467
|
+
const program = createProgram(connection, payerKp, options?.programId);
|
|
1363
1468
|
const ix = await program.methods
|
|
1364
1469
|
.setTwitter(agentId, username, tweetUrl)
|
|
1365
|
-
.accounts({ authority: wallet.publicKey } as any)
|
|
1470
|
+
.accounts({ payer: payerKp.publicKey, authority: wallet.publicKey } as any)
|
|
1366
1471
|
.instruction();
|
|
1367
|
-
|
|
1472
|
+
const signers = payer && !payer.publicKey.equals(wallet.publicKey) ? [wallet] : [];
|
|
1473
|
+
return sendTx(connection, payerKp, [ix], signers);
|
|
1368
1474
|
}
|
|
1369
1475
|
|
|
1370
1476
|
/**
|
|
@@ -1376,14 +1482,17 @@ export async function submitTweet(
|
|
|
1376
1482
|
wallet: Keypair,
|
|
1377
1483
|
agentId: string,
|
|
1378
1484
|
tweetId: bigint,
|
|
1379
|
-
options?: AgentRegistryOptions
|
|
1485
|
+
options?: AgentRegistryOptions,
|
|
1486
|
+
payer?: Keypair
|
|
1380
1487
|
): Promise<string> {
|
|
1381
|
-
const
|
|
1488
|
+
const payerKp = payer ?? wallet;
|
|
1489
|
+
const program = createProgram(connection, payerKp, options?.programId);
|
|
1382
1490
|
const ix = await program.methods
|
|
1383
1491
|
.submitTweet(agentId, new BN(tweetId.toString()))
|
|
1384
|
-
.accounts({ authority: wallet.publicKey } as any)
|
|
1492
|
+
.accounts({ payer: payerKp.publicKey, authority: wallet.publicKey } as any)
|
|
1385
1493
|
.instruction();
|
|
1386
|
-
|
|
1494
|
+
const signers = payer && !payer.publicKey.equals(wallet.publicKey) ? [wallet] : [];
|
|
1495
|
+
return sendTx(connection, payerKp, [ix], signers);
|
|
1387
1496
|
}
|
|
1388
1497
|
|
|
1389
1498
|
/**
|
|
@@ -1577,10 +1577,14 @@
|
|
|
1577
1577
|
],
|
|
1578
1578
|
"accounts": [
|
|
1579
1579
|
{
|
|
1580
|
-
"name": "
|
|
1580
|
+
"name": "payer",
|
|
1581
1581
|
"writable": true,
|
|
1582
1582
|
"signer": true
|
|
1583
1583
|
},
|
|
1584
|
+
{
|
|
1585
|
+
"name": "authority",
|
|
1586
|
+
"signer": true
|
|
1587
|
+
},
|
|
1584
1588
|
{
|
|
1585
1589
|
"name": "agent",
|
|
1586
1590
|
"writable": true,
|
|
@@ -1669,10 +1673,14 @@
|
|
|
1669
1673
|
],
|
|
1670
1674
|
"accounts": [
|
|
1671
1675
|
{
|
|
1672
|
-
"name": "
|
|
1676
|
+
"name": "payer",
|
|
1673
1677
|
"writable": true,
|
|
1674
1678
|
"signer": true
|
|
1675
1679
|
},
|
|
1680
|
+
{
|
|
1681
|
+
"name": "authority",
|
|
1682
|
+
"signer": true
|
|
1683
|
+
},
|
|
1676
1684
|
{
|
|
1677
1685
|
"name": "agent",
|
|
1678
1686
|
"writable": true,
|
|
@@ -2512,8 +2520,12 @@
|
|
|
2512
2520
|
],
|
|
2513
2521
|
"accounts": [
|
|
2514
2522
|
{
|
|
2515
|
-
"name": "
|
|
2523
|
+
"name": "payer",
|
|
2516
2524
|
"writable": true,
|
|
2525
|
+
"signer": true
|
|
2526
|
+
},
|
|
2527
|
+
{
|
|
2528
|
+
"name": "authority",
|
|
2517
2529
|
"signer": true,
|
|
2518
2530
|
"relations": [
|
|
2519
2531
|
"agent"
|
|
@@ -2675,8 +2687,12 @@
|
|
|
2675
2687
|
],
|
|
2676
2688
|
"accounts": [
|
|
2677
2689
|
{
|
|
2678
|
-
"name": "
|
|
2690
|
+
"name": "payer",
|
|
2679
2691
|
"writable": true,
|
|
2692
|
+
"signer": true
|
|
2693
|
+
},
|
|
2694
|
+
{
|
|
2695
|
+
"name": "authority",
|
|
2680
2696
|
"signer": true,
|
|
2681
2697
|
"relations": [
|
|
2682
2698
|
"agent"
|
|
@@ -1583,10 +1583,14 @@ export type NaraAgentRegistry = {
|
|
|
1583
1583
|
],
|
|
1584
1584
|
"accounts": [
|
|
1585
1585
|
{
|
|
1586
|
-
"name": "
|
|
1586
|
+
"name": "payer",
|
|
1587
1587
|
"writable": true,
|
|
1588
1588
|
"signer": true
|
|
1589
1589
|
},
|
|
1590
|
+
{
|
|
1591
|
+
"name": "authority",
|
|
1592
|
+
"signer": true
|
|
1593
|
+
},
|
|
1590
1594
|
{
|
|
1591
1595
|
"name": "agent",
|
|
1592
1596
|
"writable": true,
|
|
@@ -1675,10 +1679,14 @@ export type NaraAgentRegistry = {
|
|
|
1675
1679
|
],
|
|
1676
1680
|
"accounts": [
|
|
1677
1681
|
{
|
|
1678
|
-
"name": "
|
|
1682
|
+
"name": "payer",
|
|
1679
1683
|
"writable": true,
|
|
1680
1684
|
"signer": true
|
|
1681
1685
|
},
|
|
1686
|
+
{
|
|
1687
|
+
"name": "authority",
|
|
1688
|
+
"signer": true
|
|
1689
|
+
},
|
|
1682
1690
|
{
|
|
1683
1691
|
"name": "agent",
|
|
1684
1692
|
"writable": true,
|
|
@@ -2518,8 +2526,12 @@ export type NaraAgentRegistry = {
|
|
|
2518
2526
|
],
|
|
2519
2527
|
"accounts": [
|
|
2520
2528
|
{
|
|
2521
|
-
"name": "
|
|
2529
|
+
"name": "payer",
|
|
2522
2530
|
"writable": true,
|
|
2531
|
+
"signer": true
|
|
2532
|
+
},
|
|
2533
|
+
{
|
|
2534
|
+
"name": "authority",
|
|
2523
2535
|
"signer": true,
|
|
2524
2536
|
"relations": [
|
|
2525
2537
|
"agent"
|
|
@@ -2681,8 +2693,12 @@ export type NaraAgentRegistry = {
|
|
|
2681
2693
|
],
|
|
2682
2694
|
"accounts": [
|
|
2683
2695
|
{
|
|
2684
|
-
"name": "
|
|
2696
|
+
"name": "payer",
|
|
2685
2697
|
"writable": true,
|
|
2698
|
+
"signer": true
|
|
2699
|
+
},
|
|
2700
|
+
{
|
|
2701
|
+
"name": "authority",
|
|
2686
2702
|
"signer": true,
|
|
2687
2703
|
"relations": [
|
|
2688
2704
|
"agent"
|