@swarm-tips/client 0.4.7 → 0.4.9

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/SBOM.spdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "spdxVersion": "SPDX-2.3",
3
3
  "dataLicense": "CC0-1.0",
4
4
  "SPDXID": "SPDXRef-DOCUMENT",
5
- "name": "@swarm-tips/client-0.4.7",
6
- "documentNamespace": "https://swarm.tips/sbom/client/0.4.7",
5
+ "name": "@swarm-tips/client-0.4.9",
6
+ "documentNamespace": "https://swarm.tips/sbom/client/0.4.9",
7
7
  "creationInfo": {
8
- "created": "2026-11-17T05:34:07.531Z",
8
+ "created": "2026-11-26T07:16:02.960Z",
9
9
  "creators": [
10
10
  "Tool: sdk/client/scripts/generate-sbom.mjs",
11
11
  "Organization: Swarm Tips"
@@ -15,8 +15,8 @@
15
15
  {
16
16
  "name": "@swarm-tips/client",
17
17
  "SPDXID": "SPDXRef-Package",
18
- "versionInfo": "0.4.7",
19
- "downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.4.7",
18
+ "versionInfo": "0.4.9",
19
+ "downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.4.9",
20
20
  "filesAnalyzed": false,
21
21
  "licenseConcluded": "MIT",
22
22
  "licenseDeclared": "MIT"
package/dist/agent.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { Connection } from "@solana/web3.js";
2
2
  import { CoordinationGameApiClient } from "./coordination-game/api.js";
3
3
  import { type AckMessageResult, type InboxListOptions, type InboxListPage, type MessagePage, type MessageReference, type MuteReceipt, type OpenMessageResult, type PublishReceipt, type ReportReceipt, type SendReceipt, type TopicId, type TopicPage } from "./inbox/client.js";
4
- import { type CampaignListResponse, type PreparedTransactionResponse, type TaskListResponse } from "./shillbot/api.js";
4
+ import { type BuildVerifyResponse, type CampaignListResponse, type ListProofsOptions, type PreflightTaskResponse, type PreparedTransactionResponse, type ProofsResponse, type SubmitTaskRequest, type SubmitTaskResponse, type TaskListResponse } from "./shillbot/api.js";
5
5
  import type { SwarmSigner } from "./signer/types.js";
6
6
  import { type AgentJob, type AgentReputation, type EigenTrustRecord, type SearchHit } from "./swarm/index.js";
7
7
  import type { Verdict } from "./vow/types.js";
8
8
  export type SwarmNetwork = "mainnet" | "devnet";
9
9
  /** Default EVM gas price ceiling (`maxFeePerGas` = 50 gwei). */
10
10
  export declare const DEFAULT_MAX_NETWORK_FEE_WEI = 50000000000n;
11
- /** Recoupable SOL advance (`0.0031 SOL` = `3_100_000` lamports = `3_000_000` rent + `100_000` first-task gas budget) fronted by `/agent/onboard`. */
12
- export declare const ONBOARD_ADVANCE_LAMPORTS = 3100000;
13
- /** Minimum SOL balance (`0.003 SOL` = `3_000_000` lamports) required for self-paid `AgentState` initialization + lifecycle fees. */
14
- export declare const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS = 3000000;
11
+ /** Recoupable SOL advance (`0.0026 SOL` = `2_600_000` lamports) fronted by proof-gated onboarding / `/agent/onboard`. */
12
+ export declare const ONBOARD_ADVANCE_LAMPORTS = 2600000;
13
+ /** Minimum SOL balance (`0.00255 SOL` = `2_550_000` lamports) required for self-paid `AgentState` initialization + lifecycle fees. */
14
+ export declare const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS = 2550000;
15
15
  export interface SwarmAgentOptions {
16
16
  signer?: SwarmSigner;
17
17
  token?: string | (() => Promise<string | undefined>);
@@ -42,6 +42,21 @@ export interface ExecutedTaskResult<TConfirm = unknown> {
42
42
  signature: string;
43
43
  task_pda?: string;
44
44
  confirmation?: TConfirm;
45
+ attempt_id?: string;
46
+ open_competition?: boolean;
47
+ status?: string;
48
+ onboarded_advance_tx?: string | null;
49
+ }
50
+ export interface PreflightTaskOptions {
51
+ proof_lean?: string;
52
+ proofLean?: string;
53
+ compile?: boolean;
54
+ content_id?: string;
55
+ contentId?: string;
56
+ agent_wallet?: string;
57
+ agentWallet?: string;
58
+ network?: SwarmNetwork;
59
+ token?: string | null;
45
60
  }
46
61
  export interface ExecuteTaskOptions {
47
62
  sponsor?: "auto" | "true" | "none";
@@ -52,6 +67,14 @@ export interface ExecuteTaskOptions {
52
67
  feePayer?: string;
53
68
  /** Explicit authorized payout destination pubkey (base58) when `set_payout_to` is expected. */
54
69
  payoutTo?: string;
70
+ /** Optional inline Lean 4 proof source forwarded as `proof_lean` on `POST /tasks/:id/submit`. */
71
+ proofLean?: string;
72
+ /** Optional self-reported prover harness tag forwarded on `POST /tasks/:id/submit`. */
73
+ agentHarness?: string;
74
+ /** Optional self-reported model family tag forwarded on `POST /tasks/:id/submit`. */
75
+ modelFamily?: string;
76
+ /** Optional Open-Competition (`M2`) attempt ID forwarded on `POST /tasks/:id/build-verify`. */
77
+ attemptId?: string;
55
78
  extra?: Record<string, unknown>;
56
79
  }
57
80
  /**
@@ -113,13 +136,17 @@ export declare class SwarmAgent {
113
136
  onboard: <TResponse = unknown>() => Promise<TResponse>;
114
137
  claim: (id: string, sponsor?: string) => Promise<PreparedTransactionResponse>;
115
138
  claimAndExecute: (id: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
116
- submit: (id: string, body: unknown) => Promise<PreparedTransactionResponse>;
117
- preflight: <TResponse = unknown>(id: string, body?: unknown) => Promise<TResponse>;
118
- submitAndExecute: (id: string, contentId: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
119
- buildVerify: (id: string) => Promise<PreparedTransactionResponse>;
120
- verifyAndExecute: (id: string, opts?: {
121
- connection?: Connection;
122
- payoutTo?: string;
139
+ submit: (id: string, body: SubmitTaskRequest | Record<string, unknown>) => Promise<SubmitTaskResponse>;
140
+ preflight: <TResponse = PreflightTaskResponse>(id: string, opts?: PreflightTaskOptions) => Promise<TResponse>;
141
+ submitAndExecute: (id: string, contentId?: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
142
+ buildVerify: (id: string, opts?: {
143
+ attemptId?: string;
144
+ }) => Promise<BuildVerifyResponse>;
145
+ verify: (id: string, opts?: ExecuteTaskOptions & {
146
+ attemptId?: string;
147
+ }) => Promise<ExecutedTaskResult>;
148
+ verifyAndExecute: (id: string, opts?: ExecuteTaskOptions & {
149
+ attemptId?: string;
123
150
  }) => Promise<ExecutedTaskResult>;
124
151
  buildFinalize: (id: string) => Promise<PreparedTransactionResponse>;
125
152
  finalizeAndExecute: (id: string, opts?: {
@@ -139,6 +166,9 @@ export declare class SwarmAgent {
139
166
  allowLocalhostHttp?: boolean;
140
167
  }) => Promise<Verdict>;
141
168
  };
169
+ readonly proofs: {
170
+ list: (opts?: ListProofsOptions) => Promise<ProofsResponse>;
171
+ };
142
172
  readonly campaigns: {
143
173
  list: <TCampaign = unknown>() => Promise<CampaignListResponse<TCampaign> | TCampaign[]>;
144
174
  get: <TCampaign = unknown>(id: string) => Promise<TCampaign>;
@@ -207,25 +237,29 @@ export declare class SwarmAgent {
207
237
  }) => Promise<T>;
208
238
  };
209
239
  constructor(options?: SwarmAgentOptions);
210
- /** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`3_100_000` lamports). */
240
+ /** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`2_600_000` lamports). */
211
241
  onboard<TResponse = unknown>(): Promise<TResponse>;
212
242
  /** Claim a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
213
243
  claimTask(id: string, opts?: ExecuteTaskOptions): Promise<ExecutedTaskResult>;
214
- /** Submit work for a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
215
- submitWork(id: string, contentId: string, opts?: ExecuteTaskOptions): Promise<ExecutedTaskResult>;
244
+ /** Submit work for a task and execute the prepared transaction (or return immediately on M2 202 Accepted open competition). */
245
+ submitWork(id: string, contentId?: string, opts?: ExecuteTaskOptions): Promise<ExecutedTaskResult>;
246
+ /** Build, locally validate, sign, broadcast, and confirm a task verification transaction (including M2 1-tx Open->Verified bundles). */
247
+ verifyTask(id: string, opts?: ExecuteTaskOptions & {
248
+ attemptId?: string;
249
+ }): Promise<ExecutedTaskResult>;
216
250
  private requireSigner;
217
251
  private executeClaimOrSubmit;
218
252
  /**
219
253
  * Resolve an authorized `payoutTo` pubkey (`P1-2` / `HIGH-02`):
220
254
  * - If caller explicitly passed `explicitPayoutTo`, return it verbatim.
221
- * - Otherwise, NEVER trust `advance_backer` from the API response alone:
222
- * 1. Verify `advancePda(advance_backer, walletAddress) === prepared.payout_to`.
223
- * 2. Fetch the PDA on-chain via `connection.getAccountInfo(derived, "confirmed")` and require:
255
+ * - Otherwise, NEVER trust `advance_backer` or `required_payout_to` from the API response alone:
256
+ * 1. When `advance_backer` is provided, verify `advancePda(advance_backer, walletAddress) === candidatePayoutTo`.
257
+ * 2. Fetch the PDA on-chain via `connection.getAccountInfo(candidatePk, "confirmed")` and require:
224
258
  * - account exists (`acct !== null && acct.lamports > 0`),
225
259
  * - `acct.owner.equals(EXTENSION_CREDIT_PROGRAM_ID)`,
226
260
  * - valid 113-byte `Advance` account (`sha256("account:Advance")[0..8]`) with
227
- * `backer === advance_backer`, `recipient === walletAddress`, and
228
- * `recouped_lamports < advance_lamports`.
261
+ * `recipient === walletAddress`, canonical `advancePda(decoded.backer, walletAddress) === candidatePk`,
262
+ * `backer === advance_backer` (when provided), and `recouped_lamports < advance_lamports`.
229
263
  * 3. On any mismatch or RPC error, return `undefined` so `validatePreparedTransaction`
230
264
  * rejects any `set_payout_to` fail-closed.
231
265
  */
package/dist/agent.js CHANGED
@@ -10,10 +10,10 @@ import { SwarmClient, } from "./swarm/index.js";
10
10
  import { verifyVow } from "./vow/verify.js";
11
11
  /** Default EVM gas price ceiling (`maxFeePerGas` = 50 gwei). */
12
12
  export const DEFAULT_MAX_NETWORK_FEE_WEI = 50000000000n;
13
- /** Recoupable SOL advance (`0.0031 SOL` = `3_100_000` lamports = `3_000_000` rent + `100_000` first-task gas budget) fronted by `/agent/onboard`. */
14
- export const ONBOARD_ADVANCE_LAMPORTS = 3_100_000;
15
- /** Minimum SOL balance (`0.003 SOL` = `3_000_000` lamports) required for self-paid `AgentState` initialization + lifecycle fees. */
16
- export const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS = 3_000_000;
13
+ /** Recoupable SOL advance (`0.0026 SOL` = `2_600_000` lamports) fronted by proof-gated onboarding / `/agent/onboard`. */
14
+ export const ONBOARD_ADVANCE_LAMPORTS = 2_600_000;
15
+ /** Minimum SOL balance (`0.00255 SOL` = `2_550_000` lamports) required for self-paid `AgentState` initialization + lifecycle fees. */
16
+ export const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS = 2_550_000;
17
17
  /** Minimum SOL balance (`50_000` lamports) required for standalone post-claim `submit_work` fee payment. */
18
18
  const MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS = 50_000;
19
19
  const DEFAULT_SOLANA_RPC = {
@@ -117,6 +117,7 @@ export class SwarmAgent {
117
117
  auth;
118
118
  discovery;
119
119
  tasks;
120
+ proofs;
120
121
  campaigns;
121
122
  inbox;
122
123
  topics;
@@ -216,20 +217,36 @@ export class SwarmAgent {
216
217
  claim: (id, sponsor = "auto") => self.shillbotClient.claimTask(id, sponsor),
217
218
  claimAndExecute: (id, opts) => self.executeClaimOrSubmit(id, "claim", undefined, opts),
218
219
  submit: (id, body) => self.shillbotClient.submitTask(id, body),
219
- preflight: (id, body) => self.shillbotClient.preflightTask(id, body),
220
+ preflight(id, opts) {
221
+ const body = {};
222
+ const proofLean = opts?.proof_lean ?? opts?.proofLean;
223
+ const contentId = opts?.content_id ?? opts?.contentId;
224
+ const agentWallet = opts?.agent_wallet ?? opts?.agentWallet;
225
+ if (proofLean !== undefined)
226
+ body.proof_lean = proofLean;
227
+ if (opts?.compile !== undefined)
228
+ body.compile = opts.compile;
229
+ if (contentId !== undefined)
230
+ body.content_id = contentId;
231
+ if (agentWallet !== undefined)
232
+ body.agent_wallet = agentWallet;
233
+ const callOpts = opts?.network !== undefined || opts?.token !== undefined
234
+ ? {
235
+ ...(opts.network !== undefined ? { network: opts.network } : {}),
236
+ ...(opts.token !== undefined ? { token: opts.token } : {}),
237
+ }
238
+ : undefined;
239
+ return self.shillbotClient.preflightTask(id, body, callOpts);
240
+ },
220
241
  submitAndExecute: (id, contentId, opts) => self.executeClaimOrSubmit(id, "submit", contentId, opts),
221
- buildVerify: (id) => self.shillbotClient.buildVerify(id, {
242
+ buildVerify: (id, opts) => self.shillbotClient.buildVerify(id, {
222
243
  payer: self.auth.walletAddress,
223
244
  mcpBaseUrl: self.mcpUrl,
224
245
  network: self.network,
246
+ ...(opts?.attemptId ? { attemptId: opts.attemptId } : {}),
225
247
  }),
226
- async verifyAndExecute(id, opts) {
227
- const prepared = await self.tasks.buildVerify(id);
228
- return self.executePreparedAction(id, "verify", prepared, {
229
- connection: opts?.connection,
230
- payoutTo: opts?.payoutTo,
231
- });
232
- },
248
+ verify: (id, opts) => self.verifyTask(id, opts),
249
+ verifyAndExecute: (id, opts) => self.verifyTask(id, opts),
233
250
  buildFinalize: (id) => self.shillbotClient.buildFinalize(id),
234
251
  async finalizeAndExecute(id, opts) {
235
252
  const prepared = await self.tasks.buildFinalize(id);
@@ -260,6 +277,9 @@ export class SwarmAgent {
260
277
  });
261
278
  },
262
279
  };
280
+ this.proofs = {
281
+ list: (opts) => self.shillbotClient.listProofs(opts),
282
+ };
263
283
  this.campaigns = {
264
284
  list: () => self.shillbotClient.listCampaigns(),
265
285
  get: (id) => self.shillbotClient.campaign(id),
@@ -347,7 +367,7 @@ export class SwarmAgent {
347
367
  },
348
368
  };
349
369
  }
350
- /** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`3_100_000` lamports). */
370
+ /** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`2_600_000` lamports). */
351
371
  onboard() {
352
372
  return this.shillbotClient.onboard();
353
373
  }
@@ -355,10 +375,19 @@ export class SwarmAgent {
355
375
  claimTask(id, opts) {
356
376
  return this.executeClaimOrSubmit(id, "claim", undefined, opts);
357
377
  }
358
- /** Submit work for a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
378
+ /** Submit work for a task and execute the prepared transaction (or return immediately on M2 202 Accepted open competition). */
359
379
  submitWork(id, contentId, opts) {
360
380
  return this.executeClaimOrSubmit(id, "submit", contentId, opts);
361
381
  }
382
+ /** Build, locally validate, sign, broadcast, and confirm a task verification transaction (including M2 1-tx Open->Verified bundles). */
383
+ async verifyTask(id, opts) {
384
+ const prepared = await this.tasks.buildVerify(id, opts?.attemptId ? { attemptId: opts.attemptId } : undefined);
385
+ return this.executePreparedAction(id, "verify", prepared, {
386
+ connection: opts?.connection,
387
+ feePayer: opts?.feePayer,
388
+ payoutTo: opts?.payoutTo,
389
+ });
390
+ }
362
391
  requireSigner() {
363
392
  if (!this.signer) {
364
393
  throw new SwarmClientError({
@@ -378,7 +407,25 @@ export class SwarmAgent {
378
407
  return this.shillbotClient.claimTask(id, query);
379
408
  }
380
409
  const suffix = sponsorMode !== "none" ? `?sponsor=${encodeURIComponent(query)}` : "";
381
- return this.shillbotClient.post(`/tasks/${encodeURIComponent(id)}/submit${suffix}`, { content_id: contentId, ...(opts?.extra ?? {}) });
410
+ const payload = {
411
+ ...(opts?.extra ?? {}),
412
+ };
413
+ if (opts?.proofLean !== undefined && payload.proof_lean === undefined) {
414
+ payload.proof_lean = opts.proofLean;
415
+ }
416
+ if (contentId !== undefined && contentId !== "") {
417
+ payload.content_id = contentId;
418
+ }
419
+ else if (payload.content_id === undefined && payload.proof_lean === undefined) {
420
+ payload.content_id = contentId ?? "";
421
+ }
422
+ if (opts?.agentHarness && payload.agent_harness === undefined) {
423
+ payload.agent_harness = opts.agentHarness;
424
+ }
425
+ if (opts?.modelFamily && payload.model_family === undefined) {
426
+ payload.model_family = opts.modelFamily;
427
+ }
428
+ return this.shillbotClient.post(`/tasks/${encodeURIComponent(id)}/submit${suffix}`, payload);
382
429
  };
383
430
  let prepared;
384
431
  try {
@@ -401,10 +448,23 @@ export class SwarmAgent {
401
448
  throw err;
402
449
  }
403
450
  }
451
+ // M2 Open-Competition off-chain submission (`202 Accepted`, $0 gas):
452
+ // return immediately without calling RPC, signing, broadcasting, or auto-onboarding prematurely.
453
+ if (action === "submit" &&
454
+ (prepared.open_competition === true || (!prepared.transaction && Boolean(prepared.attempt_id)))) {
455
+ return {
456
+ task_id: prepared.task_id ?? id,
457
+ signature: "",
458
+ ...(prepared.task_pda ? { task_pda: prepared.task_pda } : {}),
459
+ attempt_id: prepared.attempt_id,
460
+ open_competition: true,
461
+ status: prepared.status ?? "verifying",
462
+ };
463
+ }
404
464
  const connection = this.signer?.chain === "solana"
405
465
  ? (opts?.connection ?? new Connection(this.rpcUrl, "confirmed"))
406
466
  : opts?.connection;
407
- // When a Solana wallet holds less than MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS (3_000_000 lamports
467
+ // When a Solana wallet holds less than MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS (2_550_000 lamports
408
468
  // for claim / atomic claim+submit) or MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS (50_000 lamports
409
469
  // for standalone submit) and receives a self-paid HTTP 200 transaction, onboard once and re-request.
410
470
  if (prepared.transaction &&
@@ -491,14 +551,14 @@ export class SwarmAgent {
491
551
  /**
492
552
  * Resolve an authorized `payoutTo` pubkey (`P1-2` / `HIGH-02`):
493
553
  * - If caller explicitly passed `explicitPayoutTo`, return it verbatim.
494
- * - Otherwise, NEVER trust `advance_backer` from the API response alone:
495
- * 1. Verify `advancePda(advance_backer, walletAddress) === prepared.payout_to`.
496
- * 2. Fetch the PDA on-chain via `connection.getAccountInfo(derived, "confirmed")` and require:
554
+ * - Otherwise, NEVER trust `advance_backer` or `required_payout_to` from the API response alone:
555
+ * 1. When `advance_backer` is provided, verify `advancePda(advance_backer, walletAddress) === candidatePayoutTo`.
556
+ * 2. Fetch the PDA on-chain via `connection.getAccountInfo(candidatePk, "confirmed")` and require:
497
557
  * - account exists (`acct !== null && acct.lamports > 0`),
498
558
  * - `acct.owner.equals(EXTENSION_CREDIT_PROGRAM_ID)`,
499
559
  * - valid 113-byte `Advance` account (`sha256("account:Advance")[0..8]`) with
500
- * `backer === advance_backer`, `recipient === walletAddress`, and
501
- * `recouped_lamports < advance_lamports`.
560
+ * `recipient === walletAddress`, canonical `advancePda(decoded.backer, walletAddress) === candidatePk`,
561
+ * `backer === advance_backer` (when provided), and `recouped_lamports < advance_lamports`.
502
562
  * 3. On any mismatch or RPC error, return `undefined` so `validatePreparedTransaction`
503
563
  * rejects any `set_payout_to` fail-closed.
504
564
  */
@@ -506,17 +566,26 @@ export class SwarmAgent {
506
566
  if (explicitPayoutTo !== undefined) {
507
567
  return explicitPayoutTo;
508
568
  }
509
- if (!walletAddress || !prepared.payout_to || !prepared.advance_backer) {
569
+ const candidatePayoutTo = prepared.payout_to ?? prepared.required_payout_to ?? undefined;
570
+ if (!walletAddress || !candidatePayoutTo) {
510
571
  return undefined;
511
572
  }
512
573
  try {
513
- const expectedBacker = new PublicKey(prepared.advance_backer);
514
574
  const expectedRecipient = new PublicKey(walletAddress);
515
- const derived = advancePda(expectedBacker, expectedRecipient);
516
- if (derived.toBase58() !== prepared.payout_to) {
517
- return undefined;
575
+ let expectedBacker;
576
+ let candidatePk;
577
+ if (prepared.advance_backer) {
578
+ expectedBacker = new PublicKey(prepared.advance_backer);
579
+ const derived = advancePda(expectedBacker, expectedRecipient);
580
+ if (derived.toBase58() !== candidatePayoutTo) {
581
+ return undefined;
582
+ }
583
+ candidatePk = derived;
584
+ }
585
+ else {
586
+ candidatePk = new PublicKey(candidatePayoutTo);
518
587
  }
519
- const acct = await connection.getAccountInfo(derived, "confirmed");
588
+ const acct = await connection.getAccountInfo(candidatePk, "confirmed");
520
589
  if (!acct || acct.lamports <= 0) {
521
590
  return undefined;
522
591
  }
@@ -527,13 +596,16 @@ export class SwarmAgent {
527
596
  if (!decoded) {
528
597
  return undefined;
529
598
  }
530
- if (!decoded.backer.equals(expectedBacker) ||
531
- !decoded.recipient.equals(expectedRecipient) ||
599
+ if (expectedBacker && !decoded.backer.equals(expectedBacker)) {
600
+ return undefined;
601
+ }
602
+ if (!decoded.recipient.equals(expectedRecipient) ||
603
+ !advancePda(decoded.backer, expectedRecipient).equals(candidatePk) ||
532
604
  decoded.advanceLamports === 0n ||
533
605
  decoded.recoupedLamports >= decoded.advanceLamports) {
534
606
  return undefined;
535
607
  }
536
- return derived.toBase58();
608
+ return candidatePk.toBase58();
537
609
  }
538
610
  catch {
539
611
  return undefined;
@@ -613,7 +685,8 @@ export class SwarmAgent {
613
685
  };
614
686
  }
615
687
  async executeSolanaAction(id, action, prepared, signer, opts) {
616
- if (!prepared.transaction) {
688
+ const encodedTx = prepared.transaction || prepared.co_signed_transaction || "";
689
+ if (!encodedTx) {
617
690
  throw new SwarmClientError({
618
691
  code: "INVALID_RESPONSE",
619
692
  operation: `tasks.${action}AndExecute`,
@@ -621,7 +694,7 @@ export class SwarmAgent {
621
694
  });
622
695
  }
623
696
  if (action === "create") {
624
- const txEscrow = extractCreateEscrowLamports(prepared.transaction);
697
+ const txEscrow = extractCreateEscrowLamports(encodedTx);
625
698
  if (txEscrow !== undefined && txEscrow > this.maxEscrowSpendLamports) {
626
699
  throw new SwarmClientError({
627
700
  code: "SPEND_CAP_EXCEEDED",
@@ -633,7 +706,7 @@ export class SwarmAgent {
633
706
  // C9 Network Fee Cap check first so fee cap breaches report SPEND_CAP_EXCEEDED
634
707
  let preInspected;
635
708
  try {
636
- preInspected = inspectTransaction(prepared.transaction);
709
+ preInspected = inspectTransaction(encodedTx);
637
710
  }
638
711
  catch (err) {
639
712
  throw new SwarmClientError({
@@ -665,10 +738,10 @@ export class SwarmAgent {
665
738
  ? { escrowLamports: opts.expectedEscrowLamports }
666
739
  : {}),
667
740
  };
668
- validatePreparedTransaction(prepared.transaction, expected);
741
+ validatePreparedTransaction(encodedTx, expected);
669
742
  const signature = await signBroadcastPreparedTransaction({
670
743
  connection,
671
- transaction: prepared.transaction,
744
+ transaction: encodedTx,
672
745
  expected,
673
746
  sign: (tx) => signer.signTransaction(tx),
674
747
  });
@@ -682,15 +755,39 @@ export class SwarmAgent {
682
755
  signature,
683
756
  task_pda: prepared.task_pda,
684
757
  confirmation,
758
+ ...(prepared.attempt_id !== undefined ? { attempt_id: prepared.attempt_id } : {}),
759
+ ...(prepared.onboarded_advance_tx !== undefined
760
+ ? { onboarded_advance_tx: prepared.onboarded_advance_tx }
761
+ : {}),
685
762
  };
686
763
  }
687
764
  static adviseNextAction(task, nowMs = Date.now()) {
688
765
  const rawState = String(task.state ?? task.status ?? "").trim().toLowerCase();
689
766
  const rawPlatform = task.platform;
690
- const isOnChainAction = rawPlatform === 11 ||
691
- (typeof rawPlatform === "string" && rawPlatform.trim().toLowerCase() === "onchain_action");
767
+ const normalizedPlatform = typeof rawPlatform === "string" ? rawPlatform.trim().toLowerCase() : undefined;
768
+ const isOpenCompetition = rawPlatform === 10 ||
769
+ rawPlatform === 11 ||
770
+ normalizedPlatform === "10" ||
771
+ normalizedPlatform === "11" ||
772
+ normalizedPlatform === "lean_proof" ||
773
+ normalizedPlatform === "onchain_action";
692
774
  if (rawState === "open") {
693
- return { step: isOnChainAction ? "submit" : "claim" };
775
+ if (isOpenCompetition) {
776
+ const latestAttempt = task.my_latest_attempt && typeof task.my_latest_attempt === "object"
777
+ ? task.my_latest_attempt
778
+ : undefined;
779
+ const attemptStatus = typeof latestAttempt?.status === "string"
780
+ ? latestAttempt.status.trim().toLowerCase()
781
+ : "";
782
+ if (attemptStatus === "passed") {
783
+ return { step: "verify" };
784
+ }
785
+ if (attemptStatus === "verifying") {
786
+ return { step: "wait_attestation" };
787
+ }
788
+ return { step: "submit" };
789
+ }
790
+ return { step: "claim" };
694
791
  }
695
792
  if (rawState === "claimed") {
696
793
  return { step: "submit" };
@@ -0,0 +1,39 @@
1
+ import type { ProofLimits } from "../shillbot/api.js";
2
+ export declare const DEFAULT_LEAN_TOOLCHAINS: Readonly<Record<number, string>>;
3
+ export declare const DEFAULT_MATHLIB_REV_V2_V3 = "c5ea00351c28e24afc9f0f84379aa41082b1188f";
4
+ export declare const DEFAULT_MATHLIB_REV_V4 = "51e6992efd06126df61a496bebf8f49482a4e129";
5
+ export declare const DEFAULT_ZETA23_REV_V4 = "3635e74826a4c1fcece7d1cd2b6fa75e43a00510";
6
+ export interface LeanWorkspaceSpec {
7
+ task_id: string;
8
+ statement_lean: string;
9
+ lean_policy: number;
10
+ lean_toolchain: string;
11
+ mode: string;
12
+ mathlib_rev?: string;
13
+ zeta23_rev?: string;
14
+ swarm_proofs_rev?: string;
15
+ import_allowlist: string[];
16
+ allows_disproof: boolean;
17
+ limits: ProofLimits;
18
+ }
19
+ export interface ScaffoldLeanWorkspaceResult {
20
+ ok: true;
21
+ task_id: string;
22
+ dir: string;
23
+ lean_policy: number;
24
+ lean_toolchain: string;
25
+ allows_disproof: boolean;
26
+ limits: ProofLimits;
27
+ files: string[];
28
+ }
29
+ export declare function extractLeanWorkspaceSpec(task: Record<string, unknown>, taskId: string): LeanWorkspaceSpec;
30
+ /**
31
+ * Pure helper generating the complete Lean 4 workspace file map for a
32
+ * `platform === 10` task without touching the filesystem.
33
+ */
34
+ export declare function buildLeanWorkspaceFiles(task: Record<string, unknown>, taskId: string): Record<string, string>;
35
+ /**
36
+ * Materialize a Lean 4 prover workspace on disk. Refuses to overwrite any
37
+ * existing non-empty target file unless `force === true`.
38
+ */
39
+ export declare function scaffoldLeanWorkspace(task: Record<string, unknown>, taskId: string, targetDir: string, force?: boolean): ScaffoldLeanWorkspaceResult;