@b3dotfun/sdk 0.0.83 → 0.0.84-alpha.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.
Files changed (133) hide show
  1. package/dist/cjs/anyspend/constants/index.d.ts +1 -1
  2. package/dist/cjs/anyspend/constants/index.js +2 -2
  3. package/dist/cjs/anyspend/react/components/AnySpend.js +21 -9
  4. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -3
  5. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
  6. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  7. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
  8. package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +1 -1
  9. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -4
  10. package/dist/cjs/anyspend/react/components/common/OrderToken.js +2 -2
  11. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +1 -1
  12. package/dist/cjs/anyspend/react/components/common/OrderTokenAmountFiat.js +1 -1
  13. package/dist/cjs/anyspend/react/components/common/OrderTokenAmountNew.js +2 -2
  14. package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +4 -6
  15. package/dist/cjs/anyspend/react/components/common/PaymentVendorUI.js +41 -2
  16. package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +1 -1
  17. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -3
  18. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  19. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  20. package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  21. package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
  22. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  23. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
  24. package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
  25. package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +133 -0
  26. package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -13
  27. package/dist/cjs/anyspend/types/chain.d.ts +10 -2
  28. package/dist/cjs/anyspend/types/chain.js +1 -0
  29. package/dist/cjs/anyspend/utils/address.d.ts +11 -0
  30. package/dist/cjs/anyspend/utils/address.js +15 -0
  31. package/dist/cjs/anyspend/utils/chain.d.ts +20 -1
  32. package/dist/cjs/anyspend/utils/chain.js +73 -4
  33. package/dist/cjs/anyspend/utils/token.d.ts +1 -0
  34. package/dist/cjs/anyspend/utils/token.js +19 -6
  35. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +1 -1
  36. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
  37. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  38. package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
  39. package/dist/cjs/global-account/react/hooks/index.js +1 -3
  40. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
  41. package/dist/cjs/shared/utils/payment.utils.d.ts +1 -0
  42. package/dist/cjs/shared/utils/payment.utils.js +9 -0
  43. package/dist/esm/anyspend/constants/index.d.ts +1 -1
  44. package/dist/esm/anyspend/constants/index.js +1 -1
  45. package/dist/esm/anyspend/react/components/AnySpend.js +22 -10
  46. package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -4
  47. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
  48. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  49. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
  50. package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
  51. package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -5
  52. package/dist/esm/anyspend/react/components/common/OrderToken.js +3 -3
  53. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -2
  54. package/dist/esm/anyspend/react/components/common/OrderTokenAmountFiat.js +2 -2
  55. package/dist/esm/anyspend/react/components/common/OrderTokenAmountNew.js +3 -3
  56. package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -4
  57. package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +9 -3
  58. package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
  59. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +3 -4
  60. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  61. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  62. package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  63. package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
  64. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  65. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
  66. package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
  67. package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +127 -0
  68. package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -13
  69. package/dist/esm/anyspend/types/chain.d.ts +10 -2
  70. package/dist/esm/anyspend/types/chain.js +1 -0
  71. package/dist/esm/anyspend/utils/address.d.ts +11 -0
  72. package/dist/esm/anyspend/utils/address.js +14 -0
  73. package/dist/esm/anyspend/utils/chain.d.ts +20 -1
  74. package/dist/esm/anyspend/utils/chain.js +70 -4
  75. package/dist/esm/anyspend/utils/token.d.ts +1 -0
  76. package/dist/esm/anyspend/utils/token.js +19 -7
  77. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
  78. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
  79. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  80. package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
  81. package/dist/esm/global-account/react/hooks/index.js +0 -1
  82. package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
  83. package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
  84. package/dist/esm/shared/utils/payment.utils.js +9 -1
  85. package/dist/types/anyspend/constants/index.d.ts +1 -1
  86. package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  87. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  88. package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  89. package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  90. package/dist/types/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
  91. package/dist/types/anyspend/types/chain.d.ts +10 -2
  92. package/dist/types/anyspend/utils/address.d.ts +11 -0
  93. package/dist/types/anyspend/utils/chain.d.ts +20 -1
  94. package/dist/types/anyspend/utils/token.d.ts +1 -0
  95. package/dist/types/global-account/react/hooks/index.d.ts +0 -1
  96. package/dist/types/shared/utils/payment.utils.d.ts +1 -0
  97. package/package.json +1 -1
  98. package/src/anyspend/constants/index.ts +1 -1
  99. package/src/anyspend/react/components/AnySpend.tsx +31 -9
  100. package/src/anyspend/react/components/AnySpendCustom.tsx +9 -25
  101. package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
  102. package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
  103. package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
  104. package/src/anyspend/react/components/common/OrderDetails.tsx +6 -5
  105. package/src/anyspend/react/components/common/OrderToken.tsx +5 -5
  106. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +3 -3
  107. package/src/anyspend/react/components/common/OrderTokenAmountFiat.tsx +3 -3
  108. package/src/anyspend/react/components/common/OrderTokenAmountNew.tsx +6 -6
  109. package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -5
  110. package/src/anyspend/react/components/common/PaymentVendorUI.tsx +26 -2
  111. package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
  112. package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +3 -5
  113. package/src/anyspend/react/hooks/index.ts +1 -0
  114. package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
  115. package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
  116. package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +152 -0
  117. package/src/anyspend/react/providers/AnyspendProvider.tsx +7 -22
  118. package/src/anyspend/types/chain.ts +10 -1
  119. package/src/anyspend/utils/address.ts +15 -0
  120. package/src/anyspend/utils/chain.ts +84 -4
  121. package/src/anyspend/utils/token.ts +20 -7
  122. package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -2
  123. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
  124. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
  125. package/src/global-account/react/hooks/index.ts +0 -1
  126. package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
  127. package/src/shared/utils/payment.utils.ts +10 -1
  128. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  129. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
  130. package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  131. package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
  132. package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  133. package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
