@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.
Files changed (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +882 -0
  3. package/dist/cjs/constants/index.js +43 -0
  4. package/dist/cjs/constants/index.js.map +1 -0
  5. package/dist/cjs/constants/limits.js +161 -0
  6. package/dist/cjs/constants/limits.js.map +1 -0
  7. package/dist/cjs/constants/programs.js +78 -0
  8. package/dist/cjs/constants/programs.js.map +1 -0
  9. package/dist/cjs/constants/seeds.js +57 -0
  10. package/dist/cjs/constants/seeds.js.map +1 -0
  11. package/dist/cjs/core/client.js +391 -0
  12. package/dist/cjs/core/client.js.map +1 -0
  13. package/dist/cjs/core/connection.js +319 -0
  14. package/dist/cjs/core/connection.js.map +1 -0
  15. package/dist/cjs/core/index.js +24 -0
  16. package/dist/cjs/core/index.js.map +1 -0
  17. package/dist/cjs/errors/index.js +334 -0
  18. package/dist/cjs/errors/index.js.map +1 -0
  19. package/dist/cjs/events/index.js +136 -0
  20. package/dist/cjs/events/index.js.map +1 -0
  21. package/dist/cjs/idl/index.js +63 -0
  22. package/dist/cjs/idl/index.js.map +1 -0
  23. package/dist/cjs/idl/synapse_agent_sap.json +9710 -0
  24. package/dist/cjs/index.js +147 -0
  25. package/dist/cjs/index.js.map +1 -0
  26. package/dist/cjs/modules/agent.js +272 -0
  27. package/dist/cjs/modules/agent.js.map +1 -0
  28. package/dist/cjs/modules/attestation.js +147 -0
  29. package/dist/cjs/modules/attestation.js.map +1 -0
  30. package/dist/cjs/modules/base.js +128 -0
  31. package/dist/cjs/modules/base.js.map +1 -0
  32. package/dist/cjs/modules/escrow.js +246 -0
  33. package/dist/cjs/modules/escrow.js.map +1 -0
  34. package/dist/cjs/modules/feedback.js +166 -0
  35. package/dist/cjs/modules/feedback.js.map +1 -0
  36. package/dist/cjs/modules/index.js +35 -0
  37. package/dist/cjs/modules/index.js.map +1 -0
  38. package/dist/cjs/modules/indexing.js +375 -0
  39. package/dist/cjs/modules/indexing.js.map +1 -0
  40. package/dist/cjs/modules/ledger.js +234 -0
  41. package/dist/cjs/modules/ledger.js.map +1 -0
  42. package/dist/cjs/modules/tools.js +319 -0
  43. package/dist/cjs/modules/tools.js.map +1 -0
  44. package/dist/cjs/modules/vault.js +410 -0
  45. package/dist/cjs/modules/vault.js.map +1 -0
  46. package/dist/cjs/pda/index.js +377 -0
  47. package/dist/cjs/pda/index.js.map +1 -0
  48. package/dist/cjs/plugin/index.js +934 -0
  49. package/dist/cjs/plugin/index.js.map +1 -0
  50. package/dist/cjs/plugin/protocols.js +282 -0
  51. package/dist/cjs/plugin/protocols.js.map +1 -0
  52. package/dist/cjs/plugin/schemas.js +831 -0
  53. package/dist/cjs/plugin/schemas.js.map +1 -0
  54. package/dist/cjs/postgres/adapter.js +715 -0
  55. package/dist/cjs/postgres/adapter.js.map +1 -0
  56. package/dist/cjs/postgres/index.js +50 -0
  57. package/dist/cjs/postgres/index.js.map +1 -0
  58. package/dist/cjs/postgres/serializers.js +381 -0
  59. package/dist/cjs/postgres/serializers.js.map +1 -0
  60. package/dist/cjs/postgres/sync.js +221 -0
  61. package/dist/cjs/postgres/sync.js.map +1 -0
  62. package/dist/cjs/postgres/types.js +44 -0
  63. package/dist/cjs/postgres/types.js.map +1 -0
  64. package/dist/cjs/registries/builder.js +414 -0
  65. package/dist/cjs/registries/builder.js.map +1 -0
  66. package/dist/cjs/registries/discovery.js +362 -0
  67. package/dist/cjs/registries/discovery.js.map +1 -0
  68. package/dist/cjs/registries/index.js +51 -0
  69. package/dist/cjs/registries/index.js.map +1 -0
  70. package/dist/cjs/registries/session.js +433 -0
  71. package/dist/cjs/registries/session.js.map +1 -0
  72. package/dist/cjs/registries/x402.js +577 -0
  73. package/dist/cjs/registries/x402.js.map +1 -0
  74. package/dist/cjs/types/accounts.js +13 -0
  75. package/dist/cjs/types/accounts.js.map +1 -0
  76. package/dist/cjs/types/common.js +13 -0
  77. package/dist/cjs/types/common.js.map +1 -0
  78. package/dist/cjs/types/enums.js +174 -0
  79. package/dist/cjs/types/enums.js.map +1 -0
  80. package/dist/cjs/types/index.js +36 -0
  81. package/dist/cjs/types/index.js.map +1 -0
  82. package/dist/cjs/types/instructions.js +92 -0
  83. package/dist/cjs/types/instructions.js.map +1 -0
  84. package/dist/cjs/utils/hash.js +58 -0
  85. package/dist/cjs/utils/hash.js.map +1 -0
  86. package/dist/cjs/utils/index.js +27 -0
  87. package/dist/cjs/utils/index.js.map +1 -0
  88. package/dist/cjs/utils/serialization.js +105 -0
  89. package/dist/cjs/utils/serialization.js.map +1 -0
  90. package/dist/cjs/utils/validation.js +36 -0
  91. package/dist/cjs/utils/validation.js.map +1 -0
  92. package/dist/esm/constants/index.js +29 -0
  93. package/dist/esm/constants/index.js.map +1 -0
  94. package/dist/esm/constants/limits.js +158 -0
  95. package/dist/esm/constants/limits.js.map +1 -0
  96. package/dist/esm/constants/programs.js +75 -0
  97. package/dist/esm/constants/programs.js.map +1 -0
  98. package/dist/esm/constants/seeds.js +54 -0
  99. package/dist/esm/constants/seeds.js.map +1 -0
  100. package/dist/esm/core/client.js +384 -0
  101. package/dist/esm/core/client.js.map +1 -0
  102. package/dist/esm/core/connection.js +315 -0
  103. package/dist/esm/core/connection.js.map +1 -0
  104. package/dist/esm/core/index.js +19 -0
  105. package/dist/esm/core/index.js.map +1 -0
  106. package/dist/esm/errors/index.js +325 -0
  107. package/dist/esm/errors/index.js.map +1 -0
  108. package/dist/esm/events/index.js +132 -0
  109. package/dist/esm/events/index.js.map +1 -0
  110. package/dist/esm/idl/index.js +57 -0
  111. package/dist/esm/idl/index.js.map +1 -0
  112. package/dist/esm/idl/synapse_agent_sap.json +9710 -0
  113. package/dist/esm/index.js +70 -0
  114. package/dist/esm/index.js.map +1 -0
  115. package/dist/esm/modules/agent.js +268 -0
  116. package/dist/esm/modules/agent.js.map +1 -0
  117. package/dist/esm/modules/attestation.js +143 -0
  118. package/dist/esm/modules/attestation.js.map +1 -0
  119. package/dist/esm/modules/base.js +124 -0
  120. package/dist/esm/modules/base.js.map +1 -0
  121. package/dist/esm/modules/escrow.js +242 -0
  122. package/dist/esm/modules/escrow.js.map +1 -0
  123. package/dist/esm/modules/feedback.js +162 -0
  124. package/dist/esm/modules/feedback.js.map +1 -0
  125. package/dist/esm/modules/index.js +23 -0
  126. package/dist/esm/modules/index.js.map +1 -0
  127. package/dist/esm/modules/indexing.js +371 -0
  128. package/dist/esm/modules/indexing.js.map +1 -0
  129. package/dist/esm/modules/ledger.js +230 -0
  130. package/dist/esm/modules/ledger.js.map +1 -0
  131. package/dist/esm/modules/tools.js +315 -0
  132. package/dist/esm/modules/tools.js.map +1 -0
  133. package/dist/esm/modules/vault.js +406 -0
  134. package/dist/esm/modules/vault.js.map +1 -0
  135. package/dist/esm/pda/index.js +357 -0
  136. package/dist/esm/pda/index.js.map +1 -0
  137. package/dist/esm/plugin/index.js +927 -0
  138. package/dist/esm/plugin/index.js.map +1 -0
  139. package/dist/esm/plugin/protocols.js +279 -0
  140. package/dist/esm/plugin/protocols.js.map +1 -0
  141. package/dist/esm/plugin/schemas.js +828 -0
  142. package/dist/esm/plugin/schemas.js.map +1 -0
  143. package/dist/esm/postgres/adapter.js +678 -0
  144. package/dist/esm/postgres/adapter.js.map +1 -0
  145. package/dist/esm/postgres/index.js +27 -0
  146. package/dist/esm/postgres/index.js.map +1 -0
  147. package/dist/esm/postgres/serializers.js +362 -0
  148. package/dist/esm/postgres/serializers.js.map +1 -0
  149. package/dist/esm/postgres/sync.js +217 -0
  150. package/dist/esm/postgres/sync.js.map +1 -0
  151. package/dist/esm/postgres/types.js +41 -0
  152. package/dist/esm/postgres/types.js.map +1 -0
  153. package/dist/esm/registries/builder.js +410 -0
  154. package/dist/esm/registries/builder.js.map +1 -0
  155. package/dist/esm/registries/discovery.js +358 -0
  156. package/dist/esm/registries/discovery.js.map +1 -0
  157. package/dist/esm/registries/index.js +44 -0
  158. package/dist/esm/registries/index.js.map +1 -0
  159. package/dist/esm/registries/session.js +429 -0
  160. package/dist/esm/registries/session.js.map +1 -0
  161. package/dist/esm/registries/x402.js +573 -0
  162. package/dist/esm/registries/x402.js.map +1 -0
  163. package/dist/esm/types/accounts.js +12 -0
  164. package/dist/esm/types/accounts.js.map +1 -0
  165. package/dist/esm/types/common.js +12 -0
  166. package/dist/esm/types/common.js.map +1 -0
  167. package/dist/esm/types/enums.js +171 -0
  168. package/dist/esm/types/enums.js.map +1 -0
  169. package/dist/esm/types/index.js +25 -0
  170. package/dist/esm/types/index.js.map +1 -0
  171. package/dist/esm/types/instructions.js +89 -0
  172. package/dist/esm/types/instructions.js.map +1 -0
  173. package/dist/esm/utils/hash.js +53 -0
  174. package/dist/esm/utils/hash.js.map +1 -0
  175. package/dist/esm/utils/index.js +19 -0
  176. package/dist/esm/utils/index.js.map +1 -0
  177. package/dist/esm/utils/serialization.js +98 -0
  178. package/dist/esm/utils/serialization.js.map +1 -0
  179. package/dist/esm/utils/validation.js +33 -0
  180. package/dist/esm/utils/validation.js.map +1 -0
  181. package/dist/types/constants/index.d.ts +27 -0
  182. package/dist/types/constants/index.d.ts.map +1 -0
  183. package/dist/types/constants/limits.d.ts +149 -0
  184. package/dist/types/constants/limits.d.ts.map +1 -0
  185. package/dist/types/constants/programs.d.ts +69 -0
  186. package/dist/types/constants/programs.d.ts.map +1 -0
  187. package/dist/types/constants/seeds.d.ts +61 -0
  188. package/dist/types/constants/seeds.d.ts.map +1 -0
  189. package/dist/types/core/client.d.ts +323 -0
  190. package/dist/types/core/client.d.ts.map +1 -0
  191. package/dist/types/core/connection.d.ts +279 -0
  192. package/dist/types/core/connection.d.ts.map +1 -0
  193. package/dist/types/core/index.d.ts +20 -0
  194. package/dist/types/core/index.d.ts.map +1 -0
  195. package/dist/types/errors/index.d.ts +276 -0
  196. package/dist/types/errors/index.d.ts.map +1 -0
  197. package/dist/types/events/index.d.ts +248 -0
  198. package/dist/types/events/index.d.ts.map +1 -0
  199. package/dist/types/idl/index.d.ts +70 -0
  200. package/dist/types/idl/index.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +68 -0
  202. package/dist/types/index.d.ts.map +1 -0
  203. package/dist/types/modules/agent.d.ts +166 -0
  204. package/dist/types/modules/agent.d.ts.map +1 -0
  205. package/dist/types/modules/attestation.d.ts +96 -0
  206. package/dist/types/modules/attestation.d.ts.map +1 -0
  207. package/dist/types/modules/base.d.ts +126 -0
  208. package/dist/types/modules/base.d.ts.map +1 -0
  209. package/dist/types/modules/escrow.d.ts +151 -0
  210. package/dist/types/modules/escrow.d.ts.map +1 -0
  211. package/dist/types/modules/feedback.d.ts +105 -0
  212. package/dist/types/modules/feedback.d.ts.map +1 -0
  213. package/dist/types/modules/index.d.ts +24 -0
  214. package/dist/types/modules/index.d.ts.map +1 -0
  215. package/dist/types/modules/indexing.d.ts +200 -0
  216. package/dist/types/modules/indexing.d.ts.map +1 -0
  217. package/dist/types/modules/ledger.d.ts +150 -0
  218. package/dist/types/modules/ledger.d.ts.map +1 -0
  219. package/dist/types/modules/tools.d.ts +182 -0
  220. package/dist/types/modules/tools.d.ts.map +1 -0
  221. package/dist/types/modules/vault.d.ts +240 -0
  222. package/dist/types/modules/vault.d.ts.map +1 -0
  223. package/dist/types/pda/index.d.ts +296 -0
  224. package/dist/types/pda/index.d.ts.map +1 -0
  225. package/dist/types/plugin/index.d.ts +171 -0
  226. package/dist/types/plugin/index.d.ts.map +1 -0
  227. package/dist/types/plugin/protocols.d.ts +152 -0
  228. package/dist/types/plugin/protocols.d.ts.map +1 -0
  229. package/dist/types/plugin/schemas.d.ts +823 -0
  230. package/dist/types/plugin/schemas.d.ts.map +1 -0
  231. package/dist/types/postgres/adapter.d.ts +355 -0
  232. package/dist/types/postgres/adapter.d.ts.map +1 -0
  233. package/dist/types/postgres/index.d.ts +24 -0
  234. package/dist/types/postgres/index.d.ts.map +1 -0
  235. package/dist/types/postgres/serializers.d.ts +30 -0
  236. package/dist/types/postgres/serializers.d.ts.map +1 -0
  237. package/dist/types/postgres/sync.d.ts +132 -0
  238. package/dist/types/postgres/sync.d.ts.map +1 -0
  239. package/dist/types/postgres/types.d.ts +167 -0
  240. package/dist/types/postgres/types.d.ts.map +1 -0
  241. package/dist/types/registries/builder.d.ts +340 -0
  242. package/dist/types/registries/builder.d.ts.map +1 -0
  243. package/dist/types/registries/discovery.d.ts +333 -0
  244. package/dist/types/registries/discovery.d.ts.map +1 -0
  245. package/dist/types/registries/index.d.ts +48 -0
  246. package/dist/types/registries/index.d.ts.map +1 -0
  247. package/dist/types/registries/session.d.ts +323 -0
  248. package/dist/types/registries/session.d.ts.map +1 -0
  249. package/dist/types/registries/x402.d.ts +463 -0
  250. package/dist/types/registries/x402.d.ts.map +1 -0
  251. package/dist/types/types/accounts.d.ts +565 -0
  252. package/dist/types/types/accounts.d.ts.map +1 -0
  253. package/dist/types/types/common.d.ts +166 -0
  254. package/dist/types/types/common.d.ts.map +1 -0
  255. package/dist/types/types/enums.d.ts +238 -0
  256. package/dist/types/types/enums.d.ts.map +1 -0
  257. package/dist/types/types/index.d.ts +28 -0
  258. package/dist/types/types/index.d.ts.map +1 -0
  259. package/dist/types/types/instructions.d.ts +366 -0
  260. package/dist/types/types/instructions.d.ts.map +1 -0
  261. package/dist/types/utils/hash.d.ts +48 -0
  262. package/dist/types/utils/hash.d.ts.map +1 -0
  263. package/dist/types/utils/index.d.ts +19 -0
  264. package/dist/types/utils/index.d.ts.map +1 -0
  265. package/dist/types/utils/serialization.d.ts +69 -0
  266. package/dist/types/utils/serialization.d.ts.map +1 -0
  267. package/dist/types/utils/validation.d.ts +29 -0
  268. package/dist/types/utils/validation.d.ts.map +1 -0
  269. package/package.json +178 -0
  270. package/src/constants/index.ts +44 -0
  271. package/src/constants/limits.ts +165 -0
  272. package/src/constants/programs.ts +83 -0
  273. package/src/constants/seeds.ts +66 -0
  274. package/src/core/client.ts +416 -0
  275. package/src/core/connection.ts +409 -0
  276. package/src/core/index.ts +20 -0
  277. package/src/errors/index.ts +346 -0
  278. package/src/events/index.ts +335 -0
  279. package/src/idl/index.ts +76 -0
  280. package/src/idl/synapse_agent_sap.json +9710 -0
  281. package/src/index.ts +253 -0
  282. package/src/modules/agent.ts +319 -0
  283. package/src/modules/attestation.ts +168 -0
  284. package/src/modules/base.ts +158 -0
  285. package/src/modules/escrow.ts +308 -0
  286. package/src/modules/feedback.ts +186 -0
  287. package/src/modules/index.ts +24 -0
  288. package/src/modules/indexing.ts +444 -0
  289. package/src/modules/ledger.ts +262 -0
  290. package/src/modules/tools.ts +411 -0
  291. package/src/modules/vault.ts +533 -0
  292. package/src/pda/index.ts +512 -0
  293. package/src/plugin/index.ts +1202 -0
  294. package/src/plugin/protocols.ts +404 -0
  295. package/src/plugin/schemas.ts +909 -0
  296. package/src/postgres/adapter.ts +904 -0
  297. package/src/postgres/index.ts +59 -0
  298. package/src/postgres/schema.sql +683 -0
  299. package/src/postgres/serializers.ts +485 -0
  300. package/src/postgres/sync.ts +254 -0
  301. package/src/postgres/types.ts +245 -0
  302. package/src/registries/builder.ts +607 -0
  303. package/src/registries/discovery.ts +572 -0
  304. package/src/registries/index.ts +77 -0
  305. package/src/registries/session.ts +613 -0
  306. package/src/registries/x402.ts +906 -0
  307. package/src/types/accounts.ts +618 -0
  308. package/src/types/common.ts +187 -0
  309. package/src/types/enums.ts +214 -0
  310. package/src/types/index.ts +92 -0
  311. package/src/types/instructions.ts +413 -0
  312. package/src/utils/hash.ts +57 -0
  313. package/src/utils/index.ts +19 -0
  314. package/src/utils/serialization.ts +98 -0
  315. 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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Solana](https://img.shields.io/badge/Solana-Anchor%200.32-purple.svg)](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)