@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
package/README.md
ADDED
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
# @synapse-sap/sdk
|
|
2
|
+
|
|
3
|
+
> TypeScript SDK for the **Synapse Agent Protocol (SAP v2)** on Solana.
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://www.anchor-lang.com/)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
- [Core — Client & Connection](#core--client--connection)
|
|
18
|
+
- [Modules (Low-Level)](#modules-low-level)
|
|
19
|
+
- [Registries (High-Level)](#registries-high-level)
|
|
20
|
+
- [Plugin (SynapseAgentKit)](#plugin-synapseagentkit)
|
|
21
|
+
- [PDA Derivation](#pda-derivation)
|
|
22
|
+
- [Events](#events)
|
|
23
|
+
- [Error Handling](#error-handling)
|
|
24
|
+
- [Utilities](#utilities)
|
|
25
|
+
- [Types](#types)
|
|
26
|
+
- [Constants](#constants)
|
|
27
|
+
- [Deep Imports](#deep-imports)
|
|
28
|
+
- [API Reference](#api-reference)
|
|
29
|
+
- [Development](#development)
|
|
30
|
+
- [License](#license)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **8 domain modules** — Agent, Feedback, Indexing, Tools, Vault, Escrow, Attestation, Ledger
|
|
37
|
+
- **4 high-level registries** — Discovery, x402 Payments, Session Manager, Agent Builder
|
|
38
|
+
- **52-tool plugin adapter** — drop-in for `SynapseAgentKit` / LangChain tooling
|
|
39
|
+
- **SapConnection** — RPC-first entry point compatible with `synapse-client-sdk`
|
|
40
|
+
- **Typed errors** — `SapError`, `SapRpcError`, `SapAccountNotFoundError`, etc.
|
|
41
|
+
- **Serialization** — automatic `PublicKey`/`BN` → JSON-safe object conversion
|
|
42
|
+
- **17 PDA functions** — deterministic, pure, memoizable
|
|
43
|
+
- **Fully typed** — 17 account interfaces, 11 instruction DTOs, 38 decoded events
|
|
44
|
+
- **Dual output** — CommonJS + ESM with TypeScript declarations
|
|
45
|
+
- **Subpath exports** — `@synapse-sap/sdk/core`, `@synapse-sap/sdk/types`, etc.
|
|
46
|
+
- **Tree-shakeable** — import only what you need
|
|
47
|
+
- **Embedded IDL** — zero external workspace dependency; npm-ready
|
|
48
|
+
- **Strict TypeScript** — `strict`, `noUncheckedIndexedAccess`, `noUnusedLocals`
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Yarn
|
|
54
|
+
yarn add @synapse-sap/sdk @coral-xyz/anchor @solana/web3.js
|
|
55
|
+
|
|
56
|
+
# npm
|
|
57
|
+
npm install @synapse-sap/sdk @coral-xyz/anchor @solana/web3.js
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Peer Dependencies
|
|
61
|
+
|
|
62
|
+
| Package | Version | Notes |
|
|
63
|
+
|---------|---------|-------|
|
|
64
|
+
| `@coral-xyz/anchor` | `>=0.30.0` | Required |
|
|
65
|
+
| `@solana/web3.js` | `>=1.90.0` | Required |
|
|
66
|
+
| `zod` | `>=3.20.0` | Optional — only for plugin schemas |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### Option A — Anchor Provider (classic)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { SapClient } from "@synapse-sap/sdk";
|
|
76
|
+
import { AnchorProvider } from "@coral-xyz/anchor";
|
|
77
|
+
|
|
78
|
+
const provider = AnchorProvider.env();
|
|
79
|
+
const client = SapClient.from(provider);
|
|
80
|
+
|
|
81
|
+
// Register agent
|
|
82
|
+
await client.agent.register({
|
|
83
|
+
name: "SwapBot",
|
|
84
|
+
description: "AI-powered DEX aggregator",
|
|
85
|
+
capabilities: [{ id: "jupiter:swap", description: null, protocolId: "jupiter", version: "1.0.0" }],
|
|
86
|
+
pricing: [],
|
|
87
|
+
protocols: ["jupiter"],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Fetch agent
|
|
91
|
+
const agent = await client.agent.fetch();
|
|
92
|
+
console.log(agent.name, agent.isActive);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Option B — RPC URL + Keypair (synapse-client-sdk compatible)
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { SapConnection } from "@synapse-sap/sdk";
|
|
99
|
+
import { Keypair } from "@solana/web3.js";
|
|
100
|
+
|
|
101
|
+
// One-liner:
|
|
102
|
+
const { client } = SapConnection.fromKeypair(
|
|
103
|
+
"https://api.devnet.solana.com",
|
|
104
|
+
Keypair.generate(),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// Or step-by-step:
|
|
108
|
+
const conn = SapConnection.devnet(); // or .mainnet(rpcUrl), .localnet()
|
|
109
|
+
const client = conn.fromKeypair(myKeypair);
|
|
110
|
+
|
|
111
|
+
// Use exactly the same API:
|
|
112
|
+
await client.agent.register({ ... });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Option C — Fluent Builder
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { SapClient } from "@synapse-sap/sdk";
|
|
119
|
+
|
|
120
|
+
const client = SapClient.from(provider);
|
|
121
|
+
|
|
122
|
+
await client.builder
|
|
123
|
+
.agent("SwapBot")
|
|
124
|
+
.description("AI-powered swap agent")
|
|
125
|
+
.x402Endpoint("https://api.example.com/x402")
|
|
126
|
+
.addCapability("jupiter:swap", { protocol: "jupiter" })
|
|
127
|
+
.addPricingTier({
|
|
128
|
+
tierId: "standard",
|
|
129
|
+
pricePerCall: 1000,
|
|
130
|
+
rateLimit: 60,
|
|
131
|
+
})
|
|
132
|
+
.register();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Architecture
|
|
138
|
+
|
|
139
|
+
### Directory Structure
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
src/
|
|
143
|
+
├── index.ts # Root barrel export
|
|
144
|
+
│
|
|
145
|
+
├── core/ # Client & connection infrastructure
|
|
146
|
+
│ ├── client.ts # SapClient — Anchor program wrapper
|
|
147
|
+
│ ├── connection.ts # SapConnection — RPC factory (synapse-client-sdk compat)
|
|
148
|
+
│ └── index.ts
|
|
149
|
+
│
|
|
150
|
+
├── types/ # On-chain type mirrors
|
|
151
|
+
│ ├── enums.ts # Anchor enum variant objects
|
|
152
|
+
│ ├── common.ts # Shared structs (Capability, PricingTier, …)
|
|
153
|
+
│ ├── accounts.ts # 17 account data interfaces
|
|
154
|
+
│ ├── instructions.ts # 11 instruction arg DTOs + helpers
|
|
155
|
+
│ └── index.ts
|
|
156
|
+
│
|
|
157
|
+
├── constants/ # Protocol constants
|
|
158
|
+
│ ├── programs.ts # Network-specific program IDs
|
|
159
|
+
│ ├── seeds.ts # 20 PDA seed prefixes
|
|
160
|
+
│ ├── limits.ts # Size constraints, versions
|
|
161
|
+
│ └── index.ts
|
|
162
|
+
│
|
|
163
|
+
├── pda/ # PDA derivation functions
|
|
164
|
+
│ └── index.ts # 17 derive* functions
|
|
165
|
+
│
|
|
166
|
+
├── events/ # Event parsing
|
|
167
|
+
│ └── index.ts # EventParser + 38 event types
|
|
168
|
+
│
|
|
169
|
+
├── errors/ # Typed SDK error classes
|
|
170
|
+
│ └── index.ts # SapError hierarchy
|
|
171
|
+
│
|
|
172
|
+
├── utils/ # Shared utilities
|
|
173
|
+
│ ├── hash.ts # sha256, hashToArray
|
|
174
|
+
│ ├── validation.ts # assert
|
|
175
|
+
│ ├── serialization.ts # serializeAccount, serializeValue
|
|
176
|
+
│ └── index.ts
|
|
177
|
+
│
|
|
178
|
+
├── modules/ # Low-level instruction wrappers
|
|
179
|
+
│ ├── base.ts # BaseModule abstract class
|
|
180
|
+
│ ├── agent.ts # Identity, reputation, lifecycle
|
|
181
|
+
│ ├── feedback.ts # Trustless reviews
|
|
182
|
+
│ ├── indexing.ts # Discovery indexes
|
|
183
|
+
│ ├── tools.ts # Tool schema registry
|
|
184
|
+
│ ├── vault.ts # Encrypted memory vault
|
|
185
|
+
│ ├── escrow.ts # x402 micropayments
|
|
186
|
+
│ ├── attestation.ts # Web-of-trust vouching
|
|
187
|
+
│ ├── ledger.ts # Ring-buffer memory
|
|
188
|
+
│ └── index.ts
|
|
189
|
+
│
|
|
190
|
+
├── registries/ # High-level abstractions
|
|
191
|
+
│ ├── discovery.ts # DiscoveryRegistry — findAgents*, profiles
|
|
192
|
+
│ ├── x402.ts # X402Registry — pricing, headers, settlement
|
|
193
|
+
│ ├── session.ts # SessionManager — vault+session+ledger lifecycle
|
|
194
|
+
│ ├── builder.ts # AgentBuilder — fluent registration
|
|
195
|
+
│ └── index.ts
|
|
196
|
+
│
|
|
197
|
+
├── plugin/ # SynapseAgentKit adapter (52 tools)
|
|
198
|
+
│ ├── index.ts # createSAPPlugin factory
|
|
199
|
+
│ ├── protocols.ts # 8 protocol method registries
|
|
200
|
+
│ └── schemas.ts # Zod schemas for LLM tool validation
|
|
201
|
+
│
|
|
202
|
+
└── idl/ # Embedded Anchor IDL
|
|
203
|
+
├── index.ts # SAP_IDL, IDL_PROGRAM_ADDRESS
|
|
204
|
+
└── synapse_agent_sap.json # 58 ix, 17 accounts, 38 events
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### SapClient Access Tree
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
SapClient
|
|
211
|
+
│
|
|
212
|
+
│ Modules (low-level, 1:1 with program instructions):
|
|
213
|
+
├── .agent → AgentModule (identity, reputation, lifecycle)
|
|
214
|
+
├── .feedback → FeedbackModule (trustless reviews)
|
|
215
|
+
├── .indexing → IndexingModule (capability/protocol/category indexes)
|
|
216
|
+
├── .tools → ToolsModule (tool schemas, checkpoints)
|
|
217
|
+
├── .vault → VaultModule (encrypted memory, delegation)
|
|
218
|
+
├── .escrow → EscrowModule (x402 micropayments, batch settle)
|
|
219
|
+
├── .attestation → AttestationModule (web-of-trust vouching)
|
|
220
|
+
├── .ledger → LedgerModule (ring buffer, sealed pages)
|
|
221
|
+
├── .events → EventParser (decoded TX-log events)
|
|
222
|
+
│
|
|
223
|
+
│ Registries (high-level, cross-module aggregation):
|
|
224
|
+
├── .discovery → DiscoveryRegistry (findAgents*, profiles, network overview)
|
|
225
|
+
├── .x402 → X402Registry (pricing, headers, settlement lifecycle)
|
|
226
|
+
├── .session → SessionManager (vault → session → ledger lifecycle)
|
|
227
|
+
└── .builder → AgentBuilder (fluent registration + tools)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
All module and registry properties are **lazily instantiated** (created on first access).
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Core — Client & Connection
|
|
235
|
+
|
|
236
|
+
### SapClient
|
|
237
|
+
|
|
238
|
+
The primary entry point. Wraps an Anchor `Program` and exposes domain modules.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { SapClient } from "@synapse-sap/sdk";
|
|
242
|
+
|
|
243
|
+
// From AnchorProvider (auto-loads embedded IDL)
|
|
244
|
+
const client = SapClient.from(provider);
|
|
245
|
+
|
|
246
|
+
// From an existing Program instance
|
|
247
|
+
const client = SapClient.fromProgram(program);
|
|
248
|
+
|
|
249
|
+
// With custom program ID
|
|
250
|
+
const client = SapClient.from(provider, customProgramId);
|
|
251
|
+
|
|
252
|
+
// Access properties
|
|
253
|
+
client.program; // Anchor Program instance
|
|
254
|
+
client.walletPubkey; // Wallet public key
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### SapConnection
|
|
258
|
+
|
|
259
|
+
RPC-first factory. Creates `SapClient` instances from an RPC URL — no Anchor boilerplate. Resolves the correct program ID automatically based on cluster.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
import { SapConnection } from "@synapse-sap/sdk";
|
|
263
|
+
|
|
264
|
+
// ─── Cluster shortcuts ───
|
|
265
|
+
const conn = SapConnection.devnet();
|
|
266
|
+
const conn = SapConnection.mainnet("https://my-rpc.com");
|
|
267
|
+
const conn = SapConnection.localnet();
|
|
268
|
+
|
|
269
|
+
// ─── Custom config ───
|
|
270
|
+
const conn = new SapConnection({
|
|
271
|
+
rpcUrl: "https://my-rpc-provider.com",
|
|
272
|
+
cluster: "mainnet-beta",
|
|
273
|
+
commitment: "confirmed",
|
|
274
|
+
wsUrl: "wss://my-rpc-provider.com/ws",
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ─── Create client ───
|
|
278
|
+
const client = conn.fromKeypair(keypair);
|
|
279
|
+
const client = conn.createClient(wallet); // Anchor Wallet
|
|
280
|
+
|
|
281
|
+
// ─── One-liner with client attached ───
|
|
282
|
+
const { client, connection, cluster, programId } = SapConnection.fromKeypair(
|
|
283
|
+
"https://api.devnet.solana.com",
|
|
284
|
+
keypair,
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
// ─── Utility methods ───
|
|
288
|
+
await conn.airdrop(pubkey, 2); // 2 SOL (devnet/localnet)
|
|
289
|
+
const balance = await conn.getBalanceSol(pubkey); // SOL balance
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Modules (Low-Level)
|
|
295
|
+
|
|
296
|
+
Each module wraps one protocol domain. All methods return `TransactionSignature` (the TX hash) unless documented otherwise.
|
|
297
|
+
|
|
298
|
+
### Agent
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
// Register
|
|
302
|
+
await client.agent.register({
|
|
303
|
+
name: "Bot",
|
|
304
|
+
description: "AI agent",
|
|
305
|
+
capabilities: [{ id: "swap", description: null, protocolId: "jupiter", version: "1.0.0" }],
|
|
306
|
+
pricing: [],
|
|
307
|
+
protocols: ["jupiter"],
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// Update metadata
|
|
311
|
+
await client.agent.update({ name: "BotV2" });
|
|
312
|
+
|
|
313
|
+
// Report metrics
|
|
314
|
+
await client.agent.reportCalls(42);
|
|
315
|
+
await client.agent.updateReputation(150, 9950); // 150ms latency, 99.50% uptime
|
|
316
|
+
|
|
317
|
+
// Lifecycle
|
|
318
|
+
await client.agent.deactivate();
|
|
319
|
+
await client.agent.reactivate();
|
|
320
|
+
await client.agent.close();
|
|
321
|
+
|
|
322
|
+
// Fetch
|
|
323
|
+
const agent = await client.agent.fetch(walletPubkey);
|
|
324
|
+
const stats = await client.agent.fetchStats(agentPda);
|
|
325
|
+
const registry = await client.agent.fetchGlobalRegistry();
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Vault (Encrypted Memory)
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
// Init vault
|
|
332
|
+
await client.vault.initVault(Array.from(nonce));
|
|
333
|
+
|
|
334
|
+
// Open session
|
|
335
|
+
await client.vault.openSession(Array.from(sessionHash));
|
|
336
|
+
|
|
337
|
+
// Inscribe encrypted data (zero rent — written to TX log)
|
|
338
|
+
await client.vault.inscribe({
|
|
339
|
+
sequence: 0,
|
|
340
|
+
encryptedData: ciphertext,
|
|
341
|
+
nonce: nonce,
|
|
342
|
+
contentHash: hash,
|
|
343
|
+
totalFragments: 1,
|
|
344
|
+
fragmentIndex: 0,
|
|
345
|
+
compression: 0,
|
|
346
|
+
epochIndex: 0,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Delegation (hot wallet)
|
|
350
|
+
await client.vault.addDelegate(hotWallet, 0b111, expiresAt);
|
|
351
|
+
await client.vault.revokeDelegate(hotWallet);
|
|
352
|
+
|
|
353
|
+
// Close
|
|
354
|
+
await client.vault.closeSession(vaultPda, sessionPda);
|
|
355
|
+
await client.vault.closeVault();
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Escrow (x402 Micropayments)
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
// Create SOL escrow
|
|
362
|
+
await client.escrow.create(agentWallet, {
|
|
363
|
+
pricePerCall: new BN(1_000_000),
|
|
364
|
+
maxCalls: new BN(100),
|
|
365
|
+
initialDeposit: new BN(100_000_000),
|
|
366
|
+
expiresAt: new BN(0),
|
|
367
|
+
volumeCurve: [],
|
|
368
|
+
tokenMint: null,
|
|
369
|
+
tokenDecimals: 9,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// Deposit
|
|
373
|
+
await client.escrow.deposit(agentWallet, new BN(50_000_000));
|
|
374
|
+
|
|
375
|
+
// Agent settles calls
|
|
376
|
+
await client.escrow.settle(depositorWallet, 10, serviceHash);
|
|
377
|
+
|
|
378
|
+
// Batch settlement (up to 10 per TX)
|
|
379
|
+
await client.escrow.settleBatch(depositorWallet, [
|
|
380
|
+
{ callsToSettle: new BN(5), serviceHash: hash1 },
|
|
381
|
+
{ callsToSettle: new BN(3), serviceHash: hash2 },
|
|
382
|
+
]);
|
|
383
|
+
|
|
384
|
+
// Withdraw remaining
|
|
385
|
+
await client.escrow.withdraw(agentWallet, new BN(10_000_000));
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Ledger (Ring Buffer Memory)
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
// Init ledger (~0.032 SOL rent)
|
|
392
|
+
await client.ledger.init(sessionPda);
|
|
393
|
+
|
|
394
|
+
// Write entries (TX fee only, zero additional rent)
|
|
395
|
+
await client.ledger.write(sessionPda, data, contentHash);
|
|
396
|
+
|
|
397
|
+
// Seal current buffer to permanent page (~0.031 SOL)
|
|
398
|
+
await client.ledger.seal(sessionPda);
|
|
399
|
+
|
|
400
|
+
// Read
|
|
401
|
+
const ledger = await client.ledger.fetchLedger(sessionPda);
|
|
402
|
+
const page = await client.ledger.fetchPage(ledgerPda, 0);
|
|
403
|
+
const entries = client.ledger.decodeRingBuffer(ledgerData.ringBuffer);
|
|
404
|
+
|
|
405
|
+
// Close
|
|
406
|
+
await client.ledger.close(sessionPda);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Feedback, Attestation, Tools, Indexing
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
// ── Feedback ──
|
|
413
|
+
await client.feedback.give(agentWallet, { score: 5, tag: "fast", commentHash: null });
|
|
414
|
+
await client.feedback.update(agentWallet, { newScore: 4, newTag: null, commentHash: null });
|
|
415
|
+
await client.feedback.revoke(agentWallet);
|
|
416
|
+
|
|
417
|
+
// ── Attestation ──
|
|
418
|
+
await client.attestation.create(agentWallet, {
|
|
419
|
+
attestationType: 1,
|
|
420
|
+
metadataHash: [...hashBytes],
|
|
421
|
+
expiresAt: new BN(Date.now() / 1000 + 86400 * 365),
|
|
422
|
+
});
|
|
423
|
+
await client.attestation.revoke(agentWallet);
|
|
424
|
+
|
|
425
|
+
// ── Tools ──
|
|
426
|
+
await client.tools.publishByName("swap", "jupiter", "Execute swap", input, output, 1, 0, 3, 2, false);
|
|
427
|
+
await client.tools.inscribeSchema("swap", { schemaType: 0, schemaData, schemaHash, compression: 0 });
|
|
428
|
+
await client.tools.update("swap", { httpMethod: 1, category: null, ... });
|
|
429
|
+
|
|
430
|
+
// ── Indexing ──
|
|
431
|
+
await client.indexing.initCapabilityIndex("jupiter:swap");
|
|
432
|
+
await client.indexing.addToCapabilityIndex("jupiter:swap");
|
|
433
|
+
await client.indexing.initProtocolIndex("jupiter");
|
|
434
|
+
await client.indexing.addToProtocolIndex("jupiter");
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
## Registries (High-Level)
|
|
440
|
+
|
|
441
|
+
Registries provide **cross-module orchestration** with developer-friendly APIs.
|
|
442
|
+
|
|
443
|
+
### DiscoveryRegistry
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
// Find agents by protocol
|
|
447
|
+
const agents = await client.discovery.findAgentsByProtocol("jupiter");
|
|
448
|
+
|
|
449
|
+
// Find by capability
|
|
450
|
+
const swappers = await client.discovery.findAgentsByCapability("jupiter:swap");
|
|
451
|
+
|
|
452
|
+
// Get full agent profile
|
|
453
|
+
const profile = await client.discovery.getAgentProfile(agentWallet);
|
|
454
|
+
// → { agent, stats, tools, feedback, attestations }
|
|
455
|
+
|
|
456
|
+
// Find tools by category
|
|
457
|
+
const tools = await client.discovery.findToolsByCategory("swap");
|
|
458
|
+
|
|
459
|
+
// Network overview
|
|
460
|
+
const overview = await client.discovery.getNetworkOverview();
|
|
461
|
+
// → { totalAgents, activeAgents, totalTools, protocols, categories }
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### X402Registry
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
// Prepare payment context
|
|
468
|
+
const ctx = await client.x402.preparePayment(agentWallet, {
|
|
469
|
+
tierId: "standard",
|
|
470
|
+
maxCalls: 100,
|
|
471
|
+
initialDeposit: new BN(100_000_000),
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Build HTTP headers (for x402 protocol)
|
|
475
|
+
const headers = client.x402.buildPaymentHeaders(ctx);
|
|
476
|
+
// → { "X-402-Token": "...", "X-402-Agent": "...", ... }
|
|
477
|
+
|
|
478
|
+
// Estimate costs
|
|
479
|
+
const cost = await client.x402.estimateCost(agentWallet, 50);
|
|
480
|
+
// → { totalLamports, perCallLamports, tierId }
|
|
481
|
+
|
|
482
|
+
// Settle
|
|
483
|
+
const receipt = await client.x402.settle(depositor, 5, serviceData);
|
|
484
|
+
|
|
485
|
+
// Batch settle
|
|
486
|
+
const results = await client.x402.batchSettle(depositor, settlements);
|
|
487
|
+
|
|
488
|
+
// Check balance
|
|
489
|
+
const balance = await client.x402.getBalance(agentWallet, depositorWallet);
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### SessionManager
|
|
493
|
+
|
|
494
|
+
Manages the full `vault → session → ledger` lifecycle in one API:
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
// Start a session (inits vault + opens session + inits ledger)
|
|
498
|
+
const ctx = await client.session.start("conversation-123");
|
|
499
|
+
// → { vaultPda, sessionPda, ledgerPda, sessionHash }
|
|
500
|
+
|
|
501
|
+
// Write data
|
|
502
|
+
const result = await client.session.write(ctx, "Hello from agent");
|
|
503
|
+
// → { txSignature, sequence }
|
|
504
|
+
|
|
505
|
+
// Read latest entries
|
|
506
|
+
const messages = await client.session.readLatest(ctx);
|
|
507
|
+
// → RingBufferEntry[]
|
|
508
|
+
|
|
509
|
+
// Seal to permanent storage
|
|
510
|
+
const seal = await client.session.seal(ctx);
|
|
511
|
+
// → { txSignature, pageIndex }
|
|
512
|
+
|
|
513
|
+
// Get session status
|
|
514
|
+
const status = await client.session.getStatus(ctx);
|
|
515
|
+
// → { isOpen, totalWrites, sealedPages, ringBufferUsage }
|
|
516
|
+
|
|
517
|
+
// End session
|
|
518
|
+
await client.session.end(ctx);
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### AgentBuilder
|
|
522
|
+
|
|
523
|
+
Fluent builder for one-shot agent registration with tools:
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
const result = await client.builder
|
|
527
|
+
.agent("SwapBot")
|
|
528
|
+
.description("AI-powered DEX aggregator using Jupiter")
|
|
529
|
+
.x402Endpoint("https://api.mybot.com/x402")
|
|
530
|
+
.addCapability("jupiter:swap", {
|
|
531
|
+
protocol: "jupiter",
|
|
532
|
+
description: "Execute token swaps",
|
|
533
|
+
})
|
|
534
|
+
.addCapability("jupiter:quote", {
|
|
535
|
+
protocol: "jupiter",
|
|
536
|
+
description: "Get swap quotes",
|
|
537
|
+
})
|
|
538
|
+
.addPricingTier({
|
|
539
|
+
tierId: "standard",
|
|
540
|
+
pricePerCall: 1000,
|
|
541
|
+
rateLimit: 60,
|
|
542
|
+
tokenType: "sol",
|
|
543
|
+
settlementMode: "x402",
|
|
544
|
+
})
|
|
545
|
+
.addTool({
|
|
546
|
+
name: "swap",
|
|
547
|
+
protocolId: "jupiter",
|
|
548
|
+
description: "Execute a token swap",
|
|
549
|
+
category: "swap",
|
|
550
|
+
httpMethod: "post",
|
|
551
|
+
paramsCount: 3,
|
|
552
|
+
requiredParams: 2,
|
|
553
|
+
})
|
|
554
|
+
.registerWithTools();
|
|
555
|
+
// → { agentTx, toolTxs: string[] }
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
## Plugin (SynapseAgentKit)
|
|
561
|
+
|
|
562
|
+
The SDK ships a 52-tool plugin that integrates with `SynapseAgentKit` and
|
|
563
|
+
LangChain-compatible AI agent frameworks:
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
import { createSAPPlugin } from "@synapse-sap/sdk/plugin";
|
|
567
|
+
|
|
568
|
+
// Create plugin
|
|
569
|
+
const sapPlugin = createSAPPlugin({ provider });
|
|
570
|
+
|
|
571
|
+
// Use with SynapseAgentKit
|
|
572
|
+
const kit = new SynapseAgentKit({ rpcUrl })
|
|
573
|
+
.use(sapPlugin);
|
|
574
|
+
|
|
575
|
+
const tools = kit.getTools(); // → 52 LangChain StructuredTool instances
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
**8 Protocol Domains × Tools:**
|
|
579
|
+
|
|
580
|
+
| Protocol | Tools |
|
|
581
|
+
|----------|-------|
|
|
582
|
+
| `sap-agent` | registerAgent, updateAgent, deactivateAgent, reactivateAgent, reportCalls, updateReputation, fetchAgent, fetchGlobalRegistry |
|
|
583
|
+
| `sap-feedback` | giveFeedback, updateFeedback, revokeFeedback, fetchFeedback |
|
|
584
|
+
| `sap-attestation` | createAttestation, revokeAttestation, fetchAttestation |
|
|
585
|
+
| `sap-escrow` | createEscrow, depositEscrow, settleEscrow, withdrawEscrow, batchSettle, fetchEscrow |
|
|
586
|
+
| `sap-tools` | publishToolByName, inscribeToolSchema, updateTool, deactivateTool, reactivateTool, reportInvocations, fetchTool |
|
|
587
|
+
| `sap-vault` | initVault, openSession, inscribeMemory, closeSession, closeVault, rotateNonce, addDelegate, revokeDelegate, fetchVault, fetchSession |
|
|
588
|
+
| `sap-indexing` | initCapabilityIndex, addToCapabilityIndex, removeFromCapabilityIndex, initProtocolIndex, addToProtocolIndex, removeFromProtocolIndex, fetchCapabilityIndex, fetchProtocolIndex |
|
|
589
|
+
| `sap-ledger` | initLedger, writeLedger, sealLedger, closeLedger, fetchLedger, fetchLedgerPage |
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
## PDA Derivation
|
|
594
|
+
|
|
595
|
+
All 17 PDA functions are pure (no RPC calls) and return `[PublicKey, bump]`:
|
|
596
|
+
|
|
597
|
+
```typescript
|
|
598
|
+
import {
|
|
599
|
+
deriveAgent,
|
|
600
|
+
deriveVault,
|
|
601
|
+
deriveSession,
|
|
602
|
+
deriveEscrow,
|
|
603
|
+
deriveTool,
|
|
604
|
+
deriveLedger,
|
|
605
|
+
deriveAttestation,
|
|
606
|
+
} from "@synapse-sap/sdk/pda";
|
|
607
|
+
|
|
608
|
+
const [agentPda, bump] = deriveAgent(walletPubkey);
|
|
609
|
+
const [vaultPda] = deriveVault(agentPda);
|
|
610
|
+
const [sessionPda] = deriveSession(vaultPda, sessionHashBytes);
|
|
611
|
+
const [escrowPda] = deriveEscrow(agentPda, depositorPubkey);
|
|
612
|
+
const [toolPda] = deriveTool(agentPda, toolNameHash);
|
|
613
|
+
const [ledgerPda] = deriveLedger(sessionPda);
|
|
614
|
+
const [attestPda] = deriveAttestation(agentPda, attesterPubkey);
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
**Full list:** `deriveGlobalRegistry`, `deriveAgent`, `deriveAgentStats`, `deriveFeedback`, `deriveCapabilityIndex`, `deriveProtocolIndex`, `deriveToolCategoryIndex`, `deriveVault`, `deriveSession`, `deriveEpochPage`, `deriveVaultDelegate`, `deriveCheckpoint`, `deriveTool`, `deriveEscrow`, `deriveAttestation`, `deriveLedger`, `deriveLedgerPage`
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
## Events
|
|
622
|
+
|
|
623
|
+
Decode SAP events from transaction logs:
|
|
624
|
+
|
|
625
|
+
```typescript
|
|
626
|
+
import { EventParser } from "@synapse-sap/sdk";
|
|
627
|
+
|
|
628
|
+
// Parse
|
|
629
|
+
const events = client.events.parseLogs(txLogs);
|
|
630
|
+
|
|
631
|
+
// Filter
|
|
632
|
+
const inscriptions = client.events.filterByName(events, "MemoryInscribedEvent");
|
|
633
|
+
const payments = client.events.filterByName(events, "PaymentSettledEvent");
|
|
634
|
+
|
|
635
|
+
// 38 event types available (see API Reference)
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
---
|
|
639
|
+
|
|
640
|
+
## Error Handling
|
|
641
|
+
|
|
642
|
+
The SDK provides a typed error hierarchy for precise error handling:
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
import {
|
|
646
|
+
SapError,
|
|
647
|
+
SapRpcError,
|
|
648
|
+
SapAccountNotFoundError,
|
|
649
|
+
SapValidationError,
|
|
650
|
+
SapTimeoutError,
|
|
651
|
+
SapPermissionError,
|
|
652
|
+
} from "@synapse-sap/sdk";
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
const agent = await client.agent.fetch();
|
|
656
|
+
} catch (err) {
|
|
657
|
+
if (err instanceof SapAccountNotFoundError) {
|
|
658
|
+
// Account doesn't exist on-chain
|
|
659
|
+
console.log(`${err.accountType} not found: ${err.address}`);
|
|
660
|
+
} else if (err instanceof SapRpcError) {
|
|
661
|
+
// Anchor / RPC error with code and logs
|
|
662
|
+
console.error(`RPC error ${err.rpcCode}:`, err.logs);
|
|
663
|
+
} else if (err instanceof SapValidationError) {
|
|
664
|
+
// SDK-side validation failed
|
|
665
|
+
console.error(`Invalid ${err.field}:`, err.message);
|
|
666
|
+
} else if (err instanceof SapTimeoutError) {
|
|
667
|
+
// Transaction confirmation timeout
|
|
668
|
+
console.error(`Timeout after ${err.timeoutMs}ms`);
|
|
669
|
+
} else if (err instanceof SapPermissionError) {
|
|
670
|
+
// Missing authority / delegate permission
|
|
671
|
+
console.error(err.message);
|
|
672
|
+
} else if (err instanceof SapError) {
|
|
673
|
+
// Catch-all for any SAP SDK error
|
|
674
|
+
console.error(`[${err.code}]`, err.message);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Wrapping Anchor errors
|
|
679
|
+
try {
|
|
680
|
+
await program.methods.registerAgent(...).rpc();
|
|
681
|
+
} catch (e) {
|
|
682
|
+
throw SapRpcError.fromAnchor(e); // extracts code + logs
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
## Utilities
|
|
689
|
+
|
|
690
|
+
```typescript
|
|
691
|
+
import { sha256, hashToArray, assert, serializeAccount, serializeValue } from "@synapse-sap/sdk";
|
|
692
|
+
|
|
693
|
+
// ── Hashing ──
|
|
694
|
+
const hash = sha256("jupiter:swap"); // Uint8Array (32 bytes)
|
|
695
|
+
const arr = hashToArray(hash); // number[] for Anchor args
|
|
696
|
+
|
|
697
|
+
// ── Assertion ──
|
|
698
|
+
assert(score >= 1 && score <= 5, "Score must be 1–5"); // throws RangeError
|
|
699
|
+
|
|
700
|
+
// ── Serialization (PublicKey/BN → JSON-safe) ──
|
|
701
|
+
const raw = await program.account.agent.fetch(pda);
|
|
702
|
+
const json = serializeAccount(raw);
|
|
703
|
+
// { authority: "GBL...", totalCalls: "42", isActive: true }
|
|
704
|
+
|
|
705
|
+
const val = serializeValue(somePublicKey); // → "base58string"
|
|
706
|
+
const val = serializeValue(new BN(1000)); // → "1000"
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
---
|
|
710
|
+
|
|
711
|
+
## Types
|
|
712
|
+
|
|
713
|
+
Every on-chain type is mirrored in TypeScript:
|
|
714
|
+
|
|
715
|
+
```typescript
|
|
716
|
+
import type {
|
|
717
|
+
// Account data
|
|
718
|
+
AgentAccountData,
|
|
719
|
+
EscrowAccountData,
|
|
720
|
+
MemoryVaultData,
|
|
721
|
+
ToolDescriptorData,
|
|
722
|
+
|
|
723
|
+
// Instruction args
|
|
724
|
+
RegisterAgentArgs,
|
|
725
|
+
CreateEscrowArgs,
|
|
726
|
+
InscribeMemoryArgs,
|
|
727
|
+
|
|
728
|
+
// Helper types
|
|
729
|
+
Capability,
|
|
730
|
+
PricingTier,
|
|
731
|
+
Settlement,
|
|
732
|
+
VolumeCurveBreakpoint,
|
|
733
|
+
} from "@synapse-sap/sdk/types";
|
|
734
|
+
|
|
735
|
+
import {
|
|
736
|
+
TokenType, // { sol: {}, usdc: {}, spl: {} }
|
|
737
|
+
SettlementMode, // { instant: {}, escrow: {}, batched: {}, x402: {} }
|
|
738
|
+
ToolCategory, // { swap: {}, lend: {}, stake: {}, ... }
|
|
739
|
+
DelegatePermission, // READ, WRITE, ADMIN bit flags
|
|
740
|
+
SchemaType, // INPUT, OUTPUT, DESCRIPTION
|
|
741
|
+
CompressionType, // NONE, DEFLATE, GZIP, BROTLI
|
|
742
|
+
} from "@synapse-sap/sdk/types";
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
---
|
|
746
|
+
|
|
747
|
+
## Constants
|
|
748
|
+
|
|
749
|
+
```typescript
|
|
750
|
+
import {
|
|
751
|
+
SAP_PROGRAM_ADDRESS, // "SAPTU7aUXk2AaAdktexae1iuxXpokxzNDBAYYhaVyQL"
|
|
752
|
+
SAP_PROGRAM_ID, // PublicKey (= devnet for now)
|
|
753
|
+
MAINNET_SAP_PROGRAM_ID, // PublicKey
|
|
754
|
+
DEVNET_SAP_PROGRAM_ID, // PublicKey
|
|
755
|
+
LOCALNET_SAP_PROGRAM_ID, // PublicKey
|
|
756
|
+
SEEDS, // { agent: "agent", vault: "vault", ... } (20 seeds)
|
|
757
|
+
LIMITS, // { maxNameLen: 64, maxCapabilities: 10, ... } (23 limits)
|
|
758
|
+
AGENT_VERSION, // 2
|
|
759
|
+
VAULT_PROTOCOL_VERSION, // 2
|
|
760
|
+
TOOL_CATEGORY_VALUES, // { swap: 0, lend: 1, ... }
|
|
761
|
+
HTTP_METHOD_VALUES, // { get: 0, post: 1, ... }
|
|
762
|
+
} from "@synapse-sap/sdk/constants";
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
---
|
|
766
|
+
|
|
767
|
+
## Deep Imports
|
|
768
|
+
|
|
769
|
+
Import individual packages for smaller bundles:
|
|
770
|
+
|
|
771
|
+
```typescript
|
|
772
|
+
// Core
|
|
773
|
+
import { SapClient, SapConnection } from "@synapse-sap/sdk/core";
|
|
774
|
+
|
|
775
|
+
// Individual modules
|
|
776
|
+
import { AgentModule } from "@synapse-sap/sdk/agent";
|
|
777
|
+
import { EscrowModule } from "@synapse-sap/sdk/escrow";
|
|
778
|
+
|
|
779
|
+
// Types only (zero runtime cost)
|
|
780
|
+
import type { AgentAccountData } from "@synapse-sap/sdk/types";
|
|
781
|
+
import type { SapCluster } from "@synapse-sap/sdk/core";
|
|
782
|
+
|
|
783
|
+
// PDA derivation
|
|
784
|
+
import { deriveAgent, deriveEscrow } from "@synapse-sap/sdk/pda";
|
|
785
|
+
|
|
786
|
+
// Constants
|
|
787
|
+
import { SEEDS, LIMITS } from "@synapse-sap/sdk/constants";
|
|
788
|
+
|
|
789
|
+
// Events
|
|
790
|
+
import { EventParser } from "@synapse-sap/sdk/events";
|
|
791
|
+
|
|
792
|
+
// Errors
|
|
793
|
+
import { SapError, SapRpcError } from "@synapse-sap/sdk/errors";
|
|
794
|
+
|
|
795
|
+
// Utilities
|
|
796
|
+
import { sha256, serializeAccount } from "@synapse-sap/sdk/utils";
|
|
797
|
+
|
|
798
|
+
// IDL
|
|
799
|
+
import { SAP_IDL } from "@synapse-sap/sdk/idl";
|
|
800
|
+
|
|
801
|
+
// Plugin
|
|
802
|
+
import { createSAPPlugin } from "@synapse-sap/sdk/plugin";
|
|
803
|
+
|
|
804
|
+
// Registries
|
|
805
|
+
import { DiscoveryRegistry } from "@synapse-sap/sdk/registries/discovery";
|
|
806
|
+
import { X402Registry } from "@synapse-sap/sdk/registries/x402";
|
|
807
|
+
import { SessionManager } from "@synapse-sap/sdk/registries/session";
|
|
808
|
+
import { AgentBuilder } from "@synapse-sap/sdk/registries/builder";
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
---
|
|
812
|
+
|
|
813
|
+
## API Reference
|
|
814
|
+
|
|
815
|
+
### Accounts (17 types)
|
|
816
|
+
|
|
817
|
+
| Account | Description |
|
|
818
|
+
|---------|-------------|
|
|
819
|
+
| `AgentAccountData` | Agent identity, capabilities, pricing, protocols |
|
|
820
|
+
| `AgentStatsData` | Call count, latency, uptime metrics |
|
|
821
|
+
| `GlobalRegistryData` | Protocol-wide agent counter + authority |
|
|
822
|
+
| `FeedbackAccountData` | Single reviewer's feedback for an agent |
|
|
823
|
+
| `CapabilityIndexData` | List of agents with a given capability |
|
|
824
|
+
| `ProtocolIndexData` | List of agents supporting a protocol |
|
|
825
|
+
| `ToolCategoryIndexData` | List of tools in a category |
|
|
826
|
+
| `ToolDescriptorData` | Tool schema, metadata, invocation stats |
|
|
827
|
+
| `SessionCheckpointData` | Session checkpoint for recovery |
|
|
828
|
+
| `MemoryVaultData` | Encrypted vault metadata + encryption nonce |
|
|
829
|
+
| `SessionLedgerData` | Session within a vault |
|
|
830
|
+
| `EpochPageData` | Finalized epoch page of inscriptions |
|
|
831
|
+
| `VaultDelegateData` | Delegate permissions + expiry |
|
|
832
|
+
| `EscrowAccountData` | x402 escrow balance + settlement state |
|
|
833
|
+
| `AgentAttestationData` | Attestation metadata + expiry |
|
|
834
|
+
| `MemoryLedgerData` | Ring-buffer ledger metadata |
|
|
835
|
+
| `LedgerPageData` | Sealed ledger page content |
|
|
836
|
+
|
|
837
|
+
### Events (38 types)
|
|
838
|
+
|
|
839
|
+
`RegisteredEvent` · `UpdatedEvent` · `DeactivatedEvent` · `ReactivatedEvent` · `ClosedEvent` · `FeedbackEvent` · `FeedbackUpdatedEvent` · `FeedbackRevokedEvent` · `ReputationUpdatedEvent` · `CallsReportedEvent` · `VaultInitializedEvent` · `SessionOpenedEvent` · `MemoryInscribedEvent` · `EpochOpenedEvent` · `SessionClosedEvent` · `VaultClosedEvent` · `SessionPdaClosedEvent` · `EpochPageClosedEvent` · `VaultNonceRotatedEvent` · `DelegateAddedEvent` · `DelegateRevokedEvent` · `ToolPublishedEvent` · `ToolSchemaInscribedEvent` · `ToolUpdatedEvent` · `ToolDeactivatedEvent` · `ToolReactivatedEvent` · `ToolClosedEvent` · `ToolInvocationReportedEvent` · `CheckpointCreatedEvent` · `EscrowCreatedEvent` · `EscrowDepositedEvent` · `PaymentSettledEvent` · `EscrowWithdrawnEvent` · `BatchSettledEvent` · `AttestationCreatedEvent` · `AttestationRevokedEvent` · `LedgerEntryEvent` · `LedgerSealedEvent`
|
|
840
|
+
|
|
841
|
+
### Enum Constants
|
|
842
|
+
|
|
843
|
+
| Enum | Variants |
|
|
844
|
+
|------|----------|
|
|
845
|
+
| `TokenType` | `sol`, `usdc`, `spl` |
|
|
846
|
+
| `PluginType` | `native`, `wasm`, `external` |
|
|
847
|
+
| `SettlementMode` | `instant`, `escrow`, `batched`, `x402` |
|
|
848
|
+
| `ToolHttpMethod` | `get`, `post`, `put`, `delete`, `compound` |
|
|
849
|
+
| `ToolCategory` | `swap`, `lend`, `stake`, `nft`, `payment`, `data`, `governance`, `bridge`, `analytics`, `custom` |
|
|
850
|
+
| `DelegatePermission` | `READ` (1), `WRITE` (2), `ADMIN` (4) |
|
|
851
|
+
| `SchemaType` | `INPUT` (0), `OUTPUT` (1), `DESCRIPTION` (2) |
|
|
852
|
+
| `CompressionType` | `NONE` (0), `DEFLATE` (1), `GZIP` (2), `BROTLI` (3) |
|
|
853
|
+
|
|
854
|
+
---
|
|
855
|
+
|
|
856
|
+
## Development
|
|
857
|
+
|
|
858
|
+
```bash
|
|
859
|
+
yarn install # Install dependencies
|
|
860
|
+
yarn typecheck # Type-check (strict mode)
|
|
861
|
+
yarn build # Build CJS + ESM + declarations
|
|
862
|
+
yarn clean # Remove dist/
|
|
863
|
+
yarn sync-idl # Copy latest IDL from anchor build
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
### Building for Developers
|
|
867
|
+
|
|
868
|
+
The SDK outputs three artifacts:
|
|
869
|
+
|
|
870
|
+
| Output | Path | Config |
|
|
871
|
+
|--------|------|--------|
|
|
872
|
+
| ESM | `dist/esm/` | `tsconfig.esm.json` |
|
|
873
|
+
| CJS | `dist/cjs/` | `tsconfig.cjs.json` |
|
|
874
|
+
| Types | `dist/types/` | `tsconfig.json --emitDeclarationOnly` |
|
|
875
|
+
|
|
876
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for full development guidelines.
|
|
877
|
+
|
|
878
|
+
---
|
|
879
|
+
|
|
880
|
+
## License
|
|
881
|
+
|
|
882
|
+
[MIT](LICENSE)
|