@aephia/atlas-kit 0.6.0-next.4 → 0.6.0-next.40

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 (348) hide show
  1. package/README.md +3 -1
  2. package/dist/cargo/actions/deposit.d.ts.map +1 -1
  3. package/dist/cargo/actions/deposit.js +51 -9
  4. package/dist/cargo/actions/deposit.js.map +1 -1
  5. package/dist/cargo/actions/wallet-context.d.ts +2 -3
  6. package/dist/cargo/actions/wallet-context.d.ts.map +1 -1
  7. package/dist/cargo/actions/wallet-context.js +6 -33
  8. package/dist/cargo/actions/wallet-context.js.map +1 -1
  9. package/dist/cargo/actions/wallet-token.d.ts +1 -1
  10. package/dist/cargo/actions/wallet-token.d.ts.map +1 -1
  11. package/dist/cargo/actions/wallet-token.js +1 -9
  12. package/dist/cargo/actions/wallet-token.js.map +1 -1
  13. package/dist/cargo/actions/withdrawal.d.ts.map +1 -1
  14. package/dist/cargo/actions/withdrawal.js +54 -11
  15. package/dist/cargo/actions/withdrawal.js.map +1 -1
  16. package/dist/claim-stakes/actions/index.d.ts.map +1 -1
  17. package/dist/claim-stakes/actions/index.js +2 -3
  18. package/dist/claim-stakes/actions/index.js.map +1 -1
  19. package/dist/client/errors.d.ts +4 -0
  20. package/dist/client/errors.d.ts.map +1 -1
  21. package/dist/client/errors.js +31 -1
  22. package/dist/client/errors.js.map +1 -1
  23. package/dist/client/index.d.ts +1 -0
  24. package/dist/client/index.d.ts.map +1 -1
  25. package/dist/client/index.js +1 -0
  26. package/dist/client/index.js.map +1 -1
  27. package/dist/client/rpc-subscription-provider.d.ts +35 -0
  28. package/dist/client/rpc-subscription-provider.d.ts.map +1 -0
  29. package/dist/client/rpc-subscription-provider.js +190 -0
  30. package/dist/client/rpc-subscription-provider.js.map +1 -0
  31. package/dist/combat/actions/index.d.ts.map +1 -1
  32. package/dist/combat/actions/index.js +19 -8
  33. package/dist/combat/actions/index.js.map +1 -1
  34. package/dist/crafting/actions/index.d.ts.map +1 -1
  35. package/dist/crafting/actions/index.js +36 -13
  36. package/dist/crafting/actions/index.js.map +1 -1
  37. package/dist/crafting/index.d.ts +8 -2
  38. package/dist/crafting/index.d.ts.map +1 -1
  39. package/dist/crafting/index.js +1 -1
  40. package/dist/crafting/index.js.map +1 -1
  41. package/dist/factions/actions/index.d.ts +36 -0
  42. package/dist/factions/actions/index.d.ts.map +1 -0
  43. package/dist/factions/actions/index.js +136 -0
  44. package/dist/factions/actions/index.js.map +1 -0
  45. package/dist/factions/index.d.ts +1 -0
  46. package/dist/factions/index.d.ts.map +1 -1
  47. package/dist/factions/index.js +1 -0
  48. package/dist/factions/index.js.map +1 -1
  49. package/dist/factions/profile-faction.d.ts +58 -0
  50. package/dist/factions/profile-faction.d.ts.map +1 -0
  51. package/dist/factions/profile-faction.js +63 -0
  52. package/dist/factions/profile-faction.js.map +1 -0
  53. package/dist/fleets/actions/add-ship.d.ts +35 -0
  54. package/dist/fleets/actions/add-ship.d.ts.map +1 -0
  55. package/dist/fleets/actions/add-ship.js +149 -0
  56. package/dist/fleets/actions/add-ship.js.map +1 -0
  57. package/dist/fleets/actions/create-fleet.d.ts +36 -0
  58. package/dist/fleets/actions/create-fleet.d.ts.map +1 -0
  59. package/dist/fleets/actions/create-fleet.js +138 -0
  60. package/dist/fleets/actions/create-fleet.js.map +1 -0
  61. package/dist/fleets/actions/index.d.ts +27 -15
  62. package/dist/fleets/actions/index.d.ts.map +1 -1
  63. package/dist/fleets/actions/index.js +95 -52
  64. package/dist/fleets/actions/index.js.map +1 -1
  65. package/dist/fleets/actions/ship-import.d.ts +48 -0
  66. package/dist/fleets/actions/ship-import.d.ts.map +1 -0
  67. package/dist/fleets/actions/ship-import.js +322 -0
  68. package/dist/fleets/actions/ship-import.js.map +1 -0
  69. package/dist/identity/actions/create-profile.d.ts +56 -0
  70. package/dist/identity/actions/create-profile.d.ts.map +1 -0
  71. package/dist/identity/actions/create-profile.js +139 -0
  72. package/dist/identity/actions/create-profile.js.map +1 -0
  73. package/dist/identity/actions/index.d.ts +3 -0
  74. package/dist/identity/actions/index.d.ts.map +1 -1
  75. package/dist/identity/actions/index.js +11 -10
  76. package/dist/identity/actions/index.js.map +1 -1
  77. package/dist/identity/index.d.ts +15 -0
  78. package/dist/identity/index.d.ts.map +1 -1
  79. package/dist/identity/index.js +15 -0
  80. package/dist/identity/index.js.map +1 -1
  81. package/dist/identity/permissions.d.ts +124 -0
  82. package/dist/identity/permissions.d.ts.map +1 -0
  83. package/dist/identity/permissions.js +171 -0
  84. package/dist/identity/permissions.js.map +1 -0
  85. package/dist/internal/c4/cargo-bytes-config.d.ts +7 -0
  86. package/dist/internal/c4/cargo-bytes-config.d.ts.map +1 -0
  87. package/dist/internal/c4/cargo-bytes-config.js +19 -0
  88. package/dist/internal/c4/cargo-bytes-config.js.map +1 -0
  89. package/dist/internal/c4/character-registration.d.ts.map +1 -1
  90. package/dist/internal/c4/character-registration.js +2 -0
  91. package/dist/internal/c4/character-registration.js.map +1 -1
  92. package/dist/internal/c4/claim-stake.d.ts +0 -27
  93. package/dist/internal/c4/claim-stake.d.ts.map +1 -1
  94. package/dist/internal/c4/claim-stake.js +0 -33
  95. package/dist/internal/c4/claim-stake.js.map +1 -1
  96. package/dist/internal/c4/combat.d.ts +0 -27
  97. package/dist/internal/c4/combat.d.ts.map +1 -1
  98. package/dist/internal/c4/combat.js +0 -33
  99. package/dist/internal/c4/combat.js.map +1 -1
  100. package/dist/internal/c4/crafting-process-codec.d.ts +13 -0
  101. package/dist/internal/c4/crafting-process-codec.d.ts.map +1 -0
  102. package/dist/internal/c4/crafting-process-codec.js +34 -0
  103. package/dist/internal/c4/crafting-process-codec.js.map +1 -0
  104. package/dist/internal/c4/crafting.d.ts +10 -31
  105. package/dist/internal/c4/crafting.d.ts.map +1 -1
  106. package/dist/internal/c4/crafting.js +22 -43
  107. package/dist/internal/c4/crafting.js.map +1 -1
  108. package/dist/internal/c4/faction-adapter.d.ts +12 -0
  109. package/dist/internal/c4/faction-adapter.d.ts.map +1 -0
  110. package/dist/internal/c4/faction-adapter.js +52 -0
  111. package/dist/internal/c4/faction-adapter.js.map +1 -0
  112. package/dist/internal/c4/faction-enrollment.d.ts +6 -0
  113. package/dist/internal/c4/faction-enrollment.d.ts.map +1 -0
  114. package/dist/internal/c4/faction-enrollment.js +8 -0
  115. package/dist/internal/c4/faction-enrollment.js.map +1 -0
  116. package/dist/internal/c4/faction-epoch-meter.d.ts +10 -0
  117. package/dist/internal/c4/faction-epoch-meter.d.ts.map +1 -0
  118. package/dist/internal/c4/faction-epoch-meter.js +31 -0
  119. package/dist/internal/c4/faction-epoch-meter.js.map +1 -0
  120. package/dist/internal/c4/faction-treasury.d.ts +23 -0
  121. package/dist/internal/c4/faction-treasury.d.ts.map +1 -0
  122. package/dist/internal/c4/faction-treasury.js +48 -0
  123. package/dist/internal/c4/faction-treasury.js.map +1 -0
  124. package/dist/internal/c4/factions.d.ts +9 -57
  125. package/dist/internal/c4/factions.d.ts.map +1 -1
  126. package/dist/internal/c4/factions.js +21 -139
  127. package/dist/internal/c4/factions.js.map +1 -1
  128. package/dist/internal/c4/fleet-arrival.d.ts +27 -0
  129. package/dist/internal/c4/fleet-arrival.d.ts.map +1 -0
  130. package/dist/internal/c4/fleet-arrival.js +39 -0
  131. package/dist/internal/c4/fleet-arrival.js.map +1 -0
  132. package/dist/internal/c4/fleet-creation.d.ts +7 -0
  133. package/dist/internal/c4/fleet-creation.d.ts.map +1 -0
  134. package/dist/internal/c4/fleet-creation.js +180 -0
  135. package/dist/internal/c4/fleet-creation.js.map +1 -0
  136. package/dist/internal/c4/fleet-crew-binding.d.ts +9 -0
  137. package/dist/internal/c4/fleet-crew-binding.d.ts.map +1 -1
  138. package/dist/internal/c4/fleet-crew-binding.js +15 -0
  139. package/dist/internal/c4/fleet-crew-binding.js.map +1 -1
  140. package/dist/internal/c4/fleet-ship-assembly.d.ts +11 -0
  141. package/dist/internal/c4/fleet-ship-assembly.d.ts.map +1 -0
  142. package/dist/internal/c4/fleet-ship-assembly.js +44 -0
  143. package/dist/internal/c4/fleet-ship-assembly.js.map +1 -0
  144. package/dist/internal/c4/fleet.d.ts +10 -5
  145. package/dist/internal/c4/fleet.d.ts.map +1 -1
  146. package/dist/internal/c4/fleet.js.map +1 -1
  147. package/dist/internal/c4/game.d.ts +20 -6
  148. package/dist/internal/c4/game.d.ts.map +1 -1
  149. package/dist/internal/c4/game.js +39 -9
  150. package/dist/internal/c4/game.js.map +1 -1
  151. package/dist/internal/c4/identity.d.ts +2 -7
  152. package/dist/internal/c4/identity.d.ts.map +1 -1
  153. package/dist/internal/c4/identity.js +2 -23
  154. package/dist/internal/c4/identity.js.map +1 -1
  155. package/dist/internal/c4/legacy-cargo-config.d.ts +6 -0
  156. package/dist/internal/c4/legacy-cargo-config.d.ts.map +1 -0
  157. package/dist/internal/c4/legacy-cargo-config.js +26 -0
  158. package/dist/internal/c4/legacy-cargo-config.js.map +1 -0
  159. package/dist/internal/c4/loyalty.d.ts +0 -27
  160. package/dist/internal/c4/loyalty.d.ts.map +1 -1
  161. package/dist/internal/c4/loyalty.js +0 -33
  162. package/dist/internal/c4/loyalty.js.map +1 -1
  163. package/dist/internal/c4/market.d.ts +1 -37
  164. package/dist/internal/c4/market.d.ts.map +1 -1
  165. package/dist/internal/c4/market.js +11 -49
  166. package/dist/internal/c4/market.js.map +1 -1
  167. package/dist/internal/c4/mining-instructions.d.ts +2 -0
  168. package/dist/internal/c4/mining-instructions.d.ts.map +1 -0
  169. package/dist/internal/c4/mining-instructions.js +3 -0
  170. package/dist/internal/c4/mining-instructions.js.map +1 -0
  171. package/dist/internal/c4/profile-creation.d.ts +17 -0
  172. package/dist/internal/c4/profile-creation.d.ts.map +1 -0
  173. package/dist/internal/c4/profile-creation.js +36 -0
  174. package/dist/internal/c4/profile-creation.js.map +1 -0
  175. package/dist/internal/c4/profile-faction.d.ts.map +1 -1
  176. package/dist/internal/c4/profile-faction.js +2 -0
  177. package/dist/internal/c4/profile-faction.js.map +1 -1
  178. package/dist/internal/c4/profile-permissions.d.ts +14 -0
  179. package/dist/internal/c4/profile-permissions.d.ts.map +1 -0
  180. package/dist/internal/c4/profile-permissions.js +81 -0
  181. package/dist/internal/c4/profile-permissions.js.map +1 -0
  182. package/dist/internal/c4/rewards.d.ts +0 -27
  183. package/dist/internal/c4/rewards.d.ts.map +1 -1
  184. package/dist/internal/c4/rewards.js +0 -33
  185. package/dist/internal/c4/rewards.js.map +1 -1
  186. package/dist/internal/c4/runtime-bindings.d.ts +3 -0
  187. package/dist/internal/c4/runtime-bindings.d.ts.map +1 -0
  188. package/dist/internal/c4/runtime-bindings.js +4 -0
  189. package/dist/internal/c4/runtime-bindings.js.map +1 -0
  190. package/dist/internal/c4/scanning.d.ts +1 -28
  191. package/dist/internal/c4/scanning.d.ts.map +1 -1
  192. package/dist/internal/c4/scanning.js +2 -33
  193. package/dist/internal/c4/scanning.js.map +1 -1
  194. package/dist/internal/c4/ship-import.d.ts +4 -0
  195. package/dist/internal/c4/ship-import.d.ts.map +1 -0
  196. package/dist/internal/c4/ship-import.js +13 -0
  197. package/dist/internal/c4/ship-import.js.map +1 -0
  198. package/dist/internal/c4/ship-stats.d.ts.map +1 -1
  199. package/dist/internal/c4/ship-stats.js +11 -7
  200. package/dist/internal/c4/ship-stats.js.map +1 -1
  201. package/dist/internal/c4/starbase.d.ts +0 -32
  202. package/dist/internal/c4/starbase.d.ts.map +1 -1
  203. package/dist/internal/c4/starbase.js +3 -41
  204. package/dist/internal/c4/starbase.js.map +1 -1
  205. package/dist/internal/c4/wallet-cargo-cache.d.ts +3 -0
  206. package/dist/internal/c4/wallet-cargo-cache.d.ts.map +1 -0
  207. package/dist/internal/c4/wallet-cargo-cache.js +24 -0
  208. package/dist/internal/c4/wallet-cargo-cache.js.map +1 -0
  209. package/dist/internal/c4/world.js +2 -1
  210. package/dist/internal/c4/world.js.map +1 -1
  211. package/dist/internal/fleet.d.ts.map +1 -1
  212. package/dist/internal/fleet.js +3 -1
  213. package/dist/internal/fleet.js.map +1 -1
  214. package/dist/internal/loyalty-atlas-bank-state.d.ts +16 -0
  215. package/dist/internal/loyalty-atlas-bank-state.d.ts.map +1 -0
  216. package/dist/internal/loyalty-atlas-bank-state.js +10 -0
  217. package/dist/internal/loyalty-atlas-bank-state.js.map +1 -0
  218. package/dist/internal/planning/account-state.d.ts +4 -0
  219. package/dist/internal/planning/account-state.d.ts.map +1 -0
  220. package/dist/internal/planning/account-state.js +11 -0
  221. package/dist/internal/planning/account-state.js.map +1 -0
  222. package/dist/internal/planning/action-runtime.d.ts +38 -0
  223. package/dist/internal/planning/action-runtime.d.ts.map +1 -0
  224. package/dist/internal/planning/action-runtime.js +63 -0
  225. package/dist/internal/planning/action-runtime.js.map +1 -0
  226. package/dist/internal/planning/arrival-guards.d.ts +20 -0
  227. package/dist/internal/planning/arrival-guards.d.ts.map +1 -0
  228. package/dist/internal/planning/arrival-guards.js +231 -0
  229. package/dist/internal/planning/arrival-guards.js.map +1 -0
  230. package/dist/internal/planning/authorization-adapter.d.ts +19 -0
  231. package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
  232. package/dist/internal/planning/authorization-adapter.js +99 -0
  233. package/dist/internal/planning/authorization-adapter.js.map +1 -1
  234. package/dist/internal/planning/democracy-history.d.ts +50 -0
  235. package/dist/internal/planning/democracy-history.d.ts.map +1 -0
  236. package/dist/internal/planning/democracy-history.js +198 -0
  237. package/dist/internal/planning/democracy-history.js.map +1 -0
  238. package/dist/internal/planning/faction-enrollment.d.ts +12 -0
  239. package/dist/internal/planning/faction-enrollment.d.ts.map +1 -0
  240. package/dist/internal/planning/faction-enrollment.js +67 -0
  241. package/dist/internal/planning/faction-enrollment.js.map +1 -0
  242. package/dist/internal/planning/faction-trade-guards.d.ts +30 -0
  243. package/dist/internal/planning/faction-trade-guards.d.ts.map +1 -0
  244. package/dist/internal/planning/faction-trade-guards.js +18 -0
  245. package/dist/internal/planning/faction-trade-guards.js.map +1 -0
  246. package/dist/internal/planning/faction-trade-state.d.ts +16 -0
  247. package/dist/internal/planning/faction-trade-state.d.ts.map +1 -0
  248. package/dist/internal/planning/faction-trade-state.js +43 -0
  249. package/dist/internal/planning/faction-trade-state.js.map +1 -0
  250. package/dist/internal/planning/fleet-arrival.d.ts +49 -0
  251. package/dist/internal/planning/fleet-arrival.d.ts.map +1 -0
  252. package/dist/internal/planning/fleet-arrival.js +135 -0
  253. package/dist/internal/planning/fleet-arrival.js.map +1 -0
  254. package/dist/internal/planning/fleet-creation.d.ts +30 -0
  255. package/dist/internal/planning/fleet-creation.d.ts.map +1 -0
  256. package/dist/internal/planning/fleet-creation.js +107 -0
  257. package/dist/internal/planning/fleet-creation.js.map +1 -0
  258. package/dist/internal/planning/fleet-ship-assembly.d.ts +36 -0
  259. package/dist/internal/planning/fleet-ship-assembly.d.ts.map +1 -0
  260. package/dist/internal/planning/fleet-ship-assembly.js +136 -0
  261. package/dist/internal/planning/fleet-ship-assembly.js.map +1 -0
  262. package/dist/internal/planning/governance-fees.d.ts +64 -0
  263. package/dist/internal/planning/governance-fees.d.ts.map +1 -0
  264. package/dist/internal/planning/governance-fees.js +239 -0
  265. package/dist/internal/planning/governance-fees.js.map +1 -0
  266. package/dist/internal/planning/mining-stop.d.ts +14 -0
  267. package/dist/internal/planning/mining-stop.d.ts.map +1 -0
  268. package/dist/internal/planning/mining-stop.js +41 -0
  269. package/dist/internal/planning/mining-stop.js.map +1 -0
  270. package/dist/internal/planning/runtime-guards.d.ts +43 -0
  271. package/dist/internal/planning/runtime-guards.d.ts.map +1 -0
  272. package/dist/internal/planning/runtime-guards.js +552 -0
  273. package/dist/internal/planning/runtime-guards.js.map +1 -0
  274. package/dist/internal/planning/ship-import-funding.d.ts +22 -0
  275. package/dist/internal/planning/ship-import-funding.d.ts.map +1 -0
  276. package/dist/internal/planning/ship-import-funding.js +52 -0
  277. package/dist/internal/planning/ship-import-funding.js.map +1 -0
  278. package/dist/internal/planning/ship-token.d.ts +10 -0
  279. package/dist/internal/planning/ship-token.d.ts.map +1 -0
  280. package/dist/internal/planning/ship-token.js +47 -0
  281. package/dist/internal/planning/ship-token.js.map +1 -0
  282. package/dist/internal/planning/token-mint.d.ts +4 -0
  283. package/dist/internal/planning/token-mint.d.ts.map +1 -0
  284. package/dist/internal/planning/token-mint.js +15 -0
  285. package/dist/internal/planning/token-mint.js.map +1 -0
  286. package/dist/internal/planning/trade-faction-market.d.ts +20 -0
  287. package/dist/internal/planning/trade-faction-market.d.ts.map +1 -0
  288. package/dist/internal/planning/trade-faction-market.js +56 -0
  289. package/dist/internal/planning/trade-faction-market.js.map +1 -0
  290. package/dist/internal/planning/xp-runtime.d.ts +20 -0
  291. package/dist/internal/planning/xp-runtime.d.ts.map +1 -0
  292. package/dist/internal/planning/xp-runtime.js +96 -0
  293. package/dist/internal/planning/xp-runtime.js.map +1 -0
  294. package/dist/loyalty/actions/index.d.ts.map +1 -1
  295. package/dist/loyalty/actions/index.js +4 -3
  296. package/dist/loyalty/actions/index.js.map +1 -1
  297. package/dist/loyalty/index.d.ts.map +1 -1
  298. package/dist/loyalty/index.js +2 -6
  299. package/dist/loyalty/index.js.map +1 -1
  300. package/dist/markets/actions/index.d.ts +1 -0
  301. package/dist/markets/actions/index.d.ts.map +1 -1
  302. package/dist/markets/actions/index.js +42 -16
  303. package/dist/markets/actions/index.js.map +1 -1
  304. package/dist/markets/actions/trade-faction-market.d.ts +43 -0
  305. package/dist/markets/actions/trade-faction-market.d.ts.map +1 -0
  306. package/dist/markets/actions/trade-faction-market.js +291 -0
  307. package/dist/markets/actions/trade-faction-market.js.map +1 -0
  308. package/dist/mining/actions/index.d.ts +87 -0
  309. package/dist/mining/actions/index.d.ts.map +1 -0
  310. package/dist/mining/actions/index.js +317 -0
  311. package/dist/mining/actions/index.js.map +1 -0
  312. package/dist/planning/assembly.d.ts.map +1 -1
  313. package/dist/planning/assembly.js +6 -0
  314. package/dist/planning/assembly.js.map +1 -1
  315. package/dist/planning/execution.d.ts.map +1 -1
  316. package/dist/planning/execution.js +294 -17
  317. package/dist/planning/execution.js.map +1 -1
  318. package/dist/planning/index.d.ts +465 -5
  319. package/dist/planning/index.d.ts.map +1 -1
  320. package/dist/planning/index.js +649 -14
  321. package/dist/planning/index.js.map +1 -1
  322. package/dist/planning/simulation.d.ts +18 -1
  323. package/dist/planning/simulation.d.ts.map +1 -1
  324. package/dist/planning/simulation.js +56 -10
  325. package/dist/planning/simulation.js.map +1 -1
  326. package/dist/registry/cargo.d.ts +9 -6
  327. package/dist/registry/cargo.d.ts.map +1 -1
  328. package/dist/registry/cargo.js +30 -4
  329. package/dist/registry/cargo.js.map +1 -1
  330. package/dist/registry/onboarding.d.ts +2 -0
  331. package/dist/registry/onboarding.d.ts.map +1 -1
  332. package/dist/registry/onboarding.js +11 -6
  333. package/dist/registry/onboarding.js.map +1 -1
  334. package/dist/registry/ship-stats-snapshot.js +5 -5
  335. package/dist/registry/ship-stats-snapshot.js.map +1 -1
  336. package/dist/registry/ships.d.ts +28 -0
  337. package/dist/registry/ships.d.ts.map +1 -0
  338. package/dist/registry/ships.js +51 -0
  339. package/dist/registry/ships.js.map +1 -0
  340. package/dist/registry/xp-runtime.d.ts +4 -0
  341. package/dist/registry/xp-runtime.d.ts.map +1 -0
  342. package/dist/registry/xp-runtime.js +14 -0
  343. package/dist/registry/xp-runtime.js.map +1 -0
  344. package/dist/scanning/index.d.ts +1 -1
  345. package/dist/scanning/index.d.ts.map +1 -1
  346. package/dist/scanning/index.js +2 -2
  347. package/dist/scanning/index.js.map +1 -1
  348. package/package.json +10 -2
