@aephia/atlas-kit 0.6.0-next.14 → 0.6.0-next.141

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 (825) hide show
  1. package/README.md +3 -1
  2. package/dist/cargo/actions/deposit.d.ts +5 -2
  3. package/dist/cargo/actions/deposit.d.ts.map +1 -1
  4. package/dist/cargo/actions/deposit.js +60 -129
  5. package/dist/cargo/actions/deposit.js.map +1 -1
  6. package/dist/cargo/actions/index.d.ts +12 -6
  7. package/dist/cargo/actions/index.d.ts.map +1 -1
  8. package/dist/cargo/actions/index.js +97 -94
  9. package/dist/cargo/actions/index.js.map +1 -1
  10. package/dist/cargo/actions/wallet-context.d.ts +52 -3
  11. package/dist/cargo/actions/wallet-context.d.ts.map +1 -1
  12. package/dist/cargo/actions/wallet-context.js +118 -7
  13. package/dist/cargo/actions/wallet-context.js.map +1 -1
  14. package/dist/cargo/actions/wallet-token.d.ts +1 -6
  15. package/dist/cargo/actions/wallet-token.d.ts.map +1 -1
  16. package/dist/cargo/actions/wallet-token.js +0 -45
  17. package/dist/cargo/actions/wallet-token.js.map +1 -1
  18. package/dist/cargo/actions/withdrawal.d.ts +1 -1
  19. package/dist/cargo/actions/withdrawal.d.ts.map +1 -1
  20. package/dist/cargo/actions/withdrawal.js +39 -168
  21. package/dist/cargo/actions/withdrawal.js.map +1 -1
  22. package/dist/cargo/index.d.ts.map +1 -1
  23. package/dist/cargo/index.js +2 -10
  24. package/dist/cargo/index.js.map +1 -1
  25. package/dist/claim-stakes/actions/index.d.ts +69 -14
  26. package/dist/claim-stakes/actions/index.d.ts.map +1 -1
  27. package/dist/claim-stakes/actions/index.js +613 -697
  28. package/dist/claim-stakes/actions/index.js.map +1 -1
  29. package/dist/claim-stakes/index.d.ts +21 -6
  30. package/dist/claim-stakes/index.d.ts.map +1 -1
  31. package/dist/claim-stakes/index.js +33 -19
  32. package/dist/claim-stakes/index.js.map +1 -1
  33. package/dist/client/context.d.ts.map +1 -1
  34. package/dist/client/context.js +1 -1
  35. package/dist/client/context.js.map +1 -1
  36. package/dist/client/contracts.d.ts +16 -6
  37. package/dist/client/contracts.d.ts.map +1 -1
  38. package/dist/client/errors.d.ts +2 -2
  39. package/dist/client/errors.d.ts.map +1 -1
  40. package/dist/client/errors.js.map +1 -1
  41. package/dist/client/index.d.ts +35 -0
  42. package/dist/client/index.d.ts.map +1 -1
  43. package/dist/client/index.js +35 -0
  44. package/dist/client/index.js.map +1 -1
  45. package/dist/client/rpc-subscription-provider.d.ts +35 -0
  46. package/dist/client/rpc-subscription-provider.d.ts.map +1 -0
  47. package/dist/client/rpc-subscription-provider.js +190 -0
  48. package/dist/client/rpc-subscription-provider.js.map +1 -0
  49. package/dist/combat/actions/index.d.ts +24 -12
  50. package/dist/combat/actions/index.d.ts.map +1 -1
  51. package/dist/combat/actions/index.js +331 -299
  52. package/dist/combat/actions/index.js.map +1 -1
  53. package/dist/combat/index.d.ts +25 -8
  54. package/dist/combat/index.d.ts.map +1 -1
  55. package/dist/combat/index.js +21 -18
  56. package/dist/combat/index.js.map +1 -1
  57. package/dist/crafting/actions/index.d.ts +28 -18
  58. package/dist/crafting/actions/index.d.ts.map +1 -1
  59. package/dist/crafting/actions/index.js +297 -352
  60. package/dist/crafting/actions/index.js.map +1 -1
  61. package/dist/crafting/index.d.ts +33 -3
  62. package/dist/crafting/index.d.ts.map +1 -1
  63. package/dist/crafting/index.js +49 -28
  64. package/dist/crafting/index.js.map +1 -1
  65. package/dist/factions/actions/index.d.ts +2 -1
  66. package/dist/factions/actions/index.d.ts.map +1 -1
  67. package/dist/factions/actions/index.js +6 -4
  68. package/dist/factions/actions/index.js.map +1 -1
  69. package/dist/factions/index.d.ts +6 -1
  70. package/dist/factions/index.d.ts.map +1 -1
  71. package/dist/factions/index.js +16 -18
  72. package/dist/factions/index.js.map +1 -1
  73. package/dist/factions/profile-faction.d.ts +20 -8
  74. package/dist/factions/profile-faction.d.ts.map +1 -1
  75. package/dist/factions/profile-faction.js +20 -8
  76. package/dist/factions/profile-faction.js.map +1 -1
  77. package/dist/fleets/actions/add-ship.d.ts +46 -0
  78. package/dist/fleets/actions/add-ship.d.ts.map +1 -0
  79. package/dist/fleets/actions/add-ship.js +131 -0
  80. package/dist/fleets/actions/add-ship.js.map +1 -0
  81. package/dist/fleets/actions/create-fleet.d.ts +36 -0
  82. package/dist/fleets/actions/create-fleet.d.ts.map +1 -0
  83. package/dist/fleets/actions/create-fleet.js +108 -0
  84. package/dist/fleets/actions/create-fleet.js.map +1 -0
  85. package/dist/fleets/actions/crew-transfer.d.ts +42 -0
  86. package/dist/fleets/actions/crew-transfer.d.ts.map +1 -0
  87. package/dist/fleets/actions/crew-transfer.js +95 -0
  88. package/dist/fleets/actions/crew-transfer.js.map +1 -0
  89. package/dist/fleets/actions/dock-bounds.d.ts +38 -0
  90. package/dist/fleets/actions/dock-bounds.d.ts.map +1 -0
  91. package/dist/fleets/actions/dock-bounds.js +46 -0
  92. package/dist/fleets/actions/dock-bounds.js.map +1 -0
  93. package/dist/fleets/actions/index.d.ts +81 -25
  94. package/dist/fleets/actions/index.d.ts.map +1 -1
  95. package/dist/fleets/actions/index.js +483 -353
  96. package/dist/fleets/actions/index.js.map +1 -1
  97. package/dist/fleets/actions/respawn.d.ts +38 -0
  98. package/dist/fleets/actions/respawn.d.ts.map +1 -0
  99. package/dist/fleets/actions/respawn.js +93 -0
  100. package/dist/fleets/actions/respawn.js.map +1 -0
  101. package/dist/fleets/actions/ship-import.d.ts +1 -1
  102. package/dist/fleets/actions/ship-import.d.ts.map +1 -1
  103. package/dist/fleets/actions/ship-import.js +61 -90
  104. package/dist/fleets/actions/ship-import.js.map +1 -1
  105. package/dist/fleets/cooldown.d.ts +47 -0
  106. package/dist/fleets/cooldown.d.ts.map +1 -0
  107. package/dist/fleets/cooldown.js +48 -0
  108. package/dist/fleets/cooldown.js.map +1 -0
  109. package/dist/fleets/coordinate-warp-estimate.d.ts +70 -0
  110. package/dist/fleets/coordinate-warp-estimate.d.ts.map +1 -0
  111. package/dist/fleets/coordinate-warp-estimate.js +46 -0
  112. package/dist/fleets/coordinate-warp-estimate.js.map +1 -0
  113. package/dist/fleets/index.d.ts +35 -0
  114. package/dist/fleets/index.d.ts.map +1 -1
  115. package/dist/fleets/index.js +54 -12
  116. package/dist/fleets/index.js.map +1 -1
  117. package/dist/fleets/movement-arithmetic.d.ts +21 -0
  118. package/dist/fleets/movement-arithmetic.d.ts.map +1 -0
  119. package/dist/fleets/movement-arithmetic.js +45 -0
  120. package/dist/fleets/movement-arithmetic.js.map +1 -0
  121. package/dist/fleets/subwarp-estimate.d.ts +72 -0
  122. package/dist/fleets/subwarp-estimate.d.ts.map +1 -0
  123. package/dist/fleets/subwarp-estimate.js +40 -0
  124. package/dist/fleets/subwarp-estimate.js.map +1 -0
  125. package/dist/fleets/travel-profile.d.ts +102 -0
  126. package/dist/fleets/travel-profile.d.ts.map +1 -0
  127. package/dist/fleets/travel-profile.js +120 -0
  128. package/dist/fleets/travel-profile.js.map +1 -0
  129. package/dist/fleets/warp-lane-estimate.d.ts +59 -0
  130. package/dist/fleets/warp-lane-estimate.d.ts.map +1 -0
  131. package/dist/fleets/warp-lane-estimate.js +36 -0
  132. package/dist/fleets/warp-lane-estimate.js.map +1 -0
  133. package/dist/fleets/warp-lane-policy.d.ts +74 -0
  134. package/dist/fleets/warp-lane-policy.d.ts.map +1 -0
  135. package/dist/fleets/warp-lane-policy.js +103 -0
  136. package/dist/fleets/warp-lane-policy.js.map +1 -0
  137. package/dist/fleets/warp-lane-toll.d.ts +55 -0
  138. package/dist/fleets/warp-lane-toll.d.ts.map +1 -0
  139. package/dist/fleets/warp-lane-toll.js +79 -0
  140. package/dist/fleets/warp-lane-toll.js.map +1 -0
  141. package/dist/identity/actions/create-profile.d.ts +1 -1
  142. package/dist/identity/actions/create-profile.d.ts.map +1 -1
  143. package/dist/identity/actions/create-profile.js +2 -2
  144. package/dist/identity/actions/create-profile.js.map +1 -1
  145. package/dist/identity/actions/index.d.ts +5 -4
  146. package/dist/identity/actions/index.d.ts.map +1 -1
  147. package/dist/identity/actions/index.js +52 -29
  148. package/dist/identity/actions/index.js.map +1 -1
  149. package/dist/identity/actions/research-unlock.d.ts +61 -0
  150. package/dist/identity/actions/research-unlock.d.ts.map +1 -0
  151. package/dist/identity/actions/research-unlock.js +166 -0
  152. package/dist/identity/actions/research-unlock.js.map +1 -0
  153. package/dist/identity/index.d.ts +5 -2
  154. package/dist/identity/index.d.ts.map +1 -1
  155. package/dist/identity/index.js +6 -12
  156. package/dist/identity/index.js.map +1 -1
  157. package/dist/identity/research-state.d.ts +60 -0
  158. package/dist/identity/research-state.d.ts.map +1 -0
  159. package/dist/identity/research-state.js +68 -0
  160. package/dist/identity/research-state.js.map +1 -0
  161. package/dist/index.d.ts +26 -1
  162. package/dist/index.d.ts.map +1 -1
  163. package/dist/index.js +24 -7
  164. package/dist/index.js.map +1 -1
  165. package/dist/internal/c4/account-decoding.d.ts +49 -0
  166. package/dist/internal/c4/account-decoding.d.ts.map +1 -0
  167. package/dist/internal/c4/account-decoding.js +74 -0
  168. package/dist/internal/c4/account-decoding.js.map +1 -0
  169. package/dist/internal/c4/cargo-bytes-config.d.ts +7 -0
  170. package/dist/internal/c4/cargo-bytes-config.d.ts.map +1 -0
  171. package/dist/internal/c4/cargo-bytes-config.js +19 -0
  172. package/dist/internal/c4/cargo-bytes-config.js.map +1 -0
  173. package/dist/internal/c4/cargo-instructions.d.ts +24 -0
  174. package/dist/internal/c4/cargo-instructions.d.ts.map +1 -0
  175. package/dist/internal/c4/cargo-instructions.js +30 -0
  176. package/dist/internal/c4/cargo-instructions.js.map +1 -0
  177. package/dist/internal/c4/cargo-pod.d.ts +15 -0
  178. package/dist/internal/c4/cargo-pod.d.ts.map +1 -0
  179. package/dist/internal/c4/cargo-pod.js +13 -0
  180. package/dist/internal/c4/cargo-pod.js.map +1 -0
  181. package/dist/internal/c4/character-modifier.d.ts +1 -1
  182. package/dist/internal/c4/character-modifier.d.ts.map +1 -1
  183. package/dist/internal/c4/character-registration.d.ts +2 -0
  184. package/dist/internal/c4/character-registration.d.ts.map +1 -1
  185. package/dist/internal/c4/character-registration.js +2 -0
  186. package/dist/internal/c4/character-registration.js.map +1 -1
  187. package/dist/internal/c4/character.d.ts +157 -0
  188. package/dist/internal/c4/character.d.ts.map +1 -0
  189. package/dist/internal/c4/character.js +64 -0
  190. package/dist/internal/c4/character.js.map +1 -0
  191. package/dist/internal/c4/claim-stake-building-definitions.d.ts.map +1 -1
  192. package/dist/internal/c4/claim-stake-building-definitions.js +2 -1
  193. package/dist/internal/c4/claim-stake-building-definitions.js.map +1 -1
  194. package/dist/internal/c4/claim-stake-configuration.d.ts.map +1 -1
  195. package/dist/internal/c4/claim-stake-configuration.js +5 -36
  196. package/dist/internal/c4/claim-stake-configuration.js.map +1 -1
  197. package/dist/internal/c4/claim-stake-definitions.d.ts +4 -4
  198. package/dist/internal/c4/claim-stake-definitions.d.ts.map +1 -1
  199. package/dist/internal/c4/claim-stake-definitions.js +2 -1
  200. package/dist/internal/c4/claim-stake-definitions.js.map +1 -1
  201. package/dist/internal/c4/claim-stake-plots.d.ts +17 -0
  202. package/dist/internal/c4/claim-stake-plots.d.ts.map +1 -0
  203. package/dist/internal/c4/claim-stake-plots.js +29 -0
  204. package/dist/internal/c4/claim-stake-plots.js.map +1 -0
  205. package/dist/internal/c4/claim-stake.d.ts +13 -33
  206. package/dist/internal/c4/claim-stake.d.ts.map +1 -1
  207. package/dist/internal/c4/claim-stake.js +49 -94
  208. package/dist/internal/c4/claim-stake.js.map +1 -1
  209. package/dist/internal/c4/combat-storage.d.ts +20 -0
  210. package/dist/internal/c4/combat-storage.d.ts.map +1 -0
  211. package/dist/internal/c4/combat-storage.js +43 -0
  212. package/dist/internal/c4/combat-storage.js.map +1 -0
  213. package/dist/internal/c4/combat.d.ts +1 -82
  214. package/dist/internal/c4/combat.d.ts.map +1 -1
  215. package/dist/internal/c4/combat.js +16 -213
  216. package/dist/internal/c4/combat.js.map +1 -1
  217. package/dist/internal/c4/crafting-process-codec.d.ts +13 -0
  218. package/dist/internal/c4/crafting-process-codec.d.ts.map +1 -0
  219. package/dist/internal/c4/crafting-process-codec.js +34 -0
  220. package/dist/internal/c4/crafting-process-codec.js.map +1 -0
  221. package/dist/internal/c4/crafting-storage.d.ts +20 -0
  222. package/dist/internal/c4/crafting-storage.d.ts.map +1 -0
  223. package/dist/internal/c4/crafting-storage.js +54 -0
  224. package/dist/internal/c4/crafting-storage.js.map +1 -0
  225. package/dist/internal/c4/crafting.d.ts +30 -33
  226. package/dist/internal/c4/crafting.d.ts.map +1 -1
  227. package/dist/internal/c4/crafting.js +76 -127
  228. package/dist/internal/c4/crafting.js.map +1 -1
  229. package/dist/internal/c4/currency-cache.d.ts +6 -0
  230. package/dist/internal/c4/currency-cache.d.ts.map +1 -0
  231. package/dist/internal/c4/currency-cache.js +27 -0
  232. package/dist/internal/c4/currency-cache.js.map +1 -0
  233. package/dist/internal/c4/discriminators.d.ts +91 -0
  234. package/dist/internal/c4/discriminators.d.ts.map +1 -0
  235. package/dist/internal/c4/discriminators.js +186 -0
  236. package/dist/internal/c4/discriminators.js.map +1 -0
  237. package/dist/internal/c4/docking-funding.d.ts +4 -0
  238. package/dist/internal/c4/docking-funding.d.ts.map +1 -0
  239. package/dist/internal/c4/docking-funding.js +11 -0
  240. package/dist/internal/c4/docking-funding.js.map +1 -0
  241. package/dist/internal/c4/faction-epoch-meter.d.ts +10 -0
  242. package/dist/internal/c4/faction-epoch-meter.d.ts.map +1 -0
  243. package/dist/internal/c4/faction-epoch-meter.js +26 -0
  244. package/dist/internal/c4/faction-epoch-meter.js.map +1 -0
  245. package/dist/internal/c4/faction-treasury.d.ts +23 -0
  246. package/dist/internal/c4/faction-treasury.d.ts.map +1 -0
  247. package/dist/internal/c4/faction-treasury.js +41 -0
  248. package/dist/internal/c4/faction-treasury.js.map +1 -0
  249. package/dist/internal/c4/faction.d.ts +21 -0
  250. package/dist/internal/c4/faction.d.ts.map +1 -0
  251. package/dist/internal/c4/faction.js +23 -0
  252. package/dist/internal/c4/faction.js.map +1 -0
  253. package/dist/internal/c4/factions.d.ts +15 -57
  254. package/dist/internal/c4/factions.d.ts.map +1 -1
  255. package/dist/internal/c4/factions.js +80 -223
  256. package/dist/internal/c4/factions.js.map +1 -1
  257. package/dist/internal/c4/fleet-arrival.d.ts +28 -0
  258. package/dist/internal/c4/fleet-arrival.d.ts.map +1 -0
  259. package/dist/internal/c4/fleet-arrival.js +42 -0
  260. package/dist/internal/c4/fleet-arrival.js.map +1 -0
  261. package/dist/internal/c4/fleet-creation.d.ts +7 -0
  262. package/dist/internal/c4/fleet-creation.d.ts.map +1 -0
  263. package/dist/internal/c4/fleet-creation.js +171 -0
  264. package/dist/internal/c4/fleet-creation.js.map +1 -0
  265. package/dist/internal/c4/fleet-crew-binding.d.ts +9 -0
  266. package/dist/internal/c4/fleet-crew-binding.d.ts.map +1 -1
  267. package/dist/internal/c4/fleet-crew-binding.js +31 -44
  268. package/dist/internal/c4/fleet-crew-binding.js.map +1 -1
  269. package/dist/internal/c4/fleet-respawn.d.ts +17 -0
  270. package/dist/internal/c4/fleet-respawn.d.ts.map +1 -0
  271. package/dist/internal/c4/fleet-respawn.js +62 -0
  272. package/dist/internal/c4/fleet-respawn.js.map +1 -0
  273. package/dist/internal/c4/fleet-ship-assembly.d.ts +27 -0
  274. package/dist/internal/c4/fleet-ship-assembly.d.ts.map +1 -0
  275. package/dist/internal/c4/fleet-ship-assembly.js +94 -0
  276. package/dist/internal/c4/fleet-ship-assembly.js.map +1 -0
  277. package/dist/internal/c4/fleet-storage.d.ts +44 -0
  278. package/dist/internal/c4/fleet-storage.d.ts.map +1 -0
  279. package/dist/internal/c4/fleet-storage.js +108 -0
  280. package/dist/internal/c4/fleet-storage.js.map +1 -0
  281. package/dist/internal/c4/fleet.d.ts +59 -22
  282. package/dist/internal/c4/fleet.d.ts.map +1 -1
  283. package/dist/internal/c4/fleet.js +50 -87
  284. package/dist/internal/c4/fleet.js.map +1 -1
  285. package/dist/internal/c4/game-definition-layout.d.ts +2 -0
  286. package/dist/internal/c4/game-definition-layout.d.ts.map +1 -1
  287. package/dist/internal/c4/game-definition-layout.js +4 -0
  288. package/dist/internal/c4/game-definition-layout.js.map +1 -1
  289. package/dist/internal/c4/game.d.ts +117 -32
  290. package/dist/internal/c4/game.d.ts.map +1 -1
  291. package/dist/internal/c4/game.js +227 -130
  292. package/dist/internal/c4/game.js.map +1 -1
  293. package/dist/internal/c4/identity.d.ts +3 -152
  294. package/dist/internal/c4/identity.d.ts.map +1 -1
  295. package/dist/internal/c4/identity.js +19 -126
  296. package/dist/internal/c4/identity.js.map +1 -1
  297. package/dist/internal/c4/local-market-order.d.ts +29 -0
  298. package/dist/internal/c4/local-market-order.d.ts.map +1 -0
  299. package/dist/internal/c4/local-market-order.js +46 -0
  300. package/dist/internal/c4/local-market-order.js.map +1 -0
  301. package/dist/internal/c4/loot-layout.js +1 -1
  302. package/dist/internal/c4/loot-layout.js.map +1 -1
  303. package/dist/internal/c4/loot.d.ts +89 -0
  304. package/dist/internal/c4/loot.d.ts.map +1 -0
  305. package/dist/internal/c4/loot.js +109 -0
  306. package/dist/internal/c4/loot.js.map +1 -0
  307. package/dist/internal/c4/loyalty.d.ts +2 -28
  308. package/dist/internal/c4/loyalty.d.ts.map +1 -1
  309. package/dist/internal/c4/loyalty.js +36 -161
  310. package/dist/internal/c4/loyalty.js.map +1 -1
  311. package/dist/internal/c4/market-storage.d.ts +25 -0
  312. package/dist/internal/c4/market-storage.d.ts.map +1 -0
  313. package/dist/internal/c4/market-storage.js +53 -0
  314. package/dist/internal/c4/market-storage.js.map +1 -0
  315. package/dist/internal/c4/market.d.ts +2 -38
  316. package/dist/internal/c4/market.d.ts.map +1 -1
  317. package/dist/internal/c4/market.js +26 -120
  318. package/dist/internal/c4/market.js.map +1 -1
  319. package/dist/internal/c4/mining-instructions.d.ts +2 -0
  320. package/dist/internal/c4/mining-instructions.d.ts.map +1 -0
  321. package/dist/internal/c4/mining-instructions.js +3 -0
  322. package/dist/internal/c4/mining-instructions.js.map +1 -0
  323. package/dist/internal/c4/open-signal.d.ts +8 -0
  324. package/dist/internal/c4/open-signal.d.ts.map +1 -0
  325. package/dist/internal/c4/open-signal.js +37 -0
  326. package/dist/internal/c4/open-signal.js.map +1 -0
  327. package/dist/internal/c4/pda.d.ts +43 -0
  328. package/dist/internal/c4/pda.d.ts.map +1 -1
  329. package/dist/internal/c4/pda.js +83 -17
  330. package/dist/internal/c4/pda.js.map +1 -1
  331. package/dist/internal/c4/profile-faction.d.ts +2 -1
  332. package/dist/internal/c4/profile-faction.d.ts.map +1 -1
  333. package/dist/internal/c4/profile-faction.js +36 -72
  334. package/dist/internal/c4/profile-faction.js.map +1 -1
  335. package/dist/internal/c4/profile-permissions.d.ts +1 -1
  336. package/dist/internal/c4/profile-permissions.d.ts.map +1 -1
  337. package/dist/internal/c4/profile-permissions.js +4 -1
  338. package/dist/internal/c4/profile-permissions.js.map +1 -1
  339. package/dist/internal/c4/region-geometry.d.ts +8 -0
  340. package/dist/internal/c4/region-geometry.d.ts.map +1 -0
  341. package/dist/internal/c4/region-geometry.js +43 -0
  342. package/dist/internal/c4/region-geometry.js.map +1 -0
  343. package/dist/internal/c4/rewards.d.ts +1 -61
  344. package/dist/internal/c4/rewards.d.ts.map +1 -1
  345. package/dist/internal/c4/rewards.js +23 -203
  346. package/dist/internal/c4/rewards.js.map +1 -1
  347. package/dist/internal/c4/runtime-bindings.d.ts +4 -0
  348. package/dist/internal/c4/runtime-bindings.d.ts.map +1 -0
  349. package/dist/internal/c4/runtime-bindings.js +4 -0
  350. package/dist/internal/c4/runtime-bindings.js.map +1 -0
  351. package/dist/internal/c4/scan-detection-codecs.d.ts +3 -0
  352. package/dist/internal/c4/scan-detection-codecs.d.ts.map +1 -0
  353. package/dist/internal/c4/scan-detection-codecs.js +3 -0
  354. package/dist/internal/c4/scan-detection-codecs.js.map +1 -0
  355. package/dist/internal/c4/scan-lifecycle.d.ts +306 -0
  356. package/dist/internal/c4/scan-lifecycle.d.ts.map +1 -0
  357. package/dist/internal/c4/scan-lifecycle.js +235 -0
  358. package/dist/internal/c4/scan-lifecycle.js.map +1 -0
  359. package/dist/internal/c4/scanning.d.ts +4 -41
  360. package/dist/internal/c4/scanning.d.ts.map +1 -1
  361. package/dist/internal/c4/scanning.js +27 -108
  362. package/dist/internal/c4/scanning.js.map +1 -1
  363. package/dist/internal/c4/ship-import.d.ts +4 -0
  364. package/dist/internal/c4/ship-import.d.ts.map +1 -0
  365. package/dist/internal/c4/ship-import.js +13 -0
  366. package/dist/internal/c4/ship-import.js.map +1 -0
  367. package/dist/internal/c4/ship-stats.d.ts.map +1 -1
  368. package/dist/internal/c4/ship-stats.js +46 -44
  369. package/dist/internal/c4/ship-stats.js.map +1 -1
  370. package/dist/internal/c4/starbase.d.ts +0 -32
  371. package/dist/internal/c4/starbase.d.ts.map +1 -1
  372. package/dist/internal/c4/starbase.js +26 -136
  373. package/dist/internal/c4/starbase.js.map +1 -1
  374. package/dist/internal/c4/stimulant.d.ts +26 -0
  375. package/dist/internal/c4/stimulant.d.ts.map +1 -0
  376. package/dist/internal/c4/stimulant.js +36 -0
  377. package/dist/internal/c4/stimulant.js.map +1 -0
  378. package/dist/internal/c4/wallet-cargo-cache.js +2 -1
  379. package/dist/internal/c4/wallet-cargo-cache.js.map +1 -1
  380. package/dist/internal/c4/world.d.ts +37 -7
  381. package/dist/internal/c4/world.d.ts.map +1 -1
  382. package/dist/internal/c4/world.js +87 -129
  383. package/dist/internal/c4/world.js.map +1 -1
  384. package/dist/internal/cargo.d.ts +2 -0
  385. package/dist/internal/cargo.d.ts.map +1 -1
  386. package/dist/internal/cargo.js +8 -0
  387. package/dist/internal/cargo.js.map +1 -1
  388. package/dist/internal/fleet-route.d.ts +12 -0
  389. package/dist/internal/fleet-route.d.ts.map +1 -0
  390. package/dist/internal/fleet-route.js +11 -0
  391. package/dist/internal/fleet-route.js.map +1 -0
  392. package/dist/internal/fleet.d.ts +1 -0
  393. package/dist/internal/fleet.d.ts.map +1 -1
  394. package/dist/internal/fleet.js +3 -1
  395. package/dist/internal/fleet.js.map +1 -1
  396. package/dist/internal/loyalty-atlas-bank-state.d.ts +17 -0
  397. package/dist/internal/loyalty-atlas-bank-state.d.ts.map +1 -0
  398. package/dist/internal/loyalty-atlas-bank-state.js +11 -0
  399. package/dist/internal/loyalty-atlas-bank-state.js.map +1 -0
  400. package/dist/internal/planning/account-state.d.ts +6 -0
  401. package/dist/internal/planning/account-state.d.ts.map +1 -1
  402. package/dist/internal/planning/account-state.js +13 -0
  403. package/dist/internal/planning/account-state.js.map +1 -1
  404. package/dist/internal/planning/action-runtime.d.ts +38 -0
  405. package/dist/internal/planning/action-runtime.d.ts.map +1 -0
  406. package/dist/internal/planning/action-runtime.js +63 -0
  407. package/dist/internal/planning/action-runtime.js.map +1 -0
  408. package/dist/internal/planning/arrival-guards.d.ts +19 -0
  409. package/dist/internal/planning/arrival-guards.d.ts.map +1 -0
  410. package/dist/internal/planning/arrival-guards.js +172 -0
  411. package/dist/internal/planning/arrival-guards.js.map +1 -0
  412. package/dist/internal/planning/authorization-adapter.d.ts +55 -37
  413. package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
  414. package/dist/internal/planning/authorization-adapter.js +231 -81
  415. package/dist/internal/planning/authorization-adapter.js.map +1 -1
  416. package/dist/internal/planning/cargo-storage-actions.d.ts +8 -0
  417. package/dist/internal/planning/cargo-storage-actions.d.ts.map +1 -0
  418. package/dist/internal/planning/cargo-storage-actions.js +97 -0
  419. package/dist/internal/planning/cargo-storage-actions.js.map +1 -0
  420. package/dist/internal/planning/character-registration-guard.d.ts +4 -0
  421. package/dist/internal/planning/character-registration-guard.d.ts.map +1 -0
  422. package/dist/internal/planning/character-registration-guard.js +59 -0
  423. package/dist/internal/planning/character-registration-guard.js.map +1 -0
  424. package/dist/internal/planning/character-registration.d.ts +23 -0
  425. package/dist/internal/planning/character-registration.d.ts.map +1 -0
  426. package/dist/internal/planning/character-registration.js +87 -0
  427. package/dist/internal/planning/character-registration.js.map +1 -0
  428. package/dist/internal/planning/combat-storage-actions.d.ts +9 -0
  429. package/dist/internal/planning/combat-storage-actions.d.ts.map +1 -0
  430. package/dist/internal/planning/combat-storage-actions.js +55 -0
  431. package/dist/internal/planning/combat-storage-actions.js.map +1 -0
  432. package/dist/internal/planning/crafting-storage-actions.d.ts +7 -0
  433. package/dist/internal/planning/crafting-storage-actions.d.ts.map +1 -0
  434. package/dist/internal/planning/crafting-storage-actions.js +64 -0
  435. package/dist/internal/planning/crafting-storage-actions.js.map +1 -0
  436. package/dist/internal/planning/currency-cache-guard.d.ts +4 -0
  437. package/dist/internal/planning/currency-cache-guard.d.ts.map +1 -0
  438. package/dist/internal/planning/currency-cache-guard.js +34 -0
  439. package/dist/internal/planning/currency-cache-guard.js.map +1 -0
  440. package/dist/internal/planning/democracy-history.d.ts +50 -0
  441. package/dist/internal/planning/democracy-history.d.ts.map +1 -0
  442. package/dist/internal/planning/democracy-history.js +189 -0
  443. package/dist/internal/planning/democracy-history.js.map +1 -0
  444. package/dist/internal/planning/direct-options.d.ts +17 -0
  445. package/dist/internal/planning/direct-options.d.ts.map +1 -0
  446. package/dist/internal/planning/direct-options.js +43 -0
  447. package/dist/internal/planning/direct-options.js.map +1 -0
  448. package/dist/internal/planning/faction-enrollment.d.ts +0 -4
  449. package/dist/internal/planning/faction-enrollment.d.ts.map +1 -1
  450. package/dist/internal/planning/faction-enrollment.js +1 -31
  451. package/dist/internal/planning/faction-enrollment.js.map +1 -1
  452. package/dist/internal/planning/faction-trade-guards.d.ts +30 -0
  453. package/dist/internal/planning/faction-trade-guards.d.ts.map +1 -0
  454. package/dist/internal/planning/faction-trade-guards.js +15 -0
  455. package/dist/internal/planning/faction-trade-guards.js.map +1 -0
  456. package/dist/internal/planning/faction-trade-state.d.ts +16 -0
  457. package/dist/internal/planning/faction-trade-state.d.ts.map +1 -0
  458. package/dist/internal/planning/faction-trade-state.js +43 -0
  459. package/dist/internal/planning/faction-trade-state.js.map +1 -0
  460. package/dist/internal/planning/fleet-arrival.d.ts +40 -0
  461. package/dist/internal/planning/fleet-arrival.d.ts.map +1 -0
  462. package/dist/internal/planning/fleet-arrival.js +107 -0
  463. package/dist/internal/planning/fleet-arrival.js.map +1 -0
  464. package/dist/internal/planning/fleet-attack-xp.d.ts +20 -0
  465. package/dist/internal/planning/fleet-attack-xp.d.ts.map +1 -0
  466. package/dist/internal/planning/fleet-attack-xp.js +104 -0
  467. package/dist/internal/planning/fleet-attack-xp.js.map +1 -0
  468. package/dist/internal/planning/fleet-creation.d.ts +30 -0
  469. package/dist/internal/planning/fleet-creation.d.ts.map +1 -0
  470. package/dist/internal/planning/fleet-creation.js +89 -0
  471. package/dist/internal/planning/fleet-creation.js.map +1 -0
  472. package/dist/internal/planning/fleet-crew-guard.d.ts +28 -0
  473. package/dist/internal/planning/fleet-crew-guard.d.ts.map +1 -0
  474. package/dist/internal/planning/fleet-crew-guard.js +48 -0
  475. package/dist/internal/planning/fleet-crew-guard.js.map +1 -0
  476. package/dist/internal/planning/fleet-crew-transfer.d.ts +7 -0
  477. package/dist/internal/planning/fleet-crew-transfer.d.ts.map +1 -0
  478. package/dist/internal/planning/fleet-crew-transfer.js +129 -0
  479. package/dist/internal/planning/fleet-crew-transfer.js.map +1 -0
  480. package/dist/internal/planning/fleet-dock-funding-guard.d.ts +42 -0
  481. package/dist/internal/planning/fleet-dock-funding-guard.d.ts.map +1 -0
  482. package/dist/internal/planning/fleet-dock-funding-guard.js +209 -0
  483. package/dist/internal/planning/fleet-dock-funding-guard.js.map +1 -0
  484. package/dist/internal/planning/fleet-dock-funding.d.ts +9 -0
  485. package/dist/internal/planning/fleet-dock-funding.d.ts.map +1 -0
  486. package/dist/internal/planning/fleet-dock-funding.js +164 -0
  487. package/dist/internal/planning/fleet-dock-funding.js.map +1 -0
  488. package/dist/internal/planning/fleet-docking-guard.d.ts +4 -0
  489. package/dist/internal/planning/fleet-docking-guard.d.ts.map +1 -0
  490. package/dist/internal/planning/fleet-docking-guard.js +44 -0
  491. package/dist/internal/planning/fleet-docking-guard.js.map +1 -0
  492. package/dist/internal/planning/fleet-docking.d.ts +25 -0
  493. package/dist/internal/planning/fleet-docking.d.ts.map +1 -0
  494. package/dist/internal/planning/fleet-docking.js +106 -0
  495. package/dist/internal/planning/fleet-docking.js.map +1 -0
  496. package/dist/internal/planning/fleet-respawn.d.ts +28 -0
  497. package/dist/internal/planning/fleet-respawn.d.ts.map +1 -0
  498. package/dist/internal/planning/fleet-respawn.js +164 -0
  499. package/dist/internal/planning/fleet-respawn.js.map +1 -0
  500. package/dist/internal/planning/fleet-ship-assembly.d.ts +36 -0
  501. package/dist/internal/planning/fleet-ship-assembly.d.ts.map +1 -0
  502. package/dist/internal/planning/fleet-ship-assembly.js +158 -0
  503. package/dist/internal/planning/fleet-ship-assembly.js.map +1 -0
  504. package/dist/internal/planning/fleet-state.d.ts +25 -0
  505. package/dist/internal/planning/fleet-state.d.ts.map +1 -0
  506. package/dist/internal/planning/fleet-state.js +28 -0
  507. package/dist/internal/planning/fleet-state.js.map +1 -0
  508. package/dist/internal/planning/governance-fees.d.ts +64 -0
  509. package/dist/internal/planning/governance-fees.d.ts.map +1 -0
  510. package/dist/internal/planning/governance-fees.js +231 -0
  511. package/dist/internal/planning/governance-fees.js.map +1 -0
  512. package/dist/internal/planning/local-market-order-funding.d.ts +8 -0
  513. package/dist/internal/planning/local-market-order-funding.d.ts.map +1 -0
  514. package/dist/internal/planning/local-market-order-funding.js +128 -0
  515. package/dist/internal/planning/local-market-order-funding.js.map +1 -0
  516. package/dist/internal/planning/local-market-order.d.ts +40 -0
  517. package/dist/internal/planning/local-market-order.d.ts.map +1 -0
  518. package/dist/internal/planning/local-market-order.js +139 -0
  519. package/dist/internal/planning/local-market-order.js.map +1 -0
  520. package/dist/internal/planning/market-storage-actions.d.ts +7 -0
  521. package/dist/internal/planning/market-storage-actions.d.ts.map +1 -0
  522. package/dist/internal/planning/market-storage-actions.js +71 -0
  523. package/dist/internal/planning/market-storage-actions.js.map +1 -0
  524. package/dist/internal/planning/mining-stop.d.ts +14 -0
  525. package/dist/internal/planning/mining-stop.d.ts.map +1 -0
  526. package/dist/internal/planning/mining-stop.js +42 -0
  527. package/dist/internal/planning/mining-stop.js.map +1 -0
  528. package/dist/internal/planning/mining-storage-actions.d.ts +11 -0
  529. package/dist/internal/planning/mining-storage-actions.d.ts.map +1 -0
  530. package/dist/internal/planning/mining-storage-actions.js +57 -0
  531. package/dist/internal/planning/mining-storage-actions.js.map +1 -0
  532. package/dist/internal/planning/movement-character.d.ts +7 -0
  533. package/dist/internal/planning/movement-character.d.ts.map +1 -0
  534. package/dist/internal/planning/movement-character.js +41 -0
  535. package/dist/internal/planning/movement-character.js.map +1 -0
  536. package/dist/internal/planning/movement-storage-actions.d.ts +7 -0
  537. package/dist/internal/planning/movement-storage-actions.d.ts.map +1 -0
  538. package/dist/internal/planning/movement-storage-actions.js +38 -0
  539. package/dist/internal/planning/movement-storage-actions.js.map +1 -0
  540. package/dist/internal/planning/movement-xp-guard.d.ts +4 -0
  541. package/dist/internal/planning/movement-xp-guard.d.ts.map +1 -0
  542. package/dist/internal/planning/movement-xp-guard.js +104 -0
  543. package/dist/internal/planning/movement-xp-guard.js.map +1 -0
  544. package/dist/internal/planning/open-signal-guard.d.ts +3 -0
  545. package/dist/internal/planning/open-signal-guard.d.ts.map +1 -0
  546. package/dist/internal/planning/open-signal-guard.js +32 -0
  547. package/dist/internal/planning/open-signal-guard.js.map +1 -0
  548. package/dist/internal/planning/open-signal.d.ts +31 -0
  549. package/dist/internal/planning/open-signal.d.ts.map +1 -0
  550. package/dist/internal/planning/open-signal.js +94 -0
  551. package/dist/internal/planning/open-signal.js.map +1 -0
  552. package/dist/internal/planning/original-token.d.ts +40 -0
  553. package/dist/internal/planning/original-token.d.ts.map +1 -0
  554. package/dist/internal/planning/original-token.js +112 -0
  555. package/dist/internal/planning/original-token.js.map +1 -0
  556. package/dist/internal/planning/own-starbase-facts.d.ts +37 -0
  557. package/dist/internal/planning/own-starbase-facts.d.ts.map +1 -0
  558. package/dist/internal/planning/own-starbase-facts.js +52 -0
  559. package/dist/internal/planning/own-starbase-facts.js.map +1 -0
  560. package/dist/internal/planning/plan-fields.d.ts +60 -0
  561. package/dist/internal/planning/plan-fields.d.ts.map +1 -0
  562. package/dist/internal/planning/plan-fields.js +159 -0
  563. package/dist/internal/planning/plan-fields.js.map +1 -0
  564. package/dist/internal/planning/plan-guards.d.ts +4 -0
  565. package/dist/internal/planning/plan-guards.d.ts.map +1 -0
  566. package/dist/internal/planning/plan-guards.js +177 -0
  567. package/dist/internal/planning/plan-guards.js.map +1 -0
  568. package/dist/internal/planning/profile-key.d.ts +13 -0
  569. package/dist/internal/planning/profile-key.d.ts.map +1 -0
  570. package/dist/internal/planning/profile-key.js +20 -0
  571. package/dist/internal/planning/profile-key.js.map +1 -0
  572. package/dist/internal/planning/profile-storage-funding-guard.d.ts +28 -0
  573. package/dist/internal/planning/profile-storage-funding-guard.d.ts.map +1 -0
  574. package/dist/internal/planning/profile-storage-funding-guard.js +75 -0
  575. package/dist/internal/planning/profile-storage-funding-guard.js.map +1 -0
  576. package/dist/internal/planning/profile-storage-funding.d.ts +46 -0
  577. package/dist/internal/planning/profile-storage-funding.d.ts.map +1 -0
  578. package/dist/internal/planning/profile-storage-funding.js +58 -0
  579. package/dist/internal/planning/profile-storage-funding.js.map +1 -0
  580. package/dist/internal/planning/recipe-state.d.ts +9 -0
  581. package/dist/internal/planning/recipe-state.d.ts.map +1 -0
  582. package/dist/internal/planning/recipe-state.js +23 -0
  583. package/dist/internal/planning/recipe-state.js.map +1 -0
  584. package/dist/internal/planning/rent-catalog.d.ts +37 -0
  585. package/dist/internal/planning/rent-catalog.d.ts.map +1 -0
  586. package/dist/internal/planning/rent-catalog.js +165 -0
  587. package/dist/internal/planning/rent-catalog.js.map +1 -0
  588. package/dist/internal/planning/rent.d.ts +19 -0
  589. package/dist/internal/planning/rent.d.ts.map +1 -0
  590. package/dist/internal/planning/rent.js +35 -0
  591. package/dist/internal/planning/rent.js.map +1 -0
  592. package/dist/internal/planning/research-unlock.d.ts +69 -0
  593. package/dist/internal/planning/research-unlock.d.ts.map +1 -0
  594. package/dist/internal/planning/research-unlock.js +287 -0
  595. package/dist/internal/planning/research-unlock.js.map +1 -0
  596. package/dist/internal/planning/respawn-guards.d.ts +3 -0
  597. package/dist/internal/planning/respawn-guards.d.ts.map +1 -0
  598. package/dist/internal/planning/respawn-guards.js +42 -0
  599. package/dist/internal/planning/respawn-guards.js.map +1 -0
  600. package/dist/internal/planning/runtime-guards.d.ts +41 -0
  601. package/dist/internal/planning/runtime-guards.d.ts.map +1 -0
  602. package/dist/internal/planning/runtime-guards.js +658 -0
  603. package/dist/internal/planning/runtime-guards.js.map +1 -0
  604. package/dist/internal/planning/scan-completion-guard.d.ts +43 -0
  605. package/dist/internal/planning/scan-completion-guard.d.ts.map +1 -0
  606. package/dist/internal/planning/scan-completion-guard.js +95 -0
  607. package/dist/internal/planning/scan-completion-guard.js.map +1 -0
  608. package/dist/internal/planning/scan-completion.d.ts +20 -0
  609. package/dist/internal/planning/scan-completion.d.ts.map +1 -0
  610. package/dist/internal/planning/scan-completion.js +198 -0
  611. package/dist/internal/planning/scan-completion.js.map +1 -0
  612. package/dist/internal/planning/scan-detect-guard.d.ts +34 -0
  613. package/dist/internal/planning/scan-detect-guard.d.ts.map +1 -0
  614. package/dist/internal/planning/scan-detect-guard.js +77 -0
  615. package/dist/internal/planning/scan-detect-guard.js.map +1 -0
  616. package/dist/internal/planning/scan-detect.d.ts +24 -0
  617. package/dist/internal/planning/scan-detect.d.ts.map +1 -0
  618. package/dist/internal/planning/scan-detect.js +246 -0
  619. package/dist/internal/planning/scan-detect.js.map +1 -0
  620. package/dist/internal/planning/scan-idle-scope.d.ts +5 -0
  621. package/dist/internal/planning/scan-idle-scope.d.ts.map +1 -0
  622. package/dist/internal/planning/scan-idle-scope.js +5 -0
  623. package/dist/internal/planning/scan-idle-scope.js.map +1 -0
  624. package/dist/internal/planning/scan-input.d.ts +9 -0
  625. package/dist/internal/planning/scan-input.d.ts.map +1 -0
  626. package/dist/internal/planning/scan-input.js +58 -0
  627. package/dist/internal/planning/scan-input.js.map +1 -0
  628. package/dist/internal/planning/ship-import-funding.d.ts +22 -0
  629. package/dist/internal/planning/ship-import-funding.d.ts.map +1 -0
  630. package/dist/internal/planning/ship-import-funding.js +53 -0
  631. package/dist/internal/planning/ship-import-funding.js.map +1 -0
  632. package/dist/internal/planning/ship-token.d.ts +1 -6
  633. package/dist/internal/planning/ship-token.d.ts.map +1 -1
  634. package/dist/internal/planning/ship-token.js +0 -37
  635. package/dist/internal/planning/ship-token.js.map +1 -1
  636. package/dist/internal/planning/starbase-player-owner.d.ts +21 -0
  637. package/dist/internal/planning/starbase-player-owner.d.ts.map +1 -0
  638. package/dist/internal/planning/starbase-player-owner.js +17 -0
  639. package/dist/internal/planning/starbase-player-owner.js.map +1 -0
  640. package/dist/internal/planning/starbase-system-guard.d.ts +6 -0
  641. package/dist/internal/planning/starbase-system-guard.d.ts.map +1 -0
  642. package/dist/internal/planning/starbase-system-guard.js +94 -0
  643. package/dist/internal/planning/starbase-system-guard.js.map +1 -0
  644. package/dist/internal/planning/starbase-system.d.ts +15 -0
  645. package/dist/internal/planning/starbase-system.d.ts.map +1 -0
  646. package/dist/internal/planning/starbase-system.js +25 -0
  647. package/dist/internal/planning/starbase-system.js.map +1 -0
  648. package/dist/internal/planning/storage-action-readers.d.ts +10 -0
  649. package/dist/internal/planning/storage-action-readers.d.ts.map +1 -0
  650. package/dist/internal/planning/storage-action-readers.js +41 -0
  651. package/dist/internal/planning/storage-action-readers.js.map +1 -0
  652. package/dist/internal/planning/storage-actions.d.ts +85 -0
  653. package/dist/internal/planning/storage-actions.d.ts.map +1 -0
  654. package/dist/internal/planning/storage-actions.js +183 -0
  655. package/dist/internal/planning/storage-actions.js.map +1 -0
  656. package/dist/internal/planning/token-mint.d.ts.map +1 -1
  657. package/dist/internal/planning/token-mint.js +2 -1
  658. package/dist/internal/planning/token-mint.js.map +1 -1
  659. package/dist/internal/planning/trade-faction-market.d.ts +20 -0
  660. package/dist/internal/planning/trade-faction-market.d.ts.map +1 -0
  661. package/dist/internal/planning/trade-faction-market.js +56 -0
  662. package/dist/internal/planning/trade-faction-market.js.map +1 -0
  663. package/dist/internal/planning/wallet-starbase.d.ts +34 -0
  664. package/dist/internal/planning/wallet-starbase.d.ts.map +1 -0
  665. package/dist/internal/planning/wallet-starbase.js +39 -0
  666. package/dist/internal/planning/wallet-starbase.js.map +1 -0
  667. package/dist/internal/planning/xp-runtime.d.ts +36 -0
  668. package/dist/internal/planning/xp-runtime.d.ts.map +1 -0
  669. package/dist/internal/planning/xp-runtime.js +122 -0
  670. package/dist/internal/planning/xp-runtime.js.map +1 -0
  671. package/dist/internal/read-meta.d.ts +12 -0
  672. package/dist/internal/read-meta.d.ts.map +1 -1
  673. package/dist/internal/read-meta.js +10 -0
  674. package/dist/internal/read-meta.js.map +1 -1
  675. package/dist/internal/system-program.d.ts +4 -0
  676. package/dist/internal/system-program.d.ts.map +1 -0
  677. package/dist/internal/system-program.js +3 -0
  678. package/dist/internal/system-program.js.map +1 -0
  679. package/dist/loyalty/actions/index.d.ts +1 -1
  680. package/dist/loyalty/actions/index.d.ts.map +1 -1
  681. package/dist/loyalty/actions/index.js +16 -46
  682. package/dist/loyalty/actions/index.js.map +1 -1
  683. package/dist/loyalty/index.d.ts +4 -0
  684. package/dist/loyalty/index.d.ts.map +1 -1
  685. package/dist/loyalty/index.js +21 -33
  686. package/dist/loyalty/index.js.map +1 -1
  687. package/dist/markets/actions/index.d.ts +62 -4
  688. package/dist/markets/actions/index.d.ts.map +1 -1
  689. package/dist/markets/actions/index.js +261 -187
  690. package/dist/markets/actions/index.js.map +1 -1
  691. package/dist/markets/actions/trade-faction-market.d.ts +45 -0
  692. package/dist/markets/actions/trade-faction-market.d.ts.map +1 -0
  693. package/dist/markets/actions/trade-faction-market.js +311 -0
  694. package/dist/markets/actions/trade-faction-market.js.map +1 -0
  695. package/dist/markets/index.d.ts +38 -7
  696. package/dist/markets/index.d.ts.map +1 -1
  697. package/dist/markets/index.js +59 -20
  698. package/dist/markets/index.js.map +1 -1
  699. package/dist/mining/actions/index.d.ts +87 -0
  700. package/dist/mining/actions/index.d.ts.map +1 -0
  701. package/dist/mining/actions/index.js +369 -0
  702. package/dist/mining/actions/index.js.map +1 -0
  703. package/dist/mining/estimate.d.ts +114 -0
  704. package/dist/mining/estimate.d.ts.map +1 -0
  705. package/dist/mining/estimate.js +127 -0
  706. package/dist/mining/estimate.js.map +1 -0
  707. package/dist/mining/index.d.ts +9 -2
  708. package/dist/mining/index.d.ts.map +1 -1
  709. package/dist/mining/index.js +10 -13
  710. package/dist/mining/index.js.map +1 -1
  711. package/dist/mining/profile.d.ts +82 -0
  712. package/dist/mining/profile.d.ts.map +1 -0
  713. package/dist/mining/profile.js +109 -0
  714. package/dist/mining/profile.js.map +1 -0
  715. package/dist/planning/assembly.d.ts +6 -1
  716. package/dist/planning/assembly.d.ts.map +1 -1
  717. package/dist/planning/assembly.js +12 -8
  718. package/dist/planning/assembly.js.map +1 -1
  719. package/dist/planning/execution.d.ts +19 -3
  720. package/dist/planning/execution.d.ts.map +1 -1
  721. package/dist/planning/execution.js +603 -72
  722. package/dist/planning/execution.js.map +1 -1
  723. package/dist/planning/index.d.ts +226 -165
  724. package/dist/planning/index.d.ts.map +1 -1
  725. package/dist/planning/index.js +31 -388
  726. package/dist/planning/index.js.map +1 -1
  727. package/dist/planning/plan-construction.d.ts +25 -0
  728. package/dist/planning/plan-construction.d.ts.map +1 -0
  729. package/dist/planning/plan-construction.js +143 -0
  730. package/dist/planning/plan-construction.js.map +1 -0
  731. package/dist/planning/plan-sequence-checkpoint.d.ts +9 -0
  732. package/dist/planning/plan-sequence-checkpoint.d.ts.map +1 -1
  733. package/dist/planning/plan-sequence-checkpoint.js +16 -7
  734. package/dist/planning/plan-sequence-checkpoint.js.map +1 -1
  735. package/dist/planning/plan-sequence-execution.d.ts +5 -0
  736. package/dist/planning/plan-sequence-execution.d.ts.map +1 -1
  737. package/dist/planning/plan-sequence-execution.js +74 -40
  738. package/dist/planning/plan-sequence-execution.js.map +1 -1
  739. package/dist/planning/plan-sequence.d.ts +2 -1
  740. package/dist/planning/plan-sequence.d.ts.map +1 -1
  741. package/dist/planning/plan-sequence.js +8 -1
  742. package/dist/planning/plan-sequence.js.map +1 -1
  743. package/dist/planning/plan-validation.d.ts +17 -0
  744. package/dist/planning/plan-validation.d.ts.map +1 -0
  745. package/dist/planning/plan-validation.js +139 -0
  746. package/dist/planning/plan-validation.js.map +1 -0
  747. package/dist/planning/simulation.d.ts +25 -1
  748. package/dist/planning/simulation.d.ts.map +1 -1
  749. package/dist/planning/simulation.js +111 -11
  750. package/dist/planning/simulation.js.map +1 -1
  751. package/dist/registry/cargo.d.ts +7 -12
  752. package/dist/registry/cargo.d.ts.map +1 -1
  753. package/dist/registry/cargo.js +19 -20
  754. package/dist/registry/cargo.js.map +1 -1
  755. package/dist/registry/docking.d.ts +10 -0
  756. package/dist/registry/docking.d.ts.map +1 -0
  757. package/dist/registry/docking.js +12 -0
  758. package/dist/registry/docking.js.map +1 -0
  759. package/dist/registry/index.d.ts +4 -0
  760. package/dist/registry/index.d.ts.map +1 -1
  761. package/dist/registry/index.js +190 -224
  762. package/dist/registry/index.js.map +1 -1
  763. package/dist/registry/onboarding.d.ts +10 -2
  764. package/dist/registry/onboarding.d.ts.map +1 -1
  765. package/dist/registry/onboarding.js +22 -7
  766. package/dist/registry/onboarding.js.map +1 -1
  767. package/dist/registry/scanning.d.ts +7 -0
  768. package/dist/registry/scanning.d.ts.map +1 -0
  769. package/dist/registry/scanning.js +13 -0
  770. package/dist/registry/scanning.js.map +1 -0
  771. package/dist/registry/ship-stats-snapshot.d.ts.map +1 -1
  772. package/dist/registry/ship-stats-snapshot.js +38 -24
  773. package/dist/registry/ship-stats-snapshot.js.map +1 -1
  774. package/dist/registry/ships.d.ts +22 -2
  775. package/dist/registry/ships.d.ts.map +1 -1
  776. package/dist/registry/ships.js +31 -4
  777. package/dist/registry/ships.js.map +1 -1
  778. package/dist/registry/xp-runtime.d.ts +4 -0
  779. package/dist/registry/xp-runtime.d.ts.map +1 -0
  780. package/dist/registry/xp-runtime.js +14 -0
  781. package/dist/registry/xp-runtime.js.map +1 -0
  782. package/dist/rewards/index.d.ts +11 -5
  783. package/dist/rewards/index.d.ts.map +1 -1
  784. package/dist/rewards/index.js +10 -21
  785. package/dist/rewards/index.js.map +1 -1
  786. package/dist/scanning/actions/index.d.ts +116 -0
  787. package/dist/scanning/actions/index.d.ts.map +1 -0
  788. package/dist/scanning/actions/index.js +191 -0
  789. package/dist/scanning/actions/index.js.map +1 -0
  790. package/dist/scanning/index.d.ts +10 -12
  791. package/dist/scanning/index.d.ts.map +1 -1
  792. package/dist/scanning/index.js +19 -23
  793. package/dist/scanning/index.js.map +1 -1
  794. package/dist/scanning/lifecycle.d.ts +77 -0
  795. package/dist/scanning/lifecycle.d.ts.map +1 -0
  796. package/dist/scanning/lifecycle.js +93 -0
  797. package/dist/scanning/lifecycle.js.map +1 -0
  798. package/dist/scanning/odds.d.ts +115 -0
  799. package/dist/scanning/odds.d.ts.map +1 -0
  800. package/dist/scanning/odds.js +294 -0
  801. package/dist/scanning/odds.js.map +1 -0
  802. package/dist/scanning/signals.d.ts +121 -0
  803. package/dist/scanning/signals.d.ts.map +1 -0
  804. package/dist/scanning/signals.js +171 -0
  805. package/dist/scanning/signals.js.map +1 -0
  806. package/dist/starbases/actions/index.d.ts +6 -4
  807. package/dist/starbases/actions/index.d.ts.map +1 -1
  808. package/dist/starbases/actions/index.js +34 -67
  809. package/dist/starbases/actions/index.js.map +1 -1
  810. package/dist/starbases/index.d.ts.map +1 -1
  811. package/dist/starbases/index.js +3 -11
  812. package/dist/starbases/index.js.map +1 -1
  813. package/dist/world/index.d.ts +108 -5
  814. package/dist/world/index.d.ts.map +1 -1
  815. package/dist/world/index.js +110 -15
  816. package/dist/world/index.js.map +1 -1
  817. package/dist/world/planet-claim-stake-plots.d.ts +139 -0
  818. package/dist/world/planet-claim-stake-plots.d.ts.map +1 -0
  819. package/dist/world/planet-claim-stake-plots.js +117 -0
  820. package/dist/world/planet-claim-stake-plots.js.map +1 -0
  821. package/dist/world/starbase-status.d.ts +176 -0
  822. package/dist/world/starbase-status.d.ts.map +1 -0
  823. package/dist/world/starbase-status.js +153 -0
  824. package/dist/world/starbase-status.js.map +1 -0
  825. package/package.json +10 -2
