@aephia/atlas-kit 0.6.0-next.3 → 0.6.0-next.30

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 (220) hide show
  1. package/README.md +4 -1
  2. package/dist/cargo/actions/deposit.d.ts.map +1 -1
  3. package/dist/cargo/actions/deposit.js +51 -9
  4. package/dist/cargo/actions/deposit.js.map +1 -1
  5. package/dist/cargo/actions/wallet-context.d.ts +2 -3
  6. package/dist/cargo/actions/wallet-context.d.ts.map +1 -1
  7. package/dist/cargo/actions/wallet-context.js +6 -33
  8. package/dist/cargo/actions/wallet-context.js.map +1 -1
  9. package/dist/cargo/actions/wallet-token.d.ts +1 -1
  10. package/dist/cargo/actions/wallet-token.d.ts.map +1 -1
  11. package/dist/cargo/actions/wallet-token.js +1 -9
  12. package/dist/cargo/actions/wallet-token.js.map +1 -1
  13. package/dist/cargo/actions/withdrawal.d.ts.map +1 -1
  14. package/dist/cargo/actions/withdrawal.js +54 -11
  15. package/dist/cargo/actions/withdrawal.js.map +1 -1
  16. package/dist/client/errors.d.ts +4 -0
  17. package/dist/client/errors.d.ts.map +1 -1
  18. package/dist/client/errors.js +31 -1
  19. package/dist/client/errors.js.map +1 -1
  20. package/dist/client/index.d.ts +1 -0
  21. package/dist/client/index.d.ts.map +1 -1
  22. package/dist/client/index.js +1 -0
  23. package/dist/client/index.js.map +1 -1
  24. package/dist/client/rpc-subscription-provider.d.ts +35 -0
  25. package/dist/client/rpc-subscription-provider.d.ts.map +1 -0
  26. package/dist/client/rpc-subscription-provider.js +190 -0
  27. package/dist/client/rpc-subscription-provider.js.map +1 -0
  28. package/dist/factions/actions/index.d.ts +36 -0
  29. package/dist/factions/actions/index.d.ts.map +1 -0
  30. package/dist/factions/actions/index.js +136 -0
  31. package/dist/factions/actions/index.js.map +1 -0
  32. package/dist/factions/index.d.ts +1 -0
  33. package/dist/factions/index.d.ts.map +1 -1
  34. package/dist/factions/index.js +1 -0
  35. package/dist/factions/index.js.map +1 -1
  36. package/dist/factions/profile-faction.d.ts +58 -0
  37. package/dist/factions/profile-faction.d.ts.map +1 -0
  38. package/dist/factions/profile-faction.js +63 -0
  39. package/dist/factions/profile-faction.js.map +1 -0
  40. package/dist/fleets/actions/add-ship.d.ts +35 -0
  41. package/dist/fleets/actions/add-ship.d.ts.map +1 -0
  42. package/dist/fleets/actions/add-ship.js +149 -0
  43. package/dist/fleets/actions/add-ship.js.map +1 -0
  44. package/dist/fleets/actions/create-fleet.d.ts +36 -0
  45. package/dist/fleets/actions/create-fleet.d.ts.map +1 -0
  46. package/dist/fleets/actions/create-fleet.js +138 -0
  47. package/dist/fleets/actions/create-fleet.js.map +1 -0
  48. package/dist/fleets/actions/index.d.ts +3 -0
  49. package/dist/fleets/actions/index.d.ts.map +1 -1
  50. package/dist/fleets/actions/index.js +3 -0
  51. package/dist/fleets/actions/index.js.map +1 -1
  52. package/dist/fleets/actions/ship-import.d.ts +48 -0
  53. package/dist/fleets/actions/ship-import.d.ts.map +1 -0
  54. package/dist/fleets/actions/ship-import.js +309 -0
  55. package/dist/fleets/actions/ship-import.js.map +1 -0
  56. package/dist/identity/actions/create-profile.d.ts +56 -0
  57. package/dist/identity/actions/create-profile.d.ts.map +1 -0
  58. package/dist/identity/actions/create-profile.js +139 -0
  59. package/dist/identity/actions/create-profile.js.map +1 -0
  60. package/dist/identity/actions/index.d.ts +38 -0
  61. package/dist/identity/actions/index.d.ts.map +1 -0
  62. package/dist/identity/actions/index.js +109 -0
  63. package/dist/identity/actions/index.js.map +1 -0
  64. package/dist/identity/index.d.ts +15 -0
  65. package/dist/identity/index.d.ts.map +1 -1
  66. package/dist/identity/index.js +15 -0
  67. package/dist/identity/index.js.map +1 -1
  68. package/dist/identity/permissions.d.ts +124 -0
  69. package/dist/identity/permissions.d.ts.map +1 -0
  70. package/dist/identity/permissions.js +171 -0
  71. package/dist/identity/permissions.js.map +1 -0
  72. package/dist/internal/c4/cargo-bytes-config.d.ts +7 -0
  73. package/dist/internal/c4/cargo-bytes-config.d.ts.map +1 -0
  74. package/dist/internal/c4/cargo-bytes-config.js +19 -0
  75. package/dist/internal/c4/cargo-bytes-config.js.map +1 -0
  76. package/dist/internal/c4/character-registration.d.ts +9 -0
  77. package/dist/internal/c4/character-registration.d.ts.map +1 -0
  78. package/dist/internal/c4/character-registration.js +21 -0
  79. package/dist/internal/c4/character-registration.js.map +1 -0
  80. package/dist/internal/c4/faction-adapter.d.ts +12 -0
  81. package/dist/internal/c4/faction-adapter.d.ts.map +1 -0
  82. package/dist/internal/c4/faction-adapter.js +52 -0
  83. package/dist/internal/c4/faction-adapter.js.map +1 -0
  84. package/dist/internal/c4/faction-enrollment.d.ts +6 -0
  85. package/dist/internal/c4/faction-enrollment.d.ts.map +1 -0
  86. package/dist/internal/c4/faction-enrollment.js +8 -0
  87. package/dist/internal/c4/faction-enrollment.js.map +1 -0
  88. package/dist/internal/c4/faction-epoch-meter.d.ts +10 -0
  89. package/dist/internal/c4/faction-epoch-meter.d.ts.map +1 -0
  90. package/dist/internal/c4/faction-epoch-meter.js +31 -0
  91. package/dist/internal/c4/faction-epoch-meter.js.map +1 -0
  92. package/dist/internal/c4/faction-treasury.d.ts +23 -0
  93. package/dist/internal/c4/faction-treasury.d.ts.map +1 -0
  94. package/dist/internal/c4/faction-treasury.js +48 -0
  95. package/dist/internal/c4/faction-treasury.js.map +1 -0
  96. package/dist/internal/c4/factions.d.ts +9 -30
  97. package/dist/internal/c4/factions.d.ts.map +1 -1
  98. package/dist/internal/c4/factions.js +4 -89
  99. package/dist/internal/c4/factions.js.map +1 -1
  100. package/dist/internal/c4/fleet-creation.d.ts +7 -0
  101. package/dist/internal/c4/fleet-creation.d.ts.map +1 -0
  102. package/dist/internal/c4/fleet-creation.js +180 -0
  103. package/dist/internal/c4/fleet-creation.js.map +1 -0
  104. package/dist/internal/c4/fleet-crew-binding.d.ts +2 -0
  105. package/dist/internal/c4/fleet-crew-binding.d.ts.map +1 -1
  106. package/dist/internal/c4/fleet-crew-binding.js +5 -0
  107. package/dist/internal/c4/fleet-crew-binding.js.map +1 -1
  108. package/dist/internal/c4/fleet-ship-assembly.d.ts +11 -0
  109. package/dist/internal/c4/fleet-ship-assembly.d.ts.map +1 -0
  110. package/dist/internal/c4/fleet-ship-assembly.js +44 -0
  111. package/dist/internal/c4/fleet-ship-assembly.js.map +1 -0
  112. package/dist/internal/c4/game.d.ts +18 -6
  113. package/dist/internal/c4/game.d.ts.map +1 -1
  114. package/dist/internal/c4/game.js +32 -8
  115. package/dist/internal/c4/game.js.map +1 -1
  116. package/dist/internal/c4/identity.d.ts +2 -7
  117. package/dist/internal/c4/identity.d.ts.map +1 -1
  118. package/dist/internal/c4/identity.js +2 -23
  119. package/dist/internal/c4/identity.js.map +1 -1
  120. package/dist/internal/c4/legacy-cargo-config.d.ts +6 -0
  121. package/dist/internal/c4/legacy-cargo-config.d.ts.map +1 -0
  122. package/dist/internal/c4/legacy-cargo-config.js +26 -0
  123. package/dist/internal/c4/legacy-cargo-config.js.map +1 -0
  124. package/dist/internal/c4/profile-creation.d.ts +17 -0
  125. package/dist/internal/c4/profile-creation.d.ts.map +1 -0
  126. package/dist/internal/c4/profile-creation.js +36 -0
  127. package/dist/internal/c4/profile-creation.js.map +1 -0
  128. package/dist/internal/c4/profile-faction.d.ts.map +1 -1
  129. package/dist/internal/c4/profile-faction.js +2 -0
  130. package/dist/internal/c4/profile-faction.js.map +1 -1
  131. package/dist/internal/c4/profile-permissions.d.ts +14 -0
  132. package/dist/internal/c4/profile-permissions.d.ts.map +1 -0
  133. package/dist/internal/c4/profile-permissions.js +80 -0
  134. package/dist/internal/c4/profile-permissions.js.map +1 -0
  135. package/dist/internal/c4/wallet-cargo-cache.d.ts +3 -0
  136. package/dist/internal/c4/wallet-cargo-cache.d.ts.map +1 -0
  137. package/dist/internal/c4/wallet-cargo-cache.js +24 -0
  138. package/dist/internal/c4/wallet-cargo-cache.js.map +1 -0
  139. package/dist/internal/loyalty-atlas-bank-state.d.ts +16 -0
  140. package/dist/internal/loyalty-atlas-bank-state.d.ts.map +1 -0
  141. package/dist/internal/loyalty-atlas-bank-state.js +10 -0
  142. package/dist/internal/loyalty-atlas-bank-state.js.map +1 -0
  143. package/dist/internal/planning/account-state.d.ts +4 -0
  144. package/dist/internal/planning/account-state.d.ts.map +1 -0
  145. package/dist/internal/planning/account-state.js +11 -0
  146. package/dist/internal/planning/account-state.js.map +1 -0
  147. package/dist/internal/planning/authorization-adapter.d.ts +17 -0
  148. package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
  149. package/dist/internal/planning/authorization-adapter.js +50 -0
  150. package/dist/internal/planning/authorization-adapter.js.map +1 -1
  151. package/dist/internal/planning/faction-enrollment.d.ts +12 -0
  152. package/dist/internal/planning/faction-enrollment.d.ts.map +1 -0
  153. package/dist/internal/planning/faction-enrollment.js +67 -0
  154. package/dist/internal/planning/faction-enrollment.js.map +1 -0
  155. package/dist/internal/planning/faction-trade-state.d.ts +16 -0
  156. package/dist/internal/planning/faction-trade-state.d.ts.map +1 -0
  157. package/dist/internal/planning/faction-trade-state.js +39 -0
  158. package/dist/internal/planning/faction-trade-state.js.map +1 -0
  159. package/dist/internal/planning/fleet-creation.d.ts +29 -0
  160. package/dist/internal/planning/fleet-creation.d.ts.map +1 -0
  161. package/dist/internal/planning/fleet-creation.js +106 -0
  162. package/dist/internal/planning/fleet-creation.js.map +1 -0
  163. package/dist/internal/planning/fleet-ship-assembly.d.ts +35 -0
  164. package/dist/internal/planning/fleet-ship-assembly.d.ts.map +1 -0
  165. package/dist/internal/planning/fleet-ship-assembly.js +135 -0
  166. package/dist/internal/planning/fleet-ship-assembly.js.map +1 -0
  167. package/dist/internal/planning/ship-token.d.ts +10 -0
  168. package/dist/internal/planning/ship-token.d.ts.map +1 -0
  169. package/dist/internal/planning/ship-token.js +47 -0
  170. package/dist/internal/planning/ship-token.js.map +1 -0
  171. package/dist/internal/planning/token-mint.d.ts +4 -0
  172. package/dist/internal/planning/token-mint.d.ts.map +1 -0
  173. package/dist/internal/planning/token-mint.js +15 -0
  174. package/dist/internal/planning/token-mint.js.map +1 -0
  175. package/dist/internal/planning/trade-faction-market.d.ts +20 -0
  176. package/dist/internal/planning/trade-faction-market.d.ts.map +1 -0
  177. package/dist/internal/planning/trade-faction-market.js +56 -0
  178. package/dist/internal/planning/trade-faction-market.js.map +1 -0
  179. package/dist/loyalty/actions/index.d.ts.map +1 -1
  180. package/dist/loyalty/actions/index.js +4 -3
  181. package/dist/loyalty/actions/index.js.map +1 -1
  182. package/dist/loyalty/index.d.ts.map +1 -1
  183. package/dist/loyalty/index.js +2 -6
  184. package/dist/loyalty/index.js.map +1 -1
  185. package/dist/markets/actions/index.d.ts +1 -0
  186. package/dist/markets/actions/index.d.ts.map +1 -1
  187. package/dist/markets/actions/index.js +1 -0
  188. package/dist/markets/actions/index.js.map +1 -1
  189. package/dist/markets/actions/trade-faction-market.d.ts +43 -0
  190. package/dist/markets/actions/trade-faction-market.d.ts.map +1 -0
  191. package/dist/markets/actions/trade-faction-market.js +288 -0
  192. package/dist/markets/actions/trade-faction-market.js.map +1 -0
  193. package/dist/mining/actions/index.d.ts +86 -0
  194. package/dist/mining/actions/index.d.ts.map +1 -0
  195. package/dist/mining/actions/index.js +295 -0
  196. package/dist/mining/actions/index.js.map +1 -0
  197. package/dist/planning/execution.d.ts.map +1 -1
  198. package/dist/planning/execution.js +191 -16
  199. package/dist/planning/execution.js.map +1 -1
  200. package/dist/planning/index.d.ts +316 -4
  201. package/dist/planning/index.d.ts.map +1 -1
  202. package/dist/planning/index.js +489 -12
  203. package/dist/planning/index.js.map +1 -1
  204. package/dist/planning/simulation.d.ts +18 -1
  205. package/dist/planning/simulation.d.ts.map +1 -1
  206. package/dist/planning/simulation.js +56 -10
  207. package/dist/planning/simulation.js.map +1 -1
  208. package/dist/registry/cargo.d.ts +9 -6
  209. package/dist/registry/cargo.d.ts.map +1 -1
  210. package/dist/registry/cargo.js +30 -4
  211. package/dist/registry/cargo.js.map +1 -1
  212. package/dist/registry/onboarding.d.ts +6 -0
  213. package/dist/registry/onboarding.d.ts.map +1 -0
  214. package/dist/registry/onboarding.js +24 -0
  215. package/dist/registry/onboarding.js.map +1 -0
  216. package/dist/registry/ships.d.ts +28 -0
  217. package/dist/registry/ships.d.ts.map +1 -0
  218. package/dist/registry/ships.js +51 -0
  219. package/dist/registry/ships.js.map +1 -0
  220. package/package.json +13 -1
