@aephia/atlas-kit 0.6.0-next.4 → 0.6.0-next.41
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.
- package/README.md +3 -1
- package/dist/cargo/actions/deposit.d.ts.map +1 -1
- package/dist/cargo/actions/deposit.js +51 -9
- package/dist/cargo/actions/deposit.js.map +1 -1
- package/dist/cargo/actions/wallet-context.d.ts +2 -3
- package/dist/cargo/actions/wallet-context.d.ts.map +1 -1
- package/dist/cargo/actions/wallet-context.js +6 -33
- package/dist/cargo/actions/wallet-context.js.map +1 -1
- package/dist/cargo/actions/wallet-token.d.ts +1 -1
- package/dist/cargo/actions/wallet-token.d.ts.map +1 -1
- package/dist/cargo/actions/wallet-token.js +1 -9
- package/dist/cargo/actions/wallet-token.js.map +1 -1
- package/dist/cargo/actions/withdrawal.d.ts.map +1 -1
- package/dist/cargo/actions/withdrawal.js +54 -11
- package/dist/cargo/actions/withdrawal.js.map +1 -1
- package/dist/claim-stakes/actions/index.d.ts.map +1 -1
- package/dist/claim-stakes/actions/index.js +2 -3
- package/dist/claim-stakes/actions/index.js.map +1 -1
- package/dist/client/errors.d.ts +4 -0
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +31 -1
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/rpc-subscription-provider.d.ts +35 -0
- package/dist/client/rpc-subscription-provider.d.ts.map +1 -0
- package/dist/client/rpc-subscription-provider.js +190 -0
- package/dist/client/rpc-subscription-provider.js.map +1 -0
- package/dist/combat/actions/index.d.ts.map +1 -1
- package/dist/combat/actions/index.js +19 -8
- package/dist/combat/actions/index.js.map +1 -1
- package/dist/crafting/actions/index.d.ts.map +1 -1
- package/dist/crafting/actions/index.js +36 -13
- package/dist/crafting/actions/index.js.map +1 -1
- package/dist/crafting/index.d.ts +8 -2
- package/dist/crafting/index.d.ts.map +1 -1
- package/dist/crafting/index.js +1 -1
- package/dist/crafting/index.js.map +1 -1
- package/dist/factions/actions/index.d.ts +36 -0
- package/dist/factions/actions/index.d.ts.map +1 -0
- package/dist/factions/actions/index.js +136 -0
- package/dist/factions/actions/index.js.map +1 -0
- package/dist/factions/index.d.ts +1 -0
- package/dist/factions/index.d.ts.map +1 -1
- package/dist/factions/index.js +1 -0
- package/dist/factions/index.js.map +1 -1
- package/dist/factions/profile-faction.d.ts +58 -0
- package/dist/factions/profile-faction.d.ts.map +1 -0
- package/dist/factions/profile-faction.js +63 -0
- package/dist/factions/profile-faction.js.map +1 -0
- package/dist/fleets/actions/add-ship.d.ts +35 -0
- package/dist/fleets/actions/add-ship.d.ts.map +1 -0
- package/dist/fleets/actions/add-ship.js +149 -0
- package/dist/fleets/actions/add-ship.js.map +1 -0
- package/dist/fleets/actions/create-fleet.d.ts +36 -0
- package/dist/fleets/actions/create-fleet.d.ts.map +1 -0
- package/dist/fleets/actions/create-fleet.js +138 -0
- package/dist/fleets/actions/create-fleet.js.map +1 -0
- package/dist/fleets/actions/index.d.ts +22 -14
- package/dist/fleets/actions/index.d.ts.map +1 -1
- package/dist/fleets/actions/index.js +75 -53
- package/dist/fleets/actions/index.js.map +1 -1
- package/dist/fleets/actions/ship-import.d.ts +48 -0
- package/dist/fleets/actions/ship-import.d.ts.map +1 -0
- package/dist/fleets/actions/ship-import.js +322 -0
- package/dist/fleets/actions/ship-import.js.map +1 -0
- package/dist/identity/actions/create-profile.d.ts +56 -0
- package/dist/identity/actions/create-profile.d.ts.map +1 -0
- package/dist/identity/actions/create-profile.js +139 -0
- package/dist/identity/actions/create-profile.js.map +1 -0
- package/dist/identity/actions/index.d.ts +3 -0
- package/dist/identity/actions/index.d.ts.map +1 -1
- package/dist/identity/actions/index.js +11 -10
- package/dist/identity/actions/index.js.map +1 -1
- package/dist/identity/index.d.ts +15 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +15 -0
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/permissions.d.ts +124 -0
- package/dist/identity/permissions.d.ts.map +1 -0
- package/dist/identity/permissions.js +171 -0
- package/dist/identity/permissions.js.map +1 -0
- package/dist/internal/c4/cargo-bytes-config.d.ts +7 -0
- package/dist/internal/c4/cargo-bytes-config.d.ts.map +1 -0
- package/dist/internal/c4/cargo-bytes-config.js +19 -0
- package/dist/internal/c4/cargo-bytes-config.js.map +1 -0
- package/dist/internal/c4/character-registration.d.ts.map +1 -1
- package/dist/internal/c4/character-registration.js +2 -0
- package/dist/internal/c4/character-registration.js.map +1 -1
- package/dist/internal/c4/claim-stake.d.ts +0 -27
- package/dist/internal/c4/claim-stake.d.ts.map +1 -1
- package/dist/internal/c4/claim-stake.js +0 -33
- package/dist/internal/c4/claim-stake.js.map +1 -1
- package/dist/internal/c4/combat.d.ts +0 -27
- package/dist/internal/c4/combat.d.ts.map +1 -1
- package/dist/internal/c4/combat.js +0 -33
- package/dist/internal/c4/combat.js.map +1 -1
- package/dist/internal/c4/crafting-process-codec.d.ts +13 -0
- package/dist/internal/c4/crafting-process-codec.d.ts.map +1 -0
- package/dist/internal/c4/crafting-process-codec.js +34 -0
- package/dist/internal/c4/crafting-process-codec.js.map +1 -0
- package/dist/internal/c4/crafting.d.ts +10 -31
- package/dist/internal/c4/crafting.d.ts.map +1 -1
- package/dist/internal/c4/crafting.js +22 -43
- package/dist/internal/c4/crafting.js.map +1 -1
- package/dist/internal/c4/faction-adapter.d.ts +12 -0
- package/dist/internal/c4/faction-adapter.d.ts.map +1 -0
- package/dist/internal/c4/faction-adapter.js +52 -0
- package/dist/internal/c4/faction-adapter.js.map +1 -0
- package/dist/internal/c4/faction-enrollment.d.ts +6 -0
- package/dist/internal/c4/faction-enrollment.d.ts.map +1 -0
- package/dist/internal/c4/faction-enrollment.js +8 -0
- package/dist/internal/c4/faction-enrollment.js.map +1 -0
- package/dist/internal/c4/faction-epoch-meter.d.ts +10 -0
- package/dist/internal/c4/faction-epoch-meter.d.ts.map +1 -0
- package/dist/internal/c4/faction-epoch-meter.js +31 -0
- package/dist/internal/c4/faction-epoch-meter.js.map +1 -0
- package/dist/internal/c4/faction-treasury.d.ts +23 -0
- package/dist/internal/c4/faction-treasury.d.ts.map +1 -0
- package/dist/internal/c4/faction-treasury.js +48 -0
- package/dist/internal/c4/faction-treasury.js.map +1 -0
- package/dist/internal/c4/factions.d.ts +9 -57
- package/dist/internal/c4/factions.d.ts.map +1 -1
- package/dist/internal/c4/factions.js +21 -139
- package/dist/internal/c4/factions.js.map +1 -1
- package/dist/internal/c4/fleet-arrival.d.ts +27 -0
- package/dist/internal/c4/fleet-arrival.d.ts.map +1 -0
- package/dist/internal/c4/fleet-arrival.js +39 -0
- package/dist/internal/c4/fleet-arrival.js.map +1 -0
- package/dist/internal/c4/fleet-creation.d.ts +7 -0
- package/dist/internal/c4/fleet-creation.d.ts.map +1 -0
- package/dist/internal/c4/fleet-creation.js +180 -0
- package/dist/internal/c4/fleet-creation.js.map +1 -0
- package/dist/internal/c4/fleet-crew-binding.d.ts +9 -0
- package/dist/internal/c4/fleet-crew-binding.d.ts.map +1 -1
- package/dist/internal/c4/fleet-crew-binding.js +15 -0
- package/dist/internal/c4/fleet-crew-binding.js.map +1 -1
- package/dist/internal/c4/fleet-ship-assembly.d.ts +11 -0
- package/dist/internal/c4/fleet-ship-assembly.d.ts.map +1 -0
- package/dist/internal/c4/fleet-ship-assembly.js +44 -0
- package/dist/internal/c4/fleet-ship-assembly.js.map +1 -0
- package/dist/internal/c4/fleet.d.ts +10 -5
- package/dist/internal/c4/fleet.d.ts.map +1 -1
- package/dist/internal/c4/fleet.js.map +1 -1
- package/dist/internal/c4/game.d.ts +20 -6
- package/dist/internal/c4/game.d.ts.map +1 -1
- package/dist/internal/c4/game.js +39 -9
- package/dist/internal/c4/game.js.map +1 -1
- package/dist/internal/c4/identity.d.ts +2 -7
- package/dist/internal/c4/identity.d.ts.map +1 -1
- package/dist/internal/c4/identity.js +2 -23
- package/dist/internal/c4/identity.js.map +1 -1
- package/dist/internal/c4/loyalty.d.ts +0 -27
- package/dist/internal/c4/loyalty.d.ts.map +1 -1
- package/dist/internal/c4/loyalty.js +0 -33
- package/dist/internal/c4/loyalty.js.map +1 -1
- package/dist/internal/c4/market.d.ts +1 -37
- package/dist/internal/c4/market.d.ts.map +1 -1
- package/dist/internal/c4/market.js +11 -49
- package/dist/internal/c4/market.js.map +1 -1
- package/dist/internal/c4/mining-instructions.d.ts +2 -0
- package/dist/internal/c4/mining-instructions.d.ts.map +1 -0
- package/dist/internal/c4/mining-instructions.js +3 -0
- package/dist/internal/c4/mining-instructions.js.map +1 -0
- package/dist/internal/c4/profile-creation.d.ts +17 -0
- package/dist/internal/c4/profile-creation.d.ts.map +1 -0
- package/dist/internal/c4/profile-creation.js +36 -0
- package/dist/internal/c4/profile-creation.js.map +1 -0
- package/dist/internal/c4/profile-faction.d.ts.map +1 -1
- package/dist/internal/c4/profile-faction.js +2 -0
- package/dist/internal/c4/profile-faction.js.map +1 -1
- package/dist/internal/c4/profile-permissions.d.ts +14 -0
- package/dist/internal/c4/profile-permissions.d.ts.map +1 -0
- package/dist/internal/c4/profile-permissions.js +81 -0
- package/dist/internal/c4/profile-permissions.js.map +1 -0
- package/dist/internal/c4/rewards.d.ts +0 -27
- package/dist/internal/c4/rewards.d.ts.map +1 -1
- package/dist/internal/c4/rewards.js +0 -33
- package/dist/internal/c4/rewards.js.map +1 -1
- package/dist/internal/c4/runtime-bindings.d.ts +3 -0
- package/dist/internal/c4/runtime-bindings.d.ts.map +1 -0
- package/dist/internal/c4/runtime-bindings.js +4 -0
- package/dist/internal/c4/runtime-bindings.js.map +1 -0
- package/dist/internal/c4/scanning.d.ts +1 -28
- package/dist/internal/c4/scanning.d.ts.map +1 -1
- package/dist/internal/c4/scanning.js +2 -33
- package/dist/internal/c4/scanning.js.map +1 -1
- package/dist/internal/c4/ship-import.d.ts +4 -0
- package/dist/internal/c4/ship-import.d.ts.map +1 -0
- package/dist/internal/c4/ship-import.js +13 -0
- package/dist/internal/c4/ship-import.js.map +1 -0
- package/dist/internal/c4/ship-stats.d.ts.map +1 -1
- package/dist/internal/c4/ship-stats.js +11 -7
- package/dist/internal/c4/ship-stats.js.map +1 -1
- package/dist/internal/c4/starbase.d.ts +0 -32
- package/dist/internal/c4/starbase.d.ts.map +1 -1
- package/dist/internal/c4/starbase.js +3 -41
- package/dist/internal/c4/starbase.js.map +1 -1
- package/dist/internal/c4/wallet-cargo-cache.d.ts +3 -0
- package/dist/internal/c4/wallet-cargo-cache.d.ts.map +1 -0
- package/dist/internal/c4/wallet-cargo-cache.js +24 -0
- package/dist/internal/c4/wallet-cargo-cache.js.map +1 -0
- package/dist/internal/c4/world.js +2 -1
- package/dist/internal/c4/world.js.map +1 -1
- package/dist/internal/fleet.d.ts.map +1 -1
- package/dist/internal/fleet.js +3 -1
- package/dist/internal/fleet.js.map +1 -1
- package/dist/internal/loyalty-atlas-bank-state.d.ts +16 -0
- package/dist/internal/loyalty-atlas-bank-state.d.ts.map +1 -0
- package/dist/internal/loyalty-atlas-bank-state.js +10 -0
- package/dist/internal/loyalty-atlas-bank-state.js.map +1 -0
- package/dist/internal/planning/account-state.d.ts +4 -0
- package/dist/internal/planning/account-state.d.ts.map +1 -0
- package/dist/internal/planning/account-state.js +11 -0
- package/dist/internal/planning/account-state.js.map +1 -0
- package/dist/internal/planning/action-runtime.d.ts +38 -0
- package/dist/internal/planning/action-runtime.d.ts.map +1 -0
- package/dist/internal/planning/action-runtime.js +63 -0
- package/dist/internal/planning/action-runtime.js.map +1 -0
- package/dist/internal/planning/arrival-guards.d.ts +20 -0
- package/dist/internal/planning/arrival-guards.d.ts.map +1 -0
- package/dist/internal/planning/arrival-guards.js +187 -0
- package/dist/internal/planning/arrival-guards.js.map +1 -0
- package/dist/internal/planning/authorization-adapter.d.ts +19 -6
- package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
- package/dist/internal/planning/authorization-adapter.js +99 -16
- package/dist/internal/planning/authorization-adapter.js.map +1 -1
- package/dist/internal/planning/democracy-history.d.ts +50 -0
- package/dist/internal/planning/democracy-history.d.ts.map +1 -0
- package/dist/internal/planning/democracy-history.js +198 -0
- package/dist/internal/planning/democracy-history.js.map +1 -0
- package/dist/internal/planning/faction-enrollment.d.ts +12 -0
- package/dist/internal/planning/faction-enrollment.d.ts.map +1 -0
- package/dist/internal/planning/faction-enrollment.js +67 -0
- package/dist/internal/planning/faction-enrollment.js.map +1 -0
- package/dist/internal/planning/faction-trade-guards.d.ts +30 -0
- package/dist/internal/planning/faction-trade-guards.d.ts.map +1 -0
- package/dist/internal/planning/faction-trade-guards.js +15 -0
- package/dist/internal/planning/faction-trade-guards.js.map +1 -0
- package/dist/internal/planning/faction-trade-state.d.ts +16 -0
- package/dist/internal/planning/faction-trade-state.d.ts.map +1 -0
- package/dist/internal/planning/faction-trade-state.js +43 -0
- package/dist/internal/planning/faction-trade-state.js.map +1 -0
- package/dist/internal/planning/fleet-arrival.d.ts +38 -0
- package/dist/internal/planning/fleet-arrival.d.ts.map +1 -0
- package/dist/internal/planning/fleet-arrival.js +100 -0
- package/dist/internal/planning/fleet-arrival.js.map +1 -0
- package/dist/internal/planning/fleet-creation.d.ts +30 -0
- package/dist/internal/planning/fleet-creation.d.ts.map +1 -0
- package/dist/internal/planning/fleet-creation.js +107 -0
- package/dist/internal/planning/fleet-creation.js.map +1 -0
- package/dist/internal/planning/fleet-ship-assembly.d.ts +36 -0
- package/dist/internal/planning/fleet-ship-assembly.d.ts.map +1 -0
- package/dist/internal/planning/fleet-ship-assembly.js +136 -0
- package/dist/internal/planning/fleet-ship-assembly.js.map +1 -0
- package/dist/internal/planning/governance-fees.d.ts +64 -0
- package/dist/internal/planning/governance-fees.d.ts.map +1 -0
- package/dist/internal/planning/governance-fees.js +239 -0
- package/dist/internal/planning/governance-fees.js.map +1 -0
- package/dist/internal/planning/mining-stop.d.ts +14 -0
- package/dist/internal/planning/mining-stop.d.ts.map +1 -0
- package/dist/internal/planning/mining-stop.js +41 -0
- package/dist/internal/planning/mining-stop.js.map +1 -0
- package/dist/internal/planning/runtime-guards.d.ts +43 -0
- package/dist/internal/planning/runtime-guards.d.ts.map +1 -0
- package/dist/internal/planning/runtime-guards.js +550 -0
- package/dist/internal/planning/runtime-guards.js.map +1 -0
- package/dist/internal/planning/ship-import-funding.d.ts +22 -0
- package/dist/internal/planning/ship-import-funding.d.ts.map +1 -0
- package/dist/internal/planning/ship-import-funding.js +52 -0
- package/dist/internal/planning/ship-import-funding.js.map +1 -0
- package/dist/internal/planning/ship-token.d.ts +10 -0
- package/dist/internal/planning/ship-token.d.ts.map +1 -0
- package/dist/internal/planning/ship-token.js +47 -0
- package/dist/internal/planning/ship-token.js.map +1 -0
- package/dist/internal/planning/token-mint.d.ts +4 -0
- package/dist/internal/planning/token-mint.d.ts.map +1 -0
- package/dist/internal/planning/token-mint.js +15 -0
- package/dist/internal/planning/token-mint.js.map +1 -0
- package/dist/internal/planning/trade-faction-market.d.ts +20 -0
- package/dist/internal/planning/trade-faction-market.d.ts.map +1 -0
- package/dist/internal/planning/trade-faction-market.js +56 -0
- package/dist/internal/planning/trade-faction-market.js.map +1 -0
- package/dist/internal/planning/xp-runtime.d.ts +20 -0
- package/dist/internal/planning/xp-runtime.d.ts.map +1 -0
- package/dist/internal/planning/xp-runtime.js +94 -0
- package/dist/internal/planning/xp-runtime.js.map +1 -0
- package/dist/loyalty/actions/index.d.ts.map +1 -1
- package/dist/loyalty/actions/index.js +4 -3
- package/dist/loyalty/actions/index.js.map +1 -1
- package/dist/loyalty/index.d.ts.map +1 -1
- package/dist/loyalty/index.js +2 -6
- package/dist/loyalty/index.js.map +1 -1
- package/dist/markets/actions/index.d.ts +1 -0
- package/dist/markets/actions/index.d.ts.map +1 -1
- package/dist/markets/actions/index.js +42 -16
- package/dist/markets/actions/index.js.map +1 -1
- package/dist/markets/actions/trade-faction-market.d.ts +43 -0
- package/dist/markets/actions/trade-faction-market.d.ts.map +1 -0
- package/dist/markets/actions/trade-faction-market.js +291 -0
- package/dist/markets/actions/trade-faction-market.js.map +1 -0
- package/dist/mining/actions/index.d.ts +84 -0
- package/dist/mining/actions/index.d.ts.map +1 -0
- package/dist/mining/actions/index.js +314 -0
- package/dist/mining/actions/index.js.map +1 -0
- package/dist/planning/assembly.d.ts.map +1 -1
- package/dist/planning/assembly.js +6 -0
- package/dist/planning/assembly.js.map +1 -1
- package/dist/planning/execution.d.ts.map +1 -1
- package/dist/planning/execution.js +290 -17
- package/dist/planning/execution.js.map +1 -1
- package/dist/planning/index.d.ts +151 -86
- package/dist/planning/index.d.ts.map +1 -1
- package/dist/planning/index.js +470 -57
- package/dist/planning/index.js.map +1 -1
- package/dist/planning/simulation.d.ts +18 -1
- package/dist/planning/simulation.d.ts.map +1 -1
- package/dist/planning/simulation.js +56 -10
- package/dist/planning/simulation.js.map +1 -1
- package/dist/registry/cargo.d.ts +6 -6
- package/dist/registry/cargo.d.ts.map +1 -1
- package/dist/registry/cargo.js +25 -4
- package/dist/registry/cargo.js.map +1 -1
- package/dist/registry/onboarding.d.ts +2 -0
- package/dist/registry/onboarding.d.ts.map +1 -1
- package/dist/registry/onboarding.js +11 -6
- package/dist/registry/onboarding.js.map +1 -1
- package/dist/registry/ship-stats-snapshot.js +5 -5
- package/dist/registry/ship-stats-snapshot.js.map +1 -1
- package/dist/registry/ships.d.ts +28 -0
- package/dist/registry/ships.d.ts.map +1 -0
- package/dist/registry/ships.js +51 -0
- package/dist/registry/ships.js.map +1 -0
- package/dist/registry/xp-runtime.d.ts +4 -0
- package/dist/registry/xp-runtime.d.ts.map +1 -0
- package/dist/registry/xp-runtime.js +14 -0
- package/dist/registry/xp-runtime.js.map +1 -0
- package/dist/scanning/index.d.ts +1 -1
- package/dist/scanning/index.d.ts.map +1 -1
- package/dist/scanning/index.js +2 -2
- package/dist/scanning/index.js.map +1 -1
- package/package.json +10 -2
package/dist/planning/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { normalizeArrivalGuard, arrivalGuardToJSON, validateArrivalInstructions, } from '../internal/planning/arrival-guards.js';
|
|
2
|
+
import { isRuntimeGuard, normalizeRuntimeGuard, runtimeGuardToJSON, validateRuntimeInstructions, } from '../internal/planning/runtime-guards.js';
|
|
3
|
+
import { isTradeBuyGuard, isTradeSellGuard, isTradeMeterGuard, isFactionTradeGuard, } from '../internal/planning/faction-trade-guards.js';
|
|
1
4
|
import { AccountRole, getBase64Decoder, getBase64Encoder, isAddress, isWritableRole, } from '@solana/kit';
|
|
2
|
-
import { InvalidActionInputError } from '../client/errors.js';
|
|
5
|
+
import { InvalidActionInputError, SageSdkError } from '../client/errors.js';
|
|
3
6
|
import { deepFreeze } from '../internal/immutable-tree.js';
|
|
7
|
+
import { validateMiningStopInstructions } from '../internal/planning/mining-stop.js';
|
|
4
8
|
import { validatePlanComposition } from './composition.js';
|
|
5
9
|
import { isPlanInstance, registerPlanInstance } from './plan-instances.js';
|
|
6
10
|
const PLAN_BRAND = Symbol('AephiaSagePlan');
|
|
@@ -159,9 +163,327 @@ function normalizeSemanticFact(value, field) {
|
|
|
159
163
|
}
|
|
160
164
|
return invalid(`${field}.kind`, semantic.kind, 'one of exclusive, requires, invalidates, or transition');
|
|
161
165
|
}
|
|
162
|
-
function normalizePrecondition(value, field
|
|
166
|
+
function normalizePrecondition(value, field) {
|
|
163
167
|
const precondition = readRecord(value, field);
|
|
164
|
-
if (precondition.kind === '
|
|
168
|
+
if (precondition.kind === 'fleet-arrival')
|
|
169
|
+
return normalizeArrivalGuard(precondition, field);
|
|
170
|
+
if (isRuntimeGuard(precondition))
|
|
171
|
+
return normalizeRuntimeGuard(precondition, field);
|
|
172
|
+
if (precondition.kind === 'ship-import-funding') {
|
|
173
|
+
assertKeys(precondition, field, [
|
|
174
|
+
'kind',
|
|
175
|
+
'address',
|
|
176
|
+
'game',
|
|
177
|
+
'profile',
|
|
178
|
+
'system',
|
|
179
|
+
'shipId',
|
|
180
|
+
'maximumProfileDebit',
|
|
181
|
+
'describes',
|
|
182
|
+
]);
|
|
183
|
+
const shipId = precondition.shipId;
|
|
184
|
+
if (typeof shipId !== 'number' ||
|
|
185
|
+
!Number.isInteger(shipId) ||
|
|
186
|
+
shipId < 0 ||
|
|
187
|
+
shipId > 65535)
|
|
188
|
+
invalid(`${field}.shipId`, shipId, 'an unsigned u16 ship configuration ID');
|
|
189
|
+
const maximumProfileDebit = precondition.maximumProfileDebit;
|
|
190
|
+
if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
|
|
191
|
+
invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
kind: 'ship-import-funding',
|
|
194
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
195
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
196
|
+
profile: readAddress(precondition.profile, `${field}.profile`),
|
|
197
|
+
system: readAddress(precondition.system, `${field}.system`),
|
|
198
|
+
shipId,
|
|
199
|
+
maximumProfileDebit,
|
|
200
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (precondition.kind === 'fleet-mining') {
|
|
204
|
+
assertKeys(precondition, field, [
|
|
205
|
+
'kind',
|
|
206
|
+
'address',
|
|
207
|
+
'game',
|
|
208
|
+
'profile',
|
|
209
|
+
'asteroid',
|
|
210
|
+
'describes',
|
|
211
|
+
]);
|
|
212
|
+
return Object.freeze({
|
|
213
|
+
kind: 'fleet-mining',
|
|
214
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
215
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
216
|
+
profile: readAddress(precondition.profile, `${field}.profile`),
|
|
217
|
+
asteroid: readAddress(precondition.asteroid, `${field}.asteroid`),
|
|
218
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (isFactionTradeGuard(precondition)) {
|
|
222
|
+
const kind = precondition.kind;
|
|
223
|
+
assertKeys(precondition, field, [
|
|
224
|
+
'kind',
|
|
225
|
+
'address',
|
|
226
|
+
'game',
|
|
227
|
+
'factionId',
|
|
228
|
+
'describes',
|
|
229
|
+
'schemaVersion',
|
|
230
|
+
...(isTradeBuyGuard(precondition)
|
|
231
|
+
? ['cargoId', 'floorRaw']
|
|
232
|
+
: isTradeSellGuard(precondition)
|
|
233
|
+
? ['atlasOutCapPerEpochRaw', 'epochLengthSeconds']
|
|
234
|
+
: []),
|
|
235
|
+
]);
|
|
236
|
+
const unsigned = (key, max = 65535) => {
|
|
237
|
+
const n = precondition[key];
|
|
238
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < 0 || n > max)
|
|
239
|
+
invalid(`${field}.${key}`, n, `an unsigned ${max === 255 ? 'u8' : 'u16'} integer`);
|
|
240
|
+
return n;
|
|
241
|
+
};
|
|
242
|
+
const integer = (key, signed = false) => {
|
|
243
|
+
const n = precondition[key];
|
|
244
|
+
const min = signed ? -(1n << 63n) : 0n;
|
|
245
|
+
const max = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
|
|
246
|
+
if (typeof n !== 'bigint' || n < min || n > max)
|
|
247
|
+
invalid(`${field}.${key}`, n, signed ? 'an i64 bigint' : 'a u64 bigint');
|
|
248
|
+
return n;
|
|
249
|
+
};
|
|
250
|
+
const common = {
|
|
251
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
252
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
253
|
+
factionId: unsigned('factionId'),
|
|
254
|
+
schemaVersion: unsigned('schemaVersion', 255),
|
|
255
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
256
|
+
};
|
|
257
|
+
if (isTradeBuyGuard(precondition))
|
|
258
|
+
return Object.freeze({
|
|
259
|
+
kind,
|
|
260
|
+
...common,
|
|
261
|
+
cargoId: unsigned('cargoId'),
|
|
262
|
+
floorRaw: integer('floorRaw'),
|
|
263
|
+
});
|
|
264
|
+
if (isTradeSellGuard(precondition))
|
|
265
|
+
return Object.freeze({
|
|
266
|
+
kind,
|
|
267
|
+
...common,
|
|
268
|
+
atlasOutCapPerEpochRaw: integer('atlasOutCapPerEpochRaw'),
|
|
269
|
+
epochLengthSeconds: integer('epochLengthSeconds', true),
|
|
270
|
+
});
|
|
271
|
+
return Object.freeze({ kind, ...common });
|
|
272
|
+
}
|
|
273
|
+
if (precondition.kind === 'fleet-add-ship') {
|
|
274
|
+
assertKeys(precondition, field, [
|
|
275
|
+
'kind',
|
|
276
|
+
'address',
|
|
277
|
+
'game',
|
|
278
|
+
'profile',
|
|
279
|
+
'authority',
|
|
280
|
+
'system',
|
|
281
|
+
'shipId',
|
|
282
|
+
'amount',
|
|
283
|
+
'keyIndex',
|
|
284
|
+
'configHash',
|
|
285
|
+
'maximumProfileDebit',
|
|
286
|
+
'describes',
|
|
287
|
+
]);
|
|
288
|
+
const keyIndex = precondition.keyIndex;
|
|
289
|
+
if (typeof keyIndex !== 'number' ||
|
|
290
|
+
!Number.isInteger(keyIndex) ||
|
|
291
|
+
keyIndex < 0 ||
|
|
292
|
+
keyIndex > 65535)
|
|
293
|
+
invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
|
|
294
|
+
const shipId = precondition.shipId;
|
|
295
|
+
if (typeof shipId !== 'number' ||
|
|
296
|
+
!Number.isInteger(shipId) ||
|
|
297
|
+
shipId < 0 ||
|
|
298
|
+
shipId > 65535)
|
|
299
|
+
invalid(`${field}.shipId`, shipId, 'a u16 ship configuration ID');
|
|
300
|
+
const amount = precondition.amount;
|
|
301
|
+
if (typeof amount !== 'bigint' || amount < 1n || amount > 255n)
|
|
302
|
+
invalid(`${field}.amount`, amount, 'a whole ship quantity from 1n through 255n');
|
|
303
|
+
const maximumProfileDebit = precondition.maximumProfileDebit;
|
|
304
|
+
if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
|
|
305
|
+
invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
|
|
306
|
+
return Object.freeze({
|
|
307
|
+
kind: 'fleet-add-ship',
|
|
308
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
309
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
310
|
+
profile: readAddress(precondition.profile, `${field}.profile`),
|
|
311
|
+
authority: readAddress(precondition.authority, `${field}.authority`),
|
|
312
|
+
system: readAddress(precondition.system, `${field}.system`),
|
|
313
|
+
keyIndex,
|
|
314
|
+
shipId,
|
|
315
|
+
amount,
|
|
316
|
+
maximumProfileDebit,
|
|
317
|
+
configHash: readDataHash(precondition.configHash, `${field}.configHash`),
|
|
318
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if (precondition.kind === 'fleet-create') {
|
|
322
|
+
assertKeys(precondition, field, [
|
|
323
|
+
'kind',
|
|
324
|
+
'address',
|
|
325
|
+
'game',
|
|
326
|
+
'profile',
|
|
327
|
+
'authority',
|
|
328
|
+
'system',
|
|
329
|
+
'keyIndex',
|
|
330
|
+
'label',
|
|
331
|
+
'maximumProfileDebit',
|
|
332
|
+
'describes',
|
|
333
|
+
]);
|
|
334
|
+
const keyIndex = precondition.keyIndex;
|
|
335
|
+
if (typeof keyIndex !== 'number' ||
|
|
336
|
+
!Number.isSafeInteger(keyIndex) ||
|
|
337
|
+
keyIndex < 0 ||
|
|
338
|
+
keyIndex > 65_535)
|
|
339
|
+
invalid(`${field}.keyIndex`, keyIndex, 'an integer from 0 through 65535');
|
|
340
|
+
const label = readString(precondition.label, `${field}.label`);
|
|
341
|
+
const bytes = new TextEncoder().encode(label);
|
|
342
|
+
if (label.trim().length === 0 ||
|
|
343
|
+
label.includes('\0') ||
|
|
344
|
+
bytes.length > 64 ||
|
|
345
|
+
new TextDecoder('utf-8', { ignoreBOM: true }).decode(bytes) !== label)
|
|
346
|
+
invalid(`${field}.label`, label, 'a nonblank, NUL-free Unicode label of at most 64 UTF-8 bytes');
|
|
347
|
+
const maximumProfileDebit = precondition.maximumProfileDebit;
|
|
348
|
+
if (typeof maximumProfileDebit !== 'bigint' || maximumProfileDebit < 0n)
|
|
349
|
+
invalid(`${field}.maximumProfileDebit`, maximumProfileDebit, 'a nonnegative bigint');
|
|
350
|
+
return Object.freeze({
|
|
351
|
+
kind: 'fleet-create',
|
|
352
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
353
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
354
|
+
profile: readAddress(precondition.profile, `${field}.profile`),
|
|
355
|
+
authority: readAddress(precondition.authority, `${field}.authority`),
|
|
356
|
+
system: readAddress(precondition.system, `${field}.system`),
|
|
357
|
+
keyIndex,
|
|
358
|
+
label,
|
|
359
|
+
maximumProfileDebit,
|
|
360
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (precondition.kind === 'system-account-or-absent') {
|
|
364
|
+
assertKeys(precondition, field, ['kind', 'address', 'describes']);
|
|
365
|
+
return Object.freeze({
|
|
366
|
+
kind: 'system-account-or-absent',
|
|
367
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
368
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (precondition.kind === 'token-mint') {
|
|
372
|
+
assertKeys(precondition, field, [
|
|
373
|
+
'kind',
|
|
374
|
+
'address',
|
|
375
|
+
'decimals',
|
|
376
|
+
'describes',
|
|
377
|
+
]);
|
|
378
|
+
const decimals = precondition.decimals;
|
|
379
|
+
if (typeof decimals !== 'number' ||
|
|
380
|
+
!Number.isInteger(decimals) ||
|
|
381
|
+
decimals < 0 ||
|
|
382
|
+
decimals > 255)
|
|
383
|
+
invalid(`${field}.decimals`, decimals, 'an unsigned u8 mint decimals value');
|
|
384
|
+
return Object.freeze({
|
|
385
|
+
kind: 'token-mint',
|
|
386
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
387
|
+
decimals,
|
|
388
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (precondition.kind === 'game-ship-config') {
|
|
392
|
+
assertKeys(precondition, field, [
|
|
393
|
+
'kind',
|
|
394
|
+
'address',
|
|
395
|
+
'shipId',
|
|
396
|
+
'configHash',
|
|
397
|
+
'describes',
|
|
398
|
+
]);
|
|
399
|
+
const id = precondition.shipId;
|
|
400
|
+
if (typeof id !== 'number' || !Number.isInteger(id) || id < 0 || id > 65535)
|
|
401
|
+
invalid(`${field}.shipId`, id, 'a u16 ship configuration ID');
|
|
402
|
+
return Object.freeze({
|
|
403
|
+
kind: 'game-ship-config',
|
|
404
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
405
|
+
shipId: id,
|
|
406
|
+
configHash: readDataHash(precondition.configHash, `${field}.configHash`),
|
|
407
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (precondition.kind === 'game-account') {
|
|
411
|
+
assertKeys(precondition, field, ['kind', 'address', 'describes']);
|
|
412
|
+
return Object.freeze({
|
|
413
|
+
kind: 'game-account',
|
|
414
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
415
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
if (['game-cargo-bytes-config', 'token-account', 'cargo-cache'].includes(String(precondition.kind))) {
|
|
419
|
+
const base = {
|
|
420
|
+
address: readAddress(precondition.address, `${field}.address`),
|
|
421
|
+
describes: readString(precondition.describes, `${field}.describes`),
|
|
422
|
+
};
|
|
423
|
+
if (precondition.kind === 'token-account') {
|
|
424
|
+
assertKeys(precondition, field, [
|
|
425
|
+
'kind',
|
|
426
|
+
'address',
|
|
427
|
+
'mint',
|
|
428
|
+
'owner',
|
|
429
|
+
'minimumBalance',
|
|
430
|
+
'describes',
|
|
431
|
+
]);
|
|
432
|
+
const amount = precondition.minimumBalance;
|
|
433
|
+
if (typeof amount !== 'bigint' ||
|
|
434
|
+
amount < 0n ||
|
|
435
|
+
amount > (1n << 64n) - 1n)
|
|
436
|
+
invalid(`${field}.minimumBalance`, amount, 'an unsigned u64 bigint');
|
|
437
|
+
return Object.freeze({
|
|
438
|
+
...base,
|
|
439
|
+
kind: 'token-account',
|
|
440
|
+
mint: readAddress(precondition.mint, `${field}.mint`),
|
|
441
|
+
owner: readAddress(precondition.owner, `${field}.owner`),
|
|
442
|
+
minimumBalance: amount,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
if (precondition.kind === 'game-cargo-bytes-config') {
|
|
446
|
+
assertKeys(precondition, field, [
|
|
447
|
+
'kind',
|
|
448
|
+
'address',
|
|
449
|
+
'cargoId',
|
|
450
|
+
'configHash',
|
|
451
|
+
'describes',
|
|
452
|
+
]);
|
|
453
|
+
const id = precondition.cargoId;
|
|
454
|
+
if (typeof id !== 'number' ||
|
|
455
|
+
!Number.isInteger(id) ||
|
|
456
|
+
id < 0 ||
|
|
457
|
+
id > 65535)
|
|
458
|
+
invalid(`${field}.cargoId`, id, 'a u16 cargo ID');
|
|
459
|
+
return Object.freeze({
|
|
460
|
+
...base,
|
|
461
|
+
kind: precondition.kind,
|
|
462
|
+
cargoId: id,
|
|
463
|
+
configHash: readDataHash(precondition.configHash, `${field}.configHash`),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
assertKeys(precondition, field, [
|
|
467
|
+
'kind',
|
|
468
|
+
'address',
|
|
469
|
+
'game',
|
|
470
|
+
'bump',
|
|
471
|
+
'describes',
|
|
472
|
+
]);
|
|
473
|
+
const bump = precondition.bump;
|
|
474
|
+
if (typeof bump !== 'number' ||
|
|
475
|
+
!Number.isInteger(bump) ||
|
|
476
|
+
bump < 0 ||
|
|
477
|
+
bump > 255)
|
|
478
|
+
invalid(`${field}.bump`, bump, 'a u8 PDA bump');
|
|
479
|
+
return Object.freeze({
|
|
480
|
+
...base,
|
|
481
|
+
kind: 'cargo-cache',
|
|
482
|
+
game: readAddress(precondition.game, `${field}.game`),
|
|
483
|
+
bump,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
if (precondition.kind === 'token-account-or-absent') {
|
|
165
487
|
assertKeys(precondition, field, [
|
|
166
488
|
'kind',
|
|
167
489
|
'address',
|
|
@@ -177,7 +499,7 @@ function normalizePrecondition(value, field, version = 3) {
|
|
|
177
499
|
describes: readString(precondition.describes, `${field}.describes`),
|
|
178
500
|
});
|
|
179
501
|
}
|
|
180
|
-
if (precondition.kind === 'account-absent'
|
|
502
|
+
if (precondition.kind === 'account-absent') {
|
|
181
503
|
assertKeys(precondition, field, ['kind', 'address', 'describes']);
|
|
182
504
|
return Object.freeze({
|
|
183
505
|
kind: 'account-absent',
|
|
@@ -186,11 +508,7 @@ function normalizePrecondition(value, field, version = 3) {
|
|
|
186
508
|
});
|
|
187
509
|
}
|
|
188
510
|
if (precondition.kind !== 'account-state') {
|
|
189
|
-
invalid(`${field}.kind`, precondition.kind,
|
|
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');
|
|
511
|
+
invalid(`${field}.kind`, precondition.kind, 'a supported current Plan guard; recreate the Plan using the current capability planner');
|
|
194
512
|
}
|
|
195
513
|
assertKeys(precondition, field, ['kind', 'address', 'dataHash', 'describes']);
|
|
196
514
|
return Object.freeze({
|
|
@@ -226,50 +544,48 @@ function instructionToJSON(instruction) {
|
|
|
226
544
|
return deepFreeze(value);
|
|
227
545
|
}
|
|
228
546
|
function planToJSON(plan) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const common = {
|
|
547
|
+
return deepFreeze({
|
|
548
|
+
v: 18,
|
|
232
549
|
kind: plan.kind,
|
|
233
550
|
summary: plan.summary,
|
|
234
551
|
affected: [...plan.affected],
|
|
235
552
|
requiredSigners: [...plan.requiredSigners],
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
:
|
|
243
|
-
signers: [...step.signers],
|
|
244
|
-
}));
|
|
245
|
-
if (plan.preconditions.some(({ kind }) => kind === 'token-account-or-absent')) {
|
|
246
|
-
return deepFreeze({
|
|
247
|
-
v: 3,
|
|
248
|
-
...common,
|
|
249
|
-
steps,
|
|
250
|
-
preconditions: plan.preconditions.map((guard) => ({ ...guard })),
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
if (hasSemantics || hasAbsentPrecondition) {
|
|
254
|
-
return deepFreeze({
|
|
255
|
-
v: 2,
|
|
256
|
-
...common,
|
|
257
|
-
steps,
|
|
258
|
-
preconditions: plan.preconditions.map((guard) => ({
|
|
259
|
-
...guard,
|
|
260
|
-
})),
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
return deepFreeze({
|
|
264
|
-
v: 1,
|
|
265
|
-
...common,
|
|
266
|
-
steps,
|
|
267
|
-
preconditions: plan.preconditions.map((precondition) => ({
|
|
268
|
-
kind: 'account-state',
|
|
269
|
-
address: precondition.address,
|
|
270
|
-
dataHash: precondition.dataHash,
|
|
271
|
-
describes: precondition.describes,
|
|
553
|
+
steps: plan.steps.map((step) => ({
|
|
554
|
+
instruction: instructionToJSON(step.instruction),
|
|
555
|
+
describes: step.describes,
|
|
556
|
+
...((step.semantics?.length ?? 0) > 0
|
|
557
|
+
? { semantics: step.semantics.map((semantic) => ({ ...semantic })) }
|
|
558
|
+
: {}),
|
|
559
|
+
signers: [...step.signers],
|
|
272
560
|
})),
|
|
561
|
+
preconditions: plan.preconditions.map((guard) => {
|
|
562
|
+
if (guard.kind === 'fleet-arrival')
|
|
563
|
+
return arrivalGuardToJSON(guard);
|
|
564
|
+
if (isRuntimeGuard(guard))
|
|
565
|
+
return runtimeGuardToJSON(guard);
|
|
566
|
+
if (isTradeBuyGuard(guard))
|
|
567
|
+
return { ...guard, floorRaw: String(guard.floorRaw) };
|
|
568
|
+
if (isTradeSellGuard(guard))
|
|
569
|
+
return {
|
|
570
|
+
...guard,
|
|
571
|
+
atlasOutCapPerEpochRaw: String(guard.atlasOutCapPerEpochRaw),
|
|
572
|
+
epochLengthSeconds: String(guard.epochLengthSeconds),
|
|
573
|
+
};
|
|
574
|
+
if (guard.kind === 'fleet-add-ship')
|
|
575
|
+
return {
|
|
576
|
+
...guard,
|
|
577
|
+
amount: String(guard.amount),
|
|
578
|
+
maximumProfileDebit: String(guard.maximumProfileDebit),
|
|
579
|
+
};
|
|
580
|
+
if (guard.kind === 'fleet-create' || guard.kind === 'ship-import-funding')
|
|
581
|
+
return {
|
|
582
|
+
...guard,
|
|
583
|
+
maximumProfileDebit: String(guard.maximumProfileDebit),
|
|
584
|
+
};
|
|
585
|
+
if (guard.kind === 'token-account')
|
|
586
|
+
return { ...guard, minimumBalance: String(guard.minimumBalance) };
|
|
587
|
+
return { ...guard };
|
|
588
|
+
}),
|
|
273
589
|
});
|
|
274
590
|
}
|
|
275
591
|
/** Creates an inert branded Plan while deriving every aggregate field.
|
|
@@ -291,6 +607,7 @@ export function createPlan(input) {
|
|
|
291
607
|
assertKeys(value, 'plan', ['kind', 'summary', 'steps', 'preconditions']);
|
|
292
608
|
const steps = Object.freeze(readArray(value.steps, 'plan.steps').map((step, index) => normalizeStep(step, `plan.steps[${String(index)}]`)));
|
|
293
609
|
const preconditions = Object.freeze(readArray(value.preconditions, 'plan.preconditions').map((precondition, index) => normalizePrecondition(precondition, `plan.preconditions[${String(index)}]`)));
|
|
610
|
+
validateShipImportFundingComposition(preconditions);
|
|
294
611
|
const descriptions = Object.freeze(steps.map((step) => step.describes));
|
|
295
612
|
const plan = {
|
|
296
613
|
kind: readString(value.kind, 'plan.kind'),
|
|
@@ -337,13 +654,13 @@ function sameAddresses(actual, encoded) {
|
|
|
337
654
|
*
|
|
338
655
|
* @example
|
|
339
656
|
* ```ts
|
|
340
|
-
* declare const wire:
|
|
657
|
+
* declare const wire: PlanJson;
|
|
341
658
|
* const plan = planFromJSON(wire);
|
|
342
659
|
* console.log(plan.describe());
|
|
343
660
|
* ```
|
|
344
661
|
*/
|
|
345
662
|
export function planFromJSON(json) {
|
|
346
|
-
const value = readRecord(json, 'planJson');
|
|
663
|
+
const value = { ...readRecord(json, 'planJson') };
|
|
347
664
|
assertKeys(value, 'planJson', [
|
|
348
665
|
'v',
|
|
349
666
|
'kind',
|
|
@@ -353,18 +670,66 @@ export function planFromJSON(json) {
|
|
|
353
670
|
'affected',
|
|
354
671
|
'requiredSigners',
|
|
355
672
|
]);
|
|
356
|
-
if (value.v !==
|
|
357
|
-
|
|
673
|
+
if (value.v !== 18) {
|
|
674
|
+
throw new InvalidActionInputError('planJson.v', value.v, 'the current Plan wire version 18', 'Recreate the Plan using the current capability planner; do not change its saved version or migrate its guards.');
|
|
358
675
|
}
|
|
359
|
-
|
|
676
|
+
value.preconditions = readArray(value.preconditions, 'planJson.preconditions').map((entry) => {
|
|
677
|
+
const guard = readRecord(entry, 'precondition');
|
|
678
|
+
if (guard.kind === 'fleet-arrival')
|
|
679
|
+
return normalizeArrivalGuard(guard, 'precondition', true);
|
|
680
|
+
if (isRuntimeGuard(guard))
|
|
681
|
+
return normalizeRuntimeGuard(guard, 'precondition', true);
|
|
682
|
+
if (isTradeBuyGuard(guard) || isTradeSellGuard(guard)) {
|
|
683
|
+
const keys = isTradeBuyGuard(guard)
|
|
684
|
+
? ['floorRaw']
|
|
685
|
+
: ['atlasOutCapPerEpochRaw', 'epochLengthSeconds'];
|
|
686
|
+
const decoded = { ...guard };
|
|
687
|
+
for (const key of keys) {
|
|
688
|
+
const raw = guard[key];
|
|
689
|
+
const pattern = key === 'epochLengthSeconds'
|
|
690
|
+
? /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
|
|
691
|
+
: /^(0|[1-9][0-9]*)$/;
|
|
692
|
+
if (typeof raw !== 'string' || !pattern.test(raw))
|
|
693
|
+
invalid(key, raw, 'a canonical decimal string');
|
|
694
|
+
decoded[key] = BigInt(raw);
|
|
695
|
+
}
|
|
696
|
+
return decoded;
|
|
697
|
+
}
|
|
698
|
+
if (guard.kind === 'fleet-add-ship') {
|
|
699
|
+
for (const field of ['amount', 'maximumProfileDebit'])
|
|
700
|
+
if (typeof guard[field] !== 'string' ||
|
|
701
|
+
!/^(0|[1-9][0-9]*)$/.test(guard[field]))
|
|
702
|
+
invalid(field, guard[field], 'a canonical unsigned decimal string');
|
|
703
|
+
return {
|
|
704
|
+
...guard,
|
|
705
|
+
amount: BigInt(guard.amount),
|
|
706
|
+
maximumProfileDebit: BigInt(guard.maximumProfileDebit),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
if (guard.kind === 'fleet-create' || guard.kind === 'ship-import-funding') {
|
|
710
|
+
if (typeof guard.maximumProfileDebit !== 'string' ||
|
|
711
|
+
!/^(0|[1-9][0-9]*)$/.test(guard.maximumProfileDebit))
|
|
712
|
+
invalid('maximumProfileDebit', guard.maximumProfileDebit, 'a canonical unsigned decimal string');
|
|
713
|
+
return {
|
|
714
|
+
...guard,
|
|
715
|
+
maximumProfileDebit: BigInt(guard.maximumProfileDebit),
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
if (guard.kind !== 'token-account')
|
|
719
|
+
return guard;
|
|
720
|
+
if (typeof guard.minimumBalance !== 'string' ||
|
|
721
|
+
!/^(0|[1-9][0-9]*)$/.test(guard.minimumBalance))
|
|
722
|
+
invalid('minimumBalance', guard.minimumBalance, 'a canonical unsigned decimal string');
|
|
723
|
+
return { ...guard, minimumBalance: BigInt(guard.minimumBalance) };
|
|
724
|
+
});
|
|
360
725
|
const steps = readArray(value.steps, 'planJson.steps').map((candidate, index) => {
|
|
361
726
|
const field = `planJson.steps[${String(index)}]`;
|
|
362
727
|
const step = readRecord(candidate, field);
|
|
363
|
-
assertKeys(step, field, ['instruction', 'describes', 'signers'],
|
|
728
|
+
assertKeys(step, field, ['instruction', 'describes', 'signers'], ['semantics']);
|
|
364
729
|
return {
|
|
365
730
|
instruction: readWireInstruction(step.instruction, `${field}.instruction`),
|
|
366
731
|
describes: readString(step.describes, `${field}.describes`),
|
|
367
|
-
...(
|
|
732
|
+
...(step.semantics !== undefined
|
|
368
733
|
? {
|
|
369
734
|
semantics: readArray(step.semantics, `${field}.semantics`).map((semantic, semanticIndex) => normalizeSemanticFact(semantic, `${field}.semantics[${String(semanticIndex)}]`)),
|
|
370
735
|
}
|
|
@@ -372,7 +737,7 @@ export function planFromJSON(json) {
|
|
|
372
737
|
signers: readArray(step.signers, `${field}.signers`).map((signer, signerIndex) => readAddress(signer, `${field}.signers[${String(signerIndex)}]`)),
|
|
373
738
|
};
|
|
374
739
|
});
|
|
375
|
-
const preconditions = readArray(value.preconditions, 'planJson.preconditions').map((candidate, index) => normalizePrecondition(candidate, `planJson.preconditions[${String(index)}]
|
|
740
|
+
const preconditions = readArray(value.preconditions, 'planJson.preconditions').map((candidate, index) => normalizePrecondition(candidate, `planJson.preconditions[${String(index)}]`));
|
|
376
741
|
const affected = readArray(value.affected, 'planJson.affected').map((candidate, index) => readAddress(candidate, `planJson.affected[${String(index)}]`));
|
|
377
742
|
const requiredSigners = readArray(value.requiredSigners, 'planJson.requiredSigners').map((candidate, index) => readAddress(candidate, `planJson.requiredSigners[${String(index)}]`));
|
|
378
743
|
const plan = createPlan({
|
|
@@ -397,6 +762,49 @@ function assertPlan(value, index) {
|
|
|
397
762
|
function combinedSummary(steps) {
|
|
398
763
|
return steps.map((step) => step.describes).join(' ');
|
|
399
764
|
}
|
|
765
|
+
function validateShipImportFundingComposition(guards) {
|
|
766
|
+
const targets = new Map();
|
|
767
|
+
for (const guard of guards) {
|
|
768
|
+
if (guard.kind !== 'ship-import-funding')
|
|
769
|
+
continue;
|
|
770
|
+
const identity = `${guard.game}:${guard.profile}:${guard.system}:${String(guard.shipId)}`;
|
|
771
|
+
const previous = targets.get(guard.address);
|
|
772
|
+
if (previous !== undefined && previous !== identity)
|
|
773
|
+
throw new SageSdkError('INCOMPATIBLE_PLAN_COMPOSITION', 'Ship imports retain conflicting identities or different configurations for one StarbasePlayer. Use separate confirmed imports, then refresh inventory and replan; prefunding cannot be shared across independently estimated storage growth.');
|
|
774
|
+
targets.set(guard.address, identity);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function validateFactionGuardComposition(guards) {
|
|
778
|
+
const retained = new Map();
|
|
779
|
+
for (const guard of guards) {
|
|
780
|
+
if (!isFactionTradeGuard(guard))
|
|
781
|
+
continue;
|
|
782
|
+
const constraints = [
|
|
783
|
+
[
|
|
784
|
+
`${isTradeMeterGuard(guard) ? 'meter' : 'treasury'}:${guard.address}:identity`,
|
|
785
|
+
`${guard.game}:${String(guard.factionId)}`,
|
|
786
|
+
],
|
|
787
|
+
];
|
|
788
|
+
if (!isTradeMeterGuard(guard)) {
|
|
789
|
+
constraints.push(isTradeBuyGuard(guard)
|
|
790
|
+
? [
|
|
791
|
+
`${guard.address}:buy:${String(guard.cargoId)}`,
|
|
792
|
+
String(guard.floorRaw),
|
|
793
|
+
]
|
|
794
|
+
: [
|
|
795
|
+
`${guard.address}:sell`,
|
|
796
|
+
`${String(guard.atlasOutCapPerEpochRaw)}:${String(guard.epochLengthSeconds)}`,
|
|
797
|
+
]);
|
|
798
|
+
}
|
|
799
|
+
constraints.push([`${guard.address}:schema`, String(guard.schemaVersion)]);
|
|
800
|
+
for (const [key, value] of constraints) {
|
|
801
|
+
const previous = retained.get(key);
|
|
802
|
+
if (previous !== undefined && previous !== value)
|
|
803
|
+
throw new SageSdkError('INCOMPATIBLE_PLAN_COMPOSITION', 'Faction Market Plans retain incompatible Treasury policy or shared account identity. Refresh the affected Markets and prepare compatible Plans, or use separate confirmed transactions.');
|
|
804
|
+
retained.set(key, value);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
400
808
|
/** Combines one or more Plans with deterministic associative flattening.
|
|
401
809
|
*
|
|
402
810
|
* Semantic validation is eager. Conflict indices are relative to the flattened
|
|
@@ -417,11 +825,16 @@ export function combinePlans(...plans) {
|
|
|
417
825
|
plans.forEach(assertPlan);
|
|
418
826
|
const steps = plans.flatMap((plan) => plan.steps);
|
|
419
827
|
validatePlanComposition(steps);
|
|
828
|
+
const preconditions = plans.flatMap((plan) => plan.preconditions);
|
|
829
|
+
validateFactionGuardComposition(preconditions);
|
|
830
|
+
validateMiningStopInstructions(steps, preconditions);
|
|
831
|
+
validateArrivalInstructions(steps, preconditions);
|
|
832
|
+
validateRuntimeInstructions(steps, preconditions);
|
|
420
833
|
return createPlan({
|
|
421
834
|
kind: 'combined',
|
|
422
835
|
summary: combinedSummary(steps),
|
|
423
836
|
steps,
|
|
424
|
-
preconditions
|
|
837
|
+
preconditions,
|
|
425
838
|
});
|
|
426
839
|
}
|
|
427
840
|
export { assemblePlan } from './assembly.js';
|