@@ -1,201 +0,0 @@
1
- "use client";
2
-
3
- import { isNativeToken } from "@b3dotfun/sdk/anyspend";
4
- import { useAccountWallet, useOneBalance, useTokenBalance } from "@b3dotfun/sdk/global-account/react";
5
- import { useMemo } from "react";
6
- import { formatUnits } from "viem";
7
- import { components } from "@b3dotfun/sdk/anyspend/types/api";
8
-
9
- export type TransactionType = "send" | "swap" | "bridge";
10
-
11
- const supportedSprinterTokenSymbols = ["ETH", "USDC", "WETH"] as const;
12
-
13
- export interface SprinterOption {
14
- chainId: number;
15
- balance: bigint;
16
- formattedBalance: string;
17
- }
18
-
19
- export interface TransactionPath {
20
- type: "native" | "sprinter" | "anyspend";
21
- hasNativePath: boolean;
22
- hasSprinterPath: boolean;
23
- availableBalance: bigint;
24
- totalCrossChainBalance: number;
25
- sprinterOptions?: SprinterOption[];
26
- }
27
-
28
- export interface TransactionPathResult extends TransactionPath {
29
- loading: boolean;
30
- }
31
-
32
- interface UseBestTransactionPathProps {
33
- amount: bigint;
34
- token: components["schemas"]["Token"];
35
- address?: string;
36
- transactionType?: TransactionType;
37
- }
38
-
39
- /**
40
- * Hook to determine the optimal transaction path based on user's balances across chains
41
- *
42
- * @param props.amount - Amount to transact
43
- * @param props.token - Token (a Token object)
44
- * @param props.address - Target address (optional, defaults to self)
45
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
46
- *
47
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
48
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
49
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
50
- * - availableBalance: The user's balance of this asset
51
- * - sprinterOptions: Available chains and balances for bridging
52
- * @returns TransactionPathResult object containing path information and loading state
53
- */
54
- export function useBestTransactionPath({
55
- amount,
56
- token,
57
- address,
58
- transactionType: _transactionType = "send",
59
- }: UseBestTransactionPathProps): TransactionPathResult {
60
- const account = useAccountWallet();
61
- const effectiveAddress = address || account?.address;
62
-
63
- const isSupportedSprinterToken = supportedSprinterTokenSymbols.includes(
64
- token.symbol.toUpperCase() as (typeof supportedSprinterTokenSymbols)[number],
65
- );
66
-
67
- // Get balances across all chains
68
- const { aggregatedBalances, aggregatedTokenBalances, loading: oneBalanceLoading } = useOneBalance();
69
-
70
- // Get the token balance using our new hook
71
- const { rawBalance, isLoading: tokenBalanceLoading } = useTokenBalance({
72
- token,
73
- address: effectiveAddress,
74
- });
75
-
76
- // Check if amount is available natively on destination chain
77
- const hasNativeBalance = useMemo(() => {
78
- if (!rawBalance || !amount) return false;
79
-
80
- return rawBalance >= amount;
81
- }, [amount, rawBalance]);
82
-
83
- // Calculate non-native token balance using the same logic as hasNativeBalance
84
- const nonNativeTokenBalance = useMemo(() => {
85
- if (isNativeToken(token.address)) return BigInt(0);
86
-
87
- // For sprinter supported tokens, use aggregated balances
88
- if (isSupportedSprinterToken && !oneBalanceLoading && aggregatedBalances) {
89
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
90
- if (asset) {
91
- const chainBalance = asset.chainBalances.find(cb => cb.chainId === token.chainId);
92
- if (chainBalance) {
93
- return BigInt(chainBalance.balance);
94
- }
95
- }
96
- return BigInt(0);
97
- }
98
-
99
- // For non-sprinter tokens, use token balance from our new hook
100
- return rawBalance;
101
- }, [
102
- token.address,
103
- token.symbol,
104
- token.chainId,
105
- isSupportedSprinterToken,
106
- oneBalanceLoading,
107
- aggregatedBalances,
108
- rawBalance,
109
- ]);
110
-
111
- const totalCrossChainBalance = useMemo(() => {
112
- if (oneBalanceLoading || !aggregatedTokenBalances || !token.symbol) return 0;
113
- return aggregatedTokenBalances[token.symbol] || 0;
114
- }, [aggregatedTokenBalances, token.symbol, oneBalanceLoading]);
115
-
116
- // Calculate available sprinter options and determine if sprinter path is available
117
- const { hasSprinterPath, sprinterOptions } = useMemo(() => {
118
- if (!isSupportedSprinterToken || oneBalanceLoading || !aggregatedBalances || !token.symbol || !amount) {
119
- return { hasSprinterPath: false, sprinterOptions: [] };
120
- }
121
-
122
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
123
- if (!asset) {
124
- return { hasSprinterPath: false, sprinterOptions: [] };
125
- }
126
-
127
- const options: SprinterOption[] = [];
128
-
129
- // Get all chains where user has sufficient balance
130
- for (const chainBalance of asset.chainBalances) {
131
- const balanceBi = BigInt(chainBalance.balance);
132
- if (balanceBi >= amount && chainBalance.chainId !== token.chainId) {
133
- options.push({
134
- chainId: chainBalance.chainId,
135
- balance: balanceBi,
136
- formattedBalance: formatUnits(balanceBi, chainBalance.tokenDecimals),
137
- });
138
- }
139
- }
140
-
141
- return {
142
- hasSprinterPath: options.length > 0,
143
- sprinterOptions: options,
144
- };
145
- }, [isSupportedSprinterToken, oneBalanceLoading, aggregatedBalances, token.symbol, token.chainId, amount]);
146
-
147
- // Determine the best path
148
- const path = useMemo(() => {
149
- const availableBalance = (isNativeToken(token.address) ? rawBalance : nonNativeTokenBalance) || BigInt(0);
150
-
151
- // Case 1: Native path if available
152
- if (hasNativeBalance) {
153
- return {
154
- type: "native" as const,
155
- hasNativePath: true,
156
- hasSprinterPath,
157
- availableBalance,
158
- totalCrossChainBalance,
159
- sprinterOptions,
160
- };
161
- }
162
-
163
- // Case 2: Sprinter path if available
164
- if (hasSprinterPath) {
165
- return {
166
- type: "sprinter" as const,
167
- hasNativePath: false,
168
- hasSprinterPath: true,
169
- availableBalance,
170
- totalCrossChainBalance,
171
- sprinterOptions,
172
- };
173
- }
174
-
175
- // Case 3: Fallback to anyspend
176
- return {
177
- type: "anyspend" as const,
178
- hasNativePath: false,
179
- hasSprinterPath: false,
180
- availableBalance,
181
- totalCrossChainBalance,
182
- sprinterOptions: [],
183
- };
184
- }, [
185
- token.address,
186
- rawBalance,
187
- nonNativeTokenBalance,
188
- hasNativeBalance,
189
- hasSprinterPath,
190
- totalCrossChainBalance,
191
- sprinterOptions,
192
- ]);
193
-
194
- // Combine all loading states
195
- const loading = oneBalanceLoading || tokenBalanceLoading;
196
-
197
- return {
198
- ...path,
199
- loading,
200
- };
201
- }