@oobe-protocol-labs/synapse-sap-sdk 0.12.9 → 0.14.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 (640) hide show
  1. package/dist/cjs/accounts/index.js +286 -0
  2. package/dist/cjs/accounts/index.js.map +1 -0
  3. package/dist/cjs/client.js +108 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/constants.js +59 -0
  6. package/dist/cjs/constants.js.map +1 -0
  7. package/dist/cjs/errors.js +250 -0
  8. package/dist/cjs/errors.js.map +1 -0
  9. package/dist/cjs/events/index.js +38 -130
  10. package/dist/cjs/events/index.js.map +1 -1
  11. package/dist/cjs/idlTypes.js +4 -0
  12. package/dist/cjs/idlTypes.js.map +1 -0
  13. package/dist/cjs/index.js +75 -241
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/instructions/agent.js +89 -0
  16. package/dist/cjs/instructions/agent.js.map +1 -0
  17. package/dist/cjs/instructions/attestation.js +112 -0
  18. package/dist/cjs/instructions/attestation.js.map +1 -0
  19. package/dist/cjs/instructions/digest.js +28 -0
  20. package/dist/cjs/instructions/digest.js.map +1 -0
  21. package/dist/cjs/instructions/dispute.js +116 -0
  22. package/dist/cjs/instructions/dispute.js.map +1 -0
  23. package/dist/cjs/instructions/escrow.js +101 -0
  24. package/dist/cjs/instructions/escrow.js.map +1 -0
  25. package/dist/cjs/instructions/global.js +28 -0
  26. package/dist/cjs/instructions/global.js.map +1 -0
  27. package/dist/cjs/instructions/index.js +31 -0
  28. package/dist/cjs/instructions/index.js.map +1 -0
  29. package/dist/cjs/instructions/indexing.js +221 -0
  30. package/dist/cjs/instructions/indexing.js.map +1 -0
  31. package/dist/cjs/instructions/misc.js +73 -0
  32. package/dist/cjs/instructions/misc.js.map +1 -0
  33. package/dist/cjs/instructions/session.js +89 -0
  34. package/dist/cjs/instructions/session.js.map +1 -0
  35. package/dist/cjs/instructions/staking.js +132 -0
  36. package/dist/cjs/instructions/staking.js.map +1 -0
  37. package/dist/cjs/instructions/subscription.js +80 -0
  38. package/dist/cjs/instructions/subscription.js.map +1 -0
  39. package/dist/cjs/instructions/tools.js +109 -0
  40. package/dist/cjs/instructions/tools.js.map +1 -0
  41. package/dist/cjs/instructions/vault.js +106 -0
  42. package/dist/cjs/instructions/vault.js.map +1 -0
  43. package/dist/cjs/pdas/index.js +120 -0
  44. package/dist/cjs/pdas/index.js.map +1 -0
  45. package/dist/cjs/types.js +42 -0
  46. package/dist/cjs/types.js.map +1 -0
  47. package/dist/cjs/utils/index.js +29 -75
  48. package/dist/cjs/utils/index.js.map +1 -1
  49. package/dist/cjs/utils/validate.js +236 -0
  50. package/dist/cjs/utils/validate.js.map +1 -0
  51. package/dist/esm/accounts/index.d.ts +11 -0
  52. package/dist/esm/accounts/index.d.ts.map +1 -0
  53. package/dist/esm/accounts/index.js +273 -0
  54. package/dist/esm/accounts/index.js.map +1 -0
  55. package/dist/esm/client.d.ts +55 -0
  56. package/dist/esm/client.d.ts.map +1 -0
  57. package/dist/esm/client.js +70 -0
  58. package/dist/esm/client.js.map +1 -0
  59. package/dist/esm/constants.d.ts +52 -0
  60. package/dist/esm/constants.d.ts.map +1 -0
  61. package/dist/esm/constants.js +56 -0
  62. package/dist/esm/constants.js.map +1 -0
  63. package/dist/esm/errors.d.ts +111 -0
  64. package/dist/esm/errors.d.ts.map +1 -0
  65. package/dist/esm/errors.js +244 -0
  66. package/dist/esm/errors.js.map +1 -0
  67. package/dist/esm/events/index.d.ts +13 -0
  68. package/dist/esm/events/index.d.ts.map +1 -0
  69. package/dist/esm/events/index.js +36 -128
  70. package/dist/esm/events/index.js.map +1 -1
  71. package/dist/esm/idlTypes.d.ts +925 -0
  72. package/dist/esm/idlTypes.d.ts.map +1 -0
  73. package/dist/esm/idlTypes.js +3 -0
  74. package/dist/esm/idlTypes.js.map +1 -0
  75. package/dist/esm/index.d.ts +12 -0
  76. package/dist/esm/index.d.ts.map +1 -0
  77. package/dist/esm/index.js +15 -88
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/instructions/agent.d.ts +71 -0
  80. package/dist/esm/instructions/agent.d.ts.map +1 -0
  81. package/dist/esm/instructions/agent.js +85 -0
  82. package/dist/esm/instructions/agent.js.map +1 -0
  83. package/dist/esm/instructions/attestation.d.ts +76 -0
  84. package/dist/esm/instructions/attestation.d.ts.map +1 -0
  85. package/dist/esm/instructions/attestation.js +108 -0
  86. package/dist/esm/instructions/attestation.js.map +1 -0
  87. package/dist/esm/instructions/digest.d.ts +20 -0
  88. package/dist/esm/instructions/digest.d.ts.map +1 -0
  89. package/dist/esm/instructions/digest.js +24 -0
  90. package/dist/esm/instructions/digest.js.map +1 -0
  91. package/dist/esm/instructions/dispute.d.ts +81 -0
  92. package/dist/esm/instructions/dispute.d.ts.map +1 -0
  93. package/dist/esm/instructions/dispute.js +112 -0
  94. package/dist/esm/instructions/dispute.js.map +1 -0
  95. package/dist/esm/instructions/escrow.d.ts +79 -0
  96. package/dist/esm/instructions/escrow.d.ts.map +1 -0
  97. package/dist/esm/instructions/escrow.js +97 -0
  98. package/dist/esm/instructions/escrow.js.map +1 -0
  99. package/dist/esm/instructions/global.d.ts +14 -0
  100. package/dist/esm/instructions/global.d.ts.map +1 -0
  101. package/dist/esm/instructions/global.js +24 -0
  102. package/dist/esm/instructions/global.js.map +1 -0
  103. package/dist/esm/instructions/index.d.ts +14 -0
  104. package/dist/esm/instructions/index.d.ts.map +1 -0
  105. package/dist/esm/instructions/index.js +15 -0
  106. package/dist/esm/instructions/index.js.map +1 -0
  107. package/dist/esm/instructions/indexing.d.ts +150 -0
  108. package/dist/esm/instructions/indexing.d.ts.map +1 -0
  109. package/dist/esm/instructions/indexing.js +217 -0
  110. package/dist/esm/instructions/indexing.js.map +1 -0
  111. package/dist/esm/instructions/memory.d.ts +8 -0
  112. package/dist/esm/instructions/memory.d.ts.map +1 -0
  113. package/dist/esm/instructions/memory.js +234 -0
  114. package/dist/esm/instructions/memory.js.map +1 -0
  115. package/dist/esm/instructions/misc.d.ts +50 -0
  116. package/dist/esm/instructions/misc.d.ts.map +1 -0
  117. package/dist/esm/instructions/misc.js +69 -0
  118. package/dist/esm/instructions/misc.js.map +1 -0
  119. package/dist/esm/instructions/session.d.ts +57 -0
  120. package/dist/esm/instructions/session.d.ts.map +1 -0
  121. package/dist/esm/instructions/session.js +85 -0
  122. package/dist/esm/instructions/session.js.map +1 -0
  123. package/dist/esm/instructions/staking.d.ts +85 -0
  124. package/dist/esm/instructions/staking.d.ts.map +1 -0
  125. package/dist/esm/instructions/staking.js +128 -0
  126. package/dist/esm/instructions/staking.js.map +1 -0
  127. package/dist/esm/instructions/subscription.d.ts +50 -0
  128. package/dist/esm/instructions/subscription.d.ts.map +1 -0
  129. package/dist/esm/instructions/subscription.js +76 -0
  130. package/dist/esm/instructions/subscription.js.map +1 -0
  131. package/dist/esm/instructions/tools.d.ts +88 -0
  132. package/dist/esm/instructions/tools.d.ts.map +1 -0
  133. package/dist/esm/instructions/tools.js +105 -0
  134. package/dist/esm/instructions/tools.js.map +1 -0
  135. package/dist/esm/instructions/vault.d.ts +84 -0
  136. package/dist/esm/instructions/vault.d.ts.map +1 -0
  137. package/dist/esm/instructions/vault.js +102 -0
  138. package/dist/esm/instructions/vault.js.map +1 -0
  139. package/dist/esm/pdas/index.d.ts +37 -0
  140. package/dist/esm/pdas/index.d.ts.map +1 -0
  141. package/dist/esm/pdas/index.js +101 -0
  142. package/dist/esm/pdas/index.js.map +1 -0
  143. package/dist/esm/types.d.ts +208 -0
  144. package/dist/esm/types.d.ts.map +1 -0
  145. package/dist/esm/types.js +39 -0
  146. package/dist/esm/types.js.map +1 -0
  147. package/dist/esm/utils/index.d.ts +4 -0
  148. package/dist/esm/utils/index.d.ts.map +1 -0
  149. package/dist/esm/utils/index.js +13 -29
  150. package/dist/esm/utils/index.js.map +1 -1
  151. package/dist/esm/utils/validate.d.ts +66 -0
  152. package/dist/esm/utils/validate.d.ts.map +1 -0
  153. package/dist/esm/utils/validate.js +221 -0
  154. package/dist/esm/utils/validate.js.map +1 -0
  155. package/package.json +59 -183
  156. package/LICENSE +0 -21
  157. package/README.md +0 -986
  158. package/dist/cjs/constants/addresses.js +0 -143
  159. package/dist/cjs/constants/addresses.js.map +0 -1
  160. package/dist/cjs/constants/index.js +0 -64
  161. package/dist/cjs/constants/index.js.map +0 -1
  162. package/dist/cjs/constants/limits.js +0 -161
  163. package/dist/cjs/constants/limits.js.map +0 -1
  164. package/dist/cjs/constants/network.js +0 -81
  165. package/dist/cjs/constants/network.js.map +0 -1
  166. package/dist/cjs/constants/payments.js +0 -137
  167. package/dist/cjs/constants/payments.js.map +0 -1
  168. package/dist/cjs/constants/programs.js +0 -78
  169. package/dist/cjs/constants/programs.js.map +0 -1
  170. package/dist/cjs/constants/seeds.js +0 -76
  171. package/dist/cjs/constants/seeds.js.map +0 -1
  172. package/dist/cjs/core/client.js +0 -546
  173. package/dist/cjs/core/client.js.map +0 -1
  174. package/dist/cjs/core/connection.js +0 -350
  175. package/dist/cjs/core/connection.js.map +0 -1
  176. package/dist/cjs/core/index.js +0 -25
  177. package/dist/cjs/core/index.js.map +0 -1
  178. package/dist/cjs/errors/index.js +0 -334
  179. package/dist/cjs/errors/index.js.map +0 -1
  180. package/dist/cjs/events/geyser.js +0 -295
  181. package/dist/cjs/events/geyser.js.map +0 -1
  182. package/dist/cjs/idl/index.js +0 -63
  183. package/dist/cjs/idl/index.js.map +0 -1
  184. package/dist/cjs/idl/synapse_agent_sap.json +0 -14595
  185. package/dist/cjs/modules/agent.js +0 -272
  186. package/dist/cjs/modules/agent.js.map +0 -1
  187. package/dist/cjs/modules/attestation.js +0 -147
  188. package/dist/cjs/modules/attestation.js.map +0 -1
  189. package/dist/cjs/modules/base.js +0 -128
  190. package/dist/cjs/modules/base.js.map +0 -1
  191. package/dist/cjs/modules/escrow-v2.js +0 -454
  192. package/dist/cjs/modules/escrow-v2.js.map +0 -1
  193. package/dist/cjs/modules/escrow.js +0 -300
  194. package/dist/cjs/modules/escrow.js.map +0 -1
  195. package/dist/cjs/modules/feedback.js +0 -166
  196. package/dist/cjs/modules/feedback.js.map +0 -1
  197. package/dist/cjs/modules/index.js +0 -43
  198. package/dist/cjs/modules/index.js.map +0 -1
  199. package/dist/cjs/modules/indexing.js +0 -375
  200. package/dist/cjs/modules/indexing.js.map +0 -1
  201. package/dist/cjs/modules/ledger.js +0 -234
  202. package/dist/cjs/modules/ledger.js.map +0 -1
  203. package/dist/cjs/modules/receipt.js +0 -148
  204. package/dist/cjs/modules/receipt.js.map +0 -1
  205. package/dist/cjs/modules/staking.js +0 -124
  206. package/dist/cjs/modules/staking.js.map +0 -1
  207. package/dist/cjs/modules/subscription.js +0 -96
  208. package/dist/cjs/modules/subscription.js.map +0 -1
  209. package/dist/cjs/modules/tools.js +0 -319
  210. package/dist/cjs/modules/tools.js.map +0 -1
  211. package/dist/cjs/modules/vault.js +0 -410
  212. package/dist/cjs/modules/vault.js.map +0 -1
  213. package/dist/cjs/parser/client.js +0 -146
  214. package/dist/cjs/parser/client.js.map +0 -1
  215. package/dist/cjs/parser/complete.js +0 -177
  216. package/dist/cjs/parser/complete.js.map +0 -1
  217. package/dist/cjs/parser/index.js +0 -57
  218. package/dist/cjs/parser/index.js.map +0 -1
  219. package/dist/cjs/parser/inner.js +0 -185
  220. package/dist/cjs/parser/inner.js.map +0 -1
  221. package/dist/cjs/parser/instructions.js +0 -114
  222. package/dist/cjs/parser/instructions.js.map +0 -1
  223. package/dist/cjs/parser/transaction.js +0 -153
  224. package/dist/cjs/parser/transaction.js.map +0 -1
  225. package/dist/cjs/parser/types.js +0 -14
  226. package/dist/cjs/parser/types.js.map +0 -1
  227. package/dist/cjs/pda/index.js +0 -672
  228. package/dist/cjs/pda/index.js.map +0 -1
  229. package/dist/cjs/plugin/index.js +0 -952
  230. package/dist/cjs/plugin/index.js.map +0 -1
  231. package/dist/cjs/plugin/protocols.js +0 -282
  232. package/dist/cjs/plugin/protocols.js.map +0 -1
  233. package/dist/cjs/plugin/schemas.js +0 -863
  234. package/dist/cjs/plugin/schemas.js.map +0 -1
  235. package/dist/cjs/postgres/adapter.js +0 -715
  236. package/dist/cjs/postgres/adapter.js.map +0 -1
  237. package/dist/cjs/postgres/index.js +0 -50
  238. package/dist/cjs/postgres/index.js.map +0 -1
  239. package/dist/cjs/postgres/serializers.js +0 -381
  240. package/dist/cjs/postgres/serializers.js.map +0 -1
  241. package/dist/cjs/postgres/sync.js +0 -289
  242. package/dist/cjs/postgres/sync.js.map +0 -1
  243. package/dist/cjs/postgres/types.js +0 -44
  244. package/dist/cjs/postgres/types.js.map +0 -1
  245. package/dist/cjs/registries/builder.js +0 -414
  246. package/dist/cjs/registries/builder.js.map +0 -1
  247. package/dist/cjs/registries/discovery.js +0 -362
  248. package/dist/cjs/registries/discovery.js.map +0 -1
  249. package/dist/cjs/registries/fairscale.js +0 -639
  250. package/dist/cjs/registries/fairscale.js.map +0 -1
  251. package/dist/cjs/registries/index.js +0 -58
  252. package/dist/cjs/registries/index.js.map +0 -1
  253. package/dist/cjs/registries/metaplex-bridge.js +0 -743
  254. package/dist/cjs/registries/metaplex-bridge.js.map +0 -1
  255. package/dist/cjs/registries/session.js +0 -433
  256. package/dist/cjs/registries/session.js.map +0 -1
  257. package/dist/cjs/registries/x402.js +0 -668
  258. package/dist/cjs/registries/x402.js.map +0 -1
  259. package/dist/cjs/types/accounts.js +0 -13
  260. package/dist/cjs/types/accounts.js.map +0 -1
  261. package/dist/cjs/types/common.js +0 -13
  262. package/dist/cjs/types/common.js.map +0 -1
  263. package/dist/cjs/types/endpoint.js +0 -15
  264. package/dist/cjs/types/endpoint.js.map +0 -1
  265. package/dist/cjs/types/enums.js +0 -269
  266. package/dist/cjs/types/enums.js.map +0 -1
  267. package/dist/cjs/types/index.js +0 -41
  268. package/dist/cjs/types/index.js.map +0 -1
  269. package/dist/cjs/types/instructions.js +0 -92
  270. package/dist/cjs/types/instructions.js.map +0 -1
  271. package/dist/cjs/utils/endpoint-validator.js +0 -232
  272. package/dist/cjs/utils/endpoint-validator.js.map +0 -1
  273. package/dist/cjs/utils/escrow-validation.js +0 -219
  274. package/dist/cjs/utils/escrow-validation.js.map +0 -1
  275. package/dist/cjs/utils/hash.js +0 -109
  276. package/dist/cjs/utils/hash.js.map +0 -1
  277. package/dist/cjs/utils/merchant-validator.js +0 -246
  278. package/dist/cjs/utils/merchant-validator.js.map +0 -1
  279. package/dist/cjs/utils/network-normalizer.js +0 -236
  280. package/dist/cjs/utils/network-normalizer.js.map +0 -1
  281. package/dist/cjs/utils/priority-fee.js +0 -215
  282. package/dist/cjs/utils/priority-fee.js.map +0 -1
  283. package/dist/cjs/utils/rpc-strategy.js +0 -239
  284. package/dist/cjs/utils/rpc-strategy.js.map +0 -1
  285. package/dist/cjs/utils/schemas.js +0 -331
  286. package/dist/cjs/utils/schemas.js.map +0 -1
  287. package/dist/cjs/utils/serialization.js +0 -105
  288. package/dist/cjs/utils/serialization.js.map +0 -1
  289. package/dist/cjs/utils/validation.js +0 -36
  290. package/dist/cjs/utils/validation.js.map +0 -1
  291. package/dist/cjs/utils/x402-direct.js +0 -231
  292. package/dist/cjs/utils/x402-direct.js.map +0 -1
  293. package/dist/esm/constants/addresses.js +0 -140
  294. package/dist/esm/constants/addresses.js.map +0 -1
  295. package/dist/esm/constants/index.js +0 -35
  296. package/dist/esm/constants/index.js.map +0 -1
  297. package/dist/esm/constants/limits.js +0 -158
  298. package/dist/esm/constants/limits.js.map +0 -1
  299. package/dist/esm/constants/network.js +0 -78
  300. package/dist/esm/constants/network.js.map +0 -1
  301. package/dist/esm/constants/payments.js +0 -131
  302. package/dist/esm/constants/payments.js.map +0 -1
  303. package/dist/esm/constants/programs.js +0 -75
  304. package/dist/esm/constants/programs.js.map +0 -1
  305. package/dist/esm/constants/seeds.js +0 -73
  306. package/dist/esm/constants/seeds.js.map +0 -1
  307. package/dist/esm/core/client.js +0 -539
  308. package/dist/esm/core/client.js.map +0 -1
  309. package/dist/esm/core/connection.js +0 -345
  310. package/dist/esm/core/connection.js.map +0 -1
  311. package/dist/esm/core/index.js +0 -19
  312. package/dist/esm/core/index.js.map +0 -1
  313. package/dist/esm/errors/index.js +0 -325
  314. package/dist/esm/errors/index.js.map +0 -1
  315. package/dist/esm/events/geyser.js +0 -258
  316. package/dist/esm/events/geyser.js.map +0 -1
  317. package/dist/esm/idl/index.js +0 -57
  318. package/dist/esm/idl/index.js.map +0 -1
  319. package/dist/esm/idl/synapse_agent_sap.json +0 -14595
  320. package/dist/esm/modules/agent.js +0 -268
  321. package/dist/esm/modules/agent.js.map +0 -1
  322. package/dist/esm/modules/attestation.js +0 -143
  323. package/dist/esm/modules/attestation.js.map +0 -1
  324. package/dist/esm/modules/base.js +0 -124
  325. package/dist/esm/modules/base.js.map +0 -1
  326. package/dist/esm/modules/escrow-v2.js +0 -450
  327. package/dist/esm/modules/escrow-v2.js.map +0 -1
  328. package/dist/esm/modules/escrow.js +0 -296
  329. package/dist/esm/modules/escrow.js.map +0 -1
  330. package/dist/esm/modules/feedback.js +0 -162
  331. package/dist/esm/modules/feedback.js.map +0 -1
  332. package/dist/esm/modules/index.js +0 -27
  333. package/dist/esm/modules/index.js.map +0 -1
  334. package/dist/esm/modules/indexing.js +0 -371
  335. package/dist/esm/modules/indexing.js.map +0 -1
  336. package/dist/esm/modules/ledger.js +0 -230
  337. package/dist/esm/modules/ledger.js.map +0 -1
  338. package/dist/esm/modules/receipt.js +0 -144
  339. package/dist/esm/modules/receipt.js.map +0 -1
  340. package/dist/esm/modules/staking.js +0 -120
  341. package/dist/esm/modules/staking.js.map +0 -1
  342. package/dist/esm/modules/subscription.js +0 -92
  343. package/dist/esm/modules/subscription.js.map +0 -1
  344. package/dist/esm/modules/tools.js +0 -315
  345. package/dist/esm/modules/tools.js.map +0 -1
  346. package/dist/esm/modules/vault.js +0 -406
  347. package/dist/esm/modules/vault.js.map +0 -1
  348. package/dist/esm/parser/client.js +0 -142
  349. package/dist/esm/parser/client.js.map +0 -1
  350. package/dist/esm/parser/complete.js +0 -173
  351. package/dist/esm/parser/complete.js.map +0 -1
  352. package/dist/esm/parser/index.js +0 -43
  353. package/dist/esm/parser/index.js.map +0 -1
  354. package/dist/esm/parser/inner.js +0 -180
  355. package/dist/esm/parser/inner.js.map +0 -1
  356. package/dist/esm/parser/instructions.js +0 -109
  357. package/dist/esm/parser/instructions.js.map +0 -1
  358. package/dist/esm/parser/transaction.js +0 -149
  359. package/dist/esm/parser/transaction.js.map +0 -1
  360. package/dist/esm/parser/types.js +0 -13
  361. package/dist/esm/parser/types.js.map +0 -1
  362. package/dist/esm/pda/index.js +0 -638
  363. package/dist/esm/pda/index.js.map +0 -1
  364. package/dist/esm/plugin/index.js +0 -945
  365. package/dist/esm/plugin/index.js.map +0 -1
  366. package/dist/esm/plugin/protocols.js +0 -279
  367. package/dist/esm/plugin/protocols.js.map +0 -1
  368. package/dist/esm/plugin/schemas.js +0 -860
  369. package/dist/esm/plugin/schemas.js.map +0 -1
  370. package/dist/esm/postgres/adapter.js +0 -678
  371. package/dist/esm/postgres/adapter.js.map +0 -1
  372. package/dist/esm/postgres/index.js +0 -27
  373. package/dist/esm/postgres/index.js.map +0 -1
  374. package/dist/esm/postgres/serializers.js +0 -362
  375. package/dist/esm/postgres/serializers.js.map +0 -1
  376. package/dist/esm/postgres/sync.js +0 -285
  377. package/dist/esm/postgres/sync.js.map +0 -1
  378. package/dist/esm/postgres/types.js +0 -41
  379. package/dist/esm/postgres/types.js.map +0 -1
  380. package/dist/esm/registries/builder.js +0 -410
  381. package/dist/esm/registries/builder.js.map +0 -1
  382. package/dist/esm/registries/discovery.js +0 -358
  383. package/dist/esm/registries/discovery.js.map +0 -1
  384. package/dist/esm/registries/fairscale.js +0 -633
  385. package/dist/esm/registries/fairscale.js.map +0 -1
  386. package/dist/esm/registries/index.js +0 -46
  387. package/dist/esm/registries/index.js.map +0 -1
  388. package/dist/esm/registries/metaplex-bridge.js +0 -706
  389. package/dist/esm/registries/metaplex-bridge.js.map +0 -1
  390. package/dist/esm/registries/session.js +0 -429
  391. package/dist/esm/registries/session.js.map +0 -1
  392. package/dist/esm/registries/x402.js +0 -664
  393. package/dist/esm/registries/x402.js.map +0 -1
  394. package/dist/esm/types/accounts.js +0 -12
  395. package/dist/esm/types/accounts.js.map +0 -1
  396. package/dist/esm/types/common.js +0 -12
  397. package/dist/esm/types/common.js.map +0 -1
  398. package/dist/esm/types/endpoint.js +0 -14
  399. package/dist/esm/types/endpoint.js.map +0 -1
  400. package/dist/esm/types/enums.js +0 -266
  401. package/dist/esm/types/enums.js.map +0 -1
  402. package/dist/esm/types/index.js +0 -25
  403. package/dist/esm/types/index.js.map +0 -1
  404. package/dist/esm/types/instructions.js +0 -89
  405. package/dist/esm/types/instructions.js.map +0 -1
  406. package/dist/esm/utils/endpoint-validator.js +0 -226
  407. package/dist/esm/utils/endpoint-validator.js.map +0 -1
  408. package/dist/esm/utils/escrow-validation.js +0 -212
  409. package/dist/esm/utils/escrow-validation.js.map +0 -1
  410. package/dist/esm/utils/hash.js +0 -103
  411. package/dist/esm/utils/hash.js.map +0 -1
  412. package/dist/esm/utils/merchant-validator.js +0 -241
  413. package/dist/esm/utils/merchant-validator.js.map +0 -1
  414. package/dist/esm/utils/network-normalizer.js +0 -229
  415. package/dist/esm/utils/network-normalizer.js.map +0 -1
  416. package/dist/esm/utils/priority-fee.js +0 -209
  417. package/dist/esm/utils/priority-fee.js.map +0 -1
  418. package/dist/esm/utils/rpc-strategy.js +0 -231
  419. package/dist/esm/utils/rpc-strategy.js.map +0 -1
  420. package/dist/esm/utils/schemas.js +0 -320
  421. package/dist/esm/utils/schemas.js.map +0 -1
  422. package/dist/esm/utils/serialization.js +0 -98
  423. package/dist/esm/utils/serialization.js.map +0 -1
  424. package/dist/esm/utils/validation.js +0 -33
  425. package/dist/esm/utils/validation.js.map +0 -1
  426. package/dist/esm/utils/x402-direct.js +0 -228
  427. package/dist/esm/utils/x402-direct.js.map +0 -1
  428. package/dist/types/constants/addresses.d.ts +0 -117
  429. package/dist/types/constants/addresses.d.ts.map +0 -1
  430. package/dist/types/constants/index.d.ts +0 -31
  431. package/dist/types/constants/index.d.ts.map +0 -1
  432. package/dist/types/constants/limits.d.ts +0 -149
  433. package/dist/types/constants/limits.d.ts.map +0 -1
  434. package/dist/types/constants/network.d.ts +0 -81
  435. package/dist/types/constants/network.d.ts.map +0 -1
  436. package/dist/types/constants/payments.d.ts +0 -121
  437. package/dist/types/constants/payments.d.ts.map +0 -1
  438. package/dist/types/constants/programs.d.ts +0 -69
  439. package/dist/types/constants/programs.d.ts.map +0 -1
  440. package/dist/types/constants/seeds.d.ts +0 -80
  441. package/dist/types/constants/seeds.d.ts.map +0 -1
  442. package/dist/types/core/client.d.ts +0 -452
  443. package/dist/types/core/client.d.ts.map +0 -1
  444. package/dist/types/core/connection.d.ts +0 -305
  445. package/dist/types/core/connection.d.ts.map +0 -1
  446. package/dist/types/core/index.d.ts +0 -20
  447. package/dist/types/core/index.d.ts.map +0 -1
  448. package/dist/types/errors/index.d.ts +0 -276
  449. package/dist/types/errors/index.d.ts.map +0 -1
  450. package/dist/types/events/geyser.d.ts +0 -150
  451. package/dist/types/events/geyser.d.ts.map +0 -1
  452. package/dist/types/events/index.d.ts +0 -248
  453. package/dist/types/events/index.d.ts.map +0 -1
  454. package/dist/types/idl/index.d.ts +0 -70
  455. package/dist/types/idl/index.d.ts.map +0 -1
  456. package/dist/types/index.d.ts +0 -85
  457. package/dist/types/index.d.ts.map +0 -1
  458. package/dist/types/modules/agent.d.ts +0 -166
  459. package/dist/types/modules/agent.d.ts.map +0 -1
  460. package/dist/types/modules/attestation.d.ts +0 -96
  461. package/dist/types/modules/attestation.d.ts.map +0 -1
  462. package/dist/types/modules/base.d.ts +0 -126
  463. package/dist/types/modules/base.d.ts.map +0 -1
  464. package/dist/types/modules/escrow-v2.d.ts +0 -100
  465. package/dist/types/modules/escrow-v2.d.ts.map +0 -1
  466. package/dist/types/modules/escrow.d.ts +0 -168
  467. package/dist/types/modules/escrow.d.ts.map +0 -1
  468. package/dist/types/modules/feedback.d.ts +0 -105
  469. package/dist/types/modules/feedback.d.ts.map +0 -1
  470. package/dist/types/modules/index.d.ts +0 -28
  471. package/dist/types/modules/index.d.ts.map +0 -1
  472. package/dist/types/modules/indexing.d.ts +0 -200
  473. package/dist/types/modules/indexing.d.ts.map +0 -1
  474. package/dist/types/modules/ledger.d.ts +0 -150
  475. package/dist/types/modules/ledger.d.ts.map +0 -1
  476. package/dist/types/modules/receipt.d.ts +0 -77
  477. package/dist/types/modules/receipt.d.ts.map +0 -1
  478. package/dist/types/modules/staking.d.ts +0 -51
  479. package/dist/types/modules/staking.d.ts.map +0 -1
  480. package/dist/types/modules/subscription.d.ts +0 -33
  481. package/dist/types/modules/subscription.d.ts.map +0 -1
  482. package/dist/types/modules/tools.d.ts +0 -182
  483. package/dist/types/modules/tools.d.ts.map +0 -1
  484. package/dist/types/modules/vault.d.ts +0 -240
  485. package/dist/types/modules/vault.d.ts.map +0 -1
  486. package/dist/types/parser/client.d.ts +0 -123
  487. package/dist/types/parser/client.d.ts.map +0 -1
  488. package/dist/types/parser/complete.d.ts +0 -90
  489. package/dist/types/parser/complete.d.ts.map +0 -1
  490. package/dist/types/parser/index.d.ts +0 -40
  491. package/dist/types/parser/index.d.ts.map +0 -1
  492. package/dist/types/parser/inner.d.ts +0 -114
  493. package/dist/types/parser/inner.d.ts.map +0 -1
  494. package/dist/types/parser/instructions.d.ts +0 -76
  495. package/dist/types/parser/instructions.d.ts.map +0 -1
  496. package/dist/types/parser/transaction.d.ts +0 -77
  497. package/dist/types/parser/transaction.d.ts.map +0 -1
  498. package/dist/types/parser/types.d.ts +0 -154
  499. package/dist/types/parser/types.d.ts.map +0 -1
  500. package/dist/types/pda/index.d.ts +0 -510
  501. package/dist/types/pda/index.d.ts.map +0 -1
  502. package/dist/types/plugin/index.d.ts +0 -171
  503. package/dist/types/plugin/index.d.ts.map +0 -1
  504. package/dist/types/plugin/protocols.d.ts +0 -152
  505. package/dist/types/plugin/protocols.d.ts.map +0 -1
  506. package/dist/types/plugin/schemas.d.ts +0 -829
  507. package/dist/types/plugin/schemas.d.ts.map +0 -1
  508. package/dist/types/postgres/adapter.d.ts +0 -355
  509. package/dist/types/postgres/adapter.d.ts.map +0 -1
  510. package/dist/types/postgres/index.d.ts +0 -24
  511. package/dist/types/postgres/index.d.ts.map +0 -1
  512. package/dist/types/postgres/serializers.d.ts +0 -30
  513. package/dist/types/postgres/serializers.d.ts.map +0 -1
  514. package/dist/types/postgres/sync.d.ts +0 -156
  515. package/dist/types/postgres/sync.d.ts.map +0 -1
  516. package/dist/types/postgres/types.d.ts +0 -167
  517. package/dist/types/postgres/types.d.ts.map +0 -1
  518. package/dist/types/registries/builder.d.ts +0 -340
  519. package/dist/types/registries/builder.d.ts.map +0 -1
  520. package/dist/types/registries/discovery.d.ts +0 -333
  521. package/dist/types/registries/discovery.d.ts.map +0 -1
  522. package/dist/types/registries/fairscale.d.ts +0 -680
  523. package/dist/types/registries/fairscale.d.ts.map +0 -1
  524. package/dist/types/registries/index.d.ts +0 -52
  525. package/dist/types/registries/index.d.ts.map +0 -1
  526. package/dist/types/registries/metaplex-bridge.d.ts +0 -488
  527. package/dist/types/registries/metaplex-bridge.d.ts.map +0 -1
  528. package/dist/types/registries/session.d.ts +0 -323
  529. package/dist/types/registries/session.d.ts.map +0 -1
  530. package/dist/types/registries/x402.d.ts +0 -530
  531. package/dist/types/registries/x402.d.ts.map +0 -1
  532. package/dist/types/types/accounts.d.ts +0 -765
  533. package/dist/types/types/accounts.d.ts.map +0 -1
  534. package/dist/types/types/common.d.ts +0 -166
  535. package/dist/types/types/common.d.ts.map +0 -1
  536. package/dist/types/types/endpoint.d.ts +0 -161
  537. package/dist/types/types/endpoint.d.ts.map +0 -1
  538. package/dist/types/types/enums.d.ts +0 -353
  539. package/dist/types/types/enums.d.ts.map +0 -1
  540. package/dist/types/types/index.d.ts +0 -29
  541. package/dist/types/types/index.d.ts.map +0 -1
  542. package/dist/types/types/instructions.d.ts +0 -400
  543. package/dist/types/types/instructions.d.ts.map +0 -1
  544. package/dist/types/utils/endpoint-validator.d.ts +0 -110
  545. package/dist/types/utils/endpoint-validator.d.ts.map +0 -1
  546. package/dist/types/utils/escrow-validation.d.ts +0 -145
  547. package/dist/types/utils/escrow-validation.d.ts.map +0 -1
  548. package/dist/types/utils/hash.d.ts +0 -75
  549. package/dist/types/utils/hash.d.ts.map +0 -1
  550. package/dist/types/utils/index.d.ts +0 -33
  551. package/dist/types/utils/index.d.ts.map +0 -1
  552. package/dist/types/utils/merchant-validator.d.ts +0 -176
  553. package/dist/types/utils/merchant-validator.d.ts.map +0 -1
  554. package/dist/types/utils/network-normalizer.d.ts +0 -120
  555. package/dist/types/utils/network-normalizer.d.ts.map +0 -1
  556. package/dist/types/utils/priority-fee.d.ts +0 -205
  557. package/dist/types/utils/priority-fee.d.ts.map +0 -1
  558. package/dist/types/utils/rpc-strategy.d.ts +0 -172
  559. package/dist/types/utils/rpc-strategy.d.ts.map +0 -1
  560. package/dist/types/utils/schemas.d.ts +0 -351
  561. package/dist/types/utils/schemas.d.ts.map +0 -1
  562. package/dist/types/utils/serialization.d.ts +0 -69
  563. package/dist/types/utils/serialization.d.ts.map +0 -1
  564. package/dist/types/utils/validation.d.ts +0 -29
  565. package/dist/types/utils/validation.d.ts.map +0 -1
  566. package/dist/types/utils/x402-direct.d.ts +0 -114
  567. package/dist/types/utils/x402-direct.d.ts.map +0 -1
  568. package/src/constants/addresses.ts +0 -162
  569. package/src/constants/index.ts +0 -69
  570. package/src/constants/limits.ts +0 -165
  571. package/src/constants/network.ts +0 -89
  572. package/src/constants/payments.ts +0 -145
  573. package/src/constants/programs.ts +0 -83
  574. package/src/constants/seeds.ts +0 -85
  575. package/src/core/client.ts +0 -583
  576. package/src/core/connection.ts +0 -461
  577. package/src/core/index.ts +0 -20
  578. package/src/errors/index.ts +0 -346
  579. package/src/events/geyser.ts +0 -384
  580. package/src/events/index.ts +0 -335
  581. package/src/events/yellowstone.d.ts +0 -7
  582. package/src/idl/index.ts +0 -76
  583. package/src/idl/synapse_agent_sap.json +0 -14595
  584. package/src/index.ts +0 -421
  585. package/src/modules/agent.ts +0 -319
  586. package/src/modules/attestation.ts +0 -168
  587. package/src/modules/base.ts +0 -158
  588. package/src/modules/escrow-v2.ts +0 -658
  589. package/src/modules/escrow.ts +0 -383
  590. package/src/modules/feedback.ts +0 -186
  591. package/src/modules/index.ts +0 -28
  592. package/src/modules/indexing.ts +0 -444
  593. package/src/modules/ledger.ts +0 -262
  594. package/src/modules/receipt.ts +0 -212
  595. package/src/modules/staking.ts +0 -157
  596. package/src/modules/subscription.ts +0 -147
  597. package/src/modules/tools.ts +0 -411
  598. package/src/modules/vault.ts +0 -533
  599. package/src/parser/client.ts +0 -211
  600. package/src/parser/complete.ts +0 -232
  601. package/src/parser/index.ts +0 -71
  602. package/src/parser/inner.ts +0 -255
  603. package/src/parser/instructions.ts +0 -135
  604. package/src/parser/transaction.ts +0 -200
  605. package/src/parser/types.ts +0 -182
  606. package/src/pda/index.ts +0 -919
  607. package/src/plugin/index.ts +0 -1224
  608. package/src/plugin/protocols.ts +0 -404
  609. package/src/plugin/schemas.ts +0 -941
  610. package/src/postgres/adapter.ts +0 -904
  611. package/src/postgres/index.ts +0 -59
  612. package/src/postgres/schema.sql +0 -683
  613. package/src/postgres/serializers.ts +0 -485
  614. package/src/postgres/sync.ts +0 -340
  615. package/src/postgres/types.ts +0 -245
  616. package/src/registries/builder.ts +0 -607
  617. package/src/registries/discovery.ts +0 -572
  618. package/src/registries/fairscale.ts +0 -1278
  619. package/src/registries/index.ts +0 -143
  620. package/src/registries/metaplex-bridge.ts +0 -1199
  621. package/src/registries/session.ts +0 -613
  622. package/src/registries/x402.ts +0 -1048
  623. package/src/types/accounts.ts +0 -858
  624. package/src/types/common.ts +0 -187
  625. package/src/types/endpoint.ts +0 -181
  626. package/src/types/enums.ts +0 -333
  627. package/src/types/index.ts +0 -121
  628. package/src/types/instructions.ts +0 -453
  629. package/src/utils/endpoint-validator.ts +0 -300
  630. package/src/utils/escrow-validation.ts +0 -301
  631. package/src/utils/hash.ts +0 -113
  632. package/src/utils/index.ts +0 -102
  633. package/src/utils/merchant-validator.ts +0 -359
  634. package/src/utils/network-normalizer.ts +0 -240
  635. package/src/utils/priority-fee.ts +0 -325
  636. package/src/utils/rpc-strategy.ts +0 -322
  637. package/src/utils/schemas.ts +0 -359
  638. package/src/utils/serialization.ts +0 -98
  639. package/src/utils/validation.ts +0 -36
  640. package/src/utils/x402-direct.ts +0 -370
