@swarm-tips/client 0.4.8 → 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 +5 -5
- package/dist/agent.d.ts +35 -19
- package/dist/agent.js +101 -38
- package/dist/cli/swarm.js +50 -20
- package/dist/index.d.ts +1 -1
- package/dist/shillbot/api.d.ts +32 -6
- package/dist/shillbot/api.js +71 -25
- package/dist/shillbot/verify-tx.js +109 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
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.
|
|
6
|
-
"documentNamespace": "https://swarm.tips/sbom/client/0.4.
|
|
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-
|
|
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.
|
|
19
|
-
"downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.4.
|
|
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 ListProofsOptions, type PreflightTaskResponse, type PreparedTransactionResponse, type ProofsResponse, type SubmitTaskRequest, 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.
|
|
12
|
-
export declare const ONBOARD_ADVANCE_LAMPORTS =
|
|
13
|
-
/** Minimum SOL balance (`0.
|
|
14
|
-
export declare const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS =
|
|
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,10 @@ 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;
|
|
45
49
|
}
|
|
46
50
|
export interface PreflightTaskOptions {
|
|
47
51
|
proof_lean?: string;
|
|
@@ -63,10 +67,14 @@ export interface ExecuteTaskOptions {
|
|
|
63
67
|
feePayer?: string;
|
|
64
68
|
/** Explicit authorized payout destination pubkey (base58) when `set_payout_to` is expected. */
|
|
65
69
|
payoutTo?: string;
|
|
70
|
+
/** Optional inline Lean 4 proof source forwarded as `proof_lean` on `POST /tasks/:id/submit`. */
|
|
71
|
+
proofLean?: string;
|
|
66
72
|
/** Optional self-reported prover harness tag forwarded on `POST /tasks/:id/submit`. */
|
|
67
73
|
agentHarness?: string;
|
|
68
74
|
/** Optional self-reported model family tag forwarded on `POST /tasks/:id/submit`. */
|
|
69
75
|
modelFamily?: string;
|
|
76
|
+
/** Optional Open-Competition (`M2`) attempt ID forwarded on `POST /tasks/:id/build-verify`. */
|
|
77
|
+
attemptId?: string;
|
|
70
78
|
extra?: Record<string, unknown>;
|
|
71
79
|
}
|
|
72
80
|
/**
|
|
@@ -128,13 +136,17 @@ export declare class SwarmAgent {
|
|
|
128
136
|
onboard: <TResponse = unknown>() => Promise<TResponse>;
|
|
129
137
|
claim: (id: string, sponsor?: string) => Promise<PreparedTransactionResponse>;
|
|
130
138
|
claimAndExecute: (id: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
|
|
131
|
-
submit: (id: string, body: SubmitTaskRequest | Record<string, unknown>) => Promise<
|
|
139
|
+
submit: (id: string, body: SubmitTaskRequest | Record<string, unknown>) => Promise<SubmitTaskResponse>;
|
|
132
140
|
preflight: <TResponse = PreflightTaskResponse>(id: string, opts?: PreflightTaskOptions) => Promise<TResponse>;
|
|
133
|
-
submitAndExecute: (id: string, contentId
|
|
134
|
-
buildVerify: (id: string
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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;
|
|
138
150
|
}) => Promise<ExecutedTaskResult>;
|
|
139
151
|
buildFinalize: (id: string) => Promise<PreparedTransactionResponse>;
|
|
140
152
|
finalizeAndExecute: (id: string, opts?: {
|
|
@@ -225,25 +237,29 @@ export declare class SwarmAgent {
|
|
|
225
237
|
}) => Promise<T>;
|
|
226
238
|
};
|
|
227
239
|
constructor(options?: SwarmAgentOptions);
|
|
228
|
-
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`
|
|
240
|
+
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`2_600_000` lamports). */
|
|
229
241
|
onboard<TResponse = unknown>(): Promise<TResponse>;
|
|
230
242
|
/** Claim a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
|
|
231
243
|
claimTask(id: string, opts?: ExecuteTaskOptions): Promise<ExecutedTaskResult>;
|
|
232
|
-
/** Submit work for a task and execute the prepared transaction (
|
|
233
|
-
submitWork(id: string, contentId
|
|
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>;
|
|
234
250
|
private requireSigner;
|
|
235
251
|
private executeClaimOrSubmit;
|
|
236
252
|
/**
|
|
237
253
|
* Resolve an authorized `payoutTo` pubkey (`P1-2` / `HIGH-02`):
|
|
238
254
|
* - If caller explicitly passed `explicitPayoutTo`, return it verbatim.
|
|
239
|
-
* - Otherwise, NEVER trust `advance_backer` from the API response alone:
|
|
240
|
-
* 1.
|
|
241
|
-
* 2. Fetch the PDA on-chain via `connection.getAccountInfo(
|
|
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:
|
|
242
258
|
* - account exists (`acct !== null && acct.lamports > 0`),
|
|
243
259
|
* - `acct.owner.equals(EXTENSION_CREDIT_PROGRAM_ID)`,
|
|
244
260
|
* - valid 113-byte `Advance` account (`sha256("account:Advance")[0..8]`) with
|
|
245
|
-
* `
|
|
246
|
-
* `recouped_lamports < advance_lamports`.
|
|
261
|
+
* `recipient === walletAddress`, canonical `advancePda(decoded.backer, walletAddress) === candidatePk`,
|
|
262
|
+
* `backer === advance_backer` (when provided), and `recouped_lamports < advance_lamports`.
|
|
247
263
|
* 3. On any mismatch or RPC error, return `undefined` so `validatePreparedTransaction`
|
|
248
264
|
* rejects any `set_payout_to` fail-closed.
|
|
249
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.
|
|
14
|
-
export const ONBOARD_ADVANCE_LAMPORTS =
|
|
15
|
-
/** Minimum SOL balance (`0.
|
|
16
|
-
export const MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS =
|
|
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 = {
|
|
@@ -239,18 +239,14 @@ export class SwarmAgent {
|
|
|
239
239
|
return self.shillbotClient.preflightTask(id, body, callOpts);
|
|
240
240
|
},
|
|
241
241
|
submitAndExecute: (id, contentId, opts) => self.executeClaimOrSubmit(id, "submit", contentId, opts),
|
|
242
|
-
buildVerify: (id) => self.shillbotClient.buildVerify(id, {
|
|
242
|
+
buildVerify: (id, opts) => self.shillbotClient.buildVerify(id, {
|
|
243
243
|
payer: self.auth.walletAddress,
|
|
244
244
|
mcpBaseUrl: self.mcpUrl,
|
|
245
245
|
network: self.network,
|
|
246
|
+
...(opts?.attemptId ? { attemptId: opts.attemptId } : {}),
|
|
246
247
|
}),
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return self.executePreparedAction(id, "verify", prepared, {
|
|
250
|
-
connection: opts?.connection,
|
|
251
|
-
payoutTo: opts?.payoutTo,
|
|
252
|
-
});
|
|
253
|
-
},
|
|
248
|
+
verify: (id, opts) => self.verifyTask(id, opts),
|
|
249
|
+
verifyAndExecute: (id, opts) => self.verifyTask(id, opts),
|
|
254
250
|
buildFinalize: (id) => self.shillbotClient.buildFinalize(id),
|
|
255
251
|
async finalizeAndExecute(id, opts) {
|
|
256
252
|
const prepared = await self.tasks.buildFinalize(id);
|
|
@@ -371,7 +367,7 @@ export class SwarmAgent {
|
|
|
371
367
|
},
|
|
372
368
|
};
|
|
373
369
|
}
|
|
374
|
-
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`
|
|
370
|
+
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`2_600_000` lamports). */
|
|
375
371
|
onboard() {
|
|
376
372
|
return this.shillbotClient.onboard();
|
|
377
373
|
}
|
|
@@ -379,10 +375,19 @@ export class SwarmAgent {
|
|
|
379
375
|
claimTask(id, opts) {
|
|
380
376
|
return this.executeClaimOrSubmit(id, "claim", undefined, opts);
|
|
381
377
|
}
|
|
382
|
-
/** Submit work for a task and execute the prepared transaction (
|
|
378
|
+
/** Submit work for a task and execute the prepared transaction (or return immediately on M2 202 Accepted open competition). */
|
|
383
379
|
submitWork(id, contentId, opts) {
|
|
384
380
|
return this.executeClaimOrSubmit(id, "submit", contentId, opts);
|
|
385
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
|
+
}
|
|
386
391
|
requireSigner() {
|
|
387
392
|
if (!this.signer) {
|
|
388
393
|
throw new SwarmClientError({
|
|
@@ -403,9 +408,17 @@ export class SwarmAgent {
|
|
|
403
408
|
}
|
|
404
409
|
const suffix = sponsorMode !== "none" ? `?sponsor=${encodeURIComponent(query)}` : "";
|
|
405
410
|
const payload = {
|
|
406
|
-
content_id: contentId ?? "",
|
|
407
411
|
...(opts?.extra ?? {}),
|
|
408
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
|
+
}
|
|
409
422
|
if (opts?.agentHarness && payload.agent_harness === undefined) {
|
|
410
423
|
payload.agent_harness = opts.agentHarness;
|
|
411
424
|
}
|
|
@@ -435,10 +448,23 @@ export class SwarmAgent {
|
|
|
435
448
|
throw err;
|
|
436
449
|
}
|
|
437
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
|
+
}
|
|
438
464
|
const connection = this.signer?.chain === "solana"
|
|
439
465
|
? (opts?.connection ?? new Connection(this.rpcUrl, "confirmed"))
|
|
440
466
|
: opts?.connection;
|
|
441
|
-
// When a Solana wallet holds less than MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS (
|
|
467
|
+
// When a Solana wallet holds less than MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS (2_550_000 lamports
|
|
442
468
|
// for claim / atomic claim+submit) or MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS (50_000 lamports
|
|
443
469
|
// for standalone submit) and receives a self-paid HTTP 200 transaction, onboard once and re-request.
|
|
444
470
|
if (prepared.transaction &&
|
|
@@ -525,14 +551,14 @@ export class SwarmAgent {
|
|
|
525
551
|
/**
|
|
526
552
|
* Resolve an authorized `payoutTo` pubkey (`P1-2` / `HIGH-02`):
|
|
527
553
|
* - If caller explicitly passed `explicitPayoutTo`, return it verbatim.
|
|
528
|
-
* - Otherwise, NEVER trust `advance_backer` from the API response alone:
|
|
529
|
-
* 1.
|
|
530
|
-
* 2. Fetch the PDA on-chain via `connection.getAccountInfo(
|
|
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:
|
|
531
557
|
* - account exists (`acct !== null && acct.lamports > 0`),
|
|
532
558
|
* - `acct.owner.equals(EXTENSION_CREDIT_PROGRAM_ID)`,
|
|
533
559
|
* - valid 113-byte `Advance` account (`sha256("account:Advance")[0..8]`) with
|
|
534
|
-
* `
|
|
535
|
-
* `recouped_lamports < advance_lamports`.
|
|
560
|
+
* `recipient === walletAddress`, canonical `advancePda(decoded.backer, walletAddress) === candidatePk`,
|
|
561
|
+
* `backer === advance_backer` (when provided), and `recouped_lamports < advance_lamports`.
|
|
536
562
|
* 3. On any mismatch or RPC error, return `undefined` so `validatePreparedTransaction`
|
|
537
563
|
* rejects any `set_payout_to` fail-closed.
|
|
538
564
|
*/
|
|
@@ -540,17 +566,26 @@ export class SwarmAgent {
|
|
|
540
566
|
if (explicitPayoutTo !== undefined) {
|
|
541
567
|
return explicitPayoutTo;
|
|
542
568
|
}
|
|
543
|
-
|
|
569
|
+
const candidatePayoutTo = prepared.payout_to ?? prepared.required_payout_to ?? undefined;
|
|
570
|
+
if (!walletAddress || !candidatePayoutTo) {
|
|
544
571
|
return undefined;
|
|
545
572
|
}
|
|
546
573
|
try {
|
|
547
|
-
const expectedBacker = new PublicKey(prepared.advance_backer);
|
|
548
574
|
const expectedRecipient = new PublicKey(walletAddress);
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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);
|
|
552
587
|
}
|
|
553
|
-
const acct = await connection.getAccountInfo(
|
|
588
|
+
const acct = await connection.getAccountInfo(candidatePk, "confirmed");
|
|
554
589
|
if (!acct || acct.lamports <= 0) {
|
|
555
590
|
return undefined;
|
|
556
591
|
}
|
|
@@ -561,13 +596,16 @@ export class SwarmAgent {
|
|
|
561
596
|
if (!decoded) {
|
|
562
597
|
return undefined;
|
|
563
598
|
}
|
|
564
|
-
if (!decoded.backer.equals(expectedBacker)
|
|
565
|
-
|
|
599
|
+
if (expectedBacker && !decoded.backer.equals(expectedBacker)) {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
if (!decoded.recipient.equals(expectedRecipient) ||
|
|
603
|
+
!advancePda(decoded.backer, expectedRecipient).equals(candidatePk) ||
|
|
566
604
|
decoded.advanceLamports === 0n ||
|
|
567
605
|
decoded.recoupedLamports >= decoded.advanceLamports) {
|
|
568
606
|
return undefined;
|
|
569
607
|
}
|
|
570
|
-
return
|
|
608
|
+
return candidatePk.toBase58();
|
|
571
609
|
}
|
|
572
610
|
catch {
|
|
573
611
|
return undefined;
|
|
@@ -647,7 +685,8 @@ export class SwarmAgent {
|
|
|
647
685
|
};
|
|
648
686
|
}
|
|
649
687
|
async executeSolanaAction(id, action, prepared, signer, opts) {
|
|
650
|
-
|
|
688
|
+
const encodedTx = prepared.transaction || prepared.co_signed_transaction || "";
|
|
689
|
+
if (!encodedTx) {
|
|
651
690
|
throw new SwarmClientError({
|
|
652
691
|
code: "INVALID_RESPONSE",
|
|
653
692
|
operation: `tasks.${action}AndExecute`,
|
|
@@ -655,7 +694,7 @@ export class SwarmAgent {
|
|
|
655
694
|
});
|
|
656
695
|
}
|
|
657
696
|
if (action === "create") {
|
|
658
|
-
const txEscrow = extractCreateEscrowLamports(
|
|
697
|
+
const txEscrow = extractCreateEscrowLamports(encodedTx);
|
|
659
698
|
if (txEscrow !== undefined && txEscrow > this.maxEscrowSpendLamports) {
|
|
660
699
|
throw new SwarmClientError({
|
|
661
700
|
code: "SPEND_CAP_EXCEEDED",
|
|
@@ -667,7 +706,7 @@ export class SwarmAgent {
|
|
|
667
706
|
// C9 Network Fee Cap check first so fee cap breaches report SPEND_CAP_EXCEEDED
|
|
668
707
|
let preInspected;
|
|
669
708
|
try {
|
|
670
|
-
preInspected = inspectTransaction(
|
|
709
|
+
preInspected = inspectTransaction(encodedTx);
|
|
671
710
|
}
|
|
672
711
|
catch (err) {
|
|
673
712
|
throw new SwarmClientError({
|
|
@@ -699,10 +738,10 @@ export class SwarmAgent {
|
|
|
699
738
|
? { escrowLamports: opts.expectedEscrowLamports }
|
|
700
739
|
: {}),
|
|
701
740
|
};
|
|
702
|
-
validatePreparedTransaction(
|
|
741
|
+
validatePreparedTransaction(encodedTx, expected);
|
|
703
742
|
const signature = await signBroadcastPreparedTransaction({
|
|
704
743
|
connection,
|
|
705
|
-
transaction:
|
|
744
|
+
transaction: encodedTx,
|
|
706
745
|
expected,
|
|
707
746
|
sign: (tx) => signer.signTransaction(tx),
|
|
708
747
|
});
|
|
@@ -716,15 +755,39 @@ export class SwarmAgent {
|
|
|
716
755
|
signature,
|
|
717
756
|
task_pda: prepared.task_pda,
|
|
718
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
|
+
: {}),
|
|
719
762
|
};
|
|
720
763
|
}
|
|
721
764
|
static adviseNextAction(task, nowMs = Date.now()) {
|
|
722
765
|
const rawState = String(task.state ?? task.status ?? "").trim().toLowerCase();
|
|
723
766
|
const rawPlatform = task.platform;
|
|
724
|
-
const
|
|
725
|
-
|
|
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";
|
|
726
774
|
if (rawState === "open") {
|
|
727
|
-
|
|
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" };
|
|
728
791
|
}
|
|
729
792
|
if (rawState === "claimed") {
|
|
730
793
|
return { step: "submit" };
|
package/dist/cli/swarm.js
CHANGED
|
@@ -110,8 +110,8 @@ Commands:
|
|
|
110
110
|
tasks init <id> [--dir <path>] [--force] (scaffold pinned Lean 4 workspace — zero auth / zero SOL)
|
|
111
111
|
tasks check <id> <proof-file> [--compile] (static or remote compile preflight with diagnostics & compression metrics)
|
|
112
112
|
tasks claim <id> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
113
|
-
tasks submit <id> (--content <str> | --proof-file <path>) [--harness <name>] [--model <name>] [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
114
|
-
tasks verify <id> [--no-exec]
|
|
113
|
+
tasks submit <id> ([<content_id>] | --content <str> | --proof-file <path> | --proof-lean <src>) [--harness <name>] [--model <name>] [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
114
|
+
tasks verify <id> [--attempt-id <id>] [--payout-to <pubkey>] [--no-exec]
|
|
115
115
|
tasks finalize <id> [--no-exec]
|
|
116
116
|
tasks expire <id> [--no-exec] (client escrow refund past claim/submit deadline or past submitted_at + verification_timeout)
|
|
117
117
|
proofs list [--limit N] [--policy N] (public verified Lean 4 proofs & prover leaderboard)
|
|
@@ -506,12 +506,16 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
506
506
|
}
|
|
507
507
|
if (sub === "submit") {
|
|
508
508
|
const id = rest[0]?.trim();
|
|
509
|
-
const content = getStringFlag(flags, "--content");
|
|
509
|
+
const content = getStringFlag(flags, "--content") ?? rest[1];
|
|
510
510
|
const proofFile = getStringFlag(flags, "--proof-file");
|
|
511
|
+
const inlineProofLean = getStringFlag(flags, "--proof-lean");
|
|
511
512
|
const harness = getStringFlag(flags, "--harness");
|
|
512
513
|
const model = getStringFlag(flags, "--model");
|
|
513
|
-
if (
|
|
514
|
-
throw new CliUsageError("
|
|
514
|
+
if (proofFile && inlineProofLean !== undefined) {
|
|
515
|
+
throw new CliUsageError("Specify either --proof-file or --proof-lean, not both.");
|
|
516
|
+
}
|
|
517
|
+
if (!id || (!content && !proofFile && inlineProofLean === undefined)) {
|
|
518
|
+
throw new CliUsageError("Usage: swarm tasks submit <task_id> ([<content_id>] | --content <str> | --proof-file <path> | --proof-lean <src>) [--harness <name>] [--model <name>] [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]");
|
|
515
519
|
}
|
|
516
520
|
let proofLean;
|
|
517
521
|
if (proofFile) {
|
|
@@ -525,8 +529,23 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
525
529
|
throw new CliUsageError(`Proof file ${proofFile} is empty.`);
|
|
526
530
|
}
|
|
527
531
|
}
|
|
532
|
+
else if (inlineProofLean !== undefined) {
|
|
533
|
+
if (!inlineProofLean.trim()) {
|
|
534
|
+
throw new CliUsageError("Flag --proof-lean must not be empty.");
|
|
535
|
+
}
|
|
536
|
+
proofLean = inlineProofLean;
|
|
537
|
+
}
|
|
528
538
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
529
539
|
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
540
|
+
const formatOpenCompetitionHuman = (res) => {
|
|
541
|
+
const targetId = res.task_id ?? id;
|
|
542
|
+
const attemptPart = res.attempt_id ? ` --attempt-id ${res.attempt_id}` : "";
|
|
543
|
+
stdout.write([
|
|
544
|
+
`Accepted (Open Competition — $0 gas) — task ${targetId}`,
|
|
545
|
+
`Attempt ID: ${res.attempt_id ?? "pending"} | Status: ${res.status ?? "verifying"}`,
|
|
546
|
+
`Next: poll \`swarm tasks get ${targetId}\`, then run \`swarm tasks verify ${targetId}${attemptPart}\` once passed.`,
|
|
547
|
+
].join("\n") + "\n");
|
|
548
|
+
};
|
|
530
549
|
if (noExec) {
|
|
531
550
|
const submitBody = {
|
|
532
551
|
content_id: content ?? "",
|
|
@@ -535,34 +554,45 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
535
554
|
...(model ? { model_family: model } : {}),
|
|
536
555
|
};
|
|
537
556
|
const res = await agent.tasks.submit(id, submitBody);
|
|
538
|
-
|
|
557
|
+
if (!jsonMode && res.open_competition === true) {
|
|
558
|
+
formatOpenCompetitionHuman(res);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
writeOutput(stdout, jsonMode, res);
|
|
562
|
+
}
|
|
539
563
|
return 0;
|
|
540
564
|
}
|
|
541
|
-
const
|
|
542
|
-
...(proofLean !== undefined ? { proof_lean: proofLean } : {}),
|
|
543
|
-
...(harness ? { agent_harness: harness } : {}),
|
|
544
|
-
...(model ? { model_family: model } : {}),
|
|
545
|
-
};
|
|
546
|
-
const execOpts = payoutTo || feePayer || harness || model || Object.keys(extra).length > 0
|
|
565
|
+
const execOpts = payoutTo || feePayer || harness || model || proofLean !== undefined
|
|
547
566
|
? {
|
|
548
567
|
...(payoutTo ? { payoutTo } : {}),
|
|
549
568
|
...(feePayer ? { feePayer } : {}),
|
|
569
|
+
...(proofLean !== undefined ? { proofLean } : {}),
|
|
550
570
|
...(harness ? { agentHarness: harness } : {}),
|
|
551
571
|
...(model ? { modelFamily: model } : {}),
|
|
552
|
-
...(Object.keys(extra).length > 0 ? { extra } : {}),
|
|
553
572
|
}
|
|
554
573
|
: undefined;
|
|
555
|
-
const res = await agent.tasks.submitAndExecute(id, content
|
|
556
|
-
|
|
574
|
+
const res = await agent.tasks.submitAndExecute(id, content, execOpts);
|
|
575
|
+
if (!jsonMode && res.open_competition === true) {
|
|
576
|
+
formatOpenCompetitionHuman(res);
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
writeOutput(stdout, jsonMode, res);
|
|
580
|
+
}
|
|
557
581
|
return 0;
|
|
558
582
|
}
|
|
559
583
|
if (sub === "verify") {
|
|
560
|
-
const id = rest[0];
|
|
561
|
-
if (!id)
|
|
562
|
-
throw new CliUsageError("Usage: swarm tasks verify <task_id> [--no-exec]");
|
|
584
|
+
const id = rest[0]?.trim();
|
|
585
|
+
if (!id) {
|
|
586
|
+
throw new CliUsageError("Usage: swarm tasks verify <task_id> [--attempt-id <id>] [--payout-to <pubkey>] [--no-exec]");
|
|
587
|
+
}
|
|
588
|
+
const attemptId = getStringFlag(flags, "--attempt-id")?.trim() || undefined;
|
|
589
|
+
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
590
|
+
const verifyOpts = attemptId || payoutTo
|
|
591
|
+
? { ...(attemptId ? { attemptId } : {}), ...(payoutTo ? { payoutTo } : {}) }
|
|
592
|
+
: undefined;
|
|
563
593
|
const res = noExec
|
|
564
|
-
? await agent.tasks.buildVerify(id)
|
|
565
|
-
: await agent.tasks.verifyAndExecute(id);
|
|
594
|
+
? await agent.tasks.buildVerify(id, attemptId ? { attemptId } : undefined)
|
|
595
|
+
: await agent.tasks.verifyAndExecute(id, verifyOpts);
|
|
566
596
|
writeOutput(stdout, jsonMode, res);
|
|
567
597
|
return 0;
|
|
568
598
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { SwarmClientErrorCode, SwarmClientErrorOptions } from "./errors.js"
|
|
|
6
6
|
export { DEFAULT_MAX_NETWORK_FEE_WEI, MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS, ONBOARD_ADVANCE_LAMPORTS, SwarmAgent, createSwarmAgent, extractCreateEscrowLamports, type ExecuteTaskOptions, type ExecutedTaskResult, type NextTaskAction, type PreflightTaskOptions, type SwarmAgentOptions, type SwarmNetwork, type TaskLifecycleStep, } from "./agent.js";
|
|
7
7
|
export { WalletTokenManager, type TokenProvider, type WalletTokenManagerOptions, } from "./auth/token-manager.js";
|
|
8
8
|
export { fromEvmPrivateKey, fromEvmWalletClient, fromSolanaKeypair, fromSolanaSecretKey, fromSolanaWalletAdapter, redactSigner, type EvmCallRequest, type EvmPrivateKeyOptions, type EvmSwarmSigner, type EvmTransactionSigner, type EvmWalletClientLike, type SolanaSwarmSigner, type SolanaWalletAdapterLike, type SwarmSigner, } from "./signer/index.js";
|
|
9
|
-
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, SHILLBOT_INSTRUCTION_SPECS, buildOnChainActionProofRef, deriveAdvancePda, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, normalizeEvmChainId, validateComputeBudgetInstruction, validateComputeBudgetInstructions, validatePreparedEvmCall, validatePreparedTransaction, verifyBuiltTransaction, type AuthoritySlotRule, type BuildOnChainActionProofRefParams, type BuildVerifyOptions, type ExpireTaskState, type LeanDiagnostic, type LeanEnvironmentInfo, type ListProofsOptions, type PreflightTaskRequest, type PreflightTaskResponse, type PreparedEvmCallExpectation, type PreparedTransactionExpectation, type PreparedTransactionResponse, type ProofLimits, type ProofMetrics, type ProofsLeaderboardEntry, type ProofsResponse, type ShillbotInstructionName, type ShillbotInstructionSpec, type SubmitTaskRequest, type TaskResponse, type ValidatedEvmCall, type VerificationDataResponse, type VerifiedProofRecord, type VerifyBuiltTransactionExpectation, } from "./shillbot/api.js";
|
|
9
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_ESCROW_DEPLOYMENTS, SHILLBOT_EVM_SELECTORS, SHILLBOT_INSTRUCTION_SPECS, buildOnChainActionProofRef, deriveAdvancePda, estimateSolanaNetworkFeeLamports, formatOnChainActionAttributionMessage, normalizeEvmChainId, validateComputeBudgetInstruction, validateComputeBudgetInstructions, validatePreparedEvmCall, validatePreparedTransaction, verifyBuiltTransaction, type AuthoritySlotRule, type BuildOnChainActionProofRefParams, type BuildVerifyOptions, type BuildVerifyResponse, type ExpireTaskState, type LeanDiagnostic, type LeanEnvironmentInfo, type ListProofsOptions, type PreflightTaskRequest, type PreflightTaskResponse, type PreparedEvmCallExpectation, type PreparedTransactionExpectation, type PreparedTransactionResponse, type ProofLimits, type ProofMetrics, type ProofsLeaderboardEntry, type ProofsResponse, type ShillbotInstructionName, type ShillbotInstructionSpec, type SubmitTaskRequest, type SubmitTaskResponse, type TaskAttemptSummary, type TaskResponse, type ValidatedEvmCall, type VerificationDataResponse, type VerifiedProofRecord, type VerifyBuiltTransactionExpectation, } from "./shillbot/api.js";
|
|
10
10
|
export { ADVANCE_ACCOUNT_SPACE, EXTENSION_CREDIT_PROGRAM_ID, advanceAccountDiscriminator, advancePda, decodeExtensionCreditAdvance, type DecodedAdvanceAccount, } from "./shillbot/index.js";
|
|
11
11
|
export { VALID_TOPICS, isValidTopicId, type TopicId, } from "./inbox/types.js";
|
|
12
12
|
export { DEFAULT_MAX_VOW_BYTES, fetchVowAttestationJson, validateVowUrl, verifyVow, type FetchVowOptions, type VerifyVowOptions, } from "./vow/verify.js";
|
package/dist/shillbot/api.d.ts
CHANGED
|
@@ -5,13 +5,21 @@ export type { Action } from "./index.js";
|
|
|
5
5
|
export interface PreparedTransactionResponse {
|
|
6
6
|
message?: string;
|
|
7
7
|
task_id?: string;
|
|
8
|
-
transaction
|
|
8
|
+
transaction?: string;
|
|
9
9
|
task_pda?: string;
|
|
10
10
|
transaction_intent?: TransactionIntent;
|
|
11
11
|
evm_call?: unknown;
|
|
12
12
|
payout_to?: string;
|
|
13
13
|
advance_backer?: string;
|
|
14
|
+
attempt_id?: string;
|
|
15
|
+
open_competition?: boolean;
|
|
16
|
+
status?: string;
|
|
17
|
+
onboarded_advance_tx?: string | null;
|
|
18
|
+
required_payout_to?: string | null;
|
|
19
|
+
co_signed_transaction?: string | null;
|
|
14
20
|
}
|
|
21
|
+
export type SubmitTaskResponse = PreparedTransactionResponse;
|
|
22
|
+
export type BuildVerifyResponse = PreparedTransactionResponse;
|
|
15
23
|
export interface VerificationDataResponse {
|
|
16
24
|
task_id?: string;
|
|
17
25
|
task_pda: string;
|
|
@@ -19,16 +27,19 @@ export interface VerificationDataResponse {
|
|
|
19
27
|
verification_hash: string;
|
|
20
28
|
global_state?: string;
|
|
21
29
|
switchboard_feed: string;
|
|
22
|
-
required_payout_to?: string;
|
|
23
|
-
advance_backer?: string;
|
|
30
|
+
required_payout_to?: string | null;
|
|
31
|
+
advance_backer?: string | null;
|
|
24
32
|
verification_kind?: number;
|
|
25
|
-
co_signed_transaction?: string;
|
|
33
|
+
co_signed_transaction?: string | null;
|
|
26
34
|
evm_verify_call?: unknown;
|
|
35
|
+
attempt_id?: string;
|
|
36
|
+
onboarded_advance_tx?: string | null;
|
|
27
37
|
}
|
|
28
38
|
export interface BuildVerifyOptions {
|
|
29
39
|
payer?: string;
|
|
30
40
|
mcpBaseUrl?: string;
|
|
31
41
|
network?: "mainnet" | "devnet";
|
|
42
|
+
attemptId?: string;
|
|
32
43
|
}
|
|
33
44
|
export interface ConfirmTransactionRequest {
|
|
34
45
|
tx_signature: string;
|
|
@@ -49,6 +60,19 @@ export interface LeanEnvironmentInfo {
|
|
|
49
60
|
max_proof_bytes?: number | null;
|
|
50
61
|
max_line_width?: number | null;
|
|
51
62
|
}
|
|
63
|
+
export interface TaskAttemptSummary {
|
|
64
|
+
attempt_id: string;
|
|
65
|
+
task_id?: string;
|
|
66
|
+
agent?: string;
|
|
67
|
+
status: string;
|
|
68
|
+
score?: number | null;
|
|
69
|
+
check_detail?: string | null;
|
|
70
|
+
content_id?: string | null;
|
|
71
|
+
artifact_hash?: string | null;
|
|
72
|
+
submitted_at_unix?: number | null;
|
|
73
|
+
verified_at?: string | null;
|
|
74
|
+
updated_at?: string | null;
|
|
75
|
+
}
|
|
52
76
|
export interface TaskResponse {
|
|
53
77
|
task_id: string;
|
|
54
78
|
campaign_id?: string;
|
|
@@ -73,6 +97,8 @@ export interface TaskResponse {
|
|
|
73
97
|
lean_policy?: number | null;
|
|
74
98
|
lean_environment?: LeanEnvironmentInfo | null;
|
|
75
99
|
check_detail?: string | null;
|
|
100
|
+
competing_attempts_count?: number | null;
|
|
101
|
+
my_latest_attempt?: TaskAttemptSummary | null;
|
|
76
102
|
brief?: unknown;
|
|
77
103
|
[key: string]: unknown;
|
|
78
104
|
}
|
|
@@ -219,8 +245,8 @@ export declare class ShillbotApiClient {
|
|
|
219
245
|
}): Promise<TResponse>;
|
|
220
246
|
listProofs<TResponse = ProofsResponse>(opts?: ListProofsOptions): Promise<TResponse>;
|
|
221
247
|
approveTask(id: string): Promise<PreparedTransactionResponse>;
|
|
222
|
-
getVerificationData(id: string, network?: "mainnet" | "devnet"): Promise<VerificationDataResponse>;
|
|
223
|
-
buildVerify(id: string,
|
|
248
|
+
getVerificationData(id: string, network?: "mainnet" | "devnet", attemptId?: string): Promise<VerificationDataResponse>;
|
|
249
|
+
buildVerify(id: string, optsOrAttemptId?: BuildVerifyOptions | string): Promise<BuildVerifyResponse>;
|
|
224
250
|
buildFinalize(id: string): Promise<PreparedTransactionResponse>;
|
|
225
251
|
buildExpire(id: string): Promise<PreparedTransactionResponse>;
|
|
226
252
|
confirmTask<TResponse = unknown>(id: string, body: ConfirmTransactionRequest): Promise<TResponse>;
|
package/dist/shillbot/api.js
CHANGED
|
@@ -126,15 +126,27 @@ export class ShillbotApiClient {
|
|
|
126
126
|
approveTask(id) {
|
|
127
127
|
return this.post(`/tasks/${encodeURIComponent(id)}/approve`);
|
|
128
128
|
}
|
|
129
|
-
getVerificationData(id, network) {
|
|
130
|
-
const
|
|
129
|
+
getVerificationData(id, network, attemptId) {
|
|
130
|
+
const params = [];
|
|
131
|
+
if (network && network !== "mainnet") {
|
|
132
|
+
params.push(`network=${encodeURIComponent(network)}`);
|
|
133
|
+
}
|
|
134
|
+
const trimmedAttempt = attemptId?.trim();
|
|
135
|
+
if (trimmedAttempt) {
|
|
136
|
+
params.push(`attempt_id=${encodeURIComponent(trimmedAttempt)}`);
|
|
137
|
+
}
|
|
138
|
+
const suffix = params.length > 0 ? `?${params.join("&")}` : "";
|
|
131
139
|
return this.post(`/tasks/${encodeURIComponent(id)}/build-verify${suffix}`);
|
|
132
140
|
}
|
|
133
|
-
async buildVerify(id,
|
|
141
|
+
async buildVerify(id, optsOrAttemptId) {
|
|
142
|
+
const opts = typeof optsOrAttemptId === "string"
|
|
143
|
+
? { attemptId: optsOrAttemptId }
|
|
144
|
+
: optsOrAttemptId;
|
|
134
145
|
const mcpBaseUrl = (opts?.mcpBaseUrl ?? "https://mcp.swarm.tips").replace(/\/$/, "");
|
|
135
146
|
const resolvedNetwork = opts?.network ?? (this.http.network === "devnet" ? "devnet" : "mainnet");
|
|
136
147
|
const token = await this.http.getToken?.();
|
|
137
148
|
const payer = opts?.payer ?? decodeJwtWallet(token);
|
|
149
|
+
const attemptId = opts?.attemptId?.trim() || undefined;
|
|
138
150
|
const postMcpBuildVerify = async (payload) => {
|
|
139
151
|
const mcpHttp = new HttpClient({
|
|
140
152
|
baseUrl: mcpBaseUrl,
|
|
@@ -143,6 +155,59 @@ export class ShillbotApiClient {
|
|
|
143
155
|
});
|
|
144
156
|
return mcpHttp.post("/internal/build-verify-tx", payload);
|
|
145
157
|
};
|
|
158
|
+
const normalizePrepared = (raw, fallbackTaskPda) => {
|
|
159
|
+
const resolvedTx = raw.transaction || raw.co_signed_transaction || "";
|
|
160
|
+
const resolvedPayoutTo = raw.payout_to ?? raw.required_payout_to ?? undefined;
|
|
161
|
+
return {
|
|
162
|
+
...raw,
|
|
163
|
+
task_id: raw.task_id ?? id,
|
|
164
|
+
transaction: resolvedTx,
|
|
165
|
+
task_pda: raw.task_pda ?? fallbackTaskPda,
|
|
166
|
+
transaction_intent: raw.transaction_intent,
|
|
167
|
+
...(resolvedPayoutTo ? { payout_to: resolvedPayoutTo } : {}),
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const formatVerificationData = (vdata) => ({
|
|
171
|
+
task_id: vdata.task_id ?? id,
|
|
172
|
+
transaction: vdata.co_signed_transaction ?? "",
|
|
173
|
+
task_pda: vdata.task_pda,
|
|
174
|
+
...(vdata.evm_verify_call !== undefined ? { evm_call: vdata.evm_verify_call } : {}),
|
|
175
|
+
...(vdata.required_payout_to
|
|
176
|
+
? {
|
|
177
|
+
payout_to: vdata.required_payout_to,
|
|
178
|
+
required_payout_to: vdata.required_payout_to,
|
|
179
|
+
}
|
|
180
|
+
: {}),
|
|
181
|
+
...(vdata.advance_backer ? { advance_backer: vdata.advance_backer } : {}),
|
|
182
|
+
...(vdata.co_signed_transaction
|
|
183
|
+
? { co_signed_transaction: vdata.co_signed_transaction }
|
|
184
|
+
: {}),
|
|
185
|
+
...(vdata.attempt_id ? { attempt_id: vdata.attempt_id } : {}),
|
|
186
|
+
...(vdata.onboarded_advance_tx !== undefined
|
|
187
|
+
? { onboarded_advance_tx: vdata.onboarded_advance_tx }
|
|
188
|
+
: {}),
|
|
189
|
+
});
|
|
190
|
+
// When targeting a specific M2 Open-Competition attemptId, call shillbot-api
|
|
191
|
+
// `POST /tasks/:id/build-verify?attempt_id=...` directly (returns `co_signed_transaction`
|
|
192
|
+
// + proof-gated `onboarded_advance_tx` + `required_payout_to` in 1 hop).
|
|
193
|
+
if (attemptId) {
|
|
194
|
+
const vdata = await this.getVerificationData(id, resolvedNetwork, attemptId);
|
|
195
|
+
if (vdata.evm_verify_call || vdata.co_signed_transaction) {
|
|
196
|
+
return formatVerificationData(vdata);
|
|
197
|
+
}
|
|
198
|
+
const fallback = await postMcpBuildVerify({
|
|
199
|
+
task_id: id,
|
|
200
|
+
...(payer ? { payer } : {}),
|
|
201
|
+
network: resolvedNetwork,
|
|
202
|
+
attempt_id: attemptId,
|
|
203
|
+
task_pda: vdata.task_pda,
|
|
204
|
+
score: vdata.composite_score,
|
|
205
|
+
hash: vdata.verification_hash,
|
|
206
|
+
feed: vdata.switchboard_feed,
|
|
207
|
+
...(vdata.global_state ? { global_state: vdata.global_state } : {}),
|
|
208
|
+
});
|
|
209
|
+
return normalizePrepared(fallback, vdata.task_pda);
|
|
210
|
+
}
|
|
146
211
|
const oneHopBody = {
|
|
147
212
|
task_id: id,
|
|
148
213
|
network: resolvedNetwork,
|
|
@@ -150,13 +215,7 @@ export class ShillbotApiClient {
|
|
|
150
215
|
};
|
|
151
216
|
try {
|
|
152
217
|
const direct = await postMcpBuildVerify(oneHopBody);
|
|
153
|
-
return
|
|
154
|
-
...direct,
|
|
155
|
-
task_id: direct.task_id ?? id,
|
|
156
|
-
transaction: direct.transaction,
|
|
157
|
-
task_pda: direct.task_pda,
|
|
158
|
-
transaction_intent: direct.transaction_intent,
|
|
159
|
-
};
|
|
218
|
+
return normalizePrepared(direct);
|
|
160
219
|
}
|
|
161
220
|
catch (err) {
|
|
162
221
|
if (!(err instanceof SwarmClientError) ||
|
|
@@ -166,14 +225,7 @@ export class ShillbotApiClient {
|
|
|
166
225
|
}
|
|
167
226
|
const vdata = await this.getVerificationData(id, resolvedNetwork);
|
|
168
227
|
if (vdata.evm_verify_call || vdata.co_signed_transaction) {
|
|
169
|
-
return
|
|
170
|
-
task_id: vdata.task_id ?? id,
|
|
171
|
-
transaction: vdata.co_signed_transaction ?? "",
|
|
172
|
-
task_pda: vdata.task_pda,
|
|
173
|
-
...(vdata.evm_verify_call !== undefined ? { evm_call: vdata.evm_verify_call } : {}),
|
|
174
|
-
...(vdata.required_payout_to ? { payout_to: vdata.required_payout_to } : {}),
|
|
175
|
-
...(vdata.advance_backer ? { advance_backer: vdata.advance_backer } : {}),
|
|
176
|
-
};
|
|
228
|
+
return formatVerificationData(vdata);
|
|
177
229
|
}
|
|
178
230
|
const fallback = await postMcpBuildVerify({
|
|
179
231
|
task_id: id,
|
|
@@ -185,13 +237,7 @@ export class ShillbotApiClient {
|
|
|
185
237
|
feed: vdata.switchboard_feed,
|
|
186
238
|
...(vdata.global_state ? { global_state: vdata.global_state } : {}),
|
|
187
239
|
});
|
|
188
|
-
return
|
|
189
|
-
...fallback,
|
|
190
|
-
task_id: fallback.task_id ?? id,
|
|
191
|
-
transaction: fallback.transaction,
|
|
192
|
-
task_pda: fallback.task_pda ?? vdata.task_pda,
|
|
193
|
-
transaction_intent: fallback.transaction_intent,
|
|
194
|
-
};
|
|
240
|
+
return normalizePrepared(fallback, vdata.task_pda);
|
|
195
241
|
}
|
|
196
242
|
}
|
|
197
243
|
buildFinalize(id) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { ComputeBudgetProgram, PublicKey, Secp256k1Program } from "@solana/web3.js";
|
|
2
|
+
import { ComputeBudgetProgram, PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, Secp256k1Program, } from "@solana/web3.js";
|
|
3
3
|
import { SHILLBOT_PROGRAM_ID, shillbotInstructionDiscriminator } from "../contracts/index.js";
|
|
4
4
|
import { SwarmClientError, TransactionMismatchError } from "../errors.js";
|
|
5
5
|
import { EXTENSION_CREDIT_PROGRAM_ID, advancePda, inspectTransaction, routeAndRecoupDiscriminator, } from "./index.js";
|
|
@@ -9,6 +9,8 @@ export const deriveAdvancePda = advancePda;
|
|
|
9
9
|
export const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
|
|
10
10
|
/** Solana runtime ceiling for `ComputeBudget::SetComputeUnitLimit` (`1_400_000` CUs). */
|
|
11
11
|
export const MAX_COMPUTE_UNIT_LIMIT = 1_400_000;
|
|
12
|
+
/** Full passing composite score (`1_000_000`) required on M2 Open-Competition 1-tx verify bundles. */
|
|
13
|
+
const MAX_VERIFY_SCORE = 1000000n;
|
|
12
14
|
const MIN_HEAP_FRAME_BYTES = 32 * 1024;
|
|
13
15
|
const MAX_HEAP_FRAME_BYTES = 256 * 1024;
|
|
14
16
|
const SWITCHBOARD_PROGRAM_IDS = {
|
|
@@ -707,6 +709,112 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
707
709
|
validateSetPayoutToInstruction(companions[0], expected.wallet, primary.ix.accounts[0], expectedPayoutPubkey, operation);
|
|
708
710
|
return inspected;
|
|
709
711
|
}
|
|
712
|
+
// M2 Open-Competition 1-tx verify bundle:
|
|
713
|
+
// `[ComputeBudget?, claim_task(sysvar), set_payout_to?, submit_work, verify_task_attested(MAX_SCORE)]`
|
|
714
|
+
const isM2VerifyNoPayout = isVerifyLifecycle &&
|
|
715
|
+
primary.spec.name === "verify_task_attested" &&
|
|
716
|
+
companions.length === 2 &&
|
|
717
|
+
companions[0].spec.name === "claim_task" &&
|
|
718
|
+
companions[1].spec.name === "submit_work";
|
|
719
|
+
const isM2VerifyWithPayout = isVerifyLifecycle &&
|
|
720
|
+
primary.spec.name === "verify_task_attested" &&
|
|
721
|
+
companions.length === 3 &&
|
|
722
|
+
companions[0].spec.name === "claim_task" &&
|
|
723
|
+
companions[1].spec.name === "set_payout_to" &&
|
|
724
|
+
companions[2].spec.name === "submit_work";
|
|
725
|
+
if (isM2VerifyNoPayout || isM2VerifyWithPayout) {
|
|
726
|
+
const disallowedInM2 = new Set([
|
|
727
|
+
SWITCHBOARD_PROGRAM_IDS[expected.network],
|
|
728
|
+
Secp256k1Program.programId.toBase58(),
|
|
729
|
+
]);
|
|
730
|
+
for (const extraAllowed of expected.allowedProgramIds ?? []) {
|
|
731
|
+
disallowedInM2.delete(extraAllowed);
|
|
732
|
+
}
|
|
733
|
+
const unexpectedProgramInM2 = inspected.instructions.find((ix) => disallowedInM2.has(ix.program_id));
|
|
734
|
+
if (unexpectedProgramInM2) {
|
|
735
|
+
throw txMismatch(operation, `Unexpected program ${unexpectedProgramInM2.program_id} in M2 verify bundle`);
|
|
736
|
+
}
|
|
737
|
+
if (inspected.fee_payer !== expected.wallet) {
|
|
738
|
+
throw txMismatch(operation, `M2 verify bundle requires fee_payer ${expected.wallet}, got ${inspected.fee_payer}`);
|
|
739
|
+
}
|
|
740
|
+
if (primary.ix.accounts[2] === inspected.fee_payer) {
|
|
741
|
+
throw txMismatch(operation, "M2 verify bundle attester cannot be fee_payer");
|
|
742
|
+
}
|
|
743
|
+
if (primary.ix.accounts.length !== 3) {
|
|
744
|
+
throw txMismatch(operation, `M2 verify_task_attested must carry exact 3 accounts [task, global_state, attester], got ${primary.ix.accounts.length}`);
|
|
745
|
+
}
|
|
746
|
+
const scoreView = new DataView(primary.data.buffer, primary.data.byteOffset + 8, 8);
|
|
747
|
+
const verifyScore = scoreView.getBigUint64(0, true);
|
|
748
|
+
if (verifyScore !== MAX_VERIFY_SCORE) {
|
|
749
|
+
throw txMismatch(operation, `M2 verify bundle requires MAX_SCORE (${MAX_VERIFY_SCORE}), got ${verifyScore}`);
|
|
750
|
+
}
|
|
751
|
+
if (!primary.data.subarray(16, 48).some((b) => b !== 0)) {
|
|
752
|
+
throw txMismatch(operation, "M2 verify_task_attested verification_hash must be non-zero");
|
|
753
|
+
}
|
|
754
|
+
const lifecycleTaskPda = primary.ix.accounts[0];
|
|
755
|
+
const claimIx = companions[0];
|
|
756
|
+
const payoutIx = isM2VerifyWithPayout ? companions[1] : undefined;
|
|
757
|
+
const submitIx = isM2VerifyWithPayout ? companions[2] : companions[1];
|
|
758
|
+
if (payoutIx) {
|
|
759
|
+
if (payoutIx.txIndex !== claimIx.txIndex + 1 ||
|
|
760
|
+
submitIx.txIndex !== payoutIx.txIndex + 1 ||
|
|
761
|
+
primary.txIndex !== submitIx.txIndex + 1) {
|
|
762
|
+
throw txMismatch(operation, "M2 verify bundle instructions must execute in strict order claim_task < set_payout_to < submit_work < verify_task_attested");
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
if (expectedPayoutPubkey) {
|
|
767
|
+
throw txMismatch(operation, "Expected set_payout_to instruction matching expected.payoutTo, but none was present");
|
|
768
|
+
}
|
|
769
|
+
if (submitIx.txIndex !== claimIx.txIndex + 1 ||
|
|
770
|
+
primary.txIndex !== submitIx.txIndex + 1) {
|
|
771
|
+
throw txMismatch(operation, "M2 verify bundle instructions must execute in strict order claim_task < submit_work < verify_task_attested");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
// Validate companion claim_task
|
|
775
|
+
const validClaimAccounts = claimIx.ix.accounts.length === SHILLBOT_INSTRUCTION_SPECS.claim_task.minAccounts ||
|
|
776
|
+
(claimIx.ix.accounts.length === 6 &&
|
|
777
|
+
claimIx.ix.accounts[5] === SYSVAR_INSTRUCTIONS_PUBKEY.toBase58());
|
|
778
|
+
if (claimIx.data.length !== 8 || !validClaimAccounts) {
|
|
779
|
+
throw txMismatch(operation, "Malformed claim_task companion in M2 verify bundle");
|
|
780
|
+
}
|
|
781
|
+
if (claimIx.ix.accounts[0] !== lifecycleTaskPda) {
|
|
782
|
+
throw txMismatch(operation, "M2 verify bundle claim_task account [0] does not match expected task PDA");
|
|
783
|
+
}
|
|
784
|
+
if (claimIx.ix.accounts[3] !== expected.wallet ||
|
|
785
|
+
!inspected.signers.includes(claimIx.ix.accounts[3])) {
|
|
786
|
+
throw txMismatch(operation, "M2 verify bundle claim_task authority slot [3] does not match expected wallet signer");
|
|
787
|
+
}
|
|
788
|
+
// Validate optional companion set_payout_to
|
|
789
|
+
if (payoutIx) {
|
|
790
|
+
validateSetPayoutToInstruction(payoutIx, expected.wallet, lifecycleTaskPda, expectedPayoutPubkey, operation);
|
|
791
|
+
}
|
|
792
|
+
// Validate companion submit_work
|
|
793
|
+
if (submitIx.ix.accounts.length !== SHILLBOT_INSTRUCTION_SPECS.submit_work.minAccounts) {
|
|
794
|
+
throw txMismatch(operation, `M2 verify bundle submit_work must carry exact 4 accounts, got ${submitIx.ix.accounts.length}`);
|
|
795
|
+
}
|
|
796
|
+
if (submitIx.ix.accounts[0] !== lifecycleTaskPda) {
|
|
797
|
+
throw txMismatch(operation, "M2 verify bundle submit_work account [0] does not match expected task PDA");
|
|
798
|
+
}
|
|
799
|
+
if (submitIx.ix.accounts[3] !== expected.wallet ||
|
|
800
|
+
!inspected.signers.includes(submitIx.ix.accounts[3])) {
|
|
801
|
+
throw txMismatch(operation, "M2 verify bundle submit_work authority slot [3] does not match expected wallet signer");
|
|
802
|
+
}
|
|
803
|
+
if (submitIx.data.length < 12) {
|
|
804
|
+
throw txMismatch(operation, "M2 verify bundle submit_work instruction is truncated");
|
|
805
|
+
}
|
|
806
|
+
const submitContentLen = submitIx.data.readUInt32LE(8);
|
|
807
|
+
if (submitIx.data.length !== 12 + submitContentLen) {
|
|
808
|
+
throw txMismatch(operation, "M2 verify bundle submit_work content_id length mismatch");
|
|
809
|
+
}
|
|
810
|
+
if (expected.contentId !== undefined) {
|
|
811
|
+
const actualContent = submitIx.data.subarray(12, 12 + submitContentLen).toString("utf8");
|
|
812
|
+
if (actualContent !== expected.contentId) {
|
|
813
|
+
throw txMismatch(operation, "M2 verify bundle submit_work content_id differs from expectation");
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return inspected;
|
|
817
|
+
}
|
|
710
818
|
if ((isClaimLifecycle || isSubmitLifecycle) &&
|
|
711
819
|
companions.length === 1 &&
|
|
712
820
|
companions[0].spec.name === "set_payout_to") {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLIENT_VERSION = "0.4.
|
|
1
|
+
export declare const CLIENT_VERSION = "0.4.9";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.4.
|
|
1
|
+
export const CLIENT_VERSION = "0.4.9";
|
package/package.json
CHANGED