@liberfi.io/ui-perpetuals 0.2.0 → 0.2.2
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 +125 -0
- package/dist/index.d.mts +1064 -27
- package/dist/index.d.ts +1064 -27
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -51,6 +51,12 @@ Required peer dependencies:
|
|
|
51
51
|
- `TradeHistorySkeleton()`
|
|
52
52
|
- `TradeHistoryEmpty()`
|
|
53
53
|
- `PerpetualsProvider(props: PerpetualsProviderProps)`
|
|
54
|
+
- `DepositFormUI(props: DepositFormUIProps)` — pure deposit form (amount + recipient)
|
|
55
|
+
- `DepositConfirmUI(props: DepositConfirmUIProps)` — quote confirmation modal with expiry countdown
|
|
56
|
+
- `DepositStatusUI(props: DepositStatusUIProps)` — terminal status modal (settled / refunded / failed)
|
|
57
|
+
- `DepositFlowWidget(props: DepositFlowWidgetProps)` — orchestrates form + confirm + status with hooks
|
|
58
|
+
- `HyperliquidInitUI(props: HyperliquidInitUIProps)` — first-run setup checklist (builder fee / referrer / leverage)
|
|
59
|
+
- `HyperliquidInitWidget(props: HyperliquidInitWidgetProps)` — wires the checklist to `useHyperliquidSetup`
|
|
54
60
|
|
|
55
61
|
### Hooks
|
|
56
62
|
|
|
@@ -67,6 +73,13 @@ Required peer dependencies:
|
|
|
67
73
|
- Component script hooks:
|
|
68
74
|
- `useCoinInfo`, `useSearchCoinsScript`, `useOrderBookScript`, `useTradesScript`
|
|
69
75
|
- `usePlaceOrderFormScript`, `usePositionsScript`, `useOpenOrdersScript`, `useTradeHistoryScript`
|
|
76
|
+
- Deposit hooks (Solana → Hyperliquid USDC):
|
|
77
|
+
- `usePerpDepositClient` — accessor for the deposit REST client from `PerpetualsProvider`
|
|
78
|
+
- `usePerpDepositQuote` — TanStack Query wrapper around `POST /v1/deposits/quote`
|
|
79
|
+
- `usePerpDepositExecute` — orchestrates `quote → sign → broadcast → submit` via the `DepositState` FSM
|
|
80
|
+
- `usePerpDepositStatus` — long-poll `GET /v1/deposits/{id}` until terminal
|
|
81
|
+
- Hyperliquid first-run setup:
|
|
82
|
+
- `useHyperliquidSetup` — runs `approveBuilderFee`, `setReferrer`, and `updateLeverage` idempotently against an injected `IHyperliquidSetupAdapter`
|
|
70
83
|
- Also exported helpers from hook modules:
|
|
71
84
|
- Query keys and fetchers such as `coinsQueryKey`/`fetchCoins`, `marketQueryKey`/`fetchMarket`, `ordersQueryKey`/`fetchOrders`, etc.
|
|
72
85
|
- Trade operation helpers: `createOrder`, `cancelOrder`.
|
|
@@ -75,12 +88,30 @@ Required peer dependencies:
|
|
|
75
88
|
|
|
76
89
|
- `HyperliquidPerpetualsClient` class implementing `IPerpetualsClient`.
|
|
77
90
|
- `usePerpetualsClient()` as the context accessor utility.
|
|
91
|
+
- `LiberFiHttpTransport` — shared HTTP layer (used by every LiberFi REST client; injectable for testing).
|
|
92
|
+
- `LiberFiPerpetualsClient` — REST client over LiberFi-managed perpetuals (talks to perpetuals-server).
|
|
93
|
+
- `LiberFiPerpDepositClient` — REST client over `/v1/deposits/*` (quote / submit / status / refresh).
|
|
94
|
+
- Deposit state machine (pure functions) — `reduceDepositState`, `initialDepositState`, `isDepositTerminal`, `isDepositPolling`, `currentDepositStatus`, `currentDepositBreakdown`, `isTerminalDepositLifecycle`.
|
|
95
|
+
- Hyperliquid setup state machine (pure functions) — `reduceSetupState`, `initialSetupState`, `classifyStep`, `nextRunnableStep`.
|
|
78
96
|
|
|
79
97
|
### Types & Enums
|
|
80
98
|
|
|
81
99
|
- Client-related:
|
|
82
100
|
- `IPerpetualsClient`, `HyperliquidClientConfig`, `HyperliquidEnvironment`, `HyperliquidApiError`
|
|
83
101
|
- `PerpetualsContextValue`, `PerpetualsProviderProps`
|
|
102
|
+
- `LiberFiHttpTransportConfig`, `LiberFiHttpMethod`, `LiberFiHttpRequestOptions`, `LiberFiApiError`
|
|
103
|
+
- `LiberFiPerpetualsClientConfig`, `SignTypedDataFn`
|
|
104
|
+
- `IPerpDepositClient`, `LiberFiPerpDepositClientConfig`
|
|
105
|
+
- Deposit (Solana → Hyperliquid):
|
|
106
|
+
- `DepositSource`, `DepositStatus`, `DepositErrorInfo`, `DepositStatusTransition`, `DepositBreakdown`
|
|
107
|
+
- `DepositQuoteRequest`, `DepositQuoteResponse`, `DepositSubmitRequest`, `DepositSubmitResponse`, `DepositStatusResponse`
|
|
108
|
+
- `DepositPhase`, `DepositState`, `DepositEvent`
|
|
109
|
+
- `TERMINAL_DEPOSIT_STATUSES`
|
|
110
|
+
- Hyperliquid setup:
|
|
111
|
+
- `IHyperliquidSetupAdapter`, `HyperliquidAccountState`, `HyperliquidSetupActionResult`
|
|
112
|
+
- `ApproveBuilderFeeParams`, `SetReferrerParams`, `UpdateLeverageParams`
|
|
113
|
+
- `SetupStep`, `SetupStepId`, `StepRecord`, `StepStatus`, `SetupPhase`, `SetupState`, `SetupAction`
|
|
114
|
+
- `UseHyperliquidSetupOptions`, `UseHyperliquidSetupResult`
|
|
84
115
|
- Domain enums/types:
|
|
85
116
|
- `Symbol`, `TradingProvider`, `OrderSide`, `OrderType`, `OrderStatus`, `KlineInterval`, `TradeSide`
|
|
86
117
|
- Domain entities:
|
|
@@ -139,8 +170,102 @@ const methods = useForm<PlaceOrderFormData>({
|
|
|
139
170
|
// Pass methods directly to PlaceOrderFormUI if you build your own container.
|
|
140
171
|
```
|
|
141
172
|
|
|
173
|
+
### Deposit (Solana → Hyperliquid USDC)
|
|
174
|
+
|
|
175
|
+
The deposit flow is a single end-to-end widget plus three presentational
|
|
176
|
+
components for callers that want a custom layout. The widget consumes
|
|
177
|
+
the deposit client via `PerpetualsProvider` and delegates wallet signing
|
|
178
|
+
to the host application.
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import {
|
|
182
|
+
DepositFlowWidget,
|
|
183
|
+
HyperliquidPerpetualsClient,
|
|
184
|
+
LiberFiHttpTransport,
|
|
185
|
+
LiberFiPerpDepositClient,
|
|
186
|
+
PerpetualsProvider,
|
|
187
|
+
} from "@liberfi.io/ui-perpetuals";
|
|
188
|
+
|
|
189
|
+
const transport = new LiberFiHttpTransport({
|
|
190
|
+
baseUrl: process.env.NEXT_PUBLIC_PERPETUALS_API!,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const perpetualsClient = new HyperliquidPerpetualsClient({
|
|
194
|
+
environment: "mainnet",
|
|
195
|
+
});
|
|
196
|
+
const depositClient = new LiberFiPerpDepositClient({ transport });
|
|
197
|
+
|
|
198
|
+
export function DepositPanel({ wallet }: { wallet: SolanaWalletAdapter }) {
|
|
199
|
+
return (
|
|
200
|
+
<PerpetualsProvider client={perpetualsClient} depositClient={depositClient}>
|
|
201
|
+
<DepositFlowWidget
|
|
202
|
+
userSolanaAddress={wallet.publicKey.toBase58()}
|
|
203
|
+
userId={user.id}
|
|
204
|
+
source="dex"
|
|
205
|
+
defaultRecipient={user.evmAddress}
|
|
206
|
+
signAndBroadcast={async (txBase64) => wallet.signAndSend(txBase64)}
|
|
207
|
+
buildSolanaExplorerUrl={(h) => `https://solscan.io/tx/${h}`}
|
|
208
|
+
buildHyperliquidExplorerUrl={(h) =>
|
|
209
|
+
`https://app.hyperliquid.xyz/explorer/tx/${h}`
|
|
210
|
+
}
|
|
211
|
+
onSettled={(intentId) => console.log("settled", intentId)}
|
|
212
|
+
/>
|
|
213
|
+
</PerpetualsProvider>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
For a fully custom layout, drive the lower-level UI components with
|
|
219
|
+
`usePerpDepositQuote`, `usePerpDepositExecute`, and `usePerpDepositStatus`
|
|
220
|
+
directly. The state-machine pure functions (`reduceDepositState`, etc.)
|
|
221
|
+
are also exported for tooling and tests.
|
|
222
|
+
|
|
223
|
+
### Hyperliquid first-run setup
|
|
224
|
+
|
|
225
|
+
`HyperliquidInitWidget` orchestrates the three idempotent setup actions
|
|
226
|
+
Hyperliquid expects on a fresh account: approve a builder fee, set a
|
|
227
|
+
referrer, and pin a default leverage. Wallet signing is delegated to a
|
|
228
|
+
consumer-supplied adapter so this SDK does not pin a specific Hyperliquid
|
|
229
|
+
client library.
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
import {
|
|
233
|
+
HyperliquidInitWidget,
|
|
234
|
+
type IHyperliquidSetupAdapter,
|
|
235
|
+
} from "@liberfi.io/ui-perpetuals";
|
|
236
|
+
|
|
237
|
+
const adapter: IHyperliquidSetupAdapter = buildPrivyAdapter(/* … */);
|
|
238
|
+
|
|
239
|
+
export function FirstRunSetup({ user }: { user: { evmAddress: string } }) {
|
|
240
|
+
return (
|
|
241
|
+
<HyperliquidInitWidget
|
|
242
|
+
adapter={adapter}
|
|
243
|
+
userAddress={user.evmAddress}
|
|
244
|
+
steps={[
|
|
245
|
+
{
|
|
246
|
+
id: "approveBuilderFee",
|
|
247
|
+
params: { builder: BUILDER_ADDRESS, maxFeeRate: 45 },
|
|
248
|
+
},
|
|
249
|
+
{ id: "setReferrer", params: { code: "LIBERFI" } },
|
|
250
|
+
{
|
|
251
|
+
id: "updateLeverage",
|
|
252
|
+
params: { asset: "BTC", leverage: 5, isCross: true },
|
|
253
|
+
},
|
|
254
|
+
]}
|
|
255
|
+
onComplete={() => router.push("/perpetuals")}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The pure state machine (`reduceSetupState`, `classifyStep`,
|
|
262
|
+
`nextRunnableStep`) is exported separately so apps can build their own
|
|
263
|
+
checklist UI without reimplementing the transition rules.
|
|
264
|
+
|
|
142
265
|
## Future Improvements
|
|
143
266
|
|
|
144
267
|
- Add integration tests for order submit/cancel and subscription lifecycle.
|
|
145
268
|
- Add i18n wiring for all user-facing strings in `ui-perpetuals` components.
|
|
146
269
|
- Replace placeholder account/margin values in place-order script with real account sources.
|
|
270
|
+
- Surface deposit status updates over a push channel (SSE/WebSocket) once the perpetuals-server exposes one — today the client polls.
|
|
271
|
+
- Ship a first-party `HyperliquidSetupAdapter` implementation via a dedicated `@liberfi.io/wallet-connector-hyperliquid` package so consumers don’t need to write their own.
|