@b3dotfun/sdk 0.0.83 → 0.0.84-alpha.1
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/dist/cjs/anyspend/constants/index.d.ts +1 -1
- package/dist/cjs/anyspend/constants/index.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpend.js +23 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +2 -1
- package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -4
- package/dist/cjs/anyspend/react/components/common/OrderToken.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountFiat.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountNew.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +4 -6
- package/dist/cjs/anyspend/react/components/common/PaymentVendorUI.js +41 -2
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -3
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +133 -0
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/cjs/anyspend/types/chain.d.ts +10 -2
- package/dist/cjs/anyspend/types/chain.js +1 -0
- package/dist/cjs/anyspend/utils/address.d.ts +11 -0
- package/dist/cjs/anyspend/utils/address.js +15 -0
- package/dist/cjs/anyspend/utils/chain.d.ts +20 -1
- package/dist/cjs/anyspend/utils/chain.js +73 -4
- package/dist/cjs/anyspend/utils/token.d.ts +7 -0
- package/dist/cjs/anyspend/utils/token.js +26 -7
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +1 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/cjs/shared/utils/payment.utils.d.ts +1 -0
- package/dist/cjs/shared/utils/payment.utils.js +9 -0
- package/dist/esm/anyspend/constants/index.d.ts +1 -1
- package/dist/esm/anyspend/constants/index.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +24 -10
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +2 -1
- package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -5
- package/dist/esm/anyspend/react/components/common/OrderToken.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountFiat.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountNew.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -4
- package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +9 -3
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +3 -4
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +127 -0
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/esm/anyspend/types/chain.d.ts +10 -2
- package/dist/esm/anyspend/types/chain.js +1 -0
- package/dist/esm/anyspend/utils/address.d.ts +11 -0
- package/dist/esm/anyspend/utils/address.js +14 -0
- package/dist/esm/anyspend/utils/chain.d.ts +20 -1
- package/dist/esm/anyspend/utils/chain.js +70 -4
- package/dist/esm/anyspend/utils/token.d.ts +7 -0
- package/dist/esm/anyspend/utils/token.js +25 -7
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -1
- package/dist/types/anyspend/constants/index.d.ts +1 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/types/anyspend/types/chain.d.ts +10 -2
- package/dist/types/anyspend/utils/address.d.ts +11 -0
- package/dist/types/anyspend/utils/chain.d.ts +20 -1
- package/dist/types/anyspend/utils/token.d.ts +7 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/types/shared/utils/payment.utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/constants/index.ts +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +36 -9
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -25
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +16 -5
- package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +6 -5
- package/src/anyspend/react/components/common/OrderToken.tsx +5 -5
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountFiat.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountNew.tsx +6 -6
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -5
- package/src/anyspend/react/components/common/PaymentVendorUI.tsx +26 -2
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +3 -5
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
- package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +152 -0
- package/src/anyspend/react/providers/AnyspendProvider.tsx +7 -22
- package/src/anyspend/types/chain.ts +10 -1
- package/src/anyspend/utils/address.ts +15 -0
- package/src/anyspend/utils/chain.ts +84 -4
- package/src/anyspend/utils/token.ts +27 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -2
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/shared/utils/payment.utils.ts +10 -1
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- 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
|
-
}
|