@oobe-protocol-labs/synapse-sap-sdk 0.13.0 → 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 (654) 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 -86
  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 -33
  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 -189
  190. package/dist/cjs/modules/base.js.map +0 -1
  191. package/dist/cjs/modules/escrow-v2.js +0 -607
  192. package/dist/cjs/modules/escrow-v2.js.map +0 -1
  193. package/dist/cjs/modules/escrow.js +0 -336
  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 -159
  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 -345
  210. package/dist/cjs/modules/tools.js.map +0 -1
  211. package/dist/cjs/modules/vault.js +0 -427
  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/anchor-errors.js +0 -453
  272. package/dist/cjs/utils/anchor-errors.js.map +0 -1
  273. package/dist/cjs/utils/endpoint-validator.js +0 -232
  274. package/dist/cjs/utils/endpoint-validator.js.map +0 -1
  275. package/dist/cjs/utils/escrow-validation.js +0 -219
  276. package/dist/cjs/utils/escrow-validation.js.map +0 -1
  277. package/dist/cjs/utils/hash.js +0 -109
  278. package/dist/cjs/utils/hash.js.map +0 -1
  279. package/dist/cjs/utils/merchant-validator.js +0 -246
  280. package/dist/cjs/utils/merchant-validator.js.map +0 -1
  281. package/dist/cjs/utils/network-normalizer.js +0 -236
  282. package/dist/cjs/utils/network-normalizer.js.map +0 -1
  283. package/dist/cjs/utils/priority-fee.js +0 -215
  284. package/dist/cjs/utils/priority-fee.js.map +0 -1
  285. package/dist/cjs/utils/rpc-strategy.js +0 -239
  286. package/dist/cjs/utils/rpc-strategy.js.map +0 -1
  287. package/dist/cjs/utils/schemas.js +0 -331
  288. package/dist/cjs/utils/schemas.js.map +0 -1
  289. package/dist/cjs/utils/serialization.js +0 -105
  290. package/dist/cjs/utils/serialization.js.map +0 -1
  291. package/dist/cjs/utils/validation.js +0 -36
  292. package/dist/cjs/utils/validation.js.map +0 -1
  293. package/dist/cjs/utils/volume-curve.js +0 -117
  294. package/dist/cjs/utils/volume-curve.js.map +0 -1
  295. package/dist/cjs/utils/x402-direct.js +0 -231
  296. package/dist/cjs/utils/x402-direct.js.map +0 -1
  297. package/dist/esm/constants/addresses.js +0 -140
  298. package/dist/esm/constants/addresses.js.map +0 -1
  299. package/dist/esm/constants/index.js +0 -35
  300. package/dist/esm/constants/index.js.map +0 -1
  301. package/dist/esm/constants/limits.js +0 -158
  302. package/dist/esm/constants/limits.js.map +0 -1
  303. package/dist/esm/constants/network.js +0 -78
  304. package/dist/esm/constants/network.js.map +0 -1
  305. package/dist/esm/constants/payments.js +0 -131
  306. package/dist/esm/constants/payments.js.map +0 -1
  307. package/dist/esm/constants/programs.js +0 -75
  308. package/dist/esm/constants/programs.js.map +0 -1
  309. package/dist/esm/constants/seeds.js +0 -73
  310. package/dist/esm/constants/seeds.js.map +0 -1
  311. package/dist/esm/core/client.js +0 -539
  312. package/dist/esm/core/client.js.map +0 -1
  313. package/dist/esm/core/connection.js +0 -345
  314. package/dist/esm/core/connection.js.map +0 -1
  315. package/dist/esm/core/index.js +0 -19
  316. package/dist/esm/core/index.js.map +0 -1
  317. package/dist/esm/errors/index.js +0 -325
  318. package/dist/esm/errors/index.js.map +0 -1
  319. package/dist/esm/events/geyser.js +0 -258
  320. package/dist/esm/events/geyser.js.map +0 -1
  321. package/dist/esm/idl/index.js +0 -57
  322. package/dist/esm/idl/index.js.map +0 -1
  323. package/dist/esm/idl/synapse_agent_sap.json +0 -14595
  324. package/dist/esm/modules/agent.js +0 -268
  325. package/dist/esm/modules/agent.js.map +0 -1
  326. package/dist/esm/modules/attestation.js +0 -143
  327. package/dist/esm/modules/attestation.js.map +0 -1
  328. package/dist/esm/modules/base.js +0 -185
  329. package/dist/esm/modules/base.js.map +0 -1
  330. package/dist/esm/modules/escrow-v2.js +0 -603
  331. package/dist/esm/modules/escrow-v2.js.map +0 -1
  332. package/dist/esm/modules/escrow.js +0 -332
  333. package/dist/esm/modules/escrow.js.map +0 -1
  334. package/dist/esm/modules/feedback.js +0 -162
  335. package/dist/esm/modules/feedback.js.map +0 -1
  336. package/dist/esm/modules/index.js +0 -27
  337. package/dist/esm/modules/index.js.map +0 -1
  338. package/dist/esm/modules/indexing.js +0 -371
  339. package/dist/esm/modules/indexing.js.map +0 -1
  340. package/dist/esm/modules/ledger.js +0 -230
  341. package/dist/esm/modules/ledger.js.map +0 -1
  342. package/dist/esm/modules/receipt.js +0 -144
  343. package/dist/esm/modules/receipt.js.map +0 -1
  344. package/dist/esm/modules/staking.js +0 -155
  345. package/dist/esm/modules/staking.js.map +0 -1
  346. package/dist/esm/modules/subscription.js +0 -92
  347. package/dist/esm/modules/subscription.js.map +0 -1
  348. package/dist/esm/modules/tools.js +0 -341
  349. package/dist/esm/modules/tools.js.map +0 -1
  350. package/dist/esm/modules/vault.js +0 -423
  351. package/dist/esm/modules/vault.js.map +0 -1
  352. package/dist/esm/parser/client.js +0 -142
  353. package/dist/esm/parser/client.js.map +0 -1
  354. package/dist/esm/parser/complete.js +0 -173
  355. package/dist/esm/parser/complete.js.map +0 -1
  356. package/dist/esm/parser/index.js +0 -43
  357. package/dist/esm/parser/index.js.map +0 -1
  358. package/dist/esm/parser/inner.js +0 -180
  359. package/dist/esm/parser/inner.js.map +0 -1
  360. package/dist/esm/parser/instructions.js +0 -109
  361. package/dist/esm/parser/instructions.js.map +0 -1
  362. package/dist/esm/parser/transaction.js +0 -149
  363. package/dist/esm/parser/transaction.js.map +0 -1
  364. package/dist/esm/parser/types.js +0 -13
  365. package/dist/esm/parser/types.js.map +0 -1
  366. package/dist/esm/pda/index.js +0 -638
  367. package/dist/esm/pda/index.js.map +0 -1
  368. package/dist/esm/plugin/index.js +0 -945
  369. package/dist/esm/plugin/index.js.map +0 -1
  370. package/dist/esm/plugin/protocols.js +0 -279
  371. package/dist/esm/plugin/protocols.js.map +0 -1
  372. package/dist/esm/plugin/schemas.js +0 -860
  373. package/dist/esm/plugin/schemas.js.map +0 -1
  374. package/dist/esm/postgres/adapter.js +0 -678
  375. package/dist/esm/postgres/adapter.js.map +0 -1
  376. package/dist/esm/postgres/index.js +0 -27
  377. package/dist/esm/postgres/index.js.map +0 -1
  378. package/dist/esm/postgres/serializers.js +0 -362
  379. package/dist/esm/postgres/serializers.js.map +0 -1
  380. package/dist/esm/postgres/sync.js +0 -285
  381. package/dist/esm/postgres/sync.js.map +0 -1
  382. package/dist/esm/postgres/types.js +0 -41
  383. package/dist/esm/postgres/types.js.map +0 -1
  384. package/dist/esm/registries/builder.js +0 -410
  385. package/dist/esm/registries/builder.js.map +0 -1
  386. package/dist/esm/registries/discovery.js +0 -358
  387. package/dist/esm/registries/discovery.js.map +0 -1
  388. package/dist/esm/registries/fairscale.js +0 -633
  389. package/dist/esm/registries/fairscale.js.map +0 -1
  390. package/dist/esm/registries/index.js +0 -46
  391. package/dist/esm/registries/index.js.map +0 -1
  392. package/dist/esm/registries/metaplex-bridge.js +0 -706
  393. package/dist/esm/registries/metaplex-bridge.js.map +0 -1
  394. package/dist/esm/registries/session.js +0 -429
  395. package/dist/esm/registries/session.js.map +0 -1
  396. package/dist/esm/registries/x402.js +0 -664
  397. package/dist/esm/registries/x402.js.map +0 -1
  398. package/dist/esm/types/accounts.js +0 -12
  399. package/dist/esm/types/accounts.js.map +0 -1
  400. package/dist/esm/types/common.js +0 -12
  401. package/dist/esm/types/common.js.map +0 -1
  402. package/dist/esm/types/endpoint.js +0 -14
  403. package/dist/esm/types/endpoint.js.map +0 -1
  404. package/dist/esm/types/enums.js +0 -266
  405. package/dist/esm/types/enums.js.map +0 -1
  406. package/dist/esm/types/index.js +0 -25
  407. package/dist/esm/types/index.js.map +0 -1
  408. package/dist/esm/types/instructions.js +0 -89
  409. package/dist/esm/types/instructions.js.map +0 -1
  410. package/dist/esm/utils/anchor-errors.js +0 -447
  411. package/dist/esm/utils/anchor-errors.js.map +0 -1
  412. package/dist/esm/utils/endpoint-validator.js +0 -226
  413. package/dist/esm/utils/endpoint-validator.js.map +0 -1
  414. package/dist/esm/utils/escrow-validation.js +0 -212
  415. package/dist/esm/utils/escrow-validation.js.map +0 -1
  416. package/dist/esm/utils/hash.js +0 -103
  417. package/dist/esm/utils/hash.js.map +0 -1
  418. package/dist/esm/utils/merchant-validator.js +0 -241
  419. package/dist/esm/utils/merchant-validator.js.map +0 -1
  420. package/dist/esm/utils/network-normalizer.js +0 -229
  421. package/dist/esm/utils/network-normalizer.js.map +0 -1
  422. package/dist/esm/utils/priority-fee.js +0 -209
  423. package/dist/esm/utils/priority-fee.js.map +0 -1
  424. package/dist/esm/utils/rpc-strategy.js +0 -231
  425. package/dist/esm/utils/rpc-strategy.js.map +0 -1
  426. package/dist/esm/utils/schemas.js +0 -320
  427. package/dist/esm/utils/schemas.js.map +0 -1
  428. package/dist/esm/utils/serialization.js +0 -98
  429. package/dist/esm/utils/serialization.js.map +0 -1
  430. package/dist/esm/utils/validation.js +0 -33
  431. package/dist/esm/utils/validation.js.map +0 -1
  432. package/dist/esm/utils/volume-curve.js +0 -114
  433. package/dist/esm/utils/volume-curve.js.map +0 -1
  434. package/dist/esm/utils/x402-direct.js +0 -228
  435. package/dist/esm/utils/x402-direct.js.map +0 -1
  436. package/dist/types/constants/addresses.d.ts +0 -117
  437. package/dist/types/constants/addresses.d.ts.map +0 -1
  438. package/dist/types/constants/index.d.ts +0 -31
  439. package/dist/types/constants/index.d.ts.map +0 -1
  440. package/dist/types/constants/limits.d.ts +0 -149
  441. package/dist/types/constants/limits.d.ts.map +0 -1
  442. package/dist/types/constants/network.d.ts +0 -81
  443. package/dist/types/constants/network.d.ts.map +0 -1
  444. package/dist/types/constants/payments.d.ts +0 -121
  445. package/dist/types/constants/payments.d.ts.map +0 -1
  446. package/dist/types/constants/programs.d.ts +0 -69
  447. package/dist/types/constants/programs.d.ts.map +0 -1
  448. package/dist/types/constants/seeds.d.ts +0 -80
  449. package/dist/types/constants/seeds.d.ts.map +0 -1
  450. package/dist/types/core/client.d.ts +0 -452
  451. package/dist/types/core/client.d.ts.map +0 -1
  452. package/dist/types/core/connection.d.ts +0 -305
  453. package/dist/types/core/connection.d.ts.map +0 -1
  454. package/dist/types/core/index.d.ts +0 -20
  455. package/dist/types/core/index.d.ts.map +0 -1
  456. package/dist/types/errors/index.d.ts +0 -276
  457. package/dist/types/errors/index.d.ts.map +0 -1
  458. package/dist/types/events/geyser.d.ts +0 -150
  459. package/dist/types/events/geyser.d.ts.map +0 -1
  460. package/dist/types/events/index.d.ts +0 -248
  461. package/dist/types/events/index.d.ts.map +0 -1
  462. package/dist/types/idl/index.d.ts +0 -70
  463. package/dist/types/idl/index.d.ts.map +0 -1
  464. package/dist/types/index.d.ts +0 -85
  465. package/dist/types/index.d.ts.map +0 -1
  466. package/dist/types/modules/agent.d.ts +0 -166
  467. package/dist/types/modules/agent.d.ts.map +0 -1
  468. package/dist/types/modules/attestation.d.ts +0 -96
  469. package/dist/types/modules/attestation.d.ts.map +0 -1
  470. package/dist/types/modules/base.d.ts +0 -161
  471. package/dist/types/modules/base.d.ts.map +0 -1
  472. package/dist/types/modules/escrow-v2.d.ts +0 -169
  473. package/dist/types/modules/escrow-v2.d.ts.map +0 -1
  474. package/dist/types/modules/escrow.d.ts +0 -168
  475. package/dist/types/modules/escrow.d.ts.map +0 -1
  476. package/dist/types/modules/feedback.d.ts +0 -105
  477. package/dist/types/modules/feedback.d.ts.map +0 -1
  478. package/dist/types/modules/index.d.ts +0 -28
  479. package/dist/types/modules/index.d.ts.map +0 -1
  480. package/dist/types/modules/indexing.d.ts +0 -200
  481. package/dist/types/modules/indexing.d.ts.map +0 -1
  482. package/dist/types/modules/ledger.d.ts +0 -150
  483. package/dist/types/modules/ledger.d.ts.map +0 -1
  484. package/dist/types/modules/receipt.d.ts +0 -77
  485. package/dist/types/modules/receipt.d.ts.map +0 -1
  486. package/dist/types/modules/staking.d.ts +0 -51
  487. package/dist/types/modules/staking.d.ts.map +0 -1
  488. package/dist/types/modules/subscription.d.ts +0 -33
  489. package/dist/types/modules/subscription.d.ts.map +0 -1
  490. package/dist/types/modules/tools.d.ts +0 -182
  491. package/dist/types/modules/tools.d.ts.map +0 -1
  492. package/dist/types/modules/vault.d.ts +0 -240
  493. package/dist/types/modules/vault.d.ts.map +0 -1
  494. package/dist/types/parser/client.d.ts +0 -123
  495. package/dist/types/parser/client.d.ts.map +0 -1
  496. package/dist/types/parser/complete.d.ts +0 -90
  497. package/dist/types/parser/complete.d.ts.map +0 -1
  498. package/dist/types/parser/index.d.ts +0 -40
  499. package/dist/types/parser/index.d.ts.map +0 -1
  500. package/dist/types/parser/inner.d.ts +0 -114
  501. package/dist/types/parser/inner.d.ts.map +0 -1
  502. package/dist/types/parser/instructions.d.ts +0 -76
  503. package/dist/types/parser/instructions.d.ts.map +0 -1
  504. package/dist/types/parser/transaction.d.ts +0 -77
  505. package/dist/types/parser/transaction.d.ts.map +0 -1
  506. package/dist/types/parser/types.d.ts +0 -154
  507. package/dist/types/parser/types.d.ts.map +0 -1
  508. package/dist/types/pda/index.d.ts +0 -510
  509. package/dist/types/pda/index.d.ts.map +0 -1
  510. package/dist/types/plugin/index.d.ts +0 -171
  511. package/dist/types/plugin/index.d.ts.map +0 -1
  512. package/dist/types/plugin/protocols.d.ts +0 -152
  513. package/dist/types/plugin/protocols.d.ts.map +0 -1
  514. package/dist/types/plugin/schemas.d.ts +0 -829
  515. package/dist/types/plugin/schemas.d.ts.map +0 -1
  516. package/dist/types/postgres/adapter.d.ts +0 -355
  517. package/dist/types/postgres/adapter.d.ts.map +0 -1
  518. package/dist/types/postgres/index.d.ts +0 -24
  519. package/dist/types/postgres/index.d.ts.map +0 -1
  520. package/dist/types/postgres/serializers.d.ts +0 -30
  521. package/dist/types/postgres/serializers.d.ts.map +0 -1
  522. package/dist/types/postgres/sync.d.ts +0 -156
  523. package/dist/types/postgres/sync.d.ts.map +0 -1
  524. package/dist/types/postgres/types.d.ts +0 -167
  525. package/dist/types/postgres/types.d.ts.map +0 -1
  526. package/dist/types/registries/builder.d.ts +0 -340
  527. package/dist/types/registries/builder.d.ts.map +0 -1
  528. package/dist/types/registries/discovery.d.ts +0 -333
  529. package/dist/types/registries/discovery.d.ts.map +0 -1
  530. package/dist/types/registries/fairscale.d.ts +0 -680
  531. package/dist/types/registries/fairscale.d.ts.map +0 -1
  532. package/dist/types/registries/index.d.ts +0 -52
  533. package/dist/types/registries/index.d.ts.map +0 -1
  534. package/dist/types/registries/metaplex-bridge.d.ts +0 -488
  535. package/dist/types/registries/metaplex-bridge.d.ts.map +0 -1
  536. package/dist/types/registries/session.d.ts +0 -323
  537. package/dist/types/registries/session.d.ts.map +0 -1
  538. package/dist/types/registries/x402.d.ts +0 -530
  539. package/dist/types/registries/x402.d.ts.map +0 -1
  540. package/dist/types/types/accounts.d.ts +0 -765
  541. package/dist/types/types/accounts.d.ts.map +0 -1
  542. package/dist/types/types/common.d.ts +0 -166
  543. package/dist/types/types/common.d.ts.map +0 -1
  544. package/dist/types/types/endpoint.d.ts +0 -161
  545. package/dist/types/types/endpoint.d.ts.map +0 -1
  546. package/dist/types/types/enums.d.ts +0 -353
  547. package/dist/types/types/enums.d.ts.map +0 -1
  548. package/dist/types/types/index.d.ts +0 -29
  549. package/dist/types/types/index.d.ts.map +0 -1
  550. package/dist/types/types/instructions.d.ts +0 -400
  551. package/dist/types/types/instructions.d.ts.map +0 -1
  552. package/dist/types/utils/anchor-errors.d.ts +0 -61
  553. package/dist/types/utils/anchor-errors.d.ts.map +0 -1
  554. package/dist/types/utils/endpoint-validator.d.ts +0 -110
  555. package/dist/types/utils/endpoint-validator.d.ts.map +0 -1
  556. package/dist/types/utils/escrow-validation.d.ts +0 -145
  557. package/dist/types/utils/escrow-validation.d.ts.map +0 -1
  558. package/dist/types/utils/hash.d.ts +0 -75
  559. package/dist/types/utils/hash.d.ts.map +0 -1
  560. package/dist/types/utils/index.d.ts +0 -36
  561. package/dist/types/utils/index.d.ts.map +0 -1
  562. package/dist/types/utils/merchant-validator.d.ts +0 -176
  563. package/dist/types/utils/merchant-validator.d.ts.map +0 -1
  564. package/dist/types/utils/network-normalizer.d.ts +0 -120
  565. package/dist/types/utils/network-normalizer.d.ts.map +0 -1
  566. package/dist/types/utils/priority-fee.d.ts +0 -205
  567. package/dist/types/utils/priority-fee.d.ts.map +0 -1
  568. package/dist/types/utils/rpc-strategy.d.ts +0 -172
  569. package/dist/types/utils/rpc-strategy.d.ts.map +0 -1
  570. package/dist/types/utils/schemas.d.ts +0 -351
  571. package/dist/types/utils/schemas.d.ts.map +0 -1
  572. package/dist/types/utils/serialization.d.ts +0 -69
  573. package/dist/types/utils/serialization.d.ts.map +0 -1
  574. package/dist/types/utils/validation.d.ts +0 -29
  575. package/dist/types/utils/validation.d.ts.map +0 -1
  576. package/dist/types/utils/volume-curve.d.ts +0 -60
  577. package/dist/types/utils/volume-curve.d.ts.map +0 -1
  578. package/dist/types/utils/x402-direct.d.ts +0 -114
  579. package/dist/types/utils/x402-direct.d.ts.map +0 -1
  580. package/src/constants/addresses.ts +0 -162
  581. package/src/constants/index.ts +0 -69
  582. package/src/constants/limits.ts +0 -165
  583. package/src/constants/network.ts +0 -89
  584. package/src/constants/payments.ts +0 -145
  585. package/src/constants/programs.ts +0 -83
  586. package/src/constants/seeds.ts +0 -85
  587. package/src/core/client.ts +0 -583
  588. package/src/core/connection.ts +0 -461
  589. package/src/core/index.ts +0 -20
  590. package/src/errors/index.ts +0 -346
  591. package/src/events/geyser.ts +0 -384
  592. package/src/events/index.ts +0 -335
  593. package/src/events/yellowstone.d.ts +0 -7
  594. package/src/idl/index.ts +0 -76
  595. package/src/idl/synapse_agent_sap.json +0 -14595
  596. package/src/index.ts +0 -421
  597. package/src/modules/agent.ts +0 -319
  598. package/src/modules/attestation.ts +0 -168
  599. package/src/modules/base.ts +0 -247
  600. package/src/modules/escrow-v2.ts +0 -871
  601. package/src/modules/escrow.ts +0 -439
  602. package/src/modules/feedback.ts +0 -186
  603. package/src/modules/index.ts +0 -28
  604. package/src/modules/indexing.ts +0 -444
  605. package/src/modules/ledger.ts +0 -262
  606. package/src/modules/receipt.ts +0 -212
  607. package/src/modules/staking.ts +0 -223
  608. package/src/modules/subscription.ts +0 -147
  609. package/src/modules/tools.ts +0 -454
  610. package/src/modules/vault.ts +0 -558
  611. package/src/parser/client.ts +0 -211
  612. package/src/parser/complete.ts +0 -232
  613. package/src/parser/index.ts +0 -71
  614. package/src/parser/inner.ts +0 -255
  615. package/src/parser/instructions.ts +0 -135
  616. package/src/parser/transaction.ts +0 -200
  617. package/src/parser/types.ts +0 -182
  618. package/src/pda/index.ts +0 -919
  619. package/src/plugin/index.ts +0 -1224
  620. package/src/plugin/protocols.ts +0 -404
  621. package/src/plugin/schemas.ts +0 -941
  622. package/src/postgres/adapter.ts +0 -904
  623. package/src/postgres/index.ts +0 -59
  624. package/src/postgres/schema.sql +0 -683
  625. package/src/postgres/serializers.ts +0 -485
  626. package/src/postgres/sync.ts +0 -340
  627. package/src/postgres/types.ts +0 -245
  628. package/src/registries/builder.ts +0 -607
  629. package/src/registries/discovery.ts +0 -572
  630. package/src/registries/fairscale.ts +0 -1278
  631. package/src/registries/index.ts +0 -143
  632. package/src/registries/metaplex-bridge.ts +0 -1199
  633. package/src/registries/session.ts +0 -613
  634. package/src/registries/x402.ts +0 -1048
  635. package/src/types/accounts.ts +0 -858
  636. package/src/types/common.ts +0 -187
  637. package/src/types/endpoint.ts +0 -181
  638. package/src/types/enums.ts +0 -333
  639. package/src/types/index.ts +0 -121
  640. package/src/types/instructions.ts +0 -453
  641. package/src/utils/anchor-errors.ts +0 -461
  642. package/src/utils/endpoint-validator.ts +0 -300
  643. package/src/utils/escrow-validation.ts +0 -301
  644. package/src/utils/hash.ts +0 -113
  645. package/src/utils/index.ts +0 -118
  646. package/src/utils/merchant-validator.ts +0 -359
  647. package/src/utils/network-normalizer.ts +0 -240
  648. package/src/utils/priority-fee.ts +0 -325
  649. package/src/utils/rpc-strategy.ts +0 -322
  650. package/src/utils/schemas.ts +0 -359
  651. package/src/utils/serialization.ts +0 -98
  652. package/src/utils/validation.ts +0 -36
  653. package/src/utils/volume-curve.ts +0 -131
  654. package/src/utils/x402-direct.ts +0 -370
@@ -1,98 +0,0 @@
1
- /**
2
- * @module utils/serialization
3
- * @description JSON-safe serialization helpers for on-chain account data.
4
- *
5
- * On-chain Anchor account objects contain `PublicKey` and `BN` instances
6
- * that are not JSON-serializable. These helpers convert them to plain
7
- * strings (`base58` and decimal `string`) recursively.
8
- *
9
- * @category Utils
10
- * @since v0.1.0
11
- *
12
- * @example
13
- * ```ts
14
- * import { serializeAccount } from "@synapse-sap/sdk/utils";
15
- *
16
- * const raw = await program.account.agent.fetch(pda);
17
- * const json = serializeAccount(raw);
18
- * // { authority: "GBL...", totalCalls: "42", ... }
19
- * ```
20
- */
21
-
22
- import { PublicKey } from "@solana/web3.js";
23
- import BN from "bn.js";
24
-
25
- /**
26
- * Recursively convert a single value for JSON serialization.
27
- *
28
- * - `PublicKey` → base58 string
29
- * - `BN` → decimal string
30
- * - `Uint8Array` / `Buffer` → hex string
31
- * - `Array` → recursed
32
- * - plain `object` → recursed via {@link serializeAccount}
33
- * - primitives → identity
34
- *
35
- * @name serializeValue
36
- * @description Transforms a single Anchor-typed value into its JSON-safe equivalent.
37
- * @param value - The value to serialize.
38
- * @returns The JSON-safe representation of `value`.
39
- * @category Utils
40
- * @since v0.1.0
41
- * @example
42
- * ```ts
43
- * import { serializeValue } from "@synapse-sap/sdk/utils";
44
- *
45
- * serializeValue(new PublicKey("11111111111111111111111111111111")); // "1111..."
46
- * serializeValue(new BN(42)); // "42"
47
- * ```
48
- */
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- export function serializeValue(value: unknown): any {
51
- if (value === null || value === undefined) return null;
52
- if (value instanceof PublicKey) return value.toBase58();
53
- if (BN.isBN(value)) return value.toString();
54
- if (value instanceof Uint8Array || Buffer.isBuffer(value))
55
- return Buffer.from(value).toString("hex");
56
- if (Array.isArray(value)) return value.map(serializeValue);
57
- if (typeof value === "object") {
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- return serializeAccount(value as Record<string, any>);
60
- }
61
- return value;
62
- }
63
-
64
- /**
65
- * Serialize an entire on-chain account object to a JSON-safe shape.
66
- *
67
- * Iterates over each key and delegates to {@link serializeValue}.
68
- * Handles `PublicKey` → base58, `BN` → string, and nested
69
- * objects / arrays recursively.
70
- *
71
- * @name serializeAccount
72
- * @description Converts all non-primitive fields in an Anchor account record to JSON-safe strings.
73
- * @param obj - The raw account object returned by `program.account.<name>.fetch()`.
74
- * @returns A new plain object with all values converted.
75
- * @category Utils
76
- * @since v0.1.0
77
- * @example
78
- * ```ts
79
- * import { serializeAccount } from "@synapse-sap/sdk/utils";
80
- *
81
- * const raw = await program.account.agent.fetch(pda);
82
- * const safe = serializeAccount(raw);
83
- * console.log(JSON.stringify(safe));
84
- * ```
85
- */
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- export function serializeAccount(
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- obj: Record<string, any>,
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- ): Record<string, any> {
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- const result: Record<string, any> = {};
94
- for (const [key, value] of Object.entries(obj)) {
95
- result[key] = serializeValue(value);
96
- }
97
- return result;
98
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * @module utils/validation
3
- * @description Runtime assertion helpers.
4
- *
5
- * @category Utils
6
- * @since v0.1.0
7
- */
8
-
9
- /**
10
- * Assert that a condition holds, throwing a descriptive error otherwise.
11
- *
12
- * Uses TypeScript’s `asserts condition` return type so the compiler
13
- * narrows the guarded value after the call.
14
- *
15
- * @name assert
16
- * @description Runtime guard — throws `RangeError` with a `[SAP SDK]` prefix when the condition is falsy.
17
- * @param condition - The boolean expression to verify.
18
- * @param message - Human-readable message included in the thrown error.
19
- * @throws {RangeError} When `condition` is `false`.
20
- * @category Utils
21
- * @since v0.1.0
22
- * @example
23
- * ```ts
24
- * import { assert } from "@synapse-sap/sdk/utils";
25
- *
26
- * assert(name.length <= 64, "Agent name exceeds MAX_NAME_LEN");
27
- * ```
28
- */
29
- export function assert(
30
- condition: boolean,
31
- message: string,
32
- ): asserts condition {
33
- if (!condition) {
34
- throw new RangeError(`[SAP SDK] ${message}`);
35
- }
36
- }
@@ -1,131 +0,0 @@
1
- /**
2
- * @module volume-curve
3
- * @description Client-side mirror of the on-chain `calculate_settle_amount`
4
- * function from `programs/synapse-agent-sap/src/instructions/escrow_v2.rs`.
5
- *
6
- * Used by {@link EscrowV2Module.settle} to pre-compute the settlement
7
- * `amount` so it can chain `createPendingSettlement` in the same transaction
8
- * as `settleCallsV2` (DisputeWindow flow). Keeping the math in one place
9
- * here ensures the SDK stays byte-for-byte aligned with the program; if the
10
- * on-chain curve algorithm ever changes, this file is the single source of
11
- * truth on the client.
12
- *
13
- * @category Utilities
14
- * @since v0.13.0
15
- * @packageDocumentation
16
- */
17
-
18
- import { BN } from "@coral-xyz/anchor";
19
- import type { VolumeCurveBreakpoint } from "../types/common";
20
-
21
- const U64_MAX = new BN("18446744073709551615");
22
-
23
- function checkedMul(a: BN, b: BN): BN {
24
- const r = a.mul(b);
25
- if (r.gt(U64_MAX)) {
26
- throw new Error(
27
- `volume-curve: u64 overflow on multiply (${a.toString()} * ${b.toString()})`,
28
- );
29
- }
30
- return r;
31
- }
32
-
33
- function checkedAdd(a: BN, b: BN): BN {
34
- const r = a.add(b);
35
- if (r.gt(U64_MAX)) {
36
- throw new Error(
37
- `volume-curve: u64 overflow on add (${a.toString()} + ${b.toString()})`,
38
- );
39
- }
40
- return r;
41
- }
42
-
43
- /**
44
- * @function calculateSettleAmount
45
- * @description Compute the lamport (or token base-unit) amount the on-chain
46
- * `settle_calls_v2` handler will charge for `calls` calls, given the escrow's
47
- * `pricePerCall`, `volumeCurve`, and the current settled+pending counter.
48
- *
49
- * Mirrors the exact algorithm of `calculate_settle_amount` in
50
- * `escrow_v2.rs` (v0.7+):
51
- *
52
- * ```rust
53
- * if curve.is_empty() { calls * base_price } else { walk-the-curve }
54
- * ```
55
- *
56
- * Walks the curve from `cursor = totalCallsBefore` and at each cursor
57
- * position picks the breakpoint price whose `afterCalls` threshold the
58
- * cursor has passed. Calls are charged at the active price up to the next
59
- * threshold, then the cursor advances and the loop repeats until all
60
- * `calls` are accounted for.
61
- *
62
- * @param basePrice - Escrow's `pricePerCall` (BN, u64 lamports/base-units).
63
- * @param curve - The escrow's `volumeCurve` array (may be empty).
64
- * @param totalCallsBefore - `escrow.totalCallsSettled + escrow.pendingCalls`
65
- * AT THE MOMENT `settleCallsV2` runs on-chain.
66
- * @param calls - Number of calls being settled in this batch.
67
- * @returns The amount the on-chain handler will compute (BN, u64).
68
- *
69
- * @example
70
- * ```ts
71
- * import { calculateSettleAmount } from "@oobe-protocol-labs/synapse-sap-sdk";
72
- *
73
- * const amount = calculateSettleAmount(
74
- * escrow.pricePerCall,
75
- * escrow.volumeCurve,
76
- * escrow.totalCallsSettled.add(escrow.pendingCalls),
77
- * new BN(5),
78
- * );
79
- * ```
80
- *
81
- * @since v0.13.0
82
- */
83
- export function calculateSettleAmount(
84
- basePrice: BN,
85
- curve: VolumeCurveBreakpoint[],
86
- totalCallsBefore: BN,
87
- calls: BN,
88
- ): BN {
89
- if (calls.isZero()) return new BN(0);
90
- if (!curve || curve.length === 0) {
91
- return checkedMul(calls, basePrice);
92
- }
93
-
94
- let amount = new BN(0);
95
- let remaining = calls.clone();
96
- let cursor = totalCallsBefore.clone();
97
-
98
- while (remaining.gtn(0)) {
99
- let currentPrice = basePrice;
100
- let nextThreshold: BN | null = null;
101
-
102
- for (const bp of curve) {
103
- const threshold = new BN(bp.afterCalls);
104
- if (cursor.gte(threshold)) {
105
- currentPrice = bp.pricePerCall;
106
- } else {
107
- nextThreshold = threshold;
108
- break;
109
- }
110
- }
111
-
112
- let callsAtPrice: BN;
113
- if (nextThreshold) {
114
- const room = nextThreshold.sub(cursor);
115
- callsAtPrice = BN.min(remaining, room.isNeg() ? new BN(0) : room);
116
- if (callsAtPrice.isZero()) {
117
- // Defensive: shouldn't happen because cursor < nextThreshold by
118
- // the `else` branch above, but guard anyway.
119
- callsAtPrice = remaining;
120
- }
121
- } else {
122
- callsAtPrice = remaining;
123
- }
124
-
125
- amount = checkedAdd(amount, checkedMul(callsAtPrice, currentPrice));
126
- remaining = remaining.sub(callsAtPrice);
127
- cursor = cursor.add(callsAtPrice);
128
- }
129
-
130
- return amount;
131
- }
@@ -1,370 +0,0 @@
1
- /**
2
- * @module utils/x402-direct
3
- * @description Recognize x402 direct SPL token payments on an agent's ATA
4
- * by scanning transaction history and filtering for x402 patterns.
5
- *
6
- * @category Utils
7
- * @since v0.6.4
8
- */
9
-
10
- import {
11
- type Connection,
12
- PublicKey,
13
- type ParsedTransactionWithMeta,
14
- type ConfirmedSignatureInfo,
15
- } from "@solana/web3.js";
16
- import { sha256 } from "../utils";
17
-
18
- // ═══════════════════════════════════════════════════════════════════
19
- // Types
20
- // ═══════════════════════════════════════════════════════════════════
21
-
22
- /**
23
- * @interface SettlementPayload
24
- * @description Settlement metadata from the merchant's PAYMENT-RESPONSE.
25
- * @category Utils
26
- * @since v0.6.4
27
- */
28
- export interface SettlementPayload {
29
- /** SHA-256 service hash. */
30
- readonly serviceHash: string;
31
- /** Resource identifier. */
32
- readonly resource: string;
33
- /** Agent wallet (base58). */
34
- readonly agentWallet: string;
35
- /** Depositor wallet (base58). */
36
- readonly depositorWallet: string;
37
- /** Amount in smallest unit. */
38
- readonly amount: string;
39
- /** Service timestamp. */
40
- readonly timestamp: number;
41
- }
42
-
43
- /**
44
- * @interface X402DirectPayment
45
- * @description A recognized x402 direct SPL transfer on an agent's ATA.
46
- * @category Utils
47
- * @since v0.6.4
48
- */
49
- export interface X402DirectPayment {
50
- /** Transaction signature. */
51
- readonly signature: string;
52
- /** Transfer amount (in smallest token unit). */
53
- readonly amount: bigint;
54
- /** Source ATA (payer). */
55
- readonly payerAta: PublicKey;
56
- /** Destination ATA (payTo / agent). */
57
- readonly payeeAta: PublicKey;
58
- /** Token mint used for transfer. */
59
- readonly mint: PublicKey;
60
- /** Memo data (if a Memo instruction was included). */
61
- readonly memo: string | null;
62
- /** Matched settlement payload (if server-side verification is available). */
63
- readonly settlement: SettlementPayload | null;
64
- /** Block time (unix seconds). */
65
- readonly blockTime: number | null;
66
- /** Slot number. */
67
- readonly slot: number;
68
- }
69
-
70
- /**
71
- * @interface GetX402DirectOptions
72
- * @description Options for {@link getX402DirectPayments}.
73
- * @category Utils
74
- * @since v0.6.4
75
- */
76
- export interface GetX402DirectOptions {
77
- /** Max signatures to scan (default: 100). */
78
- readonly limit?: number;
79
- /** Only return transfers from this specific payer. */
80
- readonly filterPayer?: PublicKey;
81
- /** Known settlements from server-side PAYMENT-RESPONSE logs.
82
- * Used for deterministic hash matching. */
83
- readonly knownSettlements?: SettlementPayload[];
84
- /** Only include payments that match x402 memo prefix. Default: false. */
85
- readonly requireMemo?: boolean;
86
- /** Scan before this TX signature (pagination). */
87
- readonly before?: string;
88
- /** Scan after this TX signature (pagination). */
89
- readonly until?: string;
90
- }
91
-
92
- // ═══════════════════════════════════════════════════════════════════
93
- // Core
94
- // ═══════════════════════════════════════════════════════════════════
95
-
96
- /** Recognized x402 memo prefixes. */
97
- const X402_MEMO_PREFIXES = ["x402:", "SAP-x402:", "x402-direct:"];
98
-
99
- /**
100
- * @name extractSplTransfer
101
- * @description Extract SPL Token transfer details from a parsed transaction.
102
- *
103
- * Looks for `transfer` or `transferChecked` inner instructions on the
104
- * Token Program and returns source/dest/amount/mint.
105
- *
106
- * @internal
107
- */
108
- function extractSplTransfer(
109
- tx: ParsedTransactionWithMeta,
110
- payToAta: PublicKey,
111
- ): {
112
- amount: bigint;
113
- source: PublicKey;
114
- destination: PublicKey;
115
- mint: PublicKey;
116
- } | null {
117
- if (!tx.meta?.innerInstructions && !tx.transaction.message.instructions) {
118
- return null;
119
- }
120
-
121
- // Check all instructions (outer + inner)
122
- const allIxs = [
123
- ...tx.transaction.message.instructions,
124
- ...(tx.meta?.innerInstructions?.flatMap((g) => g.instructions) ?? []),
125
- ];
126
-
127
- for (const ix of allIxs) {
128
- // Only process parsed instructions with known program
129
- if (!("parsed" in ix) || !("program" in ix)) continue;
130
- const parsed = ix as { parsed: Record<string, unknown>; program: string };
131
-
132
- if (parsed.program !== "spl-token") continue;
133
-
134
- const info = parsed.parsed as {
135
- type?: string;
136
- info?: {
137
- source?: string;
138
- destination?: string;
139
- amount?: string;
140
- tokenAmount?: { amount?: string };
141
- mint?: string;
142
- authority?: string;
143
- };
144
- };
145
-
146
- if (
147
- info.type !== "transfer" &&
148
- info.type !== "transferChecked"
149
- ) {
150
- continue;
151
- }
152
-
153
- const transferInfo = info.info;
154
- if (!transferInfo?.source || !transferInfo?.destination) continue;
155
-
156
- // Check destination matches our payTo ATA
157
- const destPk = new PublicKey(transferInfo.destination);
158
- if (!destPk.equals(payToAta)) continue;
159
-
160
- const amountStr =
161
- transferInfo.amount ?? transferInfo.tokenAmount?.amount ?? "0";
162
-
163
- return {
164
- amount: BigInt(amountStr),
165
- source: new PublicKey(transferInfo.source),
166
- destination: destPk,
167
- mint: transferInfo.mint ? new PublicKey(transferInfo.mint) : destPk, // fallback
168
- };
169
- }
170
-
171
- return null;
172
- }
173
-
174
- /**
175
- * @name extractMemo
176
- * @description Extract memo data from a parsed transaction.
177
- * @internal
178
- */
179
- function extractMemo(tx: ParsedTransactionWithMeta): string | null {
180
- const allIxs = [
181
- ...tx.transaction.message.instructions,
182
- ...(tx.meta?.innerInstructions?.flatMap((g) => g.instructions) ?? []),
183
- ];
184
-
185
- for (const ix of allIxs) {
186
- if (!("parsed" in ix) || !("program" in ix)) continue;
187
- const parsed = ix as { parsed: unknown; program: string };
188
- if (parsed.program === "spl-memo" && typeof parsed.parsed === "string") {
189
- return parsed.parsed;
190
- }
191
- }
192
-
193
- // Also check log messages for memo
194
- if (tx.meta?.logMessages) {
195
- for (const log of tx.meta.logMessages) {
196
- if (log.startsWith("Program log: Memo")) {
197
- const memoMatch = log.match(/Memo \(len \d+\): "(.*?)"/);
198
- if (memoMatch?.[1]) return memoMatch[1];
199
- }
200
- }
201
- }
202
-
203
- return null;
204
- }
205
-
206
- /**
207
- * @name matchesX402Pattern
208
- * @description Check if a transfer matches an x402 payment pattern.
209
- *
210
- * Matches if:
211
- * - A memo with recognized x402 prefix is present, OR
212
- * - The transfer matches a known settlement payload (deterministic hash), OR
213
- * - `requireMemo` is false (any SPL transfer to the ATA is included)
214
- *
215
- * @internal
216
- */
217
- function matchesX402Pattern(
218
- transfer: { amount: bigint; source: PublicKey },
219
- memo: string | null,
220
- knownSettlements: SettlementPayload[],
221
- requireMemo: boolean,
222
- ): SettlementPayload | true | false {
223
- // 1. Check memo prefix
224
- if (memo) {
225
- for (const prefix of X402_MEMO_PREFIXES) {
226
- if (memo.startsWith(prefix)) return true;
227
- }
228
- // Try base64 JSON parse for embedded x402 payload
229
- try {
230
- const decoded = Buffer.from(memo, "base64").toString("utf-8");
231
- const parsed = JSON.parse(decoded);
232
- if (parsed.protocol === "x402" || parsed.protocol === "SAP-x402") {
233
- return true;
234
- }
235
- } catch {
236
- // Not base64 JSON — ignore
237
- }
238
- }
239
-
240
- // 2. Match against known settlements (deterministic hash)
241
- for (const settlement of knownSettlements) {
242
- const expected = BigInt(settlement.amount);
243
- if (transfer.amount !== expected) continue;
244
-
245
- // Deterministic hash: sha256(agentWallet + depositor + amount + timestamp)
246
- const hashInput =
247
- settlement.agentWallet +
248
- settlement.depositorWallet +
249
- settlement.amount +
250
- settlement.timestamp.toString();
251
- const expectedHash = Buffer.from(sha256(hashInput)).toString("hex");
252
- const serviceHash = settlement.serviceHash;
253
-
254
- if (expectedHash === serviceHash) return settlement;
255
- }
256
-
257
- // 3. If requireMemo is false, accept any SPL transfer to the ATA
258
- if (!requireMemo) return true;
259
-
260
- return false;
261
- }
262
-
263
- /**
264
- * @name getX402DirectPayments
265
- * @description Scan an agent's ATA for x402 direct payments.
266
- *
267
- * Fetches recent transaction signatures for the given `payTo` ATA,
268
- * inspects each transaction for SPL token transfers, and filters
269
- * for x402 payment patterns (memo prefix, settlement hash match, etc.).
270
- *
271
- * @param connection - Solana RPC connection.
272
- * @param payToAta - The agent's receiving ATA (e.g. USDC ATA of Syra).
273
- * @param opts - Filter and pagination options.
274
- * @returns Array of recognized x402 direct payments, newest first.
275
- *
276
- * @category Utils
277
- * @since v0.6.4
278
- *
279
- * @example
280
- * ```ts
281
- * import { getX402DirectPayments, findATA } from "@oobe-protocol-labs/synapse-sap-sdk";
282
- *
283
- * const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
284
- * const payToAta = findATA(agentWallet, USDC_MINT);
285
- *
286
- * const payments = await getX402DirectPayments(connection, payToAta, {
287
- * limit: 50,
288
- * knownSettlements: savedSettlements, // from your API PAYMENT-RESPONSE logs
289
- * });
290
- *
291
- * for (const p of payments) {
292
- * console.log(`${p.signature}: ${p.amount} from ${p.payerAta.toBase58()}`);
293
- * if (p.settlement) {
294
- * console.log(` Matched settlement: ${p.settlement.serviceHash}`);
295
- * }
296
- * }
297
- * ```
298
- */
299
- export async function getX402DirectPayments(
300
- connection: Connection,
301
- payToAta: PublicKey,
302
- opts?: GetX402DirectOptions,
303
- ): Promise<X402DirectPayment[]> {
304
- const limit = opts?.limit ?? 100;
305
- const knownSettlements = opts?.knownSettlements ?? [];
306
- const requireMemo = opts?.requireMemo ?? false;
307
-
308
- // 1. Fetch signatures
309
- const sigOpts: {
310
- limit: number;
311
- before?: string;
312
- until?: string;
313
- } = { limit };
314
- if (opts?.before) sigOpts.before = opts.before;
315
- if (opts?.until) sigOpts.until = opts.until;
316
-
317
- const sigs: ConfirmedSignatureInfo[] =
318
- await connection.getSignaturesForAddress(payToAta, sigOpts);
319
-
320
- if (sigs.length === 0) return [];
321
-
322
- // 2. Fetch transactions (batch with getParsedTransactions if available)
323
- const txs = await connection.getParsedTransactions(
324
- sigs.map((s) => s.signature),
325
- { maxSupportedTransactionVersion: 0 },
326
- );
327
-
328
- // 3. Extract and filter
329
- const results: X402DirectPayment[] = [];
330
-
331
- for (let i = 0; i < txs.length; i++) {
332
- const tx = txs[i];
333
- if (!tx) continue;
334
-
335
- // Extract SPL transfer to our ATA
336
- const transfer = extractSplTransfer(tx, payToAta);
337
- if (!transfer) continue;
338
-
339
- // Filter by payer if specified
340
- if (opts?.filterPayer && !transfer.source.equals(opts.filterPayer)) {
341
- continue;
342
- }
343
-
344
- // Extract memo
345
- const memo = extractMemo(tx);
346
-
347
- // Match x402 pattern
348
- const match = matchesX402Pattern(
349
- transfer,
350
- memo,
351
- knownSettlements,
352
- requireMemo,
353
- );
354
- if (match === false) continue;
355
-
356
- results.push({
357
- signature: sigs[i]!.signature,
358
- amount: transfer.amount,
359
- payerAta: transfer.source,
360
- payeeAta: transfer.destination,
361
- mint: transfer.mint,
362
- memo,
363
- settlement: typeof match === "object" ? match : null,
364
- blockTime: tx.blockTime ?? null,
365
- slot: tx.slot,
366
- });
367
- }
368
-
369
- return results;
370
- }