@@ -1,21 +1,45 @@
1
- import { getAddressEncoder, getBytesEncoder, getProgramDerivedAddress, isAddress, } from '@solana/kit';
1
+ import { deriveCurrencyCache, validateCurrencyCache, } from '../../internal/c4/currency-cache.js';
2
+ import { isAddress } from '@solana/kit';
2
3
  import { InvalidActionInputError, SageSdkError } from '../../client/errors.js';
3
4
  import { readContextRawAccounts } from '../../client/reconciliation.js';
4
- import { sage } from '../../internal/c4/bindings.js';
5
+ import { StarbaseLevel } from '../../internal/c4/runtime-bindings.js';
5
6
  import { readFreshGameClaimStakeConfiguration, } from '../../registry/claim-stakes.js';
6
- import { characterAccountDefinition, findCharacterPda, } from '../../internal/c4/identity.js';
7
+ import { characterAccountDefinition, findCharacterPda, } from '../../internal/c4/character.js';
7
8
  import { deriveFactionOwnershipAddress, factionOwnershipAccountDefinition, } from '../../internal/c4/factions.js';
8
9
  import { claimStakeAccountDefinition } from '../../internal/c4/claim-stake.js';
9
- import { deriveFleetCrewBindingAddress, fleetCrewBindingAccountDefinition, } from '../../internal/c4/fleet-crew-binding.js';
10
+ import { CLAIM_STAKE_PLOT_ROWS, claimStakePlacementRow, claimStakePlotPositions, } from '../../internal/c4/claim-stake-plots.js';
11
+ import { factionValue } from '../../internal/c4/faction.js';
12
+ import { deriveFleetCrewBindingAddress, fleetCrewBindingAccountDefinition, matchesFleetCrewBindingIdentity, } from '../../internal/c4/fleet-crew-binding.js';
10
13
  import { deriveFleetAddress, fleetAccountDefinition, } from '../../internal/c4/fleet.js';
