@b3dotfun/sdk 0.0.40-test.6 → 0.0.41-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.
- package/dist/cjs/anyspend/constants/index.d.ts +0 -1
- package/dist/cjs/anyspend/constants/index.js +1 -2
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +11 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +22 -10
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +41 -20
- package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +10 -8
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +7 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +9 -9
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
- package/dist/cjs/anyspend/react/components/common/OrderDetails.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +24 -23
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +9 -8
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +23 -9
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +10 -6
- package/dist/cjs/anyspend/react/components/common/PaymentMethodSwitch.d.ts +7 -0
- package/dist/cjs/anyspend/react/components/common/PaymentMethodSwitch.js +24 -0
- package/dist/cjs/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/cjs/anyspend/react/components/common/PointsBadge.js +7 -0
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +14 -0
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +6 -4
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.js +21 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +18 -8
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/cjs/anyspend/react/providers/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/providers/index.js +3 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -0
- package/dist/cjs/anyspend/types/api.d.ts +51 -1
- package/dist/cjs/anyspend/utils/chain.js +1 -1
- package/dist/cjs/anyspend/utils/orderPayload.js +3 -0
- package/dist/cjs/bondkit/bondkitToken.d.ts +37 -2
- package/dist/cjs/bondkit/bondkitToken.js +268 -2
- package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/cjs/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/cjs/bondkit/components/TradingView.js +3 -4
- package/dist/cjs/bondkit/config.d.ts +1 -1
- package/dist/cjs/bondkit/config.js +5 -2
- package/dist/cjs/bondkit/constants.d.ts +4 -0
- package/dist/cjs/bondkit/constants.js +6 -1
- package/dist/cjs/bondkit/index.d.ts +1 -0
- package/dist/cjs/bondkit/index.js +4 -1
- package/dist/cjs/bondkit/swapService.d.ts +43 -0
- package/dist/cjs/bondkit/swapService.js +376 -0
- package/dist/cjs/bondkit/types.d.ts +10 -4
- package/dist/cjs/bondkit/types.js +4 -5
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +27 -28
- package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAccountAssets.js +5 -2
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +0 -12
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +2 -3
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +32 -0
- package/dist/cjs/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/cjs/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/cjs/global-account/react/hooks/useSimBalance.js +2 -2
- package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +7 -1
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +28 -24
- package/dist/cjs/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/esm/anyspend/constants/index.d.ts +0 -1
- package/dist/esm/anyspend/constants/index.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +11 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +23 -11
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +41 -20
- package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +11 -9
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +8 -5
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +9 -9
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
- package/dist/esm/anyspend/react/components/common/OrderDetails.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +25 -24
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +10 -9
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +23 -9
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +10 -6
- package/dist/esm/anyspend/react/components/common/PaymentMethodSwitch.d.ts +7 -0
- package/dist/esm/anyspend/react/components/common/PaymentMethodSwitch.js +21 -0
- package/dist/esm/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/esm/anyspend/react/components/common/PointsBadge.js +4 -0
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +8 -0
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +6 -4
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.js +17 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +18 -8
- package/dist/esm/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/esm/anyspend/react/providers/index.d.ts +1 -0
- package/dist/esm/anyspend/react/providers/index.js +1 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -0
- package/dist/esm/anyspend/types/api.d.ts +51 -1
- package/dist/esm/anyspend/utils/chain.js +1 -1
- package/dist/esm/anyspend/utils/orderPayload.js +3 -0
- package/dist/esm/bondkit/bondkitToken.d.ts +37 -2
- package/dist/esm/bondkit/bondkitToken.js +268 -2
- package/dist/esm/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/esm/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/esm/bondkit/components/TradingView.js +3 -4
- package/dist/esm/bondkit/config.d.ts +1 -1
- package/dist/esm/bondkit/config.js +5 -2
- package/dist/esm/bondkit/constants.d.ts +4 -0
- package/dist/esm/bondkit/constants.js +5 -0
- package/dist/esm/bondkit/index.d.ts +1 -0
- package/dist/esm/bondkit/index.js +2 -0
- package/dist/esm/bondkit/swapService.d.ts +43 -0
- package/dist/esm/bondkit/swapService.js +372 -0
- package/dist/esm/bondkit/types.d.ts +10 -4
- package/dist/esm/bondkit/types.js +4 -5
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +27 -28
- package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAccountAssets.js +2 -2
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +0 -12
- package/dist/esm/global-account/react/hooks/useAuthentication.js +2 -3
- package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/esm/global-account/react/hooks/useGlobalAccount.js +29 -0
- package/dist/esm/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/esm/global-account/react/hooks/useSimBalance.js +2 -2
- package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -1
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +29 -25
- package/dist/esm/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/constants/index.d.ts +0 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +11 -1
- package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/types/anyspend/react/components/common/ConnectWalletPayment.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/OrderDetails.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/PaymentMethodSwitch.d.ts +7 -0
- package/dist/types/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/types/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/types/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/types/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/types/anyspend/react/providers/index.d.ts +1 -0
- package/dist/types/anyspend/services/anyspend.d.ts +1 -1
- package/dist/types/anyspend/types/api.d.ts +51 -1
- package/dist/types/bondkit/bondkitToken.d.ts +37 -2
- package/dist/types/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/types/bondkit/config.d.ts +1 -1
- package/dist/types/bondkit/constants.d.ts +4 -0
- package/dist/types/bondkit/index.d.ts +1 -0
- package/dist/types/bondkit/swapService.d.ts +43 -0
- package/dist/types/bondkit/types.d.ts +10 -4
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/types/shared/utils/fetchBalances.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/constants/index.ts +0 -2
- package/src/anyspend/react/components/AnySpend.tsx +52 -18
- package/src/anyspend/react/components/AnySpendBondKit.tsx +0 -1
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +0 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +82 -34
- package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +0 -1
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +38 -18
- package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +12 -4
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +13 -8
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +170 -44
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +61 -45
- package/src/anyspend/react/components/common/OrderDetails.tsx +60 -47
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +62 -41
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +28 -8
- package/src/anyspend/react/components/common/PanelOnramp.tsx +28 -15
- package/src/anyspend/react/components/common/PaymentMethodSwitch.tsx +38 -0
- package/src/anyspend/react/components/common/PointsBadge.tsx +20 -0
- package/src/anyspend/react/components/common/PointsDetailPanel.tsx +55 -0
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +65 -43
- package/src/anyspend/react/contexts/FeatureFlagsContext.tsx +34 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +18 -8
- package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +1 -1
- package/src/anyspend/react/hooks/useCoinbaseOnrampOptions.ts +1 -1
- package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
- package/src/anyspend/react/providers/index.ts +1 -0
- package/src/anyspend/services/anyspend.ts +3 -1
- package/src/anyspend/types/api.ts +51 -1
- package/src/anyspend/types/api_req_res.ts +6 -10
- package/src/anyspend/utils/chain.ts +1 -1
- package/src/anyspend/utils/orderPayload.ts +3 -0
- package/src/bondkit/bondkitToken.ts +323 -3
- package/src/bondkit/bondkitTokenFactory.ts +2 -2
- package/src/bondkit/components/TradingView.tsx +3 -5
- package/src/bondkit/config.ts +5 -2
- package/src/bondkit/constants.ts +7 -0
- package/src/bondkit/index.ts +3 -0
- package/src/bondkit/swapService.ts +464 -0
- package/src/bondkit/types.ts +12 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +31 -32
- package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAccountAssets.ts +4 -3
- package/src/global-account/react/hooks/useAccountWallet.tsx +0 -13
- package/src/global-account/react/hooks/useAuthentication.ts +2 -3
- package/src/global-account/react/hooks/useGlobalAccount.tsx +36 -0
- package/src/global-account/react/hooks/useOneBalance.tsx +1 -1
- package/src/global-account/react/hooks/useQueryB3.ts +22 -15
- package/src/global-account/react/hooks/useQueryBSMNT.ts +22 -15
- package/src/global-account/react/hooks/useSimBalance.ts +2 -2
- package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -1
- package/src/global-account/react/hooks/useTokenFromUrl.tsx +2 -2
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +30 -26
- package/src/shared/utils/fetchBalances.ts +1 -1
- package/dist/cjs/global-account/examples/client-selection-example.d.ts +0 -5
- package/dist/cjs/global-account/examples/client-selection-example.js +0 -96
- package/dist/esm/global-account/examples/client-selection-example.d.ts +0 -5
- package/dist/esm/global-account/examples/client-selection-example.js +0 -93
- package/dist/types/global-account/examples/client-selection-example.d.ts +0 -5
- package/src/global-account/docs/client-selection.md +0 -292
- package/src/global-account/examples/client-selection-example.tsx +0 -197
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient, WalletClient } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
createPublicClient,
|
|
4
|
+
encodeAbiParameters,
|
|
5
|
+
formatUnits,
|
|
6
|
+
getContract,
|
|
7
|
+
http,
|
|
8
|
+
parseAbiParameters,
|
|
9
|
+
parseUnits,
|
|
10
|
+
} from "viem";
|
|
11
|
+
import { base } from "viem/chains";
|
|
12
|
+
import { BaseMainnetRpcUrl, Permit2Address, QuoterAddress, UniversalRouterAddress } from "./constants";
|
|
13
|
+
import type { SwapQuote } from "./types";
|
|
14
|
+
|
|
15
|
+
// Minimal ABIs needed for swap functionality
|
|
16
|
+
const UNIVERSAL_ROUTER_ABI = [
|
|
17
|
+
{
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: "commands", type: "bytes" },
|
|
20
|
+
{ name: "inputs", type: "bytes[]" },
|
|
21
|
+
{ name: "deadline", type: "uint256" },
|
|
22
|
+
],
|
|
23
|
+
name: "execute",
|
|
24
|
+
outputs: [],
|
|
25
|
+
stateMutability: "payable",
|
|
26
|
+
type: "function",
|
|
27
|
+
},
|
|
28
|
+
] as const;
|
|
29
|
+
|
|
30
|
+
const QUOTER_ABI = [
|
|
31
|
+
{
|
|
32
|
+
inputs: [
|
|
33
|
+
{
|
|
34
|
+
components: [
|
|
35
|
+
{
|
|
36
|
+
components: [
|
|
37
|
+
{ internalType: "Currency", name: "currency0", type: "address" },
|
|
38
|
+
{ internalType: "Currency", name: "currency1", type: "address" },
|
|
39
|
+
{ internalType: "uint24", name: "fee", type: "uint24" },
|
|
40
|
+
{ internalType: "int24", name: "tickSpacing", type: "int24" },
|
|
41
|
+
{ internalType: "contract IHooks", name: "hooks", type: "address" },
|
|
42
|
+
],
|
|
43
|
+
internalType: "struct PoolKey",
|
|
44
|
+
name: "poolKey",
|
|
45
|
+
type: "tuple",
|
|
46
|
+
},
|
|
47
|
+
{ internalType: "bool", name: "zeroForOne", type: "bool" },
|
|
48
|
+
{ internalType: "uint128", name: "exactAmount", type: "uint128" },
|
|
49
|
+
{ internalType: "bytes", name: "hookData", type: "bytes" },
|
|
50
|
+
],
|
|
51
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
52
|
+
name: "params",
|
|
53
|
+
type: "tuple",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
name: "quoteExactInputSingle",
|
|
57
|
+
outputs: [
|
|
58
|
+
{ internalType: "uint256", name: "amountOut", type: "uint256" },
|
|
59
|
+
{ internalType: "uint256", name: "gasEstimate", type: "uint256" },
|
|
60
|
+
],
|
|
61
|
+
stateMutability: "nonpayable",
|
|
62
|
+
type: "function",
|
|
63
|
+
},
|
|
64
|
+
] as const;
|
|
65
|
+
|
|
66
|
+
const ERC20_ABI = [
|
|
67
|
+
{
|
|
68
|
+
inputs: [
|
|
69
|
+
{ name: "spender", type: "address" },
|
|
70
|
+
{ name: "amount", type: "uint256" },
|
|
71
|
+
],
|
|
72
|
+
name: "approve",
|
|
73
|
+
outputs: [{ name: "", type: "bool" }],
|
|
74
|
+
stateMutability: "nonpayable",
|
|
75
|
+
type: "function",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
inputs: [
|
|
79
|
+
{ name: "owner", type: "address" },
|
|
80
|
+
{ name: "spender", type: "address" },
|
|
81
|
+
],
|
|
82
|
+
name: "allowance",
|
|
83
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
84
|
+
stateMutability: "view",
|
|
85
|
+
type: "function",
|
|
86
|
+
},
|
|
87
|
+
] as const;
|
|
88
|
+
|
|
89
|
+
const PERMIT2_ABI = [
|
|
90
|
+
{
|
|
91
|
+
inputs: [
|
|
92
|
+
{ name: "token", type: "address" },
|
|
93
|
+
{ name: "spender", type: "address" },
|
|
94
|
+
{ name: "amount", type: "uint160" },
|
|
95
|
+
{ name: "expiration", type: "uint48" },
|
|
96
|
+
],
|
|
97
|
+
name: "approve",
|
|
98
|
+
outputs: [],
|
|
99
|
+
stateMutability: "nonpayable",
|
|
100
|
+
type: "function",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
inputs: [
|
|
104
|
+
{ name: "owner", type: "address" },
|
|
105
|
+
{ name: "token", type: "address" },
|
|
106
|
+
{ name: "spender", type: "address" },
|
|
107
|
+
],
|
|
108
|
+
name: "allowance",
|
|
109
|
+
outputs: [
|
|
110
|
+
{ name: "amount", type: "uint160" },
|
|
111
|
+
{ name: "expiration", type: "uint48" },
|
|
112
|
+
{ name: "nonce", type: "uint48" },
|
|
113
|
+
],
|
|
114
|
+
stateMutability: "view",
|
|
115
|
+
type: "function",
|
|
116
|
+
},
|
|
117
|
+
] as const;
|
|
118
|
+
|
|
119
|
+
const TOKEN_V4_CONFIG_ABI = [
|
|
120
|
+
{
|
|
121
|
+
inputs: [],
|
|
122
|
+
name: "v4Hook",
|
|
123
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
124
|
+
stateMutability: "view",
|
|
125
|
+
type: "function",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
inputs: [],
|
|
129
|
+
name: "v4PoolFee",
|
|
130
|
+
outputs: [{ internalType: "uint24", name: "", type: "uint24" }],
|
|
131
|
+
stateMutability: "view",
|
|
132
|
+
type: "function",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
inputs: [],
|
|
136
|
+
name: "v4TickSpacing",
|
|
137
|
+
outputs: [{ internalType: "int24", name: "", type: "int24" }],
|
|
138
|
+
stateMutability: "view",
|
|
139
|
+
type: "function",
|
|
140
|
+
},
|
|
141
|
+
] as const;
|
|
142
|
+
|
|
143
|
+
// Command and action constants
|
|
144
|
+
const COMMANDS = {
|
|
145
|
+
V4_SWAP: "0x10",
|
|
146
|
+
} as const;
|
|
147
|
+
|
|
148
|
+
const V4_ACTIONS = {
|
|
149
|
+
SWAP_EXACT_IN_SINGLE: 6,
|
|
150
|
+
TAKE_ALL: 15,
|
|
151
|
+
SETTLE_ALL: 12,
|
|
152
|
+
} as const;
|
|
153
|
+
|
|
154
|
+
interface V4PoolConfig {
|
|
155
|
+
hook: string;
|
|
156
|
+
fee: number;
|
|
157
|
+
tickSpacing: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface SwapParams {
|
|
161
|
+
tokenIn: Address;
|
|
162
|
+
tokenOut: Address;
|
|
163
|
+
amountIn: string;
|
|
164
|
+
tokenInDecimals: number;
|
|
165
|
+
tokenOutDecimals: number;
|
|
166
|
+
slippageTolerance: number;
|
|
167
|
+
recipient: Address;
|
|
168
|
+
deadline?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Internal swap service for handling Uniswap V4 swaps between trading token and bondkit token
|
|
173
|
+
*/
|
|
174
|
+
export class BondkitSwapService {
|
|
175
|
+
private v4Config: V4PoolConfig | null = null;
|
|
176
|
+
private configInitialized = false;
|
|
177
|
+
private readonly bondkitTokenAddress: Address;
|
|
178
|
+
private readonly publicClient: PublicClient;
|
|
179
|
+
|
|
180
|
+
constructor(bondkitTokenAddress: Address) {
|
|
181
|
+
this.bondkitTokenAddress = bondkitTokenAddress;
|
|
182
|
+
this.publicClient = createPublicClient({
|
|
183
|
+
chain: base,
|
|
184
|
+
transport: http(BaseMainnetRpcUrl),
|
|
185
|
+
}) as PublicClient;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Initialize V4 pool configuration from bondkit token contract
|
|
190
|
+
*/
|
|
191
|
+
private async initializeV4Config(): Promise<void> {
|
|
192
|
+
if (this.configInitialized) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const tokenContract = getContract({
|
|
198
|
+
address: this.bondkitTokenAddress,
|
|
199
|
+
abi: TOKEN_V4_CONFIG_ABI,
|
|
200
|
+
client: this.publicClient,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const [hook, fee, tickSpacing] = await Promise.all([
|
|
204
|
+
tokenContract.read.v4Hook(),
|
|
205
|
+
tokenContract.read.v4PoolFee(),
|
|
206
|
+
tokenContract.read.v4TickSpacing(),
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
this.v4Config = {
|
|
210
|
+
hook: hook as string,
|
|
211
|
+
fee: Number(fee),
|
|
212
|
+
tickSpacing: Number(tickSpacing),
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
this.configInitialized = true;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.warn("Failed to initialize V4 configuration:", error);
|
|
218
|
+
// Use fallback configuration
|
|
219
|
+
this.v4Config = {
|
|
220
|
+
hook: "0xB36f4A2FB18b745ef8eD31452781a463d2B3f0cC",
|
|
221
|
+
fee: 30000,
|
|
222
|
+
tickSpacing: 60,
|
|
223
|
+
};
|
|
224
|
+
this.configInitialized = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Get V4 pool configuration
|
|
230
|
+
*/
|
|
231
|
+
private async getV4Config(): Promise<V4PoolConfig> {
|
|
232
|
+
await this.initializeV4Config();
|
|
233
|
+
if (!this.v4Config) {
|
|
234
|
+
throw new Error("Failed to initialize V4 configuration");
|
|
235
|
+
}
|
|
236
|
+
return this.v4Config;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Handle token approvals for swap
|
|
241
|
+
*/
|
|
242
|
+
private async handleTokenApprovals(
|
|
243
|
+
tokenAddress: Address,
|
|
244
|
+
amountIn: string,
|
|
245
|
+
walletClient: WalletClient,
|
|
246
|
+
deadline: number,
|
|
247
|
+
): Promise<void> {
|
|
248
|
+
// Skip approvals for ETH
|
|
249
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const userAddress = walletClient.account?.address;
|
|
254
|
+
if (!userAddress) {
|
|
255
|
+
throw new Error("No user address found");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const erc20Contract = getContract({
|
|
259
|
+
address: tokenAddress,
|
|
260
|
+
abi: ERC20_ABI,
|
|
261
|
+
client: walletClient,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const permit2Contract = getContract({
|
|
265
|
+
address: Permit2Address,
|
|
266
|
+
abi: PERMIT2_ABI,
|
|
267
|
+
client: walletClient,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Check ERC20 allowance to Permit2
|
|
271
|
+
const currentAllowance = (await erc20Contract.read.allowance([userAddress, Permit2Address])) as bigint;
|
|
272
|
+
|
|
273
|
+
const requiredAmount = BigInt(amountIn);
|
|
274
|
+
|
|
275
|
+
if (currentAllowance < requiredAmount) {
|
|
276
|
+
await erc20Contract.write.approve(
|
|
277
|
+
[Permit2Address, BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")],
|
|
278
|
+
{
|
|
279
|
+
account: userAddress,
|
|
280
|
+
chain: base,
|
|
281
|
+
},
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Check Permit2 allowance for Universal Router
|
|
286
|
+
const permit2Allowance = (await permit2Contract.read.allowance([
|
|
287
|
+
userAddress,
|
|
288
|
+
tokenAddress,
|
|
289
|
+
UniversalRouterAddress,
|
|
290
|
+
])) as [bigint, number, number];
|
|
291
|
+
|
|
292
|
+
const [currentPermit2Amount, expiration] = permit2Allowance;
|
|
293
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
294
|
+
const isExpired = expiration <= currentTime;
|
|
295
|
+
|
|
296
|
+
if (currentPermit2Amount < requiredAmount || isExpired) {
|
|
297
|
+
await permit2Contract.write.approve(
|
|
298
|
+
[tokenAddress, UniversalRouterAddress, BigInt("0xffffffffffffffffffffffffffffffffffffff"), Number(deadline)],
|
|
299
|
+
{
|
|
300
|
+
account: userAddress,
|
|
301
|
+
chain: base,
|
|
302
|
+
},
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Get swap quote
|
|
309
|
+
*/
|
|
310
|
+
async getSwapQuote(params: SwapParams): Promise<SwapQuote | null> {
|
|
311
|
+
try {
|
|
312
|
+
const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, slippageTolerance } = params;
|
|
313
|
+
|
|
314
|
+
const v4Config = await this.getV4Config();
|
|
315
|
+
const amountInWei = parseUnits(amountIn, tokenInDecimals);
|
|
316
|
+
|
|
317
|
+
// Determine token order for pool
|
|
318
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
319
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
320
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
321
|
+
|
|
322
|
+
const poolKey = {
|
|
323
|
+
currency0: currency0 as Address,
|
|
324
|
+
currency1: currency1 as Address,
|
|
325
|
+
fee: v4Config.fee,
|
|
326
|
+
tickSpacing: v4Config.tickSpacing,
|
|
327
|
+
hooks: v4Config.hook as Address,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const quoteParams = {
|
|
331
|
+
poolKey,
|
|
332
|
+
zeroForOne,
|
|
333
|
+
exactAmount: BigInt(amountInWei.toString()),
|
|
334
|
+
hookData: "0x" as Hex,
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const { result } = await this.publicClient.simulateContract({
|
|
338
|
+
address: QuoterAddress,
|
|
339
|
+
abi: QUOTER_ABI,
|
|
340
|
+
functionName: "quoteExactInputSingle",
|
|
341
|
+
args: [quoteParams],
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const [amountOut] = result;
|
|
345
|
+
const amountOutRaw = formatUnits(amountOut, tokenOutDecimals);
|
|
346
|
+
const amountOutFormatted = parseFloat(amountOutRaw).toFixed(Math.min(6, tokenOutDecimals));
|
|
347
|
+
|
|
348
|
+
// Calculate minimum amount out with slippage
|
|
349
|
+
const slippageMultiplier = (100 - slippageTolerance) / 100;
|
|
350
|
+
const amountOutMinRaw = parseFloat(amountOutFormatted) * slippageMultiplier;
|
|
351
|
+
const amountOutMin = amountOutMinRaw.toFixed(tokenOutDecimals);
|
|
352
|
+
|
|
353
|
+
// Simple execution price calculation
|
|
354
|
+
const rate = parseFloat(amountOutFormatted) / parseFloat(amountIn);
|
|
355
|
+
const executionPrice = `1 = ${rate.toFixed(6)}`;
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
amountOut: amountOutFormatted,
|
|
359
|
+
amountOutMin,
|
|
360
|
+
priceImpact: "0.0", // Simplified
|
|
361
|
+
executionPrice,
|
|
362
|
+
fee: (v4Config.fee / 10000).toString(),
|
|
363
|
+
};
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.warn("Error getting swap quote:", error);
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Execute swap transaction
|
|
372
|
+
*/
|
|
373
|
+
async executeSwap(params: SwapParams, walletClient: WalletClient): Promise<string | null> {
|
|
374
|
+
try {
|
|
375
|
+
const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, deadline } = params;
|
|
376
|
+
|
|
377
|
+
const swapDeadline = deadline || Math.floor(Date.now() / 1000) + 3600;
|
|
378
|
+
|
|
379
|
+
if (!walletClient.account) {
|
|
380
|
+
throw new Error("Wallet client must have an account");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const amountInWei = parseUnits(amountIn, tokenInDecimals);
|
|
384
|
+
|
|
385
|
+
// Handle token approvals
|
|
386
|
+
await this.handleTokenApprovals(tokenIn, amountInWei.toString(), walletClient, swapDeadline);
|
|
387
|
+
|
|
388
|
+
// Get quote for minimum amount out
|
|
389
|
+
const quote = await this.getSwapQuote(params);
|
|
390
|
+
if (!quote) {
|
|
391
|
+
throw new Error("Unable to get swap quote");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const amountOutMinimum = parseUnits(quote.amountOutMin, tokenOutDecimals);
|
|
395
|
+
const v4Config = await this.getV4Config();
|
|
396
|
+
|
|
397
|
+
// Determine token order
|
|
398
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
399
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
400
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
401
|
+
|
|
402
|
+
const poolKey = [currency0, currency1, v4Config.fee, v4Config.tickSpacing, v4Config.hook];
|
|
403
|
+
|
|
404
|
+
// Encode V4 actions
|
|
405
|
+
const actions = [
|
|
406
|
+
{
|
|
407
|
+
type: V4_ACTIONS.SWAP_EXACT_IN_SINGLE,
|
|
408
|
+
params: [poolKey, zeroForOne, amountInWei, amountOutMinimum, "0x" as `0x${string}`],
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
type: V4_ACTIONS.TAKE_ALL,
|
|
412
|
+
params: [(zeroForOne ? currency1 : currency0) as Address, BigInt(0)],
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
type: V4_ACTIONS.SETTLE_ALL,
|
|
416
|
+
params: [(zeroForOne ? currency0 : currency1) as Address, amountInWei],
|
|
417
|
+
},
|
|
418
|
+
];
|
|
419
|
+
|
|
420
|
+
// Encode actions
|
|
421
|
+
const actionTypes = actions.map(action => action.type);
|
|
422
|
+
const actionsBytes = ("0x" + actionTypes.map(type => type.toString(16).padStart(2, "0")).join("")) as Hex;
|
|
423
|
+
|
|
424
|
+
const actionParams = actions.map(action => {
|
|
425
|
+
switch (action.type) {
|
|
426
|
+
case V4_ACTIONS.SWAP_EXACT_IN_SINGLE:
|
|
427
|
+
return encodeAbiParameters(
|
|
428
|
+
parseAbiParameters("((address,address,uint24,int24,address),bool,uint128,uint128,bytes)"),
|
|
429
|
+
[action.params as any],
|
|
430
|
+
);
|
|
431
|
+
case V4_ACTIONS.TAKE_ALL:
|
|
432
|
+
return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params as [Address, bigint]);
|
|
433
|
+
case V4_ACTIONS.SETTLE_ALL:
|
|
434
|
+
return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params as [Address, bigint]);
|
|
435
|
+
default:
|
|
436
|
+
return "0x00" as Hex;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
const v4SwapInput = encodeAbiParameters(parseAbiParameters("bytes,bytes[]"), [actionsBytes, actionParams]);
|
|
441
|
+
|
|
442
|
+
const commands = COMMANDS.V4_SWAP;
|
|
443
|
+
const inputs = [v4SwapInput];
|
|
444
|
+
|
|
445
|
+
// Execute swap
|
|
446
|
+
const universalRouter = getContract({
|
|
447
|
+
address: UniversalRouterAddress,
|
|
448
|
+
abi: UNIVERSAL_ROUTER_ABI,
|
|
449
|
+
client: walletClient,
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
const txHash = await universalRouter.write.execute([commands, inputs, BigInt(swapDeadline)], {
|
|
453
|
+
account: walletClient.account,
|
|
454
|
+
chain: base,
|
|
455
|
+
value: tokenIn === "0x0000000000000000000000000000000000000000" ? amountInWei : BigInt(0),
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
return txHash;
|
|
459
|
+
} catch (error) {
|
|
460
|
+
console.warn("Error executing swap:", error);
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
package/src/bondkit/types.ts
CHANGED
|
@@ -64,12 +64,11 @@ export type DexMigrationEventArgs = {
|
|
|
64
64
|
ethForFeeRecipient: bigint;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
// Enum for Status (
|
|
67
|
+
// Enum for Status (matches contract Status enum exactly)
|
|
68
68
|
export enum TokenStatus {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Migrated = 3,
|
|
69
|
+
Uninitialized = 0,
|
|
70
|
+
Bonding = 1,
|
|
71
|
+
Dex = 2,
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
export interface GetTransactionHistoryOptions {
|
|
@@ -101,3 +100,11 @@ export interface TransactionResponse {
|
|
|
101
100
|
skip: number;
|
|
102
101
|
data: Transaction[];
|
|
103
102
|
}
|
|
103
|
+
|
|
104
|
+
export interface SwapQuote {
|
|
105
|
+
amountOut: string;
|
|
106
|
+
amountOutMin: string;
|
|
107
|
+
priceImpact: string;
|
|
108
|
+
executionPrice: string;
|
|
109
|
+
fee: string;
|
|
110
|
+
}
|
|
@@ -4,6 +4,7 @@ import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permission
|
|
|
4
4
|
import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
|
|
5
5
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
6
6
|
import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
|
|
7
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
7
8
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
8
9
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
9
10
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
@@ -23,6 +24,8 @@ import { ClientType, setClientType } from "../../../client-manager";
|
|
|
23
24
|
import { StyleRoot } from "../StyleRoot";
|
|
24
25
|
import { B3Context, B3ContextType } from "./types";
|
|
25
26
|
|
|
27
|
+
const debug = debugB3React("B3Provider");
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* Default permissions configuration for B3 provider
|
|
28
31
|
*/
|
|
@@ -48,6 +51,7 @@ export function B3Provider({
|
|
|
48
51
|
simDuneApiKey,
|
|
49
52
|
toaster,
|
|
50
53
|
clientType = "rest",
|
|
54
|
+
rpcUrls,
|
|
51
55
|
partnerId,
|
|
52
56
|
}: {
|
|
53
57
|
theme: "light" | "dark";
|
|
@@ -61,6 +65,7 @@ export function B3Provider({
|
|
|
61
65
|
style?: React.CSSProperties;
|
|
62
66
|
};
|
|
63
67
|
clientType?: ClientType;
|
|
68
|
+
rpcUrls?: Record<number, string>;
|
|
64
69
|
partnerId?: string;
|
|
65
70
|
}) {
|
|
66
71
|
// Initialize Google Analytics on mount
|
|
@@ -83,22 +88,30 @@ export function B3Provider({
|
|
|
83
88
|
};
|
|
84
89
|
}, [partnerId]);
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
92
|
+
// when parent component passes new object references with same content
|
|
93
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
97
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
98
|
+
*/
|
|
99
|
+
const wagmiConfig = useMemo(() => {
|
|
100
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
101
|
+
|
|
102
|
+
return createConfig({
|
|
103
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
104
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
105
|
+
connectors: [
|
|
106
|
+
inAppWalletConnector({
|
|
107
|
+
...(ecocystemConfig || {}),
|
|
108
|
+
client,
|
|
109
|
+
}),
|
|
110
|
+
// injected(),
|
|
111
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
}, [ecocystemConfig, rpcUrlsString]);
|
|
102
115
|
|
|
103
116
|
return (
|
|
104
117
|
<ThirdwebProvider>
|
|
@@ -151,21 +164,7 @@ export function InnerProvider({
|
|
|
151
164
|
const wallets = useConnectedWallets();
|
|
152
165
|
const setActiveWallet = useSetActiveWallet();
|
|
153
166
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// Get auth token fro mecosystm wallet
|
|
157
|
-
useEffect(() => {
|
|
158
|
-
async function getEcosystemAccount() {
|
|
159
|
-
const ecosystemWallet = wallets.find(wallet => wallet.id === ecosystemWalletId);
|
|
160
|
-
if (ecosystemWallet) {
|
|
161
|
-
const authToken = ecosystemWallet.getAuthToken?.();
|
|
162
|
-
const ecosystemAccount = await ecosystemWallet.getAccount();
|
|
163
|
-
console.log("@wallets:@authToken", authToken);
|
|
164
|
-
console.log("@@wallets:ecosystemAccount", ecosystemAccount);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
getEcosystemAccount();
|
|
168
|
-
}, [wallets]);
|
|
167
|
+
debug("@@wallets", wallets);
|
|
169
168
|
|
|
170
169
|
const [user, setUser] = useState<Users | undefined>(() => {
|
|
171
170
|
// Try to restore user from localStorage on initialization
|
|
@@ -199,7 +198,7 @@ export function InnerProvider({
|
|
|
199
198
|
(wallet: Wallet) => {
|
|
200
199
|
setManuallySelectedWallet(wallet);
|
|
201
200
|
const account = wallet.getAccount();
|
|
202
|
-
|
|
201
|
+
debug("@@setWallet", wallet.id, account?.address);
|
|
203
202
|
setActiveWallet(wallet);
|
|
204
203
|
},
|
|
205
204
|
[setManuallySelectedWallet, setActiveWallet],
|