@@ -159,9 +159,278 @@ function normalizeSemanticFact(value, field) {
159
159
  }
160
160
  return invalid(`${field}.kind`, semantic.kind, 'one of exclusive, requires, invalidates, or transition');
161
161
  }
162
- function normalizePrecondition(value, field, version = 3) {
162
+ function normalizePrecondition(value, field, version = 12) {
163
163
  const precondition = readRecord(value, field);
164
- if (precondition.kind === 'token-account-or-absent' && version === 3) {
164
+ if (version >= 12 &&
165
+ (precondition.kind === 'faction-treasury-buy' ||
166
+ precondition.kind === 'faction-treasury-sell' ||
167
+ precondition.kind === 'faction-epoch-meter')) {
168
+ const { kind } = precondition;
169
+ assertKeys(precondition, field, [
170
+ 'kind',
171
+ 'address',
172
+ 'game',
173
+ 'factionId',
174
+ 'describes',
175
+ ...(kind === 'faction-treasury-buy'
176
+ ? ['cargoId', 'floorRaw']
177
+ : kind === 'faction-treasury-sell'
178
+ ? ['atlasOutCapPerEpochRaw', 'epochLengthSeconds']
179
+ : []),
180
+ ]);
181
+ const u16 = (key) => {
182
+ const n = precondition[key];
183
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 0 || n > 65535)
184
+ invalid(`${field}.${key}`, n, 'an unsigned u16 integer');
185
+ return n;
186
+ };
187
+ const integer = (key, signed = false) => {
188
+ const n = precondition[key];
189
+ const min = signed ? -(1n << 63n) : 0n;
190
+ const max = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
191
+ if (typeof n !== 'bigint' || n < min || n > max)
192
+ invalid(`${field}.${key}`, n, signed ? 'an i64 bigint' : 'a u64 bigint');
193
+ return n;
194
+ };
195
+ const common = {
196
+ address: readAddress(precondition.address, `${field}.address`),
197
+ game: readAddress(precondition.game, `${field}.game`),
198
+ factionId: u16('factionId'),
199
+ describes: readString(precondition.describes, `${field}.describes`),
200
+ };
201
+ if (kind === 'faction-treasury-buy')
202
+ return Object.freeze({
203
+ kind,
204
+ ...common,
205
+ cargoId: u16('cargoId'),
206
+ floorRaw: integer('floorRaw'),
207
+ });
208
+ if (kind === 'faction-treasury-sell')
209
+ return Object.freeze({
210
+ kind,
211
+ ...common,
212
+ atlasOutCapPerEpochRaw: integer('atlasOutCapPerEpochRaw'),
213
+ epochLengthSeconds: integer('epochLengthSeconds', true),
214
+ });
215
+ return Object.freeze({ kind, ...common });
216
+ }
217
+ if (version >= 11 && precondition.kind === 'fleet-add-ship') {
218
+ assertKeys(precondition, field, [
219
+ 'kind',
220
+ 'address',
221
+ 'game',
222
+ 'profile',
223
+ 'authority',
224
+ 'system',
225
+ 'shipId',
226
+ 'amount',
227
+ 'keyIndex',
228
+ 'configHash',
229
+ 'maximumProfileDebit',
230
+ 'describes',
231
+ ]);
232
+ const keyIndex = precondition.keyIndex;
233
+ if (typeof keyIndex !== 'number' ||
234
+ !Number.isInteger(keyIndex) ||
235
+ keyIndex < 0 ||
236
+ keyIndex > 65535)
237
+ invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
238
+ const shipId = precondition.shipId;
239
+ if (typeof shipId !== 'number' ||
240
+ !Number.isInteger(shipId) ||
241
+ shipId < 0 ||
242
+ shipId > 65535)
243
+ invalid(`${field}.shipId`, shipId, 'a u16 ship configuration ID');
244
+ const amount = precondition.amount;
245
+ if (typeof amount !== 'bigint' || amount < 1n || amount > 255n)
246
+ invalid(`${field}.amount`, amount, 'a whole ship quantity from 1n through 255n');
247
+ const maximumProfileDebit = precondition.maximumProfileDebit;
248
+ if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
249
+ invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
250
+ return Object.freeze({
251
+ kind: 'fleet-add-ship',
252
+ address: readAddress(precondition.address, `${field}.address`),
253
+ game: readAddress(precondition.game, `${field}.game`),
254
+ profile: readAddress(precondition.profile, `${field}.profile`),
255
+ authority: readAddress(precondition.authority, `${field}.authority`),
256
+ system: readAddress(precondition.system, `${field}.system`),
257
+ keyIndex,
258
+ shipId,
259
+ amount,
260
+ maximumProfileDebit,
261
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
262
+ describes: readString(precondition.describes, `${field}.describes`),
263
+ });
264
+ }
265
+ if (version >= 10 && precondition.kind === 'fleet-create') {
266
+ assertKeys(precondition, field, [
267
+ 'kind',
268
+ 'address',
269
+ 'game',
270
+ 'profile',
271
+ 'authority',
272
+ 'system',
273
+ 'keyIndex',
274
+ 'label',
275
+ 'maximumProfileDebit',
276
+ 'describes',
277
+ ]);
278
+ const keyIndex = precondition.keyIndex;
279
+ if (typeof keyIndex !== 'number' ||
280
+ !Number.isSafeInteger(keyIndex) ||
281
+ keyIndex < 0 ||
282
+ keyIndex > 65_535)
283
+ invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
284
+ const label = readString(precondition.label, `${field}.label`);
285
+ const bytes = new TextEncoder().encode(label);
286
+ if (label.trim().length === 0 ||
287
+ label.includes('\0') ||
288
+ bytes.length > 64 ||
289
+ new TextDecoder('utf-8', { ignoreBOM: true }).decode(bytes) !== label)
290
+ invalid(`${field}.label`, label, 'a nonblank, NUL-free Unicode label of at most 64 UTF-8 bytes');
291
+ const maximumProfileDebit = precondition.maximumProfileDebit;
292
+ if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
293
+ invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
294
+ return Object.freeze({
295
+ kind: 'fleet-create',
296
+ address: readAddress(precondition.address, `${field}.address`),
297
+ game: readAddress(precondition.game, `${field}.game`),
298
+ profile: readAddress(precondition.profile, `${field}.profile`),
299
+ authority: readAddress(precondition.authority, `${field}.authority`),
300
+ system: readAddress(precondition.system, `${field}.system`),
301
+ keyIndex,
302
+ label,
303
+ maximumProfileDebit,
304
+ describes: readString(precondition.describes, `${field}.describes`),
305
+ });
306
+ }
307
+ if (version >= 8 && precondition.kind === 'system-account-or-absent') {
308
+ assertKeys(precondition, field, ['kind', 'address', 'describes']);
309
+ return Object.freeze({
310
+ kind: 'system-account-or-absent',
311
+ address: readAddress(precondition.address, `${field}.address`),
312
+ describes: readString(precondition.describes, `${field}.describes`),
313
+ });
314
+ }
315
+ if (version >= 7 && precondition.kind === 'token-mint') {
316
+ assertKeys(precondition, field, [
317
+ 'kind',
318
+ 'address',
319
+ 'decimals',
320
+ 'describes',
321
+ ]);
322
+ const decimals = precondition.decimals;
323
+ if (typeof decimals !== 'number' ||
324
+ !Number.isInteger(decimals) ||
325
+ decimals < 0 ||
326
+ decimals > 255)
327
+ invalid(`${field}.decimals`, decimals, 'an unsigned u8 mint decimals value');
328
+ return Object.freeze({
329
+ kind: 'token-mint',
330
+ address: readAddress(precondition.address, `${field}.address`),
331
+ decimals,
332
+ describes: readString(precondition.describes, `${field}.describes`),
333
+ });
334
+ }
335
+ if (version >= 6 && precondition.kind === 'game-ship-config') {
336
+ assertKeys(precondition, field, [
337
+ 'kind',
338
+ 'address',
339
+ 'shipId',
340
+ 'configHash',
341
+ 'describes',
342
+ ]);
343
+ const id = precondition.shipId;
344
+ if (typeof id !== 'number' || !Number.isInteger(id) || id < 0 || id > 65535)
345
+ invalid(`${field}.shipId`, id, 'a u16 ship configuration ID');
346
+ return Object.freeze({
347
+ kind: 'game-ship-config',
348
+ address: readAddress(precondition.address, `${field}.address`),
349
+ shipId: id,
350
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
351
+ describes: readString(precondition.describes, `${field}.describes`),
352
+ });
353
+ }
354
+ if (version >= 5 && precondition.kind === 'game-account') {
355
+ assertKeys(precondition, field, ['kind', 'address', 'describes']);
356
+ return Object.freeze({
357
+ kind: 'game-account',
358
+ address: readAddress(precondition.address, `${field}.address`),
359
+ describes: readString(precondition.describes, `${field}.describes`),
360
+ });
361
+ }
362
+ if ((version >= 9 && precondition.kind === 'game-cargo-bytes-config') ||
363
+ (version >= 4 &&
364
+ ['token-account', 'game-cargo-config', 'cargo-cache'].includes(String(precondition.kind)))) {
365
+ const base = {
366
+ address: readAddress(precondition.address, `${field}.address`),
367
+ describes: readString(precondition.describes, `${field}.describes`),
368
+ };
369
+ if (precondition.kind === 'token-account') {
370
+ assertKeys(precondition, field, [
371
+ 'kind',
372
+ 'address',
373
+ 'mint',
374
+ 'owner',
375
+ 'minimumBalance',
376
+ 'describes',
377
+ ]);
378
+ const amount = precondition.minimumBalance;
379
+ if (typeof amount !== 'bigint' ||
380
+ amount < 0n ||
381
+ amount > (1n << 64n) - 1n)
382
+ invalid(`${field}.minimumBalance`, amount, 'an unsigned u64 bigint');
383
+ return Object.freeze({
384
+ ...base,
385
+ kind: 'token-account',
386
+ mint: readAddress(precondition.mint, `${field}.mint`),
387
+ owner: readAddress(precondition.owner, `${field}.owner`),
388
+ minimumBalance: amount,
389
+ });
390
+ }
391
+ if (precondition.kind === 'game-cargo-config' ||
392
+ precondition.kind === 'game-cargo-bytes-config') {
393
+ assertKeys(precondition, field, [
394
+ 'kind',
395
+ 'address',
396
+ 'cargoId',
397
+ 'configHash',
398
+ 'describes',
399
+ ]);
400
+ const id = precondition.cargoId;
401
+ if (typeof id !== 'number' ||
402
+ !Number.isInteger(id) ||
403
+ id < 0 ||
404
+ id > 65535)
405
+ invalid(`${field}.cargoId`, id, 'a u16 cargo ID');
406
+ return Object.freeze({
407
+ ...base,
408
+ kind: precondition.kind,
409
+ cargoId: id,
410
+ configHash: readDataHash(precondition.configHash, `${field}.configHash`),
411
+ });
412
+ }
413
+ assertKeys(precondition, field, [
414
+ 'kind',
415
+ 'address',
416
+ 'game',
417
+ 'bump',
418
+ 'describes',
419
+ ]);
420
+ const bump = precondition.bump;
421
+ if (typeof bump !== 'number' ||
422
+ !Number.isInteger(bump) ||
423
+ bump < 0 ||
424
+ bump > 255)
425
+ invalid(`${field}.bump`, bump, 'a u8 PDA bump');
426
+ return Object.freeze({
427
+ ...base,
428
+ kind: 'cargo-cache',
429
+ game: readAddress(precondition.game, `${field}.game`),
430
+ bump,
431
+ });
432
+ }
433
+ if (precondition.kind === 'token-account-or-absent' && version >= 3) {
165
434
  assertKeys(precondition, field, [
166
435
  'kind',
167
436
  'address',
@@ -186,11 +455,29 @@ function normalizePrecondition(value, field, version = 3) {
186
455
  });
187
456
  }
188
457
  if (precondition.kind !== 'account-state') {
189
- invalid(`${field}.kind`, precondition.kind, version === 3
190
- ? 'one of account-state, account-absent, or token-account-or-absent'
191
- : version === 2
192
- ? 'one of account-state or account-absent'
193
- : 'the value account-state');
458
+ invalid(`${field}.kind`, precondition.kind, version === 12
459
+ ? 'one of faction-treasury-buy, faction-treasury-sell, faction-epoch-meter, or a supported V1–V11 precondition'
460
+ : version === 11
461
+ ? 'one of fleet-add-ship, fleet-create, account-state, account-absent, system-account-or-absent, token-account-or-absent, token-account, token-mint, game-cargo-config, game-cargo-bytes-config, cargo-cache, game-account, or game-ship-config'
462
+ : version === 10
463
+ ? 'one of fleet-create, account-state, account-absent, system-account-or-absent, token-account-or-absent, token-account, token-mint, game-cargo-config, game-cargo-bytes-config, cargo-cache, game-account, or game-ship-config'
464
+ : version === 9
465
+ ? 'one of account-state, account-absent, system-account-or-absent, token-account-or-absent, token-account, token-mint, game-cargo-config, game-cargo-bytes-config, cargo-cache, game-account, or game-ship-config'
466
+ : version === 8
467
+ ? 'one of account-state, account-absent, system-account-or-absent, token-account-or-absent, token-account, token-mint, game-cargo-config, cargo-cache, game-account, or game-ship-config'
468
+ : version === 7
469
+ ? 'one of account-state, account-absent, token-account-or-absent, token-account, token-mint, game-cargo-config, cargo-cache, game-account, or game-ship-config'
470
+ : version === 6
471
+ ? 'one of account-state, account-absent, token-account-or-absent, token-account, game-cargo-config, cargo-cache, game-account, or game-ship-config'
472
+ : version === 5
473
+ ? 'one of account-state, account-absent, token-account-or-absent, token-account, game-cargo-config, cargo-cache, or game-account'
474
+ : version === 4
475
+ ? 'one of account-state, account-absent, token-account-or-absent, token-account, game-cargo-config, or cargo-cache'
476
+ : version === 3
477
+ ? 'one of account-state, account-absent, or token-account-or-absent'
478
+ : version === 2
479
+ ? 'one of account-state or account-absent'
480
+ : 'the value account-state');
194
481
  }
195
482
  assertKeys(precondition, field, ['kind', 'address', 'dataHash', 'describes']);
196
483
  return Object.freeze({
@@ -242,12 +529,142 @@ function planToJSON(plan) {
242
529
  : {}),
243
530
  signers: [...step.signers],
244
531
  }));
532
+ if (plan.preconditions.some(({ kind }) => kind === 'faction-treasury-buy' ||
533
+ kind === 'faction-treasury-sell' ||
534
+ kind === 'faction-epoch-meter')) {
535
+ return deepFreeze({
536
+ v: 12,
537
+ ...common,
538
+ steps,
539
+ preconditions: plan.preconditions.map((guard) => {
540
+ if (guard.kind === 'faction-treasury-buy')
541
+ return { ...guard, floorRaw: String(guard.floorRaw) };
542
+ if (guard.kind === 'faction-treasury-sell')
543
+ return {
544
+ ...guard,
545
+ atlasOutCapPerEpochRaw: String(guard.atlasOutCapPerEpochRaw),
546
+ epochLengthSeconds: String(guard.epochLengthSeconds),
547
+ };
548
+ if (guard.kind === 'fleet-add-ship')
549
+ return {
550
+ ...guard,
551
+ amount: String(guard.amount),
552
+ maximumProfileDebit: String(guard.maximumProfileDebit),
553
+ };
554
+ if (guard.kind === 'fleet-create')
555
+ return {
556
+ ...guard,
557
+ maximumProfileDebit: String(guard.maximumProfileDebit),
558
+ };
559
+ if (guard.kind === 'token-account')
560
+ return { ...guard, minimumBalance: String(guard.minimumBalance) };
561
+ return { ...guard };
562
+ }),
563
+ });
564
+ }
565
+ if (plan.preconditions.some(({ kind }) => kind === 'fleet-add-ship')) {
566
+ return deepFreeze({
567
+ v: 11,
568
+ ...common,
569
+ steps,
570
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'fleet-add-ship'
571
+ ? {
572
+ ...guard,
573
+ amount: String(guard.amount),
574
+ maximumProfileDebit: String(guard.maximumProfileDebit),
575
+ }
576
+ : guard.kind === 'fleet-create'
577
+ ? {
578
+ ...guard,
579
+ maximumProfileDebit: String(guard.maximumProfileDebit),
580
+ }
581
+ : guard.kind === 'token-account'
582
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
583
+ : { ...guard }),
584
+ });
585
+ }
586
+ if (plan.preconditions.some(({ kind }) => kind === 'fleet-create')) {
587
+ return deepFreeze({
588
+ v: 10,
589
+ ...common,
590
+ steps,
591
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'fleet-create'
592
+ ? { ...guard, maximumProfileDebit: String(guard.maximumProfileDebit) }
593
+ : guard.kind === 'token-account'
594
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
595
+ : { ...guard }),
596
+ });
597
+ }
598
+ if (plan.preconditions.some(({ kind }) => kind === 'game-cargo-bytes-config')) {
599
+ return deepFreeze({
600
+ v: 9,
601
+ ...common,
602
+ steps,
603
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
604
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
605
+ : { ...guard }),
606
+ });
607
+ }
608
+ if (plan.preconditions.some(({ kind }) => kind === 'system-account-or-absent')) {
609
+ return deepFreeze({
610
+ v: 8,
611
+ ...common,
612
+ steps,
613
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
614
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
615
+ : { ...guard }),
616
+ });
617
+ }
618
+ if (plan.preconditions.some(({ kind }) => kind === 'token-mint')) {
619
+ return deepFreeze({
620
+ v: 7,
621
+ ...common,
622
+ steps,
623
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
624
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
625
+ : { ...guard }),
626
+ });
627
+ }
628
+ if (plan.preconditions.some(({ kind }) => kind === 'game-ship-config')) {
629
+ return deepFreeze({
630
+ v: 6,
631
+ ...common,
632
+ steps,
633
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
634
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
635
+ : { ...guard }),
636
+ });
637
+ }
638
+ if (plan.preconditions.some(({ kind }) => kind === 'game-account')) {
639
+ return deepFreeze({
640
+ v: 5,
641
+ ...common,
642
+ steps,
643
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
644
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
645
+ : { ...guard }),
646
+ });
647
+ }
648
+ if (plan.preconditions.some(({ kind }) => kind === 'token-account' ||
649
+ kind === 'game-cargo-config' ||
650
+ kind === 'cargo-cache')) {
651
+ return deepFreeze({
652
+ v: 4,
653
+ ...common,
654
+ steps,
655
+ preconditions: plan.preconditions.map((guard) => guard.kind === 'token-account'
656
+ ? { ...guard, minimumBalance: String(guard.minimumBalance) }
657
+ : { ...guard }),
658
+ });
659
+ }
245
660
  if (plan.preconditions.some(({ kind }) => kind === 'token-account-or-absent')) {
246
661
  return deepFreeze({
247
662
  v: 3,
248
663
  ...common,
249
664
  steps,
250
- preconditions: plan.preconditions.map((guard) => ({ ...guard })),
665
+ preconditions: plan.preconditions.map((guard) => ({
666
+ ...guard,
667
+ })),
251
668
  });
252
669
  }
