@swarm-tips/client 0.4.6 → 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.
- package/SBOM.spdx.json +5 -5
- package/dist/agent.d.ts +19 -0
- package/dist/agent.js +82 -15
- package/dist/cli/keyfile.d.ts +3 -2
- package/dist/cli/keyfile.js +21 -4
- package/dist/cli/swarm.js +43 -11
- package/dist/coordination-game/api.d.ts +61 -26
- package/dist/coordination-game/api.js +47 -18
- package/dist/coordination-game/evm/cross-chain.d.ts +25 -4
- package/dist/coordination-game/evm/cross-chain.js +28 -2
- package/dist/coordination-game/evm/index.d.ts +1 -1
- package/dist/coordination-game/evm/session.d.ts +81 -26
- package/dist/coordination-game/evm/session.js +273 -75
- package/dist/coordination-game/index.d.ts +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/shillbot/api.d.ts +8 -4
- package/dist/shillbot/api.js +9 -4
- package/dist/shillbot/index.d.ts +1 -1
- package/dist/shillbot/index.js +1 -1
- package/dist/shillbot/verify-tx.d.ts +8 -3
- package/dist/shillbot/verify-tx.js +47 -12
- 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.7",
|
|
6
|
+
"documentNamespace": "https://swarm.tips/sbom/client/0.4.7",
|
|
7
7
|
"creationInfo": {
|
|
8
|
-
"created": "2026-11-
|
|
8
|
+
"created": "2026-11-17T05:34:07.531Z",
|
|
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.7",
|
|
19
|
+
"downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.4.7",
|
|
20
20
|
"filesAnalyzed": false,
|
|
21
21
|
"licenseConcluded": "MIT",
|
|
22
22
|
"licenseDeclared": "MIT"
|
package/dist/agent.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ 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
15
|
export interface SwarmAgentOptions {
|
|
12
16
|
signer?: SwarmSigner;
|
|
13
17
|
token?: string | (() => Promise<string | undefined>);
|
|
@@ -16,6 +20,8 @@ export interface SwarmAgentOptions {
|
|
|
16
20
|
shillbotUrl?: string;
|
|
17
21
|
gameUrl?: string;
|
|
18
22
|
mcpUrl?: string;
|
|
23
|
+
/** Automatically call `onboard()` when a Solana wallet lacks SOL for self-paid claim/submit; default `true`. */
|
|
24
|
+
autoOnboard?: boolean;
|
|
19
25
|
/** Maximum SOL escrow spend allowed per task creation; default `0n` (C9). */
|
|
20
26
|
maxEscrowSpendLamports?: bigint;
|
|
21
27
|
/** Maximum ETH/EVM escrow spend allowed per task creation; default `0n` (C9). */
|
|
@@ -39,7 +45,11 @@ export interface ExecutedTaskResult<TConfirm = unknown> {
|
|
|
39
45
|
}
|
|
40
46
|
export interface ExecuteTaskOptions {
|
|
41
47
|
sponsor?: "auto" | "true" | "none";
|
|
48
|
+
/** Automatically call `onboard()` if `?sponsor=auto` returns self-paid on an underfunded wallet; default `true`. */
|
|
49
|
+
autoOnboard?: boolean;
|
|
42
50
|
connection?: Connection;
|
|
51
|
+
/** Optional explicit sponsor fee payer pubkey (base58). */
|
|
52
|
+
feePayer?: string;
|
|
43
53
|
/** Explicit authorized payout destination pubkey (base58) when `set_payout_to` is expected. */
|
|
44
54
|
payoutTo?: string;
|
|
45
55
|
extra?: Record<string, unknown>;
|
|
@@ -59,6 +69,7 @@ export declare class SwarmAgent {
|
|
|
59
69
|
readonly shillbotUrl: string;
|
|
60
70
|
readonly gameUrl: string;
|
|
61
71
|
readonly mcpUrl: string;
|
|
72
|
+
readonly autoOnboard: boolean;
|
|
62
73
|
readonly maxEscrowSpendLamports: bigint;
|
|
63
74
|
readonly maxEscrowSpendWei: bigint;
|
|
64
75
|
readonly maxNetworkFeeLamports: bigint;
|
|
@@ -70,6 +81,7 @@ export declare class SwarmAgent {
|
|
|
70
81
|
private readonly swarmClient;
|
|
71
82
|
private readonly inboxClient;
|
|
72
83
|
private readonly gameClient;
|
|
84
|
+
private autoOnboardAttempted;
|
|
73
85
|
readonly auth: {
|
|
74
86
|
getToken: () => Promise<string | undefined>;
|
|
75
87
|
authenticate: () => Promise<string>;
|
|
@@ -132,6 +144,7 @@ export declare class SwarmAgent {
|
|
|
132
144
|
get: <TCampaign = unknown>(id: string) => Promise<TCampaign>;
|
|
133
145
|
tasks: <TTask = unknown>(id: string) => Promise<TaskListResponse<TTask>>;
|
|
134
146
|
metrics: <TMetrics = unknown>(id: string) => Promise<TMetrics>;
|
|
147
|
+
pendingApproval: <TTask = unknown>(network?: SwarmNetwork) => Promise<TaskListResponse<TTask> | TTask[]>;
|
|
135
148
|
create: <TResponse = {
|
|
136
149
|
campaign_id: string;
|
|
137
150
|
}>(body: unknown) => Promise<TResponse>;
|
|
@@ -194,6 +207,12 @@ export declare class SwarmAgent {
|
|
|
194
207
|
}) => Promise<T>;
|
|
195
208
|
};
|
|
196
209
|
constructor(options?: SwarmAgentOptions);
|
|
210
|
+
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`3_100_000` lamports). */
|
|
211
|
+
onboard<TResponse = unknown>(): Promise<TResponse>;
|
|
212
|
+
/** Claim a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
|
|
213
|
+
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>;
|
|
197
216
|
private requireSigner;
|
|
198
217
|
private executeClaimOrSubmit;
|
|
199
218
|
/**
|
package/dist/agent.js
CHANGED
|
@@ -10,6 +10,12 @@ 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;
|
|
17
|
+
/** Minimum SOL balance (`50_000` lamports) required for standalone post-claim `submit_work` fee payment. */
|
|
18
|
+
const MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS = 50_000;
|
|
13
19
|
const DEFAULT_SOLANA_RPC = {
|
|
14
20
|
mainnet: "https://api.mainnet-beta.solana.com",
|
|
15
21
|
devnet: "https://api.devnet.solana.com",
|
|
@@ -95,6 +101,7 @@ export class SwarmAgent {
|
|
|
95
101
|
shillbotUrl;
|
|
96
102
|
gameUrl;
|
|
97
103
|
mcpUrl;
|
|
104
|
+
autoOnboard;
|
|
98
105
|
maxEscrowSpendLamports;
|
|
99
106
|
maxEscrowSpendWei;
|
|
100
107
|
maxNetworkFeeLamports;
|
|
@@ -106,6 +113,7 @@ export class SwarmAgent {
|
|
|
106
113
|
swarmClient;
|
|
107
114
|
inboxClient;
|
|
108
115
|
gameClient;
|
|
116
|
+
autoOnboardAttempted = false;
|
|
109
117
|
auth;
|
|
110
118
|
discovery;
|
|
111
119
|
tasks;
|
|
@@ -119,6 +127,7 @@ export class SwarmAgent {
|
|
|
119
127
|
this.shillbotUrl = (options.shillbotUrl ?? "https://api.shillbot.org").replace(/\/$/, "");
|
|
120
128
|
this.gameUrl = (options.gameUrl ?? "https://api.coordination.game").replace(/\/$/, "");
|
|
121
129
|
this.mcpUrl = (options.mcpUrl ?? "https://mcp.swarm.tips").replace(/\/$/, "");
|
|
130
|
+
this.autoOnboard = options.autoOnboard ?? true;
|
|
122
131
|
this.maxEscrowSpendLamports = options.maxEscrowSpendLamports ?? 0n;
|
|
123
132
|
this.maxEscrowSpendWei = options.maxEscrowSpendWei ?? 0n;
|
|
124
133
|
this.maxNetworkFeeLamports = options.maxNetworkFeeLamports ?? 100000n;
|
|
@@ -203,7 +212,7 @@ export class SwarmAgent {
|
|
|
203
212
|
return Array.isArray(res) ? res : (res.tasks ?? []);
|
|
204
213
|
},
|
|
205
214
|
earnings: () => self.shillbotClient.earnings(),
|
|
206
|
-
onboard: () => self.
|
|
215
|
+
onboard: () => self.onboard(),
|
|
207
216
|
claim: (id, sponsor = "auto") => self.shillbotClient.claimTask(id, sponsor),
|
|
208
217
|
claimAndExecute: (id, opts) => self.executeClaimOrSubmit(id, "claim", undefined, opts),
|
|
209
218
|
submit: (id, body) => self.shillbotClient.submitTask(id, body),
|
|
@@ -256,6 +265,7 @@ export class SwarmAgent {
|
|
|
256
265
|
get: (id) => self.shillbotClient.campaign(id),
|
|
257
266
|
tasks: (id) => self.shillbotClient.campaignTasks(id),
|
|
258
267
|
metrics: (id) => self.shillbotClient.campaignMetrics(id),
|
|
268
|
+
pendingApproval: (net) => self.shillbotClient.listPendingApproval(net),
|
|
259
269
|
create: (body) => self.shillbotClient.createCampaign(body),
|
|
260
270
|
fund: (id, body) => self.shillbotClient.fundCampaignTask(id, body),
|
|
261
271
|
async fundAndExecute(id, body, opts) {
|
|
@@ -337,6 +347,18 @@ export class SwarmAgent {
|
|
|
337
347
|
},
|
|
338
348
|
};
|
|
339
349
|
}
|
|
350
|
+
/** Bootstrap a zero-funds Solana agent wallet via recoupable Advance PDA fronting (`3_100_000` lamports). */
|
|
351
|
+
onboard() {
|
|
352
|
+
return this.shillbotClient.onboard();
|
|
353
|
+
}
|
|
354
|
+
/** Claim a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
|
|
355
|
+
claimTask(id, opts) {
|
|
356
|
+
return this.executeClaimOrSubmit(id, "claim", undefined, opts);
|
|
357
|
+
}
|
|
358
|
+
/** Submit work for a task and execute the prepared transaction (with automatic `$0` wallet onboarding when enabled). */
|
|
359
|
+
submitWork(id, contentId, opts) {
|
|
360
|
+
return this.executeClaimOrSubmit(id, "submit", contentId, opts);
|
|
361
|
+
}
|
|
340
362
|
requireSigner() {
|
|
341
363
|
if (!this.signer) {
|
|
342
364
|
throw new SwarmClientError({
|
|
@@ -350,30 +372,30 @@ export class SwarmAgent {
|
|
|
350
372
|
async executeClaimOrSubmit(id, action, contentId, opts) {
|
|
351
373
|
const sponsorMode = opts?.sponsor ?? "auto";
|
|
352
374
|
const sponsorQuery = sponsorMode === "none" ? "false" : sponsorMode === "true" ? "true" : "auto";
|
|
353
|
-
|
|
354
|
-
|
|
375
|
+
const shouldAutoOnboard = (opts?.autoOnboard ?? this.autoOnboard) !== false;
|
|
376
|
+
const requestPrepared = (query) => {
|
|
355
377
|
if (action === "claim") {
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
const suffix = sponsorMode !== "none" ? `?sponsor=${encodeURIComponent(sponsorQuery)}` : "";
|
|
360
|
-
prepared = await this.shillbotClient.post(`/tasks/${encodeURIComponent(id)}/submit${suffix}`, { content_id: contentId, ...(opts?.extra ?? {}) });
|
|
378
|
+
return this.shillbotClient.claimTask(id, query);
|
|
361
379
|
}
|
|
380
|
+
const suffix = sponsorMode !== "none" ? `?sponsor=${encodeURIComponent(query)}` : "";
|
|
381
|
+
return this.shillbotClient.post(`/tasks/${encodeURIComponent(id)}/submit${suffix}`, { content_id: contentId, ...(opts?.extra ?? {}) });
|
|
382
|
+
};
|
|
383
|
+
let prepared;
|
|
384
|
+
try {
|
|
385
|
+
prepared = await requestPrepared(sponsorQuery);
|
|
362
386
|
}
|
|
363
387
|
catch (err) {
|
|
364
388
|
if ((action === "claim" || action === "submit") &&
|
|
365
389
|
sponsorMode !== "none" &&
|
|
390
|
+
shouldAutoOnboard &&
|
|
391
|
+
!this.autoOnboardAttempted &&
|
|
366
392
|
err instanceof SwarmClientError &&
|
|
367
393
|
err.code === "HTTP_ERROR" &&
|
|
368
394
|
(err.status === 400 || err.status === 403 || err.status === 412) &&
|
|
369
395
|
/onboard|agent_state|bootstrap/i.test(err.message)) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
prepared = await this.shillbotClient.post(`/tasks/${encodeURIComponent(id)}/submit?sponsor=${encodeURIComponent(sponsorQuery)}`, { content_id: contentId, ...(opts?.extra ?? {}) });
|
|
376
|
-
}
|
|
396
|
+
this.autoOnboardAttempted = true;
|
|
397
|
+
await this.onboard();
|
|
398
|
+
prepared = await requestPrepared(sponsorQuery);
|
|
377
399
|
}
|
|
378
400
|
else {
|
|
379
401
|
throw err;
|
|
@@ -382,6 +404,48 @@ export class SwarmAgent {
|
|
|
382
404
|
const connection = this.signer?.chain === "solana"
|
|
383
405
|
? (opts?.connection ?? new Connection(this.rpcUrl, "confirmed"))
|
|
384
406
|
: opts?.connection;
|
|
407
|
+
// When a Solana wallet holds less than MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS (3_000_000 lamports
|
|
408
|
+
// for claim / atomic claim+submit) or MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS (50_000 lamports
|
|
409
|
+
// for standalone submit) and receives a self-paid HTTP 200 transaction, onboard once and re-request.
|
|
410
|
+
if (prepared.transaction &&
|
|
411
|
+
sponsorMode !== "none" &&
|
|
412
|
+
shouldAutoOnboard &&
|
|
413
|
+
!this.autoOnboardAttempted &&
|
|
414
|
+
connection &&
|
|
415
|
+
this.signer?.chain === "solana" &&
|
|
416
|
+
typeof connection.getBalance === "function") {
|
|
417
|
+
let initialFeePayer;
|
|
418
|
+
let bundlesClaim = action === "claim";
|
|
419
|
+
try {
|
|
420
|
+
const initialInspected = inspectTransaction(prepared.transaction);
|
|
421
|
+
initialFeePayer = initialInspected.fee_payer;
|
|
422
|
+
if (!bundlesClaim) {
|
|
423
|
+
const claimDisc = shillbotInstructionDiscriminator("claim_task");
|
|
424
|
+
const claimSessionDisc = shillbotInstructionDiscriminator("claim_task_session");
|
|
425
|
+
bundlesClaim = initialInspected.instructions.some((ix) => {
|
|
426
|
+
if (ix.program_id !== SHILLBOT_PROGRAM_ID_B58)
|
|
427
|
+
return false;
|
|
428
|
+
const d = Buffer.from(ix.data_base64, "base64");
|
|
429
|
+
return (d.length >= 8 &&
|
|
430
|
+
(d.subarray(0, 8).equals(claimDisc) || d.subarray(0, 8).equals(claimSessionDisc)));
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
// Malformed transaction will fail closed during validation below.
|
|
436
|
+
}
|
|
437
|
+
if (initialFeePayer === this.signer.address) {
|
|
438
|
+
const balanceLamports = await connection.getBalance(new PublicKey(this.signer.address));
|
|
439
|
+
const minRequiredLamports = bundlesClaim
|
|
440
|
+
? MIN_SELF_PAID_SOLANA_BALANCE_LAMPORTS
|
|
441
|
+
: MIN_POST_CLAIM_SUBMIT_SOLANA_BALANCE_LAMPORTS;
|
|
442
|
+
if (balanceLamports < minRequiredLamports) {
|
|
443
|
+
this.autoOnboardAttempted = true;
|
|
444
|
+
await this.onboard();
|
|
445
|
+
prepared = await requestPrepared("auto");
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
385
449
|
let resolvedPayoutTo = connection && this.signer?.chain === "solana"
|
|
386
450
|
? await SwarmAgent.resolveVerifiedAdvancePayoutTo(prepared, this.signer.address, connection, opts?.payoutTo)
|
|
387
451
|
: opts?.payoutTo;
|
|
@@ -396,6 +460,7 @@ export class SwarmAgent {
|
|
|
396
460
|
network: this.network,
|
|
397
461
|
wallet: this.signer.address,
|
|
398
462
|
taskPda: prepared.task_pda,
|
|
463
|
+
...(opts?.feePayer !== undefined ? { feePayer: opts.feePayer } : {}),
|
|
399
464
|
...(resolvedPayoutTo !== undefined ? { payoutTo: resolvedPayoutTo } : {}),
|
|
400
465
|
});
|
|
401
466
|
if (inspected.fee_payer !== this.signer.address &&
|
|
@@ -418,6 +483,7 @@ export class SwarmAgent {
|
|
|
418
483
|
}
|
|
419
484
|
return this.executePreparedAction(id, action, prepared, {
|
|
420
485
|
connection,
|
|
486
|
+
feePayer: opts?.feePayer,
|
|
421
487
|
payoutTo: resolvedPayoutTo,
|
|
422
488
|
payoutToResolved,
|
|
423
489
|
});
|
|
@@ -593,6 +659,7 @@ export class SwarmAgent {
|
|
|
593
659
|
network: this.network,
|
|
594
660
|
wallet: signer.address,
|
|
595
661
|
taskPda: prepared.task_pda,
|
|
662
|
+
...(opts.feePayer !== undefined ? { feePayer: opts.feePayer } : {}),
|
|
596
663
|
...(resolvedPayoutTo !== undefined ? { payoutTo: resolvedPayoutTo } : {}),
|
|
597
664
|
...(action === "create" && opts.expectedEscrowLamports !== undefined
|
|
598
665
|
? { escrowLamports: opts.expectedEscrowLamports }
|
package/dist/cli/keyfile.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export declare function readSecureKeypairFile(filePath: string): string;
|
|
|
15
15
|
export interface LoadCliSignerOptions {
|
|
16
16
|
keypairFile?: string;
|
|
17
17
|
env?: Record<string, string | undefined>;
|
|
18
|
-
evmChainId?: number;
|
|
18
|
+
evmChainId?: number | string;
|
|
19
19
|
evmRpcUrl?: string;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Load a non-custodial `SwarmSigner` from `--keypair-file`
|
|
22
|
+
* Load a non-custodial `SwarmSigner` from `--keypair-file` (Solana JSON/base58 or
|
|
23
|
+
* `0x`-prefixed 32-byte hex EVM private key) or `SWARM_*` environment variables.
|
|
23
24
|
*/
|
|
24
25
|
export declare function loadSignerFromCliOrEnv(options?: LoadCliSignerOptions): SwarmSigner | undefined;
|
package/dist/cli/keyfile.js
CHANGED
|
@@ -57,13 +57,30 @@ export function readSecureKeypairFile(filePath) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Load a non-custodial `SwarmSigner` from `--keypair-file`
|
|
60
|
+
* Load a non-custodial `SwarmSigner` from `--keypair-file` (Solana JSON/base58 or
|
|
61
|
+
* `0x`-prefixed 32-byte hex EVM private key) or `SWARM_*` environment variables.
|
|
61
62
|
*/
|
|
62
63
|
export function loadSignerFromCliOrEnv(options = {}) {
|
|
63
64
|
const env = options.env ?? process.env;
|
|
64
|
-
const
|
|
65
|
+
const resolvedEvmChainId = options.evmChainId ?? env.SWARM_EVM_CHAIN_ID?.trim();
|
|
66
|
+
const resolvedEvmRpcUrl = options.evmRpcUrl ?? env.SWARM_EVM_RPC_URL?.trim();
|
|
67
|
+
const keyfilePath = options.keypairFile ?? env.SWARM_SOLANA_KEYPAIR_PATH ?? env.SWARM_EVM_KEYPAIR_PATH;
|
|
65
68
|
if (keyfilePath) {
|
|
66
69
|
const raw = readSecureKeypairFile(keyfilePath);
|
|
70
|
+
if (/^0x/i.test(raw)) {
|
|
71
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(raw)) {
|
|
72
|
+
throw new CliUsageError(`Invalid EVM private key in ${resolve(keyfilePath)}: Expected a 0x-prefixed 32-byte hex EVM private key`);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return fromEvmPrivateKey(raw, {
|
|
76
|
+
chainId: resolvedEvmChainId,
|
|
77
|
+
rpcUrl: resolvedEvmRpcUrl,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
throw new CliUsageError(`Invalid EVM private key in ${resolve(keyfilePath)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
67
84
|
try {
|
|
68
85
|
return fromSolanaSecretKey(raw);
|
|
69
86
|
}
|
|
@@ -85,8 +102,8 @@ export function loadSignerFromCliOrEnv(options = {}) {
|
|
|
85
102
|
const normalized = (evmPriv.startsWith("0x") ? evmPriv : `0x${evmPriv}`);
|
|
86
103
|
try {
|
|
87
104
|
return fromEvmPrivateKey(normalized, {
|
|
88
|
-
chainId:
|
|
89
|
-
rpcUrl:
|
|
105
|
+
chainId: resolvedEvmChainId,
|
|
106
|
+
rpcUrl: resolvedEvmRpcUrl,
|
|
90
107
|
});
|
|
91
108
|
}
|
|
92
109
|
catch (err) {
|
package/dist/cli/swarm.js
CHANGED
|
@@ -99,11 +99,12 @@ Usage:
|
|
|
99
99
|
|
|
100
100
|
Commands:
|
|
101
101
|
auth whoami | token
|
|
102
|
+
onboard
|
|
102
103
|
listings [--limit N] [--category CAT] [--chain CHAIN]
|
|
103
104
|
reputation <wallet>
|
|
104
|
-
tasks list [--limit N] | get <id> | mine | earnings | next <task-json-or-id>
|
|
105
|
-
tasks claim <id> [--payout-to <pubkey>] [--no-exec]
|
|
106
|
-
tasks submit <id> --content <str> [--payout-to <pubkey>] [--no-exec]
|
|
105
|
+
tasks list [--limit N] | get <id> | mine | earnings | onboard | next <task-json-or-id>
|
|
106
|
+
tasks claim <id> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
107
|
+
tasks submit <id> --content <str> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
107
108
|
tasks verify <id> [--no-exec]
|
|
108
109
|
tasks finalize <id> [--no-exec]
|
|
109
110
|
tasks expire <id> [--no-exec] (client escrow refund past claim/submit deadline or past submitted_at + verification_timeout)
|
|
@@ -121,8 +122,10 @@ Commands:
|
|
|
121
122
|
Global Options:
|
|
122
123
|
--json Output structured JSON (auto-enabled when stdout is non-TTY)
|
|
123
124
|
--network <mainnet|devnet> Target network (default: mainnet)
|
|
124
|
-
--keypair-file <path> Solana keypair file (
|
|
125
|
+
--keypair-file <path> Solana keypair or 0x-prefixed 32-byte EVM hex key file (chmod 600 on POSIX)
|
|
125
126
|
--rpc-url <url> Override Solana RPC URL
|
|
127
|
+
--evm-rpc-url <url> Override EVM JSON-RPC URL
|
|
128
|
+
--evm-chain-id <id> Optional EVM chain ID or CAIP-2 identifier (e.g. 84532, eip155:8453)
|
|
126
129
|
--max-spend-lamports <n> Max SOL escrow spend cap (default: 0)
|
|
127
130
|
--max-spend-wei <n> Max EVM escrow spend cap (default: 0)
|
|
128
131
|
--help, -h Show this help text
|
|
@@ -131,7 +134,9 @@ Global Options:
|
|
|
131
134
|
Environment Variables:
|
|
132
135
|
SWARM_SOLANA_KEYPAIR_PATH Path to chmod 600 Solana keypair JSON/base58 file
|
|
133
136
|
SWARM_SOLANA_SECRET_KEY Base58 or JSON 64-byte Solana secret key
|
|
137
|
+
SWARM_EVM_KEYPAIR_PATH Path to chmod 600 0x-prefixed 32-byte EVM hex private key file
|
|
134
138
|
SWARM_EVM_PRIVATE_KEY 0x-prefixed 32-byte EVM private key
|
|
139
|
+
SWARM_EVM_RPC_URL EVM JSON-RPC URL for EVM transaction broadcast
|
|
135
140
|
SWARM_AUTH_TOKEN Pre-minted Bearer JWT
|
|
136
141
|
`;
|
|
137
142
|
const VALID_ACTIONS = new Set([
|
|
@@ -235,6 +240,7 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
235
240
|
}
|
|
236
241
|
const taskPda = getStringFlag(flags, "--task-pda");
|
|
237
242
|
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
243
|
+
const sponsor = getStringFlag(flags, "--sponsor");
|
|
238
244
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
239
245
|
const rawExpireState = getStringFlag(flags, "--expire-task-state")?.trim().toLowerCase();
|
|
240
246
|
if (rawExpireState !== undefined &&
|
|
@@ -251,6 +257,7 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
251
257
|
wallet,
|
|
252
258
|
...(taskPda ? { taskPda } : {}),
|
|
253
259
|
...(feePayer ? { feePayer } : {}),
|
|
260
|
+
...(sponsor ? { sponsor } : {}),
|
|
254
261
|
...(payoutTo ? { payoutTo } : {}),
|
|
255
262
|
...(expireTaskState ? { expireTaskState } : {}),
|
|
256
263
|
...(oracleAuthority ? { oracleAuthority } : {}),
|
|
@@ -267,10 +274,13 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
267
274
|
}
|
|
268
275
|
throw new CliUsageError("Usage: swarm tx <inspect|verify> [options]");
|
|
269
276
|
}
|
|
277
|
+
const evmRpcUrl = getStringFlag(flags, "--evm-rpc-url") ?? env.SWARM_EVM_RPC_URL;
|
|
278
|
+
const evmChainId = getStringFlag(flags, "--evm-chain-id") ?? env.SWARM_EVM_CHAIN_ID;
|
|
270
279
|
const signer = loadSignerFromCliOrEnv({
|
|
271
280
|
keypairFile: getStringFlag(flags, "--keypair-file"),
|
|
272
281
|
env,
|
|
273
|
-
evmRpcUrl
|
|
282
|
+
evmRpcUrl,
|
|
283
|
+
evmChainId,
|
|
274
284
|
});
|
|
275
285
|
const agent = new SwarmAgent({
|
|
276
286
|
signer,
|
|
@@ -284,6 +294,14 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
284
294
|
maxEscrowSpendWei,
|
|
285
295
|
fetch: io.fetch,
|
|
286
296
|
});
|
|
297
|
+
if (cmd === "onboard") {
|
|
298
|
+
if (!signer && !agent.auth.walletAddress && !env.SWARM_AUTH_TOKEN) {
|
|
299
|
+
throw new CliUsageError("No wallet configured. Pass --keypair-file <path> (chmod 600) or set SWARM_SOLANA_KEYPAIR_PATH, SWARM_SOLANA_SECRET_KEY, or SWARM_EVM_PRIVATE_KEY.");
|
|
300
|
+
}
|
|
301
|
+
const res = await agent.onboard();
|
|
302
|
+
writeOutput(stdout, jsonMode, res);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
287
305
|
if (cmd === "auth") {
|
|
288
306
|
if (sub === "whoami") {
|
|
289
307
|
if (!signer && !agent.auth.walletAddress) {
|
|
@@ -351,6 +369,11 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
351
369
|
writeOutput(stdout, jsonMode, res);
|
|
352
370
|
return 0;
|
|
353
371
|
}
|
|
372
|
+
if (sub === "onboard") {
|
|
373
|
+
const res = await agent.onboard();
|
|
374
|
+
writeOutput(stdout, jsonMode, res);
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
354
377
|
if (sub === "next") {
|
|
355
378
|
const arg = rest[0] ?? (await readStdinText(io));
|
|
356
379
|
if (!arg) {
|
|
@@ -364,12 +387,17 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
364
387
|
}
|
|
365
388
|
if (sub === "claim") {
|
|
366
389
|
const id = rest[0];
|
|
367
|
-
if (!id)
|
|
368
|
-
throw new CliUsageError("Usage: swarm tasks claim <task_id> [--payout-to <pubkey>] [--no-exec]");
|
|
390
|
+
if (!id) {
|
|
391
|
+
throw new CliUsageError("Usage: swarm tasks claim <task_id> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]");
|
|
392
|
+
}
|
|
369
393
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
394
|
+
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
395
|
+
const execOpts = payoutTo || feePayer
|
|
396
|
+
? { ...(payoutTo ? { payoutTo } : {}), ...(feePayer ? { feePayer } : {}) }
|
|
397
|
+
: undefined;
|
|
370
398
|
const res = noExec
|
|
371
399
|
? await agent.tasks.claim(id)
|
|
372
|
-
: await agent.tasks.claimAndExecute(id,
|
|
400
|
+
: await agent.tasks.claimAndExecute(id, execOpts);
|
|
373
401
|
writeOutput(stdout, jsonMode, res);
|
|
374
402
|
return 0;
|
|
375
403
|
}
|
|
@@ -377,12 +405,16 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
377
405
|
const id = rest[0];
|
|
378
406
|
const content = getStringFlag(flags, "--content");
|
|
379
407
|
if (!id || !content) {
|
|
380
|
-
throw new CliUsageError("Usage: swarm tasks submit <task_id> --content <str> [--payout-to <pubkey>] [--no-exec]");
|
|
408
|
+
throw new CliUsageError("Usage: swarm tasks submit <task_id> --content <str> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]");
|
|
381
409
|
}
|
|
382
410
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
411
|
+
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
412
|
+
const execOpts = payoutTo || feePayer
|
|
413
|
+
? { ...(payoutTo ? { payoutTo } : {}), ...(feePayer ? { feePayer } : {}) }
|
|
414
|
+
: undefined;
|
|
383
415
|
const res = noExec
|
|
384
416
|
? await agent.tasks.submit(id, { content_id: content })
|
|
385
|
-
: await agent.tasks.submitAndExecute(id, content,
|
|
417
|
+
: await agent.tasks.submitAndExecute(id, content, execOpts);
|
|
386
418
|
writeOutput(stdout, jsonMode, res);
|
|
387
419
|
return 0;
|
|
388
420
|
}
|
|
@@ -416,7 +448,7 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
416
448
|
writeOutput(stdout, jsonMode, res);
|
|
417
449
|
return 0;
|
|
418
450
|
}
|
|
419
|
-
throw new CliUsageError("Usage: swarm tasks <list|get|mine|earnings|next|claim|submit|verify|finalize|expire> ...");
|
|
451
|
+
throw new CliUsageError("Usage: swarm tasks <list|get|mine|earnings|onboard|next|claim|submit|verify|finalize|expire> ...");
|
|
420
452
|
}
|
|
421
453
|
if (cmd === "inbox") {
|
|
422
454
|
if (sub === "list") {
|
|
@@ -24,6 +24,8 @@ export interface SessionAuthResponse {
|
|
|
24
24
|
export interface QueueRequest {
|
|
25
25
|
tournament_id: number;
|
|
26
26
|
is_ai?: boolean;
|
|
27
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
28
|
+
isAi?: boolean;
|
|
27
29
|
}
|
|
28
30
|
export type QueueJoinResponse = {
|
|
29
31
|
matched: true;
|
|
@@ -120,6 +122,24 @@ export interface EvmJoinResponse {
|
|
|
120
122
|
match?: EvmMatchPayload;
|
|
121
123
|
session_id?: string;
|
|
122
124
|
}
|
|
125
|
+
export interface XQueueJoinInput {
|
|
126
|
+
wallet: string;
|
|
127
|
+
chain: string;
|
|
128
|
+
session_key: string;
|
|
129
|
+
tournament_id: number;
|
|
130
|
+
is_ai?: boolean;
|
|
131
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
132
|
+
isAi?: boolean;
|
|
133
|
+
}
|
|
134
|
+
export interface EvmGameJoinInput {
|
|
135
|
+
wallet: string;
|
|
136
|
+
player_wallet?: string;
|
|
137
|
+
chain: string;
|
|
138
|
+
tournament_id: number;
|
|
139
|
+
is_ai?: boolean;
|
|
140
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
141
|
+
isAi?: boolean;
|
|
142
|
+
}
|
|
123
143
|
export declare class CoordinationGameApiClient {
|
|
124
144
|
readonly http: HttpClient;
|
|
125
145
|
constructor(options: HttpClientOptions);
|
|
@@ -128,46 +148,47 @@ export declare class CoordinationGameApiClient {
|
|
|
128
148
|
authSession(body: SessionAuthRequest): Promise<SessionAuthResponse>;
|
|
129
149
|
evmAuthChallenge(body: ChallengeRequest): Promise<ChallengeResponse>;
|
|
130
150
|
evmAuthVerify(body: VerifyRequest): Promise<VerifyResponse>;
|
|
131
|
-
joinQueue(body: QueueRequest, token
|
|
132
|
-
leaveQueue(body: QueueRequest, token
|
|
151
|
+
joinQueue(body: QueueRequest, token?: string): Promise<QueueJoinResponse>;
|
|
152
|
+
leaveQueue(body: QueueRequest, token?: string): Promise<OkResponse>;
|
|
133
153
|
gameStarted(body: {
|
|
134
154
|
game_id: number;
|
|
135
155
|
session_id: string;
|
|
136
|
-
}, token
|
|
156
|
+
}, token?: string): Promise<OkResponse>;
|
|
137
157
|
gameJoined(body: {
|
|
138
158
|
game_id: number;
|
|
139
159
|
session_id: string;
|
|
140
|
-
}, token
|
|
160
|
+
}, token?: string): Promise<OkResponse>;
|
|
141
161
|
cosign(body: {
|
|
142
162
|
session_id: string;
|
|
143
163
|
message: string;
|
|
144
|
-
}, token
|
|
164
|
+
}, token?: string): Promise<{
|
|
145
165
|
signature: string;
|
|
146
166
|
}>;
|
|
147
167
|
cosignJoin(body: {
|
|
148
168
|
session_id: string;
|
|
149
169
|
message: string;
|
|
150
|
-
}, token
|
|
170
|
+
}, token?: string): Promise<{
|
|
151
171
|
signature: string;
|
|
152
172
|
}>;
|
|
153
173
|
committed(body: {
|
|
154
174
|
session_id: string;
|
|
155
|
-
}, token
|
|
175
|
+
}, token?: string): Promise<{
|
|
156
176
|
ok: boolean;
|
|
157
177
|
both_committed: boolean;
|
|
158
178
|
}>;
|
|
159
179
|
bothCommitted(body: {
|
|
160
180
|
session_id: string;
|
|
161
|
-
}, token
|
|
181
|
+
}, token?: string): Promise<{
|
|
162
182
|
r_matchup: string;
|
|
163
183
|
}>;
|
|
164
|
-
resolved(body: Record<string, number>, token
|
|
165
|
-
joinCrossChainQueue(body:
|
|
184
|
+
resolved(body: Record<string, number>, token?: string): Promise<OkResponse>;
|
|
185
|
+
joinCrossChainQueue(body: XQueueJoinInput, token?: string): Promise<XQueueResponse>;
|
|
186
|
+
leaveCrossChainQueue(body: {
|
|
166
187
|
wallet: string;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}, token?: string): Promise<
|
|
188
|
+
tournament_id?: number;
|
|
189
|
+
chain?: string;
|
|
190
|
+
handle?: string;
|
|
191
|
+
}, token?: string): Promise<OkResponse>;
|
|
171
192
|
crossChainStatus(by: {
|
|
172
193
|
handle: string;
|
|
173
194
|
} | {
|
|
@@ -177,7 +198,7 @@ export declare class CoordinationGameApiClient {
|
|
|
177
198
|
wallet: string;
|
|
178
199
|
commit: string;
|
|
179
200
|
handle?: string;
|
|
180
|
-
}): Promise<{
|
|
201
|
+
}, token?: string): Promise<{
|
|
181
202
|
status: string;
|
|
182
203
|
both_committed: boolean;
|
|
183
204
|
}>;
|
|
@@ -186,7 +207,7 @@ export declare class CoordinationGameApiClient {
|
|
|
186
207
|
step: number;
|
|
187
208
|
signature: string;
|
|
188
209
|
handle?: string;
|
|
189
|
-
}): Promise<{
|
|
210
|
+
}, token?: string): Promise<{
|
|
190
211
|
status: string;
|
|
191
212
|
relayed: boolean;
|
|
192
213
|
r_matchup: string | null;
|
|
@@ -195,7 +216,7 @@ export declare class CoordinationGameApiClient {
|
|
|
195
216
|
wallet: string;
|
|
196
217
|
preimage: string;
|
|
197
218
|
handle?: string;
|
|
198
|
-
}): Promise<{
|
|
219
|
+
}, token?: string): Promise<{
|
|
199
220
|
status: string;
|
|
200
221
|
both_revealed: boolean;
|
|
201
222
|
}>;
|
|
@@ -203,7 +224,7 @@ export declare class CoordinationGameApiClient {
|
|
|
203
224
|
handle: string;
|
|
204
225
|
} | {
|
|
205
226
|
wallet: string;
|
|
206
|
-
}): Promise<XGameplayView>;
|
|
227
|
+
}, token?: string): Promise<XGameplayView>;
|
|
207
228
|
submitCrossChainSettleSigs(body: {
|
|
208
229
|
handle?: string;
|
|
209
230
|
wallet?: string;
|
|
@@ -216,29 +237,43 @@ export declare class CoordinationGameApiClient {
|
|
|
216
237
|
live_signature?: string;
|
|
217
238
|
outcome_signature?: string;
|
|
218
239
|
}, token?: string): Promise<XOutcomeCertPayload>;
|
|
240
|
+
buildCrossChainSolFund(body: {
|
|
241
|
+
handle?: string;
|
|
242
|
+
wallet?: string;
|
|
243
|
+
payer?: string;
|
|
244
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
245
|
+
buildCrossChainSolLock(body: {
|
|
246
|
+
handle?: string;
|
|
247
|
+
wallet?: string;
|
|
248
|
+
payer?: string;
|
|
249
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
219
250
|
buildCrossChainSolSettle(body: {
|
|
220
251
|
handle?: string;
|
|
221
252
|
wallet?: string;
|
|
222
253
|
payer?: string;
|
|
223
254
|
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
255
|
+
buildCrossChainSolRefund(body: {
|
|
256
|
+
handle?: string;
|
|
257
|
+
wallet?: string;
|
|
258
|
+
payer?: string;
|
|
259
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
260
|
+
joinEvmGame(body: EvmGameJoinInput, token?: string): Promise<EvmJoinResponse>;
|
|
261
|
+
evmGameStatus(walletOrBy: string | {
|
|
262
|
+
wallet?: string;
|
|
263
|
+
handle?: string;
|
|
229
264
|
}, token?: string): Promise<EvmJoinResponse>;
|
|
230
|
-
evmGameStatus(wallet: string, token?: string): Promise<EvmJoinResponse>;
|
|
231
265
|
evmGameCommitted(body: {
|
|
232
266
|
game_id: string;
|
|
233
267
|
wallet: string;
|
|
234
|
-
}): Promise<{
|
|
268
|
+
}, token?: string): Promise<{
|
|
235
269
|
status: string;
|
|
236
270
|
both_committed: boolean;
|
|
237
271
|
r_matchup: string | null;
|
|
238
272
|
}>;
|
|
239
273
|
evmGameStaked(body: {
|
|
240
274
|
game_id: string;
|
|
241
|
-
|
|
275
|
+
wallet?: string;
|
|
276
|
+
}, token?: string): Promise<{
|
|
242
277
|
status: string;
|
|
243
278
|
}>;
|
|
244
279
|
}
|