@swarm-tips/client 0.4.6 → 0.4.8
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 +40 -3
- package/dist/agent.js +116 -15
- package/dist/cli/keyfile.d.ts +3 -2
- package/dist/cli/keyfile.js +21 -4
- package/dist/cli/lean-init.d.ts +39 -0
- package/dist/cli/lean-init.js +231 -0
- package/dist/cli/swarm.js +197 -15
- 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 +155 -7
- package/dist/shillbot/api.js +32 -6
- 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 +2 -1
package/dist/shillbot/api.js
CHANGED
|
@@ -55,8 +55,13 @@ export class ShillbotApiClient {
|
|
|
55
55
|
listAgentTasks() {
|
|
56
56
|
return this.get("/agent/tasks");
|
|
57
57
|
}
|
|
58
|
-
listPendingApproval() {
|
|
59
|
-
|
|
58
|
+
listPendingApproval(networkOrOpts) {
|
|
59
|
+
const network = typeof networkOrOpts === "string" ? networkOrOpts : networkOrOpts?.network;
|
|
60
|
+
const token = typeof networkOrOpts === "object" && networkOrOpts !== null
|
|
61
|
+
? networkOrOpts.token
|
|
62
|
+
: undefined;
|
|
63
|
+
const suffix = network ? `?network=${encodeURIComponent(network)}` : "";
|
|
64
|
+
return this.http.get(`/client/pending-approval${suffix}`, token);
|
|
60
65
|
}
|
|
61
66
|
listCampaigns() {
|
|
62
67
|
return this.get("/campaigns");
|
|
@@ -94,8 +99,29 @@ export class ShillbotApiClient {
|
|
|
94
99
|
submitTask(id, body) {
|
|
95
100
|
return this.post(`/tasks/${encodeURIComponent(id)}/submit`, body);
|
|
96
101
|
}
|
|
97
|
-
preflightTask(
|
|
98
|
-
|
|
102
|
+
preflightTask(taskId, body, opts) {
|
|
103
|
+
const trimmed = taskId.trim();
|
|
104
|
+
if (!trimmed) {
|
|
105
|
+
throw new SwarmClientError({
|
|
106
|
+
code: "INVALID_ARGUMENT",
|
|
107
|
+
operation: "shillbot.preflightTask",
|
|
108
|
+
message: "Task id is required",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const suffix = opts?.network ? `?network=${encodeURIComponent(opts.network)}` : "";
|
|
112
|
+
return this.http.post(`/tasks/${encodeURIComponent(trimmed)}/preflight${suffix}`, body ?? {}, opts?.token);
|
|
113
|
+
}
|
|
114
|
+
listProofs(opts) {
|
|
115
|
+
const params = new URLSearchParams();
|
|
116
|
+
if (opts?.network)
|
|
117
|
+
params.set("network", opts.network);
|
|
118
|
+
if (opts?.limit !== undefined)
|
|
119
|
+
params.set("limit", String(opts.limit));
|
|
120
|
+
if (opts?.policy !== undefined)
|
|
121
|
+
params.set("policy", String(opts.policy));
|
|
122
|
+
const qs = params.toString();
|
|
123
|
+
const path = qs ? `/proofs?${qs}` : "/proofs";
|
|
124
|
+
return this.http.get(path, null);
|
|
99
125
|
}
|
|
100
126
|
approveTask(id) {
|
|
101
127
|
return this.post(`/tasks/${encodeURIComponent(id)}/approve`);
|
|
@@ -178,8 +204,8 @@ export class ShillbotApiClient {
|
|
|
178
204
|
return this.post(`/tasks/${encodeURIComponent(id)}/confirm`, body);
|
|
179
205
|
}
|
|
180
206
|
}
|
|
181
|
-
import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
182
|
-
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, };
|
|
207
|
+
import { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
208
|
+
export { EXTENSION_CREDIT_PROGRAM_ID, MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, };
|
|
183
209
|
const SWITCHBOARD_PROGRAM_IDS = {
|
|
184
210
|
mainnet: "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv",
|
|
185
211
|
devnet: "Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2",
|
package/dist/shillbot/index.d.ts
CHANGED
|
@@ -151,4 +151,4 @@ export declare const buildExpire: (request: Omit<ExpireBuild, "action">) => Buil
|
|
|
151
151
|
export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
|
|
152
152
|
export type { SwitchboardVerifyRequest } from "./switchboard.js";
|
|
153
153
|
export * from "./payout-oracle.js";
|
|
154
|
-
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, } from "./verify-tx.js";
|
|
154
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, type AuthoritySlotRule, type ShillbotInstructionName, type ShillbotInstructionSpec, type VerifyBuiltTransactionExpectation, } from "./verify-tx.js";
|
package/dist/shillbot/index.js
CHANGED
|
@@ -481,4 +481,4 @@ export const buildExpire = (request) => buildTransaction({ ...request, action: "
|
|
|
481
481
|
export { buildSwitchboardCrankAndVerify } from "./switchboard.js";
|
|
482
482
|
export * from "./payout-oracle.js";
|
|
483
483
|
import { validateComputeBudgetInstructions } from "./verify-tx.js";
|
|
484
|
-
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
484
|
+
export { MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, SHILLBOT_INSTRUCTION_SPECS, deriveAdvancePda, validateComputeBudgetInstruction, validateComputeBudgetInstructions, verifyBuiltTransaction, } from "./verify-tx.js";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type Action, type Network, type TransactionInspection } from "./index.js";
|
|
1
|
+
import { advancePda, type Action, type Network, type TransactionInspection } from "./index.js";
|
|
2
|
+
/** Alias for `advancePda` (`seeds = [b"advance", sponsorPubkey, agentPubkey]`). */
|
|
3
|
+
export declare const deriveAdvancePda: typeof advancePda;
|
|
2
4
|
/** Default maximum allowed Solana priority fee price per compute unit (`100_000` micro-lamports/CU). */
|
|
3
5
|
export declare const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
|
|
4
6
|
/** Solana runtime ceiling for `ComputeBudget::SetComputeUnitLimit` (`1_400_000` CUs). */
|
|
@@ -27,10 +29,13 @@ export interface VerifyBuiltTransactionExpectation {
|
|
|
27
29
|
wallet: string;
|
|
28
30
|
taskPda?: string;
|
|
29
31
|
feePayer?: string;
|
|
32
|
+
/** Optional alias for `feePayer` when pinning a known gas sponsor pubkey. */
|
|
33
|
+
sponsor?: string;
|
|
30
34
|
/**
|
|
31
35
|
* Explicit authorized payout destination pubkey (base58).
|
|
32
|
-
* Required whenever a `set_payout_to` instruction is present
|
|
33
|
-
* `
|
|
36
|
+
* Required whenever a `set_payout_to` instruction is present on self-paid transactions;
|
|
37
|
+
* on sponsored `claim`/`submit` (`fee_payer !== wallet`), deterministic
|
|
38
|
+
* `advancePda(fee_payer, wallet)` is also authorized.
|
|
34
39
|
*/
|
|
35
40
|
payoutTo?: string;
|
|
36
41
|
/**
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import { ComputeBudgetProgram, PublicKey, Secp256k1Program } from "@solana/web3.js";
|
|
3
3
|
import { SHILLBOT_PROGRAM_ID, shillbotInstructionDiscriminator } from "../contracts/index.js";
|
|
4
|
-
import { SwarmClientError } from "../errors.js";
|
|
4
|
+
import { SwarmClientError, TransactionMismatchError } from "../errors.js";
|
|
5
5
|
import { EXTENSION_CREDIT_PROGRAM_ID, advancePda, inspectTransaction, routeAndRecoupDiscriminator, } from "./index.js";
|
|
6
|
+
/** Alias for `advancePda` (`seeds = [b"advance", sponsorPubkey, agentPubkey]`). */
|
|
7
|
+
export const deriveAdvancePda = advancePda;
|
|
6
8
|
/** Default maximum allowed Solana priority fee price per compute unit (`100_000` micro-lamports/CU). */
|
|
7
9
|
export const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 100000n;
|
|
8
10
|
/** Solana runtime ceiling for `ComputeBudget::SetComputeUnitLimit` (`1_400_000` CUs). */
|
|
@@ -218,8 +220,7 @@ const DISCRIMINATOR_TO_SPEC = (() => {
|
|
|
218
220
|
return map;
|
|
219
221
|
})();
|
|
220
222
|
function txMismatch(operation, message) {
|
|
221
|
-
return new
|
|
222
|
-
code: "TRANSACTION_MISMATCH",
|
|
223
|
+
return new TransactionMismatchError({
|
|
223
224
|
operation,
|
|
224
225
|
message,
|
|
225
226
|
});
|
|
@@ -382,7 +383,7 @@ function verifyInstructionAuthorityAndShape(decoded, inspected, expected, operat
|
|
|
382
383
|
if (spec.exactAccounts !== undefined && ix.accounts.length !== spec.exactAccounts) {
|
|
383
384
|
throw txMismatch(operation, `Instruction ${spec.name} requires exact ${spec.exactAccounts} accounts, got ${ix.accounts.length}`);
|
|
384
385
|
}
|
|
385
|
-
const expectedFeePayer = expected.feePayer ?? expected.wallet;
|
|
386
|
+
const expectedFeePayer = expected.feePayer ?? expected.sponsor ?? expected.wallet;
|
|
386
387
|
if (!spec.allowsSponsoredFeePayer && inspected.fee_payer !== expectedFeePayer) {
|
|
387
388
|
throw txMismatch(operation, `Instruction ${spec.name} requires fee_payer ${expectedFeePayer}, got ${inspected.fee_payer}`);
|
|
388
389
|
}
|
|
@@ -459,6 +460,15 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
459
460
|
if (expected.feePayer !== undefined) {
|
|
460
461
|
parseValidatedPubkey(expected.feePayer, "feePayer", operation);
|
|
461
462
|
}
|
|
463
|
+
if (expected.sponsor !== undefined) {
|
|
464
|
+
parseValidatedPubkey(expected.sponsor, "sponsor", operation);
|
|
465
|
+
}
|
|
466
|
+
if (expected.feePayer !== undefined &&
|
|
467
|
+
expected.sponsor !== undefined &&
|
|
468
|
+
expected.feePayer !== expected.sponsor) {
|
|
469
|
+
throw invalidArg(operation, "expected.feePayer and expected.sponsor must match when both are provided");
|
|
470
|
+
}
|
|
471
|
+
const explicitFeePayer = expected.feePayer ?? expected.sponsor;
|
|
462
472
|
if (expected.oracleAuthority !== undefined) {
|
|
463
473
|
parseValidatedPubkey(expected.oracleAuthority, "oracleAuthority", operation);
|
|
464
474
|
}
|
|
@@ -479,7 +489,7 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
479
489
|
if (!inspected.signers.includes(expected.wallet)) {
|
|
480
490
|
throw txMismatch(operation, "Wallet is not a required signer");
|
|
481
491
|
}
|
|
482
|
-
if (
|
|
492
|
+
if (explicitFeePayer && inspected.fee_payer !== explicitFeePayer) {
|
|
483
493
|
throw txMismatch(operation, "Fee payer differs from expectation");
|
|
484
494
|
}
|
|
485
495
|
const isVerifyContext = expected.action === "verify" ||
|
|
@@ -661,6 +671,25 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
661
671
|
const isVerifyLifecycle = expected.action === "verify" ||
|
|
662
672
|
primary.spec.name === "verify_task" ||
|
|
663
673
|
primary.spec.name === "verify_task_attested";
|
|
674
|
+
const isSponsoredClaimOrSubmit = (isClaimLifecycle || isSubmitLifecycle) && inspected.fee_payer !== expected.wallet;
|
|
675
|
+
const derivedAdvancePda = isSponsoredClaimOrSubmit
|
|
676
|
+
? advancePda(inspected.fee_payer, expected.wallet)
|
|
677
|
+
: undefined;
|
|
678
|
+
const requiresAdvancePayout = isSponsoredClaimOrSubmit && explicitFeePayer === undefined;
|
|
679
|
+
if (inspected.fee_payer !== expected.wallet &&
|
|
680
|
+
explicitFeePayer === undefined &&
|
|
681
|
+
!isSponsoredClaimOrSubmit &&
|
|
682
|
+
!(primary.spec.name === "verify_task_attested" && primary.ix.accounts[2] === expected.wallet)) {
|
|
683
|
+
throw txMismatch(operation, `Fee payer ${inspected.fee_payer} differs from expected wallet ${expected.wallet}`);
|
|
684
|
+
}
|
|
685
|
+
if (requiresAdvancePayout &&
|
|
686
|
+
expectedPayoutPubkey &&
|
|
687
|
+
!expectedPayoutPubkey.equals(derivedAdvancePda)) {
|
|
688
|
+
throw txMismatch(operation, `set_payout_to destination pubkey ${expectedPayoutPubkey.toBase58()} differs from deterministic Advance PDA ${derivedAdvancePda.toBase58()}`);
|
|
689
|
+
}
|
|
690
|
+
const authorizedPayoutPubkey = requiresAdvancePayout
|
|
691
|
+
? derivedAdvancePda
|
|
692
|
+
: (expectedPayoutPubkey ?? derivedAdvancePda);
|
|
664
693
|
if (companions.length === 0) {
|
|
665
694
|
if (expectedPayoutPubkey &&
|
|
666
695
|
primary.spec.name !== "set_payout_to" &&
|
|
@@ -678,16 +707,19 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
678
707
|
validateSetPayoutToInstruction(companions[0], expected.wallet, primary.ix.accounts[0], expectedPayoutPubkey, operation);
|
|
679
708
|
return inspected;
|
|
680
709
|
}
|
|
681
|
-
if (isClaimLifecycle &&
|
|
710
|
+
if ((isClaimLifecycle || isSubmitLifecycle) &&
|
|
682
711
|
companions.length === 1 &&
|
|
683
712
|
companions[0].spec.name === "set_payout_to") {
|
|
684
|
-
if (primary.spec.name !== "claim_task") {
|
|
713
|
+
if (isClaimLifecycle && primary.spec.name !== "claim_task") {
|
|
685
714
|
throw txMismatch(operation, "set_payout_to companion requires direct agent claim_task");
|
|
686
715
|
}
|
|
687
|
-
if (
|
|
716
|
+
if (isSubmitLifecycle && primary.spec.name !== "submit_work") {
|
|
717
|
+
throw txMismatch(operation, "set_payout_to companion requires direct agent submit_work");
|
|
718
|
+
}
|
|
719
|
+
if (isClaimLifecycle && companions[0].txIndex <= primary.txIndex) {
|
|
688
720
|
throw txMismatch(operation, "payout route must follow claim");
|
|
689
721
|
}
|
|
690
|
-
validateSetPayoutToInstruction(companions[0], expected.wallet, primary.ix.accounts[0],
|
|
722
|
+
validateSetPayoutToInstruction(companions[0], expected.wallet, primary.ix.accounts[0], authorizedPayoutPubkey, operation);
|
|
691
723
|
return inspected;
|
|
692
724
|
}
|
|
693
725
|
// Optional leading score-0 reopen (`verify_task` or `verify_task_attested` with score == 0)
|
|
@@ -741,13 +773,16 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
741
773
|
submitCompanions.length === 2 &&
|
|
742
774
|
submitCompanions[0].spec.name === "claim_task" &&
|
|
743
775
|
submitCompanions[1].spec.name === "set_payout_to") {
|
|
776
|
+
const isClaimPayoutSubmit = submitCompanions[1].txIndex === submitCompanions[0].txIndex + 1 &&
|
|
777
|
+
primary.txIndex === submitCompanions[1].txIndex + 1;
|
|
778
|
+
const isClaimSubmitPayout = primary.txIndex === submitCompanions[0].txIndex + 1 &&
|
|
779
|
+
submitCompanions[1].txIndex === primary.txIndex + 1;
|
|
744
780
|
if (primary.spec.name !== "submit_work" ||
|
|
745
|
-
|
|
746
|
-
primary.txIndex !== submitCompanions[1].txIndex + 1 ||
|
|
781
|
+
(!isClaimPayoutSubmit && !isClaimSubmitPayout) ||
|
|
747
782
|
!validateClaimCompanion(submitCompanions[0])) {
|
|
748
783
|
throw txMismatch(operation, "Expected exactly one matching Shillbot lifecycle instruction");
|
|
749
784
|
}
|
|
750
|
-
validateSetPayoutToInstruction(submitCompanions[1], expected.wallet, primary.ix.accounts[0],
|
|
785
|
+
validateSetPayoutToInstruction(submitCompanions[1], expected.wallet, primary.ix.accounts[0], authorizedPayoutPubkey, operation);
|
|
751
786
|
return inspected;
|
|
752
787
|
}
|
|
753
788
|
if (companions.some((c) => c.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.8";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.4.
|
|
1
|
+
export const CLIENT_VERSION = "0.4.8";
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swarm-tips/client",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
|
+
"mcpName": "io.github.corsur/swarm-tips",
|
|
4
5
|
"description": "Typed browser and Node.js clients for Swarm Tips, Shillbot, and Coordination Game",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/index.js",
|