@oobe-protocol-labs/synapse-sap-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +882 -0
- package/dist/cjs/constants/index.js +43 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/limits.js +161 -0
- package/dist/cjs/constants/limits.js.map +1 -0
- package/dist/cjs/constants/programs.js +78 -0
- package/dist/cjs/constants/programs.js.map +1 -0
- package/dist/cjs/constants/seeds.js +57 -0
- package/dist/cjs/constants/seeds.js.map +1 -0
- package/dist/cjs/core/client.js +391 -0
- package/dist/cjs/core/client.js.map +1 -0
- package/dist/cjs/core/connection.js +319 -0
- package/dist/cjs/core/connection.js.map +1 -0
- package/dist/cjs/core/index.js +24 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/errors/index.js +334 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/events/index.js +136 -0
- package/dist/cjs/events/index.js.map +1 -0
- package/dist/cjs/idl/index.js +63 -0
- package/dist/cjs/idl/index.js.map +1 -0
- package/dist/cjs/idl/synapse_agent_sap.json +9710 -0
- package/dist/cjs/index.js +147 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules/agent.js +272 -0
- package/dist/cjs/modules/agent.js.map +1 -0
- package/dist/cjs/modules/attestation.js +147 -0
- package/dist/cjs/modules/attestation.js.map +1 -0
- package/dist/cjs/modules/base.js +128 -0
- package/dist/cjs/modules/base.js.map +1 -0
- package/dist/cjs/modules/escrow.js +246 -0
- package/dist/cjs/modules/escrow.js.map +1 -0
- package/dist/cjs/modules/feedback.js +166 -0
- package/dist/cjs/modules/feedback.js.map +1 -0
- package/dist/cjs/modules/index.js +35 -0
- package/dist/cjs/modules/index.js.map +1 -0
- package/dist/cjs/modules/indexing.js +375 -0
- package/dist/cjs/modules/indexing.js.map +1 -0
- package/dist/cjs/modules/ledger.js +234 -0
- package/dist/cjs/modules/ledger.js.map +1 -0
- package/dist/cjs/modules/tools.js +319 -0
- package/dist/cjs/modules/tools.js.map +1 -0
- package/dist/cjs/modules/vault.js +410 -0
- package/dist/cjs/modules/vault.js.map +1 -0
- package/dist/cjs/pda/index.js +377 -0
- package/dist/cjs/pda/index.js.map +1 -0
- package/dist/cjs/plugin/index.js +934 -0
- package/dist/cjs/plugin/index.js.map +1 -0
- package/dist/cjs/plugin/protocols.js +282 -0
- package/dist/cjs/plugin/protocols.js.map +1 -0
- package/dist/cjs/plugin/schemas.js +831 -0
- package/dist/cjs/plugin/schemas.js.map +1 -0
- package/dist/cjs/postgres/adapter.js +715 -0
- package/dist/cjs/postgres/adapter.js.map +1 -0
- package/dist/cjs/postgres/index.js +50 -0
- package/dist/cjs/postgres/index.js.map +1 -0
- package/dist/cjs/postgres/serializers.js +381 -0
- package/dist/cjs/postgres/serializers.js.map +1 -0
- package/dist/cjs/postgres/sync.js +221 -0
- package/dist/cjs/postgres/sync.js.map +1 -0
- package/dist/cjs/postgres/types.js +44 -0
- package/dist/cjs/postgres/types.js.map +1 -0
- package/dist/cjs/registries/builder.js +414 -0
- package/dist/cjs/registries/builder.js.map +1 -0
- package/dist/cjs/registries/discovery.js +362 -0
- package/dist/cjs/registries/discovery.js.map +1 -0
- package/dist/cjs/registries/index.js +51 -0
- package/dist/cjs/registries/index.js.map +1 -0
- package/dist/cjs/registries/session.js +433 -0
- package/dist/cjs/registries/session.js.map +1 -0
- package/dist/cjs/registries/x402.js +577 -0
- package/dist/cjs/registries/x402.js.map +1 -0
- package/dist/cjs/types/accounts.js +13 -0
- package/dist/cjs/types/accounts.js.map +1 -0
- package/dist/cjs/types/common.js +13 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/enums.js +174 -0
- package/dist/cjs/types/enums.js.map +1 -0
- package/dist/cjs/types/index.js +36 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/instructions.js +92 -0
- package/dist/cjs/types/instructions.js.map +1 -0
- package/dist/cjs/utils/hash.js +58 -0
- package/dist/cjs/utils/hash.js.map +1 -0
- package/dist/cjs/utils/index.js +27 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/serialization.js +105 -0
- package/dist/cjs/utils/serialization.js.map +1 -0
- package/dist/cjs/utils/validation.js +36 -0
- package/dist/cjs/utils/validation.js.map +1 -0
- package/dist/esm/constants/index.js +29 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/limits.js +158 -0
- package/dist/esm/constants/limits.js.map +1 -0
- package/dist/esm/constants/programs.js +75 -0
- package/dist/esm/constants/programs.js.map +1 -0
- package/dist/esm/constants/seeds.js +54 -0
- package/dist/esm/constants/seeds.js.map +1 -0
- package/dist/esm/core/client.js +384 -0
- package/dist/esm/core/client.js.map +1 -0
- package/dist/esm/core/connection.js +315 -0
- package/dist/esm/core/connection.js.map +1 -0
- package/dist/esm/core/index.js +19 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/errors/index.js +325 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/events/index.js +132 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/idl/index.js +57 -0
- package/dist/esm/idl/index.js.map +1 -0
- package/dist/esm/idl/synapse_agent_sap.json +9710 -0
- package/dist/esm/index.js +70 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules/agent.js +268 -0
- package/dist/esm/modules/agent.js.map +1 -0
- package/dist/esm/modules/attestation.js +143 -0
- package/dist/esm/modules/attestation.js.map +1 -0
- package/dist/esm/modules/base.js +124 -0
- package/dist/esm/modules/base.js.map +1 -0
- package/dist/esm/modules/escrow.js +242 -0
- package/dist/esm/modules/escrow.js.map +1 -0
- package/dist/esm/modules/feedback.js +162 -0
- package/dist/esm/modules/feedback.js.map +1 -0
- package/dist/esm/modules/index.js +23 -0
- package/dist/esm/modules/index.js.map +1 -0
- package/dist/esm/modules/indexing.js +371 -0
- package/dist/esm/modules/indexing.js.map +1 -0
- package/dist/esm/modules/ledger.js +230 -0
- package/dist/esm/modules/ledger.js.map +1 -0
- package/dist/esm/modules/tools.js +315 -0
- package/dist/esm/modules/tools.js.map +1 -0
- package/dist/esm/modules/vault.js +406 -0
- package/dist/esm/modules/vault.js.map +1 -0
- package/dist/esm/pda/index.js +357 -0
- package/dist/esm/pda/index.js.map +1 -0
- package/dist/esm/plugin/index.js +927 -0
- package/dist/esm/plugin/index.js.map +1 -0
- package/dist/esm/plugin/protocols.js +279 -0
- package/dist/esm/plugin/protocols.js.map +1 -0
- package/dist/esm/plugin/schemas.js +828 -0
- package/dist/esm/plugin/schemas.js.map +1 -0
- package/dist/esm/postgres/adapter.js +678 -0
- package/dist/esm/postgres/adapter.js.map +1 -0
- package/dist/esm/postgres/index.js +27 -0
- package/dist/esm/postgres/index.js.map +1 -0
- package/dist/esm/postgres/serializers.js +362 -0
- package/dist/esm/postgres/serializers.js.map +1 -0
- package/dist/esm/postgres/sync.js +217 -0
- package/dist/esm/postgres/sync.js.map +1 -0
- package/dist/esm/postgres/types.js +41 -0
- package/dist/esm/postgres/types.js.map +1 -0
- package/dist/esm/registries/builder.js +410 -0
- package/dist/esm/registries/builder.js.map +1 -0
- package/dist/esm/registries/discovery.js +358 -0
- package/dist/esm/registries/discovery.js.map +1 -0
- package/dist/esm/registries/index.js +44 -0
- package/dist/esm/registries/index.js.map +1 -0
- package/dist/esm/registries/session.js +429 -0
- package/dist/esm/registries/session.js.map +1 -0
- package/dist/esm/registries/x402.js +573 -0
- package/dist/esm/registries/x402.js.map +1 -0
- package/dist/esm/types/accounts.js +12 -0
- package/dist/esm/types/accounts.js.map +1 -0
- package/dist/esm/types/common.js +12 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/enums.js +171 -0
- package/dist/esm/types/enums.js.map +1 -0
- package/dist/esm/types/index.js +25 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/instructions.js +89 -0
- package/dist/esm/types/instructions.js.map +1 -0
- package/dist/esm/utils/hash.js +53 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/index.js +19 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/serialization.js +98 -0
- package/dist/esm/utils/serialization.js.map +1 -0
- package/dist/esm/utils/validation.js +33 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/dist/types/constants/index.d.ts +27 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/constants/limits.d.ts +149 -0
- package/dist/types/constants/limits.d.ts.map +1 -0
- package/dist/types/constants/programs.d.ts +69 -0
- package/dist/types/constants/programs.d.ts.map +1 -0
- package/dist/types/constants/seeds.d.ts +61 -0
- package/dist/types/constants/seeds.d.ts.map +1 -0
- package/dist/types/core/client.d.ts +323 -0
- package/dist/types/core/client.d.ts.map +1 -0
- package/dist/types/core/connection.d.ts +279 -0
- package/dist/types/core/connection.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +20 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +276 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +248 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/idl/index.d.ts +70 -0
- package/dist/types/idl/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/agent.d.ts +166 -0
- package/dist/types/modules/agent.d.ts.map +1 -0
- package/dist/types/modules/attestation.d.ts +96 -0
- package/dist/types/modules/attestation.d.ts.map +1 -0
- package/dist/types/modules/base.d.ts +126 -0
- package/dist/types/modules/base.d.ts.map +1 -0
- package/dist/types/modules/escrow.d.ts +151 -0
- package/dist/types/modules/escrow.d.ts.map +1 -0
- package/dist/types/modules/feedback.d.ts +105 -0
- package/dist/types/modules/feedback.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +24 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/modules/indexing.d.ts +200 -0
- package/dist/types/modules/indexing.d.ts.map +1 -0
- package/dist/types/modules/ledger.d.ts +150 -0
- package/dist/types/modules/ledger.d.ts.map +1 -0
- package/dist/types/modules/tools.d.ts +182 -0
- package/dist/types/modules/tools.d.ts.map +1 -0
- package/dist/types/modules/vault.d.ts +240 -0
- package/dist/types/modules/vault.d.ts.map +1 -0
- package/dist/types/pda/index.d.ts +296 -0
- package/dist/types/pda/index.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +171 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/plugin/protocols.d.ts +152 -0
- package/dist/types/plugin/protocols.d.ts.map +1 -0
- package/dist/types/plugin/schemas.d.ts +823 -0
- package/dist/types/plugin/schemas.d.ts.map +1 -0
- package/dist/types/postgres/adapter.d.ts +355 -0
- package/dist/types/postgres/adapter.d.ts.map +1 -0
- package/dist/types/postgres/index.d.ts +24 -0
- package/dist/types/postgres/index.d.ts.map +1 -0
- package/dist/types/postgres/serializers.d.ts +30 -0
- package/dist/types/postgres/serializers.d.ts.map +1 -0
- package/dist/types/postgres/sync.d.ts +132 -0
- package/dist/types/postgres/sync.d.ts.map +1 -0
- package/dist/types/postgres/types.d.ts +167 -0
- package/dist/types/postgres/types.d.ts.map +1 -0
- package/dist/types/registries/builder.d.ts +340 -0
- package/dist/types/registries/builder.d.ts.map +1 -0
- package/dist/types/registries/discovery.d.ts +333 -0
- package/dist/types/registries/discovery.d.ts.map +1 -0
- package/dist/types/registries/index.d.ts +48 -0
- package/dist/types/registries/index.d.ts.map +1 -0
- package/dist/types/registries/session.d.ts +323 -0
- package/dist/types/registries/session.d.ts.map +1 -0
- package/dist/types/registries/x402.d.ts +463 -0
- package/dist/types/registries/x402.d.ts.map +1 -0
- package/dist/types/types/accounts.d.ts +565 -0
- package/dist/types/types/accounts.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +166 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/enums.d.ts +238 -0
- package/dist/types/types/enums.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +28 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/instructions.d.ts +366 -0
- package/dist/types/types/instructions.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +48 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +19 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/serialization.d.ts +69 -0
- package/dist/types/utils/serialization.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts +29 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/constants/index.ts +44 -0
- package/src/constants/limits.ts +165 -0
- package/src/constants/programs.ts +83 -0
- package/src/constants/seeds.ts +66 -0
- package/src/core/client.ts +416 -0
- package/src/core/connection.ts +409 -0
- package/src/core/index.ts +20 -0
- package/src/errors/index.ts +346 -0
- package/src/events/index.ts +335 -0
- package/src/idl/index.ts +76 -0
- package/src/idl/synapse_agent_sap.json +9710 -0
- package/src/index.ts +253 -0
- package/src/modules/agent.ts +319 -0
- package/src/modules/attestation.ts +168 -0
- package/src/modules/base.ts +158 -0
- package/src/modules/escrow.ts +308 -0
- package/src/modules/feedback.ts +186 -0
- package/src/modules/index.ts +24 -0
- package/src/modules/indexing.ts +444 -0
- package/src/modules/ledger.ts +262 -0
- package/src/modules/tools.ts +411 -0
- package/src/modules/vault.ts +533 -0
- package/src/pda/index.ts +512 -0
- package/src/plugin/index.ts +1202 -0
- package/src/plugin/protocols.ts +404 -0
- package/src/plugin/schemas.ts +909 -0
- package/src/postgres/adapter.ts +904 -0
- package/src/postgres/index.ts +59 -0
- package/src/postgres/schema.sql +683 -0
- package/src/postgres/serializers.ts +485 -0
- package/src/postgres/sync.ts +254 -0
- package/src/postgres/types.ts +245 -0
- package/src/registries/builder.ts +607 -0
- package/src/registries/discovery.ts +572 -0
- package/src/registries/index.ts +77 -0
- package/src/registries/session.ts +613 -0
- package/src/registries/x402.ts +906 -0
- package/src/types/accounts.ts +618 -0
- package/src/types/common.ts +187 -0
- package/src/types/enums.ts +214 -0
- package/src/types/index.ts +92 -0
- package/src/types/instructions.ts +413 -0
- package/src/utils/hash.ts +57 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/serialization.ts +98 -0
- package/src/utils/validation.ts +36 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module feedback
|
|
3
|
+
* @description Trustless reputation system — give, update, revoke, and close
|
|
4
|
+
* on-chain feedback entries for agents.
|
|
5
|
+
*
|
|
6
|
+
* Feedback entries are PDA-based reviews tied to an agent and a reviewer wallet,
|
|
7
|
+
* enabling permissionless, verifiable reputation on Solana.
|
|
8
|
+
*
|
|
9
|
+
* @category Modules
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { SystemProgram, type PublicKey, type TransactionSignature } from "@solana/web3.js";
|
|
15
|
+
import { BaseModule } from "./base";
|
|
16
|
+
import { deriveAgent, deriveFeedback, deriveGlobalRegistry } from "../pda";
|
|
17
|
+
import type { FeedbackAccountData, GiveFeedbackArgs, UpdateFeedbackArgs } from "../types";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @name FeedbackModule
|
|
21
|
+
* @description Manages on-chain feedback entries for the Solana Agent Protocol.
|
|
22
|
+
* Provides methods to give, update, revoke, close, and fetch feedback PDAs
|
|
23
|
+
* that form the trustless reputation layer.
|
|
24
|
+
*
|
|
25
|
+
* @category Modules
|
|
26
|
+
* @since v0.1.0
|
|
27
|
+
* @extends BaseModule
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const sap = new SapClient(provider);
|
|
32
|
+
* const sig = await sap.feedback.give(agentWallet, {
|
|
33
|
+
* score: 5,
|
|
34
|
+
* tag: { quality: {} },
|
|
35
|
+
* commentHash: null,
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class FeedbackModule extends BaseModule {
|
|
40
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @name deriveFeedback
|
|
44
|
+
* @description Derive the `FeedbackAccount` PDA for a given agent and reviewer.
|
|
45
|
+
* @param agentPda - The agent account PDA to review.
|
|
46
|
+
* @param reviewer - The reviewer wallet. Defaults to the connected wallet.
|
|
47
|
+
* @returns A tuple of `[PublicKey, bump]` for the feedback PDA.
|
|
48
|
+
* @see {@link deriveFeedback} from `pda/` module for the underlying derivation.
|
|
49
|
+
* @since v0.1.0
|
|
50
|
+
*/
|
|
51
|
+
deriveFeedback(
|
|
52
|
+
agentPda: PublicKey,
|
|
53
|
+
reviewer?: PublicKey,
|
|
54
|
+
): readonly [PublicKey, number] {
|
|
55
|
+
return deriveFeedback(agentPda, reviewer ?? this.walletPubkey);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ── Instructions ─────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @name give
|
|
62
|
+
* @description Leave on-chain feedback for an agent. Creates a new
|
|
63
|
+
* `FeedbackAccount` PDA owned by the reviewer.
|
|
64
|
+
* @param agentWallet - The wallet that owns the target agent.
|
|
65
|
+
* @param args - Feedback parameters (score, tag, optional comment hash).
|
|
66
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
67
|
+
* @since v0.1.0
|
|
68
|
+
*/
|
|
69
|
+
async give(
|
|
70
|
+
agentWallet: PublicKey,
|
|
71
|
+
args: GiveFeedbackArgs,
|
|
72
|
+
): Promise<TransactionSignature> {
|
|
73
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
74
|
+
const [feedbackPda] = this.deriveFeedback(agentPda);
|
|
75
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
76
|
+
|
|
77
|
+
return this.methods
|
|
78
|
+
.giveFeedback(args.score, args.tag, args.commentHash ?? null)
|
|
79
|
+
.accounts({
|
|
80
|
+
reviewer: this.walletPubkey,
|
|
81
|
+
agent: agentPda,
|
|
82
|
+
feedback: feedbackPda,
|
|
83
|
+
globalRegistry: globalPda,
|
|
84
|
+
systemProgram: SystemProgram.programId,
|
|
85
|
+
})
|
|
86
|
+
.rpc();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @name update
|
|
91
|
+
* @description Update an existing feedback entry. Only the original reviewer
|
|
92
|
+
* may update their feedback.
|
|
93
|
+
* @param agentWallet - The wallet that owns the target agent.
|
|
94
|
+
* @param args - Updated feedback parameters (new score, optional new tag, optional comment hash).
|
|
95
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
96
|
+
* @since v0.1.0
|
|
97
|
+
*/
|
|
98
|
+
async update(
|
|
99
|
+
agentWallet: PublicKey,
|
|
100
|
+
args: UpdateFeedbackArgs,
|
|
101
|
+
): Promise<TransactionSignature> {
|
|
102
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
103
|
+
const [feedbackPda] = this.deriveFeedback(agentPda);
|
|
104
|
+
|
|
105
|
+
return this.methods
|
|
106
|
+
.updateFeedback(args.newScore, args.newTag ?? null, args.commentHash ?? null)
|
|
107
|
+
.accounts({
|
|
108
|
+
reviewer: this.walletPubkey,
|
|
109
|
+
agent: agentPda,
|
|
110
|
+
feedback: feedbackPda,
|
|
111
|
+
})
|
|
112
|
+
.rpc();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @name revoke
|
|
117
|
+
* @description Revoke a feedback entry, marking it as revoked and excluding
|
|
118
|
+
* it from reputation calculations.
|
|
119
|
+
* @param agentWallet - The wallet that owns the target agent.
|
|
120
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
121
|
+
* @since v0.1.0
|
|
122
|
+
*/
|
|
123
|
+
async revoke(agentWallet: PublicKey): Promise<TransactionSignature> {
|
|
124
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
125
|
+
const [feedbackPda] = this.deriveFeedback(agentPda);
|
|
126
|
+
|
|
127
|
+
return this.methods
|
|
128
|
+
.revokeFeedback()
|
|
129
|
+
.accounts({
|
|
130
|
+
reviewer: this.walletPubkey,
|
|
131
|
+
agent: agentPda,
|
|
132
|
+
feedback: feedbackPda,
|
|
133
|
+
})
|
|
134
|
+
.rpc();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @name close
|
|
139
|
+
* @description Close a revoked feedback PDA and reclaim rent to the reviewer.
|
|
140
|
+
* @param agentWallet - The wallet that owns the target agent.
|
|
141
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
142
|
+
* @since v0.1.0
|
|
143
|
+
*/
|
|
144
|
+
async close(agentWallet: PublicKey): Promise<TransactionSignature> {
|
|
145
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
146
|
+
const [feedbackPda] = this.deriveFeedback(agentPda);
|
|
147
|
+
|
|
148
|
+
return this.methods
|
|
149
|
+
.closeFeedback()
|
|
150
|
+
.accounts({
|
|
151
|
+
reviewer: this.walletPubkey,
|
|
152
|
+
feedback: feedbackPda,
|
|
153
|
+
})
|
|
154
|
+
.rpc();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @name fetch
|
|
161
|
+
* @description Fetch a deserialized `FeedbackAccount`.
|
|
162
|
+
* @param agentPda - The agent account PDA.
|
|
163
|
+
* @param reviewer - The reviewer wallet. Defaults to the connected wallet.
|
|
164
|
+
* @returns {Promise<FeedbackAccountData>} The feedback account data.
|
|
165
|
+
* @throws Will throw if the feedback account does not exist.
|
|
166
|
+
* @since v0.1.0
|
|
167
|
+
*/
|
|
168
|
+
async fetch(agentPda: PublicKey, reviewer?: PublicKey): Promise<FeedbackAccountData> {
|
|
169
|
+
const [pda] = this.deriveFeedback(agentPda, reviewer);
|
|
170
|
+
return this.fetchAccount<FeedbackAccountData>("feedbackAccount", pda);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @name fetchNullable
|
|
175
|
+
* @description Fetch a deserialized `FeedbackAccount`, or `null` if it
|
|
176
|
+
* does not exist on-chain.
|
|
177
|
+
* @param agentPda - The agent account PDA.
|
|
178
|
+
* @param reviewer - The reviewer wallet. Defaults to the connected wallet.
|
|
179
|
+
* @returns {Promise<FeedbackAccountData | null>} The feedback data or `null`.
|
|
180
|
+
* @since v0.1.0
|
|
181
|
+
*/
|
|
182
|
+
async fetchNullable(agentPda: PublicKey, reviewer?: PublicKey): Promise<FeedbackAccountData | null> {
|
|
183
|
+
const [pda] = this.deriveFeedback(agentPda, reviewer);
|
|
184
|
+
return this.fetchAccountNullable<FeedbackAccountData>("feedbackAccount", pda);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modules
|
|
3
|
+
* @description Barrel export for all domain modules of the `@synapse-sap/sdk`.
|
|
4
|
+
*
|
|
5
|
+
* Re-exports every module class so consumers can import from a single entry point:
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { AgentModule, VaultModule } from "@synapse-sap/sdk/modules";
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @category Modules
|
|
11
|
+
* @since v0.1.0
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { AgentModule } from "./agent";
|
|
16
|
+
export { FeedbackModule } from "./feedback";
|
|
17
|
+
export { IndexingModule } from "./indexing";
|
|
18
|
+
export { ToolsModule } from "./tools";
|
|
19
|
+
export { VaultModule } from "./vault";
|
|
20
|
+
export { EscrowModule } from "./escrow";
|
|
21
|
+
export { AttestationModule } from "./attestation";
|
|
22
|
+
export { LedgerModule } from "./ledger";
|
|
23
|
+
export { BaseModule } from "./base";
|
|
24
|
+
export type { SapProgram, SapTransactionResult } from "./base";
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module indexing
|
|
3
|
+
* @description Scalable discovery layer — capability indexes, protocol indexes,
|
|
4
|
+
* and tool category indexes for the Solana Agent Protocol.
|
|
5
|
+
*
|
|
6
|
+
* Indexes are shared PDA-based registries that map agents and tools to
|
|
7
|
+
* discovery dimensions, enabling efficient on-chain lookups.
|
|
8
|
+
*
|
|
9
|
+
* @category Modules
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { SystemProgram, type PublicKey, type TransactionSignature } from "@solana/web3.js";
|
|
15
|
+
import { BaseModule } from "./base";
|
|
16
|
+
import {
|
|
17
|
+
deriveAgent,
|
|
18
|
+
deriveCapabilityIndex,
|
|
19
|
+
deriveProtocolIndex,
|
|
20
|
+
deriveToolCategoryIndex,
|
|
21
|
+
deriveGlobalRegistry,
|
|
22
|
+
} from "../pda";
|
|
23
|
+
import type {
|
|
24
|
+
CapabilityIndexData,
|
|
25
|
+
ProtocolIndexData,
|
|
26
|
+
ToolCategoryIndexData,
|
|
27
|
+
} from "../types";
|
|
28
|
+
import { sha256, hashToArray } from "../utils";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @name IndexingModule
|
|
32
|
+
* @description Manages on-chain discovery indexes for the Solana Agent Protocol.
|
|
33
|
+
* Provides methods to create, populate, prune, close, and fetch capability
|
|
34
|
+
* indexes, protocol indexes, and tool category indexes.
|
|
35
|
+
*
|
|
36
|
+
* @category Modules
|
|
37
|
+
* @since v0.1.0
|
|
38
|
+
* @extends BaseModule
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const sap = new SapClient(provider);
|
|
43
|
+
* // Create a capability index and add your agent
|
|
44
|
+
* await sap.indexing.initCapabilityIndex("text-generation");
|
|
45
|
+
* // Query agents by capability
|
|
46
|
+
* const idx = await sap.indexing.fetchCapabilityIndex("text-generation");
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class IndexingModule extends BaseModule {
|
|
50
|
+
// ── Helpers ──────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @name hash
|
|
54
|
+
* @description Hash a capability or protocol ID string for use as a PDA seed.
|
|
55
|
+
* Uses SHA-256 internally.
|
|
56
|
+
* @param id - The capability or protocol identifier string.
|
|
57
|
+
* @returns {Uint8Array} The 32-byte SHA-256 hash.
|
|
58
|
+
* @since v0.1.0
|
|
59
|
+
*/
|
|
60
|
+
hash(id: string): Uint8Array {
|
|
61
|
+
return sha256(id);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── Capability Index ─────────────────────────────────
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @name initCapabilityIndex
|
|
68
|
+
* @description Create a new capability index and register the caller’s agent.
|
|
69
|
+
* The capability ID is hashed to derive the PDA.
|
|
70
|
+
* @param capabilityId - Human-readable capability identifier (e.g. `"text-generation"`).
|
|
71
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
72
|
+
* @since v0.1.0
|
|
73
|
+
*/
|
|
74
|
+
async initCapabilityIndex(
|
|
75
|
+
capabilityId: string,
|
|
76
|
+
): Promise<TransactionSignature> {
|
|
77
|
+
const capHash = this.hash(capabilityId);
|
|
78
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
79
|
+
const [capIdxPda] = deriveCapabilityIndex(capHash);
|
|
80
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
81
|
+
|
|
82
|
+
return this.methods
|
|
83
|
+
.initCapabilityIndex(capabilityId, hashToArray(capHash))
|
|
84
|
+
.accounts({
|
|
85
|
+
wallet: this.walletPubkey,
|
|
86
|
+
agent: agentPda,
|
|
87
|
+
capabilityIndex: capIdxPda,
|
|
88
|
+
globalRegistry: globalPda,
|
|
89
|
+
systemProgram: SystemProgram.programId,
|
|
90
|
+
})
|
|
91
|
+
.rpc();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @name addToCapabilityIndex
|
|
96
|
+
* @description Add the caller’s agent to an existing capability index.
|
|
97
|
+
* @param capabilityId - The capability identifier string.
|
|
98
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
99
|
+
* @since v0.1.0
|
|
100
|
+
*/
|
|
101
|
+
async addToCapabilityIndex(
|
|
102
|
+
capabilityId: string,
|
|
103
|
+
): Promise<TransactionSignature> {
|
|
104
|
+
const capHash = this.hash(capabilityId);
|
|
105
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
106
|
+
const [capIdxPda] = deriveCapabilityIndex(capHash);
|
|
107
|
+
|
|
108
|
+
return this.methods
|
|
109
|
+
.addToCapabilityIndex(hashToArray(capHash))
|
|
110
|
+
.accounts({
|
|
111
|
+
wallet: this.walletPubkey,
|
|
112
|
+
agent: agentPda,
|
|
113
|
+
capabilityIndex: capIdxPda,
|
|
114
|
+
})
|
|
115
|
+
.rpc();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @name removeFromCapabilityIndex
|
|
120
|
+
* @description Remove the caller’s agent from a capability index.
|
|
121
|
+
* @param capabilityId - The capability identifier string.
|
|
122
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
123
|
+
* @since v0.1.0
|
|
124
|
+
*/
|
|
125
|
+
async removeFromCapabilityIndex(
|
|
126
|
+
capabilityId: string,
|
|
127
|
+
): Promise<TransactionSignature> {
|
|
128
|
+
const capHash = this.hash(capabilityId);
|
|
129
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
130
|
+
const [capIdxPda] = deriveCapabilityIndex(capHash);
|
|
131
|
+
|
|
132
|
+
return this.methods
|
|
133
|
+
.removeFromCapabilityIndex(hashToArray(capHash))
|
|
134
|
+
.accounts({
|
|
135
|
+
wallet: this.walletPubkey,
|
|
136
|
+
agent: agentPda,
|
|
137
|
+
capabilityIndex: capIdxPda,
|
|
138
|
+
})
|
|
139
|
+
.rpc();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @name closeCapabilityIndex
|
|
144
|
+
* @description Close an empty capability index PDA and reclaim rent.
|
|
145
|
+
* @param capabilityId - The capability identifier string.
|
|
146
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
147
|
+
* @since v0.1.0
|
|
148
|
+
*/
|
|
149
|
+
async closeCapabilityIndex(
|
|
150
|
+
capabilityId: string,
|
|
151
|
+
): Promise<TransactionSignature> {
|
|
152
|
+
const capHash = this.hash(capabilityId);
|
|
153
|
+
const [capIdxPda] = deriveCapabilityIndex(capHash);
|
|
154
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
155
|
+
|
|
156
|
+
return this.methods
|
|
157
|
+
.closeCapabilityIndex(hashToArray(capHash))
|
|
158
|
+
.accounts({
|
|
159
|
+
wallet: this.walletPubkey,
|
|
160
|
+
capabilityIndex: capIdxPda,
|
|
161
|
+
globalRegistry: globalPda,
|
|
162
|
+
})
|
|
163
|
+
.rpc();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── Protocol Index ───────────────────────────────────
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @name initProtocolIndex
|
|
170
|
+
* @description Create a new protocol index and register the caller’s agent.
|
|
171
|
+
* The protocol ID is hashed to derive the PDA.
|
|
172
|
+
* @param protocolId - Human-readable protocol identifier (e.g. `"mcp-v1"`).
|
|
173
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
174
|
+
* @since v0.1.0
|
|
175
|
+
*/
|
|
176
|
+
async initProtocolIndex(
|
|
177
|
+
protocolId: string,
|
|
178
|
+
): Promise<TransactionSignature> {
|
|
179
|
+
const protoHash = this.hash(protocolId);
|
|
180
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
181
|
+
const [protoIdxPda] = deriveProtocolIndex(protoHash);
|
|
182
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
183
|
+
|
|
184
|
+
return this.methods
|
|
185
|
+
.initProtocolIndex(protocolId, hashToArray(protoHash))
|
|
186
|
+
.accounts({
|
|
187
|
+
wallet: this.walletPubkey,
|
|
188
|
+
agent: agentPda,
|
|
189
|
+
protocolIndex: protoIdxPda,
|
|
190
|
+
globalRegistry: globalPda,
|
|
191
|
+
systemProgram: SystemProgram.programId,
|
|
192
|
+
})
|
|
193
|
+
.rpc();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @name addToProtocolIndex
|
|
198
|
+
* @description Add the caller’s agent to an existing protocol index.
|
|
199
|
+
* @param protocolId - The protocol identifier string.
|
|
200
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
201
|
+
* @since v0.1.0
|
|
202
|
+
*/
|
|
203
|
+
async addToProtocolIndex(
|
|
204
|
+
protocolId: string,
|
|
205
|
+
): Promise<TransactionSignature> {
|
|
206
|
+
const protoHash = this.hash(protocolId);
|
|
207
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
208
|
+
const [protoIdxPda] = deriveProtocolIndex(protoHash);
|
|
209
|
+
|
|
210
|
+
return this.methods
|
|
211
|
+
.addToProtocolIndex(hashToArray(protoHash))
|
|
212
|
+
.accounts({
|
|
213
|
+
wallet: this.walletPubkey,
|
|
214
|
+
agent: agentPda,
|
|
215
|
+
protocolIndex: protoIdxPda,
|
|
216
|
+
})
|
|
217
|
+
.rpc();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @name removeFromProtocolIndex
|
|
222
|
+
* @description Remove the caller’s agent from a protocol index.
|
|
223
|
+
* @param protocolId - The protocol identifier string.
|
|
224
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
225
|
+
* @since v0.1.0
|
|
226
|
+
*/
|
|
227
|
+
async removeFromProtocolIndex(
|
|
228
|
+
protocolId: string,
|
|
229
|
+
): Promise<TransactionSignature> {
|
|
230
|
+
const protoHash = this.hash(protocolId);
|
|
231
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
232
|
+
const [protoIdxPda] = deriveProtocolIndex(protoHash);
|
|
233
|
+
|
|
234
|
+
return this.methods
|
|
235
|
+
.removeFromProtocolIndex(hashToArray(protoHash))
|
|
236
|
+
.accounts({
|
|
237
|
+
wallet: this.walletPubkey,
|
|
238
|
+
agent: agentPda,
|
|
239
|
+
protocolIndex: protoIdxPda,
|
|
240
|
+
})
|
|
241
|
+
.rpc();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @name closeProtocolIndex
|
|
246
|
+
* @description Close an empty protocol index PDA and reclaim rent.
|
|
247
|
+
* @param protocolId - The protocol identifier string.
|
|
248
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
249
|
+
* @since v0.1.0
|
|
250
|
+
*/
|
|
251
|
+
async closeProtocolIndex(
|
|
252
|
+
protocolId: string,
|
|
253
|
+
): Promise<TransactionSignature> {
|
|
254
|
+
const protoHash = this.hash(protocolId);
|
|
255
|
+
const [protoIdxPda] = deriveProtocolIndex(protoHash);
|
|
256
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
257
|
+
|
|
258
|
+
return this.methods
|
|
259
|
+
.closeProtocolIndex(hashToArray(protoHash))
|
|
260
|
+
.accounts({
|
|
261
|
+
wallet: this.walletPubkey,
|
|
262
|
+
protocolIndex: protoIdxPda,
|
|
263
|
+
globalRegistry: globalPda,
|
|
264
|
+
})
|
|
265
|
+
.rpc();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ── Tool Category Index ──────────────────────────────
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @name initToolCategoryIndex
|
|
272
|
+
* @description Create a new tool category index PDA.
|
|
273
|
+
* @param category - Numeric tool category enum value.
|
|
274
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
275
|
+
* @since v0.1.0
|
|
276
|
+
*/
|
|
277
|
+
async initToolCategoryIndex(
|
|
278
|
+
category: number,
|
|
279
|
+
): Promise<TransactionSignature> {
|
|
280
|
+
const [catIdxPda] = deriveToolCategoryIndex(category);
|
|
281
|
+
|
|
282
|
+
return this.methods
|
|
283
|
+
.initToolCategoryIndex(category)
|
|
284
|
+
.accounts({
|
|
285
|
+
wallet: this.walletPubkey,
|
|
286
|
+
toolCategoryIndex: catIdxPda,
|
|
287
|
+
systemProgram: SystemProgram.programId,
|
|
288
|
+
})
|
|
289
|
+
.rpc();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @name addToToolCategory
|
|
294
|
+
* @description Add a tool to its matching category index.
|
|
295
|
+
* @param category - Numeric tool category enum value.
|
|
296
|
+
* @param toolPda - The tool descriptor PDA to add.
|
|
297
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
298
|
+
* @since v0.1.0
|
|
299
|
+
*/
|
|
300
|
+
async addToToolCategory(
|
|
301
|
+
category: number,
|
|
302
|
+
toolPda: PublicKey,
|
|
303
|
+
): Promise<TransactionSignature> {
|
|
304
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
305
|
+
const [catIdxPda] = deriveToolCategoryIndex(category);
|
|
306
|
+
|
|
307
|
+
return this.methods
|
|
308
|
+
.addToToolCategory(category)
|
|
309
|
+
.accounts({
|
|
310
|
+
wallet: this.walletPubkey,
|
|
311
|
+
agent: agentPda,
|
|
312
|
+
tool: toolPda,
|
|
313
|
+
toolCategoryIndex: catIdxPda,
|
|
314
|
+
})
|
|
315
|
+
.rpc();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @name removeFromToolCategory
|
|
320
|
+
* @description Remove a tool from a category index.
|
|
321
|
+
* @param category - Numeric tool category enum value.
|
|
322
|
+
* @param toolPda - The tool descriptor PDA to remove.
|
|
323
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
324
|
+
* @since v0.1.0
|
|
325
|
+
*/
|
|
326
|
+
async removeFromToolCategory(
|
|
327
|
+
category: number,
|
|
328
|
+
toolPda: PublicKey,
|
|
329
|
+
): Promise<TransactionSignature> {
|
|
330
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
331
|
+
const [catIdxPda] = deriveToolCategoryIndex(category);
|
|
332
|
+
|
|
333
|
+
return this.methods
|
|
334
|
+
.removeFromToolCategory(category)
|
|
335
|
+
.accounts({
|
|
336
|
+
wallet: this.walletPubkey,
|
|
337
|
+
agent: agentPda,
|
|
338
|
+
tool: toolPda,
|
|
339
|
+
toolCategoryIndex: catIdxPda,
|
|
340
|
+
})
|
|
341
|
+
.rpc();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @name closeToolCategoryIndex
|
|
346
|
+
* @description Close an empty tool category index PDA and reclaim rent.
|
|
347
|
+
* @param category - Numeric tool category enum value.
|
|
348
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
349
|
+
* @since v0.1.0
|
|
350
|
+
*/
|
|
351
|
+
async closeToolCategoryIndex(
|
|
352
|
+
category: number,
|
|
353
|
+
): Promise<TransactionSignature> {
|
|
354
|
+
const [catIdxPda] = deriveToolCategoryIndex(category);
|
|
355
|
+
|
|
356
|
+
return this.methods
|
|
357
|
+
.closeToolCategoryIndex(category)
|
|
358
|
+
.accounts({
|
|
359
|
+
wallet: this.walletPubkey,
|
|
360
|
+
toolCategoryIndex: catIdxPda,
|
|
361
|
+
})
|
|
362
|
+
.rpc();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @name fetchCapabilityIndex
|
|
369
|
+
* @description Fetch a deserialized `CapabilityIndex` account by capability ID.
|
|
370
|
+
* @param capabilityId - The capability identifier string.
|
|
371
|
+
* @returns {Promise<CapabilityIndexData>} The capability index data.
|
|
372
|
+
* @throws Will throw if the capability index does not exist.
|
|
373
|
+
* @since v0.1.0
|
|
374
|
+
*/
|
|
375
|
+
async fetchCapabilityIndex(capabilityId: string): Promise<CapabilityIndexData> {
|
|
376
|
+
const [pda] = deriveCapabilityIndex(this.hash(capabilityId));
|
|
377
|
+
return this.fetchAccount<CapabilityIndexData>("capabilityIndex", pda);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @name fetchCapabilityIndexNullable
|
|
382
|
+
* @description Fetch a deserialized `CapabilityIndex` account, or `null`
|
|
383
|
+
* if it does not exist on-chain.
|
|
384
|
+
* @param capabilityId - The capability identifier string.
|
|
385
|
+
* @returns {Promise<CapabilityIndexData | null>} The capability index data or `null`.
|
|
386
|
+
* @since v0.1.0
|
|
387
|
+
*/
|
|
388
|
+
async fetchCapabilityIndexNullable(capabilityId: string): Promise<CapabilityIndexData | null> {
|
|
389
|
+
const [pda] = deriveCapabilityIndex(this.hash(capabilityId));
|
|
390
|
+
return this.fetchAccountNullable<CapabilityIndexData>("capabilityIndex", pda);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* @name fetchProtocolIndex
|
|
395
|
+
* @description Fetch a deserialized `ProtocolIndex` account by protocol ID.
|
|
396
|
+
* @param protocolId - The protocol identifier string.
|
|
397
|
+
* @returns {Promise<ProtocolIndexData>} The protocol index data.
|
|
398
|
+
* @throws Will throw if the protocol index does not exist.
|
|
399
|
+
* @since v0.1.0
|
|
400
|
+
*/
|
|
401
|
+
async fetchProtocolIndex(protocolId: string): Promise<ProtocolIndexData> {
|
|
402
|
+
const [pda] = deriveProtocolIndex(this.hash(protocolId));
|
|
403
|
+
return this.fetchAccount<ProtocolIndexData>("protocolIndex", pda);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* @name fetchProtocolIndexNullable
|
|
408
|
+
* @description Fetch a deserialized `ProtocolIndex` account, or `null`
|
|
409
|
+
* if it does not exist on-chain.
|
|
410
|
+
* @param protocolId - The protocol identifier string.
|
|
411
|
+
* @returns {Promise<ProtocolIndexData | null>} The protocol index data or `null`.
|
|
412
|
+
* @since v0.1.0
|
|
413
|
+
*/
|
|
414
|
+
async fetchProtocolIndexNullable(protocolId: string): Promise<ProtocolIndexData | null> {
|
|
415
|
+
const [pda] = deriveProtocolIndex(this.hash(protocolId));
|
|
416
|
+
return this.fetchAccountNullable<ProtocolIndexData>("protocolIndex", pda);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @name fetchToolCategoryIndex
|
|
421
|
+
* @description Fetch a deserialized `ToolCategoryIndex` account by category number.
|
|
422
|
+
* @param category - Numeric tool category enum value.
|
|
423
|
+
* @returns {Promise<ToolCategoryIndexData>} The tool category index data.
|
|
424
|
+
* @throws Will throw if the tool category index does not exist.
|
|
425
|
+
* @since v0.1.0
|
|
426
|
+
*/
|
|
427
|
+
async fetchToolCategoryIndex(category: number): Promise<ToolCategoryIndexData> {
|
|
428
|
+
const [pda] = deriveToolCategoryIndex(category);
|
|
429
|
+
return this.fetchAccount<ToolCategoryIndexData>("toolCategoryIndex", pda);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @name fetchToolCategoryIndexNullable
|
|
434
|
+
* @description Fetch a deserialized `ToolCategoryIndex` account, or `null`
|
|
435
|
+
* if it does not exist on-chain.
|
|
436
|
+
* @param category - Numeric tool category enum value.
|
|
437
|
+
* @returns {Promise<ToolCategoryIndexData | null>} The tool category index data or `null`.
|
|
438
|
+
* @since v0.1.0
|
|
439
|
+
*/
|
|
440
|
+
async fetchToolCategoryIndexNullable(category: number): Promise<ToolCategoryIndexData | null> {
|
|
441
|
+
const [pda] = deriveToolCategoryIndex(category);
|
|
442
|
+
return this.fetchAccountNullable<ToolCategoryIndexData>("toolCategoryIndex", pda);
|
|
443
|
+
}
|
|
444
|
+
}
|