@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,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module attestation
|
|
3
|
+
* @description Web-of-trust attestations — create, revoke, and close
|
|
4
|
+
* on-chain attestations that vouch for agent trustworthiness.
|
|
5
|
+
*
|
|
6
|
+
* Attestations are signed endorsements from one wallet to an agent,
|
|
7
|
+
* forming a composable trust graph 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, deriveAttestation, deriveGlobalRegistry } from "../pda";
|
|
17
|
+
import type { AgentAttestationData, CreateAttestationArgs } from "../types";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @name AttestationModule
|
|
21
|
+
* @description Manages on-chain attestations for the Solana Agent Protocol.
|
|
22
|
+
* Provides methods to create, revoke, close, and fetch attestation PDAs
|
|
23
|
+
* that form the web-of-trust 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
|
+
* // Create an attestation for an agent
|
|
33
|
+
* const sig = await sap.attestation.create(agentWallet, {
|
|
34
|
+
* attestationType: { identity: {} },
|
|
35
|
+
* metadataHash: [...],
|
|
36
|
+
* expiresAt: null,
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class AttestationModule extends BaseModule {
|
|
41
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @name deriveAttestation
|
|
45
|
+
* @description Derive the `AgentAttestation` PDA for a given agent and attester.
|
|
46
|
+
* @param agentPda - The agent account PDA to attest.
|
|
47
|
+
* @param attester - The attester wallet. Defaults to the connected wallet.
|
|
48
|
+
* @returns A tuple of `[PublicKey, bump]` for the attestation PDA.
|
|
49
|
+
* @see {@link deriveAttestation} from `pda/` module for the underlying derivation.
|
|
50
|
+
* @since v0.1.0
|
|
51
|
+
*/
|
|
52
|
+
deriveAttestation(
|
|
53
|
+
agentPda: PublicKey,
|
|
54
|
+
attester?: PublicKey,
|
|
55
|
+
): readonly [PublicKey, number] {
|
|
56
|
+
return deriveAttestation(agentPda, attester ?? this.walletPubkey);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── Instructions ─────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @name create
|
|
63
|
+
* @description Create an on-chain attestation vouching for an agent.
|
|
64
|
+
* The connected wallet becomes the attester.
|
|
65
|
+
* @param agentWallet - The wallet that owns the target agent.
|
|
66
|
+
* @param args - Attestation parameters (type, metadata hash, optional expiry).
|
|
67
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
68
|
+
* @since v0.1.0
|
|
69
|
+
*/
|
|
70
|
+
async create(
|
|
71
|
+
agentWallet: PublicKey,
|
|
72
|
+
args: CreateAttestationArgs,
|
|
73
|
+
): Promise<TransactionSignature> {
|
|
74
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
75
|
+
const [attestPda] = this.deriveAttestation(agentPda);
|
|
76
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
77
|
+
|
|
78
|
+
return this.methods
|
|
79
|
+
.createAttestation(args.attestationType, args.metadataHash, args.expiresAt)
|
|
80
|
+
.accounts({
|
|
81
|
+
attester: this.walletPubkey,
|
|
82
|
+
agent: agentPda,
|
|
83
|
+
attestation: attestPda,
|
|
84
|
+
globalRegistry: globalPda,
|
|
85
|
+
systemProgram: SystemProgram.programId,
|
|
86
|
+
})
|
|
87
|
+
.rpc();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @name revoke
|
|
92
|
+
* @description Revoke a previously issued attestation. Only the original
|
|
93
|
+
* attester may revoke.
|
|
94
|
+
* @param agentWallet - The wallet of the attested agent.
|
|
95
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
96
|
+
* @since v0.1.0
|
|
97
|
+
*/
|
|
98
|
+
async revoke(agentWallet: PublicKey): Promise<TransactionSignature> {
|
|
99
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
100
|
+
const [attestPda] = this.deriveAttestation(agentPda);
|
|
101
|
+
|
|
102
|
+
return this.methods
|
|
103
|
+
.revokeAttestation()
|
|
104
|
+
.accounts({
|
|
105
|
+
attester: this.walletPubkey,
|
|
106
|
+
attestation: attestPda,
|
|
107
|
+
})
|
|
108
|
+
.rpc();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @name close
|
|
113
|
+
* @description Close a revoked attestation PDA and reclaim rent to the attester.
|
|
114
|
+
* @param agentWallet - The wallet of the attested agent.
|
|
115
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
116
|
+
* @since v0.1.0
|
|
117
|
+
*/
|
|
118
|
+
async close(agentWallet: PublicKey): Promise<TransactionSignature> {
|
|
119
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
120
|
+
const [attestPda] = this.deriveAttestation(agentPda);
|
|
121
|
+
const [globalPda] = deriveGlobalRegistry();
|
|
122
|
+
|
|
123
|
+
return this.methods
|
|
124
|
+
.closeAttestation()
|
|
125
|
+
.accounts({
|
|
126
|
+
attester: this.walletPubkey,
|
|
127
|
+
attestation: attestPda,
|
|
128
|
+
globalRegistry: globalPda,
|
|
129
|
+
})
|
|
130
|
+
.rpc();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @name fetch
|
|
137
|
+
* @description Fetch a deserialized `AgentAttestation` account.
|
|
138
|
+
* @param agentPda - The agent account PDA.
|
|
139
|
+
* @param attester - The attester wallet. Defaults to the connected wallet.
|
|
140
|
+
* @returns {Promise<AgentAttestationData>} The attestation account data.
|
|
141
|
+
* @throws Will throw if the attestation account does not exist.
|
|
142
|
+
* @since v0.1.0
|
|
143
|
+
*/
|
|
144
|
+
async fetch(
|
|
145
|
+
agentPda: PublicKey,
|
|
146
|
+
attester?: PublicKey,
|
|
147
|
+
): Promise<AgentAttestationData> {
|
|
148
|
+
const [pda] = this.deriveAttestation(agentPda, attester);
|
|
149
|
+
return this.fetchAccount<AgentAttestationData>("agentAttestation", pda);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @name fetchNullable
|
|
154
|
+
* @description Fetch a deserialized `AgentAttestation` account, or `null`
|
|
155
|
+
* if it does not exist on-chain.
|
|
156
|
+
* @param agentPda - The agent account PDA.
|
|
157
|
+
* @param attester - The attester wallet. Defaults to the connected wallet.
|
|
158
|
+
* @returns {Promise<AgentAttestationData | null>} The attestation data or `null`.
|
|
159
|
+
* @since v0.1.0
|
|
160
|
+
*/
|
|
161
|
+
async fetchNullable(
|
|
162
|
+
agentPda: PublicKey,
|
|
163
|
+
attester?: PublicKey,
|
|
164
|
+
): Promise<AgentAttestationData | null> {
|
|
165
|
+
const [pda] = this.deriveAttestation(agentPda, attester);
|
|
166
|
+
return this.fetchAccountNullable<AgentAttestationData>("agentAttestation", pda);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module base
|
|
3
|
+
* @description Abstract base class for all SDK modules.
|
|
4
|
+
*
|
|
5
|
+
* Provides shared access to the Anchor program, provider,
|
|
6
|
+
* and typed `fetch` / `fetchNullable` helpers.
|
|
7
|
+
*
|
|
8
|
+
* @category Modules
|
|
9
|
+
* @since v0.1.0
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { type AnchorProvider, type Program, BN } from "@coral-xyz/anchor";
|
|
14
|
+
import type { PublicKey, TransactionSignature } from "@solana/web3.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Anchor `Program` instance typed for the Synapse Agent SAP IDL.
|
|
18
|
+
*
|
|
19
|
+
* @name SapProgram
|
|
20
|
+
* @description Alias for `Program<any>` — the Anchor program reference
|
|
21
|
+
* used as the backbone of every module in the SDK.
|
|
22
|
+
* @category Modules
|
|
23
|
+
* @since v0.1.0
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
export type SapProgram = Program<any>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @name SapTransactionResult
|
|
30
|
+
* @description Instruction builder return type — a ready-to-send transaction.
|
|
31
|
+
* Contains the finalized transaction signature after RPC submission.
|
|
32
|
+
* @category Modules
|
|
33
|
+
* @since v0.1.0
|
|
34
|
+
*/
|
|
35
|
+
export interface SapTransactionResult {
|
|
36
|
+
/** The base-58 encoded transaction signature returned by the RPC node. */
|
|
37
|
+
readonly signature: TransactionSignature;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @name BaseModule
|
|
42
|
+
* @description Abstract base module inherited by every domain module in the SDK.
|
|
43
|
+
* Encapsulates the Anchor program reference, provider access, and common
|
|
44
|
+
* helpers for account fetching and BN construction.
|
|
45
|
+
*
|
|
46
|
+
* @abstract
|
|
47
|
+
* @category Modules
|
|
48
|
+
* @since v0.1.0
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* class MyModule extends BaseModule {
|
|
53
|
+
* async doSomething() {
|
|
54
|
+
* const data = await this.fetchAccount<MyData>("myAccount", pda);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export abstract class BaseModule {
|
|
60
|
+
/**
|
|
61
|
+
* Create a new module instance.
|
|
62
|
+
*
|
|
63
|
+
* @param program - The Anchor `Program` instance for the SAP IDL.
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
constructor(protected readonly program: SapProgram) {}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @name methods
|
|
70
|
+
* @description Instruction method namespace — bypasses `noUncheckedIndexedAccess`
|
|
71
|
+
* on `Program<any>` where every property is `T | undefined`.
|
|
72
|
+
* Used internally by subclasses to build and send instructions.
|
|
73
|
+
* @returns The Anchor program `methods` object for chaining instruction builders.
|
|
74
|
+
* @protected
|
|
75
|
+
* @since v0.1.0
|
|
76
|
+
*/
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
protected get methods(): any {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
80
|
+
return this.program.methods;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @name provider
|
|
85
|
+
* @description The AnchorProvider from the program, giving access to
|
|
86
|
+
* the connection and wallet for signing transactions.
|
|
87
|
+
* @returns {AnchorProvider} The Anchor provider instance.
|
|
88
|
+
* @protected
|
|
89
|
+
* @since v0.1.0
|
|
90
|
+
*/
|
|
91
|
+
protected get provider(): AnchorProvider {
|
|
92
|
+
return this.program.provider as AnchorProvider;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @name walletPubkey
|
|
97
|
+
* @description Convenience accessor for the signer wallet's public key.
|
|
98
|
+
* @returns {PublicKey} The public key of the connected wallet.
|
|
99
|
+
* @protected
|
|
100
|
+
* @since v0.1.0
|
|
101
|
+
*/
|
|
102
|
+
protected get walletPubkey(): PublicKey {
|
|
103
|
+
return this.provider.wallet.publicKey;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @name fetchAccount
|
|
108
|
+
* @description Generic account fetch — deserializes the on-chain account
|
|
109
|
+
* data into the given type `T`, or throws if the account does not exist.
|
|
110
|
+
* @typeParam T - The expected deserialized account data type.
|
|
111
|
+
* @param accountName - The Anchor account discriminator name (e.g. `"agentAccount"`).
|
|
112
|
+
* @param address - The public key of the account to fetch.
|
|
113
|
+
* @returns {Promise<T>} The deserialized account data.
|
|
114
|
+
* @throws Will throw if the account does not exist on-chain.
|
|
115
|
+
* @protected
|
|
116
|
+
* @since v0.1.0
|
|
117
|
+
*/
|
|
118
|
+
protected async fetchAccount<T>(
|
|
119
|
+
accountName: string,
|
|
120
|
+
address: PublicKey,
|
|
121
|
+
): Promise<T> {
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
123
|
+
return (this.program.account as any)[accountName].fetch(address) as Promise<T>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @name fetchAccountNullable
|
|
128
|
+
* @description Generic nullable account fetch — deserializes the on-chain
|
|
129
|
+
* account data into type `T`, or returns `null` if the account does not exist.
|
|
130
|
+
* @typeParam T - The expected deserialized account data type.
|
|
131
|
+
* @param accountName - The Anchor account discriminator name (e.g. `"agentAccount"`).
|
|
132
|
+
* @param address - The public key of the account to fetch.
|
|
133
|
+
* @returns {Promise<T | null>} The deserialized account data, or `null`.
|
|
134
|
+
* @protected
|
|
135
|
+
* @since v0.1.0
|
|
136
|
+
*/
|
|
137
|
+
protected async fetchAccountNullable<T>(
|
|
138
|
+
accountName: string,
|
|
139
|
+
address: PublicKey,
|
|
140
|
+
): Promise<T | null> {
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
142
|
+
return (this.program.account as any)[accountName].fetchNullable(address) as Promise<T | null>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @name bn
|
|
147
|
+
* @description Create an Anchor `BN` from a number, bigint, or existing BN.
|
|
148
|
+
* Passes through values that are already `BN` instances.
|
|
149
|
+
* @param value - The numeric value to convert.
|
|
150
|
+
* @returns {BN} An Anchor-compatible big number.
|
|
151
|
+
* @protected
|
|
152
|
+
* @since v0.1.0
|
|
153
|
+
*/
|
|
154
|
+
protected bn(value: number | bigint | BN): BN {
|
|
155
|
+
if (BN.isBN(value)) return value;
|
|
156
|
+
return new BN(value.toString());
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module escrow
|
|
3
|
+
* @description x402 escrow settlement layer — create, deposit,
|
|
4
|
+
* settle, withdraw, batch settle, and close escrow accounts.
|
|
5
|
+
*
|
|
6
|
+
* Supports both SOL and SPL token escrows. SPL operations require
|
|
7
|
+
* passing additional `AccountMeta[]` via the `splAccounts` parameter.
|
|
8
|
+
*
|
|
9
|
+
* @category Modules
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
SystemProgram,
|
|
16
|
+
type PublicKey,
|
|
17
|
+
type TransactionSignature,
|
|
18
|
+
type AccountMeta,
|
|
19
|
+
} from "@solana/web3.js";
|
|
20
|
+
import { BN } from "@coral-xyz/anchor";
|
|
21
|
+
import { BaseModule } from "./base";
|
|
22
|
+
import {
|
|
23
|
+
deriveAgent,
|
|
24
|
+
deriveAgentStats,
|
|
25
|
+
deriveEscrow,
|
|
26
|
+
} from "../pda";
|
|
27
|
+
import type {
|
|
28
|
+
EscrowAccountData,
|
|
29
|
+
CreateEscrowArgs,
|
|
30
|
+
Settlement,
|
|
31
|
+
} from "../types";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @name EscrowModule
|
|
35
|
+
* @description Manages x402-compatible escrow accounts for agent micropayments.
|
|
36
|
+
* Provides methods to create, fund, settle, withdraw, batch-settle, close,
|
|
37
|
+
* and fetch escrow PDAs on the Solana Agent Protocol.
|
|
38
|
+
*
|
|
39
|
+
* @category Modules
|
|
40
|
+
* @since v0.1.0
|
|
41
|
+
* @extends BaseModule
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const sap = new SapClient(provider);
|
|
46
|
+
* // Create a SOL escrow for an agent
|
|
47
|
+
* const sig = await sap.escrow.create(agentWallet, {
|
|
48
|
+
* pricePerCall: new BN(1_000_000),
|
|
49
|
+
* maxCalls: new BN(100),
|
|
50
|
+
* initialDeposit: new BN(100_000_000),
|
|
51
|
+
* expiresAt: null,
|
|
52
|
+
* volumeCurve: null,
|
|
53
|
+
* tokenMint: null,
|
|
54
|
+
* tokenDecimals: null,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export class EscrowModule extends BaseModule {
|
|
59
|
+
// ── PDA helpers ──────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @name deriveEscrow
|
|
63
|
+
* @description Derive the `EscrowAccount` PDA for a given agent and depositor.
|
|
64
|
+
* @param agentPda - The agent account PDA.
|
|
65
|
+
* @param depositor - The depositor wallet. Defaults to the connected wallet.
|
|
66
|
+
* @returns A tuple of `[PublicKey, bump]` for the escrow PDA.
|
|
67
|
+
* @see {@link deriveEscrow} from `pda/` module for the underlying derivation.
|
|
68
|
+
* @since v0.1.0
|
|
69
|
+
*/
|
|
70
|
+
deriveEscrow(
|
|
71
|
+
agentPda: PublicKey,
|
|
72
|
+
depositor?: PublicKey,
|
|
73
|
+
): readonly [PublicKey, number] {
|
|
74
|
+
return deriveEscrow(agentPda, depositor ?? this.walletPubkey);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Instructions ─────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @name create
|
|
81
|
+
* @description Create a new escrow for agent micropayments.
|
|
82
|
+
*
|
|
83
|
+
* For **SOL escrow**: pass `tokenMint: null` and leave `splAccounts` empty.
|
|
84
|
+
* For **SPL escrow**: pass `tokenMint`, `tokenDecimals`, and provide
|
|
85
|
+
* `splAccounts` with `[depositorAta, escrowAta, tokenMint, tokenProgram]`.
|
|
86
|
+
*
|
|
87
|
+
* @param agentWallet - The wallet of the agent to pay.
|
|
88
|
+
* @param args - Escrow creation parameters (price, max calls, deposit, expiry, volume curve, token info).
|
|
89
|
+
* @param splAccounts - Remaining accounts for SPL token transfers:
|
|
90
|
+
* `[depositorAta, escrowAta, tokenMint, tokenProgram]`. Defaults to `[]`.
|
|
91
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
92
|
+
* @since v0.1.0
|
|
93
|
+
*/
|
|
94
|
+
async create(
|
|
95
|
+
agentWallet: PublicKey,
|
|
96
|
+
args: CreateEscrowArgs,
|
|
97
|
+
splAccounts: AccountMeta[] = [],
|
|
98
|
+
): Promise<TransactionSignature> {
|
|
99
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
100
|
+
const [escrowPda] = this.deriveEscrow(agentPda);
|
|
101
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
102
|
+
|
|
103
|
+
return this.methods
|
|
104
|
+
.createEscrow(
|
|
105
|
+
args.pricePerCall,
|
|
106
|
+
args.maxCalls,
|
|
107
|
+
args.initialDeposit,
|
|
108
|
+
args.expiresAt,
|
|
109
|
+
args.volumeCurve,
|
|
110
|
+
args.tokenMint,
|
|
111
|
+
args.tokenDecimals,
|
|
112
|
+
)
|
|
113
|
+
.accounts({
|
|
114
|
+
depositor: this.walletPubkey,
|
|
115
|
+
agent: agentPda,
|
|
116
|
+
agentStats: statsPda,
|
|
117
|
+
escrow: escrowPda,
|
|
118
|
+
systemProgram: SystemProgram.programId,
|
|
119
|
+
})
|
|
120
|
+
.remainingAccounts(splAccounts)
|
|
121
|
+
.rpc();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @name deposit
|
|
126
|
+
* @description Deposit additional funds into an existing escrow.
|
|
127
|
+
* @param agentWallet - The wallet of the agent associated with the escrow.
|
|
128
|
+
* @param amount - The amount to deposit (lamports for SOL, smallest unit for SPL).
|
|
129
|
+
* @param splAccounts - Remaining accounts for SPL token transfers. Defaults to `[]`.
|
|
130
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
131
|
+
* @since v0.1.0
|
|
132
|
+
*/
|
|
133
|
+
async deposit(
|
|
134
|
+
agentWallet: PublicKey,
|
|
135
|
+
amount: BN | number | bigint,
|
|
136
|
+
splAccounts: AccountMeta[] = [],
|
|
137
|
+
): Promise<TransactionSignature> {
|
|
138
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
139
|
+
const [escrowPda] = this.deriveEscrow(agentPda);
|
|
140
|
+
|
|
141
|
+
return this.methods
|
|
142
|
+
.depositEscrow(this.bn(amount))
|
|
143
|
+
.accounts({
|
|
144
|
+
depositor: this.walletPubkey,
|
|
145
|
+
escrow: escrowPda,
|
|
146
|
+
systemProgram: SystemProgram.programId,
|
|
147
|
+
})
|
|
148
|
+
.remainingAccounts(splAccounts)
|
|
149
|
+
.rpc();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @name settle
|
|
154
|
+
* @description Agent settles calls — claims earned funds from the escrow.
|
|
155
|
+
* Must be called by the agent owner wallet.
|
|
156
|
+
* @param depositorWallet - The wallet of the client who funded the escrow.
|
|
157
|
+
* @param callsToSettle - Number of calls to settle payment for.
|
|
158
|
+
* @param serviceHash - A 32-byte SHA-256 hash identifying the service rendered.
|
|
159
|
+
* @param splAccounts - Remaining accounts for SPL token transfers. Defaults to `[]`.
|
|
160
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
161
|
+
* @since v0.1.0
|
|
162
|
+
*/
|
|
163
|
+
async settle(
|
|
164
|
+
depositorWallet: PublicKey,
|
|
165
|
+
callsToSettle: BN | number | bigint,
|
|
166
|
+
serviceHash: number[],
|
|
167
|
+
splAccounts: AccountMeta[] = [],
|
|
168
|
+
): Promise<TransactionSignature> {
|
|
169
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
170
|
+
const [escrowPda] = deriveEscrow(agentPda, depositorWallet);
|
|
171
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
172
|
+
|
|
173
|
+
return this.methods
|
|
174
|
+
.settleCalls(this.bn(callsToSettle), serviceHash)
|
|
175
|
+
.accounts({
|
|
176
|
+
wallet: this.walletPubkey,
|
|
177
|
+
agent: agentPda,
|
|
178
|
+
agentStats: statsPda,
|
|
179
|
+
escrow: escrowPda,
|
|
180
|
+
systemProgram: SystemProgram.programId,
|
|
181
|
+
})
|
|
182
|
+
.remainingAccounts(splAccounts)
|
|
183
|
+
.rpc();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @name withdraw
|
|
188
|
+
* @description Client withdraws un-settled funds from their escrow.
|
|
189
|
+
* @param agentWallet - The wallet of the agent associated with the escrow.
|
|
190
|
+
* @param amount - The amount to withdraw (lamports for SOL, smallest unit for SPL).
|
|
191
|
+
* @param splAccounts - Remaining accounts for SPL token transfers. Defaults to `[]`.
|
|
192
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
193
|
+
* @since v0.1.0
|
|
194
|
+
*/
|
|
195
|
+
async withdraw(
|
|
196
|
+
agentWallet: PublicKey,
|
|
197
|
+
amount: BN | number | bigint,
|
|
198
|
+
splAccounts: AccountMeta[] = [],
|
|
199
|
+
): Promise<TransactionSignature> {
|
|
200
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
201
|
+
const [escrowPda] = this.deriveEscrow(agentPda);
|
|
202
|
+
|
|
203
|
+
return this.methods
|
|
204
|
+
.withdrawEscrow(this.bn(amount))
|
|
205
|
+
.accounts({
|
|
206
|
+
depositor: this.walletPubkey,
|
|
207
|
+
escrow: escrowPda,
|
|
208
|
+
systemProgram: SystemProgram.programId,
|
|
209
|
+
})
|
|
210
|
+
.remainingAccounts(splAccounts)
|
|
211
|
+
.rpc();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @name close
|
|
216
|
+
* @description Close an empty escrow PDA (balance must be 0) and reclaim rent.
|
|
217
|
+
* @param agentWallet - The wallet of the agent associated with the escrow.
|
|
218
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
219
|
+
* @since v0.1.0
|
|
220
|
+
*/
|
|
221
|
+
async close(agentWallet: PublicKey): Promise<TransactionSignature> {
|
|
222
|
+
const [agentPda] = deriveAgent(agentWallet);
|
|
223
|
+
const [escrowPda] = this.deriveEscrow(agentPda);
|
|
224
|
+
|
|
225
|
+
return this.methods
|
|
226
|
+
.closeEscrow()
|
|
227
|
+
.accounts({
|
|
228
|
+
depositor: this.walletPubkey,
|
|
229
|
+
escrow: escrowPda,
|
|
230
|
+
})
|
|
231
|
+
.rpc();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @name settleBatch
|
|
236
|
+
* @description Batch settlement — process up to 10 settlements in a single
|
|
237
|
+
* transaction. Must be called by the agent owner wallet.
|
|
238
|
+
* @param depositorWallet - The wallet of the client who funded the escrow.
|
|
239
|
+
* @param settlements - Array of settlement entries (up to 10).
|
|
240
|
+
* @param splAccounts - Remaining accounts for SPL token transfers. Defaults to `[]`.
|
|
241
|
+
* @returns {Promise<TransactionSignature>} The transaction signature.
|
|
242
|
+
* @since v0.1.0
|
|
243
|
+
*/
|
|
244
|
+
async settleBatch(
|
|
245
|
+
depositorWallet: PublicKey,
|
|
246
|
+
settlements: Settlement[],
|
|
247
|
+
splAccounts: AccountMeta[] = [],
|
|
248
|
+
): Promise<TransactionSignature> {
|
|
249
|
+
const [agentPda] = deriveAgent(this.walletPubkey);
|
|
250
|
+
const [escrowPda] = deriveEscrow(agentPda, depositorWallet);
|
|
251
|
+
const [statsPda] = deriveAgentStats(agentPda);
|
|
252
|
+
|
|
253
|
+
return this.methods
|
|
254
|
+
.settleBatch(settlements)
|
|
255
|
+
.accounts({
|
|
256
|
+
wallet: this.walletPubkey,
|
|
257
|
+
agent: agentPda,
|
|
258
|
+
agentStats: statsPda,
|
|
259
|
+
escrow: escrowPda,
|
|
260
|
+
systemProgram: SystemProgram.programId,
|
|
261
|
+
})
|
|
262
|
+
.remainingAccounts(splAccounts)
|
|
263
|
+
.rpc();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── Fetchers ─────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @name fetch
|
|
270
|
+
* @description Fetch a deserialized `EscrowAccount`.
|
|
271
|
+
* @param agentPda - The agent account PDA.
|
|
272
|
+
* @param depositor - The depositor wallet. Defaults to the connected wallet.
|
|
273
|
+
* @returns {Promise<EscrowAccountData>} The escrow account data.
|
|
274
|
+
* @throws Will throw if the escrow account does not exist.
|
|
275
|
+
* @since v0.1.0
|
|
276
|
+
*/
|
|
277
|
+
async fetch(agentPda: PublicKey, depositor?: PublicKey): Promise<EscrowAccountData> {
|
|
278
|
+
const [pda] = this.deriveEscrow(agentPda, depositor);
|
|
279
|
+
return this.fetchAccount<EscrowAccountData>("escrowAccount", pda);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @name fetchNullable
|
|
284
|
+
* @description Fetch a deserialized `EscrowAccount`, or `null` if it
|
|
285
|
+
* does not exist on-chain.
|
|
286
|
+
* @param agentPda - The agent account PDA.
|
|
287
|
+
* @param depositor - The depositor wallet. Defaults to the connected wallet.
|
|
288
|
+
* @returns {Promise<EscrowAccountData | null>} The escrow data or `null`.
|
|
289
|
+
* @since v0.1.0
|
|
290
|
+
*/
|
|
291
|
+
async fetchNullable(agentPda: PublicKey, depositor?: PublicKey): Promise<EscrowAccountData | null> {
|
|
292
|
+
const [pda] = this.deriveEscrow(agentPda, depositor);
|
|
293
|
+
return this.fetchAccountNullable<EscrowAccountData>("escrowAccount", pda);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* @name fetchByPda
|
|
298
|
+
* @description Fetch an escrow account by its PDA address directly,
|
|
299
|
+
* bypassing PDA derivation.
|
|
300
|
+
* @param escrowPda - The escrow PDA public key.
|
|
301
|
+
* @returns {Promise<EscrowAccountData>} The escrow account data.
|
|
302
|
+
* @throws Will throw if the escrow account does not exist.
|
|
303
|
+
* @since v0.1.0
|
|
304
|
+
*/
|
|
305
|
+
async fetchByPda(escrowPda: PublicKey): Promise<EscrowAccountData> {
|
|
306
|
+
return this.fetchAccount<EscrowAccountData>("escrowAccount", escrowPda);
|
|
307
|
+
}
|
|
308
|
+
}
|