@@ -1,6 +1,10 @@
1
+ import { normalizeArrivalGuard, arrivalGuardToJSON, validateArrivalInstructions, } from '../internal/planning/arrival-guards.js';
2
+ import { isRuntimeGuard, normalizeRuntimeGuard, runtimeGuardToJSON, validateRuntimeInstructions, } from '../internal/planning/runtime-guards.js';
3
+ import { isTradeBuyGuard, isTradeSellGuard, isTradeMeterGuard, isFactionTradeGuard, } from '../internal/planning/faction-trade-guards.js';
1
4
  import { AccountRole, getBase64Decoder, getBase64Encoder, isAddress, isWritableRole, } from '@solana/kit';
2
- import { InvalidActionInputError } from '../client/errors.js';
5
+ import { InvalidActionInputError, SageSdkError } from '../client/errors.js';
3
6
  import { deepFreeze } from '../internal/immutable-tree.js';
7
+ import { validateMiningStopInstructions } from '../internal/planning/mining-stop.js';
4
8
  import { validatePlanComposition } from './composition.js';
5
9
  import { isPlanInstance, registerPlanInstance } from './plan-instances.js';
6
10
  const PLAN_BRAND = Symbol('AephiaSagePlan');
@@ -159,9 +163,333 @@ function normalizeSemanticFact(value, field) {
159
163
  }
