@drakkar.software/octobot-client 0.4.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 (306) hide show
  1. package/README.md +140 -0
  2. package/dist/client/adapters/accounts.d.ts +66 -0
  3. package/dist/client/adapters/accounts.d.ts.map +1 -0
  4. package/dist/client/adapters/accounts.js +214 -0
  5. package/dist/client/adapters/accounts.js.map +1 -0
  6. package/dist/client/adapters/actionHandle.d.ts +29 -0
  7. package/dist/client/adapters/actionHandle.d.ts.map +1 -0
  8. package/dist/client/adapters/actionHandle.js +34 -0
  9. package/dist/client/adapters/actionHandle.js.map +1 -0
  10. package/dist/client/adapters/automations.d.ts +31 -0
  11. package/dist/client/adapters/automations.d.ts.map +1 -0
  12. package/dist/client/adapters/automations.js +79 -0
  13. package/dist/client/adapters/automations.js.map +1 -0
  14. package/dist/client/adapters/documents.d.ts +55 -0
  15. package/dist/client/adapters/documents.d.ts.map +1 -0
  16. package/dist/client/adapters/documents.js +66 -0
  17. package/dist/client/adapters/documents.js.map +1 -0
  18. package/dist/client/adapters/nodeApi.d.ts +25 -0
  19. package/dist/client/adapters/nodeApi.d.ts.map +1 -0
  20. package/dist/client/adapters/nodeApi.js +81 -0
  21. package/dist/client/adapters/nodeApi.js.map +1 -0
  22. package/dist/client/adapters/settings.d.ts +16 -0
  23. package/dist/client/adapters/settings.d.ts.map +1 -0
  24. package/dist/client/adapters/settings.js +43 -0
  25. package/dist/client/adapters/settings.js.map +1 -0
  26. package/dist/client/adapters/strategies.d.ts +17 -0
  27. package/dist/client/adapters/strategies.d.ts.map +1 -0
  28. package/dist/client/adapters/strategies.js +75 -0
  29. package/dist/client/adapters/strategies.js.map +1 -0
  30. package/dist/client/connect/connect.d.ts +40 -0
  31. package/dist/client/connect/connect.d.ts.map +1 -0
  32. package/dist/client/connect/connect.js +133 -0
  33. package/dist/client/connect/connect.js.map +1 -0
  34. package/dist/client/connect/readOnly.d.ts +97 -0
  35. package/dist/client/connect/readOnly.d.ts.map +1 -0
  36. package/dist/client/connect/readOnly.js +167 -0
  37. package/dist/client/connect/readOnly.js.map +1 -0
  38. package/dist/client/core/errors.d.ts +80 -0
  39. package/dist/client/core/errors.d.ts.map +1 -0
  40. package/dist/client/core/errors.js +154 -0
  41. package/dist/client/core/errors.js.map +1 -0
  42. package/dist/client/core/options.d.ts +44 -0
  43. package/dist/client/core/options.d.ts.map +1 -0
  44. package/dist/client/core/options.js +2 -0
  45. package/dist/client/core/options.js.map +1 -0
  46. package/dist/client/core/session.d.ts +90 -0
  47. package/dist/client/core/session.d.ts.map +1 -0
  48. package/dist/client/core/session.js +72 -0
  49. package/dist/client/core/session.js.map +1 -0
  50. package/dist/client/core/views.d.ts +40 -0
  51. package/dist/client/core/views.d.ts.map +1 -0
  52. package/dist/client/core/views.js +32 -0
  53. package/dist/client/core/views.js.map +1 -0
  54. package/dist/client/index.d.ts +16 -0
  55. package/dist/client/index.d.ts.map +1 -0
  56. package/dist/client/index.js +9 -0
  57. package/dist/client/index.js.map +1 -0
  58. package/dist/client/mirror/collections.d.ts +125 -0
  59. package/dist/client/mirror/collections.d.ts.map +1 -0
  60. package/dist/client/mirror/collections.js +118 -0
  61. package/dist/client/mirror/collections.js.map +1 -0
  62. package/dist/client/mirror/index.d.ts +4 -0
  63. package/dist/client/mirror/index.d.ts.map +1 -0
  64. package/dist/client/mirror/index.js +4 -0
  65. package/dist/client/mirror/index.js.map +1 -0
  66. package/dist/client/mirror/writer.d.ts +39 -0
  67. package/dist/client/mirror/writer.d.ts.map +1 -0
  68. package/dist/client/mirror/writer.js +50 -0
  69. package/dist/client/mirror/writer.js.map +1 -0
  70. package/dist/client/pairing/mirrorGrant.d.ts +91 -0
  71. package/dist/client/pairing/mirrorGrant.d.ts.map +1 -0
  72. package/dist/client/pairing/mirrorGrant.js +99 -0
  73. package/dist/client/pairing/mirrorGrant.js.map +1 -0
  74. package/dist/client/pairing/mirrorReader.d.ts +99 -0
  75. package/dist/client/pairing/mirrorReader.d.ts.map +1 -0
  76. package/dist/client/pairing/mirrorReader.js +117 -0
  77. package/dist/client/pairing/mirrorReader.js.map +1 -0
  78. package/dist/client/pairing/pairingGrantExchange.d.ts +135 -0
  79. package/dist/client/pairing/pairingGrantExchange.d.ts.map +1 -0
  80. package/dist/client/pairing/pairingGrantExchange.js +186 -0
  81. package/dist/client/pairing/pairingGrantExchange.js.map +1 -0
  82. package/dist/client/pairing/pairingRequest.d.ts +82 -0
  83. package/dist/client/pairing/pairingRequest.d.ts.map +1 -0
  84. package/dist/client/pairing/pairingRequest.js +120 -0
  85. package/dist/client/pairing/pairingRequest.js.map +1 -0
  86. package/dist/client/strategy.d.ts +36 -0
  87. package/dist/client/strategy.d.ts.map +1 -0
  88. package/dist/client/strategy.js +26 -0
  89. package/dist/client/strategy.js.map +1 -0
  90. package/dist/collections/index.d.ts +3 -0
  91. package/dist/collections/index.d.ts.map +1 -0
  92. package/dist/collections/index.js +3 -0
  93. package/dist/collections/index.js.map +1 -0
  94. package/dist/collections/nodeCollections.d.ts +57 -0
  95. package/dist/collections/nodeCollections.d.ts.map +1 -0
  96. package/dist/collections/nodeCollections.js +40 -0
  97. package/dist/collections/nodeCollections.js.map +1 -0
  98. package/dist/collections/paths.d.ts +7 -0
  99. package/dist/collections/paths.d.ts.map +1 -0
  100. package/dist/collections/paths.js +13 -0
  101. package/dist/collections/paths.js.map +1 -0
  102. package/dist/crypto/collectionKeys.d.ts +28 -0
  103. package/dist/crypto/collectionKeys.d.ts.map +1 -0
  104. package/dist/crypto/collectionKeys.js +53 -0
  105. package/dist/crypto/collectionKeys.js.map +1 -0
  106. package/dist/crypto/hkdf.d.ts +14 -0
  107. package/dist/crypto/hkdf.d.ts.map +1 -0
  108. package/dist/crypto/hkdf.js +19 -0
  109. package/dist/crypto/hkdf.js.map +1 -0
  110. package/dist/crypto/index.d.ts +5 -0
  111. package/dist/crypto/index.d.ts.map +1 -0
  112. package/dist/crypto/index.js +5 -0
  113. package/dist/crypto/index.js.map +1 -0
  114. package/dist/crypto/secretEncryptor.d.ts +20 -0
  115. package/dist/crypto/secretEncryptor.d.ts.map +1 -0
  116. package/dist/crypto/secretEncryptor.js +82 -0
  117. package/dist/crypto/secretEncryptor.js.map +1 -0
  118. package/dist/crypto/wireConstants.d.ts +14 -0
  119. package/dist/crypto/wireConstants.d.ts.map +1 -0
  120. package/dist/crypto/wireConstants.js +17 -0
  121. package/dist/crypto/wireConstants.js.map +1 -0
  122. package/dist/identity/address.d.ts +3 -0
  123. package/dist/identity/address.d.ts.map +1 -0
  124. package/dist/identity/address.js +17 -0
  125. package/dist/identity/address.js.map +1 -0
  126. package/dist/identity/bip39-wordlist.d.ts +2 -0
  127. package/dist/identity/bip39-wordlist.d.ts.map +1 -0
  128. package/dist/identity/bip39-wordlist.js +2051 -0
  129. package/dist/identity/bip39-wordlist.js.map +1 -0
  130. package/dist/identity/capProvider.d.ts +45 -0
  131. package/dist/identity/capProvider.d.ts.map +1 -0
  132. package/dist/identity/capProvider.js +80 -0
  133. package/dist/identity/capProvider.js.map +1 -0
  134. package/dist/identity/derivationSchemes.d.ts +25 -0
  135. package/dist/identity/derivationSchemes.d.ts.map +1 -0
  136. package/dist/identity/derivationSchemes.js +34 -0
  137. package/dist/identity/derivationSchemes.js.map +1 -0
  138. package/dist/identity/evm.d.ts +8 -0
  139. package/dist/identity/evm.d.ts.map +1 -0
  140. package/dist/identity/evm.js +78 -0
  141. package/dist/identity/evm.js.map +1 -0
  142. package/dist/identity/index.d.ts +10 -0
  143. package/dist/identity/index.d.ts.map +1 -0
  144. package/dist/identity/index.js +10 -0
  145. package/dist/identity/index.js.map +1 -0
  146. package/dist/identity/keys.d.ts +17 -0
  147. package/dist/identity/keys.d.ts.map +1 -0
  148. package/dist/identity/keys.js +36 -0
  149. package/dist/identity/keys.js.map +1 -0
  150. package/dist/identity/mnemonic.d.ts +4 -0
  151. package/dist/identity/mnemonic.d.ts.map +1 -0
  152. package/dist/identity/mnemonic.js +93 -0
  153. package/dist/identity/mnemonic.js.map +1 -0
  154. package/dist/identity/pairing.d.ts +45 -0
  155. package/dist/identity/pairing.d.ts.map +1 -0
  156. package/dist/identity/pairing.js +91 -0
  157. package/dist/identity/pairing.js.map +1 -0
  158. package/dist/identity/pairingRequest.d.ts +99 -0
  159. package/dist/identity/pairingRequest.d.ts.map +1 -0
  160. package/dist/identity/pairingRequest.js +217 -0
  161. package/dist/identity/pairingRequest.js.map +1 -0
  162. package/dist/identity/secret.d.ts +32 -0
  163. package/dist/identity/secret.d.ts.map +1 -0
  164. package/dist/identity/secret.js +54 -0
  165. package/dist/identity/secret.js.map +1 -0
  166. package/dist/index.d.ts +9 -0
  167. package/dist/index.d.ts.map +1 -0
  168. package/dist/index.js +18 -0
  169. package/dist/index.js.map +1 -0
  170. package/dist/internal/bytes.d.ts +11 -0
  171. package/dist/internal/bytes.d.ts.map +1 -0
  172. package/dist/internal/bytes.js +38 -0
  173. package/dist/internal/bytes.js.map +1 -0
  174. package/dist/node-api/dexPair.d.ts +24 -0
  175. package/dist/node-api/dexPair.d.ts.map +1 -0
  176. package/dist/node-api/dexPair.js +39 -0
  177. package/dist/node-api/dexPair.js.map +1 -0
  178. package/dist/node-api/dsl.d.ts +10 -0
  179. package/dist/node-api/dsl.d.ts.map +1 -0
  180. package/dist/node-api/dsl.js +7 -0
  181. package/dist/node-api/dsl.js.map +1 -0
  182. package/dist/node-api/exchanges.d.ts +49 -0
  183. package/dist/node-api/exchanges.d.ts.map +1 -0
  184. package/dist/node-api/exchanges.js +32 -0
  185. package/dist/node-api/exchanges.js.map +1 -0
  186. package/dist/node-api/index.d.ts +12 -0
  187. package/dist/node-api/index.d.ts.map +1 -0
  188. package/dist/node-api/index.js +12 -0
  189. package/dist/node-api/index.js.map +1 -0
  190. package/dist/node-api/marketMaking.d.ts +39 -0
  191. package/dist/node-api/marketMaking.d.ts.map +1 -0
  192. package/dist/node-api/marketMaking.js +44 -0
  193. package/dist/node-api/marketMaking.js.map +1 -0
  194. package/dist/node-api/octobots.d.ts +14 -0
  195. package/dist/node-api/octobots.d.ts.map +1 -0
  196. package/dist/node-api/octobots.js +16 -0
  197. package/dist/node-api/octobots.js.map +1 -0
  198. package/dist/node-api/orderBookPreview.d.ts +11 -0
  199. package/dist/node-api/orderBookPreview.d.ts.map +1 -0
  200. package/dist/node-api/orderBookPreview.js +7 -0
  201. package/dist/node-api/orderBookPreview.js.map +1 -0
  202. package/dist/node-api/pairing.d.ts +39 -0
  203. package/dist/node-api/pairing.d.ts.map +1 -0
  204. package/dist/node-api/pairing.js +61 -0
  205. package/dist/node-api/pairing.js.map +1 -0
  206. package/dist/node-api/pairs.d.ts +32 -0
  207. package/dist/node-api/pairs.d.ts.map +1 -0
  208. package/dist/node-api/pairs.js +72 -0
  209. package/dist/node-api/pairs.js.map +1 -0
  210. package/dist/node-api/requiredFunds.d.ts +11 -0
  211. package/dist/node-api/requiredFunds.d.ts.map +1 -0
  212. package/dist/node-api/requiredFunds.js +7 -0
  213. package/dist/node-api/requiredFunds.js.map +1 -0
  214. package/dist/node-api/setup.d.ts +25 -0
  215. package/dist/node-api/setup.d.ts.map +1 -0
  216. package/dist/node-api/setup.js +13 -0
  217. package/dist/node-api/setup.js.map +1 -0
  218. package/dist/node-api/wallet.d.ts +55 -0
  219. package/dist/node-api/wallet.d.ts.map +1 -0
  220. package/dist/node-api/wallet.js +87 -0
  221. package/dist/node-api/wallet.js.map +1 -0
  222. package/dist/protocol/actions.d.ts +40 -0
  223. package/dist/protocol/actions.d.ts.map +1 -0
  224. package/dist/protocol/actions.js +118 -0
  225. package/dist/protocol/actions.js.map +1 -0
  226. package/dist/protocol/documents.d.ts +25 -0
  227. package/dist/protocol/documents.d.ts.map +1 -0
  228. package/dist/protocol/documents.js +2 -0
  229. package/dist/protocol/documents.js.map +1 -0
  230. package/dist/protocol/index.d.ts +10 -0
  231. package/dist/protocol/index.d.ts.map +1 -0
  232. package/dist/protocol/index.js +12 -0
  233. package/dist/protocol/index.js.map +1 -0
  234. package/dist/protocol/orchestration/createAutomation.d.ts +61 -0
  235. package/dist/protocol/orchestration/createAutomation.d.ts.map +1 -0
  236. package/dist/protocol/orchestration/createAutomation.js +71 -0
  237. package/dist/protocol/orchestration/createAutomation.js.map +1 -0
  238. package/dist/protocol/poll.d.ts +4 -0
  239. package/dist/protocol/poll.d.ts.map +1 -0
  240. package/dist/protocol/poll.js +4 -0
  241. package/dist/protocol/poll.js.map +1 -0
  242. package/dist/protocol/proposal.d.ts +36 -0
  243. package/dist/protocol/proposal.d.ts.map +1 -0
  244. package/dist/protocol/proposal.js +39 -0
  245. package/dist/protocol/proposal.js.map +1 -0
  246. package/dist/protocol/state.d.ts +87 -0
  247. package/dist/protocol/state.d.ts.map +1 -0
  248. package/dist/protocol/state.js +303 -0
  249. package/dist/protocol/state.js.map +1 -0
  250. package/dist/protocol/strategy/build.d.ts +44 -0
  251. package/dist/protocol/strategy/build.d.ts.map +1 -0
  252. package/dist/protocol/strategy/build.js +50 -0
  253. package/dist/protocol/strategy/build.js.map +1 -0
  254. package/dist/protocol/strategy/builders.d.ts +252 -0
  255. package/dist/protocol/strategy/builders.d.ts.map +1 -0
  256. package/dist/protocol/strategy/builders.js +382 -0
  257. package/dist/protocol/strategy/builders.js.map +1 -0
  258. package/dist/protocol/strategy/index.d.ts +5 -0
  259. package/dist/protocol/strategy/index.d.ts.map +1 -0
  260. package/dist/protocol/strategy/index.js +4 -0
  261. package/dist/protocol/strategy/index.js.map +1 -0
  262. package/dist/protocol/strategy/kinds.d.ts +2 -0
  263. package/dist/protocol/strategy/kinds.d.ts.map +1 -0
  264. package/dist/protocol/strategy/kinds.js +2 -0
  265. package/dist/protocol/strategy/kinds.js.map +1 -0
  266. package/dist/protocol/strategy/patch.d.ts +59 -0
  267. package/dist/protocol/strategy/patch.d.ts.map +1 -0
  268. package/dist/protocol/strategy/patch.js +253 -0
  269. package/dist/protocol/strategy/patch.js.map +1 -0
  270. package/dist/protocol/symbols.d.ts +8 -0
  271. package/dist/protocol/symbols.d.ts.map +1 -0
  272. package/dist/protocol/symbols.js +11 -0
  273. package/dist/protocol/symbols.js.map +1 -0
  274. package/dist/transport/constants.d.ts +8 -0
  275. package/dist/transport/constants.d.ts.map +1 -0
  276. package/dist/transport/constants.js +8 -0
  277. package/dist/transport/constants.js.map +1 -0
  278. package/dist/transport/documents.d.ts +27 -0
  279. package/dist/transport/documents.d.ts.map +1 -0
  280. package/dist/transport/documents.js +34 -0
  281. package/dist/transport/documents.js.map +1 -0
  282. package/dist/transport/index.d.ts +8 -0
  283. package/dist/transport/index.d.ts.map +1 -0
  284. package/dist/transport/index.js +8 -0
  285. package/dist/transport/index.js.map +1 -0
  286. package/dist/transport/probe.d.ts +44 -0
  287. package/dist/transport/probe.d.ts.map +1 -0
  288. package/dist/transport/probe.js +121 -0
  289. package/dist/transport/probe.js.map +1 -0
  290. package/dist/transport/rendezvous.d.ts +116 -0
  291. package/dist/transport/rendezvous.d.ts.map +1 -0
  292. package/dist/transport/rendezvous.js +139 -0
  293. package/dist/transport/rendezvous.js.map +1 -0
  294. package/dist/transport/rest.d.ts +35 -0
  295. package/dist/transport/rest.d.ts.map +1 -0
  296. package/dist/transport/rest.js +58 -0
  297. package/dist/transport/rest.js.map +1 -0
  298. package/dist/transport/syncClient.d.ts +14 -0
  299. package/dist/transport/syncClient.d.ts.map +1 -0
  300. package/dist/transport/syncClient.js +30 -0
  301. package/dist/transport/syncClient.js.map +1 -0
  302. package/dist/transport/urls.d.ts +35 -0
  303. package/dist/transport/urls.d.ts.map +1 -0
  304. package/dist/transport/urls.js +126 -0
  305. package/dist/transport/urls.js.map +1 -0
  306. package/package.json +55 -0
