@aephia/atlas-kit 0.7.1-next.1 → 0.8.0-next.10
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 +1 -0
- package/dist/claim-stakes/actions/index.d.ts +61 -14
- package/dist/claim-stakes/actions/index.d.ts.map +1 -1
- package/dist/claim-stakes/actions/index.js +316 -61
- package/dist/claim-stakes/actions/index.js.map +1 -1
- package/dist/client/context.d.ts.map +1 -1
- package/dist/client/context.js +20 -1
- package/dist/client/context.js.map +1 -1
- package/dist/client/contracts.d.ts +10 -1
- package/dist/client/contracts.d.ts.map +1 -1
- package/dist/client/deployments.d.ts +16 -0
- package/dist/client/deployments.d.ts.map +1 -1
- package/dist/client/deployments.js +16 -0
- package/dist/client/deployments.js.map +1 -1
- package/dist/client/errors.d.ts +1 -1
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts +18 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +18 -0
- package/dist/client/index.js.map +1 -1
- package/dist/combat/actions/index.d.ts.map +1 -1
- package/dist/combat/actions/index.js +10 -0
- package/dist/combat/actions/index.js.map +1 -1
- package/dist/combat/index.d.ts +4 -2
- package/dist/combat/index.d.ts.map +1 -1
- package/dist/combat/index.js.map +1 -1
- package/dist/crafting/actions/index.d.ts +21 -7
- package/dist/crafting/actions/index.d.ts.map +1 -1
- package/dist/crafting/actions/index.js +69 -24
- package/dist/crafting/actions/index.js.map +1 -1
- package/dist/crafting/index.d.ts +21 -2
- package/dist/crafting/index.d.ts.map +1 -1
- package/dist/crafting/index.js +5 -1
- package/dist/crafting/index.js.map +1 -1
- package/dist/fleets/actions/index.d.ts +14 -10
- package/dist/fleets/actions/index.d.ts.map +1 -1
- package/dist/fleets/actions/index.js +19 -14
- package/dist/fleets/actions/index.js.map +1 -1
- package/dist/fleets/composition-stats.d.ts.map +1 -1
- package/dist/fleets/composition-stats.js +15 -13
- package/dist/fleets/composition-stats.js.map +1 -1
- package/dist/fleets/movement-arithmetic.d.ts +9 -1
- package/dist/fleets/movement-arithmetic.d.ts.map +1 -1
- package/dist/fleets/movement-arithmetic.js +11 -6
- package/dist/fleets/movement-arithmetic.js.map +1 -1
- package/dist/fleets/warp-lane-toll.d.ts +40 -22
- package/dist/fleets/warp-lane-toll.d.ts.map +1 -1
- package/dist/fleets/warp-lane-toll.js +36 -33
- package/dist/fleets/warp-lane-toll.js.map +1 -1
- package/dist/identity/actions/index.d.ts +1 -1
- package/dist/identity/actions/index.d.ts.map +1 -1
- package/dist/identity/actions/index.js +6 -4
- package/dist/identity/actions/index.js.map +1 -1
- package/dist/identity/actions/research-unlock.d.ts.map +1 -1
- package/dist/identity/actions/research-unlock.js +3 -0
- package/dist/identity/actions/research-unlock.js.map +1 -1
- package/dist/identity/index.d.ts +64 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +54 -0
- package/dist/identity/index.js.map +1 -1
- package/dist/internal/c4/career-xp.d.ts +26 -2
- package/dist/internal/c4/career-xp.d.ts.map +1 -1
- package/dist/internal/c4/career-xp.js +31 -4
- package/dist/internal/c4/career-xp.js.map +1 -1
- package/dist/internal/c4/character.d.ts +78 -0
- package/dist/internal/c4/character.d.ts.map +1 -1
- package/dist/internal/c4/character.js +82 -11
- package/dist/internal/c4/character.js.map +1 -1
- package/dist/internal/c4/claim-stake-plots.d.ts +25 -7
- package/dist/internal/c4/claim-stake-plots.d.ts.map +1 -1
- package/dist/internal/c4/claim-stake-plots.js +64 -16
- package/dist/internal/c4/claim-stake-plots.js.map +1 -1
- package/dist/internal/c4/claim-stake-standing.d.ts.map +1 -1
- package/dist/internal/c4/claim-stake-standing.js +9 -2
- package/dist/internal/c4/claim-stake-standing.js.map +1 -1
- package/dist/internal/c4/claim-stake-storage.d.ts +3 -2
- package/dist/internal/c4/claim-stake-storage.d.ts.map +1 -1
- package/dist/internal/c4/claim-stake-storage.js +14 -8
- package/dist/internal/c4/claim-stake-storage.js.map +1 -1
- package/dist/internal/c4/claim-stake-system-cap.d.ts +15 -0
- package/dist/internal/c4/claim-stake-system-cap.d.ts.map +1 -0
- package/dist/internal/c4/claim-stake-system-cap.js +31 -0
- package/dist/internal/c4/claim-stake-system-cap.js.map +1 -0
- package/dist/internal/c4/claim-stake.d.ts +0 -1
- package/dist/internal/c4/claim-stake.d.ts.map +1 -1
- package/dist/internal/c4/claim-stake.js +24 -2
- package/dist/internal/c4/claim-stake.js.map +1 -1
- package/dist/internal/c4/crafting-process-codec.d.ts +6 -9
- package/dist/internal/c4/crafting-process-codec.d.ts.map +1 -1
- package/dist/internal/c4/crafting-process-codec.js +9 -30
- package/dist/internal/c4/crafting-process-codec.js.map +1 -1
- package/dist/internal/c4/crafting-storage.d.ts.map +1 -1
- package/dist/internal/c4/crafting-storage.js +1 -0
- package/dist/internal/c4/crafting-storage.js.map +1 -1
- package/dist/internal/c4/crafting.d.ts +13 -4
- package/dist/internal/c4/crafting.d.ts.map +1 -1
- package/dist/internal/c4/crafting.js +16 -15
- package/dist/internal/c4/crafting.js.map +1 -1
- package/dist/internal/c4/discriminators.d.ts +17 -1
- package/dist/internal/c4/discriminators.d.ts.map +1 -1
- package/dist/internal/c4/discriminators.js +35 -3
- package/dist/internal/c4/discriminators.js.map +1 -1
- package/dist/internal/c4/fleet-creation.d.ts.map +1 -1
- package/dist/internal/c4/fleet-creation.js +3 -2
- package/dist/internal/c4/fleet-creation.js.map +1 -1
- package/dist/internal/c4/fleet-storage.d.ts.map +1 -1
- package/dist/internal/c4/fleet-storage.js +6 -1
- package/dist/internal/c4/fleet-storage.js.map +1 -1
- package/dist/internal/c4/fleet.d.ts +57 -17
- package/dist/internal/c4/fleet.d.ts.map +1 -1
- package/dist/internal/c4/fleet.js +67 -6
- package/dist/internal/c4/fleet.js.map +1 -1
- package/dist/internal/c4/game.d.ts +21 -0
- package/dist/internal/c4/game.d.ts.map +1 -1
- package/dist/internal/c4/game.js +35 -3
- package/dist/internal/c4/game.js.map +1 -1
- package/dist/internal/c4/governance.d.ts +241 -0
- package/dist/internal/c4/governance.d.ts.map +1 -0
- package/dist/internal/c4/governance.js +366 -0
- package/dist/internal/c4/governance.js.map +1 -0
- package/dist/internal/c4/local-market-order.d.ts +1 -0
- package/dist/internal/c4/local-market-order.d.ts.map +1 -1
- package/dist/internal/c4/local-market-order.js +1 -0
- package/dist/internal/c4/local-market-order.js.map +1 -1
- package/dist/internal/c4/pda.d.ts +16 -1
- package/dist/internal/c4/pda.d.ts.map +1 -1
- package/dist/internal/c4/pda.js +26 -1
- package/dist/internal/c4/pda.js.map +1 -1
- package/dist/internal/c4/profile-permissions.d.ts +1 -1
- package/dist/internal/c4/profile-permissions.d.ts.map +1 -1
- package/dist/internal/c4/profile-permissions.js +9 -11
- package/dist/internal/c4/profile-permissions.js.map +1 -1
- package/dist/internal/c4/region-building-policy.d.ts +17 -0
- package/dist/internal/c4/region-building-policy.d.ts.map +1 -0
- package/dist/internal/c4/region-building-policy.js +40 -0
- package/dist/internal/c4/region-building-policy.js.map +1 -0
- package/dist/internal/c4/runtime-bindings.d.ts +1 -1
- package/dist/internal/c4/runtime-bindings.d.ts.map +1 -1
- package/dist/internal/c4/runtime-bindings.js +1 -1
- package/dist/internal/c4/runtime-bindings.js.map +1 -1
- package/dist/internal/c4/ship-stats.js +17 -17
- package/dist/internal/c4/ship-stats.js.map +1 -1
- package/dist/internal/c4/world.d.ts +5 -4
- package/dist/internal/c4/world.d.ts.map +1 -1
- package/dist/internal/c4/world.js +18 -2
- package/dist/internal/c4/world.js.map +1 -1
- package/dist/internal/cargo.d.ts +3 -0
- package/dist/internal/cargo.d.ts.map +1 -1
- package/dist/internal/cargo.js +5 -0
- package/dist/internal/cargo.js.map +1 -1
- package/dist/internal/crafting-process-state.d.ts +16 -3
- package/dist/internal/crafting-process-state.d.ts.map +1 -1
- package/dist/internal/crafting-process-state.js +44 -0
- package/dist/internal/crafting-process-state.js.map +1 -1
- package/dist/internal/fleet.d.ts.map +1 -1
- package/dist/internal/fleet.js +1 -0
- package/dist/internal/fleet.js.map +1 -1
- package/dist/internal/planning/action-runtime.d.ts +6 -3
- package/dist/internal/planning/action-runtime.d.ts.map +1 -1
- package/dist/internal/planning/action-runtime.js +1 -6
- package/dist/internal/planning/action-runtime.js.map +1 -1
- package/dist/internal/planning/arrival-guards.js +2 -2
- package/dist/internal/planning/arrival-guards.js.map +1 -1
- package/dist/internal/planning/authorization-adapter.d.ts +61 -8
- package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
- package/dist/internal/planning/authorization-adapter.js +92 -10
- package/dist/internal/planning/authorization-adapter.js.map +1 -1
- package/dist/internal/planning/character-access.d.ts +1 -6
- package/dist/internal/planning/character-access.d.ts.map +1 -1
- package/dist/internal/planning/character-access.js +2 -7
- package/dist/internal/planning/character-access.js.map +1 -1
- package/dist/internal/planning/character-registration.js +1 -1
- package/dist/internal/planning/character-registration.js.map +1 -1
- package/dist/internal/planning/crafting-storage-actions.js +3 -3
- package/dist/internal/planning/crafting-storage-actions.js.map +1 -1
- package/dist/internal/planning/democracy-history.d.ts +5 -0
- package/dist/internal/planning/democracy-history.d.ts.map +1 -1
- package/dist/internal/planning/democracy-history.js +48 -6
- package/dist/internal/planning/democracy-history.js.map +1 -1
- package/dist/internal/planning/fleet-arrival.d.ts +2 -2
- package/dist/internal/planning/fleet-attack-xp.d.ts.map +1 -1
- package/dist/internal/planning/fleet-attack-xp.js +6 -5
- package/dist/internal/planning/fleet-attack-xp.js.map +1 -1
- package/dist/internal/planning/fleet-dock-funding.js +2 -2
- package/dist/internal/planning/fleet-dock-funding.js.map +1 -1
- package/dist/internal/planning/fleet-respawn.d.ts.map +1 -1
- package/dist/internal/planning/fleet-respawn.js +3 -4
- package/dist/internal/planning/fleet-respawn.js.map +1 -1
- package/dist/internal/planning/fleet-state.d.ts.map +1 -1
- package/dist/internal/planning/fleet-state.js +1 -0
- package/dist/internal/planning/fleet-state.js.map +1 -1
- package/dist/internal/planning/governance-fees.d.ts +14 -4
- package/dist/internal/planning/governance-fees.d.ts.map +1 -1
- package/dist/internal/planning/governance-fees.js +66 -21
- package/dist/internal/planning/governance-fees.js.map +1 -1
- package/dist/internal/planning/governance-storage-actions.d.ts +9 -0
- package/dist/internal/planning/governance-storage-actions.d.ts.map +1 -0
- package/dist/internal/planning/governance-storage-actions.js +89 -0
- package/dist/internal/planning/governance-storage-actions.js.map +1 -0
- package/dist/internal/planning/local-market-order-funding.d.ts.map +1 -1
- package/dist/internal/planning/local-market-order-funding.js +2 -2
- package/dist/internal/planning/local-market-order-funding.js.map +1 -1
- package/dist/internal/planning/mining-stop.js +1 -1
- package/dist/internal/planning/mining-stop.js.map +1 -1
- package/dist/internal/planning/movement-xp-guard.d.ts.map +1 -1
- package/dist/internal/planning/movement-xp-guard.js +0 -1
- package/dist/internal/planning/movement-xp-guard.js.map +1 -1
- package/dist/internal/planning/plan-guards.js +2 -2
- package/dist/internal/planning/profile-storage-funding-guard.d.ts +1 -1
- package/dist/internal/planning/profile-storage-funding-guard.d.ts.map +1 -1
- package/dist/internal/planning/profile-storage-funding-guard.js +15 -1
- package/dist/internal/planning/profile-storage-funding-guard.js.map +1 -1
- package/dist/internal/planning/rent-catalog.d.ts.map +1 -1
- package/dist/internal/planning/rent-catalog.js +14 -4
- package/dist/internal/planning/rent-catalog.js.map +1 -1
- package/dist/internal/planning/research-unlock.d.ts.map +1 -1
- package/dist/internal/planning/research-unlock.js +12 -1
- package/dist/internal/planning/research-unlock.js.map +1 -1
- package/dist/internal/planning/runtime-guards.d.ts.map +1 -1
- package/dist/internal/planning/runtime-guards.js +90 -71
- package/dist/internal/planning/runtime-guards.js.map +1 -1
- package/dist/internal/planning/storage-action-readers.d.ts.map +1 -1
- package/dist/internal/planning/storage-action-readers.js +7 -0
- package/dist/internal/planning/storage-action-readers.js.map +1 -1
- package/dist/internal/planning/xp-runtime.d.ts +4 -5
- package/dist/internal/planning/xp-runtime.d.ts.map +1 -1
- package/dist/internal/planning/xp-runtime.js +26 -51
- package/dist/internal/planning/xp-runtime.js.map +1 -1
- package/dist/mining/actions/index.d.ts +10 -3
- package/dist/mining/actions/index.d.ts.map +1 -1
- package/dist/mining/actions/index.js +20 -5
- package/dist/mining/actions/index.js.map +1 -1
- package/dist/mining/exit-fuel.d.ts +47 -0
- package/dist/mining/exit-fuel.d.ts.map +1 -0
- package/dist/mining/exit-fuel.js +47 -0
- package/dist/mining/exit-fuel.js.map +1 -0
- package/dist/mining/index.d.ts +1 -0
- package/dist/mining/index.d.ts.map +1 -1
- package/dist/mining/index.js +1 -0
- package/dist/mining/index.js.map +1 -1
- package/dist/mining/profile.d.ts +2 -1
- package/dist/mining/profile.d.ts.map +1 -1
- package/dist/mining/profile.js +2 -1
- package/dist/mining/profile.js.map +1 -1
- package/dist/planning/assembly.d.ts +12 -5
- package/dist/planning/assembly.d.ts.map +1 -1
- package/dist/planning/assembly.js +22 -18
- package/dist/planning/assembly.js.map +1 -1
- package/dist/planning/execution.d.ts.map +1 -1
- package/dist/planning/execution.js +3 -5
- package/dist/planning/execution.js.map +1 -1
- package/dist/planning/index.d.ts +3 -2
- package/dist/planning/index.d.ts.map +1 -1
- package/dist/planning/index.js +2 -2
- package/dist/planning/index.js.map +1 -1
- package/dist/planning/plan-construction.js +1 -1
- package/dist/planning/selected-references.d.ts +17 -0
- package/dist/planning/selected-references.d.ts.map +1 -0
- package/dist/planning/selected-references.js +42 -0
- package/dist/planning/selected-references.js.map +1 -0
- package/dist/planning/simulation.d.ts.map +1 -1
- package/dist/planning/simulation.js +2 -3
- package/dist/planning/simulation.js.map +1 -1
- package/dist/ptr/account.d.ts +109 -0
- package/dist/ptr/account.d.ts.map +1 -0
- package/dist/ptr/account.js +421 -0
- package/dist/ptr/account.js.map +1 -0
- package/dist/ptr/context.d.ts +4 -0
- package/dist/ptr/context.d.ts.map +1 -0
- package/dist/ptr/context.js +15 -0
- package/dist/ptr/context.js.map +1 -0
- package/dist/ptr/errors.d.ts +91 -0
- package/dist/ptr/errors.d.ts.map +1 -0
- package/dist/ptr/errors.js +74 -0
- package/dist/ptr/errors.js.map +1 -0
- package/dist/ptr/faucet.d.ts +231 -0
- package/dist/ptr/faucet.d.ts.map +1 -0
- package/dist/ptr/faucet.js +395 -0
- package/dist/ptr/faucet.js.map +1 -0
- package/dist/ptr/index.d.ts +22 -0
- package/dist/ptr/index.d.ts.map +1 -0
- package/dist/ptr/index.js +22 -0
- package/dist/ptr/index.js.map +1 -0
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.js +2 -2
- package/dist/registry/onboarding.d.ts +3 -1
- package/dist/registry/onboarding.d.ts.map +1 -1
- package/dist/registry/onboarding.js +4 -5
- package/dist/registry/onboarding.js.map +1 -1
- package/dist/registry/ship-stats-snapshot.js +17 -17
- package/dist/registry/ship-stats-snapshot.js.map +1 -1
- package/dist/starbases/actions/governance.d.ts +78 -0
- package/dist/starbases/actions/governance.d.ts.map +1 -0
- package/dist/starbases/actions/governance.js +382 -0
- package/dist/starbases/actions/governance.js.map +1 -0
- package/dist/starbases/actions/index.d.ts +1 -1
- package/dist/starbases/actions/index.d.ts.map +1 -1
- package/dist/starbases/actions/index.js +1 -0
- package/dist/starbases/actions/index.js.map +1 -1
- package/dist/starbases/governance.d.ts +370 -0
- package/dist/starbases/governance.d.ts.map +1 -0
- package/dist/starbases/governance.js +422 -0
- package/dist/starbases/governance.js.map +1 -0
- package/dist/starbases/index.d.ts +1 -0
- package/dist/starbases/index.d.ts.map +1 -1
- package/dist/starbases/index.js +1 -0
- package/dist/starbases/index.js.map +1 -1
- package/dist/world/planet-claim-stake-plots.d.ts +18 -14
- package/dist/world/planet-claim-stake-plots.d.ts.map +1 -1
- package/dist/world/planet-claim-stake-plots.js +11 -8
- package/dist/world/planet-claim-stake-plots.js.map +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AccountRole, getProgramDerivedAddress, } from '@solana/kit';
|
|
2
|
+
import { InvalidActionInputError } from '../client/errors.js';
|
|
3
|
+
const SEED = /* @__PURE__ */ new TextEncoder().encode('selected-reference');
|
|
4
|
+
const REFERENCE_COUNT = 6;
|
|
5
|
+
function releaseBytes(release) {
|
|
6
|
+
const bytes = new Uint8Array(32);
|
|
7
|
+
for (let index = 0; index < 32; index += 1)
|
|
8
|
+
bytes[index] = Number.parseInt(release.slice(index * 2, index * 2 + 2), 16);
|
|
9
|
+
return bytes;
|
|
10
|
+
}
|
|
11
|
+
/** The six reference accounts, in kind order 0–5, that selected gameplay
|
|
12
|
+
* requires after each SAGE instruction's own accounts. */
|
|
13
|
+
export async function selectedReferenceAddresses(deployment) {
|
|
14
|
+
const release = releaseBytes(deployment.release);
|
|
15
|
+
return Promise.all(Array.from({ length: REFERENCE_COUNT }, async (_, kind) => (await getProgramDerivedAddress({
|
|
16
|
+
programAddress: deployment.sage,
|
|
17
|
+
seeds: [SEED, release, new Uint8Array([kind])],
|
|
18
|
+
}))[0]));
|
|
19
|
+
}
|
|
20
|
+
/** Appends the selected-reference accounts, read-only, to every SAGE
|
|
21
|
+
* instruction. The program strips that exact suffix before decoding, so it is
|
|
22
|
+
* harmless where an instruction does not need it. Instructions of other
|
|
23
|
+
* programs are unchanged. A reference that already appears in the transaction
|
|
24
|
+
* is refused, because its privileges would merge with the suffix's. */
|
|
25
|
+
export async function withSelectedReferences(instructions, deployment) {
|
|
26
|
+
const references = await selectedReferenceAddresses(deployment);
|
|
27
|
+
const present = new Set(instructions.flatMap(({ accounts }) => (accounts ?? []).map(({ address }) => address)));
|
|
28
|
+
const clash = references.find((address) => present.has(address));
|
|
29
|
+
if (clash !== undefined)
|
|
30
|
+
throw new InvalidActionInputError('plan', clash, 'a Plan whose instructions do not name a selected-reference account', 'Selected-reference accounts are appended read-only during assembly. Remove that account from the Plan and recreate it before retrying.');
|
|
31
|
+
const suffix = references.map((address) => ({
|
|
32
|
+
address,
|
|
33
|
+
role: AccountRole.READONLY,
|
|
34
|
+
}));
|
|
35
|
+
return instructions.map((instruction) => instruction.programAddress === deployment.sage
|
|
36
|
+
? {
|
|
37
|
+
...instruction,
|
|
38
|
+
accounts: [...(instruction.accounts ?? []), ...suffix],
|
|
39
|
+
}
|
|
40
|
+
: instruction);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=selected-references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selected-references.js","sourceRoot":"","sources":["../../src/planning/selected-references.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAS9D,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAC5E,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,SAAS,YAAY,CAAC,OAAe;IACnC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC;QACxC,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9E,OAAO,KAAK,CAAC;AACf,CAAC;AAED;0DAC0D;AAC1D,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,UAAuC;IAEvC,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,IAAI,CACR,EAAE,MAAM,EAAE,eAAe,EAAE,EAC3B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAChB,CACE,MAAM,wBAAwB,CAAC;QAC7B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,CAAC,WAAW,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../../src/planning/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EAEb,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../../src/planning/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EAEb,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAGL,KAAK,cAAc,EAIpB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9C;AAgHD;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,CAAC;QACtC,SAAS,EAAE,MAAM,CAAC;QAClB,oBAAoB,EAAE,MAAM,CAAC;KAC9B,CAAC,CAAC;CACJ;AAsBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAmE3B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getBase64EncodedWireTransaction, SOLANA_ERROR__RPC__INTEGER_OVERFLOW, } from '@solana/kit';
|
|
2
2
|
import { InvalidActionInputError, ProviderError, SageSdkError, } from '../client/errors.js';
|
|
3
|
-
import { assembleValidatedPlan, requireWriteRpc, validateAssemblyPolicy,
|
|
3
|
+
import { assembleValidatedPlan, contextSelectedReferences, requireWriteRpc, validateAssemblyPolicy, validatePlan, } from './assembly.js';
|
|
4
4
|
function validateSimulationOptions(options) {
|
|
5
5
|
if (options === undefined)
|
|
6
6
|
return undefined;
|
|
@@ -118,10 +118,9 @@ export async function simulatePlan(context, plan, policy, options) {
|
|
|
118
118
|
validatePlan(context.programs, plan);
|
|
119
119
|
rejectMisplacedSlot(policy);
|
|
120
120
|
const validatedPolicy = validateAssemblyPolicy(policy);
|
|
121
|
-
validatePlanAssemblyPolicy(plan, validatedPolicy);
|
|
122
121
|
const minContextSlot = validateSimulationOptions(options);
|
|
123
122
|
const writeRpc = requireWriteRpc(context);
|
|
124
|
-
const transaction = await assembleValidatedPlan(writeRpc, plan, validatedPolicy);
|
|
123
|
+
const transaction = await assembleValidatedPlan(writeRpc, plan, validatedPolicy, contextSelectedReferences(context));
|
|
125
124
|
const encodedTransaction = getBase64EncodedWireTransaction(transaction);
|
|
126
125
|
let response;
|
|
127
126
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.js","sourceRoot":"","sources":["../../src/planning/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B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C;QACnC,aAAa;KACd,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type MessagePartialSigner, type TransactionSigner } from '@solana/kit';
|
|
2
|
+
import type { Address, SageContext } from '../client/contracts.js';
|
|
3
|
+
import { type PlayableFaction } from '../factions/actions/index.js';
|
|
4
|
+
import type { StarSystemSnapshot } from '../world/index.js';
|
|
5
|
+
import { type PtrAccountStep, type PtrAccountStepResult } from './errors.js';
|
|
6
|
+
import { type PtrFaucetClaim, type PtrFetch, type PtrZinkTopup } from './faucet.js';
|
|
7
|
+
/** One progress event from `createPtrAccount`.
|
|
8
|
+
*
|
|
9
|
+
* `started` precedes a step; `executed` or `skipped` finishes it.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const event: PtrAccountProgress = { step: 'claimCrew', status: 'started' };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface PtrAccountProgress {
|
|
17
|
+
readonly step: PtrAccountStep;
|
|
18
|
+
readonly status: 'started' | 'executed' | 'skipped';
|
|
19
|
+
readonly signature?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Input for `createPtrAccount`.
|
|
22
|
+
*
|
|
23
|
+
* `wallet` pays every fee and storage cost and signs the faucet proofs.
|
|
24
|
+
* `profile` is a fresh signer to create a new Profile, or the address of an
|
|
25
|
+
* existing Profile whose single authority key is the wallet, to resume.
|
|
26
|
+
* `starSystem` is the loaded home Star System whose Starbase the
|
|
27
|
+
* StarbasePlayer registers at. `profileFunding` is the native balance, in
|
|
28
|
+
* lamports, the Profile is topped up to for faction enrollment (default
|
|
29
|
+
* 500,000,000, 0.5 ZINK). `claimCrew` (default `true`) claims faucet crew for
|
|
30
|
+
* the StarbasePlayer.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import type { MessagePartialSigner, TransactionSigner } from '@solana/kit';
|
|
35
|
+
* declare const wallet: TransactionSigner & MessagePartialSigner;
|
|
36
|
+
* declare const profile: TransactionSigner;
|
|
37
|
+
* declare const starSystem: StarSystemSnapshot;
|
|
38
|
+
* const options: CreatePtrAccountOptions = { wallet, profile, faction: 'ustur', starSystem };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export interface CreatePtrAccountOptions {
|
|
42
|
+
readonly wallet: TransactionSigner & MessagePartialSigner;
|
|
43
|
+
readonly profile: TransactionSigner | Address;
|
|
44
|
+
readonly faction: PlayableFaction;
|
|
45
|
+
readonly starSystem: StarSystemSnapshot;
|
|
46
|
+
readonly profileFunding?: bigint;
|
|
47
|
+
readonly claimCrew?: boolean;
|
|
48
|
+
readonly fetch?: PtrFetch;
|
|
49
|
+
readonly signal?: AbortSignal;
|
|
50
|
+
readonly onProgress?: (event: PtrAccountProgress) => void;
|
|
51
|
+
}
|
|
52
|
+
/** The finished PTR account and what each step did.
|
|
53
|
+
*
|
|
54
|
+
* `faucet` holds the faucet's answers for the requests this call made.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* declare const account: PtrAccount;
|
|
59
|
+
* console.log(account.starbasePlayer, account.steps.map((step) => step.status));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export interface PtrAccount {
|
|
63
|
+
readonly wallet: Address;
|
|
64
|
+
readonly profile: Address;
|
|
65
|
+
readonly character: Address;
|
|
66
|
+
readonly starbasePlayer: Address;
|
|
67
|
+
readonly steps: readonly PtrAccountStepResult[];
|
|
68
|
+
readonly faucet: Readonly<{
|
|
69
|
+
starter?: PtrFaucetClaim;
|
|
70
|
+
topup?: PtrZinkTopup;
|
|
71
|
+
crew?: PtrFaucetClaim;
|
|
72
|
+
}>;
|
|
73
|
+
toJSON(): unknown;
|
|
74
|
+
}
|
|
75
|
+
/** Takes a caller-supplied wallet to a funded, crewed z.ink PTR account.
|
|
76
|
+
*
|
|
77
|
+
* Runs, in order: claim the faucet starter bundle and wait for the wallet's
|
|
78
|
+
* ZINK; request a ZINK top-up when the wallet is low; create a Profile whose
|
|
79
|
+
* single authority key is the wallet; fund the Profile; choose a faction;
|
|
80
|
+
* register a Character; register a StarbasePlayer at the home Star System's
|
|
81
|
+
* Starbase; claim faucet crew for it and wait until the crew is on the
|
|
82
|
+
* StarbasePlayer. Each step reads current state first and
|
|
83
|
+
* is skipped when already satisfied. Each on-chain step is simulated, then
|
|
84
|
+
* executed once with a compute limit from the simulation. The wallet is the
|
|
85
|
+
* fee payer and funder throughout. Faucet requests are spaced 32 seconds
|
|
86
|
+
* apart; nothing is retried.
|
|
87
|
+
*
|
|
88
|
+
* The Profile keeps exactly one authority key, the wallet: PTR's democracy
|
|
89
|
+
* enrollment refuses Profiles with more than one, and authority keys cannot be
|
|
90
|
+
* added or removed after creation. No key is generated, stored or retained;
|
|
91
|
+
* callers pass signers. Only `zink-ptr` with its default programs and Game is
|
|
92
|
+
* accepted, and the context needs `writeRpc`.
|
|
93
|
+
*
|
|
94
|
+
* A failure throws `PtrAccountIncompleteError` naming the completed steps;
|
|
95
|
+
* call again with the Profile address to resume.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { generateKeyPairSigner } from '@solana/kit';
|
|
100
|
+
* declare const ctx: SageContext;
|
|
101
|
+
* declare const starSystem: StarSystemSnapshot;
|
|
102
|
+
* const wallet = await generateKeyPairSigner();
|
|
103
|
+
* const profile = await generateKeyPairSigner();
|
|
104
|
+
* const account = await createPtrAccount(ctx, { wallet, profile, faction: 'ustur', starSystem });
|
|
105
|
+
* console.log(account.starbasePlayer);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function createPtrAccount(ctx: SageContext, options: CreatePtrAccountOptions): Promise<PtrAccount>;
|
|
109
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/ptr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;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;QACxB,OAAO,CAAC,EAAE,cAAc,CAAC;QACzB,KAAK,CAAC,EAAE,YAAY,CAAC;QACrB,IAAI,CAAC,EAAE,cAAc,CAAC;KACvB,CAAC,CAAC;IACH,MAAM,IAAI,OAAO,CAAC;CACnB;AA+OD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CA8SrB"}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { AccountRole, isAddress, isOffCurveAddress, } from '@solana/kit';
|
|
2
|
+
import { InvalidActionInputError, SageSdkError } from '../client/errors.js';
|
|
3
|
+
import { readContextRawAccounts } from '../client/reconciliation.js';
|
|
4
|
+
import { getCharacterForProfile, maybeGetCharacterForProfile, maybeGetProfile, } from '../identity/index.js';
|
|
5
|
+
import { planCreateProfile, planRegisterCharacter, } from '../identity/actions/index.js';
|
|
6
|
+
import { maybeGetFactionForProfile } from '../factions/index.js';
|
|
7
|
+
import { planChooseFaction, } from '../factions/actions/index.js';
|
|
8
|
+
import { planRegisterStarbasePlayer } from '../starbases/actions/index.js';
|
|
9
|
+
import { createPlan, executePlan, simulatePlan, } from '../planning/index.js';
|
|
10
|
+
import { deriveStarbasePlayerAddress, starbasePlayerAccountDefinition, } from '../internal/c4/starbase.js';
|
|
11
|
+
import { assertPtrContext } from './context.js';
|
|
12
|
+
import { PtrAccountIncompleteError, } from './errors.js';
|
|
13
|
+
import { PTR_FAUCET_REQUEST_SPACING_MS, claimPtrFaucet, requestPtrZinkTopup, } from './faucet.js';
|
|
14
|
+
const SYSTEM_PROGRAM = '11111111111111111111111111111111';
|
|
15
|
+
const LAMPORTS_PER_ZINK = 1000000000n;
|
|
16
|
+
// The official client tops up below these balances.
|
|
17
|
+
const TOPUP_COMBINED_BELOW = LAMPORTS_PER_ZINK;
|
|
18
|
+
const TOPUP_WALLET_BELOW = LAMPORTS_PER_ZINK / 100n;
|
|
19
|
+
const DEFAULT_PROFILE_FUNDING = 500000000n;
|
|
20
|
+
// Profile AUTH key mask the official client grants the single wallet key.
|
|
21
|
+
const WALLET_KEY_PERMISSIONS = 0x8000000000000fffn;
|
|
22
|
+
const MAX_COMPUTE_UNITS = 1_400_000;
|
|
23
|
+
const COMPUTE_HEADROOM = 1.3;
|
|
24
|
+
const BALANCE_WAIT_MS = 60_000;
|
|
25
|
+
const BALANCE_POLL_MS = 1_500;
|
|
26
|
+
function invalid(field, value, accepted, remedy) {
|
|
27
|
+
throw new InvalidActionInputError(field, value, accepted, remedy);
|
|
28
|
+
}
|
|
29
|
+
function isTransactionSigner(value) {
|
|
30
|
+
if (value === null || typeof value !== 'object')
|
|
31
|
+
return false;
|
|
32
|
+
const signer = value;
|
|
33
|
+
return (typeof signer.address === 'string' &&
|
|
34
|
+
isAddress(signer.address) &&
|
|
35
|
+
(typeof signer.signTransactions === 'function' ||
|
|
36
|
+
typeof signer.modifyAndSignTransactions === 'function' ||
|
|
37
|
+
typeof signer.signAndSendTransactions === 'function'));
|
|
38
|
+
}
|
|
39
|
+
function validateOptions(ctx, input) {
|
|
40
|
+
if (input === null || typeof input !== 'object')
|
|
41
|
+
invalid('options', input, 'an object with wallet, profile, faction and starSystem', 'Pass the wallet signer, a fresh Profile signer or existing Profile address, a faction and the loaded home Star System.');
|
|
42
|
+
const { wallet, profile, faction, starSystem } = input;
|
|
43
|
+
if (!isTransactionSigner(wallet) ||
|
|
44
|
+
typeof wallet.signMessages !==
|
|
45
|
+
'function' ||
|
|
46
|
+
isOffCurveAddress(wallet.address))
|
|
47
|
+
invalid('options.wallet', wallet, 'a Kit signer that signs both transactions and messages', 'Pass a wallet signer such as one from generateKeyPairSigner(); it pays fees and signs the faucet proofs.');
|
|
48
|
+
let profileSigner;
|
|
49
|
+
let profileAddress;
|
|
50
|
+
if (typeof profile === 'string') {
|
|
51
|
+
if (!isAddress(profile))
|
|
52
|
+
invalid('options.profile', profile, 'an existing Profile address or a fresh Profile signer', 'Pass the Profile address printed by an earlier run to resume, or a new signer to create a Profile.');
|
|
53
|
+
profileAddress = profile;
|
|
54
|
+
}
|
|
55
|
+
else if (isTransactionSigner(profile)) {
|
|
56
|
+
profileSigner = profile;
|
|
57
|
+
profileAddress = profile.address;
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
invalid('options.profile', profile, 'an existing Profile address or a fresh Profile signer', 'Pass a new signer such as one from generateKeyPairSigner() to create the Profile, or its address to resume.');
|
|
61
|
+
if (profileAddress === wallet.address)
|
|
62
|
+
invalid('options.profile', profileAddress, 'a Profile address distinct from the wallet', 'Generate a separate Profile signer; the wallet is the Profile key, not the Profile account.');
|
|
63
|
+
if (!['mud', 'oni', 'ustur'].includes(faction))
|
|
64
|
+
invalid('options.faction', faction, 'mud, oni or ustur', 'Choose the faction whose home Star System you pass.');
|
|
65
|
+
if (starSystem === null ||
|
|
66
|
+
typeof starSystem !== 'object' ||
|
|
67
|
+
starSystem.kind !== 'starSystem' ||
|
|
68
|
+
typeof starSystem.address !== 'string' ||
|
|
69
|
+
starSystem.game !== ctx.game)
|
|
70
|
+
invalid('options.starSystem', starSystem, 'a Star System snapshot loaded through this context', 'Load the home Star System with getStarSystem or getStarSystemById for this context and pass it.');
|
|
71
|
+
const profileFunding = input.profileFunding ?? DEFAULT_PROFILE_FUNDING;
|
|
72
|
+
if (typeof profileFunding !== 'bigint' ||
|
|
73
|
+
profileFunding < 0n ||
|
|
74
|
+
profileFunding > 0xffffffffffffffffn)
|
|
75
|
+
invalid('options.profileFunding', profileFunding, 'a nonnegative bigint lamport balance', 'Omit profileFunding for the default 0.5 ZINK, or pass an exact bigint.');
|
|
76
|
+
const claimCrew = input.claimCrew ?? true;
|
|
77
|
+
if (typeof claimCrew !== 'boolean')
|
|
78
|
+
invalid('options.claimCrew', claimCrew, 'a boolean', 'Pass true or false.');
|
|
79
|
+
if (input.onProgress !== undefined && typeof input.onProgress !== 'function')
|
|
80
|
+
invalid('options.onProgress', input.onProgress, 'a function', 'Pass a progress callback or omit it.');
|
|
81
|
+
return {
|
|
82
|
+
wallet,
|
|
83
|
+
profileSigner,
|
|
84
|
+
profile: profileAddress,
|
|
85
|
+
faction,
|
|
86
|
+
starSystem,
|
|
87
|
+
profileFunding,
|
|
88
|
+
claimCrew,
|
|
89
|
+
fetch: input.fetch,
|
|
90
|
+
signal: input.signal,
|
|
91
|
+
onProgress: input.onProgress,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function delay(ms, signal) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
if (signal?.aborted) {
|
|
97
|
+
reject(signal.reason);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const onAbort = () => {
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
reject(signal.reason);
|
|
103
|
+
};
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
signal?.removeEventListener('abort', onAbort);
|
|
106
|
+
resolve();
|
|
107
|
+
}, ms);
|
|
108
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function fail(message, address) {
|
|
112
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', message, { address });
|
|
113
|
+
}
|
|
114
|
+
/** Simulates, then executes once with a compute limit from the simulation,
|
|
115
|
+
* unless the signal was aborted in between. */
|
|
116
|
+
async function simulateAndExecute(ctx, plan, wallet, signers, signal) {
|
|
117
|
+
// Simulate at the ceiling: runtime-6 Character registration exceeds the default.
|
|
118
|
+
const simulation = await simulatePlan(ctx, plan, {
|
|
119
|
+
feePayer: wallet.address,
|
|
120
|
+
computeUnitLimit: MAX_COMPUTE_UNITS,
|
|
121
|
+
});
|
|
122
|
+
// Cancellation during simulation must stop before anything is signed.
|
|
123
|
+
signal?.throwIfAborted();
|
|
124
|
+
const computeUnitLimit = simulation.unitsConsumed === undefined
|
|
125
|
+
? MAX_COMPUTE_UNITS
|
|
126
|
+
: Math.min(MAX_COMPUTE_UNITS, Math.ceil(Number(simulation.unitsConsumed) * COMPUTE_HEADROOM));
|
|
127
|
+
const result = await executePlan(ctx, plan, {
|
|
128
|
+
feePayer: wallet,
|
|
129
|
+
signers,
|
|
130
|
+
computeUnitLimit,
|
|
131
|
+
});
|
|
132
|
+
if (result.status !== 'confirmed')
|
|
133
|
+
throw new SageSdkError('TRANSACTION_OUTCOME_UNKNOWN', `Transaction ${result.signature} for ${plan.kind} was submitted but its outcome is unknown (${result.reason}). Check the signature on z.ink PTR before resuming; resuming re-reads state and skips the step if it landed.`);
|
|
134
|
+
return result.signature;
|
|
135
|
+
}
|
|
136
|
+
function systemTransfer(from, to, lamports) {
|
|
137
|
+
const data = new Uint8Array(12);
|
|
138
|
+
const view = new DataView(data.buffer);
|
|
139
|
+
view.setUint32(0, 2, true);
|
|
140
|
+
view.setBigUint64(4, lamports, true);
|
|
141
|
+
return {
|
|
142
|
+
programAddress: SYSTEM_PROGRAM,
|
|
143
|
+
accounts: [
|
|
144
|
+
{ address: from, role: AccountRole.WRITABLE_SIGNER },
|
|
145
|
+
{ address: to, role: AccountRole.WRITABLE },
|
|
146
|
+
],
|
|
147
|
+
data,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function toJSONResult(account) {
|
|
151
|
+
const value = {
|
|
152
|
+
...account,
|
|
153
|
+
toJSON() {
|
|
154
|
+
return {
|
|
155
|
+
wallet: account.wallet,
|
|
156
|
+
profile: account.profile,
|
|
157
|
+
character: account.character,
|
|
158
|
+
starbasePlayer: account.starbasePlayer,
|
|
159
|
+
steps: account.steps,
|
|
160
|
+
faucet: account.faucet,
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
Object.defineProperty(value, 'toJSON', { enumerable: false });
|
|
165
|
+
return Object.freeze(value);
|
|
166
|
+
}
|
|
167
|
+
/** Takes a caller-supplied wallet to a funded, crewed z.ink PTR account.
|
|
168
|
+
*
|
|
169
|
+
* Runs, in order: claim the faucet starter bundle and wait for the wallet's
|
|
170
|
+
* ZINK; request a ZINK top-up when the wallet is low; create a Profile whose
|
|
171
|
+
* single authority key is the wallet; fund the Profile; choose a faction;
|
|
172
|
+
* register a Character; register a StarbasePlayer at the home Star System's
|
|
173
|
+
* Starbase; claim faucet crew for it and wait until the crew is on the
|
|
174
|
+
* StarbasePlayer. Each step reads current state first and
|
|
175
|
+
* is skipped when already satisfied. Each on-chain step is simulated, then
|
|
176
|
+
* executed once with a compute limit from the simulation. The wallet is the
|
|
177
|
+
* fee payer and funder throughout. Faucet requests are spaced 32 seconds
|
|
178
|
+
* apart; nothing is retried.
|
|
179
|
+
*
|
|
180
|
+
* The Profile keeps exactly one authority key, the wallet: PTR's democracy
|
|
181
|
+
* enrollment refuses Profiles with more than one, and authority keys cannot be
|
|
182
|
+
* added or removed after creation. No key is generated, stored or retained;
|
|
183
|
+
* callers pass signers. Only `zink-ptr` with its default programs and Game is
|
|
184
|
+
* accepted, and the context needs `writeRpc`.
|
|
185
|
+
*
|
|
186
|
+
* A failure throws `PtrAccountIncompleteError` naming the completed steps;
|
|
187
|
+
* call again with the Profile address to resume.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { generateKeyPairSigner } from '@solana/kit';
|
|
192
|
+
* declare const ctx: SageContext;
|
|
193
|
+
* declare const starSystem: StarSystemSnapshot;
|
|
194
|
+
* const wallet = await generateKeyPairSigner();
|
|
195
|
+
* const profile = await generateKeyPairSigner();
|
|
196
|
+
* const account = await createPtrAccount(ctx, { wallet, profile, faction: 'ustur', starSystem });
|
|
197
|
+
* console.log(account.starbasePlayer);
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export async function createPtrAccount(ctx, options) {
|
|
201
|
+
assertPtrContext(ctx);
|
|
202
|
+
const input = validateOptions(ctx, options);
|
|
203
|
+
if (ctx.writeRpc === undefined)
|
|
204
|
+
throw new SageSdkError('MISSING_WRITE_TRANSPORT', 'This SAGE context has no writeRpc transport, so createPtrAccount cannot execute its steps. Pass the optional writeRpc transport when creating the context, then retry.');
|
|
205
|
+
const { wallet, profile, signal } = input;
|
|
206
|
+
const transport = {
|
|
207
|
+
...(input.fetch === undefined ? {} : { fetch: input.fetch }),
|
|
208
|
+
...(signal === undefined ? {} : { signal }),
|
|
209
|
+
};
|
|
210
|
+
const steps = [];
|
|
211
|
+
const faucet = {};
|
|
212
|
+
let lastFaucetRequest;
|
|
213
|
+
let current = 'claimStarter';
|
|
214
|
+
const emit = (event) => input.onProgress?.(event);
|
|
215
|
+
const begin = (step) => {
|
|
216
|
+
signal?.throwIfAborted();
|
|
217
|
+
current = step;
|
|
218
|
+
emit({ step, status: 'started' });
|
|
219
|
+
};
|
|
220
|
+
const finish = (step, status, signature) => {
|
|
221
|
+
const result = Object.freeze({
|
|
222
|
+
step,
|
|
223
|
+
status,
|
|
224
|
+
...(signature === undefined ? {} : { signature }),
|
|
225
|
+
});
|
|
226
|
+
steps.push(result);
|
|
227
|
+
emit(result);
|
|
228
|
+
};
|
|
229
|
+
// Spacing is measured from the end of the previous faucet request; it is not a retry.
|
|
230
|
+
const faucetRequest = async (send) => {
|
|
231
|
+
if (lastFaucetRequest !== undefined) {
|
|
232
|
+
const wait = lastFaucetRequest + PTR_FAUCET_REQUEST_SPACING_MS - Date.now();
|
|
233
|
+
if (wait > 0)
|
|
234
|
+
await delay(wait, signal);
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
return await send();
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
lastFaucetRequest = Date.now();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const balance = async (address) => {
|
|
244
|
+
const [account] = await readContextRawAccounts(ctx, [address], signal === undefined ? {} : { signal });
|
|
245
|
+
return account?.lamports ?? 0n;
|
|
246
|
+
};
|
|
247
|
+
const waitForBalance = async (above, what) => {
|
|
248
|
+
const deadline = Date.now() + BALANCE_WAIT_MS;
|
|
249
|
+
for (;;) {
|
|
250
|
+
if ((await balance(wallet.address)) > above)
|
|
251
|
+
return;
|
|
252
|
+
if (Date.now() >= deadline)
|
|
253
|
+
fail(`Wallet ${wallet.address} shows no ${what} ${BALANCE_WAIT_MS / 1000} seconds after the faucet accepted the request. The faucet may still be delivering; wait, then resume.`, wallet.address);
|
|
254
|
+
await delay(BALANCE_POLL_MS, signal);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
// 1. Starter bundle: the faucet answers alreadyClaimed for a repeat.
|
|
259
|
+
begin('claimStarter');
|
|
260
|
+
const starter = await faucetRequest(() => claimPtrFaucet(ctx, { wallet, distribution: 'starter', ...transport }));
|
|
261
|
+
faucet.starter = starter;
|
|
262
|
+
// A repeat claim delivers nothing; a drained wallet is the top-up's job.
|
|
263
|
+
if (!starter.alreadyClaimed)
|
|
264
|
+
await waitForBalance(0n, 'ZINK');
|
|
265
|
+
finish('claimStarter', starter.alreadyClaimed ? 'skipped' : 'executed', starter.signatures[0]);
|
|
266
|
+
// 2. ZINK top-up, only when the wallet is low.
|
|
267
|
+
begin('topUpZink');
|
|
268
|
+
const walletBalance = await balance(wallet.address);
|
|
269
|
+
const profileBalance = await balance(profile);
|
|
270
|
+
if (walletBalance + profileBalance < TOPUP_COMBINED_BELOW ||
|
|
271
|
+
walletBalance < TOPUP_WALLET_BELOW) {
|
|
272
|
+
const topup = await faucetRequest(() => requestPtrZinkTopup(ctx, { wallet, ...transport }));
|
|
273
|
+
faucet.topup = topup;
|
|
274
|
+
if (topup.toppedUp === false)
|
|
275
|
+
finish('topUpZink', 'skipped');
|
|
276
|
+
else {
|
|
277
|
+
await waitForBalance(walletBalance, 'ZINK top-up');
|
|
278
|
+
finish('topUpZink', 'executed', topup.signatures[0]);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else
|
|
282
|
+
finish('topUpZink', 'skipped');
|
|
283
|
+
// 3. Profile with the wallet as its single authority key.
|
|
284
|
+
begin('createProfile');
|
|
285
|
+
const existingProfile = await maybeGetProfile(ctx, profile, {
|
|
286
|
+
refresh: true,
|
|
287
|
+
});
|
|
288
|
+
if (existingProfile !== undefined) {
|
|
289
|
+
const key = existingProfile.keys[0];
|
|
290
|
+
if (key?.address !== wallet.address ||
|
|
291
|
+
key.scope !== ctx.programs.playerProfile ||
|
|
292
|
+
(key.permissionsRaw & 1n) === 0n)
|
|
293
|
+
fail(`Profile ${profile} exists, but its primary authority key is not wallet ${wallet.address}. Resume with the wallet that created it, or pass a fresh Profile signer.`, profile);
|
|
294
|
+
finish('createProfile', 'skipped');
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
if (input.profileSigner === undefined)
|
|
298
|
+
fail(`Profile ${profile} does not exist. Pass a fresh Profile signer to create it, or the address of an existing Profile to resume.`, profile);
|
|
299
|
+
const plan = await planCreateProfile(ctx, profile, {
|
|
300
|
+
funder: wallet.address,
|
|
301
|
+
keyThreshold: 1,
|
|
302
|
+
keys: [
|
|
303
|
+
{
|
|
304
|
+
address: wallet.address,
|
|
305
|
+
scope: ctx.programs.playerProfile,
|
|
306
|
+
permissionsRaw: WALLET_KEY_PERMISSIONS,
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
finish('createProfile', 'executed', await simulateAndExecute(ctx, plan, wallet, [input.profileSigner], signal));
|
|
311
|
+
}
|
|
312
|
+
// 4. Profile funding for faction enrollment.
|
|
313
|
+
begin('fundProfile');
|
|
314
|
+
const funded = await balance(profile);
|
|
315
|
+
if (funded >= input.profileFunding)
|
|
316
|
+
finish('fundProfile', 'skipped');
|
|
317
|
+
else {
|
|
318
|
+
const amount = input.profileFunding - funded;
|
|
319
|
+
const summary = `Transfer ${amount} lamports from wallet ${wallet.address} to Profile ${profile}, bringing its balance to ${input.profileFunding} lamports for faction enrollment. Transaction fees are separate.`;
|
|
320
|
+
const plan = createPlan(ctx.programs, {
|
|
321
|
+
kind: 'ptr.fund-profile',
|
|
322
|
+
summary,
|
|
323
|
+
preconditions: [],
|
|
324
|
+
steps: [
|
|
325
|
+
{
|
|
326
|
+
instruction: systemTransfer(wallet.address, profile, amount),
|
|
327
|
+
signers: [wallet.address],
|
|
328
|
+
describes: summary,
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
});
|
|
332
|
+
finish('fundProfile', 'executed', await simulateAndExecute(ctx, plan, wallet, [], signal));
|
|
333
|
+
}
|
|
334
|
+
// 5. Faction enrollment.
|
|
335
|
+
begin('chooseFaction');
|
|
336
|
+
const enrollment = await maybeGetFactionForProfile(ctx, profile, {
|
|
337
|
+
refresh: true,
|
|
338
|
+
});
|
|
339
|
+
if (enrollment !== undefined) {
|
|
340
|
+
if (enrollment.faction !== input.faction)
|
|
341
|
+
fail(`Profile ${profile} is already enrolled as ${enrollment.faction}, not ${input.faction}. Resume with faction ${enrollment.faction} and its home Star System.`, profile);
|
|
342
|
+
finish('chooseFaction', 'skipped');
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
const plan = await planChooseFaction(ctx, {
|
|
346
|
+
faction: input.faction,
|
|
347
|
+
authorization: { profile, authority: wallet.address, keyIndex: 0 },
|
|
348
|
+
});
|
|
349
|
+
finish('chooseFaction', 'executed', await simulateAndExecute(ctx, plan, wallet, [], signal));
|
|
350
|
+
}
|
|
351
|
+
// 6. Character.
|
|
352
|
+
begin('registerCharacter');
|
|
353
|
+
let character = await maybeGetCharacterForProfile(ctx, profile, { refresh: true });
|
|
354
|
+
if (character !== undefined)
|
|
355
|
+
finish('registerCharacter', 'skipped');
|
|
356
|
+
else {
|
|
357
|
+
const plan = await planRegisterCharacter(ctx, profile, {
|
|
358
|
+
funder: wallet.address,
|
|
359
|
+
});
|
|
360
|
+
const signature = await simulateAndExecute(ctx, plan, wallet, [], signal);
|
|
361
|
+
character = await getCharacterForProfile(ctx, profile, {
|
|
362
|
+
refresh: true,
|
|
363
|
+
});
|
|
364
|
+
finish('registerCharacter', 'executed', signature);
|
|
365
|
+
}
|
|
366
|
+
// 7. StarbasePlayer at the home Star System.
|
|
367
|
+
begin('registerStarbasePlayer');
|
|
368
|
+
const starbasePlayer = await deriveStarbasePlayerAddress(ctx.programs, input.starSystem.address, character.address);
|
|
369
|
+
const readStarbasePlayer = async () => (await ctx.data.readMany(starbasePlayerAccountDefinition, [starbasePlayer], { refresh: true }))[0];
|
|
370
|
+
let registered = await readStarbasePlayer();
|
|
371
|
+
if (registered !== undefined)
|
|
372
|
+
finish('registerStarbasePlayer', 'skipped');
|
|
373
|
+
else {
|
|
374
|
+
const plan = await planRegisterStarbasePlayer(ctx, character, input.starSystem, { funder: wallet.address });
|
|
375
|
+
const signature = await simulateAndExecute(ctx, plan, wallet, [], signal);
|
|
376
|
+
registered = await readStarbasePlayer();
|
|
377
|
+
if (registered === undefined)
|
|
378
|
+
fail(`StarbasePlayer ${starbasePlayer} is not readable after confirmed registration. Wait for the node to catch up, then resume.`, starbasePlayer);
|
|
379
|
+
finish('registerStarbasePlayer', 'executed', signature);
|
|
380
|
+
}
|
|
381
|
+
// 8. Crew for the StarbasePlayer.
|
|
382
|
+
begin('claimCrew');
|
|
383
|
+
if (!input.claimCrew || registered.data.totalCrew > 0)
|
|
384
|
+
finish('claimCrew', 'skipped');
|
|
385
|
+
else {
|
|
386
|
+
const crew = await faucetRequest(() => claimPtrFaucet(ctx, {
|
|
387
|
+
wallet,
|
|
388
|
+
distribution: 'crew',
|
|
389
|
+
starbasePlayer,
|
|
390
|
+
...transport,
|
|
391
|
+
}));
|
|
392
|
+
faucet.crew = crew;
|
|
393
|
+
// The faucet may answer PENDING or alreadyClaimed before any crew lands;
|
|
394
|
+
// only crew on the StarbasePlayer completes the account.
|
|
395
|
+
const deadline = Date.now() + BALANCE_WAIT_MS;
|
|
396
|
+
for (;;) {
|
|
397
|
+
const current = await readStarbasePlayer();
|
|
398
|
+
if (current !== undefined && current.data.totalCrew > 0)
|
|
399
|
+
break;
|
|
400
|
+
if (Date.now() >= deadline)
|
|
401
|
+
fail(`StarbasePlayer ${starbasePlayer} shows no crew ${BALANCE_WAIT_MS / 1000} seconds after the faucet ${crew.alreadyClaimed ? 'reported the claim as already made' : `answered ${crew.status}`}. The faucet may still be delivering; wait, then call createPtrAccount again with Profile ${profile} to resume.`, starbasePlayer);
|
|
402
|
+
await delay(BALANCE_POLL_MS, signal);
|
|
403
|
+
}
|
|
404
|
+
finish('claimCrew', crew.alreadyClaimed ? 'skipped' : 'executed', crew.signatures[0]);
|
|
405
|
+
}
|
|
406
|
+
return toJSONResult({
|
|
407
|
+
wallet: wallet.address,
|
|
408
|
+
profile,
|
|
409
|
+
character: character.address,
|
|
410
|
+
starbasePlayer,
|
|
411
|
+
steps: Object.freeze([...steps]),
|
|
412
|
+
faucet: Object.freeze({ ...faucet }),
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
catch (cause) {
|
|
416
|
+
if (signal?.aborted && cause === signal.reason)
|
|
417
|
+
throw cause;
|
|
418
|
+
throw new PtrAccountIncompleteError(current, steps, profile, cause);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=account.js.map
|