@rash2x/bridge-widget 0.1.0 → 0.1.3

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,624 @@
1
+ import { JSX } from 'react/jsx-runtime';
2
+ import { StoreApi } from 'zustand';
3
+ import { TronWeb } from 'tronweb';
4
+ import { UseBoundStore } from 'zustand';
5
+
6
+ export declare function addrForApi(chainKey: string, addr: string): string;
7
+
8
+ export declare type AssetMatrix = Record<string, Record<string, Token>>;
9
+
10
+ declare interface BalanceData {
11
+ balance: number;
12
+ isLoading: boolean;
13
+ }
14
+
15
+ export declare type BalancesMap = Record<string, {
16
+ balance: number;
17
+ address: string;
18
+ }>;
19
+
20
+ declare interface BridgeQuoteActions {
21
+ setInputAmount: (v: string) => void;
22
+ setLoading: () => void;
23
+ setQuote: (q?: Quote) => void;
24
+ setError: (e?: string) => void;
25
+ setNoRoute: (v: boolean) => void;
26
+ triggerRefetch: () => void;
27
+ reset: () => void;
28
+ resetWithIdle: () => void;
29
+ }
30
+
31
+ declare interface BridgeQuoteState {
32
+ inputAmount: string;
33
+ status: BridgeQuoteStatus;
34
+ quote?: Quote;
35
+ error?: string;
36
+ noRoute: boolean;
37
+ refetchTrigger: number;
38
+ }
39
+
40
+ declare type BridgeQuoteStatus = "idle" | "loading" | "success" | "error";
41
+
42
+ declare type BridgeQuoteStore = BridgeQuoteState & BridgeQuoteActions;
43
+
44
+ export declare function buildAssetMatrix(tokens: Token[]): AssetMatrix;
45
+
46
+ /**
47
+ * Calculate minimum received amount with custom slippage
48
+ */
49
+ export declare function calculateMinReceived(quote: Quote | undefined, slippageBps: number, dstToken: Token | undefined): number;
50
+
51
+ export declare interface Chain {
52
+ chainId: number;
53
+ chainKey: string;
54
+ chainType: string;
55
+ name: string;
56
+ nativeCurrency: {
57
+ address: string;
58
+ chainKey: string;
59
+ decimals: number;
60
+ name: string;
61
+ symbol: string;
62
+ };
63
+ shortName: string;
64
+ }
65
+
66
+ declare interface ChainActions {
67
+ setChains: (data?: Chain[]) => Promise<void>;
68
+ setFromChain: (data?: Chain) => void;
69
+ setToChain: (data?: Chain) => void;
70
+ setAllowedFromChains: (data?: Chain[]) => void;
71
+ setAllowedToChains: (data?: Chain[]) => void;
72
+ setIsLoadingToChains: (v: boolean) => void;
73
+ swapChains: () => void;
74
+ }
75
+
76
+ export declare interface ChainChangeData {
77
+ type: "from" | "to";
78
+ chain: Chain;
79
+ }
80
+
81
+ export declare type ChainKey = "TON" | "EVM" | "TRON" | string;
82
+
83
+ declare interface chainState {
84
+ chains?: Chain[];
85
+ fromChain?: Chain;
86
+ toChain?: Chain;
87
+ allowedFromChains?: Chain[];
88
+ allowedToChains?: Chain[];
89
+ isLoadingToChains: boolean;
90
+ }
91
+
92
+ declare type ChainStoreType = chainState & ChainActions;
93
+
94
+ export declare function computeFeesUsdFromArray(fees: Array<{
95
+ amount?: string;
96
+ token?: string;
97
+ chainKey?: string;
98
+ type?: string;
99
+ usd?: number;
100
+ }> | undefined, tokens: Token[] | undefined, chains: Chain[] | undefined): {
101
+ totalUsd: number;
102
+ protocolFeeUsd?: number;
103
+ messageFeeUsd?: number;
104
+ serviceUsd?: number;
105
+ blockchainUsd?: number;
106
+ };
107
+
108
+ declare interface ConnectedWalletActions {
109
+ setTonConnected: (connected: boolean) => void;
110
+ setMetaMaskConnected: (connected: boolean) => void;
111
+ setTronConnected: (connected: boolean) => void;
112
+ hasAnyWallet: () => boolean;
113
+ }
114
+
115
+ declare interface ConnectedWalletState {
116
+ tonConnected: boolean;
117
+ metaMaskConnected: boolean;
118
+ tronConnected: boolean;
119
+ }
120
+
121
+ declare type ConnectedWalletStore = ConnectedWalletState & ConnectedWalletActions;
122
+
123
+ declare interface CurrentTransaction {
124
+ quote: Quote;
125
+ status: TxStatus_2;
126
+ srcTxHash?: string;
127
+ dstTxHash?: string;
128
+ messageId?: string;
129
+ createdAt: number;
130
+ updatedAt: number;
131
+ error?: string;
132
+ monitorReceipt?: MonitorReceipt;
133
+ metadata?: TransactionMetadata;
134
+ }
135
+
136
+ /**
137
+ * Stores custom destination address override when user enables "Send to another address"
138
+ */
139
+ declare interface CustomAddressState {
140
+ customDstAddress?: string;
141
+ setCustomDstAddress: (address?: string) => void;
142
+ clearCustomDstAddress: () => void;
143
+ }
144
+
145
+ export declare const DEFAULT_SLIPPAGE_BPS = 50;
146
+
147
+ declare type DeliveryStatus = {
148
+ status: 'pending' | 'delivered' | 'failed';
149
+ srcTxHash?: string;
150
+ dstTxHash?: string;
151
+ raw?: unknown;
152
+ };
153
+
154
+ declare interface DeliveryStatusParams {
155
+ srcChainKey: string;
156
+ dstChainKey?: string;
157
+ srcTxHash: string;
158
+ }
159
+
160
+ export declare function dollarsFromNativeFees(feeNative: string, feeLzToken: string, chain: Chain | undefined, tokens: Token[] | undefined): number;
161
+
162
+ export declare const EvaaBridge: (props: EvaaBridgeProps) => JSX.Element;
163
+
164
+ export declare interface EvaaBridgeProps {
165
+ className?: string;
166
+ onInitialized?: () => void;
167
+ onSwapStart?: (data: SwapStartData) => void;
168
+ onSwapSuccess?: (data: SwapSuccessData) => void;
169
+ onSwapError?: (error: SwapErrorData) => void;
170
+ onAmountChange?: (amount: string) => void;
171
+ onChainChange?: (data: ChainChangeData) => void;
172
+ }
173
+
174
+ declare interface EvmMonitorReceipt {
175
+ status?: string | number | boolean;
176
+ blockNumber?: string;
177
+ logs?: Array<{
178
+ address?: string;
179
+ topics?: string[];
180
+ data?: string;
181
+ }>;
182
+ }
183
+
184
+ export declare interface Fees {
185
+ token: string;
186
+ chainKey: string;
187
+ amount: string;
188
+ type: string;
189
+ }
190
+
191
+ export declare function findNativeMeta(tokens: Token[] | undefined, chain: Chain | undefined): {
192
+ decimals: number;
193
+ priceUsd?: number;
194
+ };
195
+
196
+ /**
197
+ * Formats balance with specified decimal precision
198
+ * Returns "0.00" for zero/invalid values
199
+ */
200
+ export declare const formatBalance: (amount: number, decimals?: number) => string;
201
+
202
+ /**
203
+ * Formats transaction hash for display
204
+ * Shows first 4 and last 4 characters with ellipsis
205
+ * @param hash - Transaction hash
206
+ * @param startChars - Number of characters to show at start (default: 4)
207
+ * @param endChars - Number of characters to show at end (default: 4)
208
+ */
209
+ export declare const formatHash: (hash: string | undefined, startChars?: number, endChars?: number) => string;
210
+
211
+ /**
212
+ * Formats percentage from basis points (bps)
213
+ * @param bps - Basis points (e.g., 50 = 0.5%)
214
+ * @param decimals - Number of decimal places (default: 2)
215
+ */
216
+ export declare const formatPercentage: (bps: number, decimals?: number) => string;
217
+
218
+ /**
219
+ * Formats token amount with symbol-aware logic
220
+ * Stablecoins show as integers when >= 1, other tokens use adaptive decimals
221
+ */
222
+ export declare const formatTokenAmount: (amount: number, symbol?: string, options?: {
223
+ decimals?: number;
224
+ }) => string;
225
+
226
+ /**
227
+ * Formats USD values with adaptive decimal precision
228
+ */
229
+ export declare const formatUsd: (value?: number) => string;
230
+
231
+ export declare function fromLD(ld: string, decimals: number): number;
232
+
233
+ declare type GasPreset = "auto" | "none" | "medium" | "max";
234
+
235
+ export declare function getChains(): Promise<Chain[]>;
236
+
237
+ export declare function getDeliveryStatus(params: DeliveryStatusParams): Promise<DeliveryStatus | null>;
238
+
239
+ export declare function getDestTokens(srcChainKey: string, srcTokenAddr: string): Promise<TokenWithDestination[]>;
240
+
241
+ export declare function getEvmBalances(address: string, tokens: Token[]): Promise<WalletBalances>;
242
+
243
+ /**
244
+ * Get human-readable amounts from quote
245
+ */
246
+ export declare function getQuoteAmounts(quote: Quote | undefined, srcToken: Token | undefined, dstToken: Token | undefined): {
247
+ inputHuman: number;
248
+ outputHuman: number;
249
+ outputHumanRounded: string;
250
+ minReceivedHuman: number;
251
+ };
252
+
253
+ /**
254
+ * Get complete quote details for UI display
255
+ */
256
+ export declare function getQuoteDetails(quote: Quote | undefined, srcToken: Token | undefined, dstToken: Token | undefined, tokens: Token[] | undefined, chains: Chain[] | undefined, slippageBps: number): {
257
+ inputAmount: number;
258
+ outputAmount: number;
259
+ outputAmountRounded: string;
260
+ minimumReceived: number;
261
+ etaSeconds: number | undefined;
262
+ fees: {
263
+ totalUsd: number;
264
+ protocolFeeUsd: number | undefined;
265
+ messageFeeUsd: number | undefined;
266
+ serviceUsd: number | undefined;
267
+ blockchainUsd: number | undefined;
268
+ inSrcToken: number | undefined;
269
+ inDstToken: number | undefined;
270
+ };
271
+ };
272
+
273
+ /**
274
+ * Get aggregated fees from quote
275
+ */
276
+ export declare function getQuoteFees(quote: Quote | undefined, tokens: Token[] | undefined, chains: Chain[] | undefined, srcToken: Token | undefined, dstToken: Token | undefined): {
277
+ totalUsd: number;
278
+ protocolFeeUsd: number | undefined;
279
+ messageFeeUsd: number | undefined;
280
+ serviceUsd: number | undefined;
281
+ blockchainUsd: number | undefined;
282
+ inSrcToken: number | undefined;
283
+ inDstToken: number | undefined;
284
+ };
285
+
286
+ /**
287
+ * Get quote by priority preference
288
+ * If API returns single route, use it directly
289
+ * If multiple routes available, select based on user's priority
290
+ */
291
+ export declare function getQuotesByPriority(req: QuoteRequest): Promise<Quote | null>;
292
+
293
+ export declare function getSwapBalances(accountFriendly: string): Promise<BalancesMap>;
294
+
295
+ export declare function getTokens(): Promise<Token[]>;
296
+
297
+ export declare function getTronBalances(tronWeb: TronWeb, address: string, tokens: Token[]): Promise<WalletBalances>;
298
+
299
+ export declare function isAddressValidForChain(chainKey?: string, addr?: string): boolean;
300
+
301
+ export declare const isEvmAddress: (a?: string) => boolean;
302
+
303
+ export declare function isNativeAddrEqual(chain: Chain | undefined, tokenAddr?: string): boolean;
304
+
305
+ export declare const isTronAddress: (a?: string) => boolean;
306
+
307
+ export declare const isZeroAddr: (a?: string) => boolean;
308
+
309
+ export declare function listAssetsForSelect(tokens: Token[]): Token[];
310
+
311
+ export declare function lookupTokenMeta(tokens: Token[] | undefined, chains: Chain[] | undefined, chainKey?: string, tokenAddr?: string): {
312
+ decimals: number;
313
+ priceUsd?: number;
314
+ };
315
+
316
+ export declare interface Message {
317
+ payload: string;
318
+ amount: string;
319
+ address: string;
320
+ }
321
+
322
+ declare type MonitorReceipt = EvmMonitorReceipt | TronMonitorReceipt | TonMonitorReceipt;
323
+
324
+ export declare interface MonitorResult {
325
+ status: TxStatus;
326
+ reason?: string | null;
327
+ receipt?: unknown;
328
+ confirmations?: number;
329
+ }
330
+
331
+ export declare function normalizeTickerSymbol(s: string): string;
332
+
333
+ export declare function pollUntilDelivered(args: PollUntilDeliveredParams): Promise<DeliveryStatus>;
334
+
335
+ declare interface PollUntilDeliveredParams {
336
+ srcChainKey: string;
337
+ dstChainKey?: string;
338
+ srcTxHash: string;
339
+ intervalMs?: number;
340
+ timeoutMs?: number;
341
+ signal?: AbortSignal;
342
+ onUpdate?: (st: DeliveryStatus) => void;
343
+ }
344
+
345
+ export declare interface Quote {
346
+ route: string;
347
+ error: string | null;
348
+ srcAmount: string;
349
+ dstAmount: string;
350
+ srcAmountMax: string;
351
+ dstAmountMin: string;
352
+ srcToken: string;
353
+ dstToken: string;
354
+ srcAddress: string;
355
+ dstAddress: string;
356
+ srcChainKey: string;
357
+ dstChainKey: string;
358
+ dstNativeAmount: string;
359
+ duration: {
360
+ estimated: number;
361
+ };
362
+ fees: Fees[];
363
+ steps: TransactionStep[];
364
+ }
365
+
366
+ export declare type QuoteRequest = {
367
+ srcChainKey: string;
368
+ dstChainKey: string;
369
+ srcToken: string;
370
+ dstToken: string;
371
+ srcAmountLD: string;
372
+ dstAmountMinLD?: string;
373
+ srcAddress?: string;
374
+ dstAddress?: string;
375
+ dstNativeAmount?: string;
376
+ slippage?: number;
377
+ routePriority?: RoutePriority;
378
+ };
379
+
380
+ export declare type QuoteSendRequest = {
381
+ srcChainKey: string;
382
+ dstChainKey: string;
383
+ srcToken: string;
384
+ toAddressBytes32: string;
385
+ amountLD: string;
386
+ minAmountLD: string;
387
+ payInLzToken?: boolean;
388
+ };
389
+
390
+ export declare type QuoteSendResponse = {
391
+ fee: {
392
+ nativeFee: string;
393
+ lzTokenFee: string;
394
+ };
395
+ };
396
+
397
+ export declare function resolveTokenOnChain(tokens: Token[], assetSymbol: string, chainKey: string): Token | undefined;
398
+
399
+ export declare function resolveTokenOnChainFromMatrix(assetMatrix: Record<string, Record<string, Token>> | undefined, assetSymbol: string | undefined, chainKey: string | undefined): Token | undefined;
400
+
401
+ export declare const RoutePriority: {
402
+ readonly RECOMMENDED: "recommended";
403
+ readonly FASTEST: "fastest";
404
+ readonly CHEAPEST: "cheapest";
405
+ };
406
+
407
+ export declare type RoutePriority = (typeof RoutePriority)[keyof typeof RoutePriority];
408
+
409
+ export declare const RouteType: {
410
+ readonly STARGATE_V2_FAST: "STARGATE_V2_FAST";
411
+ readonly OFT: "OFT";
412
+ readonly STARGATE_V1: "STARGATE_V1";
413
+ };
414
+
415
+ export declare type RouteType = (typeof RouteType)[keyof typeof RouteType];
416
+
417
+ declare interface SettingsState {
418
+ slippageBps: number;
419
+ routePriority: RoutePriority;
420
+ gasPreset: GasPreset;
421
+ setSlippageBps: (bps: number) => void;
422
+ setRoutePriority: (priority: RoutePriority) => void;
423
+ setGasPreset: (preset: GasPreset) => void;
424
+ getDstNativeAmount: (chainKey?: string) => string;
425
+ getSourceGasReserveHuman: (chainKey?: string) => number;
426
+ getSlippageDecimal: () => number;
427
+ }
428
+
429
+ declare type Store = TransactionState & TransactionActions;
430
+
431
+ export declare function sumFeeByTokenLD(fees: Array<{
432
+ amount?: string;
433
+ token?: string;
434
+ chainKey?: string;
435
+ }> | undefined, dstTokenAddr?: string, dstChainKey?: string): string;
436
+
437
+ export declare interface SwapErrorData {
438
+ error: string;
439
+ fromChain: string;
440
+ toChain: string;
441
+ amount: string;
442
+ tokenSymbol: string;
443
+ }
444
+
445
+ export declare interface SwapStartData {
446
+ fromChain: string;
447
+ toChain: string;
448
+ amount: string;
449
+ tokenSymbol: string;
450
+ }
451
+
452
+ export declare interface SwapSuccessData {
453
+ fromChain: string;
454
+ toChain: string;
455
+ amount: string;
456
+ tokenSymbol: string;
457
+ transactionHash?: string;
458
+ }
459
+
460
+ export declare interface Token {
461
+ address: string;
462
+ symbol: string;
463
+ chainKey: string;
464
+ name: string;
465
+ decimals: number;
466
+ isBridgeable: boolean;
467
+ price?: TokenPrice;
468
+ }
469
+
470
+ export declare interface TokenPrice {
471
+ usd: number;
472
+ }
473
+
474
+ declare interface TokensState {
475
+ tokens?: Token[];
476
+ assetMatrix?: AssetMatrix;
477
+ selectedToken?: Token;
478
+ selectedAssetSymbol?: string;
479
+ }
480
+
481
+ declare interface TokensStateActions {
482
+ setTokens: (data: Token[]) => Promise<void>;
483
+ setSelectedToken: (data?: Token) => void;
484
+ setSelectedAssetSymbol: (data: string) => void;
485
+ }
486
+
487
+ declare type TokensStoreType = TokensState & TokensStateActions;
488
+
489
+ declare interface TokenWithDestination extends Token {
490
+ dstChainKey?: string;
491
+ }
492
+
493
+ export declare function toLD(human: string, decimals: number): string;
494
+
495
+ declare interface TonMonitorReceipt {
496
+ aborted?: boolean;
497
+ transaction?: {
498
+ aborted?: boolean;
499
+ compute_phase?: {
500
+ exit_code?: number;
501
+ };
502
+ };
503
+ compute_phase?: {
504
+ exit_code?: number;
505
+ };
506
+ success?: boolean;
507
+ ok?: boolean;
508
+ status?: string;
509
+ }
510
+
511
+ export declare function tonNorm(addr?: string): string | null;
512
+
513
+ export declare interface Transaction {
514
+ data?: string;
515
+ to?: string;
516
+ from?: string;
517
+ value?: string;
518
+ network?: string;
519
+ messages?: Message[];
520
+ }
521
+
522
+ declare interface TransactionActions {
523
+ setTransaction: (quote: Quote, status?: TxStatus_2, metadata?: TransactionMetadata) => void;
524
+ updateStatus: (status: TxStatus_2) => void;
525
+ setSrcHash: (hash?: string) => void;
526
+ setDstHash: (hash?: string) => void;
527
+ setError: (error: string) => void;
528
+ reset: () => void;
529
+ }
530
+
531
+ declare interface TransactionMetadata {
532
+ srcChainName: string;
533
+ dstChainName: string;
534
+ srcTokenSymbol: string;
535
+ dstTokenSymbol: string;
536
+ srcAmountHuman: number;
537
+ dstAmountHuman: number;
538
+ totalFeeValue?: number;
539
+ totalFeeSymbol?: string;
540
+ }
541
+
542
+ declare interface TransactionState {
543
+ current?: CurrentTransaction;
544
+ successModalOpen: boolean;
545
+ history: CurrentTransaction[];
546
+ }
547
+
548
+ export declare interface TransactionStep {
549
+ type: string;
550
+ sender: string;
551
+ chainKey: string;
552
+ transaction: Transaction;
553
+ }
554
+
555
+ export declare interface TronLinkApi {
556
+ ready?: boolean;
557
+ tronWeb?: TronWeb;
558
+ request?: (args: {
559
+ method: string;
560
+ params?: unknown[];
561
+ }) => Promise<unknown>;
562
+ on?: (event: string, handler: (...args: unknown[]) => void) => void;
563
+ off?: (event: string, handler: (...args: unknown[]) => void) => void;
564
+ }
565
+
566
+ declare interface TronMonitorReceipt {
567
+ receipt?: {
568
+ result?: string;
569
+ };
570
+ }
571
+
572
+ /**
573
+ * Обрезает число до указанного количества десятичных знаков без округления
574
+ * Например: truncateToDecimals(3.389, 2) = "3.38" (не "3.39")
575
+ */
576
+ export declare const truncateToDecimals: (num: number, decimals: number) => string;
577
+
578
+ export declare type TxStatus = "success" | "failed" | "timeout";
579
+
580
+ declare type TxStatus_2 = "idle" | "pending" | "executing" | "processing" | "completed" | "failed" | "expired";
581
+
582
+ export declare const useBridgeQuoteStore: UseBoundStore<StoreApi<BridgeQuoteStore>>;
583
+
584
+ export declare const useChainsStore: UseBoundStore<StoreApi<ChainStoreType>>;
585
+
586
+ export declare const useConnectedWalletsStore: UseBoundStore<StoreApi<ConnectedWalletStore>>;
587
+
588
+ export declare const useCustomAddressStore: UseBoundStore<StoreApi<CustomAddressState>>;
589
+
590
+ export declare const useSettingsStore: UseBoundStore<StoreApi<SettingsState>>;
591
+
592
+ export declare function useSwapModel(): {
593
+ amount: string;
594
+ loadingQuote: boolean;
595
+ fromBalance: BalanceData;
596
+ receiveBalance: BalanceData;
597
+ allowedFromChains: Chain[] | undefined;
598
+ allowedToChains: Chain[] | undefined;
599
+ isLoadingToChains: boolean;
600
+ actions: {
601
+ readonly setFromChain: (data?: Chain) => void;
602
+ readonly setToChain: (data?: Chain) => void;
603
+ readonly setAmount: (v: string) => void;
604
+ readonly swapSides: () => void;
605
+ };
606
+ fromChain: Chain | undefined;
607
+ toChain: Chain | undefined;
608
+ selectedAssetSymbol: string | undefined;
609
+ };
610
+
611
+ export declare const useTokensStore: UseBoundStore<StoreApi<TokensStoreType>>;
612
+
613
+ export declare const useTransactionStore: UseBoundStore<StoreApi<Store>>;
614
+
615
+ export declare interface WalletBalance {
616
+ balance: number;
617
+ address: string;
618
+ }
619
+
620
+ export declare type WalletBalances = Record<string, WalletBalance>;
621
+
622
+ export declare type WalletKind = "ton" | "evm" | "tron" | null;
623
+
624
+ export { }