@aephia/atlas-kit 0.6.0-next.106 → 0.6.0-next.108
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/dist/cargo/actions/deposit.d.ts.map +1 -1
- package/dist/cargo/actions/deposit.js +22 -125
- package/dist/cargo/actions/deposit.js.map +1 -1
- package/dist/cargo/actions/wallet-context.d.ts +51 -2
- package/dist/cargo/actions/wallet-context.d.ts.map +1 -1
- package/dist/cargo/actions/wallet-context.js +125 -2
- package/dist/cargo/actions/wallet-context.js.map +1 -1
- package/dist/cargo/actions/wallet-token.d.ts +1 -6
- package/dist/cargo/actions/wallet-token.d.ts.map +1 -1
- package/dist/cargo/actions/wallet-token.js +0 -45
- 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 +35 -162
- package/dist/cargo/actions/withdrawal.js.map +1 -1
- package/dist/claim-stakes/actions/index.d.ts.map +1 -1
- package/dist/claim-stakes/actions/index.js +2 -11
- package/dist/claim-stakes/actions/index.js.map +1 -1
- package/dist/crafting/actions/index.d.ts.map +1 -1
- package/dist/crafting/actions/index.js +5 -11
- package/dist/crafting/actions/index.js.map +1 -1
- package/dist/fleets/actions/ship-import.d.ts.map +1 -1
- package/dist/fleets/actions/ship-import.js +31 -77
- package/dist/fleets/actions/ship-import.js.map +1 -1
- package/dist/internal/planning/original-token.d.ts +34 -0
- package/dist/internal/planning/original-token.d.ts.map +1 -0
- package/dist/internal/planning/original-token.js +98 -0
- package/dist/internal/planning/original-token.js.map +1 -0
- package/dist/internal/planning/ship-token.d.ts +1 -5
- package/dist/internal/planning/ship-token.d.ts.map +1 -1
- package/dist/internal/planning/ship-token.js +0 -36
- package/dist/internal/planning/ship-token.js.map +1 -1
- package/dist/internal/planning/starbase-player-owner.d.ts +21 -0
- package/dist/internal/planning/starbase-player-owner.d.ts.map +1 -0
- package/dist/internal/planning/starbase-player-owner.js +17 -0
- package/dist/internal/planning/starbase-player-owner.js.map +1 -0
- package/dist/internal/planning/wallet-starbase.d.ts +34 -0
- package/dist/internal/planning/wallet-starbase.d.ts.map +1 -0
- package/dist/internal/planning/wallet-starbase.js +39 -0
- package/dist/internal/planning/wallet-starbase.js.map +1 -0
- package/dist/markets/actions/index.d.ts.map +1 -1
- package/dist/markets/actions/index.js +91 -130
- package/dist/markets/actions/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/deposit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,kDAAkD,CAAC;AAO1D,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,IAAI,CAAC,CAqHf"}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getAddressEncoder, getProgramDerivedAddress, isOffCurveAddress, } from '@solana/kit';
|
|
4
|
-
import { InvalidActionInputError } from '../../client/errors.js';
|
|
5
|
-
import { readContextRawAccounts } from '../../client/reconciliation.js';
|
|
6
|
-
import { SAGE_PROGRAM_ADDRESS } from '../../internal/c4/runtime-bindings.js';
|
|
7
|
-
import { profileAccountDefinition } from '../../internal/c4/identity.js';
|
|
8
|
-
import { characterAccountDefinition, findCharacterPda, } from '../../internal/c4/character.js';
|
|
9
|
-
import { deriveStarbasePlayerAddress, starbasePlayerAccountDefinition, } from '../../internal/c4/starbase.js';
|
|
10
|
-
import { starSystemAccountDefinition, deriveStarSystemAddress, } from '../../internal/c4/world.js';
|
|
1
|
+
import { observeWalletAccount, readWalletCargo, requireWalletAccount, resolveWalletCargo, validateWalletCargoAmount, walletCargoGuards, } from './wallet-context.js';
|
|
2
|
+
import { isOffCurveAddress } from '@solana/kit';
|
|
11
3
|
import { requireGameAddress } from '../../internal/game-context.js';
|
|
12
4
|
import { adaptDepositCargoToGameInstruction, validatePlanAuthorization, } from '../../internal/planning/authorization-adapter.js';
|
|
5
|
+
import { TOKEN_TRANSFER_DISCLOSURE, deriveAssociatedTokenAddress, isTokenMultisig, readTokenAccount, } from '../../internal/planning/original-token.js';
|
|
13
6
|
import { createPlan } from '../../planning/index.js';
|
|
14
|
-
import {
|
|
15
|
-
import { deriveWalletTokenAddress, failWalletCargo, validateWalletMint, validateWalletToken, } from './wallet-token.js';
|
|
7
|
+
import { failWalletCargo } from './wallet-token.js';
|
|
16
8
|
/** Plans a wallet-to-game cargo deposit without signing, sending, or creating accounts.
|
|
17
9
|
* Amount is exact raw token units, independent of mint display decimals. Refresh
|
|
18
10
|
* the loaded Starbase before planning; execution checks the retained guards.
|
|
@@ -34,141 +26,46 @@ import { deriveWalletTokenAddress, failWalletCargo, validateWalletMint, validate
|
|
|
34
26
|
*/
|
|
35
27
|
export async function planDepositCargoToGame(ctx, starbase, options) {
|
|
36
28
|
validatePlanAuthorization(options.authorization);
|
|
37
|
-
|
|
38
|
-
options.amount <= 0n ||
|
|
39
|
-
options.amount > 18446744073709551615n) {
|
|
40
|
-
throw new InvalidActionInputError('amount', options.amount, 'a positive bigint no greater than u64 maximum', 'Supply an exact raw token amount as bigint.');
|
|
41
|
-
}
|
|
42
|
-
if (!Number.isSafeInteger(options.cargoId) ||
|
|
43
|
-
options.cargoId < 0 ||
|
|
44
|
-
options.cargoId > 65535) {
|
|
45
|
-
throw new InvalidActionInputError('cargoId', options.cargoId, 'an unsigned u16 cargo ID', 'Choose an existing cargo definition ID.');
|
|
46
|
-
}
|
|
29
|
+
validateWalletCargoAmount(options.amount, options.cargoId);
|
|
47
30
|
if (isOffCurveAddress(options.owner))
|
|
48
31
|
failWalletCargo('The token owner must be a directly signing wallet; program authorities are unsupported.', options.owner);
|
|
49
32
|
const game = requireGameAddress(ctx);
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
if (starbase.kind !== 'starbasePlayer' ||
|
|
53
|
-
starbase.address !== player ||
|
|
54
|
-
starbase.playerProfile.address !== options.authorization.profile ||
|
|
55
|
-
starbase.character.address !== character) {
|
|
56
|
-
failWalletCargo('The loaded Starbase must be the canonical registration for the authorized Profile and Character.', starbase.address);
|
|
57
|
-
}
|
|
58
|
-
const config = await readFreshGameCargoBytesConfiguration(ctx, options.cargoId);
|
|
59
|
-
const [canonicalCache, canonicalCacheBump] = await getProgramDerivedAddress({
|
|
60
|
-
programAddress: SAGE_PROGRAM_ADDRESS,
|
|
61
|
-
seeds: [
|
|
62
|
-
new TextEncoder().encode('CargoDefinitionsCache'),
|
|
63
|
-
getAddressEncoder().encode(game),
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
|
-
if (config.cache !== canonicalCache)
|
|
67
|
-
failWalletCargo('The configured cargo cache does not match the canonical Game cargo-cache PDA.', config.cache);
|
|
33
|
+
const { profile } = options.authorization;
|
|
34
|
+
const cargo = await resolveWalletCargo(ctx, starbase, profile, options.cargoId, game);
|
|
68
35
|
const source = options.source ??
|
|
69
|
-
(await
|
|
70
|
-
const
|
|
71
|
-
const addresses = [
|
|
72
|
-
options.authorization.profile,
|
|
73
|
-
character,
|
|
74
|
-
player,
|
|
75
|
-
starbase.system.address,
|
|
76
|
-
config.cache,
|
|
77
|
-
config.cargo.mint,
|
|
36
|
+
(await deriveAssociatedTokenAddress(options.owner, cargo.mint));
|
|
37
|
+
const { characterRaw, decimals, extraAccounts: [sourceCandidate, ownerAccount], playerRaw, profileRaw, systemGuard, } = await readWalletCargo(ctx, cargo, profile, game, 'deposit', [
|
|
78
38
|
source,
|
|
79
|
-
destination,
|
|
80
|
-
];
|
|
81
|
-
const candidates = await readContextRawAccounts(ctx, [
|
|
82
|
-
...addresses,
|
|
83
39
|
options.owner,
|
|
84
40
|
]);
|
|
85
|
-
const ownerAccount = candidates[addresses.length];
|
|
86
41
|
// Account program ownership does not determine whether an on-curve address
|
|
87
42
|
// can sign. Only the Token programs' explicit 355-byte multisig authority
|
|
88
43
|
// layout requires additional signer semantics outside this planner.
|
|
89
|
-
if (ownerAccount
|
|
90
|
-
ownerAccount.data.length === 355 &&
|
|
91
|
-
(ownerAccount.owner ===
|
|
92
|
-
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' ||
|
|
93
|
-
ownerAccount.owner ===
|
|
94
|
-
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb')) {
|
|
44
|
+
if (isTokenMultisig(ownerAccount))
|
|
95
45
|
failWalletCargo('The source token owner is a Token multisig authority, which this single-owner deposit planner does not support.', options.owner);
|
|
96
|
-
|
|
97
|
-
const accounts = addresses.map((address, index) => {
|
|
98
|
-
const account = candidates[index];
|
|
99
|
-
if (!account)
|
|
100
|
-
failWalletCargo(`Required deposit account ${address} is missing or the provider returned a different address. Register the player or create the required token account separately.`, address);
|
|
101
|
-
return account;
|
|
102
|
-
});
|
|
103
|
-
const [profileRaw, characterRaw, playerRaw, systemRaw, cacheRaw, mintRaw, sourceRaw, vaultRaw,] = accounts;
|
|
104
|
-
profileAccountDefinition.decode(profileRaw);
|
|
105
|
-
const characterData = characterAccountDefinition.decode(characterRaw);
|
|
106
|
-
const playerData = starbasePlayerAccountDefinition.decode(playerRaw);
|
|
107
|
-
const systemData = starSystemAccountDefinition.decode(systemRaw);
|
|
108
|
-
if (characterData.game !== game ||
|
|
109
|
-
characterData.playerProfile !== options.authorization.profile ||
|
|
110
|
-
playerData.playerProfile !== options.authorization.profile ||
|
|
111
|
-
playerData.character !== character ||
|
|
112
|
-
playerData.system !== starbase.system.address ||
|
|
113
|
-
systemData.game !== game ||
|
|
114
|
-
(await deriveStarSystemAddress(game, systemData.systemId)) !==
|
|
115
|
-
starbase.system.address) {
|
|
116
|
-
failWalletCargo('Fresh Character, player Starbase, and System must belong to the configured Game and authorized Profile.', player);
|
|
117
|
-
}
|
|
118
|
-
const systemGuard = {
|
|
119
|
-
kind: 'starbase-system',
|
|
120
|
-
address: systemRaw.address,
|
|
121
|
-
game,
|
|
122
|
-
starbaseSequenceId: systemData.sequenceId,
|
|
123
|
-
requireCss: true,
|
|
124
|
-
describes: 'The canonical Star System retains its active Starbase and generation as a Central Space Station; unrelated shared activity may change.',
|
|
125
|
-
};
|
|
126
|
-
await validateStarbaseSystem(systemRaw, systemGuard);
|
|
127
|
-
validateWalletCargoCache(cacheRaw, game, canonicalCacheBump);
|
|
128
|
-
const decimals = validateWalletMint(mintRaw);
|
|
129
|
-
const balance = validateWalletToken(sourceRaw, config.cargo.mint, options.owner);
|
|
130
|
-
validateWalletToken(vaultRaw, config.cargo.mint, config.cache);
|
|
46
|
+
const balance = readTokenAccount(requireWalletAccount(sourceCandidate, source, 'deposit'), cargo.mint, options.owner, failWalletCargo);
|
|
131
47
|
if (balance < options.amount)
|
|
132
48
|
failWalletCargo(`Source balance ${String(balance)} raw units is below requested ${String(options.amount)}. Reduce the amount.`, source);
|
|
133
|
-
const describes = `Deposit ${String(options.amount)} raw units of cargo ${String(options.cargoId)} (mint ${
|
|
49
|
+
const describes = `Deposit ${String(options.amount)} raw units of cargo ${String(options.cargoId)} (mint ${cargo.mint}, ${String(decimals)} display decimals) from token account ${source} to Game vault ${cargo.vault}, for player Starbase ${cargo.player}; the program determines the resulting game inventory credit. Profile authority ${options.authorization.authority} and token owner ${options.owner} authorize the deposit. Network fees are paid separately by the execution fee payer. Permissions, access gates, credit conversion, and final balances remain chain-authoritative; simulate before signing. ${TOKEN_TRANSFER_DISCLOSURE}${ownerAccount ? '' : ' An absent source wallet may receive native funding as an empty, non-executable System account.'}`;
|
|
134
50
|
return createPlan({
|
|
135
51
|
kind: 'cargo.wallet-deposit',
|
|
136
52
|
summary: describes,
|
|
137
53
|
preconditions: [
|
|
138
54
|
systemGuard,
|
|
139
|
-
|
|
140
|
-
kind: 'token-mint',
|
|
141
|
-
address: mintRaw.address,
|
|
142
|
-
decimals,
|
|
143
|
-
describes: `Mint ${mintRaw.address} remains a valid initialized original Token Mint with unchanged decimals; supply and authorities may change.`,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
kind: 'game-cargo-bytes-config',
|
|
147
|
-
address: game,
|
|
148
|
-
cargoId: options.cargoId,
|
|
149
|
-
configHash: config.configHash,
|
|
150
|
-
describes: 'The selected cargo’s full encoded configuration, including its stored name, and cache identity remain unchanged; unrelated Game changes are allowed.',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
kind: 'cargo-cache',
|
|
154
|
-
address: config.cache,
|
|
155
|
-
game,
|
|
156
|
-
bump: canonicalCacheBump,
|
|
157
|
-
describes: 'The canonical cargo cache retains valid Game identity and layout; counters may change.',
|
|
158
|
-
},
|
|
55
|
+
...walletCargoGuards(cargo, options.cargoId, game, decimals),
|
|
159
56
|
{
|
|
160
57
|
kind: 'token-account',
|
|
161
58
|
address: source,
|
|
162
|
-
mint:
|
|
59
|
+
mint: cargo.mint,
|
|
163
60
|
owner: options.owner,
|
|
164
61
|
minimumBalance: options.amount,
|
|
165
62
|
describes: 'The existing source remains an initialized original Token account with sufficient raw tokens.',
|
|
166
63
|
},
|
|
167
64
|
{
|
|
168
65
|
kind: 'token-account',
|
|
169
|
-
address:
|
|
170
|
-
mint:
|
|
171
|
-
owner:
|
|
66
|
+
address: cargo.vault,
|
|
67
|
+
mint: cargo.mint,
|
|
68
|
+
owner: cargo.cache,
|
|
172
69
|
minimumBalance: 0n,
|
|
173
70
|
describes: 'The existing shared vault remains a valid original Token destination; balance changes are allowed.',
|
|
174
71
|
},
|
|
@@ -196,13 +93,13 @@ export async function planDepositCargoToGame(ctx, starbase, options) {
|
|
|
196
93
|
instruction: adaptDepositCargoToGameInstruction({
|
|
197
94
|
authorization: options.authorization,
|
|
198
95
|
owner: options.owner,
|
|
199
|
-
systemAndStarbasePlayerSystem:
|
|
200
|
-
systemAndStarbasePlayerStarbasePlayer: player,
|
|
201
|
-
character,
|
|
96
|
+
systemAndStarbasePlayerSystem: cargo.system,
|
|
97
|
+
systemAndStarbasePlayerStarbasePlayer: cargo.player,
|
|
98
|
+
character: cargo.character,
|
|
202
99
|
game,
|
|
203
|
-
cargoCache:
|
|
100
|
+
cargoCache: cargo.cache,
|
|
204
101
|
source,
|
|
205
|
-
destination,
|
|
102
|
+
destination: cargo.vault,
|
|
206
103
|
amount: options.amount,
|
|
207
104
|
}),
|
|
208
105
|
signers: [...new Set([options.authorization.authority, options.owner])],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.js","sourceRoot":"","sources":["../../../src/cargo/actions/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"deposit.js","sourceRoot":"","sources":["../../../src/cargo/actions/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,G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AS;oBAC1B,IAAI;oBACJ,UAAU,EAAE,KAAK,CAAC,KAAK;oBACvB,MAAM;oBACN,WAAW,EAAE,KAAK,CAAC,KAAK;oBACxB,MAAM,EAAE,OAAO,CAAC,MAAM;iBACvB,CAAC;gBACF,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;aACxE;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address } from '@solana/kit';
|
|
2
|
-
import type { RawAccount } from '../../client/contracts.js';
|
|
2
|
+
import type { RawAccount, SageContext } from '../../client/contracts.js';
|
|
3
3
|
import type { EntityRef } from '../../client/refs.js';
|
|
4
4
|
import type { PlanPrecondition } from '../../planning/index.js';
|
|
5
5
|
export interface StarbasePlayerIntent {
|
|
@@ -10,5 +10,54 @@ export interface StarbasePlayerIntent {
|
|
|
10
10
|
readonly character: EntityRef<'character'>;
|
|
11
11
|
}
|
|
12
12
|
export declare function observeWalletAccount(account: RawAccount, role?: string): Promise<PlanPrecondition>;
|
|
13
|
-
|
|
13
|
+
/** Requires an exact raw u64 amount and a u16 cargo id. */
|
|
14
|
+
export declare function validateWalletCargoAmount(amount: unknown, cargoId: unknown): void;
|
|
15
|
+
/** Pre-read facts shared by wallet deposits and withdrawals: the authorization
|
|
16
|
+
* Profile's canonical Starbase Player, the fresh cargo configuration, and the
|
|
17
|
+
* canonical Game cargo cache and its shared vault for the cargo mint. */
|
|
18
|
+
export declare function resolveWalletCargo(ctx: SageContext, starbase: StarbasePlayerIntent, profile: Address, cargoId: number, game: Address): Promise<{
|
|
19
|
+
bump: import("@solana/kit").ProgramDerivedAddressBump;
|
|
20
|
+
cache: Address<string>;
|
|
21
|
+
character: Address;
|
|
22
|
+
config: Readonly<{
|
|
23
|
+
configHash: string;
|
|
24
|
+
rawAccount: RawAccount;
|
|
25
|
+
cargo: import("@staratlas/dev-sage").CargoType;
|
|
26
|
+
cache: import("../../client/contracts.js").Address;
|
|
27
|
+
sequenceId: number;
|
|
28
|
+
}>;
|
|
29
|
+
mint: Address;
|
|
30
|
+
player: Address;
|
|
31
|
+
system: import("../../client/contracts.js").Address;
|
|
32
|
+
vault: Address;
|
|
33
|
+
}>;
|
|
34
|
+
type WalletCargo = Awaited<ReturnType<typeof resolveWalletCargo>>;
|
|
35
|
+
/** Requires an account read for a wallet cargo transfer to exist. */
|
|
36
|
+
export declare function requireWalletAccount(account: RawAccount | undefined, address: Address, action: 'deposit' | 'withdrawal'): RawAccount;
|
|
37
|
+
/** Reads the Profile, Character, Starbase Player, System, cargo cache, mint
|
|
38
|
+
* and shared vault with `extra` accounts in the same batch, and requires the
|
|
39
|
+
* shared Starbase graph, cache, mint and vault facts. Returns the extra
|
|
40
|
+
* accounts as read, missing ones included. */
|
|
41
|
+
export declare function readWalletCargo(ctx: SageContext, cargo: WalletCargo, profile: Address, game: Address, action: 'deposit' | 'withdrawal', extra: readonly Address[]): Promise<{
|
|
42
|
+
cacheData: import("@staratlas/dev-sage").CargoDefinitionsCache;
|
|
43
|
+
characterRaw: RawAccount;
|
|
44
|
+
decimals: number;
|
|
45
|
+
extraAccounts: (RawAccount | undefined)[];
|
|
46
|
+
playerData: Readonly<import("../../starbases/index.js").StarbasePlayerAccountData>;
|
|
47
|
+
playerRaw: RawAccount;
|
|
48
|
+
profileRaw: RawAccount;
|
|
49
|
+
systemGuard: {
|
|
50
|
+
describes: string;
|
|
51
|
+
requireCss?: true;
|
|
52
|
+
kind: "starbase-system";
|
|
53
|
+
address: import("../../client/contracts.js").Address;
|
|
54
|
+
game: Address;
|
|
55
|
+
starbaseSequenceId: bigint;
|
|
56
|
+
};
|
|
57
|
+
vaultBalance: bigint;
|
|
58
|
+
}>;
|
|
59
|
+
/** The mint, cargo configuration and cargo cache guards shared by wallet
|
|
60
|
+
* cargo Plans. */
|
|
61
|
+
export declare function walletCargoGuards(cargo: WalletCargo, cargoId: number, game: Address, decimals: number): readonly PlanPrecondition[];
|
|
62
|
+
export {};
|
|
14
63
|
//# sourceMappingURL=wallet-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-context.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-context.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet-context.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-context.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,OAAO,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAUtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CAC5C;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,IAAI,SAAiB,GACpB,OAAO,CAAC,gBAAgB,CAAC,CAO3B;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,QAwB1E;AAED;;yEAEyE;AACzE,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO;;;;;;;;;;;;;;;GA+Bd;AAED,KAAK,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC;AAElE,qEAAqE;AACrE,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,UAAU,GAAG,SAAS,EAC/B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,GAAG,YAAY,GAC/B,UAAU,CAQZ;AAED;;;8CAG8C;AAC9C,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,GAAG,YAAY,EAChC,KAAK,EAAE,SAAS,OAAO,EAAE;;;;;;;;;;;;;;;;;GAkE1B;AAED;kBACkB;AAClB,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,GACf,SAAS,gBAAgB,EAAE,CAyB7B"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { hashAccountState } from '../../internal/planning/account-state.js';
|
|
2
|
-
import {} from '@solana/kit';
|
|
2
|
+
import { getAddressEncoder, getProgramDerivedAddress, } from '@solana/kit';
|
|
3
|
+
import { InvalidActionInputError } from '../../client/errors.js';
|
|
4
|
+
import { readContextRawAccounts } from '../../client/reconciliation.js';
|
|
5
|
+
import { SAGE_PROGRAM_ADDRESS } from '../../internal/c4/runtime-bindings.js';
|
|
6
|
+
import { validateWalletCargoCache } from '../../internal/c4/wallet-cargo-cache.js';
|
|
7
|
+
import { deriveAssociatedTokenAddress, readTokenAccount, } from '../../internal/planning/original-token.js';
|
|
8
|
+
import { requireProfileStarbasePlayer } from '../../internal/planning/starbase-player-owner.js';
|
|
9
|
+
import { validateTokenMint } from '../../internal/planning/token-mint.js';
|
|
10
|
+
import { validateWalletStarbase } from '../../internal/planning/wallet-starbase.js';
|
|
11
|
+
import { readFreshGameCargoBytesConfiguration } from '../../registry/cargo.js';
|
|
12
|
+
import { failWalletCargo } from './wallet-token.js';
|
|
3
13
|
export async function observeWalletAccount(account, role = 'prerequisite') {
|
|
4
14
|
return {
|
|
5
15
|
kind: 'account-state',
|
|
@@ -8,5 +18,118 @@ export async function observeWalletAccount(account, role = 'prerequisite') {
|
|
|
8
18
|
describes: `${role} account ${account.address} retains its observed owner and data; native balance is not guarded.`,
|
|
9
19
|
};
|
|
10
20
|
}
|
|
11
|
-
|
|
21
|
+
/** Requires an exact raw u64 amount and a u16 cargo id. */
|
|
22
|
+
export function validateWalletCargoAmount(amount, cargoId) {
|
|
23
|
+
if (typeof amount !== 'bigint' ||
|
|
24
|
+
amount <= 0n ||
|
|
25
|
+
amount > 18446744073709551615n)
|
|
26
|
+
throw new InvalidActionInputError('amount', amount, 'a positive bigint in the unsigned u64 range', 'Supply an exact raw token amount as bigint.');
|
|
27
|
+
if (typeof cargoId !== 'number' ||
|
|
28
|
+
!Number.isSafeInteger(cargoId) ||
|
|
29
|
+
cargoId < 0 ||
|
|
30
|
+
cargoId > 65535)
|
|
31
|
+
throw new InvalidActionInputError('cargoId', cargoId, 'an unsigned u16 cargo ID', 'Choose an existing cargo definition ID.');
|
|
32
|
+
}
|
|
33
|
+
/** Pre-read facts shared by wallet deposits and withdrawals: the authorization
|
|
34
|
+
* Profile's canonical Starbase Player, the fresh cargo configuration, and the
|
|
35
|
+
* canonical Game cargo cache and its shared vault for the cargo mint. */
|
|
36
|
+
export async function resolveWalletCargo(ctx, starbase, profile, cargoId, game) {
|
|
37
|
+
if (starbase.kind !== 'starbasePlayer')
|
|
38
|
+
failWalletCargo('The loaded Starbase must be a Starbase Player registration.', starbase.address);
|
|
39
|
+
const character = await requireProfileStarbasePlayer(starbase, profile, game);
|
|
40
|
+
const config = await readFreshGameCargoBytesConfiguration(ctx, cargoId);
|
|
41
|
+
const [cache, bump] = await getProgramDerivedAddress({
|
|
42
|
+
programAddress: SAGE_PROGRAM_ADDRESS,
|
|
43
|
+
seeds: [
|
|
44
|
+
new TextEncoder().encode('CargoDefinitionsCache'),
|
|
45
|
+
getAddressEncoder().encode(game),
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
if (config.cache !== cache)
|
|
49
|
+
failWalletCargo('The configured cargo cache does not match the canonical Game cargo-cache PDA.', config.cache);
|
|
50
|
+
return {
|
|
51
|
+
bump,
|
|
52
|
+
cache,
|
|
53
|
+
character,
|
|
54
|
+
config,
|
|
55
|
+
mint: config.cargo.mint,
|
|
56
|
+
player: starbase.address,
|
|
57
|
+
system: starbase.system.address,
|
|
58
|
+
vault: await deriveAssociatedTokenAddress(cache, config.cargo.mint),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Requires an account read for a wallet cargo transfer to exist. */
|
|
62
|
+
export function requireWalletAccount(account, address, action) {
|
|
63
|
+
return (account ??
|
|
64
|
+
failWalletCargo(`Required ${action} account ${address} is missing. Register the player or create the required accounts separately.`, address));
|
|
65
|
+
}
|
|
66
|
+
/** Reads the Profile, Character, Starbase Player, System, cargo cache, mint
|
|
67
|
+
* and shared vault with `extra` accounts in the same batch, and requires the
|
|
68
|
+
* shared Starbase graph, cache, mint and vault facts. Returns the extra
|
|
69
|
+
* accounts as read, missing ones included. */
|
|
70
|
+
export async function readWalletCargo(ctx, cargo, profile, game, action, extra) {
|
|
71
|
+
const addresses = [
|
|
72
|
+
profile,
|
|
73
|
+
cargo.character,
|
|
74
|
+
cargo.player,
|
|
75
|
+
cargo.system,
|
|
76
|
+
cargo.cache,
|
|
77
|
+
cargo.mint,
|
|
78
|
+
cargo.vault,
|
|
79
|
+
];
|
|
80
|
+
const candidates = await readContextRawAccounts(ctx, [
|
|
81
|
+
...addresses,
|
|
82
|
+
...extra,
|
|
83
|
+
]);
|
|
84
|
+
const [profileRaw, characterRaw, playerRaw, systemRaw, cacheRaw, mintRaw, vaultRaw,] = addresses.map((address, index) => requireWalletAccount(candidates[index], address, action));
|
|
85
|
+
const { playerData, systemGuard } = await validateWalletStarbase({
|
|
86
|
+
profile: profileRaw,
|
|
87
|
+
character: characterRaw,
|
|
88
|
+
player: playerRaw,
|
|
89
|
+
system: systemRaw,
|
|
90
|
+
}, {
|
|
91
|
+
game,
|
|
92
|
+
profile,
|
|
93
|
+
character: cargo.character,
|
|
94
|
+
system: cargo.system,
|
|
95
|
+
requireCss: action === 'deposit',
|
|
96
|
+
}, failWalletCargo);
|
|
97
|
+
return {
|
|
98
|
+
cacheData: validateWalletCargoCache(cacheRaw, game, cargo.bump),
|
|
99
|
+
characterRaw,
|
|
100
|
+
decimals: validateTokenMint(mintRaw),
|
|
101
|
+
extraAccounts: candidates.slice(addresses.length),
|
|
102
|
+
playerData,
|
|
103
|
+
playerRaw,
|
|
104
|
+
profileRaw,
|
|
105
|
+
systemGuard,
|
|
106
|
+
vaultBalance: readTokenAccount(vaultRaw, cargo.mint, cargo.cache, failWalletCargo),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** The mint, cargo configuration and cargo cache guards shared by wallet
|
|
110
|
+
* cargo Plans. */
|
|
111
|
+
export function walletCargoGuards(cargo, cargoId, game, decimals) {
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
kind: 'token-mint',
|
|
115
|
+
address: cargo.mint,
|
|
116
|
+
decimals,
|
|
117
|
+
describes: `Mint ${cargo.mint} remains a valid initialized original Token Mint with unchanged decimals; supply and authorities may change.`,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
kind: 'game-cargo-bytes-config',
|
|
121
|
+
address: game,
|
|
122
|
+
cargoId,
|
|
123
|
+
configHash: cargo.config.configHash,
|
|
124
|
+
describes: 'The selected cargo’s full encoded configuration, including its stored name, and cache identity remain unchanged; unrelated Game changes are allowed.',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
kind: 'cargo-cache',
|
|
128
|
+
address: cargo.cache,
|
|
129
|
+
game,
|
|
130
|
+
bump: cargo.bump,
|
|
131
|
+
describes: 'The canonical cargo cache retains valid Game identity and layout; counters may change.',
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
}
|
|
12
135
|
//# sourceMappingURL=wallet-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-context.js","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet-context.js","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GAEzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EACL,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEpF,OAAO,EAAE,oCAAoC,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAUpD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAmB,EACnB,IAAI,GAAG,cAAc;IAErB,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,OAAO,CAAC,OAAO;QAC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ACnB,OAAO,EAAE,KAAK,CAAC,KAAK;YACpB,IAAI;YACJ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EACP,wFAAwF;SAC3F;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { RawAccount } from '../../client/contracts.js';
|
|
3
|
-
export declare const ORIGINAL_TOKEN_PROGRAM: Address;
|
|
1
|
+
import type { Address } from '@solana/kit';
|
|
4
2
|
export declare function failWalletCargo(message: string, address: Address): never;
|
|
5
|
-
export declare function deriveWalletTokenAddress(owner: Address, mint: Address): Promise<Address>;
|
|
6
|
-
export { validateTokenMint as validateWalletMint } from '../../internal/planning/token-mint.js';
|
|
7
|
-
export declare function validateWalletToken(account: RawAccount, mint: Address, owner: Address): bigint;
|
|
8
3
|
//# sourceMappingURL=wallet-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-token.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-token.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet-token.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,CAMxE"}
|
|
@@ -1,50 +1,5 @@
|
|
|
1
|
-
import { getAddressDecoder, getAddressEncoder, getProgramDerivedAddress, } from '@solana/kit';
|
|
2
1
|
import { SageSdkError } from '../../client/errors.js';
|
|
3
|
-
export const ORIGINAL_TOKEN_PROGRAM = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
|
|
4
|
-
const ASSOCIATED_TOKEN_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
5
2
|
export function failWalletCargo(message, address) {
|
|
6
3
|
throw new SageSdkError('ACTION_PRECONDITION_FAILED', `${message} Refresh the accounts or select a supported original Token account before planning again.`, { address });
|
|
7
4
|
}
|
|
8
|
-
export async function deriveWalletTokenAddress(owner, mint) {
|
|
9
|
-
const encode = getAddressEncoder();
|
|
10
|
-
const [result] = await getProgramDerivedAddress({
|
|
11
|
-
programAddress: ASSOCIATED_TOKEN_PROGRAM,
|
|
12
|
-
seeds: [
|
|
13
|
-
encode.encode(owner),
|
|
14
|
-
encode.encode(ORIGINAL_TOKEN_PROGRAM),
|
|
15
|
-
encode.encode(mint),
|
|
16
|
-
],
|
|
17
|
-
});
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
function view(account, size) {
|
|
21
|
-
if (account.executable ||
|
|
22
|
-
account.owner !== ORIGINAL_TOKEN_PROGRAM ||
|
|
23
|
-
account.data.length !== size) {
|
|
24
|
-
failWalletCargo(`Account ${account.address} must have the original Token program owner and exactly ${String(size)} bytes; Token-2022 and multisig layouts are unsupported.`, account.address);
|
|
25
|
-
}
|
|
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
|
-
failWalletCargo(`Token account ${account.address} has an invalid optional field.`, account.address);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export { validateTokenMint as validateWalletMint } from '../../internal/planning/token-mint.js';
|
|
34
|
-
export function validateWalletToken(account, mint, owner) {
|
|
35
|
-
const bytes = view(account, 165);
|
|
36
|
-
option(bytes, 72, account);
|
|
37
|
-
option(bytes, 109, account);
|
|
38
|
-
option(bytes, 129, account);
|
|
39
|
-
if (bytes.getUint8(108) !== 1) {
|
|
40
|
-
failWalletCargo(`Token account ${account.address} must be initialized and unfrozen.`, account.address);
|
|
41
|
-
}
|
|
42
|
-
const decode = getAddressDecoder();
|
|
43
|
-
if (decode.decode(account.data.subarray(0, 32)) !== mint ||
|
|
44
|
-
decode.decode(account.data.subarray(32, 64)) !== owner) {
|
|
45
|
-
failWalletCargo(`Token account ${account.address} must contain cargo mint ${mint} and be owned internally by ${owner}; delegated spending is unsupported.`, account.address);
|
|
46
|
-
}
|
|
47
|
-
// A recorded delegate does not prevent the actual owner from transferring.
|
|
48
|
-
return bytes.getBigUint64(64, true);
|
|
49
|
-
}
|
|
50
5
|
//# sourceMappingURL=wallet-token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-token.js","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet-token.js","sourceRoot":"","sources":["../../../src/cargo/actions/wallet-token.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,OAAgB;IAC/D,MAAM,IAAI,YAAY,CACpB,4BAA4B,EAC5B,GAAG,OAAO,2FAA2F,EACrG,EAAE,OAAO,EAAE,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/withdrawal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../../src/cargo/actions/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,kDAAkD,CAAC;AAQ1D,OAAO,EAEL,KAAK,IAAI,EAGV,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAML,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QAC5B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;QACnC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,EAAE,gCAAgC,GACxC,OAAO,CAAC,IAAI,CAAC,CA2Lf"}
|