@b3dotfun/sdk 0.0.40-alpha.1 → 0.0.40-alpha.11
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 +2 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +6 -2
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +5 -2
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +39 -37
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -4
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +7 -6
- 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 +13 -5
- 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/types/api.d.ts +10 -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/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 +373 -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 +35 -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/useAuthentication.js +1 -2
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +6 -2
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +5 -2
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +39 -37
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -4
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +7 -6
- 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 +13 -5
- 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/types/api.d.ts +10 -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/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 +369 -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 +36 -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/useAuthentication.js +1 -2
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- 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/types/api.d.ts +10 -0
- 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/package.json +6 -5
- package/src/anyspend/react/components/AnySpend.tsx +15 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +14 -0
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +63 -45
- package/src/anyspend/react/components/common/OrderDetails.tsx +2 -5
- package/src/anyspend/react/components/common/PanelOnramp.tsx +28 -15
- 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 +13 -5
- package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
- package/src/anyspend/react/providers/index.ts +1 -0
- package/src/anyspend/types/api.ts +10 -0
- package/src/anyspend/types/api_req_res.ts +6 -10
- package/src/bondkit/bondkitToken.ts +323 -3
- package/src/bondkit/bondkitTokenFactory.ts +2 -2
- 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 +461 -0
- package/src/bondkit/types.ts +12 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +51 -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/useAuthentication.ts +1 -2
|
@@ -6,6 +6,8 @@ const accounts_1 = require("viem/accounts");
|
|
|
6
6
|
const chains_1 = require("viem/chains");
|
|
7
7
|
const abis_1 = require("./abis");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
|
+
const swapService_1 = require("./swapService");
|
|
10
|
+
const types_1 = require("./types");
|
|
9
11
|
// Event ABI snippets for decoding
|
|
10
12
|
const boughtEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
11
13
|
const soldEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
|
|
@@ -14,8 +16,8 @@ const dexMigrationEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "
|
|
|
14
16
|
const OKX_POLLING_MAX_RETRIES = 60; // 5 minutes with 5 second intervals
|
|
15
17
|
const OKX_POLLING_INTERVAL_MS = 5000; // 5 seconds
|
|
16
18
|
class BondkitToken {
|
|
17
|
-
constructor(contractAddress, walletKey) {
|
|
18
|
-
const sdkConfig = (0, config_1.getConfig)(chains_1.base.id);
|
|
19
|
+
constructor(contractAddress, walletKey, rpcUrl) {
|
|
20
|
+
const sdkConfig = (0, config_1.getConfig)(chains_1.base.id, rpcUrl);
|
|
19
21
|
this.chain = sdkConfig.chain;
|
|
20
22
|
this.rpcUrl = sdkConfig.rpcUrl;
|
|
21
23
|
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
@@ -558,5 +560,269 @@ class BondkitToken {
|
|
|
558
560
|
async renounceTokenOwnership(options) {
|
|
559
561
|
return this.executeWrite("renounceOwnership", [], options);
|
|
560
562
|
}
|
|
563
|
+
// --- DEX Swap Methods ---
|
|
564
|
+
/**
|
|
565
|
+
* Get the swap service instance (lazy initialization)
|
|
566
|
+
*/
|
|
567
|
+
getSwapService() {
|
|
568
|
+
if (!this.swapService) {
|
|
569
|
+
this.swapService = new swapService_1.BondkitSwapService(this.contractAddress);
|
|
570
|
+
}
|
|
571
|
+
return this.swapService;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Check if DEX swapping is available (token must be in Dex phase)
|
|
575
|
+
*/
|
|
576
|
+
async isSwapAvailable() {
|
|
577
|
+
try {
|
|
578
|
+
const status = await this.currentStatus();
|
|
579
|
+
return status === types_1.TokenStatus.Dex;
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
console.warn("Error checking swap availability:", error);
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Get swap quote for trading token → bondkit token
|
|
588
|
+
*/
|
|
589
|
+
async getSwapQuoteForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5) {
|
|
590
|
+
try {
|
|
591
|
+
// Check if swapping is available
|
|
592
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
593
|
+
if (!swapAvailable) {
|
|
594
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
598
|
+
if (!tradingTokenAddress) {
|
|
599
|
+
console.warn("Trading token address not available");
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
// Get token details for decimals
|
|
603
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
604
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
605
|
+
this.decimals(),
|
|
606
|
+
]);
|
|
607
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
608
|
+
console.warn("Unable to fetch token decimals");
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
const swapService = this.getSwapService();
|
|
612
|
+
const quote = await swapService.getSwapQuote({
|
|
613
|
+
tokenIn: tradingTokenAddress,
|
|
614
|
+
tokenOut: this.contractAddress,
|
|
615
|
+
amountIn: amountTradingTokenIn,
|
|
616
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
617
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
618
|
+
slippageTolerance,
|
|
619
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
620
|
+
});
|
|
621
|
+
return quote || undefined;
|
|
622
|
+
}
|
|
623
|
+
catch (error) {
|
|
624
|
+
console.warn("Error getting swap quote for bondkit token:", error);
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Get swap quote for bondkit token → trading token
|
|
630
|
+
*/
|
|
631
|
+
async getSwapQuoteForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5) {
|
|
632
|
+
try {
|
|
633
|
+
// Check if swapping is available
|
|
634
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
635
|
+
if (!swapAvailable) {
|
|
636
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
640
|
+
if (!tradingTokenAddress) {
|
|
641
|
+
console.warn("Trading token address not available");
|
|
642
|
+
return undefined;
|
|
643
|
+
}
|
|
644
|
+
// Get token details for decimals
|
|
645
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
646
|
+
this.decimals(),
|
|
647
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
648
|
+
]);
|
|
649
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
650
|
+
console.warn("Unable to fetch token decimals");
|
|
651
|
+
return undefined;
|
|
652
|
+
}
|
|
653
|
+
const swapService = this.getSwapService();
|
|
654
|
+
const quote = await swapService.getSwapQuote({
|
|
655
|
+
tokenIn: this.contractAddress,
|
|
656
|
+
tokenOut: tradingTokenAddress,
|
|
657
|
+
amountIn: amountBondkitTokenIn,
|
|
658
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
659
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
660
|
+
slippageTolerance,
|
|
661
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
662
|
+
});
|
|
663
|
+
return quote || undefined;
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
console.warn("Error getting swap quote for trading token:", error);
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Swap trading token for bondkit token
|
|
672
|
+
*/
|
|
673
|
+
async swapTradingTokenForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5, options) {
|
|
674
|
+
try {
|
|
675
|
+
// Check if swapping is available
|
|
676
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
677
|
+
if (!swapAvailable) {
|
|
678
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
682
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
686
|
+
if (!tradingTokenAddress) {
|
|
687
|
+
console.warn("Trading token address not available");
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
// Get token details for decimals
|
|
691
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
692
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
693
|
+
this.decimals(),
|
|
694
|
+
]);
|
|
695
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
696
|
+
console.warn("Unable to fetch token decimals");
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
700
|
+
(this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey).address : undefined);
|
|
701
|
+
if (!recipient) {
|
|
702
|
+
console.warn("Unable to determine recipient address");
|
|
703
|
+
return undefined;
|
|
704
|
+
}
|
|
705
|
+
const swapService = this.getSwapService();
|
|
706
|
+
const txHash = await swapService.executeSwap({
|
|
707
|
+
tokenIn: tradingTokenAddress,
|
|
708
|
+
tokenOut: this.contractAddress,
|
|
709
|
+
amountIn: amountTradingTokenIn,
|
|
710
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
711
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
712
|
+
slippageTolerance,
|
|
713
|
+
recipient,
|
|
714
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
715
|
+
}, this.walletClientInstance);
|
|
716
|
+
return txHash ? txHash : undefined;
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
console.warn("Error swapping trading token for bondkit token:", error);
|
|
720
|
+
return undefined;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Swap bondkit token for trading token
|
|
725
|
+
*/
|
|
726
|
+
async swapBondkitTokenForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5, options) {
|
|
727
|
+
try {
|
|
728
|
+
// Check if swapping is available
|
|
729
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
730
|
+
if (!swapAvailable) {
|
|
731
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
735
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
736
|
+
return undefined;
|
|
737
|
+
}
|
|
738
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
739
|
+
if (!tradingTokenAddress) {
|
|
740
|
+
console.warn("Trading token address not available");
|
|
741
|
+
return undefined;
|
|
742
|
+
}
|
|
743
|
+
// Get token details for decimals
|
|
744
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
745
|
+
this.decimals(),
|
|
746
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
747
|
+
]);
|
|
748
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
749
|
+
console.warn("Unable to fetch token decimals");
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
753
|
+
(this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey).address : undefined);
|
|
754
|
+
if (!recipient) {
|
|
755
|
+
console.warn("Unable to determine recipient address");
|
|
756
|
+
return undefined;
|
|
757
|
+
}
|
|
758
|
+
const swapService = this.getSwapService();
|
|
759
|
+
const txHash = await swapService.executeSwap({
|
|
760
|
+
tokenIn: this.contractAddress,
|
|
761
|
+
tokenOut: tradingTokenAddress,
|
|
762
|
+
amountIn: amountBondkitTokenIn,
|
|
763
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
764
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
765
|
+
slippageTolerance,
|
|
766
|
+
recipient,
|
|
767
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
768
|
+
}, this.walletClientInstance);
|
|
769
|
+
return txHash ? txHash : undefined;
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
console.warn("Error swapping bondkit token for trading token:", error);
|
|
773
|
+
return undefined;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Helper method to get trading token decimals
|
|
778
|
+
*/
|
|
779
|
+
async getTradingTokenDecimals(tradingTokenAddress) {
|
|
780
|
+
try {
|
|
781
|
+
// ETH has 18 decimals
|
|
782
|
+
if (tradingTokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
783
|
+
return 18;
|
|
784
|
+
}
|
|
785
|
+
// For ERC20 tokens, read decimals from contract
|
|
786
|
+
const tradingTokenContract = (0, viem_1.getContract)({
|
|
787
|
+
address: tradingTokenAddress,
|
|
788
|
+
abi: viem_1.erc20Abi,
|
|
789
|
+
client: this.publicClient,
|
|
790
|
+
});
|
|
791
|
+
const decimals = await tradingTokenContract.read.decimals();
|
|
792
|
+
return Number(decimals);
|
|
793
|
+
}
|
|
794
|
+
catch (error) {
|
|
795
|
+
console.warn("Error fetching trading token decimals:", error);
|
|
796
|
+
return undefined;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Get trading token symbol
|
|
801
|
+
* @param tradingTokenAddress Optional trading token address to avoid fetching it again
|
|
802
|
+
*/
|
|
803
|
+
async getTradingTokenSymbol(tradingTokenAddress) {
|
|
804
|
+
try {
|
|
805
|
+
const tokenAddress = tradingTokenAddress || (await this.getTradingTokenAddress());
|
|
806
|
+
if (!tokenAddress) {
|
|
807
|
+
return undefined;
|
|
808
|
+
}
|
|
809
|
+
// ETH symbol
|
|
810
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
811
|
+
return "ETH";
|
|
812
|
+
}
|
|
813
|
+
// For ERC20 tokens, read symbol from contract
|
|
814
|
+
const tradingTokenContract = (0, viem_1.getContract)({
|
|
815
|
+
address: tokenAddress,
|
|
816
|
+
abi: viem_1.erc20Abi,
|
|
817
|
+
client: this.publicClient,
|
|
818
|
+
});
|
|
819
|
+
const symbol = await tradingTokenContract.read.symbol();
|
|
820
|
+
return symbol;
|
|
821
|
+
}
|
|
822
|
+
catch (error) {
|
|
823
|
+
console.warn("Error fetching trading token symbol:", error);
|
|
824
|
+
return undefined;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
561
827
|
}
|
|
562
828
|
exports.BondkitToken = BondkitToken;
|
|
@@ -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.
|
|
@@ -8,14 +8,14 @@ const config_1 = require("./config");
|
|
|
8
8
|
// Define the event ABI snippet for BondkitTokenCreated specifically for decoding
|
|
9
9
|
const bondkitTokenCreatedEventAbi = abis_1.BondkitTokenFactoryABI.find(item => item.type === "event" && item.name === "BondkitTokenCreated");
|
|
10
10
|
class BondkitTokenFactory {
|
|
11
|
-
constructor(chainId, walletKey) {
|
|
11
|
+
constructor(chainId, walletKey, rpcUrl) {
|
|
12
12
|
if (walletKey && !walletKey.startsWith("0x")) {
|
|
13
13
|
this.walletKey = `0x${walletKey}`;
|
|
14
14
|
}
|
|
15
15
|
else if (walletKey) {
|
|
16
16
|
this.walletKey = walletKey;
|
|
17
17
|
}
|
|
18
|
-
const config = (0, config_1.getConfig)(chainId);
|
|
18
|
+
const config = (0, config_1.getConfig)(chainId, rpcUrl);
|
|
19
19
|
this.chain = config.chain;
|
|
20
20
|
this.contractAddress = config.factoryAddress;
|
|
21
21
|
this.rpcUrl = config.rpcUrl;
|
|
@@ -9,9 +9,12 @@ const baseMainnetConfig = {
|
|
|
9
9
|
factoryAddress: constants_1.BaseBondkitTokenFactoryContractAddress,
|
|
10
10
|
apiEndpoint: "https://api.b3.fun/bondkit-tokens",
|
|
11
11
|
};
|
|
12
|
-
const getConfig = (chainId) => {
|
|
12
|
+
const getConfig = (chainId, rpcUrl) => {
|
|
13
13
|
if (chainId === chains_1.base.id) {
|
|
14
|
-
return
|
|
14
|
+
return {
|
|
15
|
+
...baseMainnetConfig,
|
|
16
|
+
rpcUrl: rpcUrl || constants_1.BaseMainnetRpcUrl,
|
|
17
|
+
};
|
|
15
18
|
}
|
|
16
19
|
throw new Error(`Unsupported chainId: ${chainId}. This SDK is configured for Base (Chain ID: ${chains_1.base.id}) only.`);
|
|
17
20
|
};
|
|
@@ -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,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseMainnetRpcUrl = exports.BaseBondkitTokenFactoryContractAddress = void 0;
|
|
3
|
+
exports.B3TokenAddress = exports.Permit2Address = exports.QuoterAddress = exports.UniversalRouterAddress = exports.BaseMainnetRpcUrl = exports.BaseBondkitTokenFactoryContractAddress = void 0;
|
|
4
4
|
exports.BaseBondkitTokenFactoryContractAddress = "0x5d641bbB206d4B5585eCCd919F36270200A9A2Ad";
|
|
5
5
|
exports.BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";
|
|
6
|
+
// Uniswap V4 addresses on Base
|
|
7
|
+
exports.UniversalRouterAddress = "0x6ff5693b99212da76ad316178a184ab56d299b43";
|
|
8
|
+
exports.QuoterAddress = "0x0d5e0f971ed27fbff6c2837bf31316121532048d";
|
|
9
|
+
exports.Permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
10
|
+
exports.B3TokenAddress = "0xB3B32F9f8827D4634fE7d973Fa1034Ec9fdDB3B3";
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.TradingView = void 0;
|
|
20
|
+
exports.TradingView = exports.BondkitSwapService = void 0;
|
|
21
21
|
// Core exports
|
|
22
22
|
__exportStar(require("./bondkitToken"), exports);
|
|
23
23
|
__exportStar(require("./bondkitTokenFactory"), exports);
|
|
@@ -28,6 +28,9 @@ __exportStar(require("./constants"), exports);
|
|
|
28
28
|
__exportStar(require("./types"), exports);
|
|
29
29
|
// ABIs
|
|
30
30
|
__exportStar(require("./abis"), exports);
|
|
31
|
+
// Swap functionality
|
|
32
|
+
var swapService_1 = require("./swapService");
|
|
33
|
+
Object.defineProperty(exports, "BondkitSwapService", { enumerable: true, get: function () { return swapService_1.BondkitSwapService; } });
|
|
31
34
|
// Components
|
|
32
35
|
var TradingView_1 = require("./components/TradingView");
|
|
33
36
|
Object.defineProperty(exports, "TradingView", { enumerable: true, get: function () { return __importDefault(TradingView_1).default; } });
|
|
@@ -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 {};
|