nara-sdk 1.0.54 → 1.0.56

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 CHANGED
@@ -32,6 +32,7 @@ export {
32
32
  submitAnswerViaRelay,
33
33
  parseQuestReward,
34
34
  computeAnswerHash,
35
+ makeCreateQuestionIx,
35
36
  createQuestion,
36
37
  stake,
37
38
  unstake,
@@ -118,16 +119,34 @@ export {
118
119
  logActivityWithReferral,
119
120
  makeLogActivityIx,
120
121
  makeLogActivityWithReferralIx,
122
+ setReferral,
123
+ // Twitter verification
124
+ getAgentTwitter,
125
+ getTweetVerify,
126
+ setTwitter,
127
+ submitTweet,
128
+ unbindTwitter,
129
+ verifyTwitter,
130
+ rejectTwitter,
131
+ approveTweet,
132
+ rejectTweet,
133
+ // Admin
121
134
  initConfig as initAgentRegistryConfig,
122
135
  updateAdmin,
123
136
  withdrawFees as withdrawAgentRegistryFees,
124
137
  updateRegisterFee,
125
138
  updatePointsConfig,
126
- setReferral,
127
139
  updateReferralConfig,
128
140
  updateActivityConfig,
141
+ expandConfig,
142
+ updateTwitterVerifier,
143
+ updateTwitterVerificationConfig,
144
+ updateTweetVerifyConfig,
145
+ withdrawTwitterVerifyFees,
129
146
  type AgentRecord,
130
147
  type AgentInfo,
148
+ type AgentTwitterInfo,
149
+ type TweetVerifyInfo,
131
150
  type MemoryMode,
132
151
  type AgentRegistryOptions,
133
152
  } from "./src/agent_registry";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nara-sdk",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "SDK for the Nara chain (Solana-compatible)",
5
5
  "module": "index.ts",
6
6
  "main": "index.ts",
@@ -52,6 +52,20 @@ export interface AgentInfo {
52
52
  metadata: string | null;
53
53
  }
54
54
 
55
+ export interface AgentTwitterInfo {
56
+ status: number;
57
+ verifiedAt: number;
58
+ username: string;
59
+ tweetUrl: string;
60
+ }
61
+
62
+ export interface TweetVerifyInfo {
63
+ status: number;
64
+ submittedAt: number;
65
+ lastRewardedAt: number;
66
+ tweetUrl: string;
67
+ }
68
+
55
69
  export type MemoryMode = "new" | "update" | "append" | "auto";
56
70
 
57
71
  export interface AgentRegistryOptions {
@@ -147,6 +161,38 @@ function getRefereeActivityMintPda(programId: PublicKey): PublicKey {
147
161
  return pda;
148
162
  }
149
163
 
164
+ function getTreasuryPda(programId: PublicKey): PublicKey {
165
+ const [pda] = PublicKey.findProgramAddressSync(
166
+ [Buffer.from("treasury")],
167
+ programId
168
+ );
169
+ return pda;
170
+ }
171
+
172
+ function getTwitterPda(programId: PublicKey, agentPda: PublicKey): PublicKey {
173
+ const [pda] = PublicKey.findProgramAddressSync(
174
+ [Buffer.from("twitter"), agentPda.toBuffer()],
175
+ programId
176
+ );
177
+ return pda;
178
+ }
179
+
180
+ function getTweetVerifyPda(programId: PublicKey, agentPda: PublicKey): PublicKey {
181
+ const [pda] = PublicKey.findProgramAddressSync(
182
+ [Buffer.from("tweet_verify"), agentPda.toBuffer()],
183
+ programId
184
+ );
185
+ return pda;
186
+ }
187
+
188
+ function getTwitterHandlePda(programId: PublicKey, username: string): PublicKey {
189
+ const [pda] = PublicKey.findProgramAddressSync(
190
+ [Buffer.from("twitter_handle"), Buffer.from(username)],
191
+ programId
192
+ );
193
+ return pda;
194
+ }
195
+
150
196
  /**
151
197
  * Build referral-related accounts for register_agent / log_activity.
152
198
  * Returns the referral agent PDA, its authority, and the authority's ATA for point_mint.
@@ -323,6 +369,12 @@ export async function getConfig(
323
369
  referralRegisterPoints: number;
324
370
  activityReward: number;
325
371
  referralActivityReward: number;
372
+ twitterVerifier: PublicKey;
373
+ twitterVerificationFee: number;
374
+ twitterVerificationReward: number;
375
+ twitterVerificationPoints: number;
376
+ tweetVerifyReward: number;
377
+ tweetVerifyPoints: number;
326
378
  }> {
327
379
  const pid = new PublicKey(options?.programId ?? DEFAULT_AGENT_REGISTRY_PROGRAM_ID);
328
380
  const configPda = getConfigPda(pid);
@@ -344,8 +396,14 @@ export async function getConfig(
344
396
  const referralFeeShare = Number(buf.readBigUInt64LE(offset)); offset += 8;
345
397
  const referralRegisterPoints = Number(buf.readBigUInt64LE(offset)); offset += 8;
346
398
  const activityReward = Number(buf.readBigUInt64LE(offset)); offset += 8;
347
- const referralActivityReward = Number(buf.readBigUInt64LE(offset));
348
- return { admin, feeVault, pointMint, refereeMint, refereeActivityMint, registerFee, pointsSelf, pointsReferral, referralRegisterFee, referralFeeShare, referralRegisterPoints, activityReward, referralActivityReward };
399
+ const referralActivityReward = Number(buf.readBigUInt64LE(offset)); offset += 8;
400
+ const twitterVerifier = new PublicKey(buf.subarray(offset, offset + 32)); offset += 32;
401
+ const twitterVerificationFee = Number(buf.readBigUInt64LE(offset)); offset += 8;
402
+ const twitterVerificationReward = Number(buf.readBigUInt64LE(offset)); offset += 8;
403
+ const twitterVerificationPoints = Number(buf.readBigUInt64LE(offset)); offset += 8;
404
+ const tweetVerifyReward = Number(buf.readBigUInt64LE(offset)); offset += 8;
405
+ const tweetVerifyPoints = Number(buf.readBigUInt64LE(offset));
406
+ return { admin, feeVault, pointMint, refereeMint, refereeActivityMint, registerFee, pointsSelf, pointsReferral, referralRegisterFee, referralFeeShare, referralRegisterPoints, activityReward, referralActivityReward, twitterVerifier, twitterVerificationFee, twitterVerificationReward, twitterVerificationPoints, tweetVerifyReward, tweetVerifyPoints };
349
407
  }
350
408
 
351
409
  // ─── Agent CRUD ─────────────────────────────────────────────────
@@ -978,3 +1036,319 @@ export async function updateActivityConfig(
978
1036
  .instruction();
979
1037
  return sendTx(connection, wallet, [ix]);
980
1038
  }
1039
+
1040
+ /**
1041
+ * Expand the config account size (admin-only).
1042
+ */
1043
+ export async function expandConfig(
1044
+ connection: Connection,
1045
+ wallet: Keypair,
1046
+ extendSize: number | anchor.BN,
1047
+ options?: AgentRegistryOptions
1048
+ ): Promise<string> {
1049
+ const program = createProgram(connection, wallet, options?.programId);
1050
+ const size = typeof extendSize === "number" ? new anchor.BN(extendSize) : extendSize;
1051
+ const ix = await program.methods
1052
+ .expandConfig(size)
1053
+ .accounts({ admin: wallet.publicKey } as any)
1054
+ .instruction();
1055
+ return sendTx(connection, wallet, [ix]);
1056
+ }
1057
+
1058
+ /**
1059
+ * Update the twitter verifier address (admin-only).
1060
+ */
1061
+ export async function updateTwitterVerifier(
1062
+ connection: Connection,
1063
+ wallet: Keypair,
1064
+ newVerifier: PublicKey,
1065
+ options?: AgentRegistryOptions
1066
+ ): Promise<string> {
1067
+ const program = createProgram(connection, wallet, options?.programId);
1068
+ const ix = await program.methods
1069
+ .updateTwitterVerifier(newVerifier)
1070
+ .accounts({ admin: wallet.publicKey } as any)
1071
+ .instruction();
1072
+ return sendTx(connection, wallet, [ix]);
1073
+ }
1074
+
1075
+ /**
1076
+ * Update the twitter verification config (admin-only).
1077
+ * @param fee - Verification fee in lamports
1078
+ * @param reward - Reward for verified twitter in lamports
1079
+ * @param points - Points awarded for twitter verification
1080
+ */
1081
+ export async function updateTwitterVerificationConfig(
1082
+ connection: Connection,
1083
+ wallet: Keypair,
1084
+ fee: number | anchor.BN,
1085
+ reward: number | anchor.BN,
1086
+ points: number | anchor.BN,
1087
+ options?: AgentRegistryOptions
1088
+ ): Promise<string> {
1089
+ const program = createProgram(connection, wallet, options?.programId);
1090
+ const f = typeof fee === "number" ? new anchor.BN(fee) : fee;
1091
+ const r = typeof reward === "number" ? new anchor.BN(reward) : reward;
1092
+ const p = typeof points === "number" ? new anchor.BN(points) : points;
1093
+ const ix = await program.methods
1094
+ .updateTwitterVerificationConfig(f, r, p)
1095
+ .accounts({ admin: wallet.publicKey } as any)
1096
+ .instruction();
1097
+ return sendTx(connection, wallet, [ix]);
1098
+ }
1099
+
1100
+ /**
1101
+ * Update the tweet verify config (admin-only).
1102
+ * @param reward - Reward for verified tweet in lamports
1103
+ * @param points - Points awarded for tweet verification
1104
+ */
1105
+ export async function updateTweetVerifyConfig(
1106
+ connection: Connection,
1107
+ wallet: Keypair,
1108
+ reward: number | anchor.BN,
1109
+ points: number | anchor.BN,
1110
+ options?: AgentRegistryOptions
1111
+ ): Promise<string> {
1112
+ const program = createProgram(connection, wallet, options?.programId);
1113
+ const r = typeof reward === "number" ? new anchor.BN(reward) : reward;
1114
+ const p = typeof points === "number" ? new anchor.BN(points) : points;
1115
+ const ix = await program.methods
1116
+ .updateTweetVerifyConfig(r, p)
1117
+ .accounts({ admin: wallet.publicKey } as any)
1118
+ .instruction();
1119
+ return sendTx(connection, wallet, [ix]);
1120
+ }
1121
+
1122
+ /**
1123
+ * Withdraw accumulated twitter verification fees (admin-only).
1124
+ */
1125
+ export async function withdrawTwitterVerifyFees(
1126
+ connection: Connection,
1127
+ wallet: Keypair,
1128
+ amount: number | anchor.BN,
1129
+ options?: AgentRegistryOptions
1130
+ ): Promise<string> {
1131
+ const program = createProgram(connection, wallet, options?.programId);
1132
+ const amt = typeof amount === "number" ? new anchor.BN(amount) : amount;
1133
+ const ix = await program.methods
1134
+ .withdrawTwitterVerifyFees(amt)
1135
+ .accounts({ admin: wallet.publicKey } as any)
1136
+ .instruction();
1137
+ return sendTx(connection, wallet, [ix]);
1138
+ }
1139
+
1140
+ // ─── Twitter Verification ───────────────────────────────────────
1141
+
1142
+ /**
1143
+ * Read an agent's twitter verification state.
1144
+ * Returns null if no twitter account exists.
1145
+ */
1146
+ export async function getAgentTwitter(
1147
+ connection: Connection,
1148
+ agentId: string,
1149
+ options?: AgentRegistryOptions
1150
+ ): Promise<AgentTwitterInfo | null> {
1151
+ const pid = new PublicKey(options?.programId ?? DEFAULT_AGENT_REGISTRY_PROGRAM_ID);
1152
+ const agentPda = getAgentPda(pid, agentId);
1153
+ const twitterPda = getTwitterPda(pid, agentPda);
1154
+ const accountInfo = await connection.getAccountInfo(twitterPda);
1155
+ if (!accountInfo) return null;
1156
+
1157
+ const buf = Buffer.from(accountInfo.data);
1158
+ let offset = 8; // skip discriminator
1159
+ const status = Number(buf.readBigUInt64LE(offset)); offset += 8;
1160
+ const verifiedAt = Number(buf.readBigInt64LE(offset)); offset += 8;
1161
+ const usernameLen = Number(buf.readBigUInt64LE(offset)); offset += 8;
1162
+ const tweetUrlLen = Number(buf.readBigUInt64LE(offset)); offset += 8;
1163
+ const username = buf.subarray(offset, offset + usernameLen).toString("utf-8"); offset += 32;
1164
+ const tweetUrl = buf.subarray(offset, offset + tweetUrlLen).toString("utf-8");
1165
+
1166
+ return { status, verifiedAt, username, tweetUrl };
1167
+ }
1168
+
1169
+ /**
1170
+ * Read an agent's tweet verify state.
1171
+ * Returns null if no tweet verify account exists.
1172
+ */
1173
+ export async function getTweetVerify(
1174
+ connection: Connection,
1175
+ agentId: string,
1176
+ options?: AgentRegistryOptions
1177
+ ): Promise<TweetVerifyInfo | null> {
1178
+ const pid = new PublicKey(options?.programId ?? DEFAULT_AGENT_REGISTRY_PROGRAM_ID);
1179
+ const agentPda = getAgentPda(pid, agentId);
1180
+ const tweetVerifyPda = getTweetVerifyPda(pid, agentPda);
1181
+ const accountInfo = await connection.getAccountInfo(tweetVerifyPda);
1182
+ if (!accountInfo) return null;
1183
+
1184
+ const buf = Buffer.from(accountInfo.data);
1185
+ let offset = 8;
1186
+ const status = Number(buf.readBigUInt64LE(offset)); offset += 8;
1187
+ const submittedAt = Number(buf.readBigInt64LE(offset)); offset += 8;
1188
+ const lastRewardedAt = Number(buf.readBigInt64LE(offset)); offset += 8;
1189
+ const tweetUrlLen = Number(buf.readBigUInt64LE(offset)); offset += 8;
1190
+ const tweetUrl = buf.subarray(offset, offset + tweetUrlLen).toString("utf-8");
1191
+
1192
+ return { status, submittedAt, lastRewardedAt, tweetUrl };
1193
+ }
1194
+
1195
+ /**
1196
+ * Set twitter info for an agent and submit for verification.
1197
+ * Charges the twitter verification fee.
1198
+ */
1199
+ export async function setTwitter(
1200
+ connection: Connection,
1201
+ wallet: Keypair,
1202
+ agentId: string,
1203
+ username: string,
1204
+ tweetUrl: string,
1205
+ options?: AgentRegistryOptions
1206
+ ): Promise<string> {
1207
+ const program = createProgram(connection, wallet, options?.programId);
1208
+ const ix = await program.methods
1209
+ .setTwitter(agentId, username, tweetUrl)
1210
+ .accounts({ authority: wallet.publicKey } as any)
1211
+ .instruction();
1212
+ return sendTx(connection, wallet, [ix]);
1213
+ }
1214
+
1215
+ /**
1216
+ * Submit a tweet for verification (agent owner).
1217
+ * Charges the twitter verification fee.
1218
+ */
1219
+ export async function submitTweet(
1220
+ connection: Connection,
1221
+ wallet: Keypair,
1222
+ agentId: string,
1223
+ username: string,
1224
+ tweetUrl: string,
1225
+ options?: AgentRegistryOptions
1226
+ ): Promise<string> {
1227
+ const program = createProgram(connection, wallet, options?.programId);
1228
+ const ix = await program.methods
1229
+ .submitTweet(agentId, username, tweetUrl)
1230
+ .accounts({ authority: wallet.publicKey } as any)
1231
+ .instruction();
1232
+ return sendTx(connection, wallet, [ix]);
1233
+ }
1234
+
1235
+ /**
1236
+ * Unbind twitter from an agent (agent owner).
1237
+ */
1238
+ export async function unbindTwitter(
1239
+ connection: Connection,
1240
+ wallet: Keypair,
1241
+ agentId: string,
1242
+ username: string,
1243
+ options?: AgentRegistryOptions
1244
+ ): Promise<string> {
1245
+ const program = createProgram(connection, wallet, options?.programId);
1246
+ const ix = await program.methods
1247
+ .unbindTwitter(agentId, username)
1248
+ .accounts({ authority: wallet.publicKey } as any)
1249
+ .instruction();
1250
+ return sendTx(connection, wallet, [ix]);
1251
+ }
1252
+
1253
+ /**
1254
+ * Verify an agent's twitter (verifier-only).
1255
+ * Awards verification reward and points to the agent owner.
1256
+ */
1257
+ export async function verifyTwitter(
1258
+ connection: Connection,
1259
+ wallet: Keypair,
1260
+ agentId: string,
1261
+ username: string,
1262
+ options?: AgentRegistryOptions
1263
+ ): Promise<string> {
1264
+ const program = createProgram(connection, wallet, options?.programId);
1265
+ const agentPda = getAgentPda(program.programId, agentId);
1266
+
1267
+ // Resolve agent authority for reward distribution
1268
+ const accountInfo = await connection.getAccountInfo(agentPda);
1269
+ if (!accountInfo) throw new Error(`Agent "${agentId}" not found`);
1270
+ const authority = new PublicKey(accountInfo.data.subarray(8, 40));
1271
+
1272
+ const pointMint = getPointMintPda(program.programId);
1273
+ const authorityPointAccount = getAssociatedTokenAddressSync(
1274
+ pointMint, authority, true, TOKEN_2022_PROGRAM_ID
1275
+ );
1276
+
1277
+ const ix = await program.methods
1278
+ .verifyTwitter(agentId, username)
1279
+ .accounts({
1280
+ verifier: wallet.publicKey,
1281
+ authority,
1282
+ authorityPointAccount,
1283
+ } as any)
1284
+ .instruction();
1285
+ return sendTx(connection, wallet, [ix]);
1286
+ }
1287
+
1288
+ /**
1289
+ * Reject an agent's twitter verification (verifier-only).
1290
+ */
1291
+ export async function rejectTwitter(
1292
+ connection: Connection,
1293
+ wallet: Keypair,
1294
+ agentId: string,
1295
+ options?: AgentRegistryOptions
1296
+ ): Promise<string> {
1297
+ const program = createProgram(connection, wallet, options?.programId);
1298
+ const ix = await program.methods
1299
+ .rejectTwitter(agentId)
1300
+ .accounts({ verifier: wallet.publicKey } as any)
1301
+ .instruction();
1302
+ return sendTx(connection, wallet, [ix]);
1303
+ }
1304
+
1305
+ /**
1306
+ * Approve a tweet verification (verifier-only).
1307
+ * Awards tweet verify reward and points to the agent owner.
1308
+ */
1309
+ export async function approveTweet(
1310
+ connection: Connection,
1311
+ wallet: Keypair,
1312
+ agentId: string,
1313
+ options?: AgentRegistryOptions
1314
+ ): Promise<string> {
1315
+ const program = createProgram(connection, wallet, options?.programId);
1316
+ const agentPda = getAgentPda(program.programId, agentId);
1317
+
1318
+ // Resolve agent authority for reward distribution
1319
+ const accountInfo = await connection.getAccountInfo(agentPda);
1320
+ if (!accountInfo) throw new Error(`Agent "${agentId}" not found`);
1321
+ const authority = new PublicKey(accountInfo.data.subarray(8, 40));
1322
+
1323
+ const pointMint = getPointMintPda(program.programId);
1324
+ const authorityPointAccount = getAssociatedTokenAddressSync(
1325
+ pointMint, authority, true, TOKEN_2022_PROGRAM_ID
1326
+ );
1327
+
1328
+ const ix = await program.methods
1329
+ .approveTweet(agentId)
1330
+ .accounts({
1331
+ verifier: wallet.publicKey,
1332
+ authority,
1333
+ authorityPointAccount,
1334
+ } as any)
1335
+ .instruction();
1336
+ return sendTx(connection, wallet, [ix]);
1337
+ }
1338
+
1339
+ /**
1340
+ * Reject a tweet verification (verifier-only).
1341
+ */
1342
+ export async function rejectTweet(
1343
+ connection: Connection,
1344
+ wallet: Keypair,
1345
+ agentId: string,
1346
+ options?: AgentRegistryOptions
1347
+ ): Promise<string> {
1348
+ const program = createProgram(connection, wallet, options?.programId);
1349
+ const ix = await program.methods
1350
+ .rejectTweet(agentId)
1351
+ .accounts({ verifier: wallet.publicKey } as any)
1352
+ .instruction();
1353
+ return sendTx(connection, wallet, [ix]);
1354
+ }