@swarm-tips/client 0.4.5 → 0.4.7

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.
@@ -1,6 +1,6 @@
1
1
  import { Connection, type BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
2
2
  import { HttpClient, type HttpClientOptions } from "../http.js";
3
- import { type Action, type TransactionInspection, type TransactionIntent, type WalletSignCallback } from "./index.js";
3
+ import { EXTENSION_CREDIT_PROGRAM_ID, type Action, type TransactionInspection, type TransactionIntent, type WalletSignCallback } from "./index.js";
4
4
  export type { Action } from "./index.js";
5
5
  export interface PreparedTransactionResponse {
6
6
  message?: string;
@@ -9,6 +9,8 @@ export interface PreparedTransactionResponse {
9
9
  task_pda?: string;
10
10
  transaction_intent?: TransactionIntent;
11
11
  evm_call?: unknown;
12
+ payout_to?: string;
13
+ advance_backer?: string;
12
14
  }
13
15
  export interface VerificationDataResponse {
14
16
  task_id?: string;
@@ -17,6 +19,11 @@ export interface VerificationDataResponse {
17
19
  verification_hash: string;
18
20
  global_state?: string;
19
21
  switchboard_feed: string;
22
+ required_payout_to?: string;
23
+ advance_backer?: string;
24
+ verification_kind?: number;
25
+ co_signed_transaction?: string;
26
+ evm_verify_call?: unknown;
20
27
  }
21
28
  export interface BuildVerifyOptions {
22
29
  payer?: string;
@@ -45,7 +52,10 @@ export declare class ShillbotApiClient {
45
52
  listTasks<TTask = unknown>(limit?: number): Promise<TaskListResponse<TTask>>;
46
53
  getTask<TTask = unknown>(id: string, network?: "mainnet" | "devnet"): Promise<TTask>;
47
54
  listAgentTasks<TTask = unknown>(): Promise<TTask[] | TaskListResponse<TTask>>;
48
- listPendingApproval<TTask = unknown>(): Promise<TTask[] | TaskListResponse<TTask>>;
55
+ listPendingApproval<TTask = unknown>(networkOrOpts?: "mainnet" | "devnet" | {
56
+ network?: "mainnet" | "devnet";
57
+ token?: string;
58
+ }): Promise<TTask[] | TaskListResponse<TTask>>;
49
59
  listCampaigns<TCampaign = unknown>(): Promise<TCampaign[] | CampaignListResponse<TCampaign>>;
50
60
  campaign<TCampaign = unknown>(id: string): Promise<TCampaign>;
51
61
  campaignTasks<TTask = unknown>(id: string): Promise<TaskListResponse<TTask>>;
@@ -68,17 +78,20 @@ export declare class ShillbotApiClient {
68
78
  getVerificationData(id: string, network?: "mainnet" | "devnet"): Promise<VerificationDataResponse>;
69
79
  buildVerify(id: string, opts?: BuildVerifyOptions): Promise<PreparedTransactionResponse>;
70
80
  buildFinalize(id: string): Promise<PreparedTransactionResponse>;
81
+ buildExpire(id: string): Promise<PreparedTransactionResponse>;
71
82
  confirmTask<TResponse = unknown>(id: string, body: ConfirmTransactionRequest): Promise<TResponse>;
72
83
  }
73
- import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation } from "./verify-tx.js";
74
- export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, };
84
+ import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ExpireTaskState, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation } from "./verify-tx.js";
85
+ export { EXTENSION_CREDIT_PROGRAM_ID, MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ExpireTaskState, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, };
75
86
  export interface PreparedTransactionExpectation {
76
87
  action: Action;
77
88
  network: "mainnet" | "devnet";
78
89
  wallet: string;
79
90
  taskPda?: string;
80
91
  feePayer?: string;
92
+ sponsor?: string;
81
93
  payoutTo?: string;
94
+ expireTaskState?: ExpireTaskState;
82
95
  oracleAuthority?: string;
83
96
  escrowLamports?: bigint;
84
97
  contentId?: string;
@@ -2,7 +2,7 @@ import { Buffer } from "buffer";
2
2
  import { ComputeBudgetProgram, Secp256k1Program, } from "@solana/web3.js";
3
3
  import { HttpClient } from "../http.js";
4
4
  import { SwarmClientError } from "../errors.js";
5
- import { signAndBroadcast, } from "./index.js";
5
+ import { EXTENSION_CREDIT_PROGRAM_ID, signAndBroadcast, } from "./index.js";
6
6
  function decodeJwtWallet(token) {
7
7
  if (!token)
8
8
  return undefined;
@@ -55,8 +55,13 @@ export class ShillbotApiClient {
55
55
  listAgentTasks() {
56
56
  return this.get("/agent/tasks");
57
57
  }
58
- listPendingApproval() {
59
- return this.get("/tasks?status=pending_approval");
58
+ listPendingApproval(networkOrOpts) {
59
+ const network = typeof networkOrOpts === "string" ? networkOrOpts : networkOrOpts?.network;
60
+ const token = typeof networkOrOpts === "object" && networkOrOpts !== null
61
+ ? networkOrOpts.token
62
+ : undefined;
63
+ const suffix = network ? `?network=${encodeURIComponent(network)}` : "";
64
+ return this.http.get(`/client/pending-approval${suffix}`, token);
60
65
  }
61
66
  listCampaigns() {
62
67
  return this.get("/campaigns");
@@ -139,6 +144,16 @@ export class ShillbotApiClient {
139
144
  throw err;
140
145
  }
141
146
  const vdata = await this.getVerificationData(id, resolvedNetwork);
147
+ if (vdata.evm_verify_call || vdata.co_signed_transaction) {
148
+ return {
149
+ task_id: vdata.task_id ?? id,
150
+ transaction: vdata.co_signed_transaction ?? "",
151
+ task_pda: vdata.task_pda,
152
+ ...(vdata.evm_verify_call !== undefined ? { evm_call: vdata.evm_verify_call } : {}),
153
+ ...(vdata.required_payout_to ? { payout_to: vdata.required_payout_to } : {}),
154
+ ...(vdata.advance_backer ? { advance_backer: vdata.advance_backer } : {}),
155
+ };
156
+ }
142
157
  const fallback = await postMcpBuildVerify({
143
158
  task_id: id,
144
159
  ...(payer ? { payer } : {}),
@@ -161,12 +176,15 @@ export class ShillbotApiClient {
161
176
  buildFinalize(id) {
162
177
  return this.post(`/tasks/${encodeURIComponent(id)}/build-finalize`);
163
178
  }
179
+ buildExpire(id) {
180
+ return this.post(`/tasks/${encodeURIComponent(id)}/build-expire`);
181
+ }
164
182
  confirmTask(id, body) {
165
183
  return this.post(`/tasks/${encodeURIComponent(id)}/confirm`, body);
166
184
  }
167
185
  }
168
- import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
169
- export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, };
186
+ import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
187
+ export { EXTENSION_CREDIT_PROGRAM_ID, MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, };
170
188
  const SWITCHBOARD_PROGRAM_IDS = {
171
189
  mainnet: "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv",
172
190
  devnet: "Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2",
@@ -183,6 +201,7 @@ export const SHILLBOT_EVM_SELECTORS = {
183
201
  approve: "0x97312249", // approveTask(uint64)
184
202
  verify: "0x3bae608b", // verifyTaskAttested(uint64,uint64,bytes)
185
203
  finalize: "0xcb26e65b", // finalizeTask(uint64)
204
+ expire: "0x5e9f3d19", // expireTask(uint64)
186
205
  };
187
206
  export function normalizeEvmChainId(chain) {
188
207
  if (typeof chain === "number") {
@@ -376,9 +395,13 @@ export function estimateSolanaNetworkFeeLamports(inspected, wallet) {
376
395
  return baseSignatureFeeLamports + priorityFeeLamports + additionalFeeLamports;
377
396
  }
378
397
  export function permittedPreparedProgramIds(action, network) {
379
- return action === "verify"
380
- ? [SWITCHBOARD_PROGRAM_IDS[network], Secp256k1Program.programId.toBase58()]
381
- : [];
398
+ if (action === "verify") {
399
+ return [SWITCHBOARD_PROGRAM_IDS[network], Secp256k1Program.programId.toBase58()];
400
+ }
401
+ if (action === "finalize") {
402
+ return [EXTENSION_CREDIT_PROGRAM_ID.toBase58()];
403
+ }
404
+ return [];
382
405
  }
383
406
  /**
384
407
  * Fail-closed local validation for a server-prepared Shillbot transaction.
@@ -1,8 +1,31 @@
1
- import { Connection, Transaction, TransactionInstruction, VersionedTransaction, type BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
1
+ import { Buffer } from "buffer";
2
+ import { Connection, PublicKey, Transaction, TransactionInstruction, VersionedTransaction, type BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
2
3
  export { COORDINATION_GAME_IDL, COORDINATION_GAME_PROGRAM_ID, SHILLBOT_IDL, SHILLBOT_PROGRAM_ID, agentStatePda, buildShillbotInstruction, clientStatePda, globalStatePda, shillbotInstructionDiscriminator, taskPda, } from "../contracts/index.js";
3
4
  export type { BuildShillbotInstructionRequest, CoordinationGame, Shillbot, } from "../contracts/index.js";
4
5
  export declare const SCHEMA_VERSION: "swarm.shillbot.transaction-intent/v1";
5
- export type Action = "create" | "claim" | "submit" | "approve" | "verify" | "finalize";
6
+ export declare const EXTENSION_CREDIT_PROGRAM_ID: PublicKey;
7
+ export declare function advancePda(backer: PublicKey | string, agent: PublicKey | string): PublicKey;
8
+ export declare function routeAndRecoupDiscriminator(): Buffer;
9
+ /** Exact Anchor account byte length of `extension-credit` `Advance` (`8 + 32 + 32 + 8 + 8 + 8 + 1 + 16 = 113`). */
10
+ export declare const ADVANCE_ACCOUNT_SPACE = 113;
11
+ export declare function advanceAccountDiscriminator(): Buffer;
12
+ export interface DecodedAdvanceAccount {
13
+ backer: PublicKey;
14
+ recipient: PublicKey;
15
+ advanceLamports: bigint;
16
+ recoupedLamports: bigint;
17
+ }
18
+ /**
19
+ * Decode an on-chain `extension-credit` `Advance` account (`programs/extension-credit/src/state/advance.rs`).
20
+ * Returns `null` if the length (`113` bytes) or 8-byte Anchor discriminator (`account:Advance`) does not match.
21
+ */
22
+ export declare function decodeExtensionCreditAdvance(data: Uint8Array): DecodedAdvanceAccount | null;
23
+ export declare function buildRouteAndRecoupInstruction(accounts: {
24
+ advance: PublicKey | string;
25
+ backer: PublicKey | string;
26
+ recipient: PublicKey | string;
27
+ }): TransactionInstruction;
28
+ export type Action = "create" | "claim" | "submit" | "approve" | "verify" | "finalize" | "expire";
6
29
  export type Risk = "earn" | "spend" | "escrow_control";
7
30
  export type Network = "mainnet" | "devnet";
8
31
  export type TransactionVersion = "legacy" | "v0";
@@ -85,8 +108,22 @@ export interface FinalizeBuild extends CommonBuild {
85
108
  agent: string;
86
109
  client: string;
87
110
  treasury: string;
111
+ /** Optional true agent pubkey whose `AgentState` PDA is appended as remaining account `[5]`. */
112
+ agentStateOwner?: string;
113
+ /** Optional `extension-credit` backer pubkey to bundle atomic `route_and_recoup` after `finalize_task`. */
114
+ recoupBacker?: string;
115
+ /** Optional `extension-credit` recipient pubkey (defaults to `agentStateOwner ?? wallet`) for `route_and_recoup`. */
116
+ recoupRecipient?: string;
117
+ }
118
+ export interface ExpireBuild extends CommonBuild {
119
+ action: "expire";
120
+ taskPda: string;
121
+ /** Campaign client receiving the escrow refund (defaults to `wallet`). */
122
+ client?: string;
123
+ /** Optional claimed agent pubkey whose `AgentState` PDA is appended as remaining account `[3]`. */
124
+ claimedAgent?: string;
88
125
  }
89
- export type BuildRequest = CreateBuild | ClaimBuild | ApproveBuild | SubmitBuild | VerifyBuild | FinalizeBuild;
126
+ export type BuildRequest = CreateBuild | ClaimBuild | ApproveBuild | SubmitBuild | VerifyBuild | FinalizeBuild | ExpireBuild;
90
127
  export declare function buildInstruction(request: BuildRequest): TransactionInstruction;
91
128
  export declare function intentDigest(intent: Omit<TransactionIntent, "digest">): string;
92
129
  export declare function buildTransaction(request: BuildRequest): BuiltTransaction;
@@ -110,7 +147,8 @@ export declare const buildSubmit: (request: Omit<SubmitBuild, "action">) => Buil
110
147
  export declare const buildApprove: (request: Omit<ApproveBuild, "action">) => BuiltTransaction;
111
148
  export declare const buildVerify: (request: Omit<VerifyBuild, "action">) => BuiltTransaction;
112
149
  export declare const buildFinalize: (request: Omit<FinalizeBuild, "action">) => BuiltTransaction;
150
+ export declare const buildExpire: (request: Omit<ExpireBuild, "action">) => BuiltTransaction;
113
151
  export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
114
152
  export type { SwitchboardVerifyRequest } from "./switchboard.js";
115
153
  export * from "./payout-oracle.js";
116
- export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, } from "./verify-tx.js";
154
+ export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, } from "./verify-tx.js";
@@ -2,9 +2,60 @@ import { Buffer } from "buffer";
2
2
  import { sha256 } from "js-sha256";
3
3
  import { BN, SHILLBOT_PROGRAM_ID, agentStatePda, buildShillbotInstruction, clientStatePda, globalStatePda, shillbotInstructionDiscriminator, taskPda, } from "../contracts/index.js";
4
4
  import bs58 from "bs58";
5
- import { PublicKey, Transaction, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
5
+ import { PublicKey, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
6
6
  export { COORDINATION_GAME_IDL, COORDINATION_GAME_PROGRAM_ID, SHILLBOT_IDL, SHILLBOT_PROGRAM_ID, agentStatePda, buildShillbotInstruction, clientStatePda, globalStatePda, shillbotInstructionDiscriminator, taskPda, } from "../contracts/index.js";
7
7
  export const SCHEMA_VERSION = "swarm.shillbot.transaction-intent/v1";
8
+ export const EXTENSION_CREDIT_PROGRAM_ID = new PublicKey("Ec628D7GH3hwgnVf1gqrUh83qcZprYjmTzvtdHHEr7oh");
9
+ export function advancePda(backer, agent) {
10
+ return PublicKey.findProgramAddressSync([
11
+ Buffer.from("advance"),
12
+ new PublicKey(backer).toBuffer(),
13
+ new PublicKey(agent).toBuffer(),
14
+ ], EXTENSION_CREDIT_PROGRAM_ID)[0];
15
+ }
16
+ export function routeAndRecoupDiscriminator() {
17
+ return Buffer.from(sha256.arrayBuffer("global:route_and_recoup")).subarray(0, 8);
18
+ }
19
+ /** Exact Anchor account byte length of `extension-credit` `Advance` (`8 + 32 + 32 + 8 + 8 + 8 + 1 + 16 = 113`). */
20
+ export const ADVANCE_ACCOUNT_SPACE = 113;
21
+ export function advanceAccountDiscriminator() {
22
+ return Buffer.from(sha256.arrayBuffer("account:Advance")).subarray(0, 8);
23
+ }
24
+ /**
25
+ * Decode an on-chain `extension-credit` `Advance` account (`programs/extension-credit/src/state/advance.rs`).
26
+ * Returns `null` if the length (`113` bytes) or 8-byte Anchor discriminator (`account:Advance`) does not match.
27
+ */
28
+ export function decodeExtensionCreditAdvance(data) {
29
+ const buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
30
+ if (buf.length !== ADVANCE_ACCOUNT_SPACE) {
31
+ return null;
32
+ }
33
+ if (!buf.subarray(0, 8).equals(advanceAccountDiscriminator())) {
34
+ return null;
35
+ }
36
+ const backer = new PublicKey(buf.subarray(8, 40));
37
+ const recipient = new PublicKey(buf.subarray(40, 72));
38
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
39
+ const advanceLamports = view.getBigUint64(72, true);
40
+ const recoupedLamports = view.getBigUint64(80, true);
41
+ return {
42
+ backer,
43
+ recipient,
44
+ advanceLamports,
45
+ recoupedLamports,
46
+ };
47
+ }
48
+ export function buildRouteAndRecoupInstruction(accounts) {
49
+ return new TransactionInstruction({
50
+ programId: EXTENSION_CREDIT_PROGRAM_ID,
51
+ keys: [
52
+ { pubkey: new PublicKey(accounts.advance), isSigner: false, isWritable: true },
53
+ { pubkey: new PublicKey(accounts.backer), isSigner: false, isWritable: true },
54
+ { pubkey: new PublicKey(accounts.recipient), isSigner: false, isWritable: true },
55
+ ],
56
+ data: routeAndRecoupDiscriminator(),
57
+ });
58
+ }
8
59
  export function buildInstruction(request) {
9
60
  const wallet = new PublicKey(request.wallet);
10
61
  if (request.action === "create") {
@@ -77,8 +128,26 @@ export function buildInstruction(request) {
77
128
  },
78
129
  });
79
130
  }
131
+ if (request.action === "expire") {
132
+ const ix = buildShillbotInstruction({
133
+ name: "expire_task",
134
+ accounts: {
135
+ task,
136
+ global_state: globalStatePda(),
137
+ client: request.client ?? wallet,
138
+ },
139
+ });
140
+ if (request.claimedAgent) {
141
+ ix.keys.push({
142
+ pubkey: agentStatePda(new PublicKey(request.claimedAgent)),
143
+ isSigner: false,
144
+ isWritable: true,
145
+ });
146
+ }
147
+ return ix;
148
+ }
80
149
  const finalize = request;
81
- return buildShillbotInstruction({
150
+ const ix = buildShillbotInstruction({
82
151
  name: "finalize_task",
83
152
  accounts: {
84
153
  task,
@@ -88,6 +157,14 @@ export function buildInstruction(request) {
88
157
  treasury: finalize.treasury,
89
158
  },
90
159
  });
160
+ if (finalize.agentStateOwner) {
161
+ ix.keys.push({
162
+ pubkey: agentStatePda(new PublicKey(finalize.agentStateOwner)),
163
+ isSigner: false,
164
+ isWritable: true,
165
+ });
166
+ }
167
+ return ix;
91
168
  }
92
169
  function payoutInstruction(request) {
93
170
  if (!request.payoutTo)
@@ -115,7 +192,7 @@ export function intentDigest(intent) {
115
192
  function actionRisk(action) {
116
193
  if (action === "create")
117
194
  return "spend";
118
- if (action === "approve")
195
+ if (action === "approve" || action === "expire")
119
196
  return "escrow_control";
120
197
  return "earn";
121
198
  }
@@ -146,10 +223,20 @@ export function buildTransaction(request) {
146
223
  ? request.crankInstructions
147
224
  : request.action === "claim"
148
225
  ? [payoutInstruction(request)].filter((ix) => ix !== undefined)
149
- : [];
150
- // set_payout_to authorizes against task.agent, which claim_task establishes.
151
- // Keep the two operations atomic, but execute the claim first.
152
- const instructions = request.action === "claim"
226
+ : request.action === "finalize" && request.recoupBacker
227
+ ? [
228
+ buildRouteAndRecoupInstruction({
229
+ advance: request.agent,
230
+ backer: request.recoupBacker,
231
+ recipient: request.recoupRecipient ??
232
+ request.agentStateOwner ??
233
+ request.wallet,
234
+ }),
235
+ ]
236
+ : [];
237
+ // set_payout_to authorizes against task.agent (after claim_task), and
238
+ // route_and_recoup sweeps after finalize_task lands escrow in the Advance PDA.
239
+ const instructions = request.action === "claim" || request.action === "finalize"
153
240
  ? [lifecycle, ...companions]
154
241
  : [...companions, lifecycle];
155
242
  const unsignedTx = serializeUnsigned(payer, request.recentBlockhash, instructions, request.version ?? (request.action === "verify" ? "v0" : "legacy"));
@@ -269,12 +356,14 @@ export function verifyIntent(encoded, intent) {
269
356
  if (!inspected.signers.includes(intent.wallet))
270
357
  throw new Error("wallet is not a required signer");
271
358
  const shillbotProgramId = SHILLBOT_PROGRAM_ID.toBase58();
359
+ const extensionCreditId = EXTENSION_CREDIT_PROGRAM_ID.toBase58();
272
360
  const allowedPrograms = new Set([
273
361
  shillbotProgramId,
274
362
  COMPUTE_BUDGET_PROGRAM_ID,
275
363
  ...(intent.action === "verify"
276
364
  ? [SWITCHBOARD_PROGRAM_IDS[intent.network], SECP256K1_PROGRAM_ID]
277
365
  : []),
366
+ ...(intent.action === "finalize" ? [extensionCreditId] : []),
278
367
  ]);
279
368
  for (const ix of inspected.instructions) {
280
369
  if (!allowedPrograms.has(ix.program_id)) {
@@ -313,6 +402,23 @@ export function verifyIntent(encoded, intent) {
313
402
  .toString("hex"))) {
314
403
  throw new Error("unexpected Shillbot companion instruction");
315
404
  }
405
+ const creditInstructions = inspected.instructions.filter((ix) => ix.program_id === extensionCreditId);
406
+ if (creditInstructions.length > 0) {
407
+ if (intent.action !== "finalize" || creditInstructions.length !== 1) {
408
+ throw new Error("unexpected extension-credit companion instruction");
409
+ }
410
+ const creditIx = creditInstructions[0];
411
+ if (inspected.instructions.indexOf(creditIx) <= lifecycleIndex) {
412
+ throw new Error("route_and_recoup must follow finalize_task");
413
+ }
414
+ const creditData = Buffer.from(creditIx.data_base64, "base64");
415
+ if (creditData.length !== 8 ||
416
+ !creditData.equals(routeAndRecoupDiscriminator()) ||
417
+ creditIx.accounts.length !== 3 ||
418
+ creditIx.accounts[0] !== intent.accounts[2]) {
419
+ throw new Error("malformed route_and_recoup companion instruction");
420
+ }
421
+ }
316
422
  if (lifecycle[0].accounts.join(",") !== intent.accounts.join(",")) {
317
423
  throw new Error("lifecycle accounts differ from intent");
318
424
  }
@@ -371,7 +477,8 @@ export const buildSubmit = (request) => buildTransaction({ ...request, action: "
371
477
  export const buildApprove = (request) => buildTransaction({ ...request, action: "approve" });
372
478
  export const buildVerify = (request) => buildTransaction({ ...request, action: "verify" });
373
479
  export const buildFinalize = (request) => buildTransaction({ ...request, action: "finalize" });
480
+ export const buildExpire = (request) => buildTransaction({ ...request, action: "expire" });
374
481
  export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
375
482
  export * from "./payout-oracle.js";
376
483
  import { validateComputeBudgetInstructions } from "./verify-tx.js";
377
- export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
484
+ export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
@@ -1,4 +1,6 @@
1
- import { type Action, type Network, type TransactionInspection } from "./index.js";
1
+ import { advancePda, type Action, type Network, type TransactionInspection } from "./index.js";
2
+ /** Alias for `advancePda` (`seeds = [b"advance", sponsorPubkey, agentPubkey]`). */
3
+ export declare const deriveAdvancePda: typeof advancePda;
2
4
  /** Default maximum allowed Solana priority fee price per compute unit (`100_000` micro-lamports/CU). */
3
5
  export declare const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
4
6
  /** Solana runtime ceiling for `ComputeBudget::SetComputeUnitLimit` (`1_400_000` CUs). */
@@ -19,6 +21,7 @@ export interface ShillbotInstructionSpec {
19
21
  * derived directly from `programs/shillbot/src/instructions/*.rs` and `shillbot.json` IDL.
20
22
  */
21
23
  export declare const SHILLBOT_INSTRUCTION_SPECS: Readonly<Record<ShillbotInstructionName, ShillbotInstructionSpec>>;
24
+ export type ExpireTaskState = "open" | "claimed" | "submitted" | "approved";
22
25
  export interface VerifyBuiltTransactionExpectation {
23
26
  action?: Action;
24
27
  instructionName?: ShillbotInstructionName;
@@ -26,12 +29,21 @@ export interface VerifyBuiltTransactionExpectation {
26
29
  wallet: string;
27
30
  taskPda?: string;
28
31
  feePayer?: string;
32
+ /** Optional alias for `feePayer` when pinning a known gas sponsor pubkey. */
33
+ sponsor?: string;
29
34
  /**
30
35
  * Explicit authorized payout destination pubkey (base58).
31
- * Required whenever a `set_payout_to` instruction is present; otherwise any
32
- * `set_payout_to` instruction is rejected fail-closed.
36
+ * Required whenever a `set_payout_to` instruction is present on self-paid transactions;
37
+ * on sponsored `claim`/`submit` (`fee_payer !== wallet`), deterministic
38
+ * `advancePda(fee_payer, wallet)` is also authorized.
33
39
  */
34
40
  payoutTo?: string;
41
+ /**
42
+ * Optional task state when validating `expire_task`: enforces exact 3 accounts
43
+ * `[task, global_state, client]` on `open | submitted | approved` (rejecting the
44
+ * 4-account `AgentState` form) and exact 4 accounts on `claimed`.
45
+ */
46
+ expireTaskState?: ExpireTaskState;
35
47
  oracleAuthority?: string;
36
48
  escrowLamports?: bigint;
37
49
  contentId?: string;
@@ -52,7 +64,8 @@ export declare function validateComputeBudgetInstructions(instructions: Transact
52
64
  * Strict fail-closed local validator for built or server-prepared Shillbot Solana transactions.
53
65
  *
54
66
  * Enforces:
55
- * - Allowed program IDs (Shillbot + ComputeBudget, plus Switchboard + Secp256k1 only on `verify`).
67
+ * - Allowed program IDs (Shillbot + ComputeBudget, Switchboard + Secp256k1 on `verify` / score-0 reopen,
68
+ * and `extension-credit` `route_and_recoup` strictly on `finalize`).
56
69
  * - Full loop validation of all `ComputeBudget` instructions (no early return on `RequestHeapFrame`),
57
70
  * capping `SetComputeUnitPrice <= MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS` (`100_000` micro-lamports/CU).
58
71
  * - Exact Anchor account-index positions for `task` PDA and authority signer slots per discriminator.