@whetstone-research/doppler-sdk 1.0.2 → 1.0.4

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.
@@ -0,0 +1,1046 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { Rpc, SolanaRpcApi, Address, TransactionSigner } from '@solana/kit';
5
+ import { WalletAccount, Wallet } from '@wallet-standard/base';
6
+ import { StandardConnectFeature, StandardDisconnectFeature } from '@wallet-standard/features';
7
+ import { P as Pool, m as SwapQuote, l as SwapDirection, o as AddLiquidityQuote, p as RemoveLiquidityQuote, a as Position, L as PositionValue, N as PositionWithAddress, O as OracleState, $ as TwapResult, D as OracleWithAddress } from '../../oracle-CU-nZnja.cjs';
8
+
9
+ /**
10
+ * Configuration for the AMM provider
11
+ */
12
+ interface AmmConfig {
13
+ /** Solana RPC client */
14
+ rpc: Rpc<SolanaRpcApi>;
15
+ /** CPMM Program ID (defaults to mainnet program) */
16
+ programId?: Address;
17
+ /** Default commitment level for queries */
18
+ commitment?: 'processed' | 'confirmed' | 'finalized';
19
+ /** Auto-refresh interval in milliseconds (0 to disable) */
20
+ refreshInterval?: number;
21
+ /** Default slippage tolerance in basis points (default: 50 = 0.5%) */
22
+ defaultSlippageBps?: number;
23
+ }
24
+ /**
25
+ * Context value provided to consumers
26
+ */
27
+ interface AmmContextValue$1 extends Required<Omit<AmmConfig, 'rpc'>> {
28
+ /** Solana RPC client */
29
+ rpc: Rpc<SolanaRpcApi>;
30
+ }
31
+ declare const AmmContext$1: react.Context<AmmContextValue$1 | null>;
32
+ /**
33
+ * Props for the AmmProvider component
34
+ */
35
+ interface AmmProviderProps$1 extends AmmConfig {
36
+ children: ReactNode;
37
+ }
38
+ /**
39
+ * Provider component for CPMM SDK hooks
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * import { createSolanaRpc } from '@solana/kit';
44
+ *
45
+ * const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
46
+ *
47
+ * function App() {
48
+ * return (
49
+ * <AmmProvider rpc={rpc}>
50
+ * <YourApp />
51
+ * </AmmProvider>
52
+ * );
53
+ * }
54
+ * ```
55
+ */
56
+ declare function AmmProvider$1({ rpc, programId, commitment, refreshInterval, defaultSlippageBps, children, }: AmmProviderProps$1): react_jsx_runtime.JSX.Element;
57
+ /**
58
+ * Hook to access the AMM context
59
+ *
60
+ * @throws Error if used outside of AmmProvider
61
+ */
62
+ declare function useAmm$1(): AmmContextValue$1;
63
+ /**
64
+ * Hook to access the AMM context, returning null if not available
65
+ */
66
+ declare function useAmmOptional(): AmmContextValue$1 | null;
67
+
68
+ /**
69
+ * Wallet state and capabilities
70
+ */
71
+ interface WalletState {
72
+ /** Whether a wallet is connected */
73
+ connected: boolean;
74
+ /** Connected wallet address (undefined if not connected) */
75
+ address?: Address;
76
+ /** Transaction signer (undefined if not connected) */
77
+ signer?: TransactionSigner;
78
+ /** Connect wallet function */
79
+ connect?: () => Promise<void>;
80
+ /** Disconnect wallet function */
81
+ disconnect?: () => Promise<void>;
82
+ }
83
+ /**
84
+ * Context value provided to consumers
85
+ */
86
+ interface WalletContextValue$1 extends WalletState {
87
+ /** Sign and send a transaction */
88
+ signAndSendTransaction?: (transaction: unknown) => Promise<string>;
89
+ }
90
+ declare const WalletContext$1: react.Context<WalletContextValue$1 | null>;
91
+ /**
92
+ * Props for the WalletProvider component
93
+ */
94
+ interface WalletProviderProps$1 {
95
+ /** Wallet state from your wallet adapter */
96
+ wallet: WalletState;
97
+ /** Optional sign and send transaction handler */
98
+ signAndSendTransaction?: WalletContextValue$1['signAndSendTransaction'];
99
+ children: ReactNode;
100
+ }
101
+ /**
102
+ * Provider component for wallet state
103
+ *
104
+ * This provider wraps your existing wallet adapter to provide
105
+ * a consistent interface for CPMM SDK hooks.
106
+ *
107
+ * @example
108
+ * ```tsx
109
+ * // With @solana/wallet-adapter-react
110
+ * import { useWallet } from '@solana/wallet-adapter-react';
111
+ *
112
+ * function WalletBridge({ children }) {
113
+ * const { connected, publicKey, signTransaction } = useWallet();
114
+ *
115
+ * const wallet = useMemo(() => ({
116
+ * connected,
117
+ * address: publicKey?.toBase58() as Address | undefined,
118
+ * signer: signTransaction ? { signTransactions: async (txs) => txs.map(signTransaction) } : undefined,
119
+ * }), [connected, publicKey, signTransaction]);
120
+ *
121
+ * return (
122
+ * <WalletProvider wallet={wallet}>
123
+ * {children}
124
+ * </WalletProvider>
125
+ * );
126
+ * }
127
+ * ```
128
+ */
129
+ declare function WalletProvider$1({ wallet, signAndSendTransaction, children, }: WalletProviderProps$1): react_jsx_runtime.JSX.Element;
130
+ /**
131
+ * Hook to access the wallet context
132
+ *
133
+ * @throws Error if used outside of WalletProvider
134
+ */
135
+ declare function useWallet$1(): WalletContextValue$1;
136
+ /**
137
+ * Hook to access the wallet context, returning null if not available
138
+ */
139
+ declare function useWalletOptional(): WalletContextValue$1 | null;
140
+ /**
141
+ * Hook to get connected wallet address
142
+ *
143
+ * @throws Error if wallet is not connected
144
+ */
145
+ declare function useWalletAddress(): Address;
146
+
147
+ /**
148
+ * Commitment level for RPC requests
149
+ */
150
+ type Commitment = 'processed' | 'confirmed' | 'finalized';
151
+ /**
152
+ * AMM context value exposed to consumers
153
+ */
154
+ interface AmmContextValue {
155
+ /** RPC client for Solana interactions */
156
+ rpc: Rpc<SolanaRpcApi>;
157
+ /** RPC endpoint URL */
158
+ endpoint: string;
159
+ /** CPMM program ID */
160
+ programId: Address;
161
+ /** Default commitment level */
162
+ commitment: Commitment;
163
+ /** Auto-refresh interval in milliseconds (0 to disable) */
164
+ refreshInterval: number;
165
+ /** Default slippage tolerance in basis points */
166
+ defaultSlippageBps: number;
167
+ }
168
+ /**
169
+ * Props for AmmProvider component
170
+ */
171
+ interface AmmProviderProps {
172
+ /** Child components */
173
+ children: ReactNode;
174
+ /** Solana RPC endpoint URL */
175
+ endpoint: string;
176
+ /** Custom CPMM program ID (defaults to mainnet program) */
177
+ programId?: Address;
178
+ /** Default commitment level (defaults to 'confirmed') */
179
+ commitment?: Commitment;
180
+ /** Auto-refresh interval in milliseconds (defaults to 30000) */
181
+ refreshInterval?: number;
182
+ /** Default slippage tolerance in basis points (defaults to 50 = 0.5%) */
183
+ defaultSlippageBps?: number;
184
+ }
185
+ /**
186
+ * Configuration for creating AMM context value
187
+ */
188
+ interface AmmContextConfig {
189
+ /** Solana RPC endpoint URL */
190
+ endpoint: string;
191
+ /** Custom CPMM program ID */
192
+ programId?: Address;
193
+ /** Default commitment level */
194
+ commitment?: Commitment;
195
+ /** Auto-refresh interval in milliseconds */
196
+ refreshInterval?: number;
197
+ /** Default slippage tolerance in basis points */
198
+ defaultSlippageBps?: number;
199
+ }
200
+ /**
201
+ * React context for AMM configuration
202
+ */
203
+ declare const AmmContext: react.Context<AmmContextValue | null>;
204
+ /**
205
+ * Hook to access AMM context
206
+ *
207
+ * @returns AMM context value with RPC client and configuration
208
+ * @throws Error if used outside AmmProvider
209
+ *
210
+ * @example
211
+ * ```tsx
212
+ * function MyComponent() {
213
+ * const { rpc, programId } = useAmm();
214
+ * // Use rpc to fetch pool data, etc.
215
+ * }
216
+ * ```
217
+ */
218
+ declare function useAmm(): AmmContextValue;
219
+ /**
220
+ * Create AMM context value from configuration
221
+ *
222
+ * This is exposed for testing purposes and internal use.
223
+ *
224
+ * @param config - Configuration for the AMM context
225
+ * @returns AMM context value
226
+ */
227
+ declare function createAmmContextValue(config: AmmContextConfig): AmmContextValue;
228
+ /**
229
+ * AMM Provider component
230
+ *
231
+ * Provides RPC connection and program configuration to child components.
232
+ *
233
+ * @example
234
+ * ```tsx
235
+ * function App() {
236
+ * return (
237
+ * <AmmProvider endpoint="https://api.mainnet-beta.solana.com">
238
+ * <SwapForm />
239
+ * </AmmProvider>
240
+ * );
241
+ * }
242
+ * ```
243
+ *
244
+ * @example
245
+ * With custom program ID:
246
+ * ```tsx
247
+ * import { address } from '@solana/kit';
248
+ *
249
+ * function App() {
250
+ * return (
251
+ * <AmmProvider
252
+ * endpoint="https://api.devnet.solana.com"
253
+ * programId={address('DevnetProgramId...')}
254
+ * commitment="confirmed"
255
+ * >
256
+ * <SwapForm />
257
+ * </AmmProvider>
258
+ * );
259
+ * }
260
+ * ```
261
+ */
262
+ declare function AmmProvider({ children, endpoint, programId, commitment, refreshInterval, defaultSlippageBps, }: AmmProviderProps): JSX.Element;
263
+
264
+ /**
265
+ * Wallet with required Solana features
266
+ */
267
+ type SolanaWallet = Wallet & {
268
+ features: StandardConnectFeature & Partial<StandardDisconnectFeature>;
269
+ };
270
+ /**
271
+ * Wallet context value exposed to consumers
272
+ */
273
+ interface WalletContextValue {
274
+ /** Currently selected wallet (null if none selected) */
275
+ wallet: SolanaWallet | null;
276
+ /** Currently connected account (null if not connected) */
277
+ account: WalletAccount | null;
278
+ /** Whether a wallet is currently connected */
279
+ connected: boolean;
280
+ /** Whether connection is in progress */
281
+ connecting: boolean;
282
+ /** List of available wallets */
283
+ wallets: readonly SolanaWallet[];
284
+ /** Select a wallet for connection */
285
+ select: (wallet: SolanaWallet | null) => void;
286
+ /** Connect to the selected wallet */
287
+ connect: () => Promise<void>;
288
+ /** Disconnect from the current wallet */
289
+ disconnect: () => Promise<void>;
290
+ /** Error from last operation */
291
+ error: Error | null;
292
+ }
293
+ /**
294
+ * Props for WalletProvider component
295
+ */
296
+ interface WalletProviderProps {
297
+ /** Child components */
298
+ children: ReactNode;
299
+ /** Auto-connect to previously connected wallet */
300
+ autoConnect?: boolean;
301
+ /** Callback when wallet connects */
302
+ onConnect?: (account: WalletAccount) => void;
303
+ /** Callback when wallet disconnects */
304
+ onDisconnect?: () => void;
305
+ /** Callback on error */
306
+ onError?: (error: Error) => void;
307
+ }
308
+ /**
309
+ * React context for wallet state
310
+ */
311
+ declare const WalletContext: react.Context<WalletContextValue | null>;
312
+ /**
313
+ * Hook to access wallet context
314
+ *
315
+ * @returns Wallet context value with connection state and methods
316
+ * @throws Error if used outside WalletProvider
317
+ *
318
+ * @example
319
+ * ```tsx
320
+ * function ConnectButton() {
321
+ * const { connected, connect, disconnect, account } = useWallet();
322
+ *
323
+ * if (connected) {
324
+ * return (
325
+ * <button onClick={disconnect}>
326
+ * Disconnect {account?.address.slice(0, 8)}...
327
+ * </button>
328
+ * );
329
+ * }
330
+ *
331
+ * return <button onClick={connect}>Connect Wallet</button>;
332
+ * }
333
+ * ```
334
+ */
335
+ declare function useWallet(): WalletContextValue;
336
+ /**
337
+ * Create initial wallet context value
338
+ *
339
+ * This is exposed for testing purposes.
340
+ */
341
+ declare function createWalletContextValue(): WalletContextValue;
342
+ /**
343
+ * Wallet Provider component
344
+ *
345
+ * Provides wallet connection state and methods to child components.
346
+ * Uses the wallet-standard API for cross-wallet compatibility.
347
+ *
348
+ * @example
349
+ * ```tsx
350
+ * function App() {
351
+ * return (
352
+ * <WalletProvider autoConnect>
353
+ * <AmmProvider endpoint="https://api.mainnet-beta.solana.com">
354
+ * <SwapForm />
355
+ * </AmmProvider>
356
+ * </WalletProvider>
357
+ * );
358
+ * }
359
+ * ```
360
+ *
361
+ * @example
362
+ * With callbacks:
363
+ * ```tsx
364
+ * function App() {
365
+ * return (
366
+ * <WalletProvider
367
+ * onConnect={(account) => console.log('Connected:', account.address)}
368
+ * onDisconnect={() => console.log('Disconnected')}
369
+ * onError={(err) => console.error('Wallet error:', err)}
370
+ * >
371
+ * <YourApp />
372
+ * </WalletProvider>
373
+ * );
374
+ * }
375
+ * ```
376
+ */
377
+ declare function WalletProvider({ children, autoConnect, onConnect, onDisconnect, onError, }: WalletProviderProps): JSX.Element;
378
+
379
+ /**
380
+ * usePool Hook
381
+ *
382
+ * Fetches and auto-refreshes pool data from the CPMM program.
383
+ */
384
+
385
+ /**
386
+ * Pool data with loading state
387
+ */
388
+ interface UsePoolResult {
389
+ /** Pool account data (null if not loaded or not found) */
390
+ pool: Pool | null;
391
+ /** Whether the initial load is in progress */
392
+ loading: boolean;
393
+ /** Error that occurred during fetching */
394
+ error: Error | null;
395
+ /** Manually trigger a refetch */
396
+ refetch: () => Promise<void>;
397
+ /** Whether a refetch is in progress */
398
+ refetching: boolean;
399
+ }
400
+ /**
401
+ * Options for usePool hook
402
+ */
403
+ interface UsePoolOptions {
404
+ /** Override auto-refresh interval (ms). Set to 0 to disable. */
405
+ refreshInterval?: number;
406
+ /** Whether to fetch immediately on mount. Default: true */
407
+ fetchOnMount?: boolean;
408
+ /** Commitment level override */
409
+ commitment?: 'processed' | 'confirmed' | 'finalized';
410
+ }
411
+ /**
412
+ * Hook to fetch and auto-refresh pool data
413
+ *
414
+ * @param poolAddress - Address of the pool to fetch
415
+ * @param options - Optional configuration
416
+ * @returns Pool data with loading/error states
417
+ *
418
+ * @example
419
+ * ```tsx
420
+ * function PoolInfo({ poolAddress }: { poolAddress: Address }) {
421
+ * const { pool, loading, error, refetch } = usePool(poolAddress);
422
+ *
423
+ * if (loading) return <div>Loading...</div>;
424
+ * if (error) return <div>Error: {error.message}</div>;
425
+ * if (!pool) return <div>Pool not found</div>;
426
+ *
427
+ * return (
428
+ * <div>
429
+ * <p>Reserve 0: {pool.reserve0.toString()}</p>
430
+ * <p>Reserve 1: {pool.reserve1.toString()}</p>
431
+ * <button onClick={refetch}>Refresh</button>
432
+ * </div>
433
+ * );
434
+ * }
435
+ * ```
436
+ */
437
+ declare function usePool(poolAddress: Address | undefined, options?: UsePoolOptions): UsePoolResult;
438
+ /**
439
+ * Hook to fetch multiple pools
440
+ *
441
+ * @param poolAddresses - Array of pool addresses to fetch
442
+ * @param options - Optional configuration
443
+ * @returns Map of pool address to pool data
444
+ */
445
+ declare function usePools(poolAddresses: Address[], options?: UsePoolOptions): {
446
+ pools: Map<Address, Pool>;
447
+ loading: boolean;
448
+ error: Error | null;
449
+ refetch: () => Promise<void>;
450
+ };
451
+
452
+ /**
453
+ * useSwap Hook
454
+ *
455
+ * Provides swap quote calculations and execution for the CPMM program.
456
+ */
457
+
458
+ /**
459
+ * Swap state
460
+ */
461
+ interface SwapState {
462
+ /** Input token address */
463
+ inputToken: Address | null;
464
+ /** Output token address */
465
+ outputToken: Address | null;
466
+ /** Input amount (raw bigint) */
467
+ inputAmount: bigint;
468
+ /** Output amount (raw bigint) */
469
+ outputAmount: bigint;
470
+ /** Whether input is exact (vs exact output) */
471
+ exactInput: boolean;
472
+ /** Slippage tolerance in basis points */
473
+ slippageBps: number;
474
+ }
475
+ /**
476
+ * Swap quote with additional computed fields
477
+ */
478
+ interface SwapQuoteResult extends SwapQuote {
479
+ /** Minimum output amount (after slippage) */
480
+ minAmountOut: bigint;
481
+ /** Maximum input amount (after slippage, for exact output) */
482
+ maxAmountIn: bigint;
483
+ /** Swap direction (0 = token0->token1, 1 = token1->token0) */
484
+ direction: SwapDirection;
485
+ /** Whether the quote is valid */
486
+ isValid: boolean;
487
+ /** Error message if invalid */
488
+ error: string | null;
489
+ }
490
+ /**
491
+ * Result from useSwap hook
492
+ */
493
+ interface UseSwapResult {
494
+ /** Current swap state */
495
+ state: SwapState;
496
+ /** Computed quote based on current state */
497
+ quote: SwapQuoteResult | null;
498
+ /** Whether a quote calculation is in progress */
499
+ quoting: boolean;
500
+ /** Set input token */
501
+ setInputToken: (token: Address | null) => void;
502
+ /** Set output token */
503
+ setOutputToken: (token: Address | null) => void;
504
+ /** Set input amount */
505
+ setInputAmount: (amount: bigint) => void;
506
+ /** Set output amount (switches to exact output mode) */
507
+ setOutputAmount: (amount: bigint) => void;
508
+ /** Set slippage tolerance */
509
+ setSlippage: (bps: number) => void;
510
+ /** Swap input and output tokens */
511
+ flipTokens: () => void;
512
+ /** Reset all state */
513
+ reset: () => void;
514
+ /** Whether swap can be executed */
515
+ canSwap: boolean;
516
+ }
517
+ /**
518
+ * Options for useSwap hook
519
+ */
520
+ interface UseSwapOptions {
521
+ /** Initial slippage tolerance in basis points (default: 50 = 0.5%) */
522
+ defaultSlippageBps?: number;
523
+ /** Pool to swap on */
524
+ pool: Pool | null;
525
+ /** Token0 mint address */
526
+ token0Mint: Address | null;
527
+ /** Token1 mint address */
528
+ token1Mint: Address | null;
529
+ }
530
+ /**
531
+ * Hook for swap quote calculation and state management
532
+ *
533
+ * @param options - Configuration options
534
+ * @returns Swap state and helpers
535
+ *
536
+ * @example
537
+ * ```tsx
538
+ * function SwapInterface({ pool }: { pool: Pool }) {
539
+ * const {
540
+ * state,
541
+ * quote,
542
+ * setInputAmount,
543
+ * setInputToken,
544
+ * setOutputToken,
545
+ * flipTokens,
546
+ * } = useSwap({
547
+ * pool,
548
+ * token0Mint: pool.token0Mint,
549
+ * token1Mint: pool.token1Mint,
550
+ * });
551
+ *
552
+ * return (
553
+ * <div>
554
+ * <input
555
+ * type="number"
556
+ * onChange={(e) => setInputAmount(BigInt(e.target.value))}
557
+ * />
558
+ * {quote && (
559
+ * <div>
560
+ * Output: {quote.amountOut.toString()}
561
+ * Price Impact: {(quote.priceImpact * 100).toFixed(2)}%
562
+ * </div>
563
+ * )}
564
+ * </div>
565
+ * );
566
+ * }
567
+ * ```
568
+ */
569
+ declare function useSwap(options: UseSwapOptions): UseSwapResult;
570
+
571
+ /**
572
+ * useLiquidity Hook
573
+ *
574
+ * Provides liquidity quote calculations for adding/removing liquidity.
575
+ */
576
+
577
+ /**
578
+ * Liquidity operation mode
579
+ */
580
+ type LiquidityMode = 'add' | 'remove';
581
+ /**
582
+ * Add liquidity state
583
+ */
584
+ interface AddLiquidityState {
585
+ /** Amount of token0 to deposit */
586
+ amount0: bigint;
587
+ /** Amount of token1 to deposit */
588
+ amount1: bigint;
589
+ /** Slippage tolerance in basis points */
590
+ slippageBps: number;
591
+ }
592
+ /**
593
+ * Remove liquidity state
594
+ */
595
+ interface RemoveLiquidityState {
596
+ /** Shares to burn */
597
+ shares: bigint;
598
+ /** Percentage of position to remove (0-100) */
599
+ percentage: number;
600
+ /** Slippage tolerance in basis points */
601
+ slippageBps: number;
602
+ }
603
+ /**
604
+ * Add liquidity quote with computed fields
605
+ */
606
+ interface AddLiquidityQuoteResult extends AddLiquidityQuote {
607
+ /** Minimum shares to receive (after slippage) */
608
+ minSharesOut: bigint;
609
+ /** Whether the quote is valid */
610
+ isValid: boolean;
611
+ /** Error message if invalid */
612
+ error: string | null;
613
+ }
614
+ /**
615
+ * Remove liquidity quote with computed fields
616
+ */
617
+ interface RemoveLiquidityQuoteResult extends RemoveLiquidityQuote {
618
+ /** Minimum token0 to receive (after slippage) */
619
+ minAmount0Out: bigint;
620
+ /** Minimum token1 to receive (after slippage) */
621
+ minAmount1Out: bigint;
622
+ /** Whether the quote is valid */
623
+ isValid: boolean;
624
+ /** Error message if invalid */
625
+ error: string | null;
626
+ }
627
+ /**
628
+ * Result from useLiquidity hook
629
+ */
630
+ interface UseLiquidityResult {
631
+ /** Current mode (add or remove) */
632
+ mode: LiquidityMode;
633
+ /** Set mode */
634
+ setMode: (mode: LiquidityMode) => void;
635
+ /** Add liquidity state */
636
+ addState: AddLiquidityState;
637
+ /** Add liquidity quote */
638
+ addQuote: AddLiquidityQuoteResult | null;
639
+ /** Set amount0 for add */
640
+ setAmount0: (amount: bigint) => void;
641
+ /** Set amount1 for add */
642
+ setAmount1: (amount: bigint) => void;
643
+ /** Whether can add liquidity */
644
+ canAdd: boolean;
645
+ /** Remove liquidity state */
646
+ removeState: RemoveLiquidityState;
647
+ /** Remove liquidity quote */
648
+ removeQuote: RemoveLiquidityQuoteResult | null;
649
+ /** Set shares for remove */
650
+ setShares: (shares: bigint) => void;
651
+ /** Set percentage for remove (calculates shares from position) */
652
+ setPercentage: (percentage: number) => void;
653
+ /** Whether can remove liquidity */
654
+ canRemove: boolean;
655
+ /** Set slippage tolerance */
656
+ setSlippage: (bps: number) => void;
657
+ /** Reset all state */
658
+ reset: () => void;
659
+ }
660
+ /**
661
+ * Options for useLiquidity hook
662
+ */
663
+ interface UseLiquidityOptions {
664
+ /** Pool to add/remove liquidity from */
665
+ pool: Pool | null;
666
+ /** User's current position shares (for remove percentage calculation) */
667
+ userShares?: bigint;
668
+ /** Initial slippage tolerance in basis points (default: 50 = 0.5%) */
669
+ defaultSlippageBps?: number;
670
+ /** Initial mode */
671
+ defaultMode?: LiquidityMode;
672
+ }
673
+ /**
674
+ * Hook for liquidity quote calculation and state management
675
+ *
676
+ * @param options - Configuration options
677
+ * @returns Liquidity state and helpers
678
+ *
679
+ * @example
680
+ * ```tsx
681
+ * function LiquidityInterface({ pool, position }) {
682
+ * const {
683
+ * mode,
684
+ * setMode,
685
+ * addState,
686
+ * addQuote,
687
+ * setAmount0,
688
+ * removeState,
689
+ * removeQuote,
690
+ * setPercentage,
691
+ * } = useLiquidity({
692
+ * pool,
693
+ * userShares: position?.shares,
694
+ * });
695
+ *
696
+ * return (
697
+ * <div>
698
+ * <button onClick={() => setMode('add')}>Add</button>
699
+ * <button onClick={() => setMode('remove')}>Remove</button>
700
+ *
701
+ * {mode === 'add' && addQuote && (
702
+ * <div>Shares out: {addQuote.sharesOut.toString()}</div>
703
+ * )}
704
+ * </div>
705
+ * );
706
+ * }
707
+ * ```
708
+ */
709
+ declare function useLiquidity(options: UseLiquidityOptions): UseLiquidityResult;
710
+
711
+ /**
712
+ * usePosition Hook
713
+ *
714
+ * Fetches and manages user position data from the CPMM program.
715
+ */
716
+
717
+ /**
718
+ * Position data with calculated values
719
+ */
720
+ interface UsePositionResult {
721
+ /** Position account data (null if not loaded or not found) */
722
+ position: Position | null;
723
+ /** Position address */
724
+ positionAddress?: Address;
725
+ /** Whether the initial load is in progress */
726
+ loading: boolean;
727
+ /** Error that occurred during fetching */
728
+ error: Error | null;
729
+ /** Manually trigger a refetch */
730
+ refetch: () => Promise<void>;
731
+ /** Pending uncollected fees */
732
+ pendingFees: {
733
+ pending0: bigint;
734
+ pending1: bigint;
735
+ } | null;
736
+ /** Position value breakdown (requires pool data) */
737
+ value: PositionValue | null;
738
+ }
739
+ /**
740
+ * Options for usePosition hook
741
+ */
742
+ interface UsePositionOptions {
743
+ /** Override auto-refresh interval (ms). Set to 0 to disable. */
744
+ refreshInterval?: number;
745
+ /** Whether to fetch immediately on mount. Default: true */
746
+ fetchOnMount?: boolean;
747
+ /** Commitment level override */
748
+ commitment?: 'processed' | 'confirmed' | 'finalized';
749
+ /** Pool data (if already fetched) to calculate position value */
750
+ pool?: Pool;
751
+ }
752
+ /**
753
+ * Hook to fetch user's position in a pool
754
+ *
755
+ * @param poolAddress - Address of the pool
756
+ * @param positionId - Position ID (default: 0 for first position)
757
+ * @param options - Optional configuration
758
+ * @returns Position data with loading/error states
759
+ *
760
+ * @example
761
+ * ```tsx
762
+ * function MyPosition({ poolAddress }: { poolAddress: Address }) {
763
+ * const { position, loading, error, pendingFees, value } = usePosition(poolAddress);
764
+ *
765
+ * if (loading) return <div>Loading...</div>;
766
+ * if (!position) return <div>No position found</div>;
767
+ *
768
+ * return (
769
+ * <div>
770
+ * <p>Shares: {position.shares.toString()}</p>
771
+ * {pendingFees && (
772
+ * <p>Pending fees: {pendingFees.pending0.toString()} / {pendingFees.pending1.toString()}</p>
773
+ * )}
774
+ * </div>
775
+ * );
776
+ * }
777
+ * ```
778
+ */
779
+ declare function usePosition(poolAddress: Address | undefined, positionId?: bigint, options?: UsePositionOptions): UsePositionResult;
780
+ /**
781
+ * Result for useUserPositions hook
782
+ */
783
+ interface UseUserPositionsResult {
784
+ /** Array of user positions with addresses */
785
+ positions: PositionWithAddress[];
786
+ /** Whether loading */
787
+ loading: boolean;
788
+ /** Error if any */
789
+ error: Error | null;
790
+ /** Manually trigger refetch */
791
+ refetch: () => Promise<void>;
792
+ }
793
+ /**
794
+ * Hook to fetch all positions for the connected user
795
+ *
796
+ * @param poolFilter - Optional pool address to filter positions
797
+ * @param options - Optional configuration
798
+ * @returns Array of user positions
799
+ *
800
+ * @example
801
+ * ```tsx
802
+ * function AllPositions() {
803
+ * const { positions, loading } = useUserPositions();
804
+ *
805
+ * if (loading) return <div>Loading...</div>;
806
+ *
807
+ * return (
808
+ * <ul>
809
+ * {positions.map(({ address, account }) => (
810
+ * <li key={address}>
811
+ * Pool: {account.pool} - Shares: {account.shares.toString()}
812
+ * </li>
813
+ * ))}
814
+ * </ul>
815
+ * );
816
+ * }
817
+ * ```
818
+ */
819
+ declare function useUserPositions(poolFilter?: Address, options?: Omit<UsePositionOptions, 'pool'>): UseUserPositionsResult;
820
+
821
+ /**
822
+ * useFees Hook
823
+ *
824
+ * Calculates and tracks pending fees for a user's position, with collection capability.
825
+ */
826
+
827
+ /**
828
+ * Transaction status
829
+ */
830
+ type TransactionStatus = 'idle' | 'signing' | 'sending' | 'confirming' | 'success' | 'error';
831
+ /**
832
+ * Pending fees data
833
+ */
834
+ interface PendingFees {
835
+ /** Pending fees in token0 */
836
+ pending0: bigint;
837
+ /** Pending fees in token1 */
838
+ pending1: bigint;
839
+ /** Whether there are any fees to collect */
840
+ hasFees: boolean;
841
+ }
842
+ /**
843
+ * Options for collecting fees
844
+ */
845
+ interface CollectFeesOptions {
846
+ /** Maximum amount of token0 to collect (default: all) */
847
+ max0?: bigint;
848
+ /** Maximum amount of token1 to collect (default: all) */
849
+ max1?: bigint;
850
+ /** User's token0 account */
851
+ userToken0: Address;
852
+ /** User's token1 account */
853
+ userToken1: Address;
854
+ }
855
+ /**
856
+ * Result from useFees hook
857
+ */
858
+ interface UseFeesResult {
859
+ /** Pending fees data */
860
+ fees: PendingFees | null;
861
+ /** Whether loading */
862
+ loading: boolean;
863
+ /** Error if any */
864
+ error: Error | null;
865
+ /** Manually trigger refetch */
866
+ refetch: () => Promise<void>;
867
+ /** Whether a refetch is in progress */
868
+ refetching: boolean;
869
+ /** Collect pending fees */
870
+ collect: (options: CollectFeesOptions) => Promise<string>;
871
+ /** Current transaction status */
872
+ status: TransactionStatus;
873
+ /** Transaction error */
874
+ txError: Error | null;
875
+ /** Last transaction signature */
876
+ txSignature: string | null;
877
+ /** Reset transaction status */
878
+ reset: () => void;
879
+ /** Whether fees can be collected */
880
+ canCollect: boolean;
881
+ }
882
+ /**
883
+ * Options for useFees hook
884
+ */
885
+ interface UseFeesOptions {
886
+ /** Override auto-refresh interval (ms). Set to 0 to disable. */
887
+ refreshInterval?: number;
888
+ /** Whether to fetch immediately on mount. Default: true */
889
+ fetchOnMount?: boolean;
890
+ /** Commitment level override */
891
+ commitment?: 'processed' | 'confirmed' | 'finalized';
892
+ /** Pre-fetched pool data */
893
+ pool?: Pool | null;
894
+ /** Pre-fetched position data */
895
+ position?: Position | null;
896
+ }
897
+ /**
898
+ * Hook to calculate and track pending fees for a position
899
+ *
900
+ * @param positionAddress - Address of the position
901
+ * @param poolAddress - Address of the pool (needed if position not provided)
902
+ * @param options - Optional configuration
903
+ * @returns Pending fees with loading/error states
904
+ *
905
+ * @example
906
+ * ```tsx
907
+ * function PositionFees({ positionAddress, poolAddress }: Props) {
908
+ * const { fees, loading, refetch } = useFees(positionAddress, poolAddress);
909
+ *
910
+ * if (loading) return <div>Loading...</div>;
911
+ * if (!fees) return <div>No fees data</div>;
912
+ *
913
+ * return (
914
+ * <div>
915
+ * <p>Token0 fees: {fees.pending0.toString()}</p>
916
+ * <p>Token1 fees: {fees.pending1.toString()}</p>
917
+ * {fees.hasFees && <button onClick={() => {}}>Collect Fees</button>}
918
+ * <button onClick={refetch}>Refresh</button>
919
+ * </div>
920
+ * );
921
+ * }
922
+ * ```
923
+ */
924
+ declare function useFees(positionAddress: Address | undefined, poolAddress: Address | undefined, options?: UseFeesOptions): UseFeesResult;
925
+ /**
926
+ * Hook to calculate fees from pre-fetched data (no RPC calls)
927
+ *
928
+ * @param pool - Pool data
929
+ * @param position - Position data
930
+ * @returns Pending fees
931
+ */
932
+ declare function useFeesFromData(pool: Pool | null | undefined, position: Position | null | undefined): PendingFees | null;
933
+
934
+ /**
935
+ * useOracle Hook
936
+ *
937
+ * Fetches oracle data and provides TWAP calculations for CPMM pools.
938
+ */
939
+
940
+ /**
941
+ * Oracle data with computed metrics
942
+ */
943
+ interface UseOracleResult {
944
+ /** Oracle state data (null if not loaded or not initialized) */
945
+ oracle: OracleState | null;
946
+ /** Oracle account address */
947
+ oracleAddress: Address | null;
948
+ /** Whether the initial load is in progress */
949
+ loading: boolean;
950
+ /** Error that occurred during fetching */
951
+ error: Error | null;
952
+ /** Manually trigger a refetch */
953
+ refetch: () => Promise<void>;
954
+ /** Calculate TWAP for a given window (seconds) */
955
+ twap: (windowSeconds: number) => TwapResult | null;
956
+ /** Current spot prices from oracle */
957
+ spotPrice: {
958
+ price0: number;
959
+ price1: number;
960
+ } | null;
961
+ /** Price deviation metrics */
962
+ deviation: {
963
+ deviation0: number;
964
+ deviation1: number;
965
+ } | null;
966
+ /** Oracle age in seconds */
967
+ age: number | null;
968
+ /** Whether oracle is stale */
969
+ isStale: (maxAgeSeconds: number) => boolean;
970
+ /** Buffer statistics */
971
+ bufferStats: {
972
+ capacity: number;
973
+ filledCount: number;
974
+ currentIndex: number;
975
+ timeSpanSeconds: number;
976
+ } | null;
977
+ /** Compare oracle price with pool spot price (requires pool data) */
978
+ compareWithPool: (pool: Pool) => {
979
+ poolPrice0: number;
980
+ oraclePrice0: number;
981
+ divergencePct: number;
982
+ } | null;
983
+ }
984
+ /**
985
+ * Options for useOracle hook
986
+ */
987
+ interface UseOracleOptions {
988
+ /** Override auto-refresh interval (ms). Set to 0 to disable. */
989
+ refreshInterval?: number;
990
+ /** Whether to fetch immediately on mount. Default: true */
991
+ fetchOnMount?: boolean;
992
+ /** Commitment level override */
993
+ commitment?: 'processed' | 'confirmed' | 'finalized';
994
+ }
995
+ /**
996
+ * Hook to fetch oracle data and calculate TWAPs
997
+ *
998
+ * @param poolAddress - Address of the pool (oracle is derived from pool)
999
+ * @param options - Optional configuration
1000
+ * @returns Oracle data with TWAP calculations
1001
+ *
1002
+ * @example
1003
+ * ```tsx
1004
+ * function OracleInfo({ poolAddress }: { poolAddress: Address }) {
1005
+ * const { oracle, loading, twap, spotPrice, age, isStale } = useOracle(poolAddress);
1006
+ *
1007
+ * if (loading) return <div>Loading oracle...</div>;
1008
+ * if (!oracle) return <div>Oracle not initialized</div>;
1009
+ *
1010
+ * const twap5min = twap(300); // 5-minute TWAP
1011
+ *
1012
+ * return (
1013
+ * <div>
1014
+ * <p>Spot Price: {spotPrice?.price0.toFixed(6)}</p>
1015
+ * <p>5min TWAP: {twap5min?.price0.toFixed(6)}</p>
1016
+ * <p>Oracle Age: {age}s {isStale(60) && '(STALE)'}</p>
1017
+ * </div>
1018
+ * );
1019
+ * }
1020
+ * ```
1021
+ */
1022
+ declare function useOracle(poolAddress: Address | undefined, options?: UseOracleOptions): UseOracleResult;
1023
+ /**
1024
+ * Hook to get TWAP for a specific window with automatic updates
1025
+ *
1026
+ * @param poolAddress - Pool address
1027
+ * @param windowSeconds - TWAP window in seconds
1028
+ * @param options - Optional configuration
1029
+ */
1030
+ declare function useTwap(poolAddress: Address | undefined, windowSeconds: number, options?: UseOracleOptions): {
1031
+ twap: TwapResult | null;
1032
+ loading: boolean;
1033
+ error: Error | null;
1034
+ refetch: () => Promise<void>;
1035
+ };
1036
+ /**
1037
+ * Hook to fetch oracle data for multiple pools
1038
+ */
1039
+ declare function useOracles(poolAddresses: Address[], options?: UseOracleOptions): {
1040
+ oracles: Map<Address, OracleWithAddress>;
1041
+ loading: boolean;
1042
+ error: Error | null;
1043
+ refetch: () => Promise<void>;
1044
+ };
1045
+
1046
+ export { type AddLiquidityQuoteResult, type AddLiquidityState, type AmmConfig, AmmContext$1 as AmmContext, type AmmContextConfig, type AmmContextValue$1 as AmmContextValue, AmmProvider$1 as AmmProvider, type AmmProviderProps$1 as AmmProviderProps, type CollectFeesOptions, type Commitment, AmmContext as EndpointAmmContext, type AmmContextValue as EndpointAmmContextValue, AmmProvider as EndpointAmmProvider, type AmmProviderProps as EndpointAmmProviderProps, type LiquidityMode, type PendingFees, type RemoveLiquidityQuoteResult, type RemoveLiquidityState, type SolanaWallet, type SwapQuoteResult, type SwapState, type TransactionStatus, type UseFeesOptions, type UseFeesResult, type UseLiquidityOptions, type UseLiquidityResult, type UseOracleOptions, type UseOracleResult, type UsePoolOptions, type UsePoolResult, type UsePositionOptions, type UsePositionResult, type UseSwapOptions, type UseSwapResult, type UseUserPositionsResult, WalletContext$1 as WalletContext, type WalletContextValue$1 as WalletContextValue, WalletProvider$1 as WalletProvider, type WalletProviderProps$1 as WalletProviderProps, WalletContext as WalletStandardContext, type WalletContextValue as WalletStandardContextValue, WalletProvider as WalletStandardProvider, type WalletProviderProps as WalletStandardProviderProps, type WalletState, createAmmContextValue, createWalletContextValue, useAmm$1 as useAmm, useAmmOptional, useAmm as useEndpointAmm, useFees, useFeesFromData, useLiquidity, useOracle, useOracles, usePool, usePools, usePosition, useWallet as useStandardWallet, useSwap, useTwap, useUserPositions, useWallet$1 as useWallet, useWalletAddress, useWalletOptional };