11
14
  import { deriveProfileFactionAddress, profileFactionIdentityAccountDefinition, } from '../../internal/c4/profile-faction.js';
12
15
  import { deriveStarbasePlayerAddress, starbasePlayerAccountDefinition, } from '../../internal/c4/starbase.js';
13
- import { celestialBodyAccountDefinition, decodeIndexedCelestialBodyAccount, deriveCelestialBodyAddress, deriveStarSystemAddress, starSystemAccountDefinition, } from '../../internal/c4/world.js';
16
+ import { celestialBodyAccountDefinition, deriveCelestialBodyAddress, deriveStarSystemAddress, starSystemAccountDefinition, } from '../../internal/c4/world.js';
17
+ import { resolveXpRuntime } from '../../internal/planning/xp-runtime.js';
18
+ import { requireDisabledStakeRent, requireNewStakeRent, } from '../../internal/planning/rent-catalog.js';
19
+ import { deriveStructureXpAccrualAddress } from '../../internal/c4/pda.js';
20
+ import { requireProfileStarbasePlayer } from '../../internal/planning/starbase-player-owner.js';
14
21
  import { requireGameAddress } from '../../internal/game-context.js';
15
- import { adaptCancelClaimStakeBuildingChangesInstruction, adaptClaimStakeBuildingChangesInstruction, adaptDeconstructClaimStakeInstruction, adaptFinalizeClaimStakeBuildingChangesInstruction, adaptPlaceClaimStakeInstruction, adaptRecoverClaimStakeFleetTransferInstruction, adaptStartClaimStakeFleetTransferInstruction, adaptTopUpClaimStakeRentInstruction, validatePlanAuthorization, } from '../../internal/planning/authorization-adapter.js';
16
- import { createPlan, } from '../../planning/index.js';
22
+ import { cargoStorageUnits } from '../../internal/cargo.js';
23
+ import { adaptCancelClaimStakeBuildingChangesInstruction, adaptClaimStakeBuildingChangesInstruction, adaptDeconstructClaimStakeInstruction, adaptFinalizeClaimStakeBuildingChangesInstruction, adaptPlaceClaimStakeInstruction, adaptRecoverClaimStakeFleetTransferInstruction, adaptStartClaimStakeFleetTransferInstruction, adaptTopUpClaimStakeRentInstruction, readPlanAuthorization, } from '../../internal/planning/authorization-adapter.js';
24
+ import { buildPlannerPlan } from '../../planning/plan-construction.js';
17
25
  import { readFreshGameCargoDefinitions } from '../../registry/cargo.js';
18
26
  import { resolveCargo } from '../../registry/index.js';
27
+ import { accountAbsentPrecondition, accountStatePrecondition, } from '../../internal/planning/account-state.js';
28
+ async function resolveClaimStakeXp(ctx, game, structure, character) {
29
+ const xp = await resolveXpRuntime(ctx, {
30
+ game,
31
+ structure,
32
+ ...(character === undefined ? {} : { character }),
33
+ });
34
+ const guard = {
35
+ kind: 'xp-runtime',
36
+ address: game,
37
+ intent: xp.intent,
38
+ accounts: xp.accounts,
39
+ describes: 'The Game and canonical Claim Stake XP accounts remain supported; accrued XP may change. Initialize or repair missing XP state using the game client, then recreate the Plan.',
40
+ };
41
+ return { accounts: xp.accounts, guard };
42
+ }
19
43
  const U64_MAX = (1n << 64n) - 1n;
20
44
  const U16_MAX = 65_535;
21
45
  const I32_MAX = 2_147_483_647;
@@ -31,13 +55,13 @@ const LEVEL_INDEX = Object.freeze({
31
55
  css: 6,
32
56
  });
33
57
  const CLAIM_STAKE_PLOT_LEVELS = Object.freeze([
34
- sage.StarbaseLevel.Level0,
35
- sage.StarbaseLevel.Level1,
36
- sage.StarbaseLevel.Level2,
37
- sage.StarbaseLevel.Level3,
38
- sage.StarbaseLevel.Level4,
39
- sage.StarbaseLevel.Level5,
40
- sage.StarbaseLevel.Css,
58
+ StarbaseLevel.Level0,
59
+ StarbaseLevel.Level1,
60
+ StarbaseLevel.Level2,
61
+ StarbaseLevel.Level3,
62
+ StarbaseLevel.Level4,
63
+ StarbaseLevel.Level5,
64
+ StarbaseLevel.Css,
41
65
  ]);
