@aephia/atlas-kit 0.8.0-next.25 → 0.8.0-next.27

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 (70) hide show
  1. package/dist/claim-stakes/actions/index.d.ts +104 -0
  2. package/dist/claim-stakes/actions/index.d.ts.map +1 -1
  3. package/dist/claim-stakes/actions/index.js +370 -61
  4. package/dist/claim-stakes/actions/index.js.map +1 -1
  5. package/dist/claim-stakes/index.d.ts +1 -1
  6. package/dist/claim-stakes/index.d.ts.map +1 -1
  7. package/dist/claim-stakes/index.js +1 -1
  8. package/dist/claim-stakes/index.js.map +1 -1
  9. package/dist/crafting/actions/habs.d.ts +47 -0
  10. package/dist/crafting/actions/habs.d.ts.map +1 -1
  11. package/dist/crafting/actions/habs.js +101 -2
  12. package/dist/crafting/actions/habs.js.map +1 -1
  13. package/dist/crafting/actions/index.d.ts +1 -1
  14. package/dist/crafting/actions/index.d.ts.map +1 -1
  15. package/dist/crafting/actions/index.js +1 -1
  16. package/dist/crafting/actions/index.js.map +1 -1
  17. package/dist/crafting/index.d.ts +1 -1
  18. package/dist/crafting/index.d.ts.map +1 -1
  19. package/dist/crafting/index.js +1 -1
  20. package/dist/crafting/index.js.map +1 -1
  21. package/dist/internal/c4/claim-stake.d.ts +8 -0
  22. package/dist/internal/c4/claim-stake.d.ts.map +1 -1
  23. package/dist/internal/c4/claim-stake.js +5 -0
  24. package/dist/internal/c4/claim-stake.js.map +1 -1
  25. package/dist/internal/c4/crafting.d.ts +8 -0
  26. package/dist/internal/c4/crafting.d.ts.map +1 -1
  27. package/dist/internal/c4/crafting.js +5 -0
  28. package/dist/internal/c4/crafting.js.map +1 -1
  29. package/dist/internal/c4/discriminators.d.ts +3 -0
  30. package/dist/internal/c4/discriminators.d.ts.map +1 -1
  31. package/dist/internal/c4/discriminators.js +7 -1
  32. package/dist/internal/c4/discriminators.js.map +1 -1
  33. package/dist/internal/c4/runtime-bindings.d.ts +1 -1
  34. package/dist/internal/c4/runtime-bindings.d.ts.map +1 -1
  35. package/dist/internal/c4/runtime-bindings.js +1 -1
  36. package/dist/internal/c4/runtime-bindings.js.map +1 -1
  37. package/dist/internal/planning/authorization-adapter.d.ts +49 -0
  38. package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
  39. package/dist/internal/planning/authorization-adapter.js +69 -1
  40. package/dist/internal/planning/authorization-adapter.js.map +1 -1
  41. package/dist/internal/planning/building-xp.d.ts +50 -0
  42. package/dist/internal/planning/building-xp.d.ts.map +1 -0
  43. package/dist/internal/planning/building-xp.js +166 -0
  44. package/dist/internal/planning/building-xp.js.map +1 -0
  45. package/dist/internal/planning/claim-stake-transfer-window.d.ts +18 -0
  46. package/dist/internal/planning/claim-stake-transfer-window.d.ts.map +1 -0
  47. package/dist/internal/planning/claim-stake-transfer-window.js +57 -0
  48. package/dist/internal/planning/claim-stake-transfer-window.js.map +1 -0
  49. package/dist/internal/planning/currency-cache-guard.d.ts.map +1 -1
  50. package/dist/internal/planning/currency-cache-guard.js +4 -1
  51. package/dist/internal/planning/currency-cache-guard.js.map +1 -1
  52. package/dist/internal/planning/plan-guards.d.ts.map +1 -1
  53. package/dist/internal/planning/plan-guards.js +2 -0
  54. package/dist/internal/planning/plan-guards.js.map +1 -1
  55. package/dist/internal/planning/rent-catalog.d.ts.map +1 -1
  56. package/dist/internal/planning/rent-catalog.js +19 -1
  57. package/dist/internal/planning/rent-catalog.js.map +1 -1
  58. package/dist/internal/planning/runtime-guards.d.ts.map +1 -1
  59. package/dist/internal/planning/runtime-guards.js +38 -10
  60. package/dist/internal/planning/runtime-guards.js.map +1 -1
  61. package/dist/planning/execution.d.ts.map +1 -1
  62. package/dist/planning/execution.js +32 -1
  63. package/dist/planning/execution.js.map +1 -1
  64. package/dist/planning/index.d.ts +19 -0
  65. package/dist/planning/index.d.ts.map +1 -1
  66. package/dist/planning/index.js.map +1 -1
  67. package/dist/planning/plan-validation.d.ts.map +1 -1
  68. package/dist/planning/plan-validation.js +8 -0
  69. package/dist/planning/plan-validation.js.map +1 -1
  70. package/package.json +1 -1
@@ -169,6 +169,17 @@ export interface PlanTopUpClaimStakeRentOptions {
169
169
  readonly amount: bigint;
170
170
  readonly authorization: PlanAuthorization;
171
171
  }
