hyperliquid-deposit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # @aspect-build/hyperliquid-deposit
2
+
3
+ One-click deposit to HyperLiquid trading account from any chain. Automatically bridges tokens to Arbitrum USDC and deposits to HyperLiquid.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@aspect-build/hyperliquid-deposit.svg)](https://www.npmjs.com/package/@aspect-build/hyperliquid-deposit)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - 🚀 **One-Click Deposits** - Deposit to HyperLiquid from any supported chain
11
+ - 🌉 **Auto-Bridging** - Automatically bridges tokens to Arbitrum USDC via LI.FI
12
+ - 💰 **Multi-Chain Support** - Supports 60+ chains including Ethereum, Arbitrum, Base, Monad, etc.
13
+ - 🎯 **Smart Routing** - Finds optimal routes considering fees, speed, and gas
14
+ - ⚛️ **React Component** - Drop-in React component with TypeScript support
15
+ - 🎨 **Customizable** - Custom button rendering, styles, and callbacks
16
+ - 📱 **Responsive** - Works on desktop and mobile
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # npm
22
+ npm install @aspect-build/hyperliquid-deposit
23
+
24
+ # yarn
25
+ yarn add @aspect-build/hyperliquid-deposit
26
+
27
+ # bun
28
+ bun add @aspect-build/hyperliquid-deposit
29
+
30
+ # pnpm
31
+ pnpm add @aspect-build/hyperliquid-deposit
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ### Basic Usage
37
+
38
+ ```tsx
39
+ import { HyperliquidDeposit } from '@aspect-build/hyperliquid-deposit';
40
+
41
+ function App() {
42
+ return (
43
+ <HyperliquidDeposit
44
+ walletAddress="0x..." // Connected wallet address
45
+ onDepositComplete={(txHash, amount) => {
46
+ console.log(`Deposited $${amount} USDC! Tx: ${txHash}`);
47
+ }}
48
+ />
49
+ );
50
+ }
51
+ ```
52
+
53
+ ### With Custom Button
54
+
55
+ ```tsx
56
+ import { HyperliquidDeposit } from '@aspect-build/hyperliquid-deposit';
57
+
58
+ function App() {
59
+ return (
60
+ <HyperliquidDeposit
61
+ walletAddress={address}
62
+ renderButton={({ onClick, disabled }) => (
63
+ <button
64
+ onClick={onClick}
65
+ disabled={disabled}
66
+ className="my-custom-button"
67
+ >
68
+ 💰 Fund Trading Account
69
+ </button>
70
+ )}
71
+ />
72
+ );
73
+ }
74
+ ```
75
+
76
+ ### Using the Hook
77
+
78
+ ```tsx
79
+ import { useHyperliquidDeposit } from '@aspect-build/hyperliquid-deposit';
80
+
81
+ function App() {
82
+ const { openDeposit, DepositModal } = useHyperliquidDeposit({
83
+ walletAddress: '0x...',
84
+ });
85
+
86
+ return (
87
+ <>
88
+ <button onClick={openDeposit}>
89
+ Open Deposit Modal
90
+ </button>
91
+ <DepositModal />
92
+ </>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ### Standalone Modal
98
+
99
+ ```tsx
100
+ import { DepositModal } from '@aspect-build/hyperliquid-deposit';
101
+
102
+ function App() {
103
+ const [isOpen, setIsOpen] = useState(false);
104
+
105
+ return (
106
+ <>
107
+ <button onClick={() => setIsOpen(true)}>Deposit</button>
108
+
109
+ {isOpen && (
110
+ <DepositModal
111
+ chains={chains}
112
+ walletAddress="0x..."
113
+ onClose={() => setIsOpen(false)}
114
+ />
115
+ )}
116
+ </>
117
+ );
118
+ }
119
+ ```
120
+
121
+ ## API Reference
122
+
123
+ ### `<HyperliquidDeposit />`
124
+
125
+ Main component that renders a deposit button and modal.
126
+
127
+ | Prop | Type | Required | Description |
128
+ |------|------|----------|-------------|
129
+ | `walletAddress` | `string` | ✅ | Connected wallet address |
130
+ | `chains` | `ChainInfo[]` | ❌ | Custom chains (auto-fetched if not provided) |
131
+ | `onDepositComplete` | `(txHash: string, amount: number) => void` | ❌ | Callback on successful deposit |
132
+ | `onDepositError` | `(error: string) => void` | ❌ | Callback on deposit error |
133
+ | `renderButton` | `(props: { onClick, disabled }) => ReactNode` | ❌ | Custom button renderer |
134
+ | `buttonText` | `string` | ❌ | Button text (default: "Deposit to HyperLiquid") |
135
+ | `buttonStyle` | `CSSProperties` | ❌ | Custom button styles |
136
+ | `buttonClassName` | `string` | ❌ | Custom button class name |
137
+ | `disabled` | `boolean` | ❌ | Disable the button |
138
+ | `modalStyles` | `{ modal?, overlay? }` | ❌ | Custom modal styles |
139
+
140
+ ### `useHyperliquidDeposit()`
141
+
142
+ Hook for programmatic control.
143
+
144
+ ```tsx
145
+ const {
146
+ isOpen, // boolean - modal open state
147
+ openDeposit, // () => void - open the modal
148
+ closeDeposit, // () => void - close the modal
149
+ DepositModal, // React component - the modal
150
+ } = useHyperliquidDeposit(props);
151
+ ```
152
+
153
+ ### Constants
154
+
155
+ ```tsx
156
+ import {
157
+ HYPERLIQUID_BRIDGE_ADDRESS, // HyperLiquid bridge contract on Arbitrum
158
+ MIN_HYPERLIQUID_DEPOSIT_USD // Minimum deposit ($5)
159
+ } from '@aspect-build/hyperliquid-deposit';
160
+ ```
161
+
162
+ ## How It Works
163
+
164
+ 1. **User enters amount** - e.g., $50 USDC
165
+ 2. **Scans balances** - Checks all chains for available tokens
166
+ 3. **Calculates optimal route** - Finds best bridges considering fees & speed
167
+ 4. **Executes bridges** - Bridges tokens to Arbitrum USDC
168
+ 5. **Deposits to HyperLiquid** - Transfers USDC to HyperLiquid bridge contract
169
+
170
+ ```
171
+ Your Wallet (any chain)
172
+
173
+ [LI.FI Bridge]
174
+
175
+ Arbitrum USDC
176
+
177
+ HyperLiquid Bridge Contract
178
+
179
+ HyperLiquid Trading Account
180
+ ```
181
+
182
+ ## Supported Chains
183
+
184
+ The component automatically fetches supported chains from LI.FI, including:
185
+
186
+ - Ethereum, Arbitrum, Base, Optimism, Polygon
187
+ - BSC, Avalanche, Fantom, Gnosis
188
+ - Monad, HyperEVM, Linea, zkSync, Scroll
189
+ - And 50+ more...
190
+
191
+ ## Requirements
192
+
193
+ - React 18+
194
+ - MetaMask or compatible Web3 wallet
195
+ - Tokens on any supported chain
196
+
197
+ ## Development
198
+
199
+ ```bash
200
+ # Install dependencies
201
+ bun install
202
+
203
+ # Build
204
+ bun run build
205
+
206
+ # Watch mode
207
+ bun run build:watch
208
+
209
+ # Run example
210
+ bun run dev:example
211
+ ```
212
+
213
+ ## License
214
+
215
+ MIT
@@ -0,0 +1,321 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React, { CSSProperties } from 'react';
3
+ import { LiFiStep } from '@lifi/sdk';
4
+
5
+ interface ChainInfo {
6
+ id: number;
7
+ name: string;
8
+ key: string;
9
+ chainType: string;
10
+ logoURI?: string;
11
+ nativeToken: {
12
+ symbol: string;
13
+ decimals: number;
14
+ address: string;
15
+ };
16
+ }
17
+ interface TokenInfo {
18
+ address: string;
19
+ symbol: string;
20
+ decimals: number;
21
+ chainId: number;
22
+ name: string;
23
+ logoURI?: string;
24
+ }
25
+ interface WalletState {
26
+ address: string | null;
27
+ chainId: number | null;
28
+ isConnected: boolean;
29
+ }
30
+ interface TokenBalance {
31
+ chainId: number;
32
+ chainName: string;
33
+ balance: string;
34
+ formattedBalance: string;
35
+ symbol: string;
36
+ tokenAddress: string;
37
+ }
38
+ interface ChainBalance extends TokenBalance {
39
+ chain: ChainInfo;
40
+ }
41
+
42
+ interface HyperliquidDepositProps {
43
+ /**
44
+ * Wallet address to deposit from
45
+ */
46
+ walletAddress: string;
47
+ /**
48
+ * Optional: Custom chains to support. If not provided, uses LI.FI supported chains.
49
+ */
50
+ chains?: ChainInfo[];
51
+ /**
52
+ * Optional: Callback when deposit is completed
53
+ */
54
+ onDepositComplete?: (txHash: string, amountUSDC: number) => void;
55
+ /**
56
+ * Optional: Callback when deposit fails
57
+ */
58
+ onDepositError?: (error: string) => void;
59
+ /**
60
+ * Optional: Custom button render function. If not provided, uses default button.
61
+ */
62
+ renderButton?: (props: {
63
+ onClick: () => void;
64
+ disabled: boolean;
65
+ }) => React.ReactNode;
66
+ /**
67
+ * Optional: Button text (only used with default button)
68
+ */
69
+ buttonText?: string;
70
+ /**
71
+ * Optional: Custom styles for the button (only used with default button)
72
+ */
73
+ buttonStyle?: React.CSSProperties;
74
+ /**
75
+ * Optional: Custom class name for the button (only used with default button)
76
+ */
77
+ buttonClassName?: string;
78
+ /**
79
+ * Optional: Disable the button
80
+ */
81
+ disabled?: boolean;
82
+ /**
83
+ * Optional: Custom modal styles
84
+ */
85
+ modalStyles?: {
86
+ modal?: React.CSSProperties;
87
+ overlay?: React.CSSProperties;
88
+ };
89
+ }
90
+ /**
91
+ * HyperliquidDeposit - A one-click deposit button for HyperLiquid
92
+ *
93
+ * This component provides a button that opens a modal to deposit funds
94
+ * from any supported chain to your HyperLiquid trading account.
95
+ *
96
+ * @example
97
+ * ```tsx
98
+ * import { HyperliquidDeposit } from '@aspect-build/hyperliquid-deposit';
99
+ *
100
+ * function App() {
101
+ * return (
102
+ * <HyperliquidDeposit
103
+ * walletAddress="0x..."
104
+ * onDepositComplete={(txHash, amount) => {
105
+ * console.log(`Deposited $${amount} USDC. Tx: ${txHash}`);
106
+ * }}
107
+ * />
108
+ * );
109
+ * }
110
+ * ```
111
+ */
112
+ declare const HyperliquidDeposit: React.FC<HyperliquidDepositProps>;
113
+ /**
114
+ * useHyperliquidDeposit - Hook for programmatic control
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * const { openDeposit, DepositModal } = useHyperliquidDeposit({
119
+ * walletAddress: '0x...',
120
+ * });
121
+ *
122
+ * return (
123
+ * <>
124
+ * <button onClick={openDeposit}>Custom Button</button>
125
+ * <DepositModal />
126
+ * </>
127
+ * );
128
+ * ```
129
+ */
130
+ declare const useHyperliquidDeposit: (props: Omit<HyperliquidDepositProps, "renderButton" | "buttonText" | "buttonStyle" | "buttonClassName">) => {
131
+ isOpen: boolean;
132
+ openDeposit: () => void;
133
+ closeDeposit: () => void;
134
+ DepositModal: () => react_jsx_runtime.JSX.Element | null;
135
+ };
136
+
137
+ interface DepositModalProps {
138
+ chains: ChainInfo[];
139
+ walletAddress: string;
140
+ onClose: () => void;
141
+ embedded?: boolean;
142
+ styles?: {
143
+ modal?: React.CSSProperties;
144
+ overlay?: React.CSSProperties;
145
+ };
146
+ }
147
+ declare const DepositModal: React.FC<DepositModalProps>;
148
+
149
+ declare const HYPERLIQUID_BRIDGE_ADDRESS = "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7";
150
+ declare const MIN_HYPERLIQUID_DEPOSIT_USD = 5;
151
+
152
+ interface BridgeWidgetStyles {
153
+ container?: CSSProperties;
154
+ connectButton?: CSSProperties;
155
+ bridgeButton?: CSSProperties;
156
+ walletInfo?: CSSProperties;
157
+ modal?: {
158
+ overlay?: CSSProperties;
159
+ content?: CSSProperties;
160
+ header?: CSSProperties;
161
+ closeButton?: CSSProperties;
162
+ body?: CSSProperties;
163
+ };
164
+ balanceItem?: CSSProperties;
165
+ chainInfo?: CSSProperties;
166
+ bridgeFromButton?: CSSProperties;
167
+ infoBox?: CSSProperties;
168
+ }
169
+
170
+ interface HyprBridgeWidgetProps {
171
+ styles?: BridgeWidgetStyles;
172
+ }
173
+ declare const HyprBridgeWidget: React.FC<HyprBridgeWidgetProps>;
174
+
175
+ interface SearchableToken {
176
+ symbol: string;
177
+ name: string;
178
+ address: string;
179
+ chainId: number;
180
+ decimals: number;
181
+ logoURI?: string;
182
+ priceUSD?: string;
183
+ }
184
+ declare class TokenSearchService {
185
+ private tokenCache;
186
+ private cacheTimestamp;
187
+ private readonly CACHE_DURATION;
188
+ /**
189
+ * Get all tradeable tokens for a specific chain
190
+ */
191
+ getTokensForChain(chainId: number): Promise<SearchableToken[]>;
192
+ /**
193
+ * Get only popular/whitelisted tokens for a chain (for default display)
194
+ * These are the top 200 tokens by market cap that exist on this chain
195
+ * Tokens with logos appear first, sorted by market cap rank
196
+ * Tokens without logos appear at the end
197
+ */
198
+ getPopularTokensForChain(chainId: number): Promise<SearchableToken[]>;
199
+ /**
200
+ * Search tokens by name or symbol on a specific chain
201
+ * This searches ALL tokens, not just popular ones
202
+ */
203
+ searchTokens(chainId: number, query: string): Promise<SearchableToken[]>;
204
+ /**
205
+ * Get token by exact address on a specific chain
206
+ */
207
+ getTokenByAddress(chainId: number, address: string): Promise<SearchableToken | null>;
208
+ /**
209
+ * Get token by symbol on a specific chain
210
+ */
211
+ getTokenBySymbol(chainId: number, symbol: string): Promise<SearchableToken | null>;
212
+ /**
213
+ * Get popular tokens for a chain (USDC, USDT, ETH, WBTC, etc.)
214
+ */
215
+ getPopularTokens(chainId: number): Promise<SearchableToken[]>;
216
+ /**
217
+ * Clear cache for a specific chain or all chains
218
+ */
219
+ clearCache(chainId?: number): void;
220
+ private mapToSearchableToken;
221
+ }
222
+
223
+ interface ChainTokenSelectorProps {
224
+ chains: ChainInfo[];
225
+ onSelect: (chain: ChainInfo, token: SearchableToken) => void;
226
+ onClose: () => void;
227
+ initialChainId?: number;
228
+ walletAddress?: string;
229
+ styles?: {
230
+ modal?: React.CSSProperties;
231
+ overlay?: React.CSSProperties;
232
+ };
233
+ }
234
+ declare const ChainTokenSelector: React.FC<ChainTokenSelectorProps>;
235
+
236
+ declare global {
237
+ interface Window {
238
+ ethereum?: any;
239
+ }
240
+ }
241
+ interface BridgeProgress {
242
+ status: 'idle' | 'approving' | 'pending' | 'completed' | 'failed';
243
+ message: string;
244
+ txHash?: string;
245
+ txLink?: string;
246
+ }
247
+ interface StepInfo {
248
+ id: string;
249
+ tool: string;
250
+ toolName: string;
251
+ toolLogo: string;
252
+ type: string;
253
+ status: 'waiting' | 'action_required' | 'pending' | 'done' | 'failed';
254
+ progress: number;
255
+ txHash?: string;
256
+ txLink?: string;
257
+ }
258
+ interface DetailedBridgeProgress {
259
+ overallStatus: 'idle' | 'approving' | 'pending' | 'completed' | 'failed';
260
+ message: string;
261
+ steps: StepInfo[];
262
+ txHash?: string;
263
+ txLink?: string;
264
+ }
265
+ declare class LiFiBridgeService {
266
+ private chains;
267
+ constructor();
268
+ private initializeLiFi;
269
+ getAllChains(): Promise<ChainInfo[]>;
270
+ getTokenInfo(chainId: number, tokenSymbol?: string): Promise<TokenInfo | null>;
271
+ getBridgeRoute(fromChainId: number, toChainId: number, tokenAmount: string, userAddress: string, tokenSymbol?: string): Promise<LiFiStep>;
272
+ /**
273
+ * Get bridge route with specific token addresses (for dynamic source/destination)
274
+ */
275
+ getBridgeRouteWithTokens(fromChainId: number, toChainId: number, fromTokenAddress: string, toTokenAddress: string, tokenAmount: string, userAddress: string): Promise<LiFiStep>;
276
+ executeBridge(quote: LiFiStep, onProgress: (progress: BridgeProgress) => void): Promise<void>;
277
+ private getStatusMessage;
278
+ /**
279
+ * Execute bridge with detailed step-by-step progress for status page
280
+ */
281
+ executeBridgeWithDetailedProgress(quote: LiFiStep, onDetailedProgress: (progress: DetailedBridgeProgress) => void): Promise<void>;
282
+ /**
283
+ * Get token price in USD
284
+ * Returns the current USD price for a token on a specific chain
285
+ */
286
+ getTokenPrice(chainId: number, tokenAddress: string): Promise<number | null>;
287
+ }
288
+
289
+ interface BridgeParams {
290
+ fromChainId: number;
291
+ toChainId: number;
292
+ fromToken: SearchableToken;
293
+ toToken: SearchableToken;
294
+ amount: string;
295
+ }
296
+
297
+ /**
298
+ * Top 200 tokens by market cap (CoinGecko ranking as of 2024)
299
+ * These tokens are shown by default when a user selects a chain.
300
+ * The list is ordered by market cap rank.
301
+ *
302
+ * Format: Symbol -> Rank (lower = higher market cap)
303
+ */
304
+ declare const TOP_TOKENS_BY_MARKETCAP: Map<string, number>;
305
+ /**
306
+ * Check if a token is in the top tokens list
307
+ */
308
+ declare function isTopToken(symbol: string): boolean;
309
+ /**
310
+ * Get the market cap rank of a token (lower = higher market cap)
311
+ * Returns Infinity if not in the list
312
+ */
313
+ declare function getTokenRank(symbol: string): number;
314
+ /**
315
+ * Sort tokens by market cap rank
316
+ */
317
+ declare function sortByMarketCap<T extends {
318
+ symbol: string;
319
+ }>(tokens: T[]): T[];
320
+
321
+ export { type BridgeParams, type BridgeProgress, type BridgeWidgetStyles, type ChainBalance, type ChainInfo, ChainTokenSelector, DepositModal, type DetailedBridgeProgress, HYPERLIQUID_BRIDGE_ADDRESS, HyperliquidDeposit, type HyperliquidDepositProps, HyprBridgeWidget, type HyprBridgeWidgetProps, LiFiBridgeService, MIN_HYPERLIQUID_DEPOSIT_USD, type SearchableToken, type StepInfo, TOP_TOKENS_BY_MARKETCAP, TokenSearchService, type WalletState, getTokenRank, isTopToken, sortByMarketCap, useHyperliquidDeposit };