42
66
  const TIER_INDEX = Object.freeze({
43
67
  one: 0,
@@ -83,51 +107,28 @@ function u16(value, field) {
83
107
  }
84
108
  function validateOptions(value) {
85
109
  const options = record(value, 'options');
86
- exactKeys(options, 'options', [
87
- 'authorization',
88
- 'claimStake',
89
- 'claimStakeDefinitionId',
90
- 'hubBuildingId',
91
- 'initialRentAmount',
92
- ]);
93
- const authorizationRecord = record(options.authorization, 'authorization');
94
- exactKeys(authorizationRecord, 'authorization', ['profile', 'authority', 'keyIndex'], ['certificate']);
95
- const authorization = authorizationRecord;
96
- address(authorization.profile, 'authorization.profile');
97
- address(authorization.authority, 'authorization.authority');
98
- if (authorization.certificate !== undefined) {
99
- address(authorization.certificate, 'authorization.certificate');
100
- }
101
- validatePlanAuthorization(authorization);
102
- if (typeof options.initialRentAmount !== 'bigint' ||
103
- options.initialRentAmount <= 0n ||
104
- options.initialRentAmount > U64_MAX) {
105
- invalid('initialRentAmount', options.initialRentAmount, `a positive raw bigint from 1 through ${String(U64_MAX)} (unsigned u64)`, 'Set initialRentAmount to the exact positive raw rent deposit within the instruction codec range.');
110
+ exactKeys(options, 'options', ['authorization', 'claimStake', 'claimStakeDefinitionId', 'hubBuildingId'], ['initialRentAmount']);
111
+ const authorization = readPlanAuthorization(options.authorization);
112
+ if (options.initialRentAmount !== undefined &&
113
+ (typeof options.initialRentAmount !== 'bigint' ||
114
+ options.initialRentAmount <= 0n ||
115
+ options.initialRentAmount > U64_MAX)) {
116
+ invalid('initialRentAmount', options.initialRentAmount, `a positive raw bigint from 1 through ${String(U64_MAX)} (unsigned u64)`, 'Set initialRentAmount to the exact positive raw rent deposit within the instruction codec range, or omit it to place without rent.');
106
117
  }
107
118
  return {
108
119
  authorization,
109
120
  claimStake: address(options.claimStake, 'claimStake'),
110
121
  claimStakeDefinitionId: u16(options.claimStakeDefinitionId, 'claimStakeDefinitionId'),
111
122
  hubBuildingId: u16(options.hubBuildingId, 'hubBuildingId'),
112
- initialRentAmount: options.initialRentAmount,
123
+ ...(options.initialRentAmount === undefined
124
+ ? {}
125
+ : { initialRentAmount: options.initialRentAmount }),
113
126
  };
114
127
  }
115
- function validateAuthorization(value) {
116
- const authorizationRecord = record(value, 'authorization');
117
- exactKeys(authorizationRecord, 'authorization', ['profile', 'authority', 'keyIndex'], ['certificate']);
118
- const authorization = authorizationRecord;
119
- address(authorization.profile, 'authorization.profile');
120
- address(authorization.authority, 'authorization.authority');
121
- if (authorization.certificate !== undefined) {
122
- address(authorization.certificate, 'authorization.certificate');
123
- }
124
- validatePlanAuthorization(authorization);
125
- return authorization;
126
- }
127
128
  function validateBuildingChangeOptions(value) {
128
129
  const options = record(value, 'options');
129
130
  exactKeys(options, 'options', ['authorization', 'buildingChanges']);
130
- const authorization = validateAuthorization(options.authorization);
131
+ const authorization = readPlanAuthorization(options.authorization);
131
132
  const values = options.buildingChanges;
132
133
  if (!Array.isArray(values) || values.length === 0) {
133
134
  invalid('buildingChanges', values, 'a non-empty dense array of add/remove building changes', 'Provide at least one exact building change before retrying.');
@@ -168,22 +169,22 @@ function validateBuildingChangeOptions(value) {
168
169
  function validateFinalizeBuildingChangeOptions(value) {
169
170
  const options = record(value, 'options');
170
171
  exactKeys(options, 'options', ['authorization']);
171
- return { authorization: validateAuthorization(options.authorization) };
172
+ return { authorization: readPlanAuthorization(options.authorization) };
172
173
  }
173
174
  function validateCancelBuildingChangeOptions(value) {
174
175
  const options = record(value, 'options');
175
176
  exactKeys(options, 'options', ['authorization']);
176
- return { authorization: validateAuthorization(options.authorization) };
177
+ return { authorization: readPlanAuthorization(options.authorization) };
177
178
  }
178
179
  function validateDeconstructOptions(value) {
179
180
  const options = record(value, 'options');
180
181
  exactKeys(options, 'options', ['authorization']);
181
- return { authorization: validateAuthorization(options.authorization) };
182
+ return { authorization: readPlanAuthorization(options.authorization) };
182
183
  }
183
184
  function validateTopUpRentOptions(value) {
184
185
  const options = record(value, 'options');
185
186
  exactKeys(options, 'options', ['amount', 'authorization']);
186
- const authorization = validateAuthorization(options.authorization);
187
+ const authorization = readPlanAuthorization(options.authorization);
187
188
  if (typeof options.amount !== 'bigint' ||
188
189
  options.amount <= 0n ||
189
190
  options.amount > U64_MAX) {
@@ -220,7 +221,7 @@ function validateCargoRequests(value, field, seen) {
220
221
  function validateStartFleetTransferOptions(value) {
221
222
  const options = record(value, 'options');
222
223
  exactKeys(options, 'options', ['authorization', 'load', 'unload']);
223
- const authorization = validateAuthorization(options.authorization);
224
+ const authorization = readPlanAuthorization(options.authorization);
224
225
  const seen = new Set();
225
226
  const load = validateCargoRequests(options.load, 'load', seen);
226
227
  const unload = validateCargoRequests(options.unload, 'unload', seen);
@@ -232,7 +233,7 @@ function validateStartFleetTransferOptions(value) {
232
233
  function validateRecoverFleetTransferOptions(value) {
233
234
  const options = record(value, 'options');
234
235
  exactKeys(options, 'options', ['atUnixSeconds', 'authorization']);
235
- const authorization = validateAuthorization(options.authorization);
236
+ const authorization = readPlanAuthorization(options.authorization);
236
237
  if (typeof options.atUnixSeconds !== 'bigint' ||
237
238
  options.atUnixSeconds < 0n ||
238
239
  options.atUnixSeconds > U64_MAX) {
@@ -240,53 +241,9 @@ function validateRecoverFleetTransferOptions(value) {
240
241
  }
241
242
  return { atUnixSeconds: options.atUnixSeconds, authorization };
242
243
  }
243
- async function deriveCurrencyCacheAddress(game) {
244
- const [derived] = await getProgramDerivedAddress({
245
- programAddress: sage.SAGE_PROGRAM_ADDRESS,
246
- seeds: [
247
- getBytesEncoder().encode(new TextEncoder().encode('CurrencyConfig')),
248
- getAddressEncoder().encode(game),
249
- ],
250
- });
251
- return derived;
252
- }
253
- function validateCurrencyCache(account, game, canonicalAddress, action) {
254
- const decoder = sage.getCurrencyConfigCacheDecoder();
255
- const validDiscriminator = sage.CURRENCY_CONFIG_CACHE_DISCRIMINATOR.every((byte, index) => account.data[index] === byte);
256
- if (account.address !== canonicalAddress ||
257
- account.owner !== sage.SAGE_PROGRAM_ADDRESS ||
258
- account.data.length !== decoder.fixedSize ||
259
- !validDiscriminator ||
260
- decoder.decode(account.data).gameId !== game) {
261
- fail(`CurrencyCache ${account.address} does not match the configured Game, canonical PDA, owner, or pinned account layout. Refresh the Game currency configuration and retry ${action}.`, account.address);
262
- }
263
- }
264
244
  function requireAccount(account, accountAddress, message) {
265
245
  return account ?? fail(message, accountAddress);
266
246
  }
267
- async function hashAccountState(account) {
268
- const owner = getAddressEncoder().encode(account.owner);
269
- const canonical = new Uint8Array(owner.length + account.data.length);
270
- canonical.set(owner);
271
- canonical.set(account.data, owner.length);
272
- const digest = new Uint8Array(await globalThis.crypto.subtle.digest('SHA-256', canonical));
273
- return [...digest].map((byte) => byte.toString(16).padStart(2, '0')).join('');
274
- }
275
- async function precondition(account, describes) {
276
- return Object.freeze({
277
- address: account.address,
278
- dataHash: await hashAccountState(account),
279
- describes,
280
- kind: 'account-state',
281
- });
282
- }
283
- function absentPrecondition(accountAddress, describes) {
284
- return Object.freeze({
285
- address: accountAddress,
286
- describes,
287
- kind: 'account-absent',
288
- });
289
- }
290
247
  function findDefinition(configuration, id, game) {
291
248
  const definition = configuration.claimStakes.definitions.find((candidate) => candidate.id === id);
292
249
  return (definition ??
@@ -297,18 +254,20 @@ function findHub(configuration, id, game) {
297
254
  return (hub ??
298
255
  fail(`Hub building ${String(id)} is not a member of the configured Game building catalog. Choose an exact current bundled hub id, refresh the Game definitions, and retry.`, game));
299
256
  }
300
- function claimedCount(details, definitionId) {
301
- return (details.claimedPlots.find(({ key }) => key === definitionId)?.structures
302
- .length ?? 0);
303
- }
304
257
  /** Plans placement of one Claim Stake with its exact bundled hub.
305
258
  *
306
259
  * The planner validates the configured Game/Profile/Character/System/Body
307
260
  * graph, current catalog membership, known plot/cargo/crew availability, and
308
- * absence of the caller-created Claim Stake account. It returns one inert Plan;
261
+ * absence of the caller-created Claim Stake account. It also checks the
262
+ * Character's productive plot count and tier limits, the bundled hub's tags
263
+ * against the Planet and Claim Stake definition, and that the Character's
264
+ * ATLAS covers the placement fee plus any initial rent. It returns one inert Plan;
309
265
  * permissions, placement races, rent arithmetic, and program capacity remain
310
266
  * chain-authoritative.
311
267
  *
268
+ * The new Claim Stake's rent settlement authority must not exist and stays
269
+ * guarded absent until signing.
270
+ *
312
271
  * @example
313
272
  * ```ts
314
273
  * declare const ctx: SageContext;
@@ -332,21 +291,11 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
332
291
  if (canonicalBody !== body.address) {
333
292
  fail(`Celestial Body ${body.address} is not the canonical Body ${String(body.id)} for the configured Game. Refresh the Body and retry.`, body.address);
334
293
  }
335
- if (player.playerProfile.address !== options.authorization.profile) {
336
- fail(`Starbase Player ${player.address} does not belong to authorization Profile ${options.authorization.profile}. Refresh the Starbase Player for that Profile and retry.`, player.address);
337
- }
338
- const character = await findCharacterPda(options.authorization.profile, game);
339
- if (player.character.address !== character) {
340
- fail(`Starbase Player ${player.address} does not reference the canonical Character ${character} for authorization Profile ${options.authorization.profile}. Refresh the Starbase Player and retry.`, player.address);
341
- }
342
- const canonicalPlayer = await deriveStarbasePlayerAddress(player.system.address, character);
343
- if (canonicalPlayer !== player.address) {
344
- fail(`Starbase Player ${player.address} is not canonical for its Character and System. Refresh the Starbase Player and retry.`, player.address);
345
- }
294
+ const character = await requireProfileStarbasePlayer(player, options.authorization.profile, game);
346
295
  if (body.system.address !== player.system.address) {
347
296
  fail(`Celestial Body ${body.address} belongs to System ${body.system.address}, but Starbase Player ${player.address} belongs to System ${player.system.address}. Choose both snapshots from the same System and retry.`, body.address);
348
297
  }
349
- const [freshGame, currentAccounts] = await Promise.all([
298
+ const [freshGame, currentAccounts, rent] = await Promise.all([
350
299
  readFreshGameClaimStakeConfiguration(ctx),
351
300
  readContextRawAccounts(ctx, [
352
301
  body.address,
@@ -355,13 +304,15 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
355
304
  body.system.address,
356
305
  options.claimStake,
357
306
  ]),
307
+ requireNewStakeRent(ctx, options.claimStake),
358
308
  ]);
359
309
  if (freshGame === undefined) {
360
310
  fail(`Configured Game ${game} is missing. Refresh the Game catalog and retry placement.`, game);
361
311
  }
362
312
  const definition = findDefinition(freshGame.data, options.claimStakeDefinitionId, game);
363
313
  const hub = findHub(freshGame.data, options.hubBuildingId, game);
364
- if (hub.hubValue !== definition.hubValue ||
314
+ if (hub.hubValue <= 0 ||
315
+ hub.hubValue !== definition.hubValue ||
365
316
  hub.minimumTier !== definition.tier ||
366
317
  hub.constructionCost.length !== 0) {
367
318
  fail(`Hub building ${hub.id} (${hub.name}) is not the exact zero-cost ${definition.tier} bundled hub for Claim Stake definition ${definition.id} (${definition.name}). Choose the matching bundled hub from the current Game catalog and retry.`, game);
@@ -385,11 +336,10 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
385
336
  }
386
337
  const currentBodyAccount = requireAccount(bodyAccount, body.address, `Celestial Body ${body.address} is missing. Refresh the Body and retry placement.`);
387
338
  const currentPlayerAccount = requireAccount(playerAccount, player.address, `Starbase Player ${player.address} is missing. Refresh it and retry placement.`);
388
- const currentCharacterAccount = requireAccount(characterAccount, character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry placement.`);
389
339
  const currentSystemAccount = requireAccount(systemAccount, body.system.address, `Star System ${body.system.address} is missing. Refresh the System and retry placement.`);
390
340
  const currentBody = celestialBodyAccountDefinition.decode(currentBodyAccount);
391
341
  const currentPlayer = starbasePlayerAccountDefinition.decode(currentPlayerAccount);
392
- const currentCharacter = characterAccountDefinition.decode(currentCharacterAccount);
342
+ const { account: currentCharacterAccount, current: currentCharacter } = requireProfileCharacter(characterAccount, character, options.authorization.profile, game, 'placement');
393
343
  const currentSystem = starSystemAccountDefinition.decode(currentSystemAccount);
394
344
  const canonicalSystem = await deriveStarSystemAddress(game, currentSystem.systemId);
395
345
  if (canonicalSystem !== body.system.address ||
@@ -411,10 +361,6 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
411
361
  currentPlayer.totalCrew - currentPlayer.busyCrew !== player.availableCrew) {
412
362
  fail(`Starbase Player ${player.address} changed or does not match the authorization Profile, canonical Character, System, or available crew. Refresh it and retry.`, player.address);
413
363
  }
414
- if (currentCharacter.playerProfile !== options.authorization.profile ||
415
- currentCharacter.game !== game) {
416
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry.`, character);
417
- }
418
364
  const currentCargo = currentPlayer.cargo.amounts.find(({ cargoId }) => cargoId === definition.cargoId)?.amount ?? 0n;
419
365
  if (currentCargo !== cargoQuantity || currentCargo < 1n) {
420
366
  fail(`Starbase Player ${player.address} Claim Stake cargo changed from the loaded snapshot or is no longer sufficient. Refresh its cargo and retry.`, player.address);
@@ -424,27 +370,46 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
424
370
  if (currentMissingTag !== undefined) {
425
371
  fail(`Planet ${body.name} (${body.address}) no longer provides required Claim Stake tag ${String(currentMissingTag)} for ${definition.name}. Refresh it and retry.`, body.address);
426
372
  }
373
+ // The bundled hub's tags must come from the Planet and the Claim Stake
374
+ // definition; the hub cannot satisfy its own requirements.
375
+ const hubMissingTag = hub.requiredTagIds.find((tag) => !currentDetails.providedTags.includes(tag) &&
376
+ !definition.providedTagIds.includes(tag));
377
+ if (hubMissingTag !== undefined) {
378
+ fail(`Bundled hub ${hub.name} requires tag ${String(hubMissingTag)}, which neither Planet ${body.name} nor ${definition.name} provides. Choose another Planet or definition.`, body.address);
379
+ }
427
380
  const level = LEVEL_INDEX[currentSystem.starbase.level];
428
381
  const tier = TIER_INDEX[definition.tier];
429
- const plotLimit = currentDetails.claimStakePlots[level][tier];
430
- const usedPlots = claimedCount(currentDetails, definition.id);
431
- if (usedPlots >= plotLimit) {
432
- fail(`Planet ${body.name} (${body.address}) has no available ${definition.name} plot at Starbase ${currentSystem.starbase.level}; ${String(usedPlots)} of ${String(plotLimit)} known plots are occupied. Choose another eligible Planet or tier, refresh it, and retry.`, body.address);
433
- }
382
+ // The program places the stake in the first plot row up to the Starbase's
383
+ // level with room for its tier; stakes of every tier share each row.
384
+ if (claimStakePlacementRow(currentDetails.claimStakePlots, currentDetails.claimedPlots, tier, level) === undefined) {
385
+ fail(`Planet ${body.name} (${body.address}) has no free tier-${definition.tier} Claim Stake plot at Starbase ${currentSystem.starbase.level} or any lower level; every reachable plot row is full. Choose another eligible Planet or tier, refresh it, and retry.`, body.address);
386
+ }
387
+ // The Character's research caps the productive plot tier and count.
388
+ const modifiers = currentCharacter.modifiers.values;
389
+ if (modifiers.maxProductivePlotTier !== undefined &&
390
+ tier + 1 > modifiers.maxProductivePlotTier)
391
+ fail(`Character ${character} may place up to tier ${String(modifiers.maxProductivePlotTier)}, below ${definition.name}'s tier ${definition.tier}. Research a higher plot tier or pick a lower tier.`, character);
392
+ if (currentCharacter.counts.claimStakes >= modifiers.maxProductivePlots)
393
+ fail(`Character ${character} already holds ${String(currentCharacter.counts.claimStakes)} of its ${String(modifiers.maxProductivePlots)} productive plots. Research more plots or deconstruct a Claim Stake.`, character);
394
+ const placementFee = claimStakePlacementFee(currentDetails.baseClaimStakePlacementFee[level][tier].raw, definition.placementFeeMultiplier.raw);
395
+ const rentDeposit = options.initialRentAmount ?? 0n;
396
+ if (currentCharacter.atlasRaw < placementFee + rentDeposit)
397
+ fail(`Character ${character} has ${String(currentCharacter.atlasRaw)} raw ATLAS, below the ${String(placementFee)} raw placement fee plus ${String(rentDeposit)} raw initial rent. Add ATLAS or lower the rent, then retry.`, character);
434
398
  const profileFaction = await deriveProfileFactionAddress(options.authorization.profile);
435
- const currencyCache = await deriveCurrencyCacheAddress(game);
436
- const description = `Place ${definition.name} on Planet ${body.name} (${body.address}) with bundled hub ${hub.name}, ${String(hub.neededCrew)} crew, and ${String(options.initialRentAmount)} raw initial rent.`;
437
- return createPlan({
399
+ const currencyCache = await deriveCurrencyCache(game).then(([address]) => address);
400
+ const description = `Place ${definition.name} on Planet ${body.name} (${body.address}) with bundled hub ${hub.name}, ${String(hub.neededCrew)} crew, a ${String(placementFee)} raw ATLAS placement fee and ${String(rentDeposit)} raw initial rent.`;
401
+ return buildPlannerPlan({
438
402
  kind: 'claim-stakes.place',
439
403
  preconditions: [
440
404
  ...(await Promise.all([
441
- precondition(freshGame.account, `The configured Game retains Claim Stake definition ${String(definition.id)} and bundled hub ${String(hub.id)} eligibility.`),
442
- precondition(currentBodyAccount, `Planet ${body.name} retains an available ${definition.name} plot and its configured Game/System relationship.`),
443
- precondition(currentPlayerAccount, `Starbase Player ${player.address} retains its Profile, Character, System, available crew, and ${cargoName} balance.`),
444
- precondition(currentCharacterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} in the configured Game.`),
445
- precondition(currentSystemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, and active Starbase level.`),
405
+ accountStatePrecondition(freshGame.account, `The configured Game retains Claim Stake definition ${String(definition.id)} and bundled hub ${String(hub.id)} eligibility.`),
406
+ accountStatePrecondition(currentBodyAccount, `Planet ${body.name} retains an available ${definition.name} plot and its configured Game/System relationship.`),
407
+ accountStatePrecondition(currentPlayerAccount, `Starbase Player ${player.address} retains its Profile, Character, System, available crew, and ${cargoName} balance.`),
408
+ characterPrecondition(currentCharacterAccount, options.authorization.profile),
409
+ accountStatePrecondition(currentSystemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, and active Starbase level.`),
446
410
  ])),
447
- absentPrecondition(options.claimStake, 'The caller-supplied Claim Stake signer address remains unallocated.'),
411
+ accountAbsentPrecondition(options.claimStake, 'The caller-supplied Claim Stake signer address remains unallocated.'),
412
+ ...rent.guards,
448
413
  ],
449
414
  steps: [
450
415
  {
@@ -458,8 +423,9 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
458
423
  currencyCache,
459
424
  game,
460
425
  hubBuildingId: hub.id,
461
- initialRentAmount: options.initialRentAmount,
426
+ initialRentAmount: options.initialRentAmount ?? null,
462
427
  profileFaction,
428
+ rentAuthority: rent.rentAuthority,
463
429
  systemAndStarbasePlayerStarbasePlayer: player.address,
464
430
  systemAndStarbasePlayerSystem: body.system.address,
465
431
  }),
@@ -469,6 +435,13 @@ export async function planPlaceClaimStake(ctx, body, player, input) {
469
435
  summary: description,
470
436
  });
471
437
  }
438
+ /** The ATLAS placement fee: the Planet's U32F32 base fee for the Starbase
439
+ * level and tier, times the definition's U8F56 multiplier, rounded to the
440
+ * nearest raw unit with halves rounded up. */
441
+ function claimStakePlacementFee(baseFeeRaw, multiplierRaw) {
442
+ const product = ((baseFeeRaw << 24n) * multiplierRaw) >> 56n;
443
+ return (product + (1n << 55n)) >> 56n;
444
+ }
472
445
  function quantities(buildings) {
473
446
  return new Map(buildings.map(({ buildingId, quantity }) => [buildingId, quantity]));
474
447
  }
@@ -481,9 +454,10 @@ function sameQuantities(left, right) {
481
454
  [...leftById].every(([buildingId, quantity]) => rightById.get(buildingId) === quantity));
482
455
  }
483
456
  function sameStakeState(left, right) {
484
- if (left.kind === 'deactivated')
485
- return false;
486
457
  switch (left.kind) {
458
+ case 'deactivated':
459
+ return (right.kind === 'deactivated' &&
460
+ left.deactivatedAtUnixSeconds === right.deactivatedAtUnixSeconds);
487
461
  case 'active':
488
462
  return right.kind === 'active';
489
463
  case 'design':
@@ -492,12 +466,172 @@ function sameStakeState(left, right) {
492
466
  sameQuantities(left.buildings, right.buildings));
493
467
  }
494
468
  }
495
- const LEGACY_CONTROLLER_ID = Object.freeze({
496
- unaligned: 0,
497
- mud: 1,
498
- oni: 2,
499
- ustur: 3,
500
- });
469
+ /** Finalization and deconstruction release crew the stake committed, which
470
+ * only a version-1 instance records; the program refuses a version-0 instance,
471
+ * whose stored crew is an unverified nominal value. */
472
+ function requireCommittedCrewVersion(current, stake, outcome) {
473
+ if (current.version !== 1) {
474
+ fail(`Claim Stake ${stake.address} is a version ${String(current.version)} instance, which records no committed crew, so it cannot be ${outcome}. Only version-1 Claim Stakes support this action; choose another Claim Stake.`, stake.address);
475
+ }
476
+ }
477
+ // Common facts for planners acting on an owned, placed Claim Stake. Each
478
+ // planner keeps its own eligibility checks and Plan wording at its call site;
479
+ // `action` completes the shared remedies ("retry <action>").
480
+ /** Requires the loaded Claim Stake to belong to the configured Game and to the
481
+ * authorization Profile, and returns that Profile's canonical Character. */
482
+ async function requireOwnedStake(stake, game, profile) {
483
+ if (stake.game !== game) {
484
+ fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
485
+ }
486
+ if (stake.ownerProfile.address !== profile) {
487
+ fail(`Claim Stake ${stake.address} belongs to Profile ${stake.ownerProfile.address}, not authorization Profile ${profile}. Choose a Claim Stake this Profile owns, refresh it, and retry.`, stake.address);
488
+ }
489
+ return findCharacterPda(profile, game);
490
+ }
491
+ /** Reads and decodes the fresh Claim Stake and Body, with `extra` accounts in
492
+ * the same batch. */
493
+ async function readOwnedStake(ctx, stake, action, extra = []) {
494
+ const [stakeCandidate, bodyCandidate, ...extraAccounts] = await readContextRawAccounts(ctx, [
495
+ stake.address,
496
+ stake.body.address,
497
+ ...extra,
498
+ ]);
499
+ const stakeAccount = requireAccount(stakeCandidate, stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry ${action}.`);
500
+ const bodyAccount = requireAccount(bodyCandidate, stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry ${action}.`);
501
+ return {
502
+ bodyAccount,
503
+ currentBody: celestialBodyAccountDefinition.decode(bodyAccount),
504
+ currentStake: claimStakeAccountDefinition.decode(stakeAccount),
505
+ extraAccounts,
506
+ stakeAccount,
507
+ };
508
+ }
509
+ /** Whether the fresh Claim Stake keeps the loaded ownership, Body,
510
+ * definitions, buildings and System generation. */
511
+ function sameOwnedStake(current, stake, game, profile) {
512
+ return (current.game === game &&
513
+ current.body === stake.body.address &&
514
+ current.ownerProfile === profile &&
515
+ current.claimStakeDefinitionId === stake.claimStakeDefinitionId &&
516
+ current.claimStakeDefinitionSeqId === stake.claimStakeDefinitionSeqId &&
517
+ current.buildingDefinitionSeqId === stake.buildingDefinitionSeqId &&
518
+ current.systemSeqId === stake.systemSeqId &&
519
+ sameQuantities(current.buildings, stake.buildings));
520
+ }
521
+ /** Whether the fresh Claim Stake keeps the loaded transfer facts: ownership,
522
+ * Body, active state, System generation, resources and capacity. */
523
+ function sameTransferStake(current, stake, game, profile) {
524
+ return (current.game === game &&
525
+ current.ownerProfile === profile &&
526
+ current.body === stake.body.address &&
527
+ current.systemSeqId === stake.systemSeqId &&
528
+ current.state.kind === 'active' &&
529
+ current.production.cargoPod.storageCost ===
530
+ stake.resources.capacity.usedRaw &&
531
+ current.production.resourceCapacityRaw ===
532
+ stake.resources.capacity.totalRaw &&
533
+ sameCargoAmounts(current.production.cargoPod.amounts, stake.resources.inventory.items.map(({ id, quantityRaw }) => ({
534
+ amount: quantityRaw,
535
+ id,
536
+ }))));
537
+ }
538
+ /** Whether the fresh Fleet keeps the loaded Game, owner, name, cargo and
539
+ * capacities. */
540
+ function sameTransferFleet(current, fleet, game, profile) {
541
+ return (current.game === game &&
542
+ current.ownerProfile === profile &&
543
+ current.name === fleet.name &&
544
+ current.ammoBank.cargoId === fleet.ammo.id &&
545
+ current.ammoBank.amount === fleet.ammo.amount &&
546
+ current.fuelTank.cargoId === fleet.fuel.id &&
547
+ current.fuelTank.amount === fleet.fuel.amount &&
548
+ current.cargoHold.storageCost === fleet.cargoHold.storageCost &&
549
+ sameCargoAmounts(current.cargoHold.amounts, fleet.cargoHold.items) &&
550
+ current.stats.cargo.ammoCapacity === fleet.capacities.ammo.total &&
551
+ current.stats.cargo.fuelCapacity === fleet.capacities.fuel.total &&
552
+ current.stats.cargo.cargoCapacity === fleet.capacities.cargo.total);
553
+ }
554
+ /** Requires the fresh Body to be the Claim Stake's canonical Planet in the
555
+ * configured Game at the Claim Stake's System generation. */
556
+ async function requireStakePlanet(currentBody, stake, game, action) {
557
+ if (currentBody.kind !== 'planet' ||
558
+ currentBody.game !== game ||
559
+ currentBody.systemSequenceId !== stake.systemSeqId ||
560
+ (await deriveCelestialBodyAddress(game, currentBody.id)) !==
561
+ stake.body.address) {
562
+ fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying ${action}.`, stake.body.address);
563
+ }
564
+ return currentBody;
565
+ }
566
+ /** Requires and decodes the canonical Character of the authorization Profile in
567
+ * the configured Game. */
568
+ function requireProfileCharacter(candidate, character, profile, game, action) {
569
+ const account = requireAccount(candidate, character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry ${action}.`);
570
+ const current = characterAccountDefinition.decode(account);
571
+ if (current.playerProfile !== profile || current.game !== game) {
572
+ fail(`Character ${character} does not match authorization Profile ${profile} and configured Game ${game}. Refresh the Character and retry ${action}.`, character);
573
+ }
574
+ return { account, current };
575
+ }
576
+ /** Reads the Claim Stake's System and the authorization Profile's canonical
577
+ * Starbase Player there, with `extra` accounts in the same batch. Requires a
578
+ * canonical, current System with an active Starbase that lists the Body, and a
579
+ * Starbase Player of the Profile, Character and System. */
580
+ async function readStakeStarbase(ctx, stake, game, system, character, profile, action, extra = []) {
581
+ const player = await deriveStarbasePlayerAddress(system, character);
582
+ const [systemCandidate, playerCandidate, ...extraAccounts] = await readContextRawAccounts(ctx, [system, player, ...extra]);
583
+ const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry ${action}.`);
584
+ const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${profile}. Register or refresh it in the Claim Stake's System before retrying ${action}.`);
585
+ const currentSystem = starSystemAccountDefinition.decode(systemAccount);
586
+ const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
587
+ if (currentSystem.game !== game ||
588
+ currentSystem.sequenceId !== stake.systemSeqId ||
589
+ currentSystem.starbase === undefined ||
590
+ !currentSystem.celestialBodyAddresses.includes(stake.body.address) ||
591
+ (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
592
+ fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, active nested Starbase, or Claim Stake Body relationship. Refresh the System and retry ${action}.`, system);
593
+ }
594
+ if (currentPlayer.playerProfile !== profile ||
595
+ currentPlayer.character !== character ||
596
+ currentPlayer.system !== system) {
597
+ fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry ${action}.`, player);
598
+ }
599
+ return {
600
+ currentPlayer,
601
+ currentSystem,
602
+ extraAccounts,
603
+ player,
604
+ playerAccount,
605
+ starbase: currentSystem.starbase,
606
+ systemAccount,
607
+ };
608
+ }
609
+ async function claimStakeCurrencyCache(game) {
610
+ const [currencyCache] = await deriveCurrencyCache(game);
611
+ return currencyCache;
612
+ }
613
+ /** Requires the canonical CurrencyCache and returns its Plan guard. */
614
+ async function requireCurrencyCache(candidate, currencyCache, game, action, planName) {
615
+ await validateCurrencyCache(requireAccount(candidate, currencyCache, `Canonical CurrencyCache ${currencyCache} is missing for configured Game ${game}. Refresh the Game currency configuration and retry ${action}.`), game, planName);
616
+ return {
617
+ kind: 'currency-cache',
618
+ address: currencyCache,
619
+ game,
620
+ describes: 'The canonical CurrencyCache remains assigned to the configured Game; shared accounting may change.',
621
+ };
622
+ }
623
+ function planetPrecondition(account, system) {
624
+ return accountStatePrecondition(account, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`);
625
+ }
626
+ function characterPrecondition(account, profile) {
627
+ return accountStatePrecondition(account, `The canonical Character remains assigned to Profile ${profile} in the configured Game.`);
628
+ }
629
+ function systemPrecondition(account, name) {
630
+ return accountStatePrecondition(account, `Star System ${name} retains its configured Game, sequence, nested Starbase, and Claim Stake Body relationship.`);
631
+ }
632
+ function playerPrecondition(account, player, facts = 'Profile, Character, and System') {
633
+ return accountStatePrecondition(account, `Starbase Player ${player} retains its ${facts}.`);
634
+ }
501
635
  function buildingDescription(change, name) {
502
636
  return `${change.kind} ${String(change.quantity)} ${name}`;
503
637
  }
@@ -505,9 +639,21 @@ function buildingDescription(change, name) {
505
639
  *
506
640
  * The planner verifies the fresh Claim Stake, definition sequences, canonical
507
641
  * Profile/Character/Body/System/Starbase Player graph, optional
508
- * FactionOwnership sidecar, building quantities, slots, crew, and known
509
- * construction cargo. Rent synchronization and the final concurrent sequence
510
- * race remain chain-authoritative.
642
+ * FactionOwnership sidecar, building quantities, slots, Starbase Player crew,
643
+ * non-negative power, a single unremovable hub of quantity one, building tags
644
+ * provided by the Claim Stake definition, the Planet and the buildings, and
645
+ * known construction cargo. A stake whose stored construction time is still
646
+ * running is refused; that time advances only on a production tick. Construction cargo is debited from the Starbase Player's
647
+ * Starbase cargo at finalization, never from the Claim Stake's own storage, so
648
+ * the planner checks the fresh Starbase Player pod. Rent synchronization and
649
+ * the final concurrent sequence race remain chain-authoritative.
650
+ *
651
+ * Requires Game 2 and its existing canonical Claim Stake XP ledger.
652
+ * Missing XP state must be repaired outside this Plan; no accounts are created.
653
+ *
654
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
655
+ * settlement authority must not exist, and both stay guarded absent until
656
+ * signing. The instruction carries no rent history.
511
657
  *
512
658
  * @example
513
659
  * ```ts
@@ -521,88 +667,45 @@ function buildingDescription(change, name) {
521
667
  export async function planClaimStakeBuildingChanges(ctx, stake, input) {
522
668
  const options = validateBuildingChangeOptions(input);
523
669
  const game = requireGameAddress(ctx);
670
+ const { profile } = options.authorization;
524
671
  if (stake.state.kind === 'deactivated') {
525
672
  fail(`Claim Stake ${stake.address} is deactivated; building changes require an active or design Claim Stake. Refresh it or choose another owned Claim Stake before retrying.`, stake.address);
526
673
  }
527
- if (stake.game !== game) {
528
- fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
529
- }
530
- const character = await findCharacterPda(options.authorization.profile, game);
531
- if (stake.ownerCharacter.address !== character) {
532
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned Claim Stake, refresh it, and retry.`, stake.address);
533
- }
534
- const [freshGame, firstAccounts] = await Promise.all([
674
+ const character = await requireOwnedStake(stake, game, profile);
675
+ const action = 'building changes';
676
+ const [freshGame, loaded, rent] = await Promise.all([
535
677
  readFreshGameClaimStakeConfiguration(ctx),
536
- readContextRawAccounts(ctx, [stake.address, stake.body.address, character]),
678
+ readOwnedStake(ctx, stake, action, [character]),
679
+ requireDisabledStakeRent(ctx, game, stake.address, action),
537
680
  ]);
538
681
  if (freshGame === undefined) {
539
682
  fail(`Configured Game ${game} is missing. Refresh the Game catalog and retry building changes.`, game);
540
683
  }
541
- const stakeAccount = requireAccount(firstAccounts[0], stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry building changes.`);
542
- const bodyAccount = requireAccount(firstAccounts[1], stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry building changes.`);
543
- const characterAccount = requireAccount(firstAccounts[2], character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry building changes.`);
544
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
545
- const currentBody = celestialBodyAccountDefinition.decode(bodyAccount);
546
- const currentCharacter = characterAccountDefinition.decode(characterAccount);
547
- if (currentStake.game !== game ||
548
- currentStake.body !== stake.body.address ||
549
- currentStake.ownerCharacter !== character ||
550
- currentStake.claimStakeDefinitionId !== stake.claimStakeDefinitionId ||
551
- currentStake.claimStakeDefinitionSeqId !==
552
- stake.claimStakeDefinitionSeqId ||
553
- currentStake.buildingDefinitionSeqId !== stake.buildingDefinitionSeqId ||
554
- currentStake.systemSeqId !== stake.systemSeqId ||
555
- !sameQuantities(currentStake.buildings, stake.buildings) ||
684
+ const { bodyAccount, currentStake, stakeAccount } = loaded;
685
+ if (!sameOwnedStake(currentStake, stake, game, profile) ||
556
686
  currentStake.neededCrew !== stake.neededCrew) {
557
687
  fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, crew, or System generation. Refresh it and retry building changes.`, stake.address);
558
688
  }
559
- if (currentCharacter.playerProfile !== options.authorization.profile ||
560
- currentCharacter.game !== game) {
561
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry building changes.`, character);
689
+ if (currentStake.constructionRemainingSeconds > 0n) {
690
+ fail(`Claim Stake ${stake.address} records ${String(currentStake.constructionRemainingSeconds)} seconds of construction remaining, and a stake under construction cannot change its buildings. The stored time advances only when a production tick processes the stake: wait for construction to finish, let a production tick record it, refresh the Claim Stake, and retry.`, stake.address);
562
691
  }
563
- if (currentBody.kind !== 'planet' ||
564
- currentBody.game !== game ||
565
- currentBody.systemSequenceId !== stake.systemSeqId ||
566
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
567
- stake.body.address) {
568
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying.`, stake.body.address);
569
- }
570
- const system = currentBody.system;
571
- const [player, ownership, profileFaction] = await Promise.all([
572
- deriveStarbasePlayerAddress(system, character),
692
+ const planetBody = await requireStakePlanet(loaded.currentBody, stake, game, action);
693
+ const { system } = planetBody;
694
+ const { account: characterAccount } = requireProfileCharacter(loaded.extraAccounts[0], character, profile, game, action);
695
+ const [ownership, profileFaction] = await Promise.all([
573
696
  deriveFactionOwnershipAddress(game, 'starbase', system),
574
- deriveProfileFactionAddress(options.authorization.profile),
575
- ]);
576
- const [systemAccountCandidate, playerAccountCandidate, ownershipAccount, profileFactionAccountCandidate,] = await readContextRawAccounts(ctx, [
577
- system,
578
- player,
579
- ownership,
580
- profileFaction,
697
+ deriveProfileFactionAddress(profile),
581
698
  ]);
582
- const systemAccount = requireAccount(systemAccountCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry building changes.`);
583
- const playerAccount = requireAccount(playerAccountCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake's System before retrying.`);
584
- const profileFactionAccount = requireAccount(profileFactionAccountCandidate, profileFaction, `ProfileFaction ${profileFaction} is missing for authorization Profile ${options.authorization.profile}. Choose or repair the Profile faction, refresh it, and retry building changes.`);
585
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
586
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
699
+ const { currentPlayer, currentSystem, extraAccounts: [ownershipAccount, profileFactionCandidate], player, playerAccount, starbase, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [ownership, profileFaction]);
700
+ const profileFactionAccount = requireAccount(profileFactionCandidate, profileFaction, `ProfileFaction ${profileFaction} is missing for authorization Profile ${profile}. Choose or repair the Profile faction, refresh it, and retry building changes.`);
587
701
  const currentProfileFaction = profileFactionIdentityAccountDefinition.decode(profileFactionAccount);
588
- if (currentSystem.game !== game ||
589
- currentSystem.sequenceId !== stake.systemSeqId ||
590
- currentSystem.starbase === undefined ||
591
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
592
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, or an active nested Starbase. Refresh the System and retry building changes.`, system);
702
+ if (currentProfileFaction.profile !== profile) {
703
+ fail(`ProfileFaction ${profileFaction} does not match authorization Profile ${profile}. Refresh or repair the Profile faction before retrying building changes.`, profileFaction);
593
704
  }
594
- if (currentPlayer.playerProfile !== options.authorization.profile ||
595
- currentPlayer.character !== character ||
596
- currentPlayer.system !== system) {
597
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry building changes.`, player);
598
- }
599
- if (currentProfileFaction.profile !== options.authorization.profile) {
600
- fail(`ProfileFaction ${profileFaction} does not match authorization Profile ${options.authorization.profile}. Refresh or repair the Profile faction before retrying building changes.`, profileFaction);
601
- }
602
- let controllerFactionId = LEGACY_CONTROLLER_ID[currentSystem.starbase.owner];
705
+ let controllerFactionId = factionValue(starbase.owner);
603
706
  let ownershipPrecondition;
604
707
  if (ownershipAccount === undefined) {
605
- ownershipPrecondition = absentPrecondition(ownership, `The canonical Starbase FactionOwnership ${ownership} remains unallocated so the chain applies its legacy controller gate.`);
708
+ ownershipPrecondition = accountAbsentPrecondition(ownership, `The canonical Starbase FactionOwnership ${ownership} remains unallocated so the chain applies its legacy controller gate.`);
606
709
  }
607
710
  else {
608
711
  const currentOwnership = factionOwnershipAccountDefinition.decode(ownershipAccount);
@@ -614,7 +717,7 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
614
717
  }
615
718
  controllerFactionId =
616
719
  currentOwnership.controllingFactionId ?? controllerFactionId;
617
- ownershipPrecondition = await precondition(ownershipAccount, `The Starbase FactionOwnership remains assigned to System ${system} at its current generation.`);
720
+ ownershipPrecondition = await accountStatePrecondition(ownershipAccount, `The Starbase FactionOwnership remains assigned to System ${system} at its current generation.`);
618
721
  }
619
722
  if (currentProfileFaction.factionId !== controllerFactionId) {
620
723
  fail(`ProfileFaction ${profileFaction} faction ${String(currentProfileFaction.factionId)} does not match the current Starbase controller faction ${String(controllerFactionId)}. Use a Profile aligned with the current controller, refresh the faction relationship, and retry building changes.`, profileFaction);
@@ -647,6 +750,9 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
647
750
  if (definition === undefined) {
648
751
  fail(`Building ${String(change.buildingId)} has no definition in the current Game catalog. Refresh the definitions and choose a valid building before retrying.`, game);
649
752
  }
753
+ if (change.kind === 'remove' && definition.hubValue > 0) {
754
+ fail(`Building ${definition.name} is Claim Stake ${stake.address}'s bundled hub and cannot be removed. Remove other buildings, or deconstruct the whole Claim Stake, instead.`, stake.address);
755
+ }
650
756
  const current = result.get(change.buildingId) ?? 0;
651
757
  const next = change.kind === 'add'
652
758
  ? current + change.quantity
@@ -664,10 +770,15 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
664
770
  descriptions.push(buildingDescription(change, definition.name));
665
771
  }
666
772
  let usedSlots = 0;
667
- let crewSlots = 0;
668
773
  let neededCrew = 0;
774
+ let power = 0;
775
+ let hubs = 0;
669
776
  let resourceStorageRaw = 0n;
670
- const providedTags = new Set(claimDefinition.providedTagIds);
777
+ // Tags come from the Claim Stake definition, the Planet and every building.
778
+ const providedTags = new Set([
779
+ ...claimDefinition.providedTagIds,
780
+ ...planetBody.details.providedTags,
781
+ ]);
671
782
  for (const [buildingId, quantity] of result) {
672
783
  const definition = definitions.get(buildingId);
673
784
  if (definition === undefined) {
@@ -680,9 +791,15 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
680
791
  definition.hubValue !== claimDefinition.hubValue) {
681
792
  fail(`Hub building ${definition.name} does not match Claim Stake ${claimDefinition.name}'s hub value. Choose the matching hub before retrying.`, stake.address);
682
793
  }
794
+ if (definition.hubValue > 0) {
795
+ hubs += 1;
796
+ if (quantity !== 1) {
797
+ fail(`The resulting Claim Stake design has ${String(quantity)} of hub building ${definition.name}; a Claim Stake holds exactly one hub. Remove the extra hub before retrying.`, stake.address);
798
+ }
799
+ }
683
800
  usedSlots += definition.slots * quantity;
684
- crewSlots += definition.crewSlots * quantity;
685
801
  neededCrew += definition.neededCrew * quantity;
802
+ power += definition.power * quantity;
686
803
  resourceStorageRaw += definition.resourceStorageRaw * BigInt(quantity);
687
804
  if (neededCrew > U16_MAX) {
688
805
  fail(`The resulting Claim Stake design has ${String(neededCrew)} needed crew, exceeding the ${String(U16_MAX)} maximum representable by its unsigned u16 needed-crew field. Remove crew-requiring buildings and retry.`, stake.address);
@@ -695,8 +812,11 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
695
812
  if (usedSlots > claimDefinition.slots) {
696
813
  fail(`Building changes require ${String(usedSlots)} slots, exceeding Claim Stake ${claimDefinition.name}'s ${String(claimDefinition.slots)} slot capacity. Remove buildings and retry.`, stake.address);
697
814
  }
698
- if (neededCrew > crewSlots) {
699
- fail(`Building changes require ${String(neededCrew)} crew, exceeding the resulting ${String(crewSlots)} crew capacity. Add crew-slot capacity or remove crew-requiring buildings before retrying.`, stake.address);
815
+ if (hubs > 1) {
816
+ fail(`The resulting Claim Stake design has ${String(hubs)} hub buildings; a Claim Stake holds exactly one hub. Remove the extra hubs before retrying.`, stake.address);
817
+ }
818
+ if (power < 0) {
819
+ fail(`The resulting Claim Stake design uses ${String(-power)} more power than its buildings generate. Add power-generating buildings or remove power consumers before retrying.`, stake.address);
700
820
  }
701
821
  for (const [buildingId] of result) {
702
822
  const definition = definitions.get(buildingId);
@@ -714,10 +834,7 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
714
834
  if (addedCrew > availableCrew) {
715
835
  fail(`Building additions require ${String(addedCrew)} crew, but Starbase Player ${player} has only ${String(availableCrew)} known crew capacity available. Free crew, refresh the Starbase Player, and retry.`, player);
716
836
  }
717
- const cargo = new Map(currentStake.production.cargoPod.amounts.map(({ cargoId, amount }) => [
718
- cargoId,
719
- amount,
720
- ]));
837
+ const cargo = new Map(currentPlayer.cargo.amounts.map(({ cargoId, amount }) => [cargoId, amount]));
721
838
  const constructionCosts = new Map();
722
839
  for (const change of options.buildingChanges) {
723
840
  if (change.kind !== 'add')
@@ -732,7 +849,7 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
732
849
  const available = cargo.get(cargoId) ?? 0n;
733
850
  if (required > available) {
734
851
  const snapshotItem = stake.resources.inventory.items.find(({ id }) => id === cargoId);
735
- fail(`Building construction requires ${String(required)} raw ${snapshotItem?.name ?? `cargo ${String(cargoId)}`}, but Claim Stake ${stake.address} has only ${String(available)} known. Add construction cargo, refresh the Claim Stake, and retry.`, stake.address);
852
+ fail(`Building construction requires ${String(required)} raw ${snapshotItem?.name ?? `cargo ${String(cargoId)}`}, but Starbase Player ${player} has only ${String(available)} known in Starbase cargo. Construction cargo is taken from the Starbase, not from the Claim Stake. Deposit it at the Starbase, refresh the Starbase Player, and retry.`, player);
736
853
  }
737
854
  }
738
855
  if (currentStake.production.resourceCapacityRaw !==
@@ -744,26 +861,30 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
744
861
  if (currentStake.production.cargoPod.storageCost > resourceStorageRaw) {
745
862
  fail(`The resulting Claim Stake design provides ${String(resourceStorageRaw)} raw storage capacity, below the fresh known cargo usage of ${String(currentStake.production.cargoPod.storageCost)}. Keep enough storage buildings, remove cargo, refresh the Claim Stake, and retry building changes.`, stake.address);
746
863
  }
747
- const currencyCache = await deriveCurrencyCacheAddress(game);
864
+ const currencyCache = await claimStakeCurrencyCache(game);
748
865
  const description = `Change buildings on Claim Stake ${stake.address}: ${descriptions.join('; ')}.`;
749
- return createPlan({
866
+ const xp = await resolveClaimStakeXp(ctx, game, stake.address);
867
+ return buildPlannerPlan({
750
868
  kind: 'claim-stakes.building-changes',
751
869
  preconditions: [
752
870
  ...(await Promise.all([
753
- precondition(freshGame.account, 'The configured Game retains the exact Claim Stake and building definitions.'),
754
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, buildings, cargo, crew, and Body relationship.`),
755
- precondition(bodyAccount, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`),
756
- precondition(characterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} in the configured Game.`),
757
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, and nested Starbase.`),
758
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, System, and available crew.`),
759
- precondition(profileFactionAccount, `ProfileFaction ${profileFaction} remains assigned to Profile ${options.authorization.profile} and aligned with the current Starbase controller.`),
871
+ accountStatePrecondition(freshGame.account, 'The configured Game retains the exact Claim Stake and building definitions.'),
872
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, buildings, cargo, crew, and Body relationship.`),
873
+ planetPrecondition(bodyAccount, system),
874
+ characterPrecondition(characterAccount, profile),
875
+ systemPrecondition(systemAccount, currentSystem.name),
876
+ playerPrecondition(playerAccount, player, 'Profile, Character, System, and available crew'),
877
+ accountStatePrecondition(profileFactionAccount, `ProfileFaction ${profileFaction} remains assigned to Profile ${profile} and aligned with the current Starbase controller.`),
760
878
  ])),
761
879
  ownershipPrecondition,
880
+ xp.guard,
881
+ ...rent.guards,
762
882
  ],
763
883
  steps: [
764
884
  {
765
885
  describes: description,
766
886
  instruction: adaptClaimStakeBuildingChangesInstruction({
887
+ ...xp.accounts,
767
888
  authorization: options.authorization,
768
889
  buildingChanges: options.buildingChanges.map(({ buildingId, kind, quantity }) => [buildingId, kind === 'add' ? quantity : -quantity]),
769
890
  celestialBody: stake.body.address,
@@ -772,6 +893,7 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
772
893
  factionOwnership: ownership,
773
894
  game,
774
895
  profileFaction,
896
+ ...rent.accounts,
775
897
  sequenceId,
776
898
  starbasePlayer: player,
777
899
  system,
@@ -789,6 +911,14 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
789
911
  * CurrencyCache, and a known positive rent balance. Rent timing and the final
790
912
  * crew/building validation remain chain-authoritative.
791
913
  *
914
+ * Requires Game 2 and its existing canonical Claim Stake XP ledger.
915
+ * The Character XP budget and configuration must also be reconciled.
916
+ * Missing XP state must be repaired outside this Plan; no accounts are created.
917
+ *
918
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
919
+ * settlement authority must not exist, and both stay guarded absent until
920
+ * signing. The instruction carries no rent history.
921
+ *
792
922
  * @example
793
923
  * ```ts
794
924
  * declare const ctx: SageContext;
@@ -804,22 +934,19 @@ export async function planClaimStakeBuildingChanges(ctx, stake, input) {
804
934
  export async function planFinalizeClaimStakeBuildingChanges(ctx, stake, input) {
805
935
  const options = validateFinalizeBuildingChangeOptions(input);
806
936
  const game = requireGameAddress(ctx);
937
+ const { profile } = options.authorization;
807
938
  if (stake.state.kind !== 'design') {
808
939
  fail(`Claim Stake ${stake.address} is not in design state. Refresh it and finalize only a pending building design.`, stake.address);
809
940
  }
810
- if (stake.game !== game) {
811
- fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
812
- }
813
- const character = await findCharacterPda(options.authorization.profile, game);
814
- if (stake.ownerCharacter.address !== character) {
815
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned Claim Stake, refresh it, and retry.`, stake.address);
816
- }
941
+ const character = await requireOwnedStake(stake, game, profile);
817
942
  if (stake.rentBalanceRaw <= 0n) {
818
943
  fail(`Claim Stake ${stake.address} has a known delinquent rent balance of ${String(stake.rentBalanceRaw)} raw units. Top up rent, refresh the Claim Stake, and retry finalization.`, stake.address);
819
944
  }
820
- const [freshGame, firstAccounts] = await Promise.all([
945
+ const action = 'finalization';
946
+ const [freshGame, loaded, rent] = await Promise.all([
821
947
  readFreshGameClaimStakeConfiguration(ctx),
822
- readContextRawAccounts(ctx, [stake.address, stake.body.address, character]),
948
+ readOwnedStake(ctx, stake, action, [character]),
949
+ requireDisabledStakeRent(ctx, game, stake.address, action),
823
950
  ]);
824
951
  if (freshGame === undefined) {
825
952
  fail(`Configured Game ${game} is missing. Refresh the Game catalog and retry finalization.`, game);
@@ -828,81 +955,49 @@ export async function planFinalizeClaimStakeBuildingChanges(ctx, stake, input) {
828
955
  freshGame.data.buildings.sequenceId !== stake.buildingDefinitionSeqId) {
829
956
  fail(`Claim Stake ${stake.address} definition sequence is stale against the current Game catalog. Refresh the Claim Stake and definitions to rule out stale local data. If the on-chain generation still differs, use a Claim Stake matching the current catalog before retrying finalization.`, stake.address);
830
957
  }
831
- const stakeAccount = requireAccount(firstAccounts[0], stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry finalization.`);
832
- const bodyAccount = requireAccount(firstAccounts[1], stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry finalization.`);
833
- const characterAccount = requireAccount(firstAccounts[2], character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry finalization.`);
834
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
835
- const currentBody = celestialBodyAccountDefinition.decode(bodyAccount);
836
- const currentCharacter = characterAccountDefinition.decode(characterAccount);
837
- if (currentStake.game !== game ||
838
- currentStake.body !== stake.body.address ||
839
- currentStake.ownerCharacter !== character ||
840
- currentStake.claimStakeDefinitionId !== stake.claimStakeDefinitionId ||
841
- currentStake.claimStakeDefinitionSeqId !==
842
- stake.claimStakeDefinitionSeqId ||
843
- currentStake.buildingDefinitionSeqId !== stake.buildingDefinitionSeqId ||
844
- currentStake.systemSeqId !== stake.systemSeqId ||
958
+ const { bodyAccount, currentStake, stakeAccount } = loaded;
959
+ if (!sameOwnedStake(currentStake, stake, game, profile) ||
845
960
  currentStake.rentBalanceRaw !== stake.rentBalanceRaw ||
846
- !sameQuantities(currentStake.buildings, stake.buildings) ||
847
961
  currentStake.state.kind !== 'design' ||
848
962
  currentStake.state.sequenceId !== stake.state.sequenceId ||
849
963
  !sameQuantities(currentStake.state.buildings, stake.state.buildings)) {
850
964
  fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, design sequence, rent, or System generation. Refresh it and retry finalization.`, stake.address);
851
965
  }
852
- if (currentCharacter.playerProfile !== options.authorization.profile ||
853
- currentCharacter.game !== game) {
854
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry finalization.`, character);
855
- }
856
- if (currentBody.kind !== 'planet' ||
857
- currentBody.game !== game ||
858
- currentBody.systemSequenceId !== stake.systemSeqId ||
859
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
860
- stake.body.address) {
861
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying finalization.`, stake.body.address);
862
- }
863
- const system = currentBody.system;
864
- const player = await deriveStarbasePlayerAddress(system, character);
865
- const currencyCache = await deriveCurrencyCacheAddress(game);
866
- const [systemCandidate, playerCandidate, currencyCandidate] = await readContextRawAccounts(ctx, [system, player, currencyCache]);
867
- const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry finalization.`);
868
- const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake's System before retrying finalization.`);
869
- const currencyAccount = requireAccount(currencyCandidate, currencyCache, `Canonical CurrencyCache ${currencyCache} is missing for configured Game ${game}. Refresh the Game currency configuration and retry finalization.`);
870
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
871
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
872
- if (currentSystem.game !== game ||
873
- currentSystem.sequenceId !== stake.systemSeqId ||
874
- currentSystem.starbase === undefined ||
875
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
876
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, or an active nested Starbase. Refresh the System and retry finalization.`, system);
877
- }
878
- if (currentPlayer.playerProfile !== options.authorization.profile ||
879
- currentPlayer.character !== character ||
880
- currentPlayer.system !== system) {
881
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry finalization.`, player);
882
- }
883
- validateCurrencyCache(currencyAccount, game, currencyCache, 'finalization');
966
+ requireCommittedCrewVersion(currentStake, stake, 'finalized');
967
+ const { system } = await requireStakePlanet(loaded.currentBody, stake, game, action);
968
+ const { account: characterAccount } = requireProfileCharacter(loaded.extraAccounts[0], character, profile, game, action);
969
+ const currencyCache = await claimStakeCurrencyCache(game);
970
+ const { currentSystem, extraAccounts: [currencyCandidate], player, playerAccount, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [currencyCache]);
971
+ const currencyGuard = await requireCurrencyCache(currencyCandidate, currencyCache, game, action, 'Claim Stake finalization');
884
972
  const description = `Finalize building changes on Claim Stake ${stake.address}.`;
885
- return createPlan({
973
+ const xp = await resolveClaimStakeXp(ctx, game, stake.address, character);
974
+ return buildPlannerPlan({
886
975
  kind: 'claim-stakes.finalize-building-changes',
887
- preconditions: await Promise.all([
888
- precondition(freshGame.account, 'The configured Game remains current.'),
889
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, rent balance, Body, and System generation.`),
890
- precondition(characterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} in the configured Game.`),
891
- precondition(bodyAccount, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`),
892
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, and nested Starbase.`),
893
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, and System.`),
894
- precondition(currencyAccount, 'The canonical CurrencyCache remains assigned to the configured Game.'),
895
- ]),
976
+ preconditions: [
977
+ xp.guard,
978
+ ...(await Promise.all([
979
+ accountStatePrecondition(freshGame.account, 'The configured Game remains current.'),
980
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, rent balance, Body, and System generation.`),
981
+ characterPrecondition(characterAccount, profile),
982
+ planetPrecondition(bodyAccount, system),
983
+ systemPrecondition(systemAccount, currentSystem.name),
984
+ playerPrecondition(playerAccount, player),
985
+ ])),
986
+ currencyGuard,
987
+ ...rent.guards,
988
+ ],
896
989
  steps: [
897
990
  {
898
991
  describes: description,
899
992
  instruction: adaptFinalizeClaimStakeBuildingChangesInstruction({
993
+ ...xp.accounts,
900
994
  authorization: options.authorization,
901
995
  celestialBody: stake.body.address,
902
996
  character,
903
997
  claimStakeInstance: stake.address,
904
998
  currencyCache,
905
999
  game,
1000
+ ...rent.accounts,
906
1001
  systemAndStarbasePlayerStarbasePlayer: player,
907
1002
  systemAndStarbasePlayerSystem: system,
908
1003
  }),
@@ -920,6 +1015,13 @@ export async function planFinalizeClaimStakeBuildingChanges(ctx, stake, input) {
920
1015
  * state; rent arithmetic and concurrent state transitions remain
921
1016
  * chain-authoritative.
922
1017
  *
1018
+ * Requires Game 2 and its existing canonical Claim Stake XP ledger.
1019
+ * Missing XP state must be repaired outside this Plan; no accounts are created.
1020
+ *
1021
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
1022
+ * settlement authority must not exist, and both stay guarded absent until
1023
+ * signing. The instruction carries no rent history.
1024
+ *
923
1025
  * @example
924
1026
  * ```ts
925
1027
  * declare const ctx: SageContext;
@@ -934,85 +1036,52 @@ export async function planFinalizeClaimStakeBuildingChanges(ctx, stake, input) {
934
1036
  export async function planCancelClaimStakeBuildingChanges(ctx, stake, input) {
935
1037
  const options = validateCancelBuildingChangeOptions(input);
936
1038
  const game = requireGameAddress(ctx);
1039
+ const { profile } = options.authorization;
937
1040
  if (stake.state.kind !== 'design') {
938
1041
  fail(`Claim Stake ${stake.address} is not in design state. Refresh it and cancel only a pending building design.`, stake.address);
939
1042
  }
940
- if (stake.game !== game) {
941
- fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
942
- }
943
- const character = await findCharacterPda(options.authorization.profile, game);
944
- if (stake.ownerCharacter.address !== character) {
945
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned Claim Stake, refresh it, and retry.`, stake.address);
946
- }
947
- const firstAccounts = await readContextRawAccounts(ctx, [
948
- stake.address,
949
- stake.body.address,
1043
+ const character = await requireOwnedStake(stake, game, profile);
1044
+ const action = 'cancellation';
1045
+ const [{ bodyAccount, currentBody, currentStake, stakeAccount }, rent] = await Promise.all([
1046
+ readOwnedStake(ctx, stake, action),
1047
+ requireDisabledStakeRent(ctx, game, stake.address, action),
950
1048
  ]);
951
- const stakeAccount = requireAccount(firstAccounts[0], stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry cancellation.`);
952
- const bodyAccount = requireAccount(firstAccounts[1], stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry cancellation.`);
953
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
954
- const currentBody = celestialBodyAccountDefinition.decode(bodyAccount);
955
- if (currentStake.game !== game ||
956
- currentStake.body !== stake.body.address ||
957
- currentStake.ownerCharacter !== character ||
958
- currentStake.claimStakeDefinitionId !== stake.claimStakeDefinitionId ||
959
- currentStake.claimStakeDefinitionSeqId !==
960
- stake.claimStakeDefinitionSeqId ||
961
- currentStake.buildingDefinitionSeqId !== stake.buildingDefinitionSeqId ||
962
- currentStake.systemSeqId !== stake.systemSeqId ||
963
- !sameQuantities(currentStake.buildings, stake.buildings) ||
1049
+ if (!sameOwnedStake(currentStake, stake, game, profile) ||
964
1050
  currentStake.state.kind !== 'design' ||
965
1051
  currentStake.state.sequenceId !== stake.state.sequenceId ||
966
1052
  !sameQuantities(currentStake.state.buildings, stake.state.buildings)) {
967
1053
  fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, design sequence, or System generation. Refresh it and retry cancellation.`, stake.address);
968
1054
  }
969
- if (currentBody.kind !== 'planet' ||
970
- currentBody.game !== game ||
971
- currentBody.systemSequenceId !== stake.systemSeqId ||
972
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
973
- stake.body.address) {
974
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying cancellation.`, stake.body.address);
975
- }
976
- const system = currentBody.system;
977
- const player = await deriveStarbasePlayerAddress(system, character);
978
- const currencyCache = await deriveCurrencyCacheAddress(game);
979
- const [systemCandidate, playerCandidate, currencyCandidate] = await readContextRawAccounts(ctx, [system, player, currencyCache]);
980
- const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry cancellation.`);
981
- const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake's System before retrying cancellation.`);
982
- const currencyAccount = requireAccount(currencyCandidate, currencyCache, `Canonical CurrencyCache ${currencyCache} is missing for configured Game ${game}. Refresh the Game currency configuration and retry cancellation.`);
983
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
984
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
985
- if (currentSystem.game !== game ||
986
- currentSystem.sequenceId !== stake.systemSeqId ||
987
- currentSystem.starbase === undefined ||
988
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
989
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, or an active nested Starbase. Refresh the System and retry cancellation.`, system);
990
- }
991
- if (currentPlayer.playerProfile !== options.authorization.profile ||
992
- currentPlayer.character !== character ||
993
- currentPlayer.system !== system) {
994
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry cancellation.`, player);
995
- }
996
- validateCurrencyCache(currencyAccount, game, currencyCache, 'cancellation');
1055
+ const { system } = await requireStakePlanet(currentBody, stake, game, action);
1056
+ const currencyCache = await claimStakeCurrencyCache(game);
1057
+ const { currentSystem, extraAccounts: [currencyCandidate], player, playerAccount, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [currencyCache]);
1058
+ const currencyGuard = await requireCurrencyCache(currencyCandidate, currencyCache, game, action, 'Claim Stake cancellation');
997
1059
  const description = `Cancel the pending building design on Claim Stake ${stake.address} and return it to active state.`;
998
- return createPlan({
1060
+ const xp = await resolveClaimStakeXp(ctx, game, stake.address);
1061
+ return buildPlannerPlan({
999
1062
  kind: 'claim-stakes.cancel-building-changes',
1000
- preconditions: await Promise.all([
1001
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, buildings, Body, and System generation.`),
1002
- precondition(bodyAccount, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`),
1003
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, and nested Starbase.`),
1004
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, and System.`),
1005
- precondition(currencyAccount, 'The canonical CurrencyCache remains assigned to the configured Game.'),
1006
- ]),
1063
+ preconditions: [
1064
+ xp.guard,
1065
+ ...(await Promise.all([
1066
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, design sequence, buildings, Body, and System generation.`),
1067
+ planetPrecondition(bodyAccount, system),
1068
+ systemPrecondition(systemAccount, currentSystem.name),
1069
+ playerPrecondition(playerAccount, player),
1070
+ ])),
1071
+ currencyGuard,
1072
+ ...rent.guards,
1073
+ ],
1007
1074
  steps: [
1008
1075
  {
1009
1076
  describes: description,
1010
1077
  instruction: adaptCancelClaimStakeBuildingChangesInstruction({
1078
+ ...xp.accounts,
1011
1079
  authorization: options.authorization,
1012
1080
  celestialBody: stake.body.address,
1013
1081
  claimStakeInstance: stake.address,
1014
1082
  currencyCache,
1015
1083
  game,
1084
+ ...rent.accounts,
1016
1085
  starbasePlayer: player,
1017
1086
  system,
1018
1087
  }),
@@ -1024,13 +1093,19 @@ export async function planCancelClaimStakeBuildingChanges(ctx, stake, input) {
1024
1093
  }
1025
1094
  /** Plans deconstruction of one owned active Claim Stake.
1026
1095
  *
1027
- * The planner derives the current Planet chronology index and exact plot bucket
1028
- * from the Claim Stake definition tier and fresh Body plot matrix. The only
1096
+ * The planner derives the plot level from the fresh Planet plot row that
1097
+ * records the stake, and the index from its position in that row. The only
1029
1098
  * remaining building must be the definition-compatible zero-cost bundled hub,
1030
1099
  * which deconstruction discards.
1031
1100
  * Rent settlement, cargo return, account closure, and concurrent races remain
1032
1101
  * chain-authoritative; the Plan does not estimate a refund.
1033
1102
  *
1103
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
1104
+ * settlement authority must not exist, and both stay guarded absent until
1105
+ * signing. The instruction carries no rent history. Deconstruction also
1106
+ * requires the canonical Currency Cache and closes the Claim Stake's XP ledger;
1107
+ * a Claim Stake without a ledger accrued no XP.
1108
+ *
1034
1109
  * @example
1035
1110
  * ```ts
1036
1111
  * declare const ctx: SageContext;
@@ -1043,46 +1118,27 @@ export async function planCancelClaimStakeBuildingChanges(ctx, stake, input) {
1043
1118
  export async function planDeconstructClaimStake(ctx, stake, input) {
1044
1119
  const options = validateDeconstructOptions(input);
1045
1120
  const game = requireGameAddress(ctx);
1121
+ const { profile } = options.authorization;
1046
1122
  if (stake.state.kind !== 'active') {
1047
1123
  fail(`Claim Stake ${stake.address} is not in active state. Refresh it, finalize or cancel any pending design, and retry deconstruction.`, stake.address);
1048
1124
  }
1049
- if (stake.game !== game) {
1050
- fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
1051
- }
1052
- const character = await findCharacterPda(options.authorization.profile, game);
1053
- if (stake.ownerCharacter.address !== character) {
1054
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned Claim Stake, refresh it, and retry.`, stake.address);
1055
- }
1056
- const [freshGame, firstAccounts] = await Promise.all([
1125
+ const character = await requireOwnedStake(stake, game, profile);
1126
+ const action = 'deconstruction';
1127
+ const [freshGame, { bodyAccount, currentBody, currentStake, stakeAccount }, rent,] = await Promise.all([
1057
1128
  readFreshGameClaimStakeConfiguration(ctx),
1058
- readContextRawAccounts(ctx, [stake.address, stake.body.address]),
1129
+ readOwnedStake(ctx, stake, action),
1130
+ requireDisabledStakeRent(ctx, game, stake.address, action),
1059
1131
  ]);
1060
1132
  if (freshGame === undefined) {
1061
1133
  fail(`Configured Game ${game} is missing. Refresh the Game definitions and retry deconstruction.`, game);
1062
1134
  }
1063
- const stakeAccount = requireAccount(firstAccounts[0], stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry deconstruction.`);
1064
- const bodyAccount = requireAccount(firstAccounts[1], stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry deconstruction.`);
1065
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
1066
- const currentBody = decodeIndexedCelestialBodyAccount(bodyAccount);
1067
- if (currentStake.game !== game ||
1068
- currentStake.body !== stake.body.address ||
1069
- currentStake.ownerCharacter !== character ||
1070
- currentStake.claimStakeDefinitionId !== stake.claimStakeDefinitionId ||
1071
- currentStake.claimStakeDefinitionSeqId !==
1072
- stake.claimStakeDefinitionSeqId ||
1073
- currentStake.buildingDefinitionSeqId !== stake.buildingDefinitionSeqId ||
1074
- currentStake.systemSeqId !== stake.systemSeqId ||
1075
- !sameQuantities(currentStake.buildings, stake.buildings) ||
1135
+ if (!sameOwnedStake(currentStake, stake, game, profile) ||
1076
1136
  currentStake.state.kind !== 'active') {
1077
1137
  fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, active state, or System generation. Refresh it and retry deconstruction.`, stake.address);
1078
1138
  }
1079
- if (currentBody.kind !== 'planet' ||
1080
- currentBody.game !== game ||
1081
- currentBody.systemSequenceId !== stake.systemSeqId ||
1082
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
1083
- stake.body.address) {
1084
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying deconstruction.`, stake.body.address);
1085
- }
1139
+ requireCommittedCrewVersion(currentStake, stake, 'deconstructed');
1140
+ const planet = await requireStakePlanet(currentBody, stake, game, action);
1141
+ const { system } = planet;
1086
1142
  if (freshGame.data.claimStakes.sequenceId !== stake.claimStakeDefinitionSeqId) {
1087
1143
  fail(`Claim Stake ${stake.address} definition generation is stale against the current Game catalog. Refresh the Claim Stake and definitions to rule out stale local data. If the on-chain generation still differs, use a Claim Stake matching the current catalog before retrying deconstruction.`, stake.address);
1088
1144
  }
@@ -1104,92 +1160,84 @@ export async function planDeconstructClaimStake(ctx, stake, input) {
1104
1160
  bundledHub.hubValue !== claimDefinition.hubValue ||
1105
1161
  bundledHub.minimumTier !== claimDefinition.tier ||
1106
1162
  bundledHub.constructionCost.length !== 0) {
1163
+ // Only a building with a construction cost is player-funded; a zero-cost
1164
+ // hub from another definition family is a foreign bundled hub.
1107
1165
  const hasPlayerFundedBuilding = stake.buildings.some((building) => {
1108
1166
  const definition = definitions.get(building.buildingId);
1109
- return (definition === undefined ||
1110
- definition.hubValue !== claimDefinition.hubValue ||
1111
- definition.minimumTier !== claimDefinition.tier ||
1112
- definition.constructionCost.length !== 0);
1167
+ return (definition !== undefined && definition.constructionCost.length !== 0);
1113
1168
  });
1114
1169
  fail(hasPlayerFundedBuilding
1115
1170
  ? `Claim Stake ${stake.address} still contains a player-funded building. Remove and finalize every player-funded building so only its verified bundled hub remains before retrying deconstruction.`
1116
- : `Claim Stake ${stake.address} does not contain exactly one verified bundled hub. Refresh it and restore the definition-compatible bundled hub before retrying deconstruction.`, stake.address);
1117
- }
1118
- const groups = currentBody.details.claimedPlots.filter(({ key }) => key === claimDefinition.id);
1119
- if (groups.length !== 1) {
1120
- fail(`Claim Stake definition ${String(claimDefinition.id)} does not have exactly one coherent group in Planet ${stake.body.address}'s Claim Stake Body data. Refresh the Body before retrying deconstruction.`, stake.body.address);
1121
- }
1122
- const group = groups[0];
1123
- const chronologyMatches = group.chronoAddresses
1124
- .map((address, index) => ({ address, index }))
1125
- .filter(({ address }) => address === stake.address);
1126
- if (chronologyMatches.length !== 1) {
1127
- fail(`Claim Stake ${stake.address} must appear exactly once in the Planet chronology before its deconstruction index can be derived. Refresh the Body and retry.`, stake.body.address);
1128
- }
1129
- const activeStructures = group.structures.filter(({ address, deactivationTimeUnixSeconds }) => address === stake.address && deactivationTimeUnixSeconds === 0n);
1171
+ : bundledHub === undefined
1172
+ ? `Claim Stake ${stake.address} does not contain exactly one verified bundled hub. Refresh it and restore the definition-compatible bundled hub before retrying deconstruction.`
1173
+ : `Claim Stake ${stake.address} holds ${bundledHub.name} (${String(bundledHub.id)}), which is not the zero-cost ${claimDefinition.tier} bundled hub for Claim Stake definition ${String(claimDefinition.id)} (${claimDefinition.name}). Refresh the Claim Stake and Game definitions so the recorded hub matches its definition before retrying deconstruction.`, stake.address);
1174
+ }
1175
+ // Each plot row is a Starbase level; the stake's row and its position in
1176
+ // that row's chronology give the deconstruction level and index.
1177
+ const positions = claimStakePlotPositions(planet.details.claimedPlots, stake.address);
1178
+ if (positions.length !== 1) {
1179
+ fail(`Claim Stake ${stake.address} must appear exactly once in Planet ${stake.body.address}'s plot chronology before its deconstruction level and index can be derived. Refresh the Body and retry.`, stake.body.address);
1180
+ }
1181
+ const { index: claimStakeIndex, row } = positions[0];
1182
+ const rowGroups = planet.details.claimedPlots.filter(({ key }) => key === row);
1183
+ if (!Number.isInteger(row) ||
1184
+ row < 0 ||
1185
+ row >= CLAIM_STAKE_PLOT_ROWS ||
1186
+ rowGroups.length !== 1) {
1187
+ fail(`Planet ${stake.body.address} records Claim Stake ${stake.address} in plot row ${String(row)}, which is not exactly one Starbase level row. Refresh the Body and verify the pinned binding version before retrying deconstruction.`, stake.body.address);
1188
+ }
1189
+ const activeStructures = rowGroups[0].structures.filter(({ address, deactivationTimeUnixSeconds }) => address === stake.address && deactivationTimeUnixSeconds === 0n);
1130
1190
  if (activeStructures.length !== 1) {
1131
1191
  fail(`Claim Stake ${stake.address} is not represented exactly once as an active structure in the Planet Body data. Refresh the Body and retry deconstruction.`, stake.body.address);
1132
1192
  }
1133
- const claimStakeIndex = chronologyMatches[0].index;
1134
- const tierIndex = TIER_INDEX[claimDefinition.tier];
1135
- const plotCapacities = currentBody.details.claimStakePlots.map((row) => row[tierIndex]);
1136
- if (plotCapacities.some((capacity, index) => index > 0 && capacity < plotCapacities[index - 1])) {
1137
- fail(`Planet ${stake.body.address} Claim Stake plot capacity is not coherent across Starbase levels for definition tier ${claimDefinition.tier}. Refresh the Body and verify the pinned binding version before retrying deconstruction.`, stake.body.address);
1138
- }
1139
- if (group.chronoAddresses.length > plotCapacities[plotCapacities.length - 1]) {
1140
- fail(`Planet ${stake.body.address} Claim Stake plot capacity does not cover its definition-group chronology. Refresh the Body before retrying deconstruction.`, stake.body.address);
1141
- }
1142
- const plotLevelIndex = plotCapacities.findIndex((capacity) => claimStakeIndex < capacity);
1143
- const claimStakeLevel = CLAIM_STAKE_PLOT_LEVELS[plotLevelIndex];
1144
- const system = currentBody.system;
1145
- const player = await deriveStarbasePlayerAddress(system, character);
1146
- const [characterCandidate, systemCandidate, playerCandidate] = await readContextRawAccounts(ctx, [character, system, player]);
1147
- const characterAccount = requireAccount(characterCandidate, character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry deconstruction.`);
1148
- const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry deconstruction.`);
1149
- const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake's System before retrying deconstruction.`);
1150
- const currentCharacter = characterAccountDefinition.decode(characterAccount);
1151
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
1152
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
1153
- if (currentCharacter.playerProfile !== options.authorization.profile ||
1154
- currentCharacter.game !== game) {
1155
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry deconstruction.`, character);
1156
- }
1157
- if (currentSystem.game !== game ||
1158
- currentSystem.sequenceId !== stake.systemSeqId ||
1159
- currentSystem.starbase === undefined ||
1160
- !currentSystem.celestialBodyAddresses.includes(stake.body.address) ||
1161
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
1162
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, or an active nested Starbase. Refresh the System and retry deconstruction.`, system);
1163
- }
1164
- if (currentPlayer.playerProfile !== options.authorization.profile ||
1165
- currentPlayer.character !== character ||
1166
- currentPlayer.system !== system) {
1167
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry deconstruction.`, player);
1168
- }
1193
+ const claimStakeLevel = CLAIM_STAKE_PLOT_LEVELS[row];
1194
+ const [currencyCache, [xpAccrual]] = await Promise.all([
1195
+ claimStakeCurrencyCache(game),
1196
+ deriveStructureXpAccrualAddress(stake.address),
1197
+ ]);
1198
+ const { currentSystem, extraAccounts: [characterCandidate, currencyCandidate, ledgerCandidate], player, playerAccount, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [character, currencyCache, xpAccrual]);
1199
+ const { account: characterAccount } = requireProfileCharacter(characterCandidate, character, profile, game, action);
1200
+ const currencyGuard = await requireCurrencyCache(currencyCandidate, currencyCache, game, action, 'Claim Stake deconstruction');
1201
+ // Deconstruction closes an existing XP ledger; a stake without one accrued nothing.
1202
+ const xp = ledgerCandidate === undefined
1203
+ ? {
1204
+ accounts: {},
1205
+ guard: accountAbsentPrecondition(xpAccrual, `Claim Stake ${stake.address} XP ledger ${xpAccrual} remains absent, so no Building XP has accrued.`),
1206
+ }
1207
+ : await resolveClaimStakeXp(ctx, game, stake.address, character);
1169
1208
  const description = `Deconstruct Claim Stake ${stake.address} and discard its bundled hub ${bundledHub.name}; rent settlement, cargo return, account closure, and any refund remain chain-authoritative.`;
1170
- return createPlan({
1209
+ return buildPlannerPlan({
1171
1210
  kind: 'claim-stakes.deconstruct',
1172
- preconditions: await Promise.all([
1173
- precondition(freshGame.account, `The configured Game retains Claim Stake definition ${String(claimDefinition.id)}, bundled hub ${String(bundledHub.id)}, and their current generations.`),
1174
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, active state, definitions, bundled hub, Body, and System generation.`),
1175
- precondition(bodyAccount, `The Planet retains Claim Stake ${stake.address} at chronology index ${String(claimStakeIndex)} in definition group ${String(claimDefinition.id)}.`),
1176
- precondition(characterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} in the configured Game.`),
1177
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, nested Starbase, and Claim Stake Body relationship.`),
1178
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, and System.`),
1179
- ]),
1211
+ preconditions: [
1212
+ ...(await Promise.all([
1213
+ accountStatePrecondition(freshGame.account, `The configured Game retains Claim Stake definition ${String(claimDefinition.id)}, bundled hub ${String(bundledHub.id)}, and their current generations.`),
1214
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, active state, definitions, bundled hub, Body, and System generation.`),
1215
+ accountStatePrecondition(bodyAccount, `The Planet retains Claim Stake ${stake.address} at chronology index ${String(claimStakeIndex)} in definition group ${String(claimDefinition.id)}.`),
1216
+ characterPrecondition(characterAccount, profile),
1217
+ systemPrecondition(systemAccount, currentSystem.name),
1218
+ playerPrecondition(playerAccount, player),
1219
+ ])),
1220
+ currencyGuard,
1221
+ xp.guard,
1222
+ ...rent.guards,
1223
+ ],
1180
1224
  steps: [
1181
1225
  {
1182
1226
  describes: description,
1183
1227
  instruction: adaptDeconstructClaimStakeInstruction({
1228
+ ...xp.accounts,
1184
1229
  authorization: options.authorization,
1185
1230
  celestialBody: stake.body.address,
1186
1231
  character,
1187
1232
  claimStakeIndex,
1188
1233
  claimStakeInstance: stake.address,
1189
1234
  claimStakeLevel,
1235
+ currencyCache,
1190
1236
  game,
1237
+ ...rent.accounts,
1191
1238
  systemAndStarbasePlayerStarbasePlayer: player,
1192
1239
  systemAndStarbasePlayerSystem: system,
1240
+ xpAccrual,
1193
1241
  }),
1194
1242
  signers: [options.authorization.authority],
1195
1243
  },
@@ -1197,13 +1245,19 @@ export async function planDeconstructClaimStake(ctx, stake, input) {
1197
1245
  summary: description,
1198
1246
  });
1199
1247
  }
1200
- /** Plans one exact raw rent top-up for an owned placed Claim Stake.
1248
+ /** Plans one exact raw rent top-up for an owned Claim Stake.
1201
1249
  *
1250
+ * Active, design and Deactivated (rent-delinquent) stakes all accept a top-up;
1251
+ * topping up a Deactivated stake is how its owner keeps it from eviction.
1202
1252
  * The planner validates the fresh Claim Stake and its canonical
1203
1253
  * Profile/Character/Planet/System/Starbase Player graph, plus the Character's
1204
1254
  * known raw ATLAS balance. Permission checks, concurrent balance changes, rent
1205
1255
  * arithmetic, and duration purchased remain chain-authoritative.
1206
1256
  *
1257
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
1258
+ * settlement authority must not exist, and both stay guarded absent until
1259
+ * signing. The instruction carries no rent history.
1260
+ *
1207
1261
  * @example
1208
1262
  * ```ts
1209
1263
  * declare const ctx: SageContext;
@@ -1219,87 +1273,40 @@ export async function planDeconstructClaimStake(ctx, stake, input) {
1219
1273
  export async function planTopUpClaimStakeRent(ctx, stake, input) {
1220
1274
  const options = validateTopUpRentOptions(input);
1221
1275
  const game = requireGameAddress(ctx);
1276
+ const { profile } = options.authorization;
1277
+ // Under Disabled rent a top-up has no lifecycle gate: a Deactivated stake
1278
+ // accepts one, and that is how its owner avoids eviction.
1222
1279
  const loadedState = stake.state;
1223
- if (loadedState.kind === 'deactivated') {
1224
- fail(`Claim Stake ${stake.address} is not placed. Refresh it and choose an active Claim Stake or pending building design before topping up rent.`, stake.address);
1225
- }
1226
- if (stake.game !== game) {
1227
- fail(`Claim Stake ${stake.address} does not match the configured Game ${game}. Refresh it through this context and retry.`, stake.address);
1228
- }
1229
- const character = await findCharacterPda(options.authorization.profile, game);
1230
- if (stake.ownerCharacter.address !== character) {
1231
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned Claim Stake, refresh it, and retry.`, stake.address);
1232
- }
1233
- const firstAccounts = await readContextRawAccounts(ctx, [
1234
- stake.address,
1235
- stake.body.address,
1236
- character,
1280
+ const character = await requireOwnedStake(stake, game, profile);
1281
+ const action = 'the rent top-up';
1282
+ const [{ bodyAccount, currentBody, currentStake, extraAccounts: [characterCandidate], stakeAccount, }, rent,] = await Promise.all([
1283
+ readOwnedStake(ctx, stake, action, [character]),
1284
+ requireDisabledStakeRent(ctx, game, stake.address, action),
1237
1285
  ]);
1238
- const stakeAccount = requireAccount(firstAccounts[0], stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry the rent top-up.`);
1239
- const bodyAccount = requireAccount(firstAccounts[1], stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry the rent top-up.`);
1240
- const characterAccount = requireAccount(firstAccounts[2], character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry the rent top-up.`);
1241
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
1242
- const currentBody = celestialBodyAccountDefinition.decode(bodyAccount);
1243
- const currentCharacter = characterAccountDefinition.decode(characterAccount);
1244
- if (currentStake.game !== game ||
1245
- currentStake.body !== stake.body.address ||
1246
- currentStake.ownerCharacter !== character ||
1247
- currentStake.claimStakeDefinitionId !== stake.claimStakeDefinitionId ||
1248
- currentStake.claimStakeDefinitionSeqId !==
1249
- stake.claimStakeDefinitionSeqId ||
1250
- currentStake.buildingDefinitionSeqId !== stake.buildingDefinitionSeqId ||
1251
- currentStake.systemSeqId !== stake.systemSeqId ||
1286
+ if (!sameOwnedStake(currentStake, stake, game, profile) ||
1252
1287
  currentStake.rentBalanceRaw !== stake.rentBalanceRaw ||
1253
- !sameQuantities(currentStake.buildings, stake.buildings) ||
1254
1288
  !sameStakeState(currentStake.state, loadedState)) {
1255
- fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, rent balance, placed state, or System generation. Refresh it and retry the rent top-up.`, stake.address);
1256
- }
1257
- if (currentBody.kind !== 'planet' ||
1258
- currentBody.game !== game ||
1259
- currentBody.systemSequenceId !== stake.systemSeqId ||
1260
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
1261
- stake.body.address) {
1262
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying the rent top-up.`, stake.body.address);
1263
- }
1264
- if (currentCharacter.playerProfile !== options.authorization.profile ||
1265
- currentCharacter.game !== game) {
1266
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry the rent top-up.`, character);
1289
+ fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, rent balance, lifecycle state, or System generation. Refresh it and retry the rent top-up.`, stake.address);
1267
1290
  }
1291
+ const { system } = await requireStakePlanet(currentBody, stake, game, action);
1292
+ const { account: characterAccount, current: currentCharacter } = requireProfileCharacter(characterCandidate, character, profile, game, action);
1268
1293
  if (currentCharacter.atlasRaw < options.amount) {
1269
1294
  fail(`Character ${character} has only ${String(currentCharacter.atlasRaw)} known raw ATLAS, below the requested ${String(options.amount)} raw rent top-up. Reduce the amount or add ATLAS, refresh the Character, and retry.`, character);
1270
1295
  }
1271
- const system = currentBody.system;
1272
- const player = await deriveStarbasePlayerAddress(system, character);
1273
- const [systemCandidate, playerCandidate] = await readContextRawAccounts(ctx, [
1274
- system,
1275
- player,
1276
- ]);
1277
- const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake's System and retry the rent top-up.`);
1278
- const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake's System before retrying the rent top-up.`);
1279
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
1280
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
1281
- if (currentSystem.game !== game ||
1282
- currentSystem.sequenceId !== stake.systemSeqId ||
1283
- currentSystem.starbase === undefined ||
1284
- !currentSystem.celestialBodyAddresses.includes(stake.body.address) ||
1285
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
1286
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, active nested Starbase, or Claim Stake Body relationship. Refresh the System and retry the rent top-up.`, system);
1287
- }
1288
- if (currentPlayer.playerProfile !== options.authorization.profile ||
1289
- currentPlayer.character !== character ||
1290
- currentPlayer.system !== system) {
1291
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry the rent top-up.`, player);
1292
- }
1296
+ const { currentSystem, player, playerAccount, systemAccount } = await readStakeStarbase(ctx, stake, game, system, character, profile, action);
1293
1297
  const description = `Top up Claim Stake ${stake.address} rent with ${String(options.amount)} raw rent units; rent arithmetic remains chain-authoritative.`;
1294
- return createPlan({
1298
+ return buildPlannerPlan({
1295
1299
  kind: 'claim-stakes.top-up-rent',
1296
- preconditions: await Promise.all([
1297
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, rent balance, placed state, Body, and System generation.`),
1298
- precondition(bodyAccount, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`),
1299
- precondition(characterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} with at least ${String(options.amount)} known raw ATLAS.`),
1300
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, nested Starbase, and Claim Stake Body relationship.`),
1301
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, and System.`),
1302
- ]),
1300
+ preconditions: [
1301
+ ...(await Promise.all([
1302
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, rent balance, lifecycle state, Body, and System generation.`),
1303
+ planetPrecondition(bodyAccount, system),
1304
+ accountStatePrecondition(characterAccount, `The canonical Character remains assigned to Profile ${profile} with at least ${String(options.amount)} known raw ATLAS.`),
1305
+ systemPrecondition(systemAccount, currentSystem.name),
1306
+ playerPrecondition(playerAccount, player),
1307
+ ])),
1308
+ ...rent.guards,
1309
+ ],
1303
1310
  steps: [
1304
1311
  {
1305
1312
  describes: description,
@@ -1310,6 +1317,7 @@ export async function planTopUpClaimStakeRent(ctx, stake, input) {
1310
1317
  character,
1311
1318
  claimStakeInstance: stake.address,
1312
1319
  game,
1320
+ ...rent.accounts,
1313
1321
  systemAndStarbasePlayerStarbasePlayer: player,
1314
1322
  systemAndStarbasePlayerSystem: system,
1315
1323
  }),
@@ -1341,10 +1349,10 @@ function requireTransferCapacity(destination, address, used, requested, total) {
1341
1349
  fail(`${destination} has ${String(remaining)} raw capacity units remaining, but this transfer requires ${String(requested)}. Reduce the request or free capacity, refresh both snapshots, and retry.`, address);
1342
1350
  }
1343
1351
  }
1344
- function fleetCargoAmount(fleet, cargoId) {
1345
- return ((fleet.ammoBank.cargoId === cargoId ? fleet.ammoBank.amount : 0n) +
1346
- (fleet.fuelTank.cargoId === cargoId ? fleet.fuelTank.amount : 0n) +
1347
- cargoAmount(fleet.cargoHold.amounts, cargoId));
1352
+ /** Reads a Fleet's cargo-hold balance; Claim Stake transfers never touch the
1353
+ * fuel tank or ammo bank, so Fuel and Ammunition count only when in the hold. */
1354
+ function fleetCargoHoldAmount(fleet, cargoId) {
1355
+ return cargoAmount(fleet.cargoHold.amounts, cargoId);
1348
1356
  }
1349
1357
  function describeCargoRequests(direction, requests) {
1350
1358
  return requests.map(({ amount, cargoId }) => `${direction} cargo id ${String(cargoId)} = ${String(amount)} raw ${amount === 1n ? 'unit' : 'units'}`);
@@ -1354,8 +1362,18 @@ function describeCargoRequests(direction, requests) {
1354
1362
  * The planner validates the shared Profile/Game, idle Fleet with normalized
1355
1363
  * crew, active Claim Stake, canonical Planet/System/Starbase Player graph,
1356
1364
  * exact source balances, exact destination capacities, and an optional present
1357
- * FleetCrewBinding. The chain remains authoritative for range, duration,
1358
- * permission bits, concurrent state changes, and transfer arithmetic.
1365
+ * FleetCrewBinding. Both legs use the Fleet cargo hold only: loaded Fuel and
1366
+ * Ammunition arrive in the cargo hold and consume cargo capacity, and unloads
1367
+ * are sourced from the cargo hold, never from the fuel tank or ammo bank. The
1368
+ * chain remains authoritative for range, duration, permission bits, concurrent
1369
+ * state changes, and transfer arithmetic.
1370
+ *
1371
+ * Requires Game 2 and its existing canonical Claim Stake XP ledger.
1372
+ * Missing XP state must be repaired outside this Plan; no accounts are created.
1373
+ *
1374
+ * Requires Disabled rent: the Game's rent catalog and the Claim Stake's rent
1375
+ * settlement authority must not exist, and both stay guarded absent until
1376
+ * signing. The instruction carries no rent history.
1359
1377
  *
1360
1378
  * @example
1361
1379
  * ```ts
@@ -1374,119 +1392,56 @@ function describeCargoRequests(direction, requests) {
1374
1392
  export async function planStartClaimStakeFleetTransfer(ctx, fleet, stake, input) {
1375
1393
  const options = validateStartFleetTransferOptions(input);
1376
1394
  const game = requireGameAddress(ctx);
1395
+ const { profile } = options.authorization;
1377
1396
  if (fleet.game !== game || stake.game !== game) {
1378
1397
  fail(`Fleet ${fleet.address} and Claim Stake ${stake.address} must both belong to configured Game ${game}. Refresh both snapshots through this context and retry.`, fleet.game !== game ? fleet.address : stake.address);
1379
1398
  }
1380
- if (fleet.ownerProfile.address !== options.authorization.profile) {
1381
- fail(`Fleet ${fleet.name} belongs to Profile ${fleet.ownerProfile.address}, not authorization Profile ${options.authorization.profile}. Use the owning Profile, refresh the Fleet, and retry.`, fleet.address);
1399
+ if (fleet.ownerProfile.address !== profile) {
1400
+ fail(`Fleet ${fleet.name} belongs to Profile ${fleet.ownerProfile.address}, not authorization Profile ${profile}. Use the owning Profile, refresh the Fleet, and retry.`, fleet.address);
1382
1401
  }
1383
1402
  if (fleet.state.kind !== 'idle') {
1384
1403
  fail(`Fleet ${fleet.name} is ${fleet.state.kind}, but starting a Claim Stake transfer requires an idle Fleet. Return it to idle state, refresh it, and retry.`, fleet.address);
1385
1404
  }
1405
+ const crewFailure = `Fleet ${fleet.name} has no valid normalized crew and cannot start a Claim Stake transfer. Crew the Fleet, refresh it, and retry.`;
1386
1406
  if (!Number.isSafeInteger(fleet.crewCount) || fleet.crewCount <= 0) {
1387
- fail(`Fleet ${fleet.name} has no valid normalized crew and cannot start a Claim Stake transfer. Crew the Fleet, refresh it, and retry.`, fleet.address);
1407
+ fail(crewFailure, fleet.address);
1388
1408
  }
1389
1409
  if (stake.state.kind !== 'active') {
1390
1410
  fail(`Claim Stake ${stake.address} is ${stake.state.kind}, but starting a Fleet transfer requires an active Claim Stake. Activate or restore it, refresh it, and retry.`, stake.address);
1391
1411
  }
1392
- const character = await findCharacterPda(options.authorization.profile, game);
1393
- if (stake.ownerCharacter.address !== character) {
1394
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Choose an owned active Claim Stake, refresh it, and retry.`, stake.address);
1395
- }
1396
- const [fleetCandidate, stakeCandidate, bodyCandidate, characterCandidate] = await readContextRawAccounts(ctx, [
1397
- fleet.address,
1398
- stake.address,
1399
- stake.body.address,
1400
- character,
1412
+ const character = await requireOwnedStake(stake, game, profile);
1413
+ const action = 'the Fleet transfer';
1414
+ const [{ bodyAccount, currentBody, currentStake, extraAccounts: [fleetCandidate, characterCandidate], stakeAccount, }, rent,] = await Promise.all([
1415
+ readOwnedStake(ctx, stake, action, [fleet.address, character]),
1416
+ requireDisabledStakeRent(ctx, game, stake.address, action),
1401
1417
  ]);
1402
- const fleetAccount = requireAccount(fleetCandidate, fleet.address, `Fleet ${fleet.name} is missing. Refresh it and retry the Claim Stake transfer.`);
1403
- const stakeAccount = requireAccount(stakeCandidate, stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry the Fleet transfer.`);
1404
- const bodyAccount = requireAccount(bodyCandidate, stake.body.address, `Celestial Body ${stake.body.address} is missing. Refresh the Claim Stake Body and retry the Fleet transfer.`);
1405
- const characterAccount = requireAccount(characterCandidate, character, `Canonical Character ${character} is missing. Refresh the Profile Character and retry the Claim Stake transfer.`);
1418
+ const fleetAccount = requireAccount(fleetCandidate, fleet.address, `Fleet ${fleet.name} is missing. Refresh it and retry the Fleet transfer.`);
1406
1419
  const currentFleet = fleetAccountDefinition.decode(fleetAccount);
1407
- const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
1408
- const currentBody = celestialBodyAccountDefinition.decode(bodyAccount);
1409
- const currentCharacter = characterAccountDefinition.decode(characterAccount);
1410
1420
  if (!Number.isSafeInteger(currentFleet.crewCount) ||
1411
1421
  currentFleet.crewCount <= 0) {
1412
- fail(`Fleet ${fleet.name} has no valid normalized crew and cannot start a Claim Stake transfer. Crew the Fleet, refresh it, and retry.`, fleet.address);
1422
+ fail(crewFailure, fleet.address);
1413
1423
  }
1414
- if (currentFleet.game !== game ||
1415
- currentFleet.ownerProfile !== options.authorization.profile ||
1416
- currentFleet.name !== fleet.name ||
1424
+ if (!sameTransferFleet(currentFleet, fleet, game, profile) ||
1417
1425
  currentFleet.state.kind !== 'idle' ||
1418
1426
  currentFleet.crewCount !== fleet.crewCount ||
1419
- (await deriveFleetAddress(currentFleet)) !== fleet.address ||
1420
- currentFleet.ammoBank.cargoId !== fleet.ammo.id ||
1421
- currentFleet.ammoBank.amount !== fleet.ammo.amount ||
1422
- currentFleet.fuelTank.cargoId !== fleet.fuel.id ||
1423
- currentFleet.fuelTank.amount !== fleet.fuel.amount ||
1424
- currentFleet.cargoHold.storageCost !== fleet.cargoHold.storageCost ||
1425
- !sameCargoAmounts(currentFleet.cargoHold.amounts, fleet.cargoHold.items) ||
1426
- currentFleet.stats.cargo.ammoCapacity !== fleet.capacities.ammo.total ||
1427
- currentFleet.stats.cargo.fuelCapacity !== fleet.capacities.fuel.total ||
1428
- currentFleet.stats.cargo.cargoCapacity !== fleet.capacities.cargo.total) {
1427
+ (await deriveFleetAddress(currentFleet)) !== fleet.address) {
1429
1428
  fail(`Fleet ${fleet.name} changed or no longer matches its loaded Game, owner, canonical address, name, idle state, normalized crew, cargo, or capacities. Refresh it and create a new Claim Stake transfer Plan.`, fleet.address);
1430
1429
  }
1431
- if (currentStake.game !== game ||
1432
- currentStake.ownerCharacter !== character ||
1433
- currentStake.body !== stake.body.address ||
1434
- currentStake.systemSeqId !== stake.systemSeqId ||
1435
- currentStake.state.kind !== 'active' ||
1436
- currentStake.production.cargoPod.storageCost !==
1437
- stake.resources.capacity.usedRaw ||
1438
- currentStake.production.resourceCapacityRaw !==
1439
- stake.resources.capacity.totalRaw ||
1440
- !sameCargoAmounts(currentStake.production.cargoPod.amounts, stake.resources.inventory.items.map(({ id, quantityRaw }) => ({
1441
- amount: quantityRaw,
1442
- id,
1443
- })))) {
1430
+ if (!sameTransferStake(currentStake, stake, game, profile)) {
1444
1431
  fail(`Claim Stake ${stake.address} changed or no longer matches its loaded Game, owner, Body, active state, resources, capacity, or System generation. Refresh it and create a new Fleet transfer Plan.`, stake.address);
1445
1432
  }
1446
- if (currentBody.kind !== 'planet' ||
1447
- currentBody.game !== game ||
1448
- currentBody.systemSequenceId !== stake.systemSeqId ||
1449
- (await deriveCelestialBodyAddress(game, currentBody.id)) !==
1450
- stake.body.address) {
1451
- fail(`Celestial Body ${stake.body.address} does not match the Claim Stake's configured Game, canonical Planet identity, or System generation. Refresh the Body and Claim Stake before retrying the Fleet transfer.`, stake.body.address);
1452
- }
1453
- if (currentCharacter.playerProfile !== options.authorization.profile ||
1454
- currentCharacter.game !== game) {
1455
- fail(`Character ${character} does not match authorization Profile ${options.authorization.profile} and configured Game ${game}. Refresh the Character and retry the Claim Stake transfer.`, character);
1456
- }
1457
- const system = currentBody.system;
1458
- const player = await deriveStarbasePlayerAddress(system, character);
1459
- const currencyCache = await deriveCurrencyCacheAddress(game);
1460
- const crewBinding = await deriveFleetCrewBindingAddress(fleet.address);
1461
- const [systemCandidate, playerCandidate, currencyCandidate, crewCandidate] = await readContextRawAccounts(ctx, [
1462
- system,
1463
- player,
1464
- currencyCache,
1465
- crewBinding,
1433
+ const { system } = await requireStakePlanet(currentBody, stake, game, action);
1434
+ const { account: characterAccount } = requireProfileCharacter(characterCandidate, character, profile, game, action);
1435
+ const [currencyCache, crewBinding] = await Promise.all([
1436
+ claimStakeCurrencyCache(game),
1437
+ deriveFleetCrewBindingAddress(fleet.address),
1466
1438
  ]);
1467
- const systemAccount = requireAccount(systemCandidate, system, `Star System ${system} is missing. Refresh the Claim Stake System and retry the Fleet transfer.`);
1468
- const playerAccount = requireAccount(playerCandidate, player, `Starbase Player ${player} is missing for authorization Profile ${options.authorization.profile}. Register or refresh it in the Claim Stake System before retrying the Fleet transfer.`);
1469
- const currencyAccount = requireAccount(currencyCandidate, currencyCache, `Canonical CurrencyCache ${currencyCache} is missing for configured Game ${game}. Refresh the Game currency configuration and retry the Fleet transfer.`);
1470
- const currentSystem = starSystemAccountDefinition.decode(systemAccount);
1471
- const currentPlayer = starbasePlayerAccountDefinition.decode(playerAccount);
1472
- if (currentSystem.game !== game ||
1473
- currentSystem.sequenceId !== stake.systemSeqId ||
1474
- currentSystem.starbase === undefined ||
1475
- !currentSystem.celestialBodyAddresses.includes(stake.body.address) ||
1476
- (await deriveStarSystemAddress(game, currentSystem.systemId)) !== system) {
1477
- fail(`Star System ${system} does not match the configured Game, canonical identity, Claim Stake generation, nested Starbase, or Claim Stake Body relationship. Refresh the System and retry the Fleet transfer.`, system);
1478
- }
1479
- if (currentPlayer.playerProfile !== options.authorization.profile ||
1480
- currentPlayer.character !== character ||
1481
- currentPlayer.system !== system) {
1482
- fail(`Starbase Player ${player} does not match the authorization Profile, canonical Character, and Claim Stake System. Refresh it and retry the Fleet transfer.`, player);
1483
- }
1484
- validateCurrencyCache(currencyAccount, game, currencyCache, 'the Claim Stake Fleet transfer');
1439
+ const { currentSystem, extraAccounts: [currencyCandidate, crewCandidate], player, playerAccount, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [currencyCache, crewBinding]);
1440
+ const currencyGuard = await requireCurrencyCache(currencyCandidate, currencyCache, game, action, 'Claim Stake Fleet transfer');
1485
1441
  if (crewCandidate !== undefined) {
1486
1442
  const currentCrewBinding = fleetCrewBindingAccountDefinition.decode(crewCandidate);
1487
1443
  if (crewCandidate.address !== crewBinding ||
1488
- currentCrewBinding.fleet !== fleet.address ||
1489
- currentCrewBinding.ownerProfile !== options.authorization.profile) {
1444
+ !matchesFleetCrewBindingIdentity(currentCrewBinding, fleet.address, profile)) {
1490
1445
  fail(`FleetCrewBinding ${crewCandidate.address} does not match Fleet ${fleet.address}, its owner Profile, or its canonical PDA. Refresh the Fleet crew registration or remove the invalid binding before retrying.`, crewCandidate.address);
1491
1446
  }
1492
1447
  }
@@ -1498,48 +1453,44 @@ export async function planStartClaimStakeFleetTransfer(ctx, fleet, stake, input)
1498
1453
  requireCargoBalance(`Claim Stake ${stake.address}`, stake.address, request.cargoId, cargoAmount(currentStake.production.cargoPod.amounts, request.cargoId), request.amount);
1499
1454
  }
1500
1455
  for (const request of options.unload) {
1501
- requireCargoBalance(`Fleet ${fleet.name}`, fleet.address, request.cargoId, fleetCargoAmount(currentFleet, request.cargoId), request.amount);
1502
- }
1503
- const loadAmmo = options.load
1504
- .filter(({ cargoId }) => cargoId === currentFleet.ammoBank.cargoId)
1505
- .reduce((total, { amount }) => total + amount, 0n);
1506
- const loadFuel = options.load
1507
- .filter(({ cargoId }) => cargoId === currentFleet.fuelTank.cargoId)
1508
- .reduce((total, { amount }) => total + amount, 0n);
1509
- const loadCargoStorage = options.load
1510
- .filter(({ cargoId }) => cargoId !== currentFleet.ammoBank.cargoId &&
1511
- cargoId !== currentFleet.fuelTank.cargoId)
1512
- .reduce((total, { amount, cargoId }) => total + amount * BigInt(definitions.get(cargoId).storageCost), 0n);
1513
- requireTransferCapacity(`Fleet ${fleet.name} ammo destination`, fleet.address, currentFleet.ammoBank.amount, loadAmmo, currentFleet.stats.cargo.ammoCapacity);
1514
- requireTransferCapacity(`Fleet ${fleet.name} fuel destination`, fleet.address, currentFleet.fuelTank.amount, loadFuel, currentFleet.stats.cargo.fuelCapacity);
1456
+ requireCargoBalance(`Fleet ${fleet.name}`, fleet.address, request.cargoId, fleetCargoHoldAmount(currentFleet, request.cargoId), request.amount);
1457
+ }
1458
+ // Every load, including Fuel and Ammunition, lands in the cargo hold.
1459
+ const loadCargoStorage = options.load.reduce((total, { amount, cargoId }) => total + cargoStorageUnits(amount, definitions.get(cargoId).storageCost), 0n);
1515
1460
  requireTransferCapacity(`Fleet ${fleet.name} cargo destination`, fleet.address, currentFleet.cargoHold.storageCost, loadCargoStorage, currentFleet.stats.cargo.cargoCapacity);
1516
- const unloadStorage = options.unload.reduce((total, { amount, cargoId }) => total + amount * BigInt(definitions.get(cargoId).storageCost), 0n);
1461
+ const unloadStorage = options.unload.reduce((total, { amount, cargoId }) => total + cargoStorageUnits(amount, definitions.get(cargoId).storageCost), 0n);
1517
1462
  requireTransferCapacity(`Claim Stake ${stake.address} resource destination`, stake.address, currentStake.production.cargoPod.storageCost, unloadStorage, currentStake.production.resourceCapacityRaw);
1518
1463
  const descriptions = [
1519
1464
  ...describeCargoRequests('load', options.load),
1520
1465
  ...describeCargoRequests('unload', options.unload),
1521
1466
  ];
1522
- const description = `Start fleet ${fleet.name}'s transfer to Claim Stake ${stake.address}: ${descriptions.join('; ')}. Range and transfer duration remain chain-authoritative.`;
1523
- return createPlan({
1467
+ const description = `Start fleet ${fleet.name}'s transfer to Claim Stake ${stake.address}: ${descriptions.join('; ')}. Loaded cargo, including Fuel and Ammunition, arrives in the Fleet cargo hold; unloads come from the cargo hold only. Range and transfer duration remain chain-authoritative.`;
1468
+ const xp = await resolveClaimStakeXp(ctx, game, stake.address);
1469
+ return buildPlannerPlan({
1524
1470
  kind: 'claim-stakes.start-fleet-transfer',
1525
- preconditions: await Promise.all([
1526
- precondition(fleetAccount, `Fleet ${fleet.name} retains its owner, name, idle state, normalized crew, cargo balances, and destination capacities.`),
1527
- precondition(stakeAccount, `Claim Stake ${stake.address} retains its owner, active state, cargo balances, destination capacity, Body, and System generation.`),
1528
- precondition(bodyAccount, `The Claim Stake Planet remains assigned to System ${system} at the current generation.`),
1529
- precondition(characterAccount, `The canonical Character remains assigned to Profile ${options.authorization.profile} in the configured Game.`),
1530
- precondition(systemAccount, `Star System ${currentSystem.name} retains its configured Game, sequence, nested Starbase, and Claim Stake Body relationship.`),
1531
- precondition(playerAccount, `Starbase Player ${player} retains its Profile, Character, and System.`),
1532
- precondition(currencyAccount, 'The canonical CurrencyCache remains assigned to the configured Game.'),
1533
- ...(crewCandidate === undefined
1534
- ? []
1535
- : [
1536
- precondition(crewCandidate, `Fleet ${fleet.name}'s optional FleetCrewBinding remains assigned to the Fleet and owner Profile.`),
1537
- ]),
1538
- ]),
1471
+ preconditions: [
1472
+ xp.guard,
1473
+ ...(await Promise.all([
1474
+ accountStatePrecondition(fleetAccount, `Fleet ${fleet.name} retains its owner, name, idle state, normalized crew, cargo balances, and destination capacities.`),
1475
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its owner, active state, cargo balances, destination capacity, Body, and System generation.`),
1476
+ planetPrecondition(bodyAccount, system),
1477
+ characterPrecondition(characterAccount, profile),
1478
+ systemPrecondition(systemAccount, currentSystem.name),
1479
+ playerPrecondition(playerAccount, player),
1480
+ ...(crewCandidate === undefined
1481
+ ? []
1482
+ : [
1483
+ accountStatePrecondition(crewCandidate, `Fleet ${fleet.name}'s optional FleetCrewBinding remains assigned to the Fleet and owner Profile.`),
1484
+ ]),
1485
+ ])),
1486
+ currencyGuard,
1487
+ ...rent.guards,
1488
+ ],
1539
1489
  steps: [
1540
1490
  {
1541
1491
  describes: description,
1542
1492
  instruction: adaptStartClaimStakeFleetTransferInstruction({
1493
+ ...xp.accounts,
1543
1494
  authorization: options.authorization,
1544
1495
  celestialBody: stake.body.address,
1545
1496
  character,
@@ -1548,6 +1499,7 @@ export async function planStartClaimStakeFleetTransfer(ctx, fleet, stake, input)
1548
1499
  currencyCache,
1549
1500
  fleet: fleet.address,
1550
1501
  game,
1502
+ ...rent.accounts,
1551
1503
  systemAndStarbasePlayerStarbasePlayer: player,
1552
1504
  systemAndStarbasePlayerSystem: system,
1553
1505
  toLoad: options.load.map(({ amount, cargoId }) => [cargoId, amount]),
@@ -1606,10 +1558,7 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1606
1558
  if (options.atUnixSeconds < fleet.state.endAtUnixSeconds) {
1607
1559
  fail(`Fleet ${fleet.name}'s Claim Stake transfer lock has not elapsed at Unix timestamp ${String(options.atUnixSeconds)}; it ends at ${String(fleet.state.endAtUnixSeconds)}. Wait until the lock elapses, provide a current timestamp, and retry recovery.`, fleet.address);
1608
1560
  }
1609
- const character = await findCharacterPda(options.authorization.profile, game);
1610
- if (stake.ownerCharacter.address !== character) {
1611
- fail(`Claim Stake ${stake.address} does not belong to authorization Profile ${options.authorization.profile}'s canonical Character ${character}. Supply the owned current Claim Stake and retry recovery.`, stake.address);
1612
- }
1561
+ const character = await requireOwnedStake(stake, game, options.authorization.profile);
1613
1562
  const [fleetCandidate, stakeCandidate] = await readContextRawAccounts(ctx, [
1614
1563
  fleet.address,
1615
1564
  stake.address,
@@ -1618,40 +1567,17 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1618
1567
  const stakeAccount = requireAccount(stakeCandidate, stake.address, `Claim Stake ${stake.address} is missing. Refresh it and retry Fleet transfer recovery.`);
1619
1568
  const currentFleet = fleetAccountDefinition.decode(fleetAccount);
1620
1569
  const currentStake = claimStakeAccountDefinition.decode(stakeAccount);
1621
- if (currentFleet.game !== game ||
1622
- currentFleet.ownerProfile !== options.authorization.profile ||
1623
- currentFleet.name !== fleet.name ||
1570
+ if (!sameTransferFleet(currentFleet, fleet, game, options.authorization.profile) ||
1624
1571
  currentFleet.state.kind !== 'claimStakeTransfer' ||
1625
1572
  currentFleet.state.claimStake !== stake.address ||
1626
1573
  currentFleet.state.planet !== stake.body.address ||
1627
1574
  currentFleet.state.endAtUnixSeconds !== fleet.state.endAtUnixSeconds ||
1628
1575
  !sameCargoAmounts(currentFleet.state.load, fleet.state.load) ||
1629
1576
  !sameCargoAmounts(currentFleet.state.unload, fleet.state.unload) ||
1630
- (await deriveFleetAddress(currentFleet)) !== fleet.address ||
1631
- currentFleet.ammoBank.cargoId !== fleet.ammo.id ||
1632
- currentFleet.ammoBank.amount !== fleet.ammo.amount ||
1633
- currentFleet.fuelTank.cargoId !== fleet.fuel.id ||
1634
- currentFleet.fuelTank.amount !== fleet.fuel.amount ||
1635
- currentFleet.cargoHold.storageCost !== fleet.cargoHold.storageCost ||
1636
- !sameCargoAmounts(currentFleet.cargoHold.amounts, fleet.cargoHold.items) ||
1637
- currentFleet.stats.cargo.ammoCapacity !== fleet.capacities.ammo.total ||
1638
- currentFleet.stats.cargo.fuelCapacity !== fleet.capacities.fuel.total ||
1639
- currentFleet.stats.cargo.cargoCapacity !== fleet.capacities.cargo.total) {
1577
+ (await deriveFleetAddress(currentFleet)) !== fleet.address) {
1640
1578
  fail(`Fleet ${fleet.name} changed or no longer matches its loaded owner, Game, canonical address, Claim Stake transfer snapshot, cargo, or capacities. Refresh it and retry recovery.`, fleet.address);
1641
1579
  }
1642
- if (currentStake.game !== game ||
1643
- currentStake.ownerCharacter !== character ||
1644
- currentStake.body !== stake.body.address ||
1645
- currentStake.systemSeqId !== stake.systemSeqId ||
1646
- currentStake.state.kind !== 'active' ||
1647
- currentStake.production.cargoPod.storageCost !==
1648
- stake.resources.capacity.usedRaw ||
1649
- currentStake.production.resourceCapacityRaw !==
1650
- stake.resources.capacity.totalRaw ||
1651
- !sameCargoAmounts(currentStake.production.cargoPod.amounts, stake.resources.inventory.items.map(({ id, quantityRaw }) => ({
1652
- amount: quantityRaw,
1653
- id,
1654
- })))) {
1580
+ if (!sameTransferStake(currentStake, stake, game, options.authorization.profile)) {
1655
1581
  fail(`Claim Stake ${stake.address} changed or no longer matches its loaded owner, Game, Body, active state, resources, capacity, or System generation. Refresh it and retry Fleet transfer recovery.`, stake.address);
1656
1582
  }
1657
1583
  let reason;
@@ -1664,7 +1590,7 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1664
1590
  }
1665
1591
  if (reason === undefined) {
1666
1592
  for (const request of currentFleet.state.unload) {
1667
- const available = fleetCargoAmount(currentFleet, request.cargoId);
1593
+ const available = fleetCargoHoldAmount(currentFleet, request.cargoId);
1668
1594
  if (available < request.amount) {
1669
1595
  reason = `Fleet source shortfall for cargo id ${String(request.cargoId)}`;
1670
1596
  break;
@@ -1690,22 +1616,12 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1690
1616
  }
1691
1617
  }
1692
1618
  if (reason === undefined) {
1693
- const loadAmmo = cargoAmount(currentFleet.state.load, currentFleet.ammoBank.cargoId);
1694
- const loadFuel = cargoAmount(currentFleet.state.load, currentFleet.fuelTank.cargoId);
1695
- const loadCargoStorage = currentFleet.state.load
1696
- .filter(({ cargoId }) => cargoId !== currentFleet.ammoBank.cargoId &&
1697
- cargoId !== currentFleet.fuelTank.cargoId)
1698
- .reduce((total, { amount, cargoId }) => total + amount * BigInt(queuedDefinitions.get(cargoId).storageCost), 0n);
1699
- const unloadStorage = currentFleet.state.unload.reduce((total, { amount, cargoId }) => total + amount * BigInt(queuedDefinitions.get(cargoId).storageCost), 0n);
1700
- if (currentFleet.ammoBank.amount + loadAmmo >
1701
- currentFleet.stats.cargo.ammoCapacity) {
1702
- reason = 'Fleet ammo destination overflow';
1703
- }
1704
- else if (currentFleet.fuelTank.amount + loadFuel >
1705
- currentFleet.stats.cargo.fuelCapacity) {
1706
- reason = 'Fleet fuel destination overflow';
1707
- }
1708
- else if (currentFleet.cargoHold.storageCost + loadCargoStorage >
1619
+ // Every queued load, including Fuel and Ammunition, targets the cargo hold.
1620
+ const loadCargoStorage = currentFleet.state.load.reduce((total, { amount, cargoId }) => total +
1621
+ cargoStorageUnits(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
1622
+ const unloadStorage = currentFleet.state.unload.reduce((total, { amount, cargoId }) => total +
1623
+ cargoStorageUnits(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
1624
+ if (currentFleet.cargoHold.storageCost + loadCargoStorage >
1709
1625
  currentFleet.stats.cargo.cargoCapacity) {
1710
1626
  reason = 'Fleet cargo destination overflow';
1711
1627
  }
@@ -1718,15 +1634,15 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1718
1634
  fail(`Fleet ${fleet.name}'s Claim Stake transfer is currently executable. Use the permissionless normal exit path; recovery is only for a locally proven non-executable transfer.`, fleet.address);
1719
1635
  }
1720
1636
  const description = `Recover fleet ${fleet.name} from its stuck Claim Stake transfer (${reason}); no cargo moves and the Fleet returns to idle.`;
1721
- return createPlan({
1637
+ return buildPlannerPlan({
1722
1638
  kind: 'claim-stakes.recover-fleet-transfer',
1723
1639
  preconditions: await Promise.all([
1724
- precondition(fleetAccount, `Fleet ${fleet.name} retains its owner and exact elapsed, non-executable Claim Stake transfer snapshot.`),
1725
- precondition(stakeAccount, `Claim Stake ${stake.address} remains active with the current owner, cargo, and capacity used to prove non-executability.`),
1640
+ accountStatePrecondition(fleetAccount, `Fleet ${fleet.name} retains its owner and exact elapsed, non-executable Claim Stake transfer snapshot.`),
1641
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} remains active with the current owner, cargo, and capacity used to prove non-executability.`),
1726
1642
  ...(gameAccount === undefined
1727
1643
  ? []
1728
1644
  : [
1729
- precondition(gameAccount, `Game ${game} retains the cargo definitions used to prove the transfer is non-executable.`),
1645
+ accountStatePrecondition(gameAccount, `Game ${game} retains the cargo definitions used to prove the transfer is non-executable.`),
1730
1646
  ]),
1731
1647
  ]),
1732
1648
  steps: [