172
+ /** Exact inputs for settling one owned Claim Stake's Building XP.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * declare const authorization: PlanAuthorization;
177
+ * const options: PlanSettleClaimStakeBuildingXpOptions = { authorization };
178
+ * ```
179
+ */
180
+ export interface PlanSettleClaimStakeBuildingXpOptions {
181
+ readonly authorization: PlanAuthorization;
182
+ }
172
183
  /** One exact raw cargo request for starting a Claim Stake Fleet transfer.
173
184
  *
174
185
  * @example
@@ -222,6 +233,27 @@ export interface PlanRecoverClaimStakeFleetTransferOptions {
222
233
  readonly atUnixSeconds: bigint;
223
234
  readonly authorization: PlanAuthorization;
224
235
  }
236
+ /** Exact inputs for the permissionless normal exit of one elapsed Claim Stake
237
+ * Fleet transfer.
238
+ *
239
+ * `funder` signs the exit, pays any rent shortfall of the Fleet and Claim
240
+ * Stake and receives any rent they free. It need not be the owner's key.
241
+ * `atUnixSeconds` is an explicit non-negative Unix timestamp used to prove the
242
+ * transfer has ended. The planner never reads a local clock.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * declare const funder: Address;
247
+ * const options: PlanExitClaimStakeFleetTransferOptions = {
248
+ * atUnixSeconds: 1_700_000_100n,
249
+ * funder,
250
+ * };
251
+ * ```
252
+ */
253
+ export interface PlanExitClaimStakeFleetTransferOptions {
254
+ readonly atUnixSeconds: bigint;
255
+ readonly funder: Address;
256
+ }
225
257
  interface FleetSnapshot extends Omit<ResolvedFleetAccountData, 'ownerProfile'> {
226
258
  readonly kind: 'fleet';
227
259
  readonly address: Address;
@@ -432,6 +464,35 @@ export declare function planDeconstructClaimStake(ctx: SageContext, stake: Claim
432
464
  * ```
433
465
  */
434
466
  export declare function planTopUpClaimStakeRent(ctx: SageContext, stake: ClaimStakeSnapshot, input: PlanTopUpClaimStakeRentOptions): Promise<Plan>;
467
+ /** Plans settling the Building XP one owned Claim Stake has earned.
468
+ *
469
+ * The game first brings the stake's rent and production up to date, which
470
+ * records any further paid operational time, then pays its recorded
471
+ * operational work to the owner's Character as Building XP, up to the
472
+ * Character's remaining Building allowance, and awards any claim Mining XP the
473
+ * stake recorded. Work beyond the allowance is discarded rather than carried,
474
+ * so the planner refuses while the allowance is empty, and it refuses a stake
475
+ * that has recorded no work and is not operational. The Plan states the
476
+ * recorded XP and the allowance; the exact grant remains chain-authoritative.
477
+ *
478
+ * Requires Disabled rent, the stake's current System generation and the
479
+ * Profile's Starbase Player there from the current Starbase.
480
+ * Bringing a large structure up to date can take more than the default
481
+ * 200,000 compute units, so simulate first and raise `computeUnitLimit` when
482
+ * assembling if needed.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * declare const ctx: SageContext;
487
+ * declare const stake: ClaimStakeSnapshot;
488
+ * declare const authorization: PlanAuthorization;
489
+ * const plan = await planSettleClaimStakeBuildingXp(ctx, stake, {
490
+ * authorization,
491
+ * });
492
+ * console.log(plan.describe());
493
+ * ```
494
+ */
495
+ export declare function planSettleClaimStakeBuildingXp(ctx: SageContext, stake: ClaimStakeSnapshot, input: PlanSettleClaimStakeBuildingXpOptions): Promise<Plan>;
435
496
  /** Plans the start of one Fleet transfer to an owned active Claim Stake.
436
497
  *
437
498
  * The planner validates the shared Profile/Game, idle Fleet with normalized
@@ -516,4 +577,47 @@ export declare function planStartClaimStakeFleetTransfer(ctx: SageContext, fleet
516
577
  * ```
517
578
  */
518
579
  export declare function planRecoverClaimStakeFleetTransfer(ctx: SageContext, fleet: FleetSnapshot, stake: ClaimStakeSnapshot, input: PlanRecoverClaimStakeFleetTransferOptions): Promise<Plan>;
580
+ /** Plans the permissionless normal exit of one elapsed Claim Stake Fleet transfer.
581
+ *
582
+ * The exit completes a transfer started with
583
+ * {@link planStartClaimStakeFleetTransfer}: the game accrues the Claim Stake's
584
+ * production, moves the queued loads and unloads, and returns the Fleet to
585
+ * idle. Any signer may exit an elapsed transfer, so the Plan's only signer is
586
+ * the `funder`, which pays any rent shortfall of the Fleet and Claim Stake and
587
+ * receives any rent they free.
588
+ *
589
+ * The planner requires the explicit timestamp to have reached the transfer's
590
+ * end, and the Plan carries a guard that execution checks against the chain
591
+ * Clock and the Fleet's stored end before signing: before the end, the game
592
+ * leaves the Fleet in its transfer while the funder still pays the fee. It
593
+ * requires the Fleet's required crew, the same owner Profile for the Fleet
594
+ * and the active Claim Stake, the canonical Planet, System, active Starbase
595
+ * and owner Starbase Player, and Disabled rent, as the transfer start does.
596
+ *
597
+ * When fresh state shows the queued cargo cannot move (a Fleet-side shortfall
598
+ * or overflow, an invalid queued cargo id, or a Claim Stake shortfall of a
599
+ * resource the stake does not produce), the Plan still exits: the game then
600
+ * returns the Fleet to idle without moving cargo, and the description says
601
+ * so. The game accrues the stake's production before moving cargo, so a
602
+ * stored shortfall of a resource the stake produces, or a stake storage
603
+ * overflow while it consumes a stored resource, is described as depending on that
604
+ * accrual. The game also limits Fuel to the stake's separate fuel storage,
605
+ * which this Plan does not enforce; if the cargo no longer fits then, the exit
606
+ * likewise moves nothing. Use {@link planRecoverClaimStakeFleetTransfer} only
607
+ * when the owner wants to abandon a non-executable transfer instead.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * declare const ctx: SageContext;
612
+ * declare const fleet: FleetSnapshot;
613
+ * declare const stake: ClaimStakeSnapshot;
614
+ * declare const funder: Address;
615
+ * const plan = await planExitClaimStakeFleetTransfer(ctx, fleet, stake, {
616
+ * atUnixSeconds: 1_700_000_100n,
617
+ * funder,
618
+ * });
619
+ * console.log(plan.describe());
620
+ * ```
621
+ */
622
+ export declare function planExitClaimStakeFleetTransfer(ctx: SageContext, fleet: FleetSnapshot, stake: ClaimStakeSnapshot, input: PlanExitClaimStakeFleetTransferOptions): Promise<Plan>;
519
623
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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,EAAE,WAAW,EAChB,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,kBAAkB,EACzB,KAAK,EAAE,sCAAsC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAgNf"}
@@ -16,6 +16,7 @@ import { deriveProfileFactionAddress, profileFactionIdentityAccountDefinition, }
16
16
  import { deriveStarbasePlayerAddress, starbasePlayerAccountDefinition, } from '../../internal/c4/starbase.js';
17
17
  import { celestialBodyAccountDefinition, deriveCelestialBodyAddress, deriveStarSystemAddress, starSystemAccountDefinition, } from '../../internal/c4/world.js';
18
18
  import { resolveXpRuntime } from '../../internal/planning/xp-runtime.js';
19
+ import { describeBuildingXpSettlement } from '../../internal/planning/building-xp.js';
19
20
  import { readClaimStakeStorageAction } from '../../internal/planning/claim-stake-storage-actions.js';
20
21
  import { RENT_ADDRESS } from '../../internal/planning/rent.js';
21
22
  import { planStorageFunding } from '../../internal/planning/storage-actions.js';
@@ -27,7 +28,7 @@ import { requireProfileStarbasePlayer } from '../../internal/planning/starbase-p
27
28
  import { requireGameAddress } from '../../internal/game-context.js';
28
29
  import { structurePlacementFee } from '../../internal/planning/placement-fee.js';
29
30
  import { cargoStorageUnits, cargoStorageUnitsFloor, } from '../../internal/cargo.js';
30
- import { adaptCancelClaimStakeBuildingChangesInstruction, adaptClaimStakeBuildingChangesInstruction, adaptDeconstructClaimStakeInstruction, adaptFinalizeClaimStakeBuildingChangesInstruction, adaptPlaceClaimStakeInstruction, adaptRecoverClaimStakeFleetTransferInstruction, adaptStartClaimStakeFleetTransferInstruction, adaptTopUpClaimStakeRentInstruction, readPlanAuthorization, } from '../../internal/planning/authorization-adapter.js';
31
+ import { adaptCancelClaimStakeBuildingChangesInstruction, adaptClaimStakeBuildingChangesInstruction, adaptDeconstructClaimStakeInstruction, adaptExitClaimStakeFleetTransferInstruction, adaptFinalizeClaimStakeBuildingChangesInstruction, adaptPlaceClaimStakeInstruction, adaptRecoverClaimStakeFleetTransferInstruction, adaptSettleClaimStakeBuildingXpInstruction, adaptStartClaimStakeFleetTransferInstruction, adaptTopUpClaimStakeRentInstruction, readPlanAuthorization, } from '../../internal/planning/authorization-adapter.js';
31
32
  import { buildPlannerPlan } from '../../planning/plan-construction.js';
32
33
  import { readFreshGameCargoDefinitions } from '../../registry/cargo.js';
33
34
  import { listClaimStakeBuildingDefinitions, resolveCargo, } from '../../registry/index.js';
@@ -189,6 +190,11 @@ function validateDeconstructOptions(value) {
189
190
  exactKeys(options, 'options', ['authorization']);
190
191
  return { authorization: readPlanAuthorization(options.authorization) };
191
192
  }
193
+ function validateSettleBuildingXpOptions(value) {
194
+ const options = record(value, 'options');
195
+ exactKeys(options, 'options', ['authorization']);
196
+ return { authorization: readPlanAuthorization(options.authorization) };
197
+ }
192
198
  function validateTopUpRentOptions(value) {
193
199
  const options = record(value, 'options');
194
200
  exactKeys(options, 'options', ['amount', 'authorization']);
@@ -238,16 +244,28 @@ function validateStartFleetTransferOptions(value) {
238
244
  }
239
245
  return { authorization, load, unload };
240
246
  }
247
+ function unixSeconds(value, action) {
248
+ if (typeof value !== 'bigint' || value < 0n || value > U64_MAX) {
249
+ invalid('atUnixSeconds', value, `a non-negative bigint through ${String(U64_MAX)} (unsigned u64 Unix seconds)`, `Set atUnixSeconds to the explicit current Unix timestamp before retrying ${action}.`);
250
+ }
251
+ return value;
252
+ }
241
253
  function validateRecoverFleetTransferOptions(value) {
242
254
  const options = record(value, 'options');
243
255
  exactKeys(options, 'options', ['atUnixSeconds', 'authorization']);
244
256
  const authorization = readPlanAuthorization(options.authorization);
245
- if (typeof options.atUnixSeconds !== 'bigint' ||
246
- options.atUnixSeconds < 0n ||
247
- options.atUnixSeconds > U64_MAX) {
248
- invalid('atUnixSeconds', options.atUnixSeconds, `a non-negative bigint through ${String(U64_MAX)} (unsigned u64 Unix seconds)`, 'Set atUnixSeconds to the explicit current Unix timestamp before retrying recovery.');
249
- }
250
- return { atUnixSeconds: options.atUnixSeconds, authorization };
257
+ return {
258
+ atUnixSeconds: unixSeconds(options.atUnixSeconds, 'recovery'),
259
+ authorization,
260
+ };
261
+ }
262
+ function validateExitFleetTransferOptions(value) {
263
+ const options = record(value, 'options');
264
+ exactKeys(options, 'options', ['atUnixSeconds', 'funder']);
265
+ return {
266
+ atUnixSeconds: unixSeconds(options.atUnixSeconds, 'the exit'),
267
+ funder: address(options.funder, 'funder'),
268
+ };
251
269
  }
252
270
  function requireAccount(account, accountAddress, message) {
253
271
  return account ?? fail(message, accountAddress);
@@ -1569,6 +1587,109 @@ export async function planTopUpClaimStakeRent(ctx, stake, input) {
1569
1587
  summary: description,
1570
1588
  });
1571
1589
  }
1590
+ /** Plans settling the Building XP one owned Claim Stake has earned.
1591
+ *
1592
+ * The game first brings the stake's rent and production up to date, which
1593
+ * records any further paid operational time, then pays its recorded
1594
+ * operational work to the owner's Character as Building XP, up to the
1595
+ * Character's remaining Building allowance, and awards any claim Mining XP the
1596
+ * stake recorded. Work beyond the allowance is discarded rather than carried,
1597
+ * so the planner refuses while the allowance is empty, and it refuses a stake
1598
+ * that has recorded no work and is not operational. The Plan states the
1599
+ * recorded XP and the allowance; the exact grant remains chain-authoritative.
1600
+ *
1601
+ * Requires Disabled rent, the stake's current System generation and the
1602
+ * Profile's Starbase Player there from the current Starbase.
1603
+ * Bringing a large structure up to date can take more than the default
1604
+ * 200,000 compute units, so simulate first and raise `computeUnitLimit` when
1605
+ * assembling if needed.
1606
+ *
1607
+ * @example
1608
+ * ```ts
1609
+ * declare const ctx: SageContext;
1610
+ * declare const stake: ClaimStakeSnapshot;
1611
+ * declare const authorization: PlanAuthorization;
1612
+ * const plan = await planSettleClaimStakeBuildingXp(ctx, stake, {
1613
+ * authorization,
1614
+ * });
1615
+ * console.log(plan.describe());
1616
+ * ```
1617
+ */
1618
+ export async function planSettleClaimStakeBuildingXp(ctx, stake, input) {
1619
+ const options = validateSettleBuildingXpOptions(input);
1620
+ const game = requireGameAddress(ctx);
1621
+ const { profile } = options.authorization;
1622
+ const character = await requireOwnedStake(ctx.programs, stake, game, profile);
1623
+ const currencyCache = await claimStakeCurrencyCache(ctx.programs, game);
1624
+ const action = 'the Building XP settlement';
1625
+ const [{ bodyAccount, currentBody, currentStake, extraAccounts: [characterCandidate, cacheCandidate], stakeAccount, }, rent, xp,] = await Promise.all([
1626
+ readOwnedStake(ctx, stake, action, [character, currencyCache]),
1627
+ requireDisabledStakeRent(ctx, game, stake.address, action),
1628
+ resolveClaimStakeXp(ctx, game, character),
1629
+ ]);
1630
+ if (!sameOwnedStake(currentStake, stake, game, profile)) {
1631
+ fail(`Claim Stake ${stake.address} changed or does not match its loaded ownership, Body, definitions, buildings, or System generation. Refresh it and retry ${action}.`, stake.address);
1632
+ }
1633
+ // A Character's XP runtime names both accounts or refuses the Character.
1634
+ const xpBudget = xp.accounts.xpBudget;
1635
+ const xpBudgetConfig = xp.accounts.xpBudgetConfig;
1636
+ const { system } = await requireStakePlanet(ctx.programs, currentBody, stake, game, action);
1637
+ // The settlement writes the Character's XP, which other actions change
1638
+ // too, so the Plan checks its identity without pinning its state.
1639
+ requireProfileCharacter(ctx.programs, characterCandidate, character, profile, game, action);
1640
+ const [cacheGuard, { currentPlayer, currentSystem, player, playerAccount, systemAccount },] = await Promise.all([
1641
+ requireCurrencyCache(ctx.programs, cacheCandidate, currencyCache, game, action, 'planSettleClaimStakeBuildingXp'),
1642
+ readStakeStarbase(ctx, stake, game, system, character, profile, action),
1643
+ ]);
1644
+ if (currentPlayer.sequenceId !== currentSystem.sequenceId)
1645
+ fail(`Starbase Player ${player} was registered at an earlier Starbase in Star System ${system}, which the game treats as destroyed. Register at the current Starbase and retry ${action}.`, player);
1646
+ const settlement = await describeBuildingXpSettlement(ctx, {
1647
+ structure: `Claim Stake ${stake.address}`,
1648
+ game,
1649
+ character,
1650
+ xpBudget,
1651
+ xpBudgetConfig,
1652
+ recorded: currentStake.operationalXp,
1653
+ operational: currentStake.state.kind === 'active' &&
1654
+ currentStake.constructionRemainingSeconds === 0n,
1655
+ });
1656
+ const description = `Settle Claim Stake ${stake.address}'s Building XP after bringing its rent and production up to date. ${settlement.description} Any claim Mining XP the stake recorded is awarded too.`;
1657
+ return buildPlannerPlan(ctx.programs, {
1658
+ kind: 'claim-stakes.settle-building-xp',
1659
+ preconditions: [
1660
+ ...(await Promise.all([
1661
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its ownership, buildings, rent, production, lifecycle state, recorded Building work, Body, and System generation.`),
1662
+ planetPrecondition(bodyAccount, system),
1663
+ systemPrecondition(systemAccount, currentSystem.name),
1664
+ playerPrecondition(playerAccount, player),
1665
+ ])),
1666
+ cacheGuard,
1667
+ xp.guard,
1668
+ settlement.guard,
1669
+ ...rent.guards,
1670
+ ],
1671
+ steps: [
1672
+ {
1673
+ describes: description,
1674
+ instruction: adaptSettleClaimStakeBuildingXpInstruction(ctx.programs, {
1675
+ authorization: options.authorization,
1676
+ celestialBody: stake.body.address,
1677
+ character,
1678
+ claimStakeInstance: stake.address,
1679
+ currencyCache,
1680
+ game,
1681
+ ...rent.accounts,
1682
+ systemAndStarbasePlayerStarbasePlayer: player,
1683
+ systemAndStarbasePlayerSystem: system,
1684
+ xpBudget,
1685
+ xpBudgetConfig,
1686
+ }),
1687
+ signers: [options.authorization.authority],
1688
+ },
1689
+ ],
1690
+ summary: description,
1691
+ });
1692
+ }
1572
1693
  function cargoAmount(values, cargoId) {
1573
1694
  return values.find((item) => item.cargoId === cargoId)?.amount ?? 0n;
1574
1695
  }
@@ -1838,6 +1959,93 @@ export async function planStartClaimStakeFleetTransfer(ctx, fleet, stake, input)
1838
1959
  summary: description,
1839
1960
  });
1840
1961
  }
1962
+ /** Proves from fresh state why a queued Claim Stake transfer cannot move its
1963
+ * cargo: a source shortfall, an invalid queued cargo id, or a destination
1964
+ * overflow. `reason` is undefined when the transfer looks executable.
1965
+ *
1966
+ * Recovery judges the stored cargo exactly as it stands. The normal exit
1967
+ * (`accrues`) first accrues the stake's production, so there a stored
1968
+ * Claim Stake shortfall of a resource the stake produces, or a stake storage
1969
+ * overflow while it consumes a stored resource, is only `conditional`: the cargo may
1970
+ * still move after accrual. Fleet-side shortfalls and overflows, invalid
1971
+ * cargo ids, and stake shortfalls of resources it does not produce stay
1972
+ * definite. Neither mode enforces the stake's separate fuel storage. */
1973
+ async function transferBlocker(ctx, game, currentFleet, state, currentStake, action, accrues = false) {
1974
+ const rates = currentStake.production.netResources;
1975
+ const produces = (cargoId) => accrues &&
1976
+ rates.some((rate) => rate.cargoId === cargoId && rate.ratePerSecondRaw > 0n);
1977
+ let reason;
1978
+ let conditional;
1979
+ for (const request of state.load) {
1980
+ const available = cargoAmount(currentStake.production.cargoPod.amounts, request.cargoId);
1981
+ if (available < request.amount) {
1982
+ const shortfall = `Claim Stake source shortfall for cargo id ${String(request.cargoId)}`;
1983
+ if (produces(request.cargoId))
1984
+ conditional ??= shortfall;
1985
+ else {
1986
+ reason = shortfall;
1987
+ break;
1988
+ }
1989
+ }
1990
+ }
1991
+ if (reason === undefined) {
1992
+ for (const request of state.unload) {
1993
+ const available = fleetCargoHoldAmount(currentFleet, request.cargoId);
1994
+ if (available < request.amount) {
1995
+ reason = `Fleet source shortfall for cargo id ${String(request.cargoId)}`;
1996
+ break;
1997
+ }
1998
+ }
1999
+ }
2000
+ let gameAccount;
2001
+ let queuedDefinitions = new Map();
2002
+ if (reason === undefined) {
2003
+ const cargoIds = [
2004
+ ...new Set([...state.load, ...state.unload].map(({ cargoId }) => cargoId)),
2005
+ ];
2006
+ const freshGame = (await readFreshGameCargoDefinitions(ctx)) ??
2007
+ fail(`Game ${game} is missing. Refresh the configured Game and retry ${action}.`, game);
2008
+ gameAccount = freshGame.account;
2009
+ queuedDefinitions = new Map(freshGame.data.definitions.map((definition) => [
2010
+ definition.id,
2011
+ definition,
2012
+ ]));
2013
+ const invalidCargoId = cargoIds.find((cargoId) => !queuedDefinitions.has(cargoId));
2014
+ if (invalidCargoId !== undefined) {
2015
+ reason = `invalid queued cargo id ${String(invalidCargoId)}`;
2016
+ }
2017
+ }
2018
+ if (reason === undefined) {
2019
+ // Every queued load, including Fuel and Ammunition, targets the cargo hold.
2020
+ const loadCargoStorage = state.load.reduce((total, { amount, cargoId }) => total +
2021
+ cargoStorageUnits(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
2022
+ // Only an overflow the unloads certainly cause, after the loads free
2023
+ // their storage, proves the stake side non-executable.
2024
+ const unloadStorage = state.unload.reduce((total, { amount, cargoId }) => total +
2025
+ cargoStorageUnitsFloor(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
2026
+ if (currentFleet.cargoHold.storageCost + loadCargoStorage >
2027
+ currentFleet.stats.cargo.cargoCapacity) {
2028
+ reason = 'Fleet cargo destination overflow';
2029
+ }
2030
+ else if (currentStake.production.cargoPod.storageCost -
2031
+ loadCargoStorage +
2032
+ unloadStorage >
2033
+ currentStake.production.resourceCapacityRaw) {
2034
+ const overflow = 'Claim Stake resource storage overflow';
2035
+ // Consuming a stored resource during accrual can free stake storage
2036
+ // before the exit moves cargo.
2037
+ if (accrues &&
2038
+ rates.some((rate) => rate.ratePerSecondRaw < 0n &&
2039
+ cargoAmount(currentStake.production.cargoPod.amounts, rate.cargoId) > 0n))
2040
+ conditional ??= overflow;
2041
+ else
2042
+ reason = overflow;
2043
+ }
2044
+ }
2045
+ return reason === undefined && conditional !== undefined
2046
+ ? { conditional, gameAccount, reason }
2047
+ : { gameAccount, reason };
2048
+ }
1841
2049
  /** Plans owner-authorized recovery of one provably non-executable Claim Stake transfer.
1842
2050
  *
1843
2051
  * Recovery is available only after the explicit transfer lock time and only
@@ -1912,60 +2120,7 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1912
2120
  if (!sameTransferStake(currentStake, stake, game, options.authorization.profile)) {
1913
2121
  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);
1914
2122
  }
1915
- let reason;
1916
- for (const request of currentFleet.state.load) {
1917
- const available = cargoAmount(currentStake.production.cargoPod.amounts, request.cargoId);
1918
- if (available < request.amount) {
1919
- reason = `Claim Stake source shortfall for cargo id ${String(request.cargoId)}`;
1920
- break;
1921
- }
1922
- }
1923
- if (reason === undefined) {
1924
- for (const request of currentFleet.state.unload) {
1925
- const available = fleetCargoHoldAmount(currentFleet, request.cargoId);
1926
- if (available < request.amount) {
1927
- reason = `Fleet source shortfall for cargo id ${String(request.cargoId)}`;
1928
- break;
1929
- }
1930
- }
1931
- }
1932
- let gameAccount;
1933
- let queuedDefinitions = new Map();
1934
- if (reason === undefined) {
1935
- const cargoIds = [
1936
- ...new Set([...currentFleet.state.load, ...currentFleet.state.unload].map(({ cargoId }) => cargoId)),
1937
- ];
1938
- const freshGame = (await readFreshGameCargoDefinitions(ctx)) ??
1939
- fail(`Game ${game} is missing. Refresh the configured Game and retry Claim Stake transfer recovery.`, game);
1940
- gameAccount = freshGame.account;
1941
- queuedDefinitions = new Map(freshGame.data.definitions.map((definition) => [
1942
- definition.id,
1943
- definition,
1944
- ]));
1945
- const invalidCargoId = cargoIds.find((cargoId) => !queuedDefinitions.has(cargoId));
1946
- if (invalidCargoId !== undefined) {
1947
- reason = `invalid queued cargo id ${String(invalidCargoId)}`;
1948
- }
1949
- }
1950
- if (reason === undefined) {
1951
- // Every queued load, including Fuel and Ammunition, targets the cargo hold.
1952
- const loadCargoStorage = currentFleet.state.load.reduce((total, { amount, cargoId }) => total +
1953
- cargoStorageUnits(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
1954
- // Only an overflow the unloads certainly cause, after the loads free
1955
- // their storage, proves the stake side non-executable.
1956
- const unloadStorage = currentFleet.state.unload.reduce((total, { amount, cargoId }) => total +
1957
- cargoStorageUnitsFloor(amount, queuedDefinitions.get(cargoId).storageCost), 0n);
1958
- if (currentFleet.cargoHold.storageCost + loadCargoStorage >
1959
- currentFleet.stats.cargo.cargoCapacity) {
1960
- reason = 'Fleet cargo destination overflow';
1961
- }
1962
- else if (currentStake.production.cargoPod.storageCost -
1963
- loadCargoStorage +
1964
- unloadStorage >
1965
- currentStake.production.resourceCapacityRaw) {
1966
- reason = 'Claim Stake resource storage overflow';
1967
- }
1968
- }
2123
+ const { gameAccount, reason } = await transferBlocker(ctx, game, currentFleet, currentFleet.state, currentStake, 'Claim Stake transfer recovery');
1969
2124
  if (reason === undefined) {
1970
2125
  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);
1971
2126
  }
@@ -1996,4 +2151,158 @@ export async function planRecoverClaimStakeFleetTransfer(ctx, fleet, stake, inpu
1996
2151
  summary: description,
1997
2152
  });
1998
2153
  }
2154
+ /** Plans the permissionless normal exit of one elapsed Claim Stake Fleet transfer.
2155
+ *
2156
+ * The exit completes a transfer started with
2157
+ * {@link planStartClaimStakeFleetTransfer}: the game accrues the Claim Stake's
2158
+ * production, moves the queued loads and unloads, and returns the Fleet to
2159
+ * idle. Any signer may exit an elapsed transfer, so the Plan's only signer is
2160
+ * the `funder`, which pays any rent shortfall of the Fleet and Claim Stake and
2161
+ * receives any rent they free.
2162
+ *
2163
+ * The planner requires the explicit timestamp to have reached the transfer's
2164
+ * end, and the Plan carries a guard that execution checks against the chain
2165
+ * Clock and the Fleet's stored end before signing: before the end, the game
2166
+ * leaves the Fleet in its transfer while the funder still pays the fee. It
2167
+ * requires the Fleet's required crew, the same owner Profile for the Fleet
2168
+ * and the active Claim Stake, the canonical Planet, System, active Starbase
2169
+ * and owner Starbase Player, and Disabled rent, as the transfer start does.
2170
+ *
2171
+ * When fresh state shows the queued cargo cannot move (a Fleet-side shortfall
2172
+ * or overflow, an invalid queued cargo id, or a Claim Stake shortfall of a
2173
+ * resource the stake does not produce), the Plan still exits: the game then
2174
+ * returns the Fleet to idle without moving cargo, and the description says
2175
+ * so. The game accrues the stake's production before moving cargo, so a
2176
+ * stored shortfall of a resource the stake produces, or a stake storage
2177
+ * overflow while it consumes a stored resource, is described as depending on that
2178
+ * accrual. The game also limits Fuel to the stake's separate fuel storage,
2179
+ * which this Plan does not enforce; if the cargo no longer fits then, the exit
2180
+ * likewise moves nothing. Use {@link planRecoverClaimStakeFleetTransfer} only
2181
+ * when the owner wants to abandon a non-executable transfer instead.
2182
+ *
2183
+ * @example
2184
+ * ```ts
2185
+ * declare const ctx: SageContext;
2186
+ * declare const fleet: FleetSnapshot;
2187
+ * declare const stake: ClaimStakeSnapshot;
2188
+ * declare const funder: Address;
2189
+ * const plan = await planExitClaimStakeFleetTransfer(ctx, fleet, stake, {
2190
+ * atUnixSeconds: 1_700_000_100n,
2191
+ * funder,
2192
+ * });
2193
+ * console.log(plan.describe());
2194
+ * ```
2195
+ */
2196
+ export async function planExitClaimStakeFleetTransfer(ctx, fleet, stake, input) {
2197
+ const options = validateExitFleetTransferOptions(input);
2198
+ const game = requireGameAddress(ctx);
2199
+ if (fleet.game !== game || stake.game !== game) {
2200
+ fail(`Fleet ${fleet.address} and Claim Stake ${stake.address} must both belong to configured Game ${game}. Refresh both snapshots through this context and retry the exit.`, fleet.game !== game ? fleet.address : stake.address);
2201
+ }
2202
+ if (fleet.state.kind !== 'claimStakeTransfer') {
2203
+ fail(`Fleet ${fleet.name} is ${fleet.state.kind}, not in a Claim Stake transfer. Refresh it and exit only a running Claim Stake transfer.`, fleet.address);
2204
+ }
2205
+ if (fleet.state.claimStake.address !== stake.address ||
2206
+ fleet.state.planet.address !== stake.body.address) {
2207
+ fail(`Fleet ${fleet.name}'s Claim Stake transfer does not reference Claim Stake ${stake.address} and its Body ${stake.body.address}. Supply the transfer's current Claim Stake snapshot and retry the exit.`, fleet.address);
2208
+ }
2209
+ if (options.atUnixSeconds < fleet.state.endAtUnixSeconds) {
2210
+ fail(`Fleet ${fleet.name}'s Claim Stake transfer has not ended at Unix timestamp ${String(options.atUnixSeconds)}; it ends at ${String(fleet.state.endAtUnixSeconds)}. Wait until it ends, provide a current timestamp, and retry the exit.`, fleet.address);
2211
+ }
2212
+ const profile = fleet.ownerProfile.address;
2213
+ if (stake.state.kind !== 'active') {
2214
+ fail(`Claim Stake ${stake.address} is ${stake.state.kind}, but Atlas Kit plans the normal exit only for an active Claim Stake. Restore the stake's rent or finish its design, refresh it, and retry the exit.`, stake.address);
2215
+ }
2216
+ const character = await requireOwnedStake(ctx.programs, stake, game, profile);
2217
+ const action = 'the Claim Stake transfer exit';
2218
+ const [{ bodyAccount, currentBody, currentStake, extraAccounts: [fleetCandidate], stakeAccount, }, rent,] = await Promise.all([
2219
+ readOwnedStake(ctx, stake, action, [fleet.address]),
2220
+ requireDisabledStakeRent(ctx, game, stake.address, action),
2221
+ ]);
2222
+ const fleetAccount = requireAccount(fleetCandidate, fleet.address, `Fleet ${fleet.name} is missing. Refresh it and retry the Claim Stake transfer exit.`);
2223
+ const currentFleet = fleetAccountDefinition.decode(fleetAccount, ctx.programs);
2224
+ if (!sameTransferFleet(currentFleet, fleet, game, profile) ||
2225
+ currentFleet.state.kind !== 'claimStakeTransfer' ||
2226
+ currentFleet.state.claimStake !== stake.address ||
2227
+ currentFleet.state.planet !== stake.body.address ||
2228
+ currentFleet.state.endAtUnixSeconds !== fleet.state.endAtUnixSeconds ||
2229
+ !sameCargoAmounts(currentFleet.state.load, fleet.state.load) ||
2230
+ !sameCargoAmounts(currentFleet.state.unload, fleet.state.unload) ||
2231
+ (await deriveFleetAddress(ctx.programs, currentFleet)) !== fleet.address) {
2232
+ 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 the exit.`, fleet.address);
2233
+ }
2234
+ if (currentFleet.crewCount < currentFleet.stats.misc.requiredCrew) {
2235
+ fail(`Fleet ${fleet.name} has ${String(currentFleet.crewCount)} crew but needs ${String(currentFleet.stats.misc.requiredCrew)}, and the game exits a Claim Stake transfer only for a Fleet with its required crew. Load crew, refresh it, and retry.`, fleet.address);
2236
+ }
2237
+ if (!sameTransferStake(currentStake, stake, game, profile)) {
2238
+ 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 the exit.`, stake.address);
2239
+ }
2240
+ const { system } = await requireStakePlanet(ctx.programs, currentBody, stake, game, action);
2241
+ const currencyCache = await claimStakeCurrencyCache(ctx.programs, game);
2242
+ const { currentSystem, extraAccounts: [currencyCandidate], player, playerAccount, systemAccount, } = await readStakeStarbase(ctx, stake, game, system, character, profile, action, [currencyCache]);
2243
+ const currencyGuard = await requireCurrencyCache(ctx.programs, currencyCandidate, currencyCache, game, action, 'Claim Stake Fleet transfer exit');
2244
+ const { conditional, gameAccount, reason } = await transferBlocker(ctx, game, currentFleet, currentFleet.state, currentStake, action, true);
2245
+ const xp = await resolveClaimStakeXp(ctx, game);
2246
+ const queued = [
2247
+ ...describeCargoRequests('load', currentFleet.state.load.map(({ amount, cargoId }) => ({
2248
+ amount,
2249
+ cargoId,
2250
+ }))),
2251
+ ...describeCargoRequests('unload', currentFleet.state.unload.map(({ amount, cargoId }) => ({
2252
+ amount,
2253
+ cargoId,
2254
+ }))),
2255
+ ];
2256
+ const outcome = reason !== undefined
2257
+ ? `Fresh state shows the queued cargo (${queued.join('; ')}) cannot move (${reason}), so the game is expected to return the Fleet to idle without moving cargo.`
2258
+ : conditional !== undefined
2259
+ ? `The stored Claim Stake state shows a ${conditional}, but the game accrues the stake's production first, so the queued cargo (${queued.join('; ')}) moves only if that accrual resolves it; otherwise the Fleet returns to idle without moving cargo. This Plan cannot tell which; the exit returns the Fleet to idle either way.`
2260
+ : `The game accrues the Claim Stake's production, then moves the queued cargo (${queued.join('; ')}) and returns the Fleet to idle. It checks the stake's storage again after accruing production and limits Fuel to the stake's separate fuel storage, which this Plan does not enforce; if the cargo no longer fits, the Fleet returns to idle without moving cargo.`;
2261
+ const description = `Exit fleet ${fleet.name}'s elapsed transfer with Claim Stake ${stake.address}. ${outcome} Funder ${options.funder} signs, pays any rent shortfall of the Fleet and Claim Stake and receives any rent they free.`;
2262
+ return buildPlannerPlan(ctx.programs, {
2263
+ kind: 'claim-stakes.exit-fleet-transfer',
2264
+ preconditions: [
2265
+ xp.guard,
2266
+ ...(await Promise.all([
2267
+ accountStatePrecondition(fleetAccount, `Fleet ${fleet.name} retains its owner, normalized crew, cargo and exact elapsed Claim Stake transfer.`),
2268
+ accountStatePrecondition(stakeAccount, `Claim Stake ${stake.address} retains its owner, active state, cargo, capacity, Body, and System generation.`),
2269
+ planetPrecondition(bodyAccount, system),
2270
+ systemPrecondition(systemAccount, currentSystem.name),
2271
+ playerPrecondition(playerAccount, player),
2272
+ ...(gameAccount === undefined
2273
+ ? []
2274
+ : [
2275
+ accountStatePrecondition(gameAccount, `Game ${game} retains the cargo definitions used to describe the exit.`),
2276
+ ]),
2277
+ ])),
2278
+ currencyGuard,
2279
+ ...rent.guards,
2280
+ {
2281
+ kind: 'claim-stake-transfer-exit-window',
2282
+ address: fleet.address,
2283
+ endsAtUnixSeconds: currentFleet.state.endAtUnixSeconds,
2284
+ describes: `The chain Clock has reached Fleet ${fleet.name}'s transfer end ${String(currentFleet.state.endAtUnixSeconds)} when the exit executes; before then the game leaves the Fleet in its transfer.`,
2285
+ },
2286
+ ],
2287
+ steps: [
2288
+ {
2289
+ describes: description,
2290
+ instruction: adaptExitClaimStakeFleetTransferInstruction(ctx.programs, {
2291
+ celestialBody: stake.body.address,
2292
+ claimStakeInstance: stake.address,
2293
+ currencyCache,
2294
+ fleet: fleet.address,
2295
+ funder: options.funder,
2296
+ game,
2297
+ profile,
2298
+ ...rent.accounts,
2299
+ systemAndStarbasePlayerStarbasePlayer: player,
2300
+ systemAndStarbasePlayerSystem: system,
2301
+ }),
2302
+ signers: [options.funder],
2303
+ },
2304
+ ],
2305
+ summary: description,
2306
+ });
2307
+ }
1999
2308
  //# sourceMappingURL=index.js.map