@@ -67,16 +67,17 @@ Create `packages/cli/src/actions/<name>.ts` using the template below. Fill every
6767import { Cli , z } from " incur" ;
6868import { createAction } from " ../utils/actions.js" ;
6969// Import helpers as needed:
70- // Session/wallet: import { WalletSchema } from "../utils/schemas.js";
70+ // Session/wallet: import { WalletIdSchema, DerivationIndexSchema } from "../utils/schemas.js";
7171// Solana address: import { getSolanaAddress } from "../utils/solana.js";
7272// EVM address: import { getEthereumAddress } from "../utils/evm.js";
7373// Perps client: import { createPerpsClient } from "../utils/perps.js";
7474// Shared schemas: import { ActionResponseSchema, PendingConfirmationSchema } from "../utils/output-schemas.js";
7575
76- // Use WalletSchema.safeExtend({...}) if the action touches the wallet (adds walletId resolver + derivationIndex).
77- // Use z.object({...}) if it needs no wallet access.
78- const <PascalName>Schema = WalletSchema .safeExtend ({
76+ const <PascalName>Schema = z .object ({
7977 // Each field needs a .describe() explaining its purpose and any defaults.
78+ // Always include these at the bottom if the action touches the wallet:
79+ // walletId: WalletIdSchema.describe("Optional wallet ID (defaults to authenticated wallet)"),
80+ // derivationIndex: DerivationIndexSchema.describe("Optional derivation index (default: 0)"),
8081});
8182
8283const <PascalName>OutputSchema = z .object ({
@@ -113,15 +114,15 @@ const <camelName>Action = createAction({
113114 },
114115 run : async ({ options : params , var : context }) => {
115116 const { logger } = context ;
116- const walletId = params .walletId (context .manager );
117- const derivationIndex = params .derivationIndex ;
118- // Resolve walletId BEFORE calling getClient() so auth errors surface clearly.
119- const client = context .manager .getClient ();
117+ const session = context .manager .getSession ();
120118
121- // client → PhantomClient (sign, send, addresses)
119+ // context.manager.getClient() → PhantomClient (sign, send, addresses)
122120 // context.apiClient → PhantomApiClient (REST endpoints)
123- // walletId → resolved wallet ID (param or authenticated session)
124- // derivationIndex → BIP-44 account index (default: 0)
121+ // session.walletId → currently authenticated wallet ID
122+ // session.organizationId → org ID for the current session
123+
124+ // A session is automatically initialized on first use and persisted
125+ // across calls — no manual session management required.
125126
126127 // ... implementation ...
127128
@@ -265,14 +266,15 @@ A session is initialized on first use (triggering the browser auth flow) and per
265266
266267## Reference: commonly used helpers
267268
268- | Helper | Import path | When to use |
269- | -------------------------------------------------------- | ------------------------ | ----------------------------------------------------------------------------------------- |
270- | ` getSolanaAddress(context, walletId, derivationIndex) ` | ` ../utils/solana.js ` | Derive Solana public key |
271- | ` getEthereumAddress(context, walletId, derivationIndex) ` | ` ../utils/evm.js ` | Derive EVM address |
272- | ` createPerpsClient(context, walletId, derivationIndex) ` | ` ../utils/perps.js ` | All Hyperliquid perps ops |
273- | ` normalizeNetworkId(id) ` | ` ../utils/network.js ` | Normalise CAIP-2 chain IDs |
274- | ` parseBaseUnitAmount(amount) ` | ` ../utils/amount.js ` | String/number → ` bigint ` base units |
275- | ` parseUiAmount(amount, decimals) ` | ` ../utils/amount.js ` | UI units → ` bigint ` base units |
276- | ` runSimulation(body, context) ` | ` ../utils/simulation.js ` | Simulate before submitting |
277- | ` WalletSchema ` | ` ../utils/schemas.js ` | Base schema with ` walletId ` resolver + ` derivationIndex ` ; extend it instead of ` z.object ` |
278- | ` Caip2ChainIdSchema ` | ` ../utils/schemas.js ` | CAIP-2 chain ID input field |
269+ | Helper | Import path | When to use |
270+ | -------------------------------------------------------- | ------------------------ | ----------------------------------- |
271+ | ` getSolanaAddress(context, walletId, derivationIndex) ` | ` ../utils/solana.js ` | Derive Solana public key |
272+ | ` getEthereumAddress(context, walletId, derivationIndex) ` | ` ../utils/evm.js ` | Derive EVM address |
273+ | ` createPerpsClient(context, walletId, derivationIndex?) ` | ` ../utils/perps.js ` | All Hyperliquid perps ops |
274+ | ` normalizeNetworkId(id) ` | ` ../utils/network.js ` | Normalise CAIP-2 chain IDs |
275+ | ` parseBaseUnitAmount(amount) ` | ` ../utils/amount.js ` | String/number → ` bigint ` base units |
276+ | ` parseUiAmount(amount, decimals) ` | ` ../utils/amount.js ` | UI units → ` bigint ` base units |
277+ | ` runSimulation(body, context) ` | ` ../utils/simulation.js ` | Simulate before submitting |
278+ | ` WalletIdSchema ` | ` ../utils/schemas.js ` | Optional wallet ID input field |
279+ | ` DerivationIndexSchema ` | ` ../utils/schemas.js ` | Optional HD index input field |
280+ | ` Caip2ChainIdSchema ` | ` ../utils/schemas.js ` | CAIP-2 chain ID input field |
0 commit comments