@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
|
@@ -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.7";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.4.
|
|
1
|
+
export const CLIENT_VERSION = "0.4.7";
|