@aephia/atlas-kit 0.6.0-next.3 → 0.6.0-next.31
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 +4 -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/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/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 +3 -0
- package/dist/fleets/actions/index.d.ts.map +1 -1
- package/dist/fleets/actions/index.js +3 -0
- 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 +309 -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 +38 -0
- package/dist/identity/actions/index.d.ts.map +1 -0
- package/dist/identity/actions/index.js +109 -0
- package/dist/identity/actions/index.js.map +1 -0
- 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 +9 -0
- package/dist/internal/c4/character-registration.d.ts.map +1 -0
- package/dist/internal/c4/character-registration.js +21 -0
- package/dist/internal/c4/character-registration.js.map +1 -0
- 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 -30
- package/dist/internal/c4/factions.d.ts.map +1 -1
- package/dist/internal/c4/factions.js +22 -107
- package/dist/internal/c4/factions.js.map +1 -1
- 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 +2 -0
- package/dist/internal/c4/fleet-crew-binding.d.ts.map +1 -1
- package/dist/internal/c4/fleet-crew-binding.js +5 -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/game.d.ts +18 -6
- package/dist/internal/c4/game.d.ts.map +1 -1
- package/dist/internal/c4/game.js +34 -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/legacy-cargo-config.d.ts +6 -0
- package/dist/internal/c4/legacy-cargo-config.d.ts.map +1 -0
- package/dist/internal/c4/legacy-cargo-config.js +26 -0
- package/dist/internal/c4/legacy-cargo-config.js.map +1 -0
- package/dist/internal/c4/market.js +10 -6
- package/dist/internal/c4/market.js.map +1 -1
- 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 +80 -0
- package/dist/internal/c4/profile-permissions.js.map +1 -0
- package/dist/internal/c4/starbase.js +4 -3
- 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/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/authorization-adapter.d.ts +17 -0
- package/dist/internal/planning/authorization-adapter.d.ts.map +1 -1
- package/dist/internal/planning/authorization-adapter.js +50 -0
- package/dist/internal/planning/authorization-adapter.js.map +1 -1
- 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-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 +39 -0
- package/dist/internal/planning/faction-trade-state.js.map +1 -0
- package/dist/internal/planning/fleet-creation.d.ts +29 -0
- package/dist/internal/planning/fleet-creation.d.ts.map +1 -0
- package/dist/internal/planning/fleet-creation.js +106 -0
- package/dist/internal/planning/fleet-creation.js.map +1 -0
- package/dist/internal/planning/fleet-ship-assembly.d.ts +35 -0
- package/dist/internal/planning/fleet-ship-assembly.d.ts.map +1 -0
- package/dist/internal/planning/fleet-ship-assembly.js +135 -0
- package/dist/internal/planning/fleet-ship-assembly.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/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 +1 -0
- 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 +288 -0
- package/dist/markets/actions/trade-faction-market.js.map +1 -0
- package/dist/mining/actions/index.d.ts +86 -0
- package/dist/mining/actions/index.d.ts.map +1 -0
- package/dist/mining/actions/index.js +295 -0
- package/dist/mining/actions/index.js.map +1 -0
- package/dist/planning/execution.d.ts.map +1 -1
- package/dist/planning/execution.js +191 -16
- package/dist/planning/execution.js.map +1 -1
- package/dist/planning/index.d.ts +316 -4
- package/dist/planning/index.d.ts.map +1 -1
- package/dist/planning/index.js +528 -14
- 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 +9 -6
- package/dist/registry/cargo.d.ts.map +1 -1
- package/dist/registry/cargo.js +30 -4
- package/dist/registry/cargo.js.map +1 -1
- package/dist/registry/onboarding.d.ts +6 -0
- package/dist/registry/onboarding.d.ts.map +1 -0
- package/dist/registry/onboarding.js +24 -0
- package/dist/registry/onboarding.js.map +1 -0
- 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/package.json +13 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { hashAccountState } from './account-state.js';
|
|
2
|
+
import { AccountRole } from '@solana/kit';
|
|
3
|
+
import { encodeChooseFactionData, PROFILE_FACTION_PROGRAM_ADDRESS, PLAYER_PROFILE_PROGRAM_ADDRESS, } from '../c4/faction-enrollment.js';
|
|
4
|
+
import { SageSdkError } from '../../client/errors.js';
|
|
5
|
+
export const RENT_ADDRESS = 'SysvarRent111111111111111111111111111111111';
|
|
6
|
+
export const CLOCK_ADDRESS = 'SysvarC1ock11111111111111111111111111111111';
|
|
7
|
+
const SYSVAR_OWNER = 'Sysvar1111111111111111111111111111111111111';
|
|
8
|
+
export function enrollmentFailure(message, address) {
|
|
9
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', message, { address });
|
|
10
|
+
}
|
|
11
|
+
export function readRent(account) {
|
|
12
|
+
if (account.owner !== SYSVAR_OWNER ||
|
|
13
|
+
account.executable ||
|
|
14
|
+
account.data.length !== 17)
|
|
15
|
+
enrollmentFailure('The Rent sysvar has an unexpected owner or layout. Refresh the configured deployment before calculating Profile funding.', account.address);
|
|
16
|
+
const view = new DataView(account.data.buffer, account.data.byteOffset, account.data.byteLength);
|
|
17
|
+
const rate = view.getBigUint64(0, true), threshold = view.getFloat64(8, true);
|
|
18
|
+
if (!Number.isFinite(threshold) || threshold < 0 || view.getUint8(16) > 100)
|
|
19
|
+
enrollmentFailure('The Rent sysvar contains unsupported values. Refresh the deployment or use a supported configuration before planning this action.', account.address);
|
|
20
|
+
return (length) => {
|
|
21
|
+
const base = (BigInt(length) + 128n) * rate;
|
|
22
|
+
const result = Number(base) * threshold;
|
|
23
|
+
if (base > BigInt(Number.MAX_SAFE_INTEGER) ||
|
|
24
|
+
!Number.isFinite(result) ||
|
|
25
|
+
result < 0 ||
|
|
26
|
+
result > Number.MAX_SAFE_INTEGER)
|
|
27
|
+
enrollmentFailure('Profile storage funding exceeds the supported exact calculation range. Use a supported Rent configuration before planning this action.', account.address);
|
|
28
|
+
return BigInt(Math.trunc(result));
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function readClock(account) {
|
|
32
|
+
if (account.owner !== SYSVAR_OWNER ||
|
|
33
|
+
account.executable ||
|
|
34
|
+
account.data.length !== 40)
|
|
35
|
+
enrollmentFailure('The Clock sysvar has an unexpected owner or layout. Refresh chain time before checking Profile key expiry.', account.address);
|
|
36
|
+
return new DataView(account.data.buffer, account.data.byteOffset, account.data.byteLength).getBigInt64(32, true);
|
|
37
|
+
}
|
|
38
|
+
export async function observeEnrollmentAccount(account, describes) {
|
|
39
|
+
return {
|
|
40
|
+
kind: 'account-state',
|
|
41
|
+
address: account.address,
|
|
42
|
+
dataHash: await hashAccountState(account.owner, account.data),
|
|
43
|
+
describes,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function adaptChooseFaction(authorization, target, faction) {
|
|
47
|
+
return {
|
|
48
|
+
programAddress: PROFILE_FACTION_PROGRAM_ADDRESS,
|
|
49
|
+
accounts: [
|
|
50
|
+
{ address: authorization.authority, role: AccountRole.READONLY_SIGNER },
|
|
51
|
+
{ address: authorization.profile, role: AccountRole.WRITABLE },
|
|
52
|
+
{
|
|
53
|
+
address: authorization.certificate ?? PROFILE_FACTION_PROGRAM_ADDRESS,
|
|
54
|
+
role: AccountRole.READONLY,
|
|
55
|
+
},
|
|
56
|
+
{ address: PLAYER_PROFILE_PROGRAM_ADDRESS, role: AccountRole.READONLY },
|
|
57
|
+
{ address: target, role: AccountRole.WRITABLE },
|
|
58
|
+
{
|
|
59
|
+
address: '11111111111111111111111111111111',
|
|
60
|
+
role: AccountRole.READONLY,
|
|
61
|
+
},
|
|
62
|
+
{ address: PLAYER_PROFILE_PROGRAM_ADDRESS, role: AccountRole.READONLY },
|
|
63
|
+
],
|
|
64
|
+
data: encodeChooseFactionData(authorization.keyIndex, faction),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=faction-enrollment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-enrollment.js","sourceRoot":"","sources":["../../../src/internal/planning/faction-enrollment.ts"],"names":[],"mappings":"AAAA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AM,UAAU,kBAAkB,CAChC,aAAgC,EAChC,MAAe,EACf,OAAkB;IAElB,OAAO;QACL,cAAc,EAAE,+BAA+B;QAC/C,QAAQ,EAAE;YACR,EAAE,OAAO,EAAE,aAAa,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,eAAe,EAAE;YACvE,EAAE,OAAO,EAAE,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE;YAC9D;gBACE,OAAO,EAAE,aAAa,CAAC,WAAW,IAAI,+BAA+B;gBACrE,IAAI,EAAE,WAAW,CAAC,QAAQ;aAC3B;YACD,EAAE,OAAO,EAAE,8BAA8B,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE;YACvE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE;YAC/C;gBACE,OAAO,EAAE,kCAA6C;gBACtD,IAAI,EAAE,WAAW,CAAC,QAAQ;aAC3B;YACD,EAAE,OAAO,EAAE,8BAA8B,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE;SACxE;QACD,IAAI,EAAE,uBAAuB,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Address } from '@solana/kit';
|
|
2
|
+
import type { RawAccount } from '../../client/contracts.js';
|
|
3
|
+
import type { PlanPrecondition } from '../../planning/index.js';
|
|
4
|
+
type Identity = {
|
|
5
|
+
readonly game: Address;
|
|
6
|
+
readonly factionId: number;
|
|
7
|
+
};
|
|
8
|
+
/** Shared preparation/execution validation; no balances or fill assumptions. */
|
|
9
|
+
export declare function readTradeTreasury(account: RawAccount, identity: Identity): Promise<Readonly<import("../c4/faction-treasury.js").FactionTreasuryAccountData>>;
|
|
10
|
+
export declare function validateTradeEpochMeter(account: RawAccount, identity: Identity): Promise<void>;
|
|
11
|
+
/** D053 finite comparison. Historical account-state digests do not use this path. */
|
|
12
|
+
export declare function matchesFactionTradeState(account: RawAccount, guard: Extract<PlanPrecondition, {
|
|
13
|
+
kind: 'faction-treasury-buy' | 'faction-treasury-sell' | 'faction-epoch-meter';
|
|
14
|
+
}>): Promise<boolean>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=faction-trade-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-trade-state.d.ts","sourceRoot":"","sources":["../../../src/internal/planning/faction-trade-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAUhE,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAUvE,gFAAgF;AAChF,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,QAAQ,qFAYnB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CASf;AAED,qFAAqF;AACrF,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,OAAO,CACZ,gBAAgB,EAChB;IACE,IAAI,EACA,sBAAsB,GACtB,uBAAuB,GACvB,qBAAqB,CAAC;CAC3B,CACF,GACA,OAAO,CAAC,OAAO,CAAC,CAWlB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SageSdkError } from '../../client/errors.js';
|
|
2
|
+
import { deriveFactionTreasuryAddress, factionTreasuryAccountDefinition, } from '../c4/faction-treasury.js';
|
|
3
|
+
import { decodeTradeEpochMeter, deriveTradeEpochMeterAddress, } from '../c4/faction-epoch-meter.js';
|
|
4
|
+
function invalid(account, role) {
|
|
5
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', `${role} must match its canonical Game/faction identity and supported account layout. Refresh the Market and canonical faction accounts, then prepare a new trade.`, { address: account.address });
|
|
6
|
+
}
|
|
7
|
+
/** Shared preparation/execution validation; no balances or fill assumptions. */
|
|
8
|
+
export async function readTradeTreasury(account, identity) {
|
|
9
|
+
const treasury = factionTreasuryAccountDefinition.decode(account);
|
|
10
|
+
if (account.executable ||
|
|
11
|
+
treasury.game !== identity.game ||
|
|
12
|
+
treasury.factionId !== identity.factionId ||
|
|
13
|
+
account.address !==
|
|
14
|
+
(await deriveFactionTreasuryAddress(identity.game, identity.factionId)))
|
|
15
|
+
invalid(account, 'Faction Treasury');
|
|
16
|
+
return treasury;
|
|
17
|
+
}
|
|
18
|
+
export async function validateTradeEpochMeter(account, identity) {
|
|
19
|
+
const meter = decodeTradeEpochMeter(account);
|
|
20
|
+
if (account.executable ||
|
|
21
|
+
meter.gameId !== identity.game ||
|
|
22
|
+
meter.factionId !== identity.factionId ||
|
|
23
|
+
account.address !== (await deriveTradeEpochMeterAddress(identity)))
|
|
24
|
+
invalid(account, 'Faction Epoch Meter');
|
|
25
|
+
}
|
|
26
|
+
/** D053 finite comparison. Historical account-state digests do not use this path. */
|
|
27
|
+
export async function matchesFactionTradeState(account, guard) {
|
|
28
|
+
if (guard.kind === 'faction-epoch-meter') {
|
|
29
|
+
await validateTradeEpochMeter(account, guard);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const treasury = await readTradeTreasury(account, guard);
|
|
33
|
+
return guard.kind === 'faction-treasury-buy'
|
|
34
|
+
? (treasury.reserves.find((row) => row.cargoId === guard.cargoId)
|
|
35
|
+
?.floorRaw ?? 0n) === guard.floorRaw
|
|
36
|
+
: treasury.atlasOutCapPerEpochRaw === guard.atlasOutCapPerEpochRaw &&
|
|
37
|
+
treasury.epochLengthSeconds === guard.epochLengthSeconds;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=faction-trade-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-trade-state.js","sourceRoot":"","sources":["../../../src/internal/planning/faction-trade-state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAItC,SAAS,OAAO,CAAC,OAAmB,EAAE,IAAY;IAChD,MAAM,IAAI,YAAY,CACpB,4BAA4B,EAC5B,GAAG,IAAI,4JAA4J,EACnK,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAC7B,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAmB,EACnB,QAAkB;IAElB,MAAM,QAAQ,GAAG,gCAAgC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClE,IACE,OAAO,CAAC,UAAU;QAClB,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI;QAC/B,QAAQ,CAAC,SAAS,KAAK,QAAQ,CAAC,SAAS;QACzC,OAAO,CAAC,OAAO;YACb,CAAC,MAAM,4BAA4B,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEzE,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAmB,EACnB,QAAkB;IAElB,MAAM,KAAK,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC7C,IACE,OAAO,CAAC,UAAU;QAClB,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,IAAI;QAC9B,KAAK,CAAC,SAAS,KAAK,QAAQ,CAAC,SAAS;QACtC,OAAO,CAAC,OAAO,KAAK,CAAC,MAAM,4BAA4B,CAAC,QAAQ,CAAC,CAAC;QAElE,OAAO,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;AAC5C,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAmB,EACnB,KAQC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;QACzC,MAAM,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,IAAI,KAAK,sBAAsB;QAC1C,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAAC;YAC7D,EAAE,QAAQ,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,QAAQ;QACxC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,KAAK,KAAK,CAAC,sBAAsB;YAC9D,QAAQ,CAAC,kBAAkB,KAAK,KAAK,CAAC,kBAAkB,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address } from '@solana/kit';
|
|
2
|
+
import type { RawAccount } from '../../client/contracts.js';
|
|
3
|
+
export interface FleetCreationIntent {
|
|
4
|
+
readonly game: Address;
|
|
5
|
+
readonly profile: Address;
|
|
6
|
+
readonly authority: Address;
|
|
7
|
+
readonly system: Address;
|
|
8
|
+
readonly keyIndex: number;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
}
|
|
11
|
+
export interface FleetCreationAccounts {
|
|
12
|
+
readonly game: Address;
|
|
13
|
+
readonly profile: Address;
|
|
14
|
+
readonly authority: Address;
|
|
15
|
+
readonly system: Address;
|
|
16
|
+
readonly character: Address;
|
|
17
|
+
readonly profileFaction: Address;
|
|
18
|
+
readonly starbasePlayer: Address;
|
|
19
|
+
readonly fleet: Address;
|
|
20
|
+
readonly rent: Address;
|
|
21
|
+
readonly clock: Address;
|
|
22
|
+
}
|
|
23
|
+
export declare function validateFleetCreationLabel(label: unknown): asserts label is string;
|
|
24
|
+
export declare function resolveFleetCreation(input: FleetCreationIntent): Promise<FleetCreationAccounts>;
|
|
25
|
+
export declare function validateFleetCreation(input: FleetCreationIntent, resolved: FleetCreationAccounts, accounts: ReadonlyMap<Address, RawAccount | undefined>, maximumProfileDebit?: bigint): Promise<{
|
|
26
|
+
profileDebit: bigint;
|
|
27
|
+
fleetRent: bigint;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=fleet-creation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet-creation.d.ts","sourceRoot":"","sources":["../../../src/internal/planning/fleet-creation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA8B5D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AACD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,MAAM,CAgBzB;AACD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,qBAAqB,CAAC,CAoBhC;AAID,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,mBAAmB,EAC1B,QAAQ,EAAE,qBAAqB,EAC/B,QAAQ,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC,EACtD,mBAAmB,CAAC,EAAE,MAAM,GAC3B,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAgItD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { InvalidActionInputError, SageSdkError } from '../../client/errors.js';
|
|
2
|
+
import { deriveFleetCreationAddress, emptyDockedFleetSize, } from '../c4/fleet-creation.js';
|
|
3
|
+
import { profileAccountDefinition, characterAccountDefinition, findCharacterPda, } from '../c4/identity.js';
|
|
4
|
+
import { profileFactionAccountDefinition, deriveProfileFactionAddress, } from '../c4/profile-faction.js';
|
|
5
|
+
import { starbasePlayerAccountDefinition, deriveStarbasePlayerAddress, } from '../c4/starbase.js';
|
|
6
|
+
import { starSystemAccountDefinition, deriveStarSystemAddress, } from '../c4/world.js';
|
|
7
|
+
import { PROFILE_SCOPE, SAGE_SCOPE } from '../c4/profile-permissions.js';
|
|
8
|
+
import { CLOCK_ADDRESS, RENT_ADDRESS, readClock, readRent, } from './faction-enrollment.js';
|
|
9
|
+
export function validateFleetCreationLabel(label) {
|
|
10
|
+
if (typeof label !== 'string' ||
|
|
11
|
+
label.trim().length === 0 ||
|
|
12
|
+
label.includes('\0') ||
|
|
13
|
+
new TextDecoder('utf-8', { ignoreBOM: true }).decode(new TextEncoder().encode(label)) !== label ||
|
|
14
|
+
new TextEncoder().encode(label).length > 64)
|
|
15
|
+
throw new InvalidActionInputError('options.label', label, 'a nonblank, valid UTF-8 Fleet label of at most 64 bytes without NUL', 'Choose a valid Fleet label. Accepted whitespace is preserved in the canonical Fleet address.');
|
|
16
|
+
}
|
|
17
|
+
export async function resolveFleetCreation(input) {
|
|
18
|
+
const intent = { ...input };
|
|
19
|
+
validateFleetCreationLabel(intent.label);
|
|
20
|
+
const [character, profileFaction, fleet] = await Promise.all([
|
|
21
|
+
findCharacterPda(intent.profile, intent.game),
|
|
22
|
+
deriveProfileFactionAddress(intent.profile),
|
|
23
|
+
deriveFleetCreationAddress(intent.game, intent.profile, intent.label),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
game: intent.game,
|
|
27
|
+
profile: intent.profile,
|
|
28
|
+
authority: intent.authority,
|
|
29
|
+
system: intent.system,
|
|
30
|
+
character,
|
|
31
|
+
profileFaction,
|
|
32
|
+
fleet,
|
|
33
|
+
starbasePlayer: await deriveStarbasePlayerAddress(intent.system, character),
|
|
34
|
+
rent: RENT_ADDRESS,
|
|
35
|
+
clock: CLOCK_ADDRESS,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function fail(address, message) {
|
|
39
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', message, { address });
|
|
40
|
+
}
|
|
41
|
+
export async function validateFleetCreation(input, resolved, accounts, maximumProfileDebit) {
|
|
42
|
+
const intent = { ...input };
|
|
43
|
+
const required = (address, name) => {
|
|
44
|
+
const raw = accounts.get(address);
|
|
45
|
+
if (!raw)
|
|
46
|
+
fail(address, `${name} ${address} is missing. Create or select the required account, then replan Fleet creation.`);
|
|
47
|
+
if (raw.address !== address || raw.executable)
|
|
48
|
+
fail(address, `${name} ${address} has a contradictory address or is executable. Refresh valid account state before creating a Fleet.`);
|
|
49
|
+
return raw;
|
|
50
|
+
};
|
|
51
|
+
const profileRaw = required(resolved.profile, 'Profile');
|
|
52
|
+
const profile = profileAccountDefinition.decode(profileRaw);
|
|
53
|
+
const character = characterAccountDefinition.decode(required(resolved.character, 'Character'));
|
|
54
|
+
const faction = profileFactionAccountDefinition.decode(required(resolved.profileFaction, 'ProfileFaction'));
|
|
55
|
+
const system = starSystemAccountDefinition.decode(required(resolved.system, 'Star System'));
|
|
56
|
+
const player = starbasePlayerAccountDefinition.decode(required(resolved.starbasePlayer, 'StarbasePlayer'));
|
|
57
|
+
if (character.game !== intent.game ||
|
|
58
|
+
character.playerProfile !== intent.profile)
|
|
59
|
+
fail(resolved.character, 'The Character belongs to a different Game or Profile. Refresh the canonical Character and replan Fleet creation.');
|
|
60
|
+
if (faction.profile !== intent.profile)
|
|
61
|
+
fail(resolved.profileFaction, 'The faction membership belongs to a different Profile. Refresh the canonical membership before creating a Fleet.');
|
|
62
|
+
if (system.game !== intent.game ||
|
|
63
|
+
(await deriveStarSystemAddress(system.game, system.systemId)) !==
|
|
64
|
+
intent.system ||
|
|
65
|
+
!system.starbase)
|
|
66
|
+
fail(resolved.system, 'The selected System is not canonical for this Game or has no Starbase. Choose a valid Starbase System and replan.');
|
|
67
|
+
if (player.playerProfile !== intent.profile ||
|
|
68
|
+
player.character !== resolved.character ||
|
|
69
|
+
player.system !== intent.system ||
|
|
70
|
+
player.faction !== faction.faction)
|
|
71
|
+
fail(resolved.starbasePlayer, 'The StarbasePlayer has a different Profile, Character, System or faction relationship. Refresh the canonical StarbasePlayer and replan.');
|
|
72
|
+
if (faction.faction === 'unaligned' ||
|
|
73
|
+
system.starbase.owner !== faction.faction)
|
|
74
|
+
fail(resolved.system, 'This planner supports an existing own-faction StarbasePlayer only. Select an own-faction Starbase; other diplomacy or access routes require separate supported planning.');
|
|
75
|
+
if (character.counts.fleets >= character.modifiers.values.fleetConcurrency)
|
|
76
|
+
fail(resolved.character, 'The Character has no available Fleet slots in its current stored capacity. Free a Fleet slot or refresh changed Character modifiers, then replan.');
|
|
77
|
+
const target = accounts.get(resolved.fleet);
|
|
78
|
+
if (target &&
|
|
79
|
+
(target.address !== resolved.fleet ||
|
|
80
|
+
target.executable ||
|
|
81
|
+
target.owner !== '11111111111111111111111111111111' ||
|
|
82
|
+
target.data.length !== 0))
|
|
83
|
+
fail(resolved.fleet, 'The canonical Fleet target already contains state or has a conflicting owner. Reuse the existing Fleet or choose a different label and replan.');
|
|
84
|
+
const rent = readRent(required(resolved.rent, 'Rent sysvar'));
|
|
85
|
+
const now = readClock(required(resolved.clock, 'Clock sysvar'));
|
|
86
|
+
const fleetRent = rent(emptyDockedFleetSize());
|
|
87
|
+
const balance = target?.lamports ?? 0n;
|
|
88
|
+
const profileDebit = balance < fleetRent ? fleetRent - balance : 0n;
|
|
89
|
+
if (maximumProfileDebit !== undefined && profileDebit > maximumProfileDebit)
|
|
90
|
+
fail(resolved.profile, 'Fleet creation now requires a larger Profile debit than this Plan approved. Replan and inspect the updated rent shortfall before signing.');
|
|
91
|
+
if (profileRaw.lamports < rent(profileRaw.data.length) + profileDebit)
|
|
92
|
+
fail(resolved.profile, 'The Profile lacks the Fleet rent shortfall while preserving its own rent reserve. Fund the Profile or Fleet target explicitly, then replan.');
|
|
93
|
+
const key = profile.keys[intent.keyIndex];
|
|
94
|
+
if (!key || key.address !== intent.authority)
|
|
95
|
+
fail(resolved.profile, 'The selected direct Profile key is absent or belongs to another authority. Select the current key index for this authority and replan.');
|
|
96
|
+
if (key.expiresAtRaw >= 0n && key.expiresAtRaw < now)
|
|
97
|
+
fail(resolved.profile, 'The selected Profile key has expired. Renew it or select a current direct key and replan Fleet creation.');
|
|
98
|
+
const auth = key.scope === PROFILE_SCOPE && (key.permissionsRaw & 1n) !== 0n;
|
|
99
|
+
const manages = key.scope === SAGE_SCOPE && (key.permissionsRaw & (1n << 18n)) !== 0n;
|
|
100
|
+
if (!auth && !manages)
|
|
101
|
+
fail(resolved.profile, 'The selected key cannot manage Fleets. Use a direct Profile AUTH key or a SAGE manageFleet key and replan.');
|
|
102
|
+
if (profileDebit > 0n && !auth && (key.permissionsRaw & (1n << 63n)) === 0n)
|
|
103
|
+
fail(resolved.profile, 'The selected manageFleet key cannot fund the Fleet from the Profile vault. Explicitly prefund the target or choose an authorized vault-funding key, then replan; drainSolVault grants vault withdrawal authority.');
|
|
104
|
+
return { profileDebit, fleetRent };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=fleet-creation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet-creation.js","sourceRoot":"","sources":["../../../src/internal/planning/fleet-creation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACL,aAAa,EACb,YAAY,EACZ,SAAS,EACT,QAAQ,GACT,MAAM,yBAAyB,CAAC;AAqBjC,MAAM,UAAU,0BAA0B,CACxC,KAAc;IAEd,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CACF,QAAQ,CAAC,OAAO,EAChB,wIAAwI,CACzI,CAAC;IACJ,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,IAAI,GAAG,CAAC,YAAY,GAAG,GAAG;QAClD,IAAI,CACF,QAAQ,CAAC,OAAO,EAChB,0GAA0G,CAC3G,CAAC;IACJ,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,KAAK,aAAa,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7E,MAAM,OAAO,GACX,GAAG,CAAC,KAAK,KAAK,UAAU,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACxE,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO;QACnB,IAAI,CACF,QAAQ,CAAC,OAAO,EAChB,4GAA4G,CAC7G,CAAC;IACJ,IAAI,YAAY,GAAG,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE;QACzE,IAAI,CACF,QAAQ,CAAC,OAAO,EAChB,mNAAmN,CACpN,CAAC;IACJ,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ShipAssemblyCatalog } from '../../registry/ships.js';
|
|
2
|
+
import { type Address } from '@solana/kit';
|
|
3
|
+
import type { RawAccount } from '../../client/contracts.js';
|
|
4
|
+
export interface FleetShipAssemblyIntent {
|
|
5
|
+
readonly address: Address;
|
|
6
|
+
readonly game: Address;
|
|
7
|
+
readonly profile: Address;
|
|
8
|
+
readonly authority: Address;
|
|
9
|
+
readonly system: Address;
|
|
10
|
+
readonly keyIndex: number;
|
|
11
|
+
readonly shipId: number;
|
|
12
|
+
readonly amount: bigint;
|
|
13
|
+
}
|
|
14
|
+
export interface FleetShipAssemblyAccounts {
|
|
15
|
+
readonly game: Address;
|
|
16
|
+
readonly profile: Address;
|
|
17
|
+
readonly authority: Address;
|
|
18
|
+
readonly system: Address;
|
|
19
|
+
readonly character: Address;
|
|
20
|
+
readonly profileFaction: Address;
|
|
21
|
+
readonly starbasePlayer: Address;
|
|
22
|
+
readonly fleet: Address;
|
|
23
|
+
readonly rent: Address;
|
|
24
|
+
readonly clock: Address;
|
|
25
|
+
}
|
|
26
|
+
export declare function resolveFleetShipAssembly(input: FleetShipAssemblyIntent): Promise<FleetShipAssemblyAccounts>;
|
|
27
|
+
export declare function validateFleetShipAssembly(input: FleetShipAssemblyIntent, resolved: FleetShipAssemblyAccounts, accounts: ReadonlyMap<Address, RawAccount | undefined>, expected?: {
|
|
28
|
+
readonly configHash: string;
|
|
29
|
+
readonly maximumProfileDebit: bigint;
|
|
30
|
+
}, catalog?: ShipAssemblyCatalog): Promise<{
|
|
31
|
+
profileDebit: bigint;
|
|
32
|
+
fleetRent: bigint;
|
|
33
|
+
configHash: string;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=fleet-ship-assembly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet-ship-assembly.d.ts","sourceRoot":"","sources":["../../../src/internal/planning/fleet-ship-assembly.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA2B5D,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,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
import { fleetShipAssemblySize, isBasicFleetAssemblyShip, } from '../c4/fleet-ship-assembly.js';
|
|
3
|
+
import { decodeGameShipAssemblyCatalog, hashShipAssemblyConfiguration, } from '../../registry/ships.js';
|
|
4
|
+
import { isOffCurveAddress } from '@solana/kit';
|
|
5
|
+
import { SageSdkError } from '../../client/errors.js';
|
|
6
|
+
import { profileAccountDefinition, characterAccountDefinition, findCharacterPda, } from '../c4/identity.js';
|
|
7
|
+
import { profileFactionAccountDefinition, deriveProfileFactionAddress, } from '../c4/profile-faction.js';
|
|
8
|
+
import { starbasePlayerAccountDefinition, deriveStarbasePlayerAddress, } from '../c4/starbase.js';
|
|
9
|
+
import { starSystemAccountDefinition, deriveStarSystemAddress, } from '../c4/world.js';
|
|
10
|
+
import { PROFILE_SCOPE, SAGE_SCOPE } from '../c4/profile-permissions.js';
|
|
11
|
+
import { CLOCK_ADDRESS, RENT_ADDRESS, readClock, readRent, } from './faction-enrollment.js';
|
|
12
|
+
export async function resolveFleetShipAssembly(input) {
|
|
13
|
+
const intent = { ...input };
|
|
14
|
+
const [character, profileFaction] = await Promise.all([
|
|
15
|
+
findCharacterPda(intent.profile, intent.game),
|
|
16
|
+
deriveProfileFactionAddress(intent.profile),
|
|
17
|
+
]);
|
|
18
|
+
return {
|
|
19
|
+
game: intent.game,
|
|
20
|
+
profile: intent.profile,
|
|
21
|
+
authority: intent.authority,
|
|
22
|
+
system: intent.system,
|
|
23
|
+
character,
|
|
24
|
+
profileFaction,
|
|
25
|
+
fleet: intent.address,
|
|
26
|
+
starbasePlayer: await deriveStarbasePlayerAddress(intent.system, character),
|
|
27
|
+
rent: RENT_ADDRESS,
|
|
28
|
+
clock: CLOCK_ADDRESS,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function fail(address, message) {
|
|
32
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', message, { address });
|
|
33
|
+
}
|
|
34
|
+
export async function validateFleetShipAssembly(input, resolved, accounts, expected, catalog) {
|
|
35
|
+
const intent = { ...input };
|
|
36
|
+
if (isOffCurveAddress(intent.authority))
|
|
37
|
+
fail(intent.profile, 'Ship assembly requires an on-curve direct Profile authority. Select a current direct key and replan.');
|
|
38
|
+
const required = (address, name) => {
|
|
39
|
+
const raw = accounts.get(address);
|
|
40
|
+
if (!raw)
|
|
41
|
+
fail(address, `${name} ${address} is missing. Create or select the required account, then replan ship assembly.`);
|
|
42
|
+
if (raw.address !== address || raw.executable)
|
|
43
|
+
fail(address, `${name} ${address} has a contradictory address or is executable. Refresh valid account state before assembling ships.`);
|
|
44
|
+
return raw;
|
|
45
|
+
};
|
|
46
|
+
const profileRaw = required(resolved.profile, 'Profile');
|
|
47
|
+
const profile = profileAccountDefinition.decode(profileRaw);
|
|
48
|
+
const character = characterAccountDefinition.decode(required(resolved.character, 'Character'));
|
|
49
|
+
const faction = profileFactionAccountDefinition.decode(required(resolved.profileFaction, 'ProfileFaction'));
|
|
50
|
+
const system = starSystemAccountDefinition.decode(required(resolved.system, 'Star System'));
|
|
51
|
+
const player = starbasePlayerAccountDefinition.decode(required(resolved.starbasePlayer, 'StarbasePlayer'));
|
|
52
|
+
if (character.game !== intent.game ||
|
|
53
|
+
character.playerProfile !== intent.profile)
|
|
54
|
+
fail(resolved.character, 'The Character belongs to a different Game or Profile. Refresh the canonical Character and replan ship assembly.');
|
|
55
|
+
if (faction.profile !== intent.profile)
|
|
56
|
+
fail(resolved.profileFaction, 'The faction membership belongs to a different Profile. Refresh the canonical membership before assembling ships.');
|
|
57
|
+
if (system.game !== intent.game ||
|
|
58
|
+
(await deriveStarSystemAddress(system.game, system.systemId)) !==
|
|
59
|
+
intent.system ||
|
|
60
|
+
!system.starbase)
|
|
61
|
+
fail(resolved.system, 'The selected System is not canonical for this Game or has no Starbase. Choose a valid Starbase System and replan.');
|
|
62
|
+
if (player.playerProfile !== intent.profile ||
|
|
63
|
+
player.character !== resolved.character ||
|
|
64
|
+
player.system !== intent.system ||
|
|
65
|
+
player.faction !== faction.faction)
|
|
66
|
+
fail(resolved.starbasePlayer, 'The StarbasePlayer has a different Profile, Character, System or faction relationship. Refresh the canonical StarbasePlayer and replan.');
|
|
67
|
+
if (faction.faction === 'unaligned' ||
|
|
68
|
+
system.starbase.owner !== faction.faction)
|
|
69
|
+
fail(resolved.system, 'This planner supports an existing own-faction StarbasePlayer only. Select an own-faction Starbase; other diplomacy or access routes require separate supported planning.');
|
|
70
|
+
if (system.starbase.level !== 'css')
|
|
71
|
+
fail(resolved.system, 'Ship assembly currently supports own-faction CSS Starbases only. Dock at an own-faction CSS Starbase and replan; other access routes need separate support.');
|
|
72
|
+
const fleetRaw = required(resolved.fleet, 'Fleet');
|
|
73
|
+
const fleet = fleetAccountDefinition.decode(fleetRaw);
|
|
74
|
+
if ((await deriveFleetAddress(fleet)) !== intent.address ||
|
|
75
|
+
fleet.game !== intent.game ||
|
|
76
|
+
fleet.ownerProfile !== intent.profile ||
|
|
77
|
+
fleet.faction !== faction.faction ||
|
|
78
|
+
fleet.npcFactionId !== 0)
|
|
79
|
+
fail(resolved.fleet, 'The Fleet has a noncanonical address or different Game, Profile, faction or NPC affiliation. Select a canonical owned player Fleet and replan ship assembly.');
|
|
80
|
+
if (fleet.state.kind !== 'docked' || fleet.state.system !== intent.system)
|
|
81
|
+
fail(resolved.fleet, 'Ship assembly requires the Fleet to remain Docked at the selected System. Dock at an own-faction CSS Starbase and replan.');
|
|
82
|
+
const gameRaw = required(resolved.game, 'Game');
|
|
83
|
+
const definitions = catalog ?? decodeGameShipAssemblyCatalog(gameRaw);
|
|
84
|
+
if (fleet.shipDefinitionsSeqId !== definitions.sequenceId)
|
|
85
|
+
fail(resolved.fleet, 'This SDK route supports current ship-definition sequences only. Refresh the Fleet definitions through a supported game client, then replan; stale-sequence refresh behavior remains chain-authoritative.');
|
|
86
|
+
const selected = definitions.rows.find((row) => row.id === intent.shipId);
|
|
87
|
+
if (!isBasicFleetAssemblyShip(selected))
|
|
88
|
+
fail(resolved.game, 'The selected ship ID is unresolved or is not a requirements-free XXS configuration. Select a defined requirements-free XXS configuration; research, component and other size routes need separate support.');
|
|
89
|
+
// Every validated stored maxShipSize enum permits XXS, the smallest pinned size.
|
|
90
|
+
let quantity = 0n;
|
|
91
|
+
for (const entry of fleet.fleetShips) {
|
|
92
|
+
if (entry.quantity === 0n)
|
|
93
|
+
continue;
|
|
94
|
+
if (!isBasicFleetAssemblyShip(definitions.rows.find((row) => row.id === entry.shipId)))
|
|
95
|
+
fail(resolved.fleet, 'The Fleet already contains a positive unresolved or unsupported ship configuration. Use a Fleet containing only resolved requirements-free XXS ships; mixed-size capacity needs separate support.');
|
|
96
|
+
quantity += entry.quantity;
|
|
97
|
+
}
|
|
98
|
+
const current = fleet.fleetShips.find((entry) => entry.shipId === intent.shipId)
|
|
99
|
+
?.quantity ?? 0n;
|
|
100
|
+
if (current + intent.amount > 18446744073709551615n)
|
|
101
|
+
fail(resolved.fleet, 'The resulting Fleet ship quantity exceeds the stored u64 limit. Select a smaller valid quantity and replan.');
|
|
102
|
+
if (quantity + intent.amount > BigInt(character.modifiers.values.fleetSize))
|
|
103
|
+
fail(resolved.character, 'The requested ships exceed the Character stored Fleet-size capacity. Reduce the amount or refresh changed Character modifiers, then replan.');
|
|
104
|
+
if (quantity + intent.amount > BigInt(definitions.maxFleetSize))
|
|
105
|
+
fail(resolved.game, 'The requested ships exceed the Game ship-assembly capacity. Reduce the resulting Fleet composition to fit the current Game limit, then replan; a larger Character allowance does not override it.');
|
|
106
|
+
const entitlement = player.shipsInEscrow.find((entry) => entry.shipId === intent.shipId)
|
|
107
|
+
?.quantityRaw ?? 0n;
|
|
108
|
+
if (entitlement < intent.amount)
|
|
109
|
+
fail(resolved.starbasePlayer, 'The StarbasePlayer has insufficient entitlement for this exact ship configuration. Explicitly import that configuration or reduce the amount, then replan.');
|
|
110
|
+
const configHash = await hashShipAssemblyConfiguration(definitions, selected);
|
|
111
|
+
if (expected && expected.configHash !== configHash)
|
|
112
|
+
fail(resolved.game, 'The selected ship configuration has changed. Replan and inspect its current configuration before signing.');
|
|
113
|
+
const rent = readRent(required(resolved.rent, 'Rent sysvar'));
|
|
114
|
+
const now = readClock(required(resolved.clock, 'Clock sysvar'));
|
|
115
|
+
const fleetRent = rent(fleetShipAssemblySize(fleetRaw, intent.shipId, intent.amount));
|
|
116
|
+
const balance = fleetRaw.lamports;
|
|
117
|
+
const profileDebit = balance < fleetRent ? fleetRent - balance : 0n;
|
|
118
|
+
if (expected !== undefined && profileDebit > expected.maximumProfileDebit)
|
|
119
|
+
fail(resolved.profile, 'Ship assembly now requires a larger Profile debit than this Plan approved. Replan and inspect the updated rent shortfall before signing.');
|
|
120
|
+
if (profileRaw.lamports < rent(profileRaw.data.length) + profileDebit)
|
|
121
|
+
fail(resolved.profile, 'The Profile lacks the Fleet rent shortfall while preserving its own rent reserve. Fund the Profile or Fleet target explicitly, then replan.');
|
|
122
|
+
const key = profile.keys[intent.keyIndex];
|
|
123
|
+
if (!key || key.address !== intent.authority)
|
|
124
|
+
fail(resolved.profile, 'The selected direct Profile key is absent or belongs to another authority. Select the current key index for this authority and replan.');
|
|
125
|
+
if (key.expiresAtRaw >= 0n && key.expiresAtRaw < now)
|
|
126
|
+
fail(resolved.profile, 'The selected Profile key has expired. Renew it or select a current direct key and replan ship assembly.');
|
|
127
|
+
const auth = key.scope === PROFILE_SCOPE && (key.permissionsRaw & 1n) !== 0n;
|
|
128
|
+
const manages = key.scope === SAGE_SCOPE && (key.permissionsRaw & (1n << 18n)) !== 0n;
|
|
129
|
+
if (!auth && !manages)
|
|
130
|
+
fail(resolved.profile, 'The selected key cannot manage Fleets. Use a direct Profile AUTH key or a SAGE manageFleet key and replan.');
|
|
131
|
+
if (profileDebit > 0n && !auth && (key.permissionsRaw & (1n << 63n)) === 0n)
|
|
132
|
+
fail(resolved.profile, 'The selected manageFleet key cannot fund the Fleet from the Profile vault. Explicitly prefund the target or choose an authorized vault-funding key, then replan; drainSolVault grants vault withdrawal authority.');
|
|
133
|
+
return { profileDebit, fleetRent, configHash };
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=fleet-ship-assembly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet-ship-assembly.js","sourceRoot":"","sources":["../../../src/internal/planning/fleet-ship-assembly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,GAE9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAgB,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACL,aAAa,EACb,YAAY,EACZ,SAAS,EACT,QAAQ,GACT,MAAM,yBAAyB,CAAC;AAuBjC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,KAA8B;IAE9B,MAAM,MAAM,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5B,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpD,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;QAC7C,2BAA2B,CAAC,MAAM,CA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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Address } from '@solana/kit';
|
|
2
|
+
import type { RawAccount } from '../../client/contracts.js';
|
|
3
|
+
export declare const ORIGINAL_TOKEN_PROGRAM: Address;
|
|
4
|
+
export declare const ATA_PROGRAM: Address;
|
|
5
|
+
export declare const SYSTEM_PROGRAM: Address;
|
|
6
|
+
export declare function failShipImport(message: string, address: Address): never;
|
|
7
|
+
export declare function deriveShipTokenAddress(owner: Address, mint: Address): Promise<Address>;
|
|
8
|
+
export declare function validateShipMint(account: RawAccount): void;
|
|
9
|
+
export declare function validateShipToken(account: RawAccount, mint: Address, owner: Address): bigint;
|
|
10
|
+
//# sourceMappingURL=ship-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ship-token.d.ts","sourceRoot":"","sources":["../../../src/internal/planning/ship-token.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,eAAO,MAAM,sBAAsB,EACgB,OAAO,CAAC;AAC3D,eAAO,MAAM,WAAW,EAC4B,OAAO,CAAC;AAC5D,eAAO,MAAM,cAAc,EAAyC,OAAO,CAAC;AAC5E,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,CAMvE;AACD,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAYlB;AAwBD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAM1D;AACD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GACb,MAAM,CAcR"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { validateTokenMint } from './token-mint.js';
|
|
2
|
+
import { getAddressDecoder, getAddressEncoder, getProgramDerivedAddress, } from '@solana/kit';
|
|
3
|
+
import { SageSdkError } from '../../client/errors.js';
|
|
4
|
+
export const ORIGINAL_TOKEN_PROGRAM = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
|
|
5
|
+
export const ATA_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
6
|
+
export const SYSTEM_PROGRAM = '11111111111111111111111111111111';
|
|
7
|
+
export function failShipImport(message, address) {
|
|
8
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', `${message} Refresh the relevant accounts and prepare a new ship import Plan.`, { address });
|
|
9
|
+
}
|
|
10
|
+
export async function deriveShipTokenAddress(owner, mint) {
|
|
11
|
+
const encoder = getAddressEncoder();
|
|
12
|
+
return (await getProgramDerivedAddress({
|
|
13
|
+
programAddress: ATA_PROGRAM,
|
|
14
|
+
seeds: [
|
|
15
|
+
encoder.encode(owner),
|
|
16
|
+
encoder.encode(ORIGINAL_TOKEN_PROGRAM),
|
|
17
|
+
encoder.encode(mint),
|
|
18
|
+
],
|
|
19
|
+
}))[0];
|
|
20
|
+
}
|
|
21
|
+
function bytes(account, length) {
|
|
22
|
+
if (account.executable ||
|
|
23
|
+
account.owner !== ORIGINAL_TOKEN_PROGRAM ||
|
|
24
|
+
account.data.length !== length)
|
|
25
|
+
failShipImport(`Account ${account.address} must be an original Token account with exactly ${length} bytes; Token-2022 is unsupported.`, account.address);
|
|
26
|
+
return new DataView(account.data.buffer, account.data.byteOffset, account.data.byteLength);
|
|
27
|
+
}
|
|
28
|
+
function option(view, offset, account) {
|
|
29
|
+
if (view.getUint32(offset, true) > 1)
|
|
30
|
+
failShipImport('The Token account has malformed optional fields.', account.address);
|
|
31
|
+
}
|
|
32
|
+
export function validateShipMint(account) {
|
|
33
|
+
if (validateTokenMint(account) !== 0)
|
|
34
|
+
failShipImport('Ship import requires an initialized zero-decimal mint so each token is one ship.', account.address);
|
|
35
|
+
}
|
|
36
|
+
export function validateShipToken(account, mint, owner) {
|
|
37
|
+
const view = bytes(account, 165);
|
|
38
|
+
for (const offset of [72, 109, 129])
|
|
39
|
+
option(view, offset, account);
|
|
40
|
+
const decoder = getAddressDecoder();
|
|
41
|
+
if (view.getUint8(108) !== 1 ||
|
|
42
|
+
decoder.decode(account.data.subarray(0, 32)) !== mint ||
|
|
43
|
+
decoder.decode(account.data.subarray(32, 64)) !== owner)
|
|
44
|
+
failShipImport(`The token account must be initialized, unfrozen and hold ship mint ${mint} under authority ${owner}. Delegated token spending is unsupported.`, account.address);
|
|
45
|
+
return view.getBigUint64(64, true);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=ship-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ship-token.js","sourceRoot":"","sources":["../../../src/internal/planning/ship-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAEzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GACjC,6CAAwD,CAAC;AAC3D,MAAM,CAAC,MAAM,WAAW,GACtB,8CAAyD,CAAC;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAG,kCAA6C,CAAC;AAC5E,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,OAAgB;IAC9D,MAAM,IAAI,YAAY,CACpB,4BAA4B,EAC5B,GAAG,OAAO,oEAAoE,EAC9E,EAAE,OAAO,EAAE,CACZ,CAAC;AACJ,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAAc,EACd,IAAa;IAEb,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,OAAO,CACL,MAAM,wBAAw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AC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,IACE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;QACxB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI;QACrD,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK;QAEvD,cAAc,CACZ,sEAAsE,IAAI,oBAAoB,KAAK,4CAA4C,EAC/I,OAAO,CAAC,OAAO,CAChB,CAAC;IACJ,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-mint.d.ts","sourceRoot":"","sources":["../../../src/internal/planning/token-mint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG5D,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CA2B7D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SageSdkError } from '../../client/errors.js';
|
|
2
|
+
/** Validate the finite original Token Mint facts used by wallet transfers. */
|
|
3
|
+
export function validateTokenMint(account) {
|
|
4
|
+
if (account.executable ||
|
|
5
|
+
account.owner !== 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' ||
|
|
6
|
+
account.data.length !== 82)
|
|
7
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', `Mint ${account.address} must be a non-executable original Token Mint with exactly 82 bytes. Refresh the mint or select a supported original Token mint; Token-2022 is unsupported.`, { address: account.address });
|
|
8
|
+
const view = new DataView(account.data.buffer, account.data.byteOffset, account.data.byteLength);
|
|
9
|
+
if (view.getUint32(0, true) > 1 ||
|
|
10
|
+
view.getUint32(46, true) > 1 ||
|
|
11
|
+
view.getUint8(45) !== 1)
|
|
12
|
+
throw new SageSdkError('ACTION_PRECONDITION_FAILED', `Mint ${account.address} must be initialized with valid optional authority fields. Refresh the mint and prepare a new Plan.`, { address: account.address });
|
|
13
|
+
return view.getUint8(44);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=token-mint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-mint.js","sourceRoot":"","sources":["../../../src/internal/planning/token-mint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,OAAmB;IACnD,IACE,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,KAAK,KAAK,6CAA6C;QAC/D,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE;QAE1B,MAAM,IAAI,YAAY,CACpB,4BAA4B,EAC5B,QAAQ,OAAO,CAAC,OAAO,6JAA6J,EACpL,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAC7B,CAAC;IACJ,MAAM,IAAI,GAAG,IAAI,QAAQ,CACvB,OAAO,CAAC,IAAI,CAAC,MAAM,EACnB,OAAO,CAAC,IAAI,CAAC,UAAU,EACvB,OAAO,CAAC,IAAI,CAAC,UAAU,CACxB,CAAC;IACF,IACE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC;QAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC;QAEvB,MAAM,IAAI,YAAY,CACpB,4BAA4B,EAC5B,QAAQ,OAAO,CAAC,OAAO,qGAAqG,EAC5H,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAC7B,CAAC;IACJ,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Address } from '@solana/kit';
|
|
2
|
+
import { type PlanAuthorization, type AddressOnlyInstruction } from './authorization-adapter.js';
|
|
3
|
+
/** Address-only adapter for one directional Faction Market trade. */
|
|
4
|
+
export declare function adaptTradeFactionMarketInstruction(input: {
|
|
5
|
+
readonly authorization: PlanAuthorization;
|
|
6
|
+
readonly character: Address;
|
|
7
|
+
readonly game: Address;
|
|
8
|
+
readonly system: Address;
|
|
9
|
+
readonly starbasePlayer: Address;
|
|
10
|
+
readonly fleet: Address;
|
|
11
|
+
readonly factionMarket: Address;
|
|
12
|
+
readonly treasury: Address;
|
|
13
|
+
readonly factionStanding?: Address;
|
|
14
|
+
readonly factionConfig?: Address;
|
|
15
|
+
readonly factionEpochMeter?: Address;
|
|
16
|
+
readonly offerIndex: number;
|
|
17
|
+
readonly quantity: bigint;
|
|
18
|
+
readonly playerBuys: boolean;
|
|
19
|
+
}): AddressOnlyInstruction;
|
|
20
|
+
//# sourceMappingURL=trade-faction-market.d.ts.map
|