@tbookdev/vault-react-sui 0.1.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.
@@ -0,0 +1,404 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { SuiNetwork, SuiBuildResult, SuiVaultConfig, SuiVaultPosition, SuiUserRecord } from '@tbookdev/vault-sdk-sui';
4
+ export { SuiBuildResult, SuiNetwork, SuiUserRecord, SuiVaultConfig, SuiVaultPosition, SuiVaultState } from '@tbookdev/vault-sdk-sui';
5
+ import { SuiClient, CoinBalance } from '@mysten/sui/client';
6
+ import * as _tanstack_react_query from '@tanstack/react-query';
7
+ import { UseQueryOptions, UseMutationResult } from '@tanstack/react-query';
8
+
9
+ type SuiVaultTxBuilderMode = "local-sdk" | "gateway-api" | "custom";
10
+ interface TBookSuiVaultStaleTimes {
11
+ vaultInfo: number;
12
+ balances: number;
13
+ history: number;
14
+ usdcBalance: number;
15
+ }
16
+ interface TBookSuiVaultRefetchIntervals {
17
+ vaultInfo: number | false;
18
+ balances: number | false;
19
+ history: number | false;
20
+ usdcBalance: number | false;
21
+ }
22
+ interface TBookSuiCustomTxBuilder {
23
+ buildDepositTx?: (params: {
24
+ sender: string;
25
+ amount: bigint;
26
+ }) => Promise<SuiBuildResult>;
27
+ buildQueueRedeemTx?: (params: {
28
+ sender: string;
29
+ shares: bigint;
30
+ }) => Promise<SuiBuildResult>;
31
+ buildInstantRedeemTx?: (params: {
32
+ sender: string;
33
+ shares: bigint;
34
+ }) => Promise<SuiBuildResult>;
35
+ buildClaimTx?: (params: {
36
+ sender: string;
37
+ amount?: bigint;
38
+ }) => Promise<SuiBuildResult>;
39
+ buildCancelDepositTx?: (params: {
40
+ sender: string;
41
+ recordId: string | bigint;
42
+ }) => Promise<SuiBuildResult>;
43
+ }
44
+ interface CreateSuiVaultConfigInput {
45
+ network: SuiNetwork;
46
+ vaultId?: string;
47
+ txBuilderMode?: SuiVaultTxBuilderMode;
48
+ gatewayApiBaseUrl?: string;
49
+ publishableKey?: string;
50
+ customTxBuilder?: TBookSuiCustomTxBuilder;
51
+ staleTimes?: Partial<TBookSuiVaultStaleTimes>;
52
+ refetchIntervals?: Partial<TBookSuiVaultRefetchIntervals>;
53
+ preflightChecks?: boolean;
54
+ }
55
+ interface TBookSuiVaultConfig {
56
+ network: SuiNetwork;
57
+ vaultId: string;
58
+ vault: SuiVaultConfig;
59
+ txBuilderMode: SuiVaultTxBuilderMode;
60
+ gatewayApiBaseUrl?: string;
61
+ publishableKey?: string;
62
+ customTxBuilder?: TBookSuiCustomTxBuilder;
63
+ staleTimes: TBookSuiVaultStaleTimes;
64
+ refetchIntervals: TBookSuiVaultRefetchIntervals;
65
+ preflightChecks: boolean;
66
+ }
67
+ declare const DEFAULT_SUI_VAULT_ID = "rcusdp-sui";
68
+ declare const SUI_TESTNET_GATEWAY_API_BASE_URL = "https://1cm2fjkq6k.execute-api.ap-southeast-1.amazonaws.com/v1";
69
+ declare function createSuiVaultConfig(input: CreateSuiVaultConfigInput): TBookSuiVaultConfig;
70
+
71
+ interface TBookSuiVaultProviderProps extends CreateSuiVaultConfigInput {
72
+ children: ReactNode;
73
+ }
74
+ declare function TBookSuiVaultProvider({ children, ...input }: TBookSuiVaultProviderProps): react_jsx_runtime.JSX.Element;
75
+ declare function useTBookSuiVault(): TBookSuiVaultConfig;
76
+
77
+ /** Convert a decimal UI amount into raw integer units without float drift. */
78
+ declare function parseDecimalAmount(value: string | number, decimals?: number): bigint;
79
+ /** Convert raw integer units into a compact decimal string. */
80
+ declare function formatRawAmount(value: bigint | string | number, decimals?: number): string;
81
+ /** Accept raw bigint or decimal input and return raw integer units. */
82
+ declare function toRawAmount(value: bigint | string | number, decimals?: number): bigint;
83
+
84
+ declare const suiVaultQueryKeys: {
85
+ all: readonly ["tbook-sui"];
86
+ vault: (network: SuiNetwork, vaultId: string) => readonly ["tbook-sui", "vault", SuiNetwork, string];
87
+ vaultInfo: (network: SuiNetwork, vaultId: string) => readonly ["tbook-sui", "vault", SuiNetwork, string, "info"];
88
+ balances: (network: SuiNetwork, vaultId: string, address: string) => readonly ["tbook-sui", "vault", SuiNetwork, string, "balances", string];
89
+ history: (network: SuiNetwork, vaultId: string, address: string) => readonly ["tbook-sui", "vault", SuiNetwork, string, "history", string];
90
+ usdcBalance: (network: SuiNetwork, address: string, coinType: string) => readonly ["tbook-sui", "wallet", SuiNetwork, string, "usdc", string];
91
+ };
92
+
93
+ type TBookSuiVaultReactErrorCode = "WALLET_NOT_CONNECTED" | "CONFIGURATION_ERROR" | "VAULT_PAUSED" | "SETTLEMENT_ACTIVE" | "UNSUPPORTED_TX_BUILDER" | "API_ERROR";
94
+ declare class TBookSuiVaultReactError extends Error {
95
+ readonly code: TBookSuiVaultReactErrorCode;
96
+ constructor(code: TBookSuiVaultReactErrorCode, message: string);
97
+ }
98
+
99
+ type Fetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
100
+ type SuiGatewayTxType = "deposit" | "redeem" | "claim" | "cancel_deposit";
101
+ type SuiGatewayTxFormat = "sui:tx-bytes-base64";
102
+ interface SuiGatewayTransactionEnvelope {
103
+ format: SuiGatewayTxFormat;
104
+ data: string;
105
+ }
106
+ interface SuiGatewayBuildTxResponse {
107
+ intentId?: string;
108
+ vaultId: string;
109
+ type: SuiGatewayTxType;
110
+ chain: "sui";
111
+ rail: "direct";
112
+ transaction: SuiGatewayTransactionEnvelope;
113
+ summary?: Record<string, unknown>;
114
+ message: string;
115
+ expiresAt: string;
116
+ }
117
+ interface TBookSuiGatewayApiClientOptions {
118
+ baseUrl: string;
119
+ apiKey?: string;
120
+ fetcher?: Fetcher;
121
+ }
122
+ declare class TBookSuiGatewayApiClient {
123
+ private readonly baseUrl;
124
+ private readonly apiKey?;
125
+ private readonly fetcher;
126
+ constructor(options: TBookSuiGatewayApiClientOptions);
127
+ buildDepositTx(vaultId: string, body: {
128
+ user: string;
129
+ amount: string;
130
+ }): Promise<SuiGatewayBuildTxResponse>;
131
+ buildRedeemTx(vaultId: string, body: {
132
+ user: string;
133
+ shares: string;
134
+ mode?: "queued" | "instant";
135
+ }): Promise<SuiGatewayBuildTxResponse>;
136
+ buildClaimTx(vaultId: string, body: {
137
+ user: string;
138
+ }): Promise<SuiGatewayBuildTxResponse>;
139
+ buildCancelDepositTx(vaultId: string, body: {
140
+ user: string;
141
+ recordId: string;
142
+ }): Promise<SuiGatewayBuildTxResponse>;
143
+ confirmIntent(intentId: string, digest: string): Promise<{
144
+ intentId: string;
145
+ status: string;
146
+ }>;
147
+ private post;
148
+ private headers;
149
+ }
150
+
151
+ interface SuiVaultInfo {
152
+ totalShares: bigint;
153
+ pendingDeposit: bigint;
154
+ claimReserve: bigint;
155
+ rcusdpCustody: bigint;
156
+ pendingRedeemRcusdp: bigint;
157
+ reserveFund: bigint;
158
+ depositFeeBps: bigint;
159
+ mgmtFeeBps: bigint;
160
+ redeemFeeBps: bigint;
161
+ withdrawFeeBps: bigint;
162
+ cancelDepositFeeBps: bigint;
163
+ instantRedeemFeeBps: bigint;
164
+ paused: boolean;
165
+ version: bigint;
166
+ depositEnabled: boolean;
167
+ instantRedeemEnabled: boolean;
168
+ withdrawRcusdpEnabled: boolean;
169
+ cancelDepositEnabled: boolean;
170
+ redeemSettled: boolean;
171
+ raw: Record<string, unknown>;
172
+ }
173
+ declare function getSuiVaultInfo(client: SuiClient, cfg: SuiVaultConfig): Promise<SuiVaultInfo>;
174
+
175
+ declare const useSuiVaultConfig: typeof useTBookSuiVault;
176
+
177
+ interface UseSuiVaultInfoOptions extends Omit<UseQueryOptions<SuiVaultInfo>, "queryKey" | "queryFn"> {
178
+ }
179
+ declare function useSuiVaultInfo(options?: UseSuiVaultInfoOptions): _tanstack_react_query.UseQueryResult<SuiVaultInfo, Error>;
180
+
181
+ interface UseSuiVaultBalancesOptions extends Omit<UseQueryOptions<SuiVaultPosition>, "queryKey" | "queryFn"> {
182
+ }
183
+ declare function useSuiVaultBalances(options?: UseSuiVaultBalancesOptions): _tanstack_react_query.UseQueryResult<SuiVaultPosition, Error>;
184
+
185
+ interface UseSuiTransactionHistoryOptions extends Omit<UseQueryOptions<SuiUserRecord[]>, "queryKey" | "queryFn"> {
186
+ }
187
+ declare function useSuiTransactionHistory(options?: UseSuiTransactionHistoryOptions): _tanstack_react_query.UseQueryResult<SuiUserRecord[], Error>;
188
+
189
+ interface UseSuiUsdcBalanceOptions extends Omit<UseQueryOptions<CoinBalance>, "queryKey" | "queryFn"> {
190
+ }
191
+ declare function useSuiUsdcBalance(options?: UseSuiUsdcBalanceOptions): {
192
+ balance: bigint;
193
+ decimals: number;
194
+ formatted: string;
195
+ data: CoinBalance;
196
+ error: Error;
197
+ isError: true;
198
+ isPending: false;
199
+ isLoading: false;
200
+ isLoadingError: false;
201
+ isRefetchError: true;
202
+ isSuccess: false;
203
+ isPlaceholderData: false;
204
+ status: "error";
205
+ dataUpdatedAt: number;
206
+ errorUpdatedAt: number;
207
+ failureCount: number;
208
+ failureReason: Error | null;
209
+ errorUpdateCount: number;
210
+ isFetched: boolean;
211
+ isFetchedAfterMount: boolean;
212
+ isFetching: boolean;
213
+ isInitialLoading: boolean;
214
+ isPaused: boolean;
215
+ isRefetching: boolean;
216
+ isStale: boolean;
217
+ isEnabled: boolean;
218
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
219
+ fetchStatus: _tanstack_react_query.FetchStatus;
220
+ promise: Promise<CoinBalance>;
221
+ } | {
222
+ balance: bigint;
223
+ decimals: number;
224
+ formatted: string;
225
+ data: CoinBalance;
226
+ error: null;
227
+ isError: false;
228
+ isPending: false;
229
+ isLoading: false;
230
+ isLoadingError: false;
231
+ isRefetchError: false;
232
+ isSuccess: true;
233
+ isPlaceholderData: false;
234
+ status: "success";
235
+ dataUpdatedAt: number;
236
+ errorUpdatedAt: number;
237
+ failureCount: number;
238
+ failureReason: Error | null;
239
+ errorUpdateCount: number;
240
+ isFetched: boolean;
241
+ isFetchedAfterMount: boolean;
242
+ isFetching: boolean;
243
+ isInitialLoading: boolean;
244
+ isPaused: boolean;
245
+ isRefetching: boolean;
246
+ isStale: boolean;
247
+ isEnabled: boolean;
248
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
249
+ fetchStatus: _tanstack_react_query.FetchStatus;
250
+ promise: Promise<CoinBalance>;
251
+ } | {
252
+ balance: bigint;
253
+ decimals: number;
254
+ formatted: string;
255
+ data: undefined;
256
+ error: Error;
257
+ isError: true;
258
+ isPending: false;
259
+ isLoading: false;
260
+ isLoadingError: true;
261
+ isRefetchError: false;
262
+ isSuccess: false;
263
+ isPlaceholderData: false;
264
+ status: "error";
265
+ dataUpdatedAt: number;
266
+ errorUpdatedAt: number;
267
+ failureCount: number;
268
+ failureReason: Error | null;
269
+ errorUpdateCount: number;
270
+ isFetched: boolean;
271
+ isFetchedAfterMount: boolean;
272
+ isFetching: boolean;
273
+ isInitialLoading: boolean;
274
+ isPaused: boolean;
275
+ isRefetching: boolean;
276
+ isStale: boolean;
277
+ isEnabled: boolean;
278
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
279
+ fetchStatus: _tanstack_react_query.FetchStatus;
280
+ promise: Promise<CoinBalance>;
281
+ } | {
282
+ balance: bigint;
283
+ decimals: number;
284
+ formatted: string;
285
+ data: undefined;
286
+ error: null;
287
+ isError: false;
288
+ isPending: true;
289
+ isLoading: true;
290
+ isLoadingError: false;
291
+ isRefetchError: false;
292
+ isSuccess: false;
293
+ isPlaceholderData: false;
294
+ status: "pending";
295
+ dataUpdatedAt: number;
296
+ errorUpdatedAt: number;
297
+ failureCount: number;
298
+ failureReason: Error | null;
299
+ errorUpdateCount: number;
300
+ isFetched: boolean;
301
+ isFetchedAfterMount: boolean;
302
+ isFetching: boolean;
303
+ isInitialLoading: boolean;
304
+ isPaused: boolean;
305
+ isRefetching: boolean;
306
+ isStale: boolean;
307
+ isEnabled: boolean;
308
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
309
+ fetchStatus: _tanstack_react_query.FetchStatus;
310
+ promise: Promise<CoinBalance>;
311
+ } | {
312
+ balance: bigint;
313
+ decimals: number;
314
+ formatted: string;
315
+ data: undefined;
316
+ error: null;
317
+ isError: false;
318
+ isPending: true;
319
+ isLoadingError: false;
320
+ isRefetchError: false;
321
+ isSuccess: false;
322
+ isPlaceholderData: false;
323
+ status: "pending";
324
+ dataUpdatedAt: number;
325
+ errorUpdatedAt: number;
326
+ failureCount: number;
327
+ failureReason: Error | null;
328
+ errorUpdateCount: number;
329
+ isFetched: boolean;
330
+ isFetchedAfterMount: boolean;
331
+ isFetching: boolean;
332
+ isLoading: boolean;
333
+ isInitialLoading: boolean;
334
+ isPaused: boolean;
335
+ isRefetching: boolean;
336
+ isStale: boolean;
337
+ isEnabled: boolean;
338
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
339
+ fetchStatus: _tanstack_react_query.FetchStatus;
340
+ promise: Promise<CoinBalance>;
341
+ } | {
342
+ balance: bigint;
343
+ decimals: number;
344
+ formatted: string;
345
+ data: CoinBalance;
346
+ isError: false;
347
+ error: null;
348
+ isPending: false;
349
+ isLoading: false;
350
+ isLoadingError: false;
351
+ isRefetchError: false;
352
+ isSuccess: true;
353
+ isPlaceholderData: true;
354
+ status: "success";
355
+ dataUpdatedAt: number;
356
+ errorUpdatedAt: number;
357
+ failureCount: number;
358
+ failureReason: Error | null;
359
+ errorUpdateCount: number;
360
+ isFetched: boolean;
361
+ isFetchedAfterMount: boolean;
362
+ isFetching: boolean;
363
+ isInitialLoading: boolean;
364
+ isPaused: boolean;
365
+ isRefetching: boolean;
366
+ isStale: boolean;
367
+ isEnabled: boolean;
368
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<CoinBalance, Error>>;
369
+ fetchStatus: _tanstack_react_query.FetchStatus;
370
+ promise: Promise<CoinBalance>;
371
+ };
372
+
373
+ declare function useRefreshSuiVaultData(): () => Promise<void>;
374
+
375
+ interface SuiDepositParams {
376
+ /** Raw USDC units when bigint; decimal UI units when string/number. */
377
+ amount: bigint | string | number;
378
+ }
379
+ interface SuiRedeemParams {
380
+ /** Raw share units when bigint; decimal UI units when string/number. */
381
+ shares: bigint | string | number;
382
+ mode?: "queued" | "instant";
383
+ /** Compatibility helper: USDC maps to queued, RCUSDP maps to instant. */
384
+ tokenType?: "USDC" | "RCUSDP";
385
+ }
386
+ interface SuiCancelDepositParams {
387
+ recordId: string | bigint;
388
+ }
389
+ interface SuiClaimParams {
390
+ amount?: bigint | string | number;
391
+ }
392
+ interface SuiExecutionResult {
393
+ digest?: string;
394
+ rawEffects?: number[];
395
+ effects?: string | {
396
+ bcs?: string;
397
+ };
398
+ }
399
+ declare function useSuiDeposit(): UseMutationResult<SuiExecutionResult, Error, SuiDepositParams>;
400
+ declare function useSuiRedeem(): UseMutationResult<SuiExecutionResult, Error, SuiRedeemParams>;
401
+ declare function useSuiClaim(): UseMutationResult<SuiExecutionResult, Error, SuiClaimParams | undefined>;
402
+ declare function useSuiCancelDeposit(): UseMutationResult<SuiExecutionResult, Error, SuiCancelDepositParams>;
403
+
404
+ export { type CreateSuiVaultConfigInput, DEFAULT_SUI_VAULT_ID, SUI_TESTNET_GATEWAY_API_BASE_URL, type SuiCancelDepositParams, type SuiClaimParams, type SuiDepositParams, type SuiExecutionResult, type SuiGatewayBuildTxResponse, type SuiGatewayTransactionEnvelope, type SuiGatewayTxFormat, type SuiGatewayTxType, type SuiRedeemParams, type SuiVaultInfo, type SuiVaultTxBuilderMode, type TBookSuiCustomTxBuilder, TBookSuiGatewayApiClient, type TBookSuiGatewayApiClientOptions, type TBookSuiVaultConfig, TBookSuiVaultProvider, type TBookSuiVaultProviderProps, TBookSuiVaultReactError, type TBookSuiVaultReactErrorCode, type TBookSuiVaultRefetchIntervals, type TBookSuiVaultStaleTimes, type UseSuiTransactionHistoryOptions, type UseSuiUsdcBalanceOptions, type UseSuiVaultBalancesOptions, type UseSuiVaultInfoOptions, createSuiVaultConfig, formatRawAmount, getSuiVaultInfo, parseDecimalAmount, suiVaultQueryKeys, toRawAmount, useRefreshSuiVaultData, useSuiCancelDeposit, useSuiClaim, useSuiDeposit, useSuiRedeem, useSuiTransactionHistory, useSuiUsdcBalance, useSuiVaultBalances, useSuiVaultConfig, useSuiVaultInfo, useTBookSuiVault };