160
164
  return invalid(`${field}.kind`, semantic.kind, 'one of exclusive, requires, invalidates, or transition');
161
165
  }
162
- function normalizePrecondition(value, field, version = 3) {
166
+ function normalizePrecondition(value, field, version = 17) {
163
167
  const precondition = readRecord(value, field);
164
- if (precondition.kind === 'token-account-or-absent' && version === 3) {
168
+ if (version >= 17 && precondition.kind === 'fleet-arrival')
169
+ return normalizeArrivalGuard(precondition, field);
170
+ if (version >= 16 && isRuntimeGuard(precondition))
171
+ return normalizeRuntimeGuard(precondition, field);
172
+ if (version >= 15 && precondition.kind === 'ship-import-funding') {
173
+ assertKeys(precondition, field, [
174
+ 'kind',
175
+ 'address',
176
+ 'game',
177
+ 'profile',
178
+ 'system',
179
+ 'shipId',
180
+ 'maximumProfileDebit',
181
+ 'describes',
182
+ ]);
183
+ const shipId = precondition.shipId;
184
+ if (typeof shipId !== 'number' ||
185
+ !Number.isInteger(shipId) ||
186
+ shipId < 0 ||
187
+ shipId > 65535)
188
+ invalid(`${field}.shipId`, shipId, 'an unsigned u16 ship configuration ID');
189
+ const maximumProfileDebit = precondition.maximumProfileDebit;
190
+ if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
191
+ invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
192
+ return Object.freeze({
193
+ kind: 'ship-import-funding',
194
+ address: readAddress(precondition.address, `${field}.address`),
195
+ game: readAddress(precondition.game, `${field}.game`),
196
+ profile: readAddress(precondition.profile, `${field}.profile`),
197
+ system: readAddress(precondition.system, `${field}.system`),
198
+ shipId,
199
+ maximumProfileDebit,
200
+ describes: readString(precondition.describes, `${field}.describes`),
201
+ });
202
+ }
203
+ if (version >= 13 && precondition.kind === 'fleet-mining') {
204
+ assertKeys(precondition, field, [
205
+ 'kind',
206
+ 'address',
207
+ 'game',
208
+ 'profile',
209
+ 'asteroid',
210
+ 'describes',
211
+ ]);
212
+ return Object.freeze({
213
+ kind: 'fleet-mining',
214
+ address: readAddress(precondition.address, `${field}.address`),
215
+ game: readAddress(precondition.game, `${field}.game`),
216
+ profile: readAddress(precondition.profile, `${field}.profile`),
217
+ asteroid: readAddress(precondition.asteroid, `${field}.asteroid`),
218
+ describes: readString(precondition.describes, `${field}.describes`),
219
+ });
220
+ }
221
+ if (version >= 12 &&
222
+ isFactionTradeGuard(precondition) &&
223
+ (version >= 14 || !precondition.kind.endsWith('-versioned'))) {
224
+ const kind = precondition.kind;
225
+ const versioned = kind.endsWith('-versioned');
226
+ assertKeys(precondition, field, [
227
+ 'kind',
228
+ 'address',
229
+ 'game',
230
+ 'factionId',
231
+ 'describes',
232
+ ...(versioned ? ['schemaVersion'] : []),
233
+ ...(isTradeBuyGuard(precondition)
234
+ ? ['cargoId', 'floorRaw']
235
+ : isTradeSellGuard(precondition)
236
+ ? ['atlasOutCapPerEpochRaw', 'epochLengthSeconds']
237
+ : []),
238
+ ]);
239
+ const unsigned = (key, max = 65535) => {
240
+ const n = precondition[key];
241
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 0 || n > max)
242
+ invalid(`${field}.${key}`, n, `an unsigned ${max === 255 ? 'u8' : 'u16'} integer`);
243
+ return n;
244
+ };
245
+ const integer = (key, signed = false) => {
246
+ const n = precondition[key];
247
+ const min = signed ? -(1n << 63n) : 0n;
248
+ const max = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
249
+ if (typeof n !== 'bigint' || n < min || n > max)
250
+ invalid(`${field}.${key}`, n, signed ? 'an i64 bigint' : 'a u64 bigint');
251
+ return n;
252
+ };
253
+ const common = {
254
+ address: readAddress(precondition.address, `${field}.address`),
255
+ game: readAddress(precondition.game, `${field}.game`),
256
+ factionId: unsigned('factionId'),
257
+ ...(versioned ? { schemaVersion: unsigned('schemaVersion', 255) } : {}),
258
+ describes: readString(precondition.describes, `${field}.describes`),
259
+ };
260
+ if (isTradeBuyGuard(precondition))
261
+ return Object.freeze({
262
+ kind,
263
+ ...common,
264
+ cargoId: unsigned('cargoId'),
265
+ floorRaw: integer('floorRaw'),
266
+ });
267
+ if (isTradeSellGuard(precondition))
268
+ return Object.freeze({
269
+ kind,
270
+ ...common,
271
+ atlasOutCapPerEpochRaw: integer('atlasOutCapPerEpochRaw'),
272
+ epochLengthSeconds: integer('epochLengthSeconds', true),
273
+ });
274
+ return Object.freeze({ kind, ...common });
275
+ }
276
+ if (version >= 11 && precondition.kind === 'fleet-add-ship') {
277
+ assertKeys(precondition, field, [
278
+ 'kind',
279
+ 'address',
280
+ 'game',
281
+ 'profile',
282
+ 'authority',
283
+ 'system',
284
+ 'shipId',
285
+ 'amount',
286
+ 'keyIndex',
287
+ 'configHash',
288
+ 'maximumProfileDebit',
289
+ 'describes',
290
+ ]);
291
+ const keyIndex = precondition.keyIndex;
292
+ if (typeof keyIndex !== 'number' ||
293
+ !Number.isInteger(keyIndex) ||
294
+ keyIndex < 0 ||
295
+ keyIndex > 65535)
296
+ invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
297
+ const shipId = precondition.shipId;
298
+ if (typeof shipId !== 'number' ||
299
+ !Number.isInteger(shipId) ||
300
+ shipId < 0 ||
301
+ shipId > 65535)
302
+ invalid(`${field}.shipId`, shipId, 'a u16 ship configuration ID');
303
+ const amount = precondition.amount;
304
+ if (typeof amount !== 'bigint' || amount < 1n || amount > 255n)
305
+ invalid(`${field}.amount`, amount, 'a whole ship quantity from 1n through 255n');
306
+ const maximumProfileDebit = precondition.maximumProfileDebit;
307
+ if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
308
+ invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
309
+ return Object.freeze({
310
+ kind: 'fleet-add-ship',
311
+ address: readAddress(precondition.address, `${field}.address`),
312
+ game: readAddress(precondition.game, `${field}.game`),
313
+ profile: readAddress(precondition.profile, `${field}.profile`),
314
+ authority: readAddress(precondition.authority, `${field}.authority`),
315
+ system: readAddress(precondition.system, `${field}.system`),
316
+ keyIndex,
317
+ shipId,
318
+ amount,
319
+ maximumProfileDebit,
320
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
321
+ describes: readString(precondition.describes, `${field}.describes`),
322
+ });
323
+ }
324
+ if (version >= 10 && precondition.kind === 'fleet-create') {
325
+ assertKeys(precondition, field, [
326
+ 'kind',
327
+ 'address',
328
+ 'game',
329
+ 'profile',
330
+ 'authority',
331
+ 'system',
332
+ 'keyIndex',
333
+ 'label',
334
+ 'maximumProfileDebit',
335
+ 'describes',
336
+ ]);
337
+ const keyIndex = precondition.keyIndex;
338
+ if (typeof keyIndex !== 'number' ||
339
+ !Number.isSafeInteger(keyIndex) ||
340
+ keyIndex < 0 ||
341
+ keyIndex > 65_535)
342
+ invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
343
+ const label = readString(precondition.label, `${field}.label`);
344
+ const bytes = new TextEncoder().encode(label);
345
+ if (label.trim().length === 0 ||
346
+ label.includes('\0') ||
347
+ bytes.length > 64 ||
348
+ new TextDecoder('utf-8', { ignoreBOM: true }).decode(bytes) !== label)
349
+ invalid(`${field}.label`, label, 'a nonblank, NUL-free Unicode label of at most 64 UTF-8 bytes');
350
+ const maximumProfileDebit = precondition.maximumProfileDebit;
351
+ if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
352
+ invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
353
+ return Object.freeze({
354
+ kind: 'fleet-create',
355
+ address: readAddress(precondition.address, `${field}.address`),
356
+ game: readAddress(precondition.game, `${field}.game`),
357
+ profile: readAddress(precondition.profile, `${field}.profile`),
358
+ authority: readAddress(precondition.authority, `${field}.authority`),
359
+ system: readAddress(precondition.system, `${field}.system`),
360
+ keyIndex,
361
+ label,
362
+ maximumProfileDebit,
363
+ describes: readString(precondition.describes, `${field}.describes`),
364
+ });
365
+ }
366
+ if (version >= 8 && precondition.kind === 'system-account-or-absent') {
367
+ assertKeys(precondition, field, ['kind', 'address', 'describes']);
368
+ return Object.freeze({
369
+ kind: 'system-account-or-absent',
370
+ address: readAddress(precondition.address, `${field}.address`),
371
+ describes: readString(precondition.describes, `${field}.describes`),
372
+ });
373
+ }
374
+ if (version >= 7 && precondition.kind === 'token-mint') {
375
+ assertKeys(precondition, field, [
376
+ 'kind',
377
+ 'address',
378
+ 'decimals',
379
+ 'describes',
380
+ ]);
381
+ const decimals = precondition.decimals;
382
+ if (typeof decimals !== 'number' ||
383
+ !Number.isInteger(decimals) ||
384
+ decimals < 0 ||
385
+ decimals > 255)
386
+ invalid(`${field}.decimals`, decimals, 'an unsigned u8 mint decimals value');
387
+ return Object.freeze({
388
+ kind: 'token-mint',
389
+ address: readAddress(precondition.address, `${field}.address`),
390
+ decimals,
391
+ describes: readString(precondition.describes, `${field}.describes`),
392
+ });
393
+ }
394
+ if (version >= 6 && precondition.kind === 'game-ship-config') {
395
+ assertKeys(precondition, field, [
396
+ 'kind',
397
+ 'address',
398
+ 'shipId',
399
+ 'configHash',
400
+ 'describes',
401
+ ]);
402
+ const id = precondition.shipId;
403
+ if (typeof id !== 'number' || !Number.isInteger(id) || id < 0 || id > 65535)
404
+ invalid(`${field}.shipId`, id, 'a u16 ship configuration ID');
405
+ return Object.freeze({
406
+ kind: 'game-ship-config',
407
+ address: readAddress(precondition.address, `${field}.address`),
408
+ shipId: id,
409
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
410
+ describes: readString(precondition.describes, `${field}.describes`),
411
+ });
412
+ }
413
+ if (version >= 5 && precondition.kind === 'game-account') {
414
+ assertKeys(precondition, field, ['kind', 'address', 'describes']);
415
+ return Object.freeze({
416
+ kind: 'game-account',
417
+ address: readAddress(precondition.address, `${field}.address`),
418
+ describes: readString(precondition.describes, `${field}.describes`),
419
+ });
420
+ }
421
+ if ((version >= 9 && precondition.kind === 'game-cargo-bytes-config') ||
422
+ (version >= 4 &&
423
+ ['token-account', 'game-cargo-config', 'cargo-cache'].includes(String(precondition.kind)))) {
424
+ const base = {
425
+ address: readAddress(precondition.address, `${field}.address`),
426
+ describes: readString(precondition.describes, `${field}.describes`),
427
+ };
428
+ if (precondition.kind === 'token-account') {
429
+ assertKeys(precondition, field, [
430
+ 'kind',
431
+ 'address',
432
+ 'mint',
433
+ 'owner',
434
+ 'minimumBalance',
435
+ 'describes',
436
+ ]);
437
+ const amount = precondition.minimumBalance;
438
+ if (typeof amount !== 'bigint' ||
439
+ amount < 0n ||
440
+ amount > (1n << 64n) - 1n)
441
+ invalid(`${field}.minimumBalance`, amount, 'an unsigned u64 bigint');
442
+ return Object.freeze({
443
+ ...base,
444
+ kind: 'token-account',
445
+ mint: readAddress(precondition.mint, `${field}.mint`),
446
+ owner: readAddress(precondition.owner, `${field}.owner`),
447
+ minimumBalance: amount,
448
+ });
449
+ }
450
+ if (precondition.kind === 'game-cargo-config' ||
451
+ precondition.kind === 'game-cargo-bytes-config') {
452
+ assertKeys(precondition, field, [
453
+ 'kind',
454
+ 'address',
455
+ 'cargoId',
456
+ 'configHash',
457
+ 'describes',
458
+ ]);
459
+ const id = precondition.cargoId;
460
+ if (typeof id !== 'number' ||
461
+ !Number.isInteger(id) ||
462
+ id < 0 ||
463
+ id > 65535)
464
+ invalid(`${field}.cargoId`, id, 'a u16 cargo ID');
465
+ return Object.freeze({
466
+ ...base,
467
+ kind: precondition.kind,
468
+ cargoId: id,
469
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
470
+ });
471
+ }
472
+ assertKeys(precondition, field, [
473
+ 'kind',
474
+ 'address',
475
+ 'game',
476
+ 'bump',
477
+ 'describes',
478
+ ]);
479
+ const bump = precondition.bump;
480
+ if (typeof bump !== 'number' ||
481
+ !Number.isInteger(bump) ||
482
+ bump < 0 ||
483
+ bump > 255)
484
+ invalid(`${field}.bump`, bump, 'a u8 PDA bump');
485
+ return Object.freeze({
486
+ ...base,
487
+ kind: 'cargo-cache',
488
+ game: readAddress(precondition.game, `${field}.game`),
489
+ bump,
490
+ });
491
+ }
492
+ if (precondition.kind === 'token-account-or-absent' && version >= 3) {
165
493
  assertKeys(precondition, field, [
166
494
  'kind',
167
495
  'address',
@@ -186,11 +514,45 @@ function normalizePrecondition(value, field, version = 3) {
186
514
  });
187
515
  }
188
516
  if (precondition.kind !== 'account-state') {
189
- invalid(`${field}.kind`, precondition.kind, version === 3
190
- ? 'one of account-state, account-absent, or token-account-or-absent'
191
- : version === 2
192
- ? 'one of account-state or account-absent'
193
- : 'the value account-state');
517
+ invalid(`${field}.kind`, precondition.kind, version === 1
518
+ ? 'the value account-state'
519
+ : `one of ${[
520
+ ...(version >= 17 ? ['fleet-arrival'] : []),
521
+ ...(version >= 16
522
+ ? ['democracy-history', 'xp-runtime', 'governance-fees']
523
+ : []),
524
+ ...(version >= 15 ? ['ship-import-funding'] : []),
525
+ ...(version >= 14
526
+ ? [
527
+ 'faction-treasury-buy-versioned',
528
+ 'faction-treasury-sell-versioned',
529
+ 'faction-epoch-meter-versioned',
530
+ ]
531
+ : []),
532
+ ...(version >= 13 ? ['fleet-mining'] : []),
533
+ ...(version >= 12
534
+ ? [
535
+ 'faction-treasury-buy',
536
+ 'faction-treasury-sell',
537
+ 'faction-epoch-meter',
538
+ ]
539
+ : []),
540
+ ...(version >= 11 ? ['fleet-add-ship'] : []),
541
+ ...(version >= 10 ? ['fleet-create'] : []),
542
+ 'account-state',
543
+ 'account-absent',
544
+ ...(version >= 8 ? ['system-account-or-absent'] : []),
545
+ ...(version >= 3 ? ['token-account-or-absent'] : []),
546
+ ...(version >= 4 ? ['token-account'] : []),
547
+ ...(version >= 7 ? ['token-mint'] : []),
548
+ ...(version >= 4 ? ['game-cargo-config'] : []),
549
+ ...(version >= 9 ? ['game-cargo-bytes-config'] : []),
550
+ ...(version >= 4 ? ['cargo-cache'] : []),
551
+ ...(version >= 5 ? ['game-account'] : []),
552
+ ...(version >= 6 ? ['game-ship-config'] : []),
553
+ ]
554
+ .join(', ')
555
+ .replace(/, ([^,]+)$/u, version === 2 ? ' or $1' : ', or $1')}`);
194
556
  }
195
557
  assertKeys(precondition, field, ['kind', 'address', 'dataHash', 'describes']);
196
558
  return Object.freeze({
@@ -242,12 +604,163 @@ function planToJSON(plan) {
242
604
  : {}),
243
605
  signers: [...step.signers],
244
606
  }));
607
+ const hasArrivalGuard = plan.preconditions.some(({ kind }) => kind === 'fleet-arrival');
608
+ const hasRuntimeGuard = plan.preconditions.some(isRuntimeGuard);
609
+ const hasShipImportFunding = plan.preconditions.some(({ kind }) => kind === 'ship-import-funding');
610
+ const hasMiningGuard = plan.preconditions.some(({ kind }) => kind === 'fleet-mining');
611
+ if (hasArrivalGuard ||
612
+ hasRuntimeGuard ||
613
+ hasShipImportFunding ||
614
+ hasMiningGuard ||
615
+ plan.preconditions.some(isFactionTradeGuard)) {
616
+ return deepFreeze({
617
+ v: hasArrivalGuard
618
+ ? 17
619
+ : hasRuntimeGuard
620
+ ? 16
621
+ : hasShipImportFunding
622
+ ? 15
623
+ : plan.preconditions.some((guard) => 'schemaVersion' in guard)
624
+ ? 14
625
+ : hasMiningGuard
626
+ ? 13
627
+ : 12,
628
+ ...common,
629
+ steps,
630
+ preconditions: plan.preconditions.map((guard) => {
631
+ if (guard.kind === 'fleet-arrival')
632
+ return arrivalGuardToJSON(guard);
633
+ if (isRuntimeGuard(guard))
634
+ return runtimeGuardToJSON(guard);
635
+ if (isTradeBuyGuard(guard))
636
+ return { ...guard, floorRaw: String(guard.floorRaw) };
637
+ if (isTradeSellGuard(guard))
638
+ return {
639
+ ...guard,
640
+ atlasOutCapPerEpochRaw: String(guard.atlasOutCapPerEpochRaw),
641
+ epochLengthSeconds: String(guard.epochLengthSeconds),
642
+ };
643
+ if (guard.kind === 'fleet-add-ship')
644
+ return {
645
+ ...guard,
646
+ amount: String(guard.amount),
647
+ maximumProfileDebit: String(guard.maximumProfileDebit),
648
+ };
649
+ if (guard.kind === 'fleet-create' ||
650
+ guard.kind === 'ship-import-funding')
651
+ return {
652
+ ...guard,
653
+ maximumProfileDebit: String(guard.maximumProfileDebit),
654
+ };
655
+ if (guard.kind === 'token-account')
656
+ return { ...guard, minimumBalance: String(guard.minimumBalance) };
657
+ return { ...guard };
658
+ }),
659
+ });
660
+ }
661
+ if (plan.preconditions.some(({ kind }) => kind === 'fleet-add-ship')) {
662
+ return deepFreeze({
663
+ v: 11,
664
+ ...common,
665
+ steps,
666
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'fleet-add-ship'
667
+ ? {
668
+ ...guard,
669
+ amount: String(guard.amount),
670
+ maximumProfileDebit: String(guard.maximumProfileDebit),
671
+ }
672
+ : guard.kind === 'fleet-create'
673
+ ? {
674
+ ...guard,
675
+ maximumProfileDebit: String(guard.maximumProfileDebit),
676
+ }
677
+ : guard.kind === 'token-account'
678
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
679
+ : { ...guard }),
680
+ });
681
+ }
682
+ if (plan.preconditions.some(({ kind }) => kind === 'fleet-create')) {
683
+ return deepFreeze({
684
+ v: 10,
685
+ ...common,
686
+ steps,
687
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'fleet-create'
688
+ ? { ...guard, maximumProfileDebit: String(guard.maximumProfileDebit) }
689
+ : guard.kind === 'token-account'
690
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
691
+ : { ...guard }),
692
+ });
693
+ }
694
+ if (plan.preconditions.some(({ kind }) => kind === 'game-cargo-bytes-config')) {
695
+ return deepFreeze({
696
+ v: 9,
697
+ ...common,
698
+ steps,
699
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
700
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
701
+ : { ...guard }),
702
+ });
703
+ }
704
+ if (plan.preconditions.some(({ kind }) => kind === 'system-account-or-absent')) {
705
+ return deepFreeze({
706
+ v: 8,
707
+ ...common,
708
+ steps,
709
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
710
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
711
+ : { ...guard }),
712
+ });
713
+ }
714
+ if (plan.preconditions.some(({ kind }) => kind === 'token-mint')) {
715
+ return deepFreeze({
716
+ v: 7,
717
+ ...common,
718
+ steps,
719
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
720
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
721
+ : { ...guard }),
722
+ });
723
+ }
724
+ if (plan.preconditions.some(({ kind }) => kind === 'game-ship-config')) {
725
+ return deepFreeze({
726
+ v: 6,
727
+ ...common,
728
+ steps,
729
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
730
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
731
+ : { ...guard }),
732
+ });
733
+ }
734
+ if (plan.preconditions.some(({ kind }) => kind === 'game-account')) {
735
+ return deepFreeze({
736
+ v: 5,
737
+ ...common,
738
+ steps,
739
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
740
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
741
+ : { ...guard }),
742
+ });
743
+ }
744
+ if (plan.preconditions.some(({ kind }) => kind === 'token-account' ||
745
+ kind === 'game-cargo-config' ||
746
+ kind === 'cargo-cache')) {
747
+ return deepFreeze({
748
+ v: 4,
749
+ ...common,
750
+ steps,
751
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
752
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
753
+ : { ...guard }),
754
+ });
755
+ }
245
756
  if (plan.preconditions.some(({ kind }) => kind === 'token-account-or-absent')) {
246
757
  return deepFreeze({
247
758
  v: 3,
248
759
  ...common,
249
760
  steps,
250
- preconditions: plan.preconditions.map((guard) => ({ ...guard })),
761
+ preconditions: plan.preconditions.map((guard) => ({
762
+ ...guard,
763
+ })),
251
764
  });
252
765
  }