@@ -1,1224 +0,0 @@
1
- /**
2
- * @module plugin
3
- * @description SynapsePlugin adapter for SAP v2.
4
- *
5
- * Exposes 52 tools across 8 on-chain protocol domains as a drop-in
6
- * `SynapsePlugin` for `SynapseAgentKit`:
7
- *
8
- * ```ts
9
- * import { SynapseAgentKit } from '@oobe-protocol-labs/synapse-client-sdk/ai/plugins';
10
- * import { createSAPPlugin } from '@synapse-sap/sdk/plugin';
11
- *
12
- * const sapPlugin = createSAPPlugin({ provider });
13
- * const kit = new SynapseAgentKit({ rpcUrl })
14
- * .use(sapPlugin);
15
- *
16
- * const tools = kit.getTools(); // → StructuredTool[] (LangChain)
17
- * ```
18
- *
19
- * Architecture:
20
- * 1. Schemas (Zod) → runtime validation + LLM-friendly descriptions
21
- * 2. Protocols → 8 domain method registries (agent, feedback, …)
22
- * 3. Executor → dispatches tool calls to SapClient module methods
23
- * 4. Serialization → PublicKey↔string, BN↔string bridging
24
- *
25
- * @category Plugin
26
- * @since v0.1.0
27
- */
28
-
29
- import { type AnchorProvider } from "@coral-xyz/anchor";
30
- import { PublicKey } from "@solana/web3.js";
31
- import BN from "bn.js";
32
- import { SapClient } from "../core/client";
33
- import {
34
- SAP_PROTOCOLS,
35
- type PluginProtocol,
36
- type ProtocolMethod,
37
- } from "./protocols";
38
- import type {
39
- RegisterAgentArgs,
40
- UpdateAgentArgs,
41
- GiveFeedbackArgs,
42
- UpdateFeedbackArgs,
43
- CreateAttestationArgs,
44
- CreateEscrowArgs,
45
- Settlement,
46
- InscribeMemoryArgs,
47
- InscribeToolSchemaArgs,
48
- UpdateToolArgs,
49
- VolumeCurveBreakpoint,
50
- } from "../types";
51
- import { deriveAgent, deriveVault, deriveSession, deriveLedger } from "../pda";
52
- import { hashToArray, sha256 } from "../utils";
53
-
54
- // ═══════════════════════════════════════════════════════════════════
55
- // Public Types
56
- // ═══════════════════════════════════════════════════════════════════
57
-
58
- /**
59
- * Plugin metadata exposed via {@link SynapsePlugin.meta}.
60
- *
61
- * @interface PluginMeta
62
- * @name PluginMeta
63
- * @description Describes a SynapsePlugin’s identity, version, and
64
- * discovery tags for the SynapseAgentKit plugin registry.
65
- * @category Plugin
66
- * @since v0.1.0
67
- */
68
- export interface PluginMeta {
69
- readonly id: string;
70
- readonly name: string;
71
- readonly version: string;
72
- readonly description: string;
73
- readonly tags: readonly string[];
74
- }
75
-
76
- /**
77
- * Context injected by SynapseAgentKit during `install()`.
78
- *
79
- * @interface PluginContext
80
- * @name PluginContext
81
- * @description Provides the RPC transport and original AgentKit configuration
82
- * to the plugin at installation time.
83
- * @category Plugin
84
- * @since v0.1.0
85
- */
86
- export interface PluginContext {
87
- /** The SynapseClient providing RPC transport. */
88
- readonly client: {
89
- readonly transport: unknown;
90
- };
91
- /** Original AgentKitConfig. */
92
- readonly config: Record<string, unknown>;
93
- }
94
-
95
- /**
96
- * Result of `install()` containing the tool executor and optional teardown.
97
- *
98
- * @interface PluginInstallResult
99
- * @name PluginInstallResult
100
- * @description Returned by {@link SynapsePlugin.install}. The `executor`
101
- * dispatches incoming tool calls to the correct SapClient module method.
102
- * The optional `teardown` callback is invoked on `kit.destroy()`.
103
- * @category Plugin
104
- * @since v0.1.0
105
- */
106
- export interface PluginInstallResult {
107
- /** Main executor dispatching method calls. */
108
- executor: (method: ProtocolMethod, input: unknown) => Promise<unknown>;
109
- /** Optional teardown for cleanup on `kit.destroy()`. */
110
- teardown?: () => Promise<void>;
111
- }
112
-
113
- /**
114
- * The SynapsePlugin interface (duck-typed for zero external deps).
115
- *
116
- * @interface SynapsePlugin
117
- * @name SynapsePlugin
118
- * @description Core contract for SynapseAgentKit plugins. Provides metadata,
119
- * protocol definitions, and an `install()` entry point that yields
120
- * a tool executor.
121
- * @category Plugin
122
- * @since v0.1.0
123
- */
124
- export interface SynapsePlugin {
125
- readonly meta: PluginMeta;
126
- readonly protocols: readonly PluginProtocol[];
127
- install(context: PluginContext): PluginInstallResult;
128
- }
129
-
130
- /**
131
- * Configuration for the SAP plugin.
132
- *
133
- * @interface SAPPluginConfig
134
- * @name SAPPluginConfig
135
- * @description Options passed to {@link createSAPPlugin} to instantiate
136
- * the SAP v2 plugin with an Anchor provider and optional program ID override.
137
- * @category Plugin
138
- * @since v0.1.0
139
- */
140
- export interface SAPPluginConfig {
141
- /**
142
- * Anchor provider with wallet signer.
143
- * Required for all write operations (transactions).
144
- */
145
- readonly provider: AnchorProvider;
146
-
147
- /**
148
- * Override the SAP program ID.
149
- * Defaults to the canonical program ID from constants.
150
- */
151
- readonly programId?: PublicKey;
152
- }
153
-
154
- // ═══════════════════════════════════════════════════════════════════
155
- // Version
156
- // ═══════════════════════════════════════════════════════════════════
157
-
158
- /**
159
- * Current SAP plugin version string.
160
- *
161
- * @name SAP_PLUGIN_VERSION
162
- * @description Semver version embedded in the plugin’s {@link PluginMeta}.
163
- * @internal
164
- * @since v0.1.0
165
- */
166
- const SAP_PLUGIN_VERSION = "0.1.0";
167
-
168
- // ═══════════════════════════════════════════════════════════════════
169
- // Serialization Helpers
170
- // ═══════════════════════════════════════════════════════════════════
171
-
172
- /**
173
- * Convert a base58 string to PublicKey.
174
- *
175
- * @name toPubkey
176
- * @description Returns `undefined` for nullish input, otherwise wraps
177
- * the base58 string in a Solana `PublicKey`.
178
- * @param value - Base58-encoded public key or nullish
179
- * @returns A `PublicKey` instance, or `undefined`
180
- * @internal
181
- * @since v0.1.0
182
- */
183
- function toPubkey(value: string | null | undefined): PublicKey | undefined {
184
- return value ? new PublicKey(value) : undefined;
185
- }
186
-
187
- /**
188
- * Convert a string amount to BN.
189
- *
190
- * @name toBN
191
- * @description Returns `undefined` for nullish input, otherwise parses
192
- * the string as a `BN` (big number) instance.
193
- * @param value - Numeric string or nullish
194
- * @returns A `BN` instance, or `undefined`
195
- * @internal
196
- * @since v0.1.0
197
- */
198
- function toBN(value: string | null | undefined): BN | undefined {
199
- return value ? new BN(value) : undefined;
200
- }
201
-
202
- /**
203
- * Convert a hex string to a Node.js Buffer.
204
- *
205
- * @name hexToBuffer
206
- * @description Used for encrypted data payloads before sending to
207
- * on-chain instructions.
208
- * @param hex - Hex-encoded string
209
- * @returns Buffer of decoded bytes
210
- * @internal
211
- * @since v0.1.0
212
- */
213
- function hexToBuffer(hex: string): Buffer {
214
- return Buffer.from(hex, "hex");
215
- }
216
-
217
- /**
218
- * Convert a hex string to Uint8Array for PDA seed derivation.
219
- *
220
- * @name hexToBytes
221
- * @description Wraps `Buffer.from(hex, 'hex')` into a `Uint8Array`
222
- * suitable for Solana PDA seed arrays.
223
- * @param hex - Hex-encoded string
224
- * @returns Uint8Array of decoded bytes
225
- * @internal
226
- * @since v0.1.0
227
- */
228
- function hexToBytes(hex: string): Uint8Array {
229
- return new Uint8Array(Buffer.from(hex, "hex"));
230
- }
231
-
232
- /**
233
- * Map token type strings to Anchor enum variant objects.
234
- *
235
- * @name toTokenType
236
- * @description Converts `"sol"`, `"usdc"`, or `"spl"` to the
237
- * corresponding Anchor enum variant. Defaults to `{ sol: {} }`.
238
- * @param s - Token type string
239
- * @returns Anchor-compatible enum variant object
240
- * @internal
241
- * @since v0.1.0
242
- */
243
- function toTokenType(s: string): object {
244
- const map: Record<string, object> = {
245
- sol: { sol: {} },
246
- usdc: { usdc: {} },
247
- spl: { spl: {} },
248
- };
249
- return map[s] ?? { sol: {} };
250
- }
251
-
252
- /**
253
- * Map settlement mode strings to Anchor enum variant objects.
254
- *
255
- * @name toSettlementMode
256
- * @description Converts `"instant"`, `"escrow"`, `"batched"`, or `"x402"`
257
- * to the corresponding Anchor enum variant. Returns `null` for nullish input.
258
- * @param s - Settlement mode string or nullish
259
- * @returns Anchor-compatible enum variant object, or `null`
260
- * @internal
261
- * @since v0.1.0
262
- */
263
- function toSettlementMode(s: string | null | undefined): object | null {
264
- if (!s) return null;
265
- const map: Record<string, object> = {
266
- instant: { instant: {} },
267
- escrow: { escrow: {} },
268
- batched: { batched: {} },
269
- x402: { x402: {} },
270
- };
271
- return map[s] ?? null;
272
- }
273
-
274
- /**
275
- * Map HTTP method strings to numeric enum values.
276
- *
277
- * @name toHttpMethodNum
278
- * @description Converts lowercase method names (`"get"`, `"post"`, etc.)
279
- * to their on-chain numeric representation. Defaults to `0` (GET).
280
- * @param s - HTTP method string
281
- * @returns Numeric enum value
282
- * @internal
283
- * @since v0.1.0
284
- */
285
- function toHttpMethodNum(s: string): number {
286
- const map: Record<string, number> = {
287
- get: 0,
288
- post: 1,
289
- put: 2,
290
- delete: 3,
291
- compound: 4,
292
- };
293
- return map[s] ?? 0;
294
- }
295
-
296
- /**
297
- * Map category strings to numeric enum values.
298
- *
299
- * @name toCategoryNum
300
- * @description Converts category names (`"swap"`, `"lend"`, etc.)
301
- * to their on-chain numeric representation. Defaults to `9` (custom).
302
- * @param s - Category string
303
- * @returns Numeric enum value
304
- * @internal
305
- * @since v0.1.0
306
- */
307
- function toCategoryNum(s: string): number {
308
- const map: Record<string, number> = {
309
- swap: 0,
310
- lend: 1,
311
- stake: 2,
312
- nft: 3,
313
- payment: 4,
314
- data: 5,
315
- governance: 6,
316
- bridge: 7,
317
- analytics: 8,
318
- custom: 9,
319
- };
320
- return map[s] ?? 9;
321
- }
322
-
323
- /**
324
- * Map schema type strings to numeric enum values.
325
- *
326
- * @name toSchemaTypeNum
327
- * @description Converts `"input"`, `"output"`, or `"description"`
328
- * to their on-chain numeric representation. Defaults to `0` (input).
329
- * @param s - Schema type string
330
- * @returns Numeric enum value
331
- * @internal
332
- * @since v0.1.0
333
- */
334
- function toSchemaTypeNum(s: string): number {
335
- const map: Record<string, number> = { input: 0, output: 1, description: 2 };
336
- return map[s] ?? 0;
337
- }
338
-
339
- /**
340
- * Map compression type strings to numeric enum values.
341
- *
342
- * @name toCompressionNum
343
- * @description Converts `"none"`, `"deflate"`, `"gzip"`, or `"brotli"`
344
- * to their on-chain numeric representation. Defaults to `0` (none).
345
- * @param s - Compression type string
346
- * @returns Numeric enum value
347
- * @internal
348
- * @since v0.1.0
349
- */
350
- function toCompressionNum(s: string): number {
351
- const map: Record<string, number> = {
352
- none: 0,
353
- deflate: 1,
354
- gzip: 2,
355
- brotli: 3,
356
- };
357
- return map[s] ?? 0;
358
- }
359
-
360
- /**
361
- * Convert a JSON-serialized pricing tier from plugin input
362
- * into the SDK’s PricingTier shape with BN/PublicKey/enum conversions.
363
- *
364
- * @name toPricingTier
365
- * @description Transforms raw JSON input (string amounts, string enums)
366
- * into the native Anchor-compatible shape with `BN`, `PublicKey`,
367
- * and enum variant objects.
368
- * @param raw - Raw pricing tier object from Zod-validated plugin input
369
- * @returns Anchor-compatible PricingTier object
370
- * @internal
371
- * @since v0.1.0
372
- */
373
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
374
- function toPricingTier(raw: any): any {
375
- return {
376
- tierId: raw.tierId,
377
- pricePerCall: new BN(raw.pricePerCall),
378
- minPricePerCall: toBN(raw.minPricePerCall) ?? null,
379
- maxPricePerCall: toBN(raw.maxPricePerCall) ?? null,
380
- rateLimit: raw.rateLimit,
381
- maxCallsPerSession: raw.maxCallsPerSession,
382
- burstLimit: raw.burstLimit ?? null,
383
- tokenType: toTokenType(raw.tokenType),
384
- tokenMint: toPubkey(raw.tokenMint) ?? null,
385
- tokenDecimals: raw.tokenDecimals ?? null,
386
- settlementMode: toSettlementMode(raw.settlementMode),
387
- minEscrowDeposit: toBN(raw.minEscrowDeposit) ?? null,
388
- batchIntervalSec: raw.batchIntervalSec ?? null,
389
- volumeCurve: raw.volumeCurve
390
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
391
- ? raw.volumeCurve.map((v: any) => ({
392
- afterCalls: v.afterCalls,
393
- pricePerCall: new BN(v.pricePerCall),
394
- }))
395
- : null,
396
- };
397
- }
398
-
399
- /**
400
- * Serialize an on-chain account object to a JSON-safe shape.
401
- *
402
- * @name serializeAccount
403
- * @description Recursively converts `PublicKey` → base58 string,
404
- * `BN` → decimal string, and nested objects/arrays. Used to
405
- * return tool output that is JSON-serializable for LLMs.
406
- * @param obj - Raw account data record from Anchor deserialization
407
- * @returns JSON-safe record with all Solana types converted to strings
408
- * @internal
409
- * @since v0.1.0
410
- */
411
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
412
- function serializeAccount(obj: Record<string, any>): Record<string, any> {
413
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
414
- const result: Record<string, any> = {};
415
- for (const [key, value] of Object.entries(obj)) {
416
- if (value === null || value === undefined) {
417
- result[key] = null;
418
- } else if (value instanceof PublicKey) {
419
- result[key] = value.toBase58();
420
- } else if (BN.isBN(value)) {
421
- result[key] = value.toString();
422
- } else if (Array.isArray(value)) {
423
- result[key] = value.map((item) => {
424
- if (item instanceof PublicKey) return item.toBase58();
425
- if (BN.isBN(item)) return item.toString();
426
- if (typeof item === "object" && item !== null)
427
- return serializeAccount(item);
428
- return item;
429
- });
430
- } else if (typeof value === "object") {
431
- result[key] = serializeAccount(value);
432
- } else {
433
- result[key] = value;
434
- }
435
- }
436
- return result;
437
- }
438
-
439
- // ═══════════════════════════════════════════════════════════════════
440
- // Executor Builder
441
- // ═══════════════════════════════════════════════════════════════════
442
-
443
- /**
444
- * Build the executor function that dispatches incoming tool calls
445
- * to the appropriate SapClient module method.
446
- *
447
- * @name buildExecutor
448
- * @description Creates a closure over a `SapClient` instance that routes
449
- * each incoming `ProtocolMethod` to the correct per-protocol dispatcher
450
- * based on `method.protocol`.
451
- * @param client - Initialized SapClient for the configured provider
452
- * @returns Async executor function `(method, input) => Promise<unknown>`
453
- * @internal
454
- * @since v0.1.0
455
- */
456
- function buildExecutor(
457
- client: SapClient,
458
- ): (method: ProtocolMethod, input: unknown) => Promise<unknown> {
459
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
- return async (method: ProtocolMethod, raw: any): Promise<unknown> => {
461
- switch (method.protocol) {
462
- // ────────────────────── Agent ──────────────────────
463
- case "sap-agent":
464
- return executeAgent(client, method.name, raw);
465
-
466
- // ────────────────────── Feedback ───────────────────
467
- case "sap-feedback":
468
- return executeFeedback(client, method.name, raw);
469
-
470
- // ────────────────────── Attestation ────────────────
471
- case "sap-attestation":
472
- return executeAttestation(client, method.name, raw);
473
-
474
- // ────────────────────── Escrow ─────────────────────
475
- case "sap-escrow":
476
- return executeEscrow(client, method.name, raw);
477
-
478
- // ────────────────────── Tools ──────────────────────
479
- case "sap-tools":
480
- return executeTools(client, method.name, raw);
481
-
482
- // ────────────────────── Vault ──────────────────────
483
- case "sap-vault":
484
- return executeVault(client, method.name, raw);
485
-
486
- // ────────────────────── Indexing ───────────────────
487
- case "sap-indexing":
488
- return executeIndexing(client, method.name, raw);
489
-
490
- // ────────────────────── Ledger ─────────────────────
491
- case "sap-ledger":
492
- return executeLedger(client, method.name, raw);
493
-
494
- default:
495
- throw new Error(`Unknown SAP protocol: ${method.protocol}`);
496
- }
497
- };
498
- }
499
-
500
- // ═══════════════════════════════════════════════════════════════════
501
- // Per-Protocol Dispatchers
502
- // ═══════════════════════════════════════════════════════════════════
503
-
504
- /**
505
- * Dispatch tool calls for the **sap-agent** protocol.
506
- *
507
- * @name executeAgent
508
- * @description Routes agent-domain method names to `client.agent.*` calls,
509
- * handling argument conversion and account serialization.
510
- * @param client - SapClient instance
511
- * @param name - Method name (e.g. `"registerAgent"`)
512
- * @param input - Zod-validated input from the LLM tool call
513
- * @returns Transaction signature or serialized account data
514
- * @internal
515
- * @since v0.1.0
516
- */
517
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
518
- async function executeAgent(client: SapClient, name: string, input: any) {
519
- switch (name) {
520
- case "registerAgent": {
521
- const args: RegisterAgentArgs = {
522
- name: input.name,
523
- description: input.description,
524
- capabilities: input.capabilities,
525
- pricing: (input.pricing ?? []).map(toPricingTier),
526
- protocols: input.protocols ?? [],
527
- agentId: input.agentId ?? null,
528
- agentUri: input.agentUri ?? null,
529
- x402Endpoint: input.x402Endpoint ?? null,
530
- };
531
- const tx = await client.agent.register(args);
532
- return { txSignature: tx };
533
- }
534
-
535
- case "updateAgent": {
536
- const args: UpdateAgentArgs = {
537
- name: input.name ?? null,
538
- description: input.description ?? null,
539
- capabilities: input.capabilities ?? null,
540
- pricing: input.pricing ? input.pricing.map(toPricingTier) : null,
541
- protocols: input.protocols ?? null,
542
- agentId: input.agentId ?? null,
543
- agentUri: input.agentUri ?? null,
544
- x402Endpoint: input.x402Endpoint ?? null,
545
- };
546
- const tx = await client.agent.update(args);
547
- return { txSignature: tx };
548
- }
549
-
550
- case "deactivateAgent": {
551
- const tx = await client.agent.deactivate();
552
- return { txSignature: tx };
553
- }
554
-
555
- case "reactivateAgent": {
556
- const tx = await client.agent.reactivate();
557
- return { txSignature: tx };
558
- }
559
-
560
- case "reportCalls": {
561
- const tx = await client.agent.reportCalls(input.callsServed);
562
- return { txSignature: tx };
563
- }
564
-
565
- case "updateReputation": {
566
- const tx = await client.agent.updateReputation(
567
- input.avgLatencyMs,
568
- input.uptimePercent,
569
- );
570
- return { txSignature: tx };
571
- }
572
-
573
- case "fetchAgent": {
574
- const wallet = toPubkey(input.wallet);
575
- const data = await client.agent.fetch(wallet);
576
- return serializeAccount(data as unknown as Record<string, unknown>);
577
- }
578
-
579
- case "fetchGlobalRegistry": {
580
- const data = await client.agent.fetchGlobalRegistry();
581
- return serializeAccount(data as unknown as Record<string, unknown>);
582
- }
583
-
584
- default:
585
- throw new Error(`Unknown sap-agent method: ${name}`);
586
- }
587
- }
588
-
589
- /**
590
- * Dispatch tool calls for the **sap-feedback** protocol.
591
- *
592
- * @name executeFeedback
593
- * @description Routes feedback-domain method names to `client.feedback.*` calls.
594
- * @param client - SapClient instance
595
- * @param name - Method name (e.g. `"giveFeedback"`)
596
- * @param input - Zod-validated input from the LLM tool call
597
- * @returns Transaction signature or serialized account data
598
- * @internal
599
- * @since v0.1.0
600
- */
601
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
602
- async function executeFeedback(client: SapClient, name: string, input: any) {
603
- switch (name) {
604
- case "giveFeedback": {
605
- const agentWallet = new PublicKey(input.agentWallet);
606
- const args: GiveFeedbackArgs = {
607
- score: input.score,
608
- tag: input.tag,
609
- commentHash: input.commentHash ?? null,
610
- };
611
- const tx = await client.feedback.give(agentWallet, args);
612
- return { txSignature: tx };
613
- }
614
-
615
- case "updateFeedback": {
616
- const agentWallet = new PublicKey(input.agentWallet);
617
- const args: UpdateFeedbackArgs = {
618
- newScore: input.newScore,
619
- newTag: input.newTag ?? null,
620
- commentHash: input.commentHash ?? null,
621
- };
622
- const tx = await client.feedback.update(agentWallet, args);
623
- return { txSignature: tx };
624
- }
625
-
626
- case "revokeFeedback": {
627
- const tx = await client.feedback.revoke(
628
- new PublicKey(input.agentWallet),
629
- );
630
- return { txSignature: tx };
631
- }
632
-
633
- case "fetchFeedback": {
634
- const [agentPda] = deriveAgent(new PublicKey(input.agentWallet));
635
- const reviewer = toPubkey(input.reviewer);
636
- const data = await client.feedback.fetch(agentPda, reviewer);
637
- return serializeAccount(data as unknown as Record<string, unknown>);
638
- }
639
-
640
- default:
641
- throw new Error(`Unknown sap-feedback method: ${name}`);
642
- }
643
- }
644
-
645
- /**
646
- * Dispatch tool calls for the **sap-attestation** protocol.
647
- *
648
- * @name executeAttestation
649
- * @description Routes attestation-domain method names to `client.attestation.*` calls.
650
- * @param client - SapClient instance
651
- * @param name - Method name (e.g. `"createAttestation"`)
652
- * @param input - Zod-validated input from the LLM tool call
653
- * @returns Transaction signature or serialized account data
654
- * @internal
655
- * @since v0.1.0
656
- */
657
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
658
- async function executeAttestation(client: SapClient, name: string, input: any) {
659
- switch (name) {
660
- case "createAttestation": {
661
- const args: CreateAttestationArgs = {
662
- attestationType: input.attestationType,
663
- metadataHash: input.metadataHash,
664
- expiresAt: new BN(input.expiresAt),
665
- };
666
- const tx = await client.attestation.create(
667
- new PublicKey(input.agentWallet),
668
- args,
669
- );
670
- return { txSignature: tx };
671
- }
672
-
673
- case "revokeAttestation": {
674
- const tx = await client.attestation.revoke(
675
- new PublicKey(input.agentWallet),
676
- );
677
- return { txSignature: tx };
678
- }
679
-
680
- case "fetchAttestation": {
681
- const [agentPda] = deriveAgent(new PublicKey(input.agentWallet));
682
- const attester = toPubkey(input.attester);
683
- const data = await client.attestation.fetch(agentPda, attester);
684
- return serializeAccount(data as unknown as Record<string, unknown>);
685
- }
686
-
687
- default:
688
- throw new Error(`Unknown sap-attestation method: ${name}`);
689
- }
690
- }
691
-
692
- /**
693
- * Dispatch tool calls for the **sap-escrow** protocol.
694
- *
695
- * @name executeEscrow
696
- * @description Routes escrow-domain method names to `client.escrow.*` calls,
697
- * including BN conversion for amounts and volume curves.
698
- * @param client - SapClient instance
699
- * @param name - Method name (e.g. `"createEscrow"`)
700
- * @param input - Zod-validated input from the LLM tool call
701
- * @returns Transaction signature or serialized account data
702
- * @internal
703
- * @since v0.1.0
704
- */
705
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
706
- async function executeEscrow(client: SapClient, name: string, input: any) {
707
- switch (name) {
708
- case "createEscrow": {
709
- const args: CreateEscrowArgs = {
710
- pricePerCall: new BN(input.pricePerCall),
711
- maxCalls: new BN(input.maxCalls),
712
- initialDeposit: new BN(input.initialDeposit),
713
- expiresAt: new BN(input.expiresAt),
714
- volumeCurve: (input.volumeCurve ?? []).map(
715
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
716
- (v: any): VolumeCurveBreakpoint => ({
717
- afterCalls: v.afterCalls,
718
- pricePerCall: new BN(v.pricePerCall),
719
- }),
720
- ),
721
- tokenMint: toPubkey(input.tokenMint) ?? null,
722
- tokenDecimals: input.tokenDecimals ?? 9,
723
- };
724
- const tx = await client.escrow.create(
725
- new PublicKey(input.agentWallet),
726
- args,
727
- );
728
- return { txSignature: tx };
729
- }
730
-
731
- case "depositEscrow": {
732
- const tx = await client.escrow.deposit(
733
- new PublicKey(input.agentWallet),
734
- new BN(input.amount),
735
- );
736
- return { txSignature: tx };
737
- }
738
-
739
- case "settleEscrow": {
740
- // Build settle options from optional priority fee fields
741
- const settleOpts = (input.priorityFeeMicroLamports || input.computeUnits || input.skipPreflight)
742
- ? {
743
- priorityFeeMicroLamports: input.priorityFeeMicroLamports ?? undefined,
744
- computeUnits: input.computeUnits ?? undefined,
745
- skipPreflight: input.skipPreflight ?? undefined,
746
- }
747
- : undefined;
748
- const tx = await client.escrow.settle(
749
- new PublicKey(input.depositorWallet),
750
- new BN(input.callsToSettle),
751
- input.serviceHash,
752
- [],
753
- settleOpts,
754
- );
755
- return { txSignature: tx };
756
- }
757
-
758
- case "withdrawEscrow": {
759
- const tx = await client.escrow.withdraw(
760
- new PublicKey(input.agentWallet),
761
- new BN(input.amount),
762
- );
763
- return { txSignature: tx };
764
- }
765
-
766
- case "batchSettle": {
767
- const settlements: Settlement[] = input.settlements.map(
768
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
769
- (s: any) => ({
770
- callsToSettle: new BN(s.callsToSettle),
771
- serviceHash: s.serviceHash,
772
- }),
773
- );
774
- // Build settle options from optional priority fee fields
775
- const batchOpts = (input.priorityFeeMicroLamports || input.computeUnits || input.skipPreflight)
776
- ? {
777
- priorityFeeMicroLamports: input.priorityFeeMicroLamports ?? undefined,
778
- computeUnits: input.computeUnits ?? undefined,
779
- skipPreflight: input.skipPreflight ?? undefined,
780
- }
781
- : undefined;
782
- const tx = await client.escrow.settleBatch(
783
- new PublicKey(input.depositorWallet),
784
- settlements,
785
- // batchRoot omitted \u2192 SDK auto-derives sha256(s_0 || ... || s_N)
786
- undefined,
787
- [],
788
- batchOpts,
789
- );
790
- return { txSignature: tx };
791
- }
792
-
793
- case "fetchEscrow": {
794
- const [agentPda] = deriveAgent(new PublicKey(input.agentWallet));
795
- const depositor = toPubkey(input.depositor);
796
- const data = await client.escrow.fetch(agentPda, depositor);
797
- return serializeAccount(data as unknown as Record<string, unknown>);
798
- }
799
-
800
- default:
801
- throw new Error(`Unknown sap-escrow method: ${name}`);
802
- }
803
- }
804
-
805
- /**
806
- * Dispatch tool calls for the **sap-tools** protocol.
807
- *
808
- * @name executeTools
809
- * @description Routes tools-domain method names to `client.tools.*` calls,
810
- * handling schema hashing and enum conversions.
811
- * @param client - SapClient instance
812
- * @param name - Method name (e.g. `"publishToolByName"`)
813
- * @param input - Zod-validated input from the LLM tool call
814
- * @returns Transaction signature or serialized account data
815
- * @internal
816
- * @since v0.1.0
817
- */
818
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
819
- async function executeTools(client: SapClient, name: string, input: any) {
820
- switch (name) {
821
- case "publishToolByName": {
822
- const tx = await client.tools.publishByName(
823
- input.toolName,
824
- input.protocolId,
825
- input.description,
826
- input.inputSchema,
827
- input.outputSchema,
828
- toHttpMethodNum(input.httpMethod),
829
- toCategoryNum(input.category),
830
- input.paramsCount,
831
- input.requiredParams,
832
- input.isCompound ?? false,
833
- );
834
- return { txSignature: tx };
835
- }
836
-
837
- case "inscribeToolSchema": {
838
- const args: InscribeToolSchemaArgs = {
839
- schemaType: toSchemaTypeNum(input.schemaType),
840
- schemaData: Buffer.from(input.schemaData, "utf-8"),
841
- schemaHash: hashToArray(sha256(input.schemaData)),
842
- compression: toCompressionNum(input.compression ?? "none"),
843
- };
844
- const tx = await client.tools.inscribeSchema(input.toolName, args);
845
- return { txSignature: tx };
846
- }
847
-
848
- case "updateTool": {
849
- const args: UpdateToolArgs = {
850
- descriptionHash: null,
851
- inputSchemaHash: null,
852
- outputSchemaHash: null,
853
- httpMethod:
854
- input.httpMethod != null ? toHttpMethodNum(input.httpMethod) : null,
855
- category:
856
- input.category != null ? toCategoryNum(input.category) : null,
857
- paramsCount: input.paramsCount ?? null,
858
- requiredParams: input.requiredParams ?? null,
859
- };
860
- const tx = await client.tools.update(input.toolName, args);
861
- return { txSignature: tx };
862
- }
863
-
864
- case "deactivateTool": {
865
- const tx = await client.tools.deactivate(input.toolName);
866
- return { txSignature: tx };
867
- }
868
-
869
- case "reactivateTool": {
870
- const tx = await client.tools.reactivate(input.toolName);
871
- return { txSignature: tx };
872
- }
873
-
874
- case "reportInvocations": {
875
- const tx = await client.tools.reportInvocations(
876
- input.toolName,
877
- input.invocations,
878
- );
879
- return { txSignature: tx };
880
- }
881
-
882
- case "fetchTool": {
883
- const [agentPda] = deriveAgent(new PublicKey(input.agentWallet));
884
- const data = await client.tools.fetch(agentPda, input.toolName);
885
- return serializeAccount(data as unknown as Record<string, unknown>);
886
- }
887
-
888
- default:
889
- throw new Error(`Unknown sap-tools method: ${name}`);
890
- }
891
- }
892
-
893
- /**
894
- * Dispatch tool calls for the **sap-vault** protocol.
895
- *
896
- * @name executeVault
897
- * @description Routes vault-domain method names to `client.vault.*` calls,
898
- * handling hex-to-bytes conversion and PDA derivation for sessions.
899
- * @param client - SapClient instance
900
- * @param name - Method name (e.g. `"initVault"`)
901
- * @param input - Zod-validated input from the LLM tool call
902
- * @returns Transaction signature or serialized account data
903
- * @internal
904
- * @since v0.1.0
905
- */
906
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
907
- async function executeVault(client: SapClient, name: string, input: any) {
908
- switch (name) {
909
- case "initVault": {
910
- const tx = await client.vault.initVault(input.vaultNonce);
911
- return { txSignature: tx };
912
- }
913
-
914
- case "openSession": {
915
- const tx = await client.vault.openSession(input.sessionHash);
916
- return { txSignature: tx };
917
- }
918
-
919
- case "inscribeMemory": {
920
- const args: InscribeMemoryArgs = {
921
- sequence: input.sequence,
922
- encryptedData: hexToBuffer(input.encryptedData),
923
- nonce: input.nonce,
924
- contentHash: input.contentHash,
925
- totalFragments: input.totalFragments ?? 1,
926
- fragmentIndex: input.fragmentIndex ?? 0,
927
- compression: input.compression ?? 0,
928
- epochIndex: input.epochIndex ?? 0,
929
- };
930
- const tx = await client.vault.inscribe(args);
931
- return { txSignature: tx };
932
- }
933
-
934
- case "closeSession": {
935
- const [agentPda] = deriveAgent(client.walletPubkey);
936
- const [vaultPda] = deriveVault(agentPda);
937
- const sessionHashBytes = hexToBytes(input.sessionHash);
938
- const [sessionPda] = deriveSession(vaultPda, sessionHashBytes);
939
- const tx = await client.vault.closeSession(vaultPda, sessionPda);
940
- return { txSignature: tx };
941
- }
942
-
943
- case "closeVault": {
944
- const tx = await client.vault.closeVault();
945
- return { txSignature: tx };
946
- }
947
-
948
- case "rotateNonce": {
949
- const tx = await client.vault.rotateNonce(input.newNonce);
950
- return { txSignature: tx };
951
- }
952
-
953
- case "addDelegate": {
954
- const tx = await client.vault.addDelegate(
955
- new PublicKey(input.delegatePubkey),
956
- input.permissions,
957
- BigInt(input.expiresAt),
958
- );
959
- return { txSignature: tx };
960
- }
961
-
962
- case "revokeDelegate": {
963
- const tx = await client.vault.revokeDelegate(
964
- new PublicKey(input.delegatePubkey),
965
- );
966
- return { txSignature: tx };
967
- }
968
-
969
- case "fetchVault": {
970
- const wallet = toPubkey(input.agentWallet) ?? client.walletPubkey;
971
- const [agentPda] = deriveAgent(wallet);
972
- const data = await client.vault.fetchVault(agentPda);
973
- return serializeAccount(data as unknown as Record<string, unknown>);
974
- }
975
-
976
- case "fetchSession": {
977
- const wallet = new PublicKey(input.agentWallet);
978
- const [agentPda] = deriveAgent(wallet);
979
- const [vaultPda] = deriveVault(agentPda);
980
- const sessionHashBytes = hexToBytes(input.sessionHash);
981
- const data = await client.vault.fetchSession(vaultPda, sessionHashBytes);
982
- return serializeAccount(data as unknown as Record<string, unknown>);
983
- }
984
-
985
- default:
986
- throw new Error(`Unknown sap-vault method: ${name}`);
987
- }
988
- }
989
-
990
- /**
991
- * Dispatch tool calls for the **sap-indexing** protocol.
992
- *
993
- * @name executeIndexing
994
- * @description Routes indexing-domain method names to `client.indexing.*` calls
995
- * for capability and protocol index management.
996
- * @param client - SapClient instance
997
- * @param name - Method name (e.g. `"initCapabilityIndex"`)
998
- * @param input - Zod-validated input from the LLM tool call
999
- * @returns Transaction signature or serialized account data
1000
- * @internal
1001
- * @since v0.1.0
1002
- */
1003
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1004
- async function executeIndexing(client: SapClient, name: string, input: any) {
1005
- switch (name) {
1006
- case "initCapabilityIndex": {
1007
- const tx = await client.indexing.initCapabilityIndex(input.capabilityId);
1008
- return { txSignature: tx };
1009
- }
1010
- case "addToCapabilityIndex": {
1011
- const tx = await client.indexing.addToCapabilityIndex(input.capabilityId);
1012
- return { txSignature: tx };
1013
- }
1014
- case "removeFromCapabilityIndex": {
1015
- const tx = await client.indexing.removeFromCapabilityIndex(
1016
- input.capabilityId,
1017
- );
1018
- return { txSignature: tx };
1019
- }
1020
- case "initProtocolIndex": {
1021
- const tx = await client.indexing.initProtocolIndex(input.protocolId);
1022
- return { txSignature: tx };
1023
- }
1024
- case "addToProtocolIndex": {
1025
- const tx = await client.indexing.addToProtocolIndex(input.protocolId);
1026
- return { txSignature: tx };
1027
- }
1028
- case "removeFromProtocolIndex": {
1029
- const tx = await client.indexing.removeFromProtocolIndex(
1030
- input.protocolId,
1031
- );
1032
- return { txSignature: tx };
1033
- }
1034
- case "fetchCapabilityIndex": {
1035
- const data = await client.indexing.fetchCapabilityIndex(
1036
- input.capabilityId,
1037
- );
1038
- return serializeAccount(data as unknown as Record<string, unknown>);
1039
- }
1040
- case "fetchProtocolIndex": {
1041
- const data = await client.indexing.fetchProtocolIndex(input.protocolId);
1042
- return serializeAccount(data as unknown as Record<string, unknown>);
1043
- }
1044
- default:
1045
- throw new Error(`Unknown sap-indexing method: ${name}`);
1046
- }
1047
- }
1048
-
1049
- /**
1050
- * Dispatch tool calls for the **sap-ledger** protocol.
1051
- *
1052
- * @name executeLedger
1053
- * @description Routes ledger-domain method names to `client.ledger.*` calls,
1054
- * deriving session PDAs from hex-encoded session hashes.
1055
- * @param client - SapClient instance
1056
- * @param name - Method name (e.g. `"initLedger"`)
1057
- * @param input - Zod-validated input from the LLM tool call
1058
- * @returns Transaction signature or serialized account data
1059
- * @internal
1060
- * @since v0.1.0
1061
- */
1062
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1063
- async function executeLedger(client: SapClient, name: string, input: any) {
1064
- const resolveSessionPda = (
1065
- sessionHash: string,
1066
- agentWallet?: string | null,
1067
- ) => {
1068
- const wallet = toPubkey(agentWallet) ?? client.walletPubkey;
1069
- const [agentPda] = deriveAgent(wallet);
1070
- const [vaultPda] = deriveVault(agentPda);
1071
- const sessionHashBytes = hexToBytes(sessionHash);
1072
- const [sessionPda] = deriveSession(vaultPda, sessionHashBytes);
1073
- return sessionPda;
1074
- };
1075
-
1076
- switch (name) {
1077
- case "initLedger": {
1078
- const sessionPda = resolveSessionPda(
1079
- input.sessionHash,
1080
- input.agentWallet,
1081
- );
1082
- const tx = await client.ledger.init(sessionPda);
1083
- return { txSignature: tx };
1084
- }
1085
-
1086
- case "writeLedger": {
1087
- const sessionPda = resolveSessionPda(
1088
- input.sessionHash,
1089
- input.agentWallet,
1090
- );
1091
- const data = hexToBuffer(input.data);
1092
- const tx = await client.ledger.write(sessionPda, data, input.contentHash);
1093
- return { txSignature: tx };
1094
- }
1095
-
1096
- case "sealLedger": {
1097
- const sessionPda = resolveSessionPda(
1098
- input.sessionHash,
1099
- input.agentWallet,
1100
- );
1101
- const tx = await client.ledger.seal(sessionPda);
1102
- return { txSignature: tx };
1103
- }
1104
-
1105
- case "closeLedger": {
1106
- const sessionPda = resolveSessionPda(
1107
- input.sessionHash,
1108
- input.agentWallet,
1109
- );
1110
- const tx = await client.ledger.close(sessionPda);
1111
- return { txSignature: tx };
1112
- }
1113
-
1114
- case "fetchLedger": {
1115
- const sessionPda = resolveSessionPda(
1116
- input.sessionHash,
1117
- input.agentWallet,
1118
- );
1119
- const data = await client.ledger.fetchLedger(sessionPda);
1120
- return serializeAccount(data as unknown as Record<string, unknown>);
1121
- }
1122
-
1123
- case "fetchLedgerPage": {
1124
- const sessionPda = resolveSessionPda(
1125
- input.sessionHash,
1126
- input.agentWallet,
1127
- );
1128
- const [ledgerPda] = deriveLedger(sessionPda);
1129
- const data = await client.ledger.fetchPage(ledgerPda, input.pageIndex);
1130
- return serializeAccount(data as unknown as Record<string, unknown>);
1131
- }
1132
-
1133
- default:
1134
- throw new Error(`Unknown sap-ledger method: ${name}`);
1135
- }
1136
- }
1137
-
1138
- // ═══════════════════════════════════════════════════════════════════
1139
- // Plugin Factory
1140
- // ═══════════════════════════════════════════════════════════════════
1141
-
1142
- /**
1143
- * Create a SynapsePlugin for SAP v2.
1144
- *
1145
- * @name createSAPPlugin
1146
- * @description Factory function that returns a fully configured
1147
- * {@link SynapsePlugin} exposing 52 tools across 8 on-chain
1148
- * protocol domains. The plugin can be installed into a
1149
- * `SynapseAgentKit` instance or used standalone.
1150
- * @param config - Plugin configuration with Anchor provider and optional program ID
1151
- * @returns A configured {@link SynapsePlugin} instance
1152
- * @category Plugin
1153
- * @since v0.1.0
1154
- *
1155
- * @example
1156
- * ```ts
1157
- * import { createSAPPlugin } from '@synapse-sap/sdk/plugin';
1158
- *
1159
- * const sapPlugin = createSAPPlugin({ provider });
1160
- *
1161
- * // Use with SynapseAgentKit:
1162
- * kit.use(sapPlugin);
1163
- *
1164
- * // Or standalone:
1165
- * const executor = sapPlugin.install({ client, config: {} }).executor;
1166
- * await executor(someMethod, someInput);
1167
- * ```
1168
- */
1169
- export function createSAPPlugin(config: SAPPluginConfig): SynapsePlugin {
1170
- return {
1171
- meta: {
1172
- id: "sap",
1173
- name: "SAP v2 — Synapse Agent Protocol",
1174
- version: SAP_PLUGIN_VERSION,
1175
- description:
1176
- "On-chain agent identity, reputation, tool registry, encrypted memory vault, x402 escrow, attestation, discovery indexes, and unified memory ledger on Solana",
1177
- tags: [
1178
- "solana",
1179
- "agent",
1180
- "identity",
1181
- "reputation",
1182
- "x402",
1183
- "escrow",
1184
- "vault",
1185
- "memory",
1186
- "tools",
1187
- "attestation",
1188
- "erc-8004",
1189
- ],
1190
- },
1191
-
1192
- protocols: SAP_PROTOCOLS,
1193
-
1194
- install(_context: PluginContext): PluginInstallResult {
1195
- const client = SapClient.from(config.provider, config.programId);
1196
- const executor = buildExecutor(client);
1197
-
1198
- return { executor };
1199
- },
1200
- };
1201
- }
1202
-
1203
- /**
1204
- * Pre-built plugin object for static use patterns.
1205
- *
1206
- * @name SAPPlugin
1207
- * @description Convenience namespace exposing a `configure` method
1208
- * that delegates to {@link createSAPPlugin}. Useful for concise
1209
- * one-liner instantiation.
1210
- * @category Plugin
1211
- * @since v0.1.0
1212
- *
1213
- * @example
1214
- * ```ts
1215
- * import { SAPPlugin } from '@synapse-sap/sdk/plugin';
1216
- *
1217
- * const plugin = SAPPlugin.configure({ provider });
1218
- * kit.use(plugin);
1219
- * ```
1220
- */
1221
- export const SAPPlugin = {
1222
- /** Create a configured SynapsePlugin from an AnchorProvider. */
1223
- configure: createSAPPlugin,
1224
- } as const;