@b3dotfun/sdk 0.0.40 → 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/react/components/AnySpend.d.ts +11 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +17 -4
- 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 +33 -11
- 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 +6 -3
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +5 -3
- 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.js +8 -11
- 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/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/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 +4 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +41 -9
- 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/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/react/components/AnySpend.d.ts +11 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +17 -4
- 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 +33 -11
- 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 +6 -3
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +6 -4
- 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.js +8 -11
- 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/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/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 +4 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +42 -9
- 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/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/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/CryptoPaySection.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- 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/PointsBadge.d.ts +7 -0
- package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -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 +4 -3
- 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 +6 -5
- package/src/anyspend/react/components/AnySpend.tsx +37 -1
- 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 +63 -13
- 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 +22 -0
- package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +7 -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 +10 -14
- 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/PointsBadge.tsx +20 -0
- package/src/anyspend/react/components/common/PointsDetailPanel.tsx +55 -0
- 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 +55 -15
- 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/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
|
@@ -13,13 +13,15 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
13
13
|
import { base } from "viem/chains";
|
|
14
14
|
import { BondkitTokenABI } from "./abis";
|
|
15
15
|
import { getConfig } from "./config";
|
|
16
|
+
import { BondkitSwapService } from "./swapService";
|
|
16
17
|
import type {
|
|
17
18
|
BondkitTokenInitializationConfig,
|
|
18
19
|
GetTransactionHistoryOptions,
|
|
20
|
+
SwapQuote,
|
|
19
21
|
TokenDetails,
|
|
20
|
-
TokenStatus,
|
|
21
22
|
TransactionResponse,
|
|
22
23
|
} from "./types";
|
|
24
|
+
import { TokenStatus } from "./types";
|
|
23
25
|
|
|
24
26
|
// Event ABI snippets for decoding
|
|
25
27
|
const boughtEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
@@ -53,9 +55,10 @@ export class BondkitToken {
|
|
|
53
55
|
private walletClientInstance: WalletClient;
|
|
54
56
|
private connectedProvider?: EIP1193Provider;
|
|
55
57
|
private tradingToken?: Address;
|
|
58
|
+
private swapService?: BondkitSwapService;
|
|
56
59
|
|
|
57
|
-
constructor(contractAddress: string, walletKey?: string) {
|
|
58
|
-
const sdkConfig = getConfig(base.id);
|
|
60
|
+
constructor(contractAddress: string, walletKey?: string, rpcUrl?: string) {
|
|
61
|
+
const sdkConfig = getConfig(base.id, rpcUrl);
|
|
59
62
|
this.chain = sdkConfig.chain;
|
|
60
63
|
this.rpcUrl = sdkConfig.rpcUrl;
|
|
61
64
|
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
@@ -657,6 +660,323 @@ export class BondkitToken {
|
|
|
657
660
|
return this.executeWrite("renounceOwnership", [], options);
|
|
658
661
|
}
|
|
659
662
|
|
|
663
|
+
// --- DEX Swap Methods ---
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Get the swap service instance (lazy initialization)
|
|
667
|
+
*/
|
|
668
|
+
private getSwapService(): BondkitSwapService {
|
|
669
|
+
if (!this.swapService) {
|
|
670
|
+
this.swapService = new BondkitSwapService(this.contractAddress);
|
|
671
|
+
}
|
|
672
|
+
return this.swapService;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Check if DEX swapping is available (token must be in Dex phase)
|
|
677
|
+
*/
|
|
678
|
+
public async isSwapAvailable(): Promise<boolean | undefined> {
|
|
679
|
+
try {
|
|
680
|
+
const status = await this.currentStatus();
|
|
681
|
+
return status === TokenStatus.Dex;
|
|
682
|
+
} catch (error) {
|
|
683
|
+
console.warn("Error checking swap availability:", error);
|
|
684
|
+
return undefined;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Get swap quote for trading token → bondkit token
|
|
690
|
+
*/
|
|
691
|
+
public async getSwapQuoteForBondkitToken(
|
|
692
|
+
amountTradingTokenIn: string,
|
|
693
|
+
slippageTolerance = 0.5,
|
|
694
|
+
): Promise<SwapQuote | undefined> {
|
|
695
|
+
try {
|
|
696
|
+
// Check if swapping is available
|
|
697
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
698
|
+
if (!swapAvailable) {
|
|
699
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
700
|
+
return undefined;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
704
|
+
if (!tradingTokenAddress) {
|
|
705
|
+
console.warn("Trading token address not available");
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Get token details for decimals
|
|
710
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
711
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
712
|
+
this.decimals(),
|
|
713
|
+
]);
|
|
714
|
+
|
|
715
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
716
|
+
console.warn("Unable to fetch token decimals");
|
|
717
|
+
return undefined;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const swapService = this.getSwapService();
|
|
721
|
+
const quote = await swapService.getSwapQuote({
|
|
722
|
+
tokenIn: tradingTokenAddress,
|
|
723
|
+
tokenOut: this.contractAddress,
|
|
724
|
+
amountIn: amountTradingTokenIn,
|
|
725
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
726
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
727
|
+
slippageTolerance,
|
|
728
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
729
|
+
});
|
|
730
|
+
return quote || undefined;
|
|
731
|
+
} catch (error) {
|
|
732
|
+
console.warn("Error getting swap quote for bondkit token:", error);
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Get swap quote for bondkit token → trading token
|
|
739
|
+
*/
|
|
740
|
+
public async getSwapQuoteForTradingToken(
|
|
741
|
+
amountBondkitTokenIn: string,
|
|
742
|
+
slippageTolerance = 0.5,
|
|
743
|
+
): Promise<SwapQuote | undefined> {
|
|
744
|
+
try {
|
|
745
|
+
// Check if swapping is available
|
|
746
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
747
|
+
if (!swapAvailable) {
|
|
748
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
749
|
+
return undefined;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
753
|
+
if (!tradingTokenAddress) {
|
|
754
|
+
console.warn("Trading token address not available");
|
|
755
|
+
return undefined;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Get token details for decimals
|
|
759
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
760
|
+
this.decimals(),
|
|
761
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
762
|
+
]);
|
|
763
|
+
|
|
764
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
765
|
+
console.warn("Unable to fetch token decimals");
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const swapService = this.getSwapService();
|
|
770
|
+
const quote = await swapService.getSwapQuote({
|
|
771
|
+
tokenIn: this.contractAddress,
|
|
772
|
+
tokenOut: tradingTokenAddress,
|
|
773
|
+
amountIn: amountBondkitTokenIn,
|
|
774
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
775
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
776
|
+
slippageTolerance,
|
|
777
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
778
|
+
});
|
|
779
|
+
return quote || undefined;
|
|
780
|
+
} catch (error) {
|
|
781
|
+
console.warn("Error getting swap quote for trading token:", error);
|
|
782
|
+
return undefined;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Swap trading token for bondkit token
|
|
788
|
+
*/
|
|
789
|
+
public async swapTradingTokenForBondkitToken(
|
|
790
|
+
amountTradingTokenIn: string,
|
|
791
|
+
slippageTolerance = 0.5,
|
|
792
|
+
options?: ExecuteWriteOptions,
|
|
793
|
+
): Promise<Hex | undefined> {
|
|
794
|
+
try {
|
|
795
|
+
// Check if swapping is available
|
|
796
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
797
|
+
if (!swapAvailable) {
|
|
798
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
799
|
+
return undefined;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
803
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
808
|
+
if (!tradingTokenAddress) {
|
|
809
|
+
console.warn("Trading token address not available");
|
|
810
|
+
return undefined;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Get token details for decimals
|
|
814
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
815
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
816
|
+
this.decimals(),
|
|
817
|
+
]);
|
|
818
|
+
|
|
819
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
820
|
+
console.warn("Unable to fetch token decimals");
|
|
821
|
+
return undefined;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const recipient =
|
|
825
|
+
this.walletClientInstance.account?.address ||
|
|
826
|
+
(this.walletKey ? privateKeyToAccount(this.walletKey).address : undefined);
|
|
827
|
+
|
|
828
|
+
if (!recipient) {
|
|
829
|
+
console.warn("Unable to determine recipient address");
|
|
830
|
+
return undefined;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
const swapService = this.getSwapService();
|
|
834
|
+
const txHash = await swapService.executeSwap(
|
|
835
|
+
{
|
|
836
|
+
tokenIn: tradingTokenAddress,
|
|
837
|
+
tokenOut: this.contractAddress,
|
|
838
|
+
amountIn: amountTradingTokenIn,
|
|
839
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
840
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
841
|
+
slippageTolerance,
|
|
842
|
+
recipient,
|
|
843
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
844
|
+
},
|
|
845
|
+
this.walletClientInstance,
|
|
846
|
+
);
|
|
847
|
+
|
|
848
|
+
return txHash ? (txHash as Hex) : undefined;
|
|
849
|
+
} catch (error) {
|
|
850
|
+
console.warn("Error swapping trading token for bondkit token:", error);
|
|
851
|
+
return undefined;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Swap bondkit token for trading token
|
|
857
|
+
*/
|
|
858
|
+
public async swapBondkitTokenForTradingToken(
|
|
859
|
+
amountBondkitTokenIn: string,
|
|
860
|
+
slippageTolerance = 0.5,
|
|
861
|
+
options?: ExecuteWriteOptions,
|
|
862
|
+
): Promise<Hex | undefined> {
|
|
863
|
+
try {
|
|
864
|
+
// Check if swapping is available
|
|
865
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
866
|
+
if (!swapAvailable) {
|
|
867
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
868
|
+
return undefined;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
872
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
877
|
+
if (!tradingTokenAddress) {
|
|
878
|
+
console.warn("Trading token address not available");
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// Get token details for decimals
|
|
883
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
884
|
+
this.decimals(),
|
|
885
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
886
|
+
]);
|
|
887
|
+
|
|
888
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
889
|
+
console.warn("Unable to fetch token decimals");
|
|
890
|
+
return undefined;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const recipient =
|
|
894
|
+
this.walletClientInstance.account?.address ||
|
|
895
|
+
(this.walletKey ? privateKeyToAccount(this.walletKey).address : undefined);
|
|
896
|
+
|
|
897
|
+
if (!recipient) {
|
|
898
|
+
console.warn("Unable to determine recipient address");
|
|
899
|
+
return undefined;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
const swapService = this.getSwapService();
|
|
903
|
+
const txHash = await swapService.executeSwap(
|
|
904
|
+
{
|
|
905
|
+
tokenIn: this.contractAddress,
|
|
906
|
+
tokenOut: tradingTokenAddress,
|
|
907
|
+
amountIn: amountBondkitTokenIn,
|
|
908
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
909
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
910
|
+
slippageTolerance,
|
|
911
|
+
recipient,
|
|
912
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
913
|
+
},
|
|
914
|
+
this.walletClientInstance,
|
|
915
|
+
);
|
|
916
|
+
|
|
917
|
+
return txHash ? (txHash as Hex) : undefined;
|
|
918
|
+
} catch (error) {
|
|
919
|
+
console.warn("Error swapping bondkit token for trading token:", error);
|
|
920
|
+
return undefined;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Helper method to get trading token decimals
|
|
926
|
+
*/
|
|
927
|
+
private async getTradingTokenDecimals(tradingTokenAddress: Address): Promise<number | undefined> {
|
|
928
|
+
try {
|
|
929
|
+
// ETH has 18 decimals
|
|
930
|
+
if (tradingTokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
931
|
+
return 18;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// For ERC20 tokens, read decimals from contract
|
|
935
|
+
const tradingTokenContract = getContract({
|
|
936
|
+
address: tradingTokenAddress,
|
|
937
|
+
abi: erc20Abi,
|
|
938
|
+
client: this.publicClient,
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
const decimals = await tradingTokenContract.read.decimals();
|
|
942
|
+
return Number(decimals);
|
|
943
|
+
} catch (error) {
|
|
944
|
+
console.warn("Error fetching trading token decimals:", error);
|
|
945
|
+
return undefined;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Get trading token symbol
|
|
951
|
+
* @param tradingTokenAddress Optional trading token address to avoid fetching it again
|
|
952
|
+
*/
|
|
953
|
+
public async getTradingTokenSymbol(tradingTokenAddress?: Address): Promise<string | undefined> {
|
|
954
|
+
try {
|
|
955
|
+
const tokenAddress = tradingTokenAddress || (await this.getTradingTokenAddress());
|
|
956
|
+
if (!tokenAddress) {
|
|
957
|
+
return undefined;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// ETH symbol
|
|
961
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
962
|
+
return "ETH";
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// For ERC20 tokens, read symbol from contract
|
|
966
|
+
const tradingTokenContract = getContract({
|
|
967
|
+
address: tokenAddress,
|
|
968
|
+
abi: erc20Abi,
|
|
969
|
+
client: this.publicClient,
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
const symbol = await tradingTokenContract.read.symbol();
|
|
973
|
+
return symbol;
|
|
974
|
+
} catch (error) {
|
|
975
|
+
console.warn("Error fetching trading token symbol:", error);
|
|
976
|
+
return undefined;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
660
980
|
// TODO: Add other specific write methods from BondkitTokenABI.ts
|
|
661
981
|
// e.g., setBondingCurve (if it exists and is external), updateArtistAddress, etc.
|
|
662
982
|
}
|
|
@@ -30,14 +30,14 @@ export class BondkitTokenFactory {
|
|
|
30
30
|
private walletClientInstance: WalletClient; // Made non-optional, initialized in constructor
|
|
31
31
|
private connectedProvider?: EIP1193Provider;
|
|
32
32
|
|
|
33
|
-
constructor(chainId: SupportedChainId, walletKey?: string) {
|
|
33
|
+
constructor(chainId: SupportedChainId, walletKey?: string, rpcUrl?: string) {
|
|
34
34
|
if (walletKey && !walletKey.startsWith("0x")) {
|
|
35
35
|
this.walletKey = `0x${walletKey}` as Hex;
|
|
36
36
|
} else if (walletKey) {
|
|
37
37
|
this.walletKey = walletKey as Hex;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const config = getConfig(chainId);
|
|
40
|
+
const config = getConfig(chainId, rpcUrl);
|
|
41
41
|
this.chain = config.chain;
|
|
42
42
|
this.contractAddress = config.factoryAddress;
|
|
43
43
|
this.rpcUrl = config.rpcUrl;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { loadScriptFromCDN } from "./utils/cdn-loader";
|
|
4
|
-
import { formatNumberSmall } from "./utils/format";
|
|
5
3
|
import { Loader2 } from "lucide-react";
|
|
6
4
|
import { useEffect, useRef, useState } from "react";
|
|
7
5
|
import { TradingViewProps } from "./types";
|
|
6
|
+
import { loadScriptFromCDN } from "./utils/cdn-loader";
|
|
7
|
+
import { formatNumberSmall } from "./utils/format";
|
|
8
8
|
|
|
9
9
|
// TypeScript types - these will be loaded from CDN at runtime
|
|
10
10
|
type ChartingLibraryWidgetOptions = any;
|
|
@@ -24,8 +24,6 @@ const GifLoadingOverlay = ({ className }: { className?: string }) => (
|
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
const TradingView = ({ className, tokenAddress, tokenSymbol }: TradingViewProps) => {
|
|
27
|
-
const theme = "light";
|
|
28
|
-
|
|
29
27
|
// Use token info for the current trade
|
|
30
28
|
const currentTrade = {
|
|
31
29
|
product_id: tokenAddress && tokenSymbol ? `${tokenSymbol}-${tokenAddress}` : "BONDKIT",
|
|
@@ -282,7 +280,7 @@ const TradingView = ({ className, tokenAddress, tokenSymbol }: TradingViewProps)
|
|
|
282
280
|
tvWidgetRef.current = null;
|
|
283
281
|
}
|
|
284
282
|
};
|
|
285
|
-
}, [
|
|
283
|
+
}, [librariesLoaded, currentTrade?.product_id, tradingViewDefaultInterval, tradingViewTimezone]);
|
|
286
284
|
|
|
287
285
|
useEffect(() => {
|
|
288
286
|
if (
|
package/src/bondkit/config.ts
CHANGED
|
@@ -18,9 +18,12 @@ const baseMainnetConfig: Config = {
|
|
|
18
18
|
apiEndpoint: "https://api.b3.fun/bondkit-tokens",
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const getConfig = (chainId: number): Config => {
|
|
21
|
+
export const getConfig = (chainId: number, rpcUrl?: string): Config => {
|
|
22
22
|
if (chainId === base.id) {
|
|
23
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...baseMainnetConfig,
|
|
25
|
+
rpcUrl: rpcUrl || BaseMainnetRpcUrl,
|
|
26
|
+
};
|
|
24
27
|
}
|
|
25
28
|
throw new Error(`Unsupported chainId: ${chainId}. This SDK is configured for Base (Chain ID: ${base.id}) only.`);
|
|
26
29
|
};
|
package/src/bondkit/constants.ts
CHANGED
|
@@ -3,3 +3,10 @@ import type { Address } from "viem";
|
|
|
3
3
|
export const BaseBondkitTokenFactoryContractAddress: Address = "0x5d641bbB206d4B5585eCCd919F36270200A9A2Ad";
|
|
4
4
|
|
|
5
5
|
export const BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";
|
|
6
|
+
|
|
7
|
+
// Uniswap V4 addresses on Base
|
|
8
|
+
export const UniversalRouterAddress: Address = "0x6ff5693b99212da76ad316178a184ab56d299b43";
|
|
9
|
+
export const QuoterAddress: Address = "0x0d5e0f971ed27fbff6c2837bf31316121532048d";
|
|
10
|
+
export const Permit2Address: Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
11
|
+
|
|
12
|
+
export const B3TokenAddress: Address = "0xB3B32F9f8827D4634fE7d973Fa1034Ec9fdDB3B3";
|
package/src/bondkit/index.ts
CHANGED