@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
|
@@ -3,6 +3,8 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
3
3
|
import { base } from "viem/chains";
|
|
4
4
|
import { BondkitTokenABI } from "./abis/index.js";
|
|
5
5
|
import { getConfig } from "./config.js";
|
|
6
|
+
import { BondkitSwapService } from "./swapService.js";
|
|
7
|
+
import { TokenStatus } from "./types.js";
|
|
6
8
|
// Event ABI snippets for decoding
|
|
7
9
|
const boughtEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
8
10
|
const soldEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
|
|
@@ -11,8 +13,8 @@ const dexMigrationEventAbi = BondkitTokenABI.find(item => item.type === "event"
|
|
|
11
13
|
const OKX_POLLING_MAX_RETRIES = 60; // 5 minutes with 5 second intervals
|
|
12
14
|
const OKX_POLLING_INTERVAL_MS = 5000; // 5 seconds
|
|
13
15
|
export class BondkitToken {
|
|
14
|
-
constructor(contractAddress, walletKey) {
|
|
15
|
-
const sdkConfig = getConfig(base.id);
|
|
16
|
+
constructor(contractAddress, walletKey, rpcUrl) {
|
|
17
|
+
const sdkConfig = getConfig(base.id, rpcUrl);
|
|
16
18
|
this.chain = sdkConfig.chain;
|
|
17
19
|
this.rpcUrl = sdkConfig.rpcUrl;
|
|
18
20
|
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
@@ -555,4 +557,268 @@ export class BondkitToken {
|
|
|
555
557
|
async renounceTokenOwnership(options) {
|
|
556
558
|
return this.executeWrite("renounceOwnership", [], options);
|
|
557
559
|
}
|
|
560
|
+
// --- DEX Swap Methods ---
|
|
561
|
+
/**
|
|
562
|
+
* Get the swap service instance (lazy initialization)
|
|
563
|
+
*/
|
|
564
|
+
getSwapService() {
|
|
565
|
+
if (!this.swapService) {
|
|
566
|
+
this.swapService = new BondkitSwapService(this.contractAddress);
|
|
567
|
+
}
|
|
568
|
+
return this.swapService;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Check if DEX swapping is available (token must be in Dex phase)
|
|
572
|
+
*/
|
|
573
|
+
async isSwapAvailable() {
|
|
574
|
+
try {
|
|
575
|
+
const status = await this.currentStatus();
|
|
576
|
+
return status === TokenStatus.Dex;
|
|
577
|
+
}
|
|
578
|
+
catch (error) {
|
|
579
|
+
console.warn("Error checking swap availability:", error);
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Get swap quote for trading token → bondkit token
|
|
585
|
+
*/
|
|
586
|
+
async getSwapQuoteForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5) {
|
|
587
|
+
try {
|
|
588
|
+
// Check if swapping is available
|
|
589
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
590
|
+
if (!swapAvailable) {
|
|
591
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
592
|
+
return undefined;
|
|
593
|
+
}
|
|
594
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
595
|
+
if (!tradingTokenAddress) {
|
|
596
|
+
console.warn("Trading token address not available");
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
// Get token details for decimals
|
|
600
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
601
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
602
|
+
this.decimals(),
|
|
603
|
+
]);
|
|
604
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
605
|
+
console.warn("Unable to fetch token decimals");
|
|
606
|
+
return undefined;
|
|
607
|
+
}
|
|
608
|
+
const swapService = this.getSwapService();
|
|
609
|
+
const quote = await swapService.getSwapQuote({
|
|
610
|
+
tokenIn: tradingTokenAddress,
|
|
611
|
+
tokenOut: this.contractAddress,
|
|
612
|
+
amountIn: amountTradingTokenIn,
|
|
613
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
614
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
615
|
+
slippageTolerance,
|
|
616
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
617
|
+
});
|
|
618
|
+
return quote || undefined;
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
console.warn("Error getting swap quote for bondkit token:", error);
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Get swap quote for bondkit token → trading token
|
|
627
|
+
*/
|
|
628
|
+
async getSwapQuoteForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5) {
|
|
629
|
+
try {
|
|
630
|
+
// Check if swapping is available
|
|
631
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
632
|
+
if (!swapAvailable) {
|
|
633
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
637
|
+
if (!tradingTokenAddress) {
|
|
638
|
+
console.warn("Trading token address not available");
|
|
639
|
+
return undefined;
|
|
640
|
+
}
|
|
641
|
+
// Get token details for decimals
|
|
642
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
643
|
+
this.decimals(),
|
|
644
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
645
|
+
]);
|
|
646
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
647
|
+
console.warn("Unable to fetch token decimals");
|
|
648
|
+
return undefined;
|
|
649
|
+
}
|
|
650
|
+
const swapService = this.getSwapService();
|
|
651
|
+
const quote = await swapService.getSwapQuote({
|
|
652
|
+
tokenIn: this.contractAddress,
|
|
653
|
+
tokenOut: tradingTokenAddress,
|
|
654
|
+
amountIn: amountBondkitTokenIn,
|
|
655
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
656
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
657
|
+
slippageTolerance,
|
|
658
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
659
|
+
});
|
|
660
|
+
return quote || undefined;
|
|
661
|
+
}
|
|
662
|
+
catch (error) {
|
|
663
|
+
console.warn("Error getting swap quote for trading token:", error);
|
|
664
|
+
return undefined;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Swap trading token for bondkit token
|
|
669
|
+
*/
|
|
670
|
+
async swapTradingTokenForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5, options) {
|
|
671
|
+
try {
|
|
672
|
+
// Check if swapping is available
|
|
673
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
674
|
+
if (!swapAvailable) {
|
|
675
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
678
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
679
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
683
|
+
if (!tradingTokenAddress) {
|
|
684
|
+
console.warn("Trading token address not available");
|
|
685
|
+
return undefined;
|
|
686
|
+
}
|
|
687
|
+
// Get token details for decimals
|
|
688
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
689
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
690
|
+
this.decimals(),
|
|
691
|
+
]);
|
|
692
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
693
|
+
console.warn("Unable to fetch token decimals");
|
|
694
|
+
return undefined;
|
|
695
|
+
}
|
|
696
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
697
|
+
(this.walletKey ? privateKeyToAccount(this.walletKey).address : undefined);
|
|
698
|
+
if (!recipient) {
|
|
699
|
+
console.warn("Unable to determine recipient address");
|
|
700
|
+
return undefined;
|
|
701
|
+
}
|
|
702
|
+
const swapService = this.getSwapService();
|
|
703
|
+
const txHash = await swapService.executeSwap({
|
|
704
|
+
tokenIn: tradingTokenAddress,
|
|
705
|
+
tokenOut: this.contractAddress,
|
|
706
|
+
amountIn: amountTradingTokenIn,
|
|
707
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
708
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
709
|
+
slippageTolerance,
|
|
710
|
+
recipient,
|
|
711
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
712
|
+
}, this.walletClientInstance);
|
|
713
|
+
return txHash ? txHash : undefined;
|
|
714
|
+
}
|
|
715
|
+
catch (error) {
|
|
716
|
+
console.warn("Error swapping trading token for bondkit token:", error);
|
|
717
|
+
return undefined;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Swap bondkit token for trading token
|
|
722
|
+
*/
|
|
723
|
+
async swapBondkitTokenForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5, options) {
|
|
724
|
+
try {
|
|
725
|
+
// Check if swapping is available
|
|
726
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
727
|
+
if (!swapAvailable) {
|
|
728
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
729
|
+
return undefined;
|
|
730
|
+
}
|
|
731
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
732
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
736
|
+
if (!tradingTokenAddress) {
|
|
737
|
+
console.warn("Trading token address not available");
|
|
738
|
+
return undefined;
|
|
739
|
+
}
|
|
740
|
+
// Get token details for decimals
|
|
741
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
742
|
+
this.decimals(),
|
|
743
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
744
|
+
]);
|
|
745
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
746
|
+
console.warn("Unable to fetch token decimals");
|
|
747
|
+
return undefined;
|
|
748
|
+
}
|
|
749
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
750
|
+
(this.walletKey ? privateKeyToAccount(this.walletKey).address : undefined);
|
|
751
|
+
if (!recipient) {
|
|
752
|
+
console.warn("Unable to determine recipient address");
|
|
753
|
+
return undefined;
|
|
754
|
+
}
|
|
755
|
+
const swapService = this.getSwapService();
|
|
756
|
+
const txHash = await swapService.executeSwap({
|
|
757
|
+
tokenIn: this.contractAddress,
|
|
758
|
+
tokenOut: tradingTokenAddress,
|
|
759
|
+
amountIn: amountBondkitTokenIn,
|
|
760
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
761
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
762
|
+
slippageTolerance,
|
|
763
|
+
recipient,
|
|
764
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
765
|
+
}, this.walletClientInstance);
|
|
766
|
+
return txHash ? txHash : undefined;
|
|
767
|
+
}
|
|
768
|
+
catch (error) {
|
|
769
|
+
console.warn("Error swapping bondkit token for trading token:", error);
|
|
770
|
+
return undefined;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Helper method to get trading token decimals
|
|
775
|
+
*/
|
|
776
|
+
async getTradingTokenDecimals(tradingTokenAddress) {
|
|
777
|
+
try {
|
|
778
|
+
// ETH has 18 decimals
|
|
779
|
+
if (tradingTokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
780
|
+
return 18;
|
|
781
|
+
}
|
|
782
|
+
// For ERC20 tokens, read decimals from contract
|
|
783
|
+
const tradingTokenContract = getContract({
|
|
784
|
+
address: tradingTokenAddress,
|
|
785
|
+
abi: erc20Abi,
|
|
786
|
+
client: this.publicClient,
|
|
787
|
+
});
|
|
788
|
+
const decimals = await tradingTokenContract.read.decimals();
|
|
789
|
+
return Number(decimals);
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
console.warn("Error fetching trading token decimals:", error);
|
|
793
|
+
return undefined;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Get trading token symbol
|
|
798
|
+
* @param tradingTokenAddress Optional trading token address to avoid fetching it again
|
|
799
|
+
*/
|
|
800
|
+
async getTradingTokenSymbol(tradingTokenAddress) {
|
|
801
|
+
try {
|
|
802
|
+
const tokenAddress = tradingTokenAddress || (await this.getTradingTokenAddress());
|
|
803
|
+
if (!tokenAddress) {
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
// ETH symbol
|
|
807
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
808
|
+
return "ETH";
|
|
809
|
+
}
|
|
810
|
+
// For ERC20 tokens, read symbol from contract
|
|
811
|
+
const tradingTokenContract = getContract({
|
|
812
|
+
address: tokenAddress,
|
|
813
|
+
abi: erc20Abi,
|
|
814
|
+
client: this.publicClient,
|
|
815
|
+
});
|
|
816
|
+
const symbol = await tradingTokenContract.read.symbol();
|
|
817
|
+
return symbol;
|
|
818
|
+
}
|
|
819
|
+
catch (error) {
|
|
820
|
+
console.warn("Error fetching trading token symbol:", error);
|
|
821
|
+
return undefined;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
558
824
|
}
|
|
@@ -10,7 +10,7 @@ export declare class BondkitTokenFactory {
|
|
|
10
10
|
private rpcUrl;
|
|
11
11
|
private walletClientInstance;
|
|
12
12
|
private connectedProvider?;
|
|
13
|
-
constructor(chainId: SupportedChainId, walletKey?: string);
|
|
13
|
+
constructor(chainId: SupportedChainId, walletKey?: string, rpcUrl?: string);
|
|
14
14
|
connect(provider?: EIP1193Provider): boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|
|
@@ -5,14 +5,14 @@ import { getConfig } from "./config.js";
|
|
|
5
5
|
// Define the event ABI snippet for BondkitTokenCreated specifically for decoding
|
|
6
6
|
const bondkitTokenCreatedEventAbi = BondkitTokenFactoryABI.find(item => item.type === "event" && item.name === "BondkitTokenCreated");
|
|
7
7
|
export class BondkitTokenFactory {
|
|
8
|
-
constructor(chainId, walletKey) {
|
|
8
|
+
constructor(chainId, walletKey, rpcUrl) {
|
|
9
9
|
if (walletKey && !walletKey.startsWith("0x")) {
|
|
10
10
|
this.walletKey = `0x${walletKey}`;
|
|
11
11
|
}
|
|
12
12
|
else if (walletKey) {
|
|
13
13
|
this.walletKey = walletKey;
|
|
14
14
|
}
|
|
15
|
-
const config = getConfig(chainId);
|
|
15
|
+
const config = getConfig(chainId, rpcUrl);
|
|
16
16
|
this.chain = config.chain;
|
|
17
17
|
this.contractAddress = config.factoryAddress;
|
|
18
18
|
this.rpcUrl = config.rpcUrl;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { loadScriptFromCDN } from "./utils/cdn-loader.js";
|
|
4
|
-
import { formatNumberSmall } from "./utils/format.js";
|
|
5
3
|
import { Loader2 } from "lucide-react";
|
|
6
4
|
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { loadScriptFromCDN } from "./utils/cdn-loader.js";
|
|
6
|
+
import { formatNumberSmall } from "./utils/format.js";
|
|
7
7
|
// TradingView will be available on window after loading from CDN
|
|
8
8
|
// Datafeed will be implemented inline
|
|
9
9
|
// Mock loading overlay - replace with your actual loading component
|
|
10
10
|
const GifLoadingOverlay = ({ className }) => (_jsx("div", { className: `absolute inset-0 flex items-center justify-center bg-white/50 backdrop-blur-sm ${className || ""}`, children: _jsx(Loader2, { className: "text-secondary-grey h-8 w-8 animate-spin" }) }));
|
|
11
11
|
const TradingView = ({ className, tokenAddress, tokenSymbol }) => {
|
|
12
|
-
const theme = "light";
|
|
13
12
|
// Use token info for the current trade
|
|
14
13
|
const currentTrade = {
|
|
15
14
|
product_id: tokenAddress && tokenSymbol ? `${tokenSymbol}-${tokenAddress}` : "BONDKIT",
|
|
@@ -245,7 +244,7 @@ const TradingView = ({ className, tokenAddress, tokenSymbol }) => {
|
|
|
245
244
|
tvWidgetRef.current = null;
|
|
246
245
|
}
|
|
247
246
|
};
|
|
248
|
-
}, [
|
|
247
|
+
}, [librariesLoaded, currentTrade?.product_id, tradingViewDefaultInterval, tradingViewTimezone]);
|
|
249
248
|
useEffect(() => {
|
|
250
249
|
if (chartLoaded &&
|
|
251
250
|
currentTrade?.product_id &&
|
|
@@ -6,9 +6,12 @@ const baseMainnetConfig = {
|
|
|
6
6
|
factoryAddress: BaseBondkitTokenFactoryContractAddress,
|
|
7
7
|
apiEndpoint: "https://api.b3.fun/bondkit-tokens",
|
|
8
8
|
};
|
|
9
|
-
export const getConfig = (chainId) => {
|
|
9
|
+
export const getConfig = (chainId, rpcUrl) => {
|
|
10
10
|
if (chainId === base.id) {
|
|
11
|
-
return
|
|
11
|
+
return {
|
|
12
|
+
...baseMainnetConfig,
|
|
13
|
+
rpcUrl: rpcUrl || BaseMainnetRpcUrl,
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
throw new Error(`Unsupported chainId: ${chainId}. This SDK is configured for Base (Chain ID: ${base.id}) only.`);
|
|
14
17
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
export declare const BaseBondkitTokenFactoryContractAddress: Address;
|
|
3
3
|
export declare const BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";
|
|
4
|
+
export declare const UniversalRouterAddress: Address;
|
|
5
|
+
export declare const QuoterAddress: Address;
|
|
6
|
+
export declare const Permit2Address: Address;
|
|
7
|
+
export declare const B3TokenAddress: Address;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export const BaseBondkitTokenFactoryContractAddress = "0x5d641bbB206d4B5585eCCd919F36270200A9A2Ad";
|
|
2
2
|
export const BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";
|
|
3
|
+
// Uniswap V4 addresses on Base
|
|
4
|
+
export const UniversalRouterAddress = "0x6ff5693b99212da76ad316178a184ab56d299b43";
|
|
5
|
+
export const QuoterAddress = "0x0d5e0f971ed27fbff6c2837bf31316121532048d";
|
|
6
|
+
export const Permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
7
|
+
export const B3TokenAddress = "0xB3B32F9f8827D4634fE7d973Fa1034Ec9fdDB3B3";
|
|
@@ -8,5 +8,7 @@ export * from "./constants.js";
|
|
|
8
8
|
export * from "./types.js";
|
|
9
9
|
// ABIs
|
|
10
10
|
export * from "./abis/index.js";
|
|
11
|
+
// Swap functionality
|
|
12
|
+
export { BondkitSwapService } from "./swapService.js";
|
|
11
13
|
// Components
|
|
12
14
|
export { default as TradingView } from "./components/TradingView.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Address, WalletClient } from "viem";
|
|
2
|
+
import type { SwapQuote } from "./types";
|
|
3
|
+
interface SwapParams {
|
|
4
|
+
tokenIn: Address;
|
|
5
|
+
tokenOut: Address;
|
|
6
|
+
amountIn: string;
|
|
7
|
+
tokenInDecimals: number;
|
|
8
|
+
tokenOutDecimals: number;
|
|
9
|
+
slippageTolerance: number;
|
|
10
|
+
recipient: Address;
|
|
11
|
+
deadline?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Internal swap service for handling Uniswap V4 swaps between trading token and bondkit token
|
|
15
|
+
*/
|
|
16
|
+
export declare class BondkitSwapService {
|
|
17
|
+
private v4Config;
|
|
18
|
+
private configInitialized;
|
|
19
|
+
private readonly bondkitTokenAddress;
|
|
20
|
+
private readonly publicClient;
|
|
21
|
+
constructor(bondkitTokenAddress: Address);
|
|
22
|
+
/**
|
|
23
|
+
* Initialize V4 pool configuration from bondkit token contract
|
|
24
|
+
*/
|
|
25
|
+
private initializeV4Config;
|
|
26
|
+
/**
|
|
27
|
+
* Get V4 pool configuration
|
|
28
|
+
*/
|
|
29
|
+
private getV4Config;
|
|
30
|
+
/**
|
|
31
|
+
* Handle token approvals for swap
|
|
32
|
+
*/
|
|
33
|
+
private handleTokenApprovals;
|
|
34
|
+
/**
|
|
35
|
+
* Get swap quote
|
|
36
|
+
*/
|
|
37
|
+
getSwapQuote(params: SwapParams): Promise<SwapQuote | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute swap transaction
|
|
40
|
+
*/
|
|
41
|
+
executeSwap(params: SwapParams, walletClient: WalletClient): Promise<string | null>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|