253
766
  if (hasSemantics || hasAbsentPrecondition) {
@@ -291,6 +804,7 @@ export function createPlan(input) {
291
804
  assertKeys(value, 'plan', ['kind', 'summary', 'steps', 'preconditions']);
292
805
  const steps = Object.freeze(readArray(value.steps, 'plan.steps').map((step, index) => normalizeStep(step, `plan.steps[${String(index)}]`)));
293
806
  const preconditions = Object.freeze(readArray(value.preconditions, 'plan.preconditions').map((precondition, index) => normalizePrecondition(precondition, `plan.preconditions[${String(index)}]`)));
807
+ validateShipImportFundingComposition(preconditions);
294
808
  const descriptions = Object.freeze(steps.map((step) => step.describes));
295
809
  const plan = {
296
810
  kind: readString(value.kind, 'plan.kind'),
@@ -337,13 +851,13 @@ function sameAddresses(actual, encoded) {
337
851
  *
338
852
  * @example
339
853
  * ```ts
340
- * declare const wire: PlanJsonV1 | PlanJsonV2 | PlanJsonV3;
854
+ * declare const wire: PlanJsonV1 | PlanJsonV2 | PlanJsonV3 | PlanJsonV4 | PlanJsonV5 | PlanJsonV6 | PlanJsonV7 | PlanJsonV8 | PlanJsonV9 | PlanJsonV10 | PlanJsonV11 | PlanJsonV12 | PlanJsonV13 | PlanJsonV14 | PlanJsonV15 | PlanJsonV16 | PlanJsonV17;
341
855
  * const plan = planFromJSON(wire);
342
856
  * console.log(plan.describe());
343
857
  * ```
344
858
  */
345
859
  export function planFromJSON(json) {
346
- const value = readRecord(json, 'planJson');
860
+ const value = { ...readRecord(json, 'planJson') };
347
861
  assertKeys(value, 'planJson', [
348
862
  'v',
349
863
  'kind',
@@ -353,10 +867,79 @@ export function planFromJSON(json) {
353
867
  'affected',
354
868
  'requiredSigners',
355
869
  ]);
356
- if (value.v !== 1 && value.v !== 2 && value.v !== 3) {
357
- invalid('planJson.v', value.v, 'the Plan wire version 1, 2, or 3');
870
+ if (value.v !== 1 &&
871
+ value.v !== 2 &&
872
+ value.v !== 3 &&
873
+ value.v !== 4 &&
874
+ value.v !== 5 &&
875
+ value.v !== 6 &&
876
+ value.v !== 7 &&
877
+ value.v !== 8 &&
878
+ value.v !== 9 &&
879
+ value.v !== 10 &&
880
+ value.v !== 11 &&
881
+ value.v !== 12 &&
882
+ value.v !== 13 &&
883
+ value.v !== 14 &&
884
+ value.v !== 15 &&
885
+ value.v !== 16 &&
886
+ value.v !== 17) {
887
+ invalid('planJson.v', value.v, 'the Plan wire version 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, or 17');
358
888
  }
359
889
  const version = value.v;
890
+ if (version >= 4 && Array.isArray(value.preconditions)) {
891
+ value.preconditions = value.preconditions.map((entry) => {
892
+ const guard = readRecord(entry, 'precondition');
893
+ if (version >= 17 && guard.kind === 'fleet-arrival')
894
+ return normalizeArrivalGuard(guard, 'precondition', true);
895
+ if (version >= 16 && isRuntimeGuard(guard))
896
+ return normalizeRuntimeGuard(guard, 'precondition', true);
897
+ if (version >= 12 &&
898
+ (isTradeBuyGuard(guard) || isTradeSellGuard(guard))) {
899
+ const keys = isTradeBuyGuard(guard)
900
+ ? ['floorRaw']
901
+ : ['atlasOutCapPerEpochRaw', 'epochLengthSeconds'];
902
+ const decoded = { ...guard };
903
+ for (const key of keys) {
904
+ const raw = guard[key];
905
+ const pattern = key === 'epochLengthSeconds'
906
+ ? /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
907
+ : /^(0|[1-9][0-9]*)$/;
908
+ if (typeof raw !== 'string' || !pattern.test(raw))
909
+ invalid(key, raw, 'a canonical decimal string');
910
+ decoded[key] = BigInt(raw);
911
+ }
912
+ return decoded;
913
+ }
914
+ if (version >= 11 && guard.kind === 'fleet-add-ship') {
915
+ for (const field of ['amount', 'maximumProfileDebit'])
916
+ if (typeof guard[field] !== 'string' ||
917
+ !/^(0|[1-9][0-9]*)$/.test(guard[field]))
918
+ invalid(field, guard[field], 'a canonical unsigned decimal string');
919
+ return {
920
+ ...guard,
921
+ amount: BigInt(guard.amount),
922
+ maximumProfileDebit: BigInt(guard.maximumProfileDebit),
923
+ };
924
+ }
925
+ if ((version >= 10 && guard.kind === 'fleet-create') ||
926
+ (version >= 15 && guard.kind === 'ship-import-funding')) {
927
+ if (typeof guard.maximumProfileDebit !== 'string' ||
928
+ !/^(0|[1-9][0-9]*)$/.test(guard.maximumProfileDebit))
929
+ invalid('maximumProfileDebit', guard.maximumProfileDebit, 'a canonical unsigned decimal string');
930
+ return {
931
+ ...guard,
932
+ maximumProfileDebit: BigInt(guard.maximumProfileDebit),
933
+ };
934
+ }
935
+ if (guard.kind !== 'token-account')
936
+ return guard;
937
+ if (typeof guard.minimumBalance !== 'string' ||
938
+ !/^(0|[1-9][0-9]*)$/.test(guard.minimumBalance))
939
+ invalid('minimumBalance', guard.minimumBalance, 'a canonical unsigned decimal string');
940
+ return { ...guard, minimumBalance: BigInt(guard.minimumBalance) };
941
+ });
942
+ }
360
943
  const steps = readArray(value.steps, 'planJson.steps').map((candidate, index) => {
361
944
  const field = `planJson.steps[${String(index)}]`;
362
945
  const step = readRecord(candidate, field);
@@ -397,6 +980,53 @@ function assertPlan(value, index) {
397
980
  function combinedSummary(steps) {
398
981
  return steps.map((step) => step.describes).join(' ');
399
982
  }
983
+ function validateShipImportFundingComposition(guards) {
984
+ const targets = new Map();
985
+ for (const guard of guards) {
986
+ if (guard.kind !== 'ship-import-funding')
987
+ continue;
988
+ const identity = `${guard.game}:${guard.profile}:${guard.system}:${String(guard.shipId)}`;
989
+ const previous = targets.get(guard.address);
990
+ if (previous !== undefined && previous !== identity)
991
+ throw new SageSdkError('INCOMPATIBLE_PLAN_COMPOSITION', 'Ship imports retain conflicting identities or different configurations for one StarbasePlayer. Use separate confirmed imports, then refresh inventory and replan; prefunding cannot be shared across independently estimated storage growth.');
992
+ targets.set(guard.address, identity);
993
+ }
994
+ }
995
+ function validateFactionGuardComposition(guards) {
996
+ const retained = new Map();
997
+ for (const guard of guards) {
998
+ if (!isFactionTradeGuard(guard))
999
+ continue;
1000
+ const constraints = [
1001
+ [
1002
+ `${isTradeMeterGuard(guard) ? 'meter' : 'treasury'}:${guard.address}:identity`,
1003
+ `${guard.game}:${String(guard.factionId)}`,
1004
+ ],
1005
+ ];
1006
+ if (!isTradeMeterGuard(guard)) {
1007
+ constraints.push(isTradeBuyGuard(guard)
1008
+ ? [
1009
+ `${guard.address}:buy:${String(guard.cargoId)}`,
1010
+ String(guard.floorRaw),
1011
+ ]
1012
+ : [
1013
+ `${guard.address}:sell`,
1014
+ `${String(guard.atlasOutCapPerEpochRaw)}:${String(guard.epochLengthSeconds)}`,
1015
+ ]);
1016
+ }
1017
+ if ('schemaVersion' in guard)
1018
+ constraints.push([
1019
+ `${guard.address}:schema`,
1020
+ String(guard.schemaVersion),
1021
+ ]);
1022
+ for (const [key, value] of constraints) {
1023
+ const previous = retained.get(key);
1024
+ if (previous !== undefined && previous !== value)
1025
+ throw new SageSdkError('INCOMPATIBLE_PLAN_COMPOSITION', 'Faction Market Plans retain incompatible Treasury policy or shared account identity. Refresh the affected Markets and prepare compatible Plans, or use separate confirmed transactions.');
1026
+ retained.set(key, value);
1027
+ }
1028
+ }
1029
+ }
400
1030
  /** Combines one or more Plans with deterministic associative flattening.
401
1031
  *
402
1032
  * Semantic validation is eager. Conflict indices are relative to the flattened
@@ -417,11 +1047,16 @@ export function combinePlans(...plans) {
417
1047
  plans.forEach(assertPlan);
418
1048
  const steps = plans.flatMap((plan) => plan.steps);
419
1049
  validatePlanComposition(steps);
1050
+ const preconditions = plans.flatMap((plan) => plan.preconditions);
1051
+ validateFactionGuardComposition(preconditions);
1052
+ validateMiningStopInstructions(steps, preconditions);
1053
+ validateArrivalInstructions(steps, preconditions);
1054
+ validateRuntimeInstructions(steps, preconditions);
420
1055
  return createPlan({
421
1056
  kind: 'combined',
422
1057
  summary: combinedSummary(steps),
423
1058
  steps,
424
- preconditions: plans.flatMap((plan) => plan.preconditions),
1059
+ preconditions,
425
1060
  });
426
1061
  }
427
1062
  export { assemblePlan } from './assembly.js';