Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"typecheck": "turbo run typecheck",
"size": "pnpm build && size-limit",
"prepare": "husky",
"check:circular-deps": "turbo run check:circular-deps",
"changeset": "changeset",
"version:packages": "changeset version",
"publish-packages": "changeset publish --filter @solana/client --filter @solana/react-hooks --filter @solana/web3-compat"
Expand Down
5 changes: 3 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
"format": "biome check --write src",
"lint": "biome check src",
"test:typecheck": "tsc --noEmit",
"test:typecheck": "tsc --noEmit -p tsconfig.test.json",
"test": "vitest run --config ./vitest.config.ts",
"typecheck": "pnpm test:typecheck"
"typecheck": "tsc --noEmit",
"check:circular-deps": "madge --circular $(find ./src -name '*.ts' -o -name '*.tsx')"
},
"author": "Solana Maintainers <maintainers@solana.foundation>",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/client/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type { Address, Lamports, SendableTransaction, Signature, Transaction } f
import type { TransactionWithLastValidBlockHeight } from '@solana/transaction-confirmation';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { ClientActions, SolanaClientRuntime, WalletConnector, WalletRegistry } from '../types';
import type { SolanaClientRuntime } from '../rpc/types';
import type { ClientActions } from '../types';
import type { WalletConnector, WalletRegistry } from '../wallet/types';
import { createActions } from './actions';
import { createDefaultClientStore } from './createClientStore';

Expand Down
17 changes: 6 additions & 11 deletions packages/client/src/client/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ import { fetchNonce } from '@solana-program/system';

import { createLogger, formatError } from '../logging/logger';
import { createSolanaRpcClient } from '../rpc/createSolanaRpcClient';
import type {
AddressLookupTableData,
ClientActions,
ClientState,
ClientStore,
NonceAccountData,
SolanaClientRuntime,
WalletRegistry,
} from '../types';
import type { SolanaClientRuntime } from '../rpc/types';
import type { AddressLookupTableData, ClientActions, ClientState, ClientStore, NonceAccountData } from '../types';
import { now } from '../utils';
import type { WalletRegistry, WalletSession } from '../wallet/types';

type MutableRuntime = SolanaClientRuntime;