253
670
  if (hasSemantics || hasAbsentPrecondition) {
@@ -337,13 +754,13 @@ function sameAddresses(actual, encoded) {
337
754
  *
338
755
  * @example
339
756
  * ```ts
340
- * declare const wire: PlanJsonV1 | PlanJsonV2 | PlanJsonV3;
757
+ * declare const wire: PlanJsonV1 | PlanJsonV2 | PlanJsonV3 | PlanJsonV4 | PlanJsonV5 | PlanJsonV6 | PlanJsonV7 | PlanJsonV8 | PlanJsonV9 | PlanJsonV10 | PlanJsonV11 | PlanJsonV12;
341
758
  * const plan = planFromJSON(wire);
342
759
  * console.log(plan.describe());
343
760
  * ```
344
761
  */
345
762
  export function planFromJSON(json) {
346
- const value = readRecord(json, 'planJson');
763
+ const value = { ...readRecord(json, 'planJson') };
347
764
  assertKeys(value, 'planJson', [
348
765
  'v',
349
766
  'kind',
@@ -353,10 +770,70 @@ export function planFromJSON(json) {
353
770
  'affected',
354
771
  'requiredSigners',
355
772
  ]);
356
- if (value.v !== 1 && value.v !== 2 && value.v !== 3) {
357
- invalid('planJson.v', value.v, 'the Plan wire version 1, 2, or 3');
773
+ if (value.v !== 1 &&
774
+ value.v !== 2 &&
775
+ value.v !== 3 &&
776
+ value.v !== 4 &&
777
+ value.v !== 5 &&
778
+ value.v !== 6 &&
779
+ value.v !== 7 &&
780
+ value.v !== 8 &&
781
+ value.v !== 9 &&
782
+ value.v !== 10 &&
783
+ value.v !== 11 &&
784
+ value.v !== 12) {
785
+ invalid('planJson.v', value.v, 'the Plan wire version 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, or 12');
358
786
  }
359
787
  const version = value.v;
788
+ if (version >= 4 && Array.isArray(value.preconditions)) {
789
+ value.preconditions = value.preconditions.map((entry) => {
790
+ const guard = readRecord(entry, 'precondition');
791
+ if (version >= 12 &&
792
+ (guard.kind === 'faction-treasury-buy' ||
793
+ guard.kind === 'faction-treasury-sell')) {
794
+ const keys = guard.kind === 'faction-treasury-buy'
795
+ ? ['floorRaw']
796
+ : ['atlasOutCapPerEpochRaw', 'epochLengthSeconds'];
797
+ const decoded = { ...guard };
798
+ for (const key of keys) {
799
+ const raw = guard[key];
800
+ const pattern = key === 'epochLengthSeconds'
801
+ ? /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
802
+ : /^(0|[1-9][0-9]*)$/;
803
+ if (typeof raw !== 'string' || !pattern.test(raw))
804
+ invalid(key, raw, 'a canonical decimal string');
805
+ decoded[key] = BigInt(raw);
806
+ }
807
+ return decoded;
808
+ }
809
+ if (version >= 11 && guard.kind === 'fleet-add-ship') {
810
+ for (const field of ['amount', 'maximumProfileDebit'])
811
+ if (typeof guard[field] !== 'string' ||
812
+ !/^(0|[1-9][0-9]*)$/.test(guard[field]))
813
+ invalid(field, guard[field], 'a canonical unsigned decimal string');
814
+ return {
815
+ ...guard,
816
+ amount: BigInt(guard.amount),
817
+ maximumProfileDebit: BigInt(guard.maximumProfileDebit),
818
+ };
819
+ }
820
+ if (version >= 10 && guard.kind === 'fleet-create') {
821
+ if (typeof guard.maximumProfileDebit !== 'string' ||
822
+ !/^(0|[1-9][0-9]*)$/.test(guard.maximumProfileDebit))
823
+ invalid('maximumProfileDebit', guard.maximumProfileDebit, 'a canonical unsigned decimal string');
824
+ return {
825
+ ...guard,
826
+ maximumProfileDebit: BigInt(guard.maximumProfileDebit),
827
+ };
828
+ }
829
+ if (guard.kind !== 'token-account')
830
+ return guard;
831
+ if (typeof guard.minimumBalance !== 'string' ||
832
+ !/^(0|[1-9][0-9]*)$/.test(guard.minimumBalance))
833
+ invalid('minimumBalance', guard.minimumBalance, 'a canonical unsigned decimal string');
834
+ return { ...guard, minimumBalance: BigInt(guard.minimumBalance) };
835
+ });
836
+ }
360
837
  const steps = readArray(value.steps, 'planJson.steps').map((candidate, index) => {
361
838
  const field = `planJson.steps[${String(index)}]`;
362
839
  const step = readRecord(candidate, field);