@@ -0,0 +1,253 @@
1
+ import { isSignalProfileData, signalProfileDataToInput, DCA_DEFAULTS, GRID_INPUT_DEFAULTS, } from './builders.js';
2
+ /** `TradingTentaclesConfiguration.symbols` was dropped from the protocol —
3
+ * the node resolves traded symbols from the trading mode's own config. New
4
+ * configs no longer emit it, but strategies written before that still carry
5
+ * it, so rehydration keeps reading it as a fallback. */
6
+ function legacySymbols(cfg) {
7
+ const symbols = cfg.symbols;
8
+ return Array.isArray(symbols) ? symbols.filter((s) => typeof s === 'string') : [];
9
+ }
10
+ /** Cadence an older builder encoded as a time_frames entry, in minutes. */
11
+ const LEGACY_DCA_TIMEFRAME_MINUTES = {
12
+ '1d': 1_440,
13
+ '3d': 4_320,
14
+ '1w': 10_080,
15
+ };
16
+ /** Recover an editable `StrategyInputPatch` from a protocol `Strategy`. The
17
+ * inverse of `buildStrategy` in ./build.ts, tolerant of configs written by
18
+ * older or foreign clients (never throws — unrecognized shapes fall to
19
+ * `{ kind: 'custom' }`). */
20
+ export function protocolStrategyToInput(strategy) {
21
+ const cfg = strategy.configuration;
22
+ switch (cfg.configuration_type) {
23
+ case 'market_making': {
24
+ const first = cfg.pair_settings[0];
25
+ const refsByPair = {};
26
+ const budgetByPair = {};
27
+ const stopsByPair = {};
28
+ const volumeByPair = {};
29
+ const hedgingByPair = {};
30
+ const orderBookByPair = {};
31
+ for (const p of cfg.pair_settings) {
32
+ refsByPair[p.trading_pair] = p.reference_price.map((r) => ({
33
+ pair: r.pair,
34
+ formula: r.formula ?? undefined,
35
+ timeframe: r.time_frame ?? '1h',
36
+ weight: r.weight ?? 1,
37
+ // Preserve cross-venue references across the edit round-trip; the
38
+ // bot's own venue stays implicit (re-stamped at build time).
39
+ ...(r.exchange && r.exchange !== p.exchange ? { exchange: r.exchange } : {}),
40
+ }));
41
+ // A pair carries a real budget configuration when a bound beyond the
42
+ // legacy max_base_budget echo is set — an old builder always echoed
43
+ // sizeBase into max_quote_budget, so a bare equal max_quote_budget with
44
+ // no min floor is ambiguous and treated as "no budget" for that pair.
45
+ if (p.max_quote_budget != null
46
+ && (p.max_quote_budget !== p.max_base_budget || p.min_base_budget != null || p.min_quote_budget != null)) {
47
+ budgetByPair[p.trading_pair] = {
48
+ enabled: true,
49
+ maxBase: p.max_base_budget ?? 0,
50
+ maxQuote: p.max_quote_budget,
51
+ minBase: p.min_base_budget ?? 0,
52
+ minQuote: p.min_quote_budget ?? 0,
53
+ };
54
+ }
55
+ if (p.stop_conditions) {
56
+ const sc = p.stop_conditions;
57
+ stopsByPair[p.trading_pair] = {
58
+ enabled: true,
59
+ minBaseHolding: sc.min_base_holding ?? 0,
60
+ minQuoteHolding: sc.min_quote_holding ?? 0,
61
+ maxPositivePct: sc.max_positive_percent_price_change ?? 0,
62
+ maxNegativePct: sc.max_negative_percent_price_change ?? 0,
63
+ avgPriceMinutes: sc.average_price_counted_minutes ?? 60,
64
+ };
65
+ }
66
+ if (p.scheduled_volume) {
67
+ const v = p.scheduled_volume;
68
+ volumeByPair[p.trading_pair] = {
69
+ enabled: true,
70
+ minAmount: v.min_amount,
71
+ maxAmount: v.max_amount,
72
+ minIntervalSeconds: v.min_interval_seconds,
73
+ maxIntervalSeconds: v.max_interval_seconds,
74
+ };
75
+ }
76
+ if (p.hedging_engine) {
77
+ const h = p.hedging_engine;
78
+ hedgingByPair[p.trading_pair] = {
79
+ enabled: true,
80
+ exchange: h.hedging_exchange ?? '',
81
+ maxLossThreshold: h.hedging_max_loss_threshold ?? 0,
82
+ avgPriceMinutes: h.average_price_counted_minutes ?? 60,
83
+ maxNegativePct: h.max_negative_percent_price_change ?? 0,
84
+ maxPositivePct: h.max_positive_percent_price_change ?? 0,
85
+ };
86
+ }
87
+ // Always present on the protocol (not optional like stop_conditions),
88
+ // so populated unconditionally for every pair — round to 6 decimals
89
+ // of a bp same as spreadBp above (min_spread*100 picks up FP noise).
90
+ orderBookByPair[p.trading_pair] = {
91
+ minSpreadBp: String(Math.round(p.min_spread * 100 * 1e6) / 1e6),
92
+ maxSpreadBp: String(Math.round(p.max_spread * 100 * 1e6) / 1e6),
93
+ bidsCount: String(p.bids_count ?? 0),
94
+ asksCount: String(p.asks_count ?? 0),
95
+ ordersDistribution: p.orders_distribution ?? 'linear',
96
+ fundsDistribution: p.funds_distribution ?? 'flat',
97
+ cumulatedVolumePercent: String(p.order_book_depth?.cumulated_volume_percent ?? 1),
98
+ percentDailyTradingVolume: String(p.order_book_depth?.percent_daily_trading_volume ?? 1),
99
+ };
100
+ }
101
+ // sizeBase is the bot-wide fallback max_base_budget used for pairs with
102
+ // no per-pair budget override — it must be read from one of THOSE
103
+ // pairs, not pairs[0] blindly. pairs[0] may itself carry a per-pair
104
+ // override, in which case its max_base_budget is unrelated to the
105
+ // shared fallback and recovering sizeBase from it would corrupt every
106
+ // other budget-disabled pair on the next build. Every fallback pair
107
+ // shares the same baseSize by construction, so the first one found is
108
+ // authoritative.
109
+ //
110
+ // sizeBase is NOT purely inert when no fallback pair exists (every pair
111
+ // has its own override): an editor may also display/edit it directly
112
+ // as an "size per order" field, and if the user later disables any
113
+ // pair's override in the same edit session, this recovered value
114
+ // becomes that pair's new real budget. Picking an arbitrary pair's own
115
+ // override there risks silently inflating a newly-disabled pair to an
116
+ // unrelated pair's cap — using the smallest override across all pairs
117
+ // instead bounds that risk to under- rather than over-allocating.
118
+ const fallbackBudgetPair = cfg.pair_settings.find((p) => !(p.trading_pair in budgetByPair));
119
+ const smallestOverride = cfg.pair_settings.reduce((min, p) => {
120
+ const v = p.max_base_budget;
121
+ return v != null && (min == null || v < min) ? v : min;
122
+ }, undefined);
123
+ return {
124
+ kind: 'mm',
125
+ pairs: cfg.pair_settings.map((p) => p.trading_pair),
126
+ refsByPair,
127
+ mm: {
128
+ // min_spread is spreadBp/100; multiplying back picks up FP noise
129
+ // (0.07 * 100 === 7.000000000000001) — round to 6 decimals of a bp.
130
+ spreadBp: String(Math.round((first?.min_spread ?? 0) * 100 * 1e6) / 1e6),
131
+ perSide: String(first?.bids_count ?? 0),
132
+ sizeBase: String(fallbackBudgetPair?.max_base_budget ?? smallestOverride ?? first?.max_base_budget ?? 0),
133
+ shape: first?.funds_distribution === 'valley' ? 'expo'
134
+ : first?.funds_distribution === 'random' ? 'random'
135
+ : 'flat',
136
+ exchange: first?.exchange,
137
+ ...(Object.keys(budgetByPair).length > 0 ? { budgetByPair } : {}),
138
+ ...(Object.keys(stopsByPair).length > 0 ? { stopsByPair } : {}),
139
+ ...(Object.keys(volumeByPair).length > 0 ? { volumeByPair } : {}),
140
+ ...(Object.keys(hedgingByPair).length > 0 ? { hedgingByPair } : {}),
141
+ ...(Object.keys(orderBookByPair).length > 0 ? { orderBookByPair } : {}),
142
+ },
143
+ };
144
+ }
145
+ case 'trading_tentacles': {
146
+ switch (cfg.name) {
147
+ case 'GridTradingMode': {
148
+ const c = cfg.config;
149
+ const ps = c.pair_settings?.[0] ?? {};
150
+ // `levels` counts orders, not price lines — see GridInput.levels.
151
+ const levels = (ps.buy_orders_count ?? 0) + (ps.sell_orders_count ?? 0);
152
+ const configured = (ps.flat_spread ?? 0) > 0 || (ps.flat_increment ?? 0) > 0;
153
+ return {
154
+ kind: 'grid',
155
+ pairs: ps.pair ? [ps.pair] : legacySymbols(cfg),
156
+ grid: configured
157
+ ? {
158
+ spread: ps.flat_spread ?? 0,
159
+ increment: ps.flat_increment ?? 0,
160
+ buyCount: ps.buy_orders_count ?? 0,
161
+ sellCount: ps.sell_orders_count ?? 0,
162
+ levels,
163
+ // Mirrors gridPairSettings' own emit defaults, so configs
164
+ // written before these fields existed rehydrate to what
165
+ // they actually ran with.
166
+ enableTrailingUp: ps.enable_trailing_up ?? GRID_INPUT_DEFAULTS.enableTrailingUp,
167
+ orderByOrderTrailing: ps.order_by_order_trailing ?? GRID_INPUT_DEFAULTS.orderByOrderTrailing,
168
+ }
169
+ : null,
170
+ };
171
+ }
172
+ case 'DCATradingMode': {
173
+ const c = cfg.config;
174
+ // Prefer whichever list actually has pairs, rather than `??`: that
175
+ // only falls through on null/undefined, so a `symbols: []`
176
+ // alongside a populated `config.trading_pairs` would rehydrate the
177
+ // draft with no pairs. Applying that draft re-emits
178
+ // `trading_pairs: []`, and the node — which resolves DCA's traded
179
+ // symbols from `config.trading_pairs` and ignores the top-level
180
+ // `symbols` entirely — then rejects it with "Traded symbols cannot
181
+ // be empty".
182
+ const legacy = legacySymbols(cfg);
183
+ const symbols = legacy.length ? legacy : (c.trading_pairs ?? []);
184
+ const rawAmount = c.buy_order_amount;
185
+ const buyOrderAmount = typeof rawAmount === 'number'
186
+ ? `${rawAmount}%t`
187
+ : rawAmount?.trim() || DCA_DEFAULTS.buy_order_amount;
188
+ // Legacy configs (pre minutes_before_next_buy) carried cadence in
189
+ // time_frames — map the old '1d'/'3d'/'1w' emission back to minutes.
190
+ const legacyTf = c.time_frames?.[0];
191
+ const legacyMinutes = legacyTf != null ? LEGACY_DCA_TIMEFRAME_MINUTES[legacyTf] ?? null : null;
192
+ return {
193
+ kind: 'dca',
194
+ pairs: symbols,
195
+ dca: {
196
+ buyOrderAmount,
197
+ minutesBeforeNextBuy: c.minutes_before_next_buy
198
+ ?? legacyMinutes
199
+ ?? DCA_DEFAULTS.minutes_before_next_buy,
200
+ useMarketEntry: c.use_market_entry_orders ?? DCA_DEFAULTS.use_market_entry_orders,
201
+ entryLimitPricePercent: c.entry_limit_orders_price_percent ?? DCA_DEFAULTS.entry_limit_orders_price_percent,
202
+ useTakeProfit: c.use_take_profit_exit_orders ?? DCA_DEFAULTS.use_take_profit_exit_orders,
203
+ exitLimitPricePercent: c.exit_limit_orders_price_percent ?? DCA_DEFAULTS.exit_limit_orders_price_percent,
204
+ },
205
+ };
206
+ }
207
+ case 'IndexTradingMode': {
208
+ // index_content values are raw relative weights. Configs written by
209
+ // an older builder stored 0–1 fractions instead — a sum at (or
210
+ // below) 1 is unmistakably that legacy shape (a real weight set
211
+ // summing to 1 is scale-invariant anyway), so rescale it to percent.
212
+ const c = cfg.config;
213
+ const coins = c.index_content ?? [];
214
+ const rawTotal = coins.reduce((s, coin) => s + coin.value, 0);
215
+ const scale = rawTotal > 0 && rawTotal <= 1.000001 ? 100 : 1;
216
+ const basketWeights = {};
217
+ for (const coin of coins)
218
+ basketWeights[coin.name] = Math.round(coin.value * scale * 1e6) / 1e6;
219
+ return {
220
+ kind: 'basket',
221
+ pairs: coins.map((coin) => coin.name),
222
+ basket: {
223
+ pairs: coins.map((coin) => coin.name),
224
+ basketWeights,
225
+ basketTotal: Math.round(rawTotal * scale * 1e6) / 1e6,
226
+ rebalanceTriggerPct: c.rebalance_trigger_min_percent,
227
+ },
228
+ };
229
+ }
230
+ default:
231
+ return { kind: 'custom' };
232
+ }
233
+ }
234
+ case 'copy':
235
+ return { kind: 'copy', copy: { sourceId: cfg.strategy_id } };
236
+ case 'generic_process':
237
+ return isSignalProfileData(cfg.profile_data)
238
+ ? { kind: 'signal', signal: signalProfileDataToInput(cfg.profile_data) }
239
+ : { kind: 'custom' };
240
+ default:
241
+ return { kind: 'custom' };
242
+ }
243
+ }
244
+ /** Bump a semver-ish `MAJOR.MINOR.PATCH` string's patch component by one,
245
+ * zero-filling any missing component. */
246
+ export function bumpStrategyPatchVersion(version) {
247
+ const parts = version.split('.').map((n) => Number.parseInt(n, 10));
248
+ while (parts.length < 3)
249
+ parts.push(0);
250
+ const patch = Number.isFinite(parts[2]) ? parts[2] + 1 : 1;
251
+ return `${parts[0] || 0}.${parts[1] || 0}.${patch}`;
252
+ }
253
+ //# sourceMappingURL=patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/protocol/strategy/patch.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,GAWpB,MAAM,eAAe,CAAA;AAyCtB;;;yDAGyD;AACzD,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,OAAO,GAAI,GAA6B,CAAC,OAAO,CAAA;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAChG,CAAC;AAED,2EAA2E;AAC3E,MAAM,4BAA4B,GAA2B;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AE,EAAE,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAA;QAC9D,KAAK,iBAAiB;YACpB,OAAO,mBAAmB,CAAC,GAAG,CAAC,YAAY,CAAC;gBAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,wBAAwB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;gBACxE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QACxB;YACE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;IAC7B,CAAC;AACH,CAAC;AAED;0CAC0C;AAC1C,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACnE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1D,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAA;AACrD,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Base currency of a trading pair symbol, e.g. `'BTC/USDT'` or the
2
+ * perpetual-futures form `'BTC/USDT:USDT'` → `'BTC'`. Order/Trade/Position
3
+ * `symbol` fields are always pairs, never a bare coin — this is the one
4
+ * place that assumption is encoded, for per-asset filtering and logo
5
+ * lookups (which key by bare coin symbol). Returns the input unchanged when
6
+ * it does not look like a pair (defensive default, never throws). */
7
+ export declare function baseCurrencyOf(pairSymbol: string): string;
8
+ //# sourceMappingURL=symbols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../src/protocol/symbols.ts"],"names":[],"mappings":"AAAA;;;;;sEAKsE;AACtE,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAGzD"}
@@ -0,0 +1,11 @@
1
+ /** Base currency of a trading pair symbol, e.g. `'BTC/USDT'` or the
2
+ * perpetual-futures form `'BTC/USDT:USDT'` → `'BTC'`. Order/Trade/Position
3
+ * `symbol` fields are always pairs, never a bare coin — this is the one
4
+ * place that assumption is encoded, for per-asset filtering and logo
5
+ * lookups (which key by bare coin symbol). Returns the input unchanged when
6
+ * it does not look like a pair (defensive default, never throws). */
7
+ export function baseCurrencyOf(pairSymbol) {
8
+ const [base] = pairSymbol.split('/');
9
+ return base || pairSymbol;
10
+ }
11
+ //# sourceMappingURL=symbols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/protocol/symbols.ts"],"names":[],"mappings":"AAAA;;;;;sEAKsE;AACtE,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACpC,OAAO,IAAI,IAAI,UAAU,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const API_PREFIX = "/api/v1";
2
+ export declare const DEFAULT_NODE_PORT = 5001;
3
+ export declare const EXCHANGES_TIMEOUT_MS = 8000;
4
+ export declare const PROBE_TIMEOUT_MS = 4000;
5
+ export declare const MARKET_MAKING_TIMEOUT_MS = 15000;
6
+ export declare const CREATE_GENERIC_PROCESS_TIMEOUT_MS = 60000;
7
+ export declare const NODE_STATUS_PATH = "/api/v1/setup/status";
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/transport/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,YAAY,CAAA;AAEnC,eAAO,MAAM,iBAAiB,OAAO,CAAA;AAErC,eAAO,MAAM,oBAAoB,OAAO,CAAA;AACxC,eAAO,MAAM,gBAAgB,OAAO,CAAA;AACpC,eAAO,MAAM,wBAAwB,QAAQ,CAAA;AAC7C,eAAO,MAAM,iCAAiC,QAAS,CAAA;AAEvD,eAAO,MAAM,gBAAgB,yBAA+B,CAAA"}
@@ -0,0 +1,8 @@
1
+ export const API_PREFIX = '/api/v1';
2
+ export const DEFAULT_NODE_PORT = 5001;
3
+ export const EXCHANGES_TIMEOUT_MS = 8000;
4
+ export const PROBE_TIMEOUT_MS = 4000;
5
+ export const MARKET_MAKING_TIMEOUT_MS = 15000;
6
+ export const CREATE_GENERIC_PROCESS_TIMEOUT_MS = 60_000;
7
+ export const NODE_STATUS_PATH = `${API_PREFIX}/setup/status`;
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/transport/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAA;AAEnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAErC,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAA;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAA;AACpC,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAA;AAC7C,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAA;AAEvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,UAAU,eAAe,CAAA"}
@@ -0,0 +1,27 @@
1
+ import type { StarfishClient } from '@drakkar.software/starfish-client';
2
+ import type { Encryptor } from '@drakkar.software/starfish-protocol';
3
+ import { type NodeCollectionKey } from '../collections/nodeCollections.js';
4
+ export type PulledDocument<T> = {
5
+ data: T;
6
+ hash: string | null;
7
+ };
8
+ /** One collection's `{identity}`-scoped params. `accountId` is only needed for
9
+ * `accountTrading` — every other node collection is identity-only. */
10
+ export type DocumentParams = {
11
+ identity: string;
12
+ accountId?: string;
13
+ };
14
+ /** Pull + decrypt one node-owned document. `encryptor` must be the one built
15
+ * for `collection` — see `ClientSession.collectionEncryptor()`, which is
16
+ * the enforcement point deciding whether the caller even gets one. */
17
+ export declare function pullDocument<T = Record<string, unknown>>(client: StarfishClient, collection: NodeCollectionKey, params: DocumentParams, encryptor: Encryptor): Promise<PulledDocument<T>>;
18
+ /** Encrypt + push one node-owned document. Throws `ConflictError` (from
19
+ * `@drakkar.software/starfish-client`) on a stale `baseHash`. */
20
+ export declare function pushDocument(client: StarfishClient, collection: NodeCollectionKey, params: DocumentParams, data: Record<string, unknown>, baseHash: string | null, encryptor: Encryptor): Promise<{
21
+ hash: string;
22
+ }>;
23
+ /** Append one wire element to an append-only collection (only `actions`
24
+ * today). Each append publishes ONE queue element the node consumes and
25
+ * executes — re-sending an element is re-executing it. */
26
+ export declare function appendElement(client: StarfishClient, collection: NodeCollectionKey, params: DocumentParams, element: Record<string, unknown>, encryptor: Encryptor): Promise<void>;
27
+ //# sourceMappingURL=documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../src/transport/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAA;AAEpE,OAAO,EAA6C,KAAK,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAEhE;uEACuE;AACvE,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE;;uEAEuE;AACvE,wBAAsB,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAU5B;AAED;kEACkE;AAClE,wBAAsB,YAAY,CAChC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAI3B;AAED;;2DAE2D;AAC3D,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -0,0 +1,34 @@
1
+ import { pullPath, pushPath } from '../collections/paths.js';
2
+ import { NODE_COLLECTIONS } from '../collections/nodeCollections.js';
3
+ /** Pull + decrypt one node-owned document. `encryptor` must be the one built
4
+ * for `collection` — see `ClientSession.collectionEncryptor()`, which is
5
+ * the enforcement point deciding whether the caller even gets one. */
6
+ export async function pullDocument(client, collection, params, encryptor) {
7
+ const info = NODE_COLLECTIONS[collection];
8
+ const result = await client.pull(pullPath(info.storagePath, params));
9
+ // No document has ever been pushed for this identity/collection — the node
10
+ // answers 200 with `data: null`-shaped content rather than 404 (`hash` is
11
+ // the existence signal, same as pushDocument's `baseHash`). `encryptor`
12
+ // resolves that to `{}`, which every caller downstream already treats as
13
+ // "no data" (accounts.list()'s `data.accounts ?? []`, parseNodeUserActions).
14
+ const decrypted = await encryptor.decrypt(result.data);
15
+ return { data: decrypted, hash: result.hash };
16
+ }
17
+ /** Encrypt + push one node-owned document. Throws `ConflictError` (from
18
+ * `@drakkar.software/starfish-client`) on a stale `baseHash`. */
19
+ export async function pushDocument(client, collection, params, data, baseHash, encryptor) {
20
+ const info = NODE_COLLECTIONS[collection];
21
+ const encrypted = await encryptor.encrypt(data);
22
+ return client.push(pushPath(info.storagePath, params), encrypted, baseHash);
23
+ }
24
+ /** Append one wire element to an append-only collection (only `actions`
25
+ * today). Each append publishes ONE queue element the node consumes and
26
+ * executes — re-sending an element is re-executing it. */
27
+ export async function appendElement(client, collection, params, element, encryptor) {
28
+ const info = NODE_COLLECTIONS[collection];
29
+ if (!info.appendOnly)
30
+ throw new Error(`${collection} is not an append-only collection`);
31
+ const encrypted = await encryptor.encrypt(element);
32
+ await client.append(pushPath(info.storagePath, params), encrypted);
33
+ }
34
+ //# sourceMappingURL=documents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/transport/documents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAmD,MAAM,mCAAmC,CAAA;AAQrH;;uEAEuE;AACvE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAsB,EACtB,UAA6B,EAC7B,MAAsB,EACtB,SAAoB;IAEpB,MAAM,IAAI,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;IACpE,2EAA2E;IAC3E,0EAA0E;IAC1E,wEAAwE;IACxE,yEAAyE;IACzE,6EAA6E;IAC7E,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,IAA+B,CAAC,CAAA;IACjF,OAAO,EAAE,IAAI,EAAE,SAAc,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;AACpD,CAAC;AAED;kEACkE;AAClE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAsB,EACtB,UAA6B,EAC7B,MAAsB,EACtB,IAA6B,EAC7B,QAAuB,EACvB,SAAoB;IAEpB,MAAM,IAAI,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAA;IACzC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC7E,CAAC;AAED;;2DAE2D;AAC3D,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAsB,EACtB,UAA6B,EAC7B,MAAsB,EACtB,OAAgC,EAChC,SAAoB;IAEpB,MAAM,IAAI,GAAuB,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAC7D,IAAI,CAAC,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,mCAAmC,CAAC,CAAA;IACvF,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAA;AACpE,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { nodeBaseUrl, parseHostInput, formatHostInput, classifyAddressSpace, type NodeEndpoint, type NodeAddressSpace } from './urls.js';
2
+ export { NodeHttpError, nodeRequest, nodeAuthRequest, type NodeCredentials } from './rest.js';
3
+ export { probeStarfishAuth, detectNode, type SyncAuthResult, type NodeProbeResult } from './probe.js';
4
+ export { createSyncClient, createTimeoutFetch } from './syncClient.js';
5
+ export { createRendezvousClient, pullRendezvousDoc, pushRendezvousDoc, clearRendezvousDoc, joinSessionPath, type RendezvousDoc, } from './rendezvous.js';
6
+ export { pullDocument, pushDocument, appendElement, type PulledDocument, type DocumentParams } from './documents.js';
7
+ export { API_PREFIX, DEFAULT_NODE_PORT, EXCHANGES_TIMEOUT_MS, PROBE_TIMEOUT_MS, MARKET_MAKING_TIMEOUT_MS, CREATE_GENERIC_PROCESS_TIMEOUT_MS, NODE_STATUS_PATH, } from './constants.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAA;AACxI,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AACrG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,iCAAiC,EACjC,gBAAgB,GACjB,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,8 @@
1
+ export { nodeBaseUrl, parseHostInput, formatHostInput, classifyAddressSpace } from './urls.js';
2
+ export { NodeHttpError, nodeRequest, nodeAuthRequest } from './rest.js';
3
+ export { probeStarfishAuth, detectNode } from './probe.js';
4
+ export { createSyncClient, createTimeoutFetch } from './syncClient.js';
5
+ export { createRendezvousClient, pullRendezvousDoc, pushRendezvousDoc, clearRendezvousDoc, joinSessionPath, } from './rendezvous.js';
6
+ export { pullDocument, pushDocument, appendElement } from './documents.js';
7
+ export { API_PREFIX, DEFAULT_NODE_PORT, EXCHANGES_TIMEOUT_MS, PROBE_TIMEOUT_MS, MARKET_MAKING_TIMEOUT_MS, CREATE_GENERIC_PROCESS_TIMEOUT_MS, NODE_STATUS_PATH, } from './constants.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAA4C,MAAM,WAAW,CAAA;AACxI,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAwB,MAAM,WAAW,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAA6C,MAAM,YAAY,CAAA;AACrG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAEhB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAA4C,MAAM,gBAAgB,CAAA;AACpH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,iCAAiC,EACjC,gBAAgB,GACjB,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,44 @@
1
+ export type SyncAuthResult = {
2
+ status: 'idle';
3
+ } | {
4
+ status: 'checking';
5
+ } | {
6
+ status: 'authorized';
7
+ } | {
8
+ status: 'unauthorized';
9
+ } | {
10
+ status: 'error';
11
+ detail?: string;
12
+ };
13
+ /**
14
+ * Probe whether a wallet seed is authorized on a sync server. Uses the v3
15
+ * cap-cert auth scheme to pull the user-data collection.
16
+ * 200 → wallet is configured; 401/403 → wallet not allowed; other → error.
17
+ */
18
+ export declare function probeStarfishAuth(baseUrl: string, seed: string, options?: {
19
+ signal?: AbortSignal;
20
+ timeoutMs?: number;
21
+ fetch?: typeof fetch;
22
+ }): Promise<SyncAuthResult>;
23
+ export type NodeProbeResult = {
24
+ status: 'idle';
25
+ } | {
26
+ status: 'probing';
27
+ } | {
28
+ status: 'reachable';
29
+ configured: boolean;
30
+ } | {
31
+ status: 'unreachable';
32
+ reason: 'timeout' | 'refused' | 'invalid-response' | 'http-error';
33
+ detail?: string;
34
+ };
35
+ /** Probe an OctoBot node at the given host:port via GET /api/v1/setup/status.
36
+ * Returns `{ status: 'reachable', configured }` on success.
37
+ * Caller-supplied `signal` is combined with the internal timeout so
38
+ * either can cancel the request (e.g. component unmount or new keystroke). */
39
+ export declare function detectNode(host: string, port: number, secure?: boolean, options?: {
40
+ signal?: AbortSignal;
41
+ timeoutMs?: number;
42
+ fetch?: typeof fetch;
43
+ }): Promise<NodeProbeResult>;
44
+ //# sourceMappingURL=probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../../src/transport/probe.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GACtB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GACtB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,cAAc,CAAA;CAAE,GAC1B;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAMxC;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAE,GAC3E,OAAO,CAAC,cAAc,CAAC,CAsDzB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAC5C;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,kBAAkB,GAAG,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjH;;;+EAG+E;AAC/E,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAE,GAC3E,OAAO,CAAC,eAAe,CAAC,CAsD1B"}
@@ -0,0 +1,121 @@
1
+ import { StarfishClient, StarfishHttpError } from '@drakkar.software/starfish-client';
2
+ import { WalletCapProvider } from '../identity/capProvider.js';
3
+ import { pullPath } from '../collections/paths.js';
4
+ import { SYNC_MOUNT_PATH, SYNC_NAMESPACE, DEFAULT_PROBE_TIMEOUT_MS } from '../crypto/wireConstants.js';
5
+ import { NODE_STATUS_PATH, PROBE_TIMEOUT_MS } from './constants.js';
6
+ function buildSyncBaseUrl(origin) {
7
+ return `${origin.replace(/\/$/, '')}/${SYNC_MOUNT_PATH}`;
8
+ }
9
+ /**
10
+ * Probe whether a wallet seed is authorized on a sync server. Uses the v3
11
+ * cap-cert auth scheme to pull the user-data collection.
12
+ * 200 → wallet is configured; 401/403 → wallet not allowed; other → error.
13
+ */
14
+ export async function probeStarfishAuth(baseUrl, seed, options) {
15
+ let capProvider;
16
+ try {
17
+ capProvider = new WalletCapProvider(seed);
18
+ }
19
+ catch {
20
+ return { status: 'error', detail: 'credential-derivation' };
21
+ }
22
+ let userId;
23
+ try {
24
+ userId = await capProvider.getUserId();
25
+ }
26
+ catch {
27
+ return { status: 'error', detail: 'credential-derivation' };
28
+ }
29
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
30
+ const controller = new AbortController();
31
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
32
+ const callerSignal = options?.signal;
33
+ let callerListener;
34
+ if (callerSignal) {
35
+ callerListener = () => controller.abort();
36
+ callerSignal.addEventListener('abort', callerListener);
37
+ }
38
+ const baseFetch = options?.fetch ?? globalThis.fetch;
39
+ const customFetch = (url, init) => baseFetch(url, { ...init, signal: controller.signal });
40
+ const client = new StarfishClient({
41
+ baseUrl: buildSyncBaseUrl(baseUrl),
42
+ namespace: SYNC_NAMESPACE,
43
+ capProvider,
44
+ fetch: customFetch,
45
+ });
46
+ try {
47
+ await client.pull(pullPath('users/{identity}/data', { identity: userId }));
48
+ clearTimeout(timer);
49
+ return { status: 'authorized' };
50
+ }
51
+ catch (err) {
52
+ clearTimeout(timer);
53
+ if (err instanceof StarfishHttpError) {
54
+ if (err.status === 401 || err.status === 403)
55
+ return { status: 'unauthorized' };
56
+ return { status: 'error', detail: String(err.status) };
57
+ }
58
+ if (controller.signal.aborted) {
59
+ return { status: 'error', detail: callerSignal?.aborted ? 'aborted' : 'timeout' };
60
+ }
61
+ return { status: 'error', detail: err instanceof Error ? err.message : undefined };
62
+ }
63
+ finally {
64
+ if (callerSignal && callerListener)
65
+ callerSignal.removeEventListener('abort', callerListener);
66
+ }
67
+ }
68
+ /** Probe an OctoBot node at the given host:port via GET /api/v1/setup/status.
69
+ * Returns `{ status: 'reachable', configured }` on success.
70
+ * Caller-supplied `signal` is combined with the internal timeout so
71
+ * either can cancel the request (e.g. component unmount or new keystroke). */
72
+ export async function detectNode(host, port, secure, options) {
73
+ const timeoutMs = options?.timeoutMs ?? PROBE_TIMEOUT_MS;
74
+ const url = `${secure ? 'https' : 'http'}://${host}:${port}${NODE_STATUS_PATH}`;
75
+ const baseFetch = options?.fetch ?? globalThis.fetch;
76
+ const internalController = new AbortController();
77
+ const timer = setTimeout(() => internalController.abort(), timeoutMs);
78
+ const callerSignal = options?.signal;
79
+ let callerListener;
80
+ if (callerSignal) {
81
+ callerListener = () => internalController.abort();
82
+ callerSignal.addEventListener('abort', callerListener);
83
+ }
84
+ try {
85
+ const res = await baseFetch(url, { signal: internalController.signal });
86
+ clearTimeout(timer);
87
+ if (!res.ok) {
88
+ return { status: 'unreachable', reason: 'http-error', detail: String(res.status) };
89
+ }
90
+ let json;
91
+ try {
92
+ json = await res.json();
93
+ }
94
+ catch {
95
+ return { status: 'unreachable', reason: 'invalid-response' };
96
+ }
97
+ if (typeof json === 'object' &&
98
+ json !== null &&
99
+ typeof json.configured === 'boolean') {
100
+ const { configured } = json;
101
+ return { status: 'reachable', configured };
102
+ }
103
+ return { status: 'unreachable', reason: 'invalid-response' };
104
+ }
105
+ catch (err) {
106
+ clearTimeout(timer);
107
+ if (internalController.signal.aborted) {
108
+ if (callerSignal?.aborted) {
109
+ return { status: 'idle' };
110
+ }
111
+ return { status: 'unreachable', reason: 'timeout' };
112
+ }
113
+ return { status: 'unreachable', reason: 'refused', detail: err instanceof Error ? err.message : undefined };
114
+ }
115
+ finally {
116
+ if (callerSignal && callerListener) {
117
+ callerSignal.removeEventListener('abort', callerListener);
118
+ }
119
+ }
120
+ }
121
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.js","sourceRoot":"","sources":["../../src/transport/probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACtG,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AASnE,SAAS,gBAAgB,CAAC,MAAc;IACtC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,eAAe,EAAE,CAAA;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAe,EACf,IAAY,EACZ,OAA4E;IAE5E,IAAI,WAA8B,CAAA;IAClC,IAAI,CAAC;QACH,WAAW,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAA;IAC7D,CAAC;IAED,IAAI,MAAc,CAAA;IAClB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,CAAA;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAA;IAC7D,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,wBAAwB,CAAA;IAChE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,MAAM,KA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