Expand Down Expand Up @@ -162,12 +156,12 @@ export function createActions({ connectors, logger: inputLogger, runtime, store
* Initiates a wallet connection using a registered connector.
*
* @param connectorId - Identifier for the desired wallet connector.
* @returns Promise that resolves once the connection attempt has completed.
* @returns Promise that resolves to the wallet session once the connection attempt has completed.
*/
async function connectWallet(
connectorId: string,
options: Readonly<{ autoConnect?: boolean }> = {},
): Promise<void> {
): Promise<WalletSession> {
walletEventsCleanup?.();
walletEventsCleanup = undefined;
const connector = connectors.get(connectorId);
Expand Down Expand Up @@ -206,6 +200,7 @@ export function createActions({ connectors, logger: inputLogger, runtime, store
level: 'info',
message: 'wallet connected',
});
return session;
} catch (error) {
store.setState((state) => ({
...state,
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/client/createClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createLogger, formatError } from '../logging/logger';
import { createSolanaRpcClient } from '../rpc/createSolanaRpcClient';
import type { SolanaClientRuntime } from '../rpc/types';
import { applySerializableState } from '../serialization/state';
import type { ClientStore, SolanaClient, SolanaClientConfig, SolanaClientRuntime } from '../types';
import type { ClientStore, SolanaClient, SolanaClientConfig } from '../types';
import { now } from '../utils';
import { resolveCluster } from '../utils/cluster';
import { createWalletRegistry } from '../wallet/registry';
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/client/createClientHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { createSolTransferHelper, type SolTransferHelper } from '../features/sol
import { createSplTokenHelper, type SplTokenHelper, type SplTokenHelperConfig } from '../features/spl';
import { createStakeHelper, type StakeHelper } from '../features/stake';
import { createTransactionHelper, type TransactionHelper } from '../features/transactions';
import type { SolanaClientRuntime } from '../rpc/types';
import {
type PrepareTransactionMessage,
type PrepareTransactionOptions,
prepareTransaction as prepareTransactionUtility,
} from '../transactions/prepareTransaction';
import type { ClientHelpers, ClientStore, SolanaClientRuntime } from '../types';
import type { ClientHelpers, ClientStore } from '../types';

type SplTokenCacheEntry = Readonly<{
baseCommitment?: Commitment;
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/client/defaultClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ClusterUrl, Commitment } from '@solana/kit';

import type { SolanaClient, SolanaClientConfig, WalletConnector } from '../types';
import type { SolanaClient, SolanaClientConfig } from '../types';
import { type ClusterMoniker, resolveCluster } from '../utils/cluster';
import { autoDiscover, backpack, phantom, solflare } from '../wallet/connectors';
import type { WalletConnector } from '../wallet/types';
import { createClient } from './createClient';

type BasePassthrough = Omit<SolanaClientConfig, 'endpoint' | 'websocketEndpoint' | 'walletConnectors'>;
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/client/watchers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Address, Signature } from '@solana/kit';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { ClientStore, SolanaClientRuntime } from '../types';
import type { SolanaClientRuntime } from '../rpc/types';
import type { ClientStore } from '../types';
import { createDefaultClientStore } from './createClientStore';
import { createWatchers } from './watchers';

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/client/watchers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Lamports, SolanaRpcSubscriptionsApi } from '@solana/kit';

import { createLogger, formatError } from '../logging/logger';
import type { SolanaClientRuntime } from '../rpc/types';
import type {
AccountCacheEntry,
AccountWatcherConfig,
BalanceWatcherConfig,
ClientStore,
ClientWatchers,
SignatureWatcherConfig,
SolanaClientRuntime,
SubscriptionStatus,
} from '../types';
import { now } from '../utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/features/sol.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TransactionSigner } from '@solana/kit';
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import type { WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';

type MutableMessage = {
instructions: unknown[];
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/features/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
import { getTransferSolInstruction } from '@solana-program/system';

import { lamportsMath } from '../numeric/lamports';
import type { SolanaClientRuntime } from '../rpc/types';
import { createWalletTransactionSigner, isWalletSession, resolveSignerMode } from '../signers/walletTransactionSigner';
import type { SolanaClientRuntime, WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';

type BlockhashLifetime = Readonly<{
blockhash: Blockhash;
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/features/spl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import {
} from '@solana-program/token';

import { createTokenAmount, type TokenAmountMath } from '../numeric/amounts';
import type { SolanaClientRuntime } from '../rpc/types';
import { createWalletTransactionSigner, isWalletSession, resolveSignerMode } from '../signers/walletTransactionSigner';
import type { SolanaClientRuntime, WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';
import type { SolTransferSendOptions } from './sol';

type BlockhashLifetime = Readonly<{
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/features/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import {
import { getCreateAccountInstruction } from '@solana-program/system';

import { lamportsMath } from '../numeric/lamports';
import type { SolanaClientRuntime } from '../rpc/types';
import { createWalletTransactionSigner, isWalletSession, resolveSignerMode } from '../signers/walletTransactionSigner';
import type { SolanaClientRuntime, WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';

type BlockhashLifetime = Readonly<{
blockhash: Blockhash;
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/features/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import {
getSetComputeUnitLimitInstruction,
getSetComputeUnitPriceInstruction,
} from '@solana-program/compute-budget';

import type { SolanaClientRuntime } from '../rpc/types';
import { createWalletTransactionSigner, isWalletSession, resolveSignerMode } from '../signers/walletTransactionSigner';
import {
type PrepareTransactionMessage,
type PrepareTransactionOptions,
prepareTransaction as prepareTransactionUtility,
} from '../transactions/prepareTransaction';
import type { SolanaClientRuntime, WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';

type BlockhashLifetime = Readonly<{
blockhash: Blockhash;
Expand Down
13 changes: 8 additions & 5 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export {
type SimulateTransactionOptions,
type SolanaRpcClient,
} from './rpc/createSolanaRpcClient';
export type { SolanaClientRuntime } from './rpc/types';
export { bigintFromJson, bigintToJson, lamportsFromJson, lamportsToJson } from './serialization/json';
export {
applySerializableState,
Expand Down Expand Up @@ -178,11 +179,6 @@ export type {
SetClusterReturnType,
SolanaClient,
SolanaClientConfig,
WalletConnector,
WalletConnectorMetadata,
WalletRegistry,
WalletSession,
WalletStatus,
} from './types';
export { type AddressLike, toAddress, toAddressString } from './utils/addressLike';
export { type ClusterMoniker, resolveCluster } from './utils/cluster';
Expand All @@ -194,3 +190,10 @@ export {
getWalletStandardConnectors,
watchWalletStandardConnectors,
} from './wallet/standard';
export type {
WalletConnector,
WalletConnectorMetadata,
WalletRegistry,
WalletSession,
WalletStatus,
} from './wallet/types';
7 changes: 7 additions & 0 deletions packages/client/src/rpc/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type SolanaRpcInstance = ReturnType<typeof import('@solana/kit')['createSolanaRpc']>;
type SolanaSubscriptionsInstance = ReturnType<typeof import('@solana/kit')['createSolanaRpcSubscriptions']>;

export type SolanaClientRuntime = {
rpc: SolanaRpcInstance;
rpcSubscriptions: SolanaSubscriptionsInstance;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getBase58Decoder } from '@solana/codecs-strings';
import type { TransactionSigner } from '@solana/kit';
import { describe, expect, it, vi } from 'vitest';

import type { WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';
import { createWalletTransactionSigner, isWalletSession, resolveSignerMode } from './walletTransactionSigner';

type SessionTransaction = Parameters<NonNullable<WalletSession['signTransaction']>>[0];
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/signers/walletTransactionSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
type TransactionWithinSizeLimit,
type TransactionWithLifetime,
} from '@solana/kit';

import type { WalletSession } from '../types';
import type { WalletSession } from '../wallet/types';

type WalletTransactionSignerMode = 'partial' | 'send';

Expand Down
81 changes: 3 additions & 78 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,15 @@ import type { SplTokenHelper, SplTokenHelperConfig } from './features/spl';
import type { StakeHelper } from './features/stake';
import type { TransactionHelper } from './features/transactions';
import type { SolanaRpcClient } from './rpc/createSolanaRpcClient';
import type { SolanaClientRuntime } from './rpc/types';
import type { PrepareTransactionMessage, PrepareTransactionOptions } from './transactions/prepareTransaction';
import type { ClusterMoniker } from './utils/cluster';

type SolanaRpcInstance = ReturnType<typeof import('@solana/kit')['createSolanaRpc']>;
type SolanaSubscriptionsInstance = ReturnType<typeof import('@solana/kit')['createSolanaRpcSubscriptions']>;
import type { WalletConnector, WalletRegistry, WalletSession, WalletStatus } from './wallet/types';

export type LogLevel = 'debug' | 'error' | 'info' | 'warn';

export type ClientLogger = (event: { data?: Record<string, unknown>; level: LogLevel; message: string }) => void;

export type WalletConnectorMetadata = Readonly<{
canAutoConnect?: boolean;
icon?: string;
id: string;
kind?: string;
name: string;
ready?: boolean;
}>;

export type WalletAccount = Readonly<{
address: Address;
label?: string;
publicKey: Uint8Array;
}>;

export type WalletSession = Readonly<{
account: WalletAccount;
connector: WalletConnectorMetadata;
disconnect(): Promise<void>;
onAccountsChanged?: (listener: (accounts: WalletAccount[]) => void) => () => void;
sendTransaction?(
transaction: SendableTransaction & Transaction,
config?: Readonly<{ commitment?: Commitment }>,
): Promise<Signature>;
signMessage?(message: Uint8Array): Promise<Uint8Array>;
signTransaction?(transaction: SendableTransaction & Transaction): Promise<SendableTransaction & Transaction>;
}>;

export type WalletConnector = WalletConnectorMetadata & {
connect(opts?: Readonly<{ autoConnect?: boolean; allowInteractiveFallback?: boolean }>): Promise<WalletSession>;
disconnect(): Promise<void>;
isSupported(): boolean;
};

type WalletStatusConnected = Readonly<{
autoConnect?: boolean;
connectorId: string;
session: WalletSession;
status: 'connected';
}>;

type WalletStatusConnecting = Readonly<{
autoConnect?: boolean;
connectorId: string;
status: 'connecting';
}>;

type WalletStatusDisconnected = Readonly<{
status: 'disconnected';
}>;

type WalletStatusError = Readonly<{
autoConnect?: boolean;
connectorId?: string;
error: unknown;
status: 'error';
}>;

export type WalletStatus =
| WalletStatusConnected
| WalletStatusConnecting
| WalletStatusDisconnected
| WalletStatusError;

type ClusterStatusConnecting = Readonly<{ status: 'connecting' }>;

type ClusterStatusError = Readonly<{
Expand Down Expand Up @@ -202,11 +137,6 @@ export type SerializableSolanaState = Readonly<{
websocketEndpoint?: ClusterUrl;
}>;

export type SolanaClientRuntime = {
rpc: SolanaRpcInstance;
rpcSubscriptions: SolanaSubscriptionsInstance;
};

export type BalanceWatcherConfig = Readonly<{
address: Address;
commitment?: Commitment;
Expand All @@ -232,7 +162,7 @@ export type ConnectWalletParameters = Readonly<{
options?: Readonly<{ autoConnect?: boolean; allowInteractiveFallback?: boolean }>;
}>;

export type ConnectWalletReturnType = Promise<void>;
export type ConnectWalletReturnType = Promise<WalletSession>;

export type DisconnectWalletParameters = undefined;

Expand Down Expand Up @@ -350,11 +280,6 @@ export type ClientHelpers = Readonly<{
): Promise<TMessage & TransactionMessageWithBlockhashLifetime>;
}>;

export type WalletRegistry = Readonly<{
all: readonly WalletConnector[];
get(id: string): WalletConnector | undefined;
}>;

export type SolanaClient = Readonly<{
actions: ClientActions;
config: SolanaClientConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/wallet/connectors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getWallets } from '@wallet-standard/app';
import type { Wallet } from '@wallet-standard/base';
import { StandardConnect } from '@wallet-standard/features';
import type { WalletConnector } from '../types';
import { createWalletStandardConnector } from './standard';
import type { WalletConnector } from './types';

type DiscoveryOptions = Readonly<{
overrides?: (wallet: Wallet) => Parameters<typeof createWalletStandardConnector>[1];
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/wallet/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, expect, it } from 'vitest';

import type { WalletConnector } from '../types';
import { createWalletRegistry } from './registry';
import type { WalletConnector } from './types';

describe('wallet registry', () => {
const connector = (id: string): WalletConnector => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/wallet/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WalletConnector, WalletRegistry } from '../types';
import type { WalletConnector, WalletRegistry } from './types';

/**
* Creates an in-memory wallet registry from the provided connectors.
Expand Down
Loading
Loading