@b3dotfun/sdk 0.0.40-alpha.5 → 0.0.40-alpha.7
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/bondkit/bondkitToken.d.ts +36 -1
- package/dist/cjs/bondkit/bondkitToken.js +266 -0
- 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 +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +35 -16
- 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/bondkit/bondkitToken.d.ts +36 -1
- package/dist/esm/bondkit/bondkitToken.js +266 -0
- 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 +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +36 -17
- 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/types/bondkit/bondkitToken.d.ts +36 -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 +3 -2
- package/package.json +6 -5
- package/src/bondkit/bondkitToken.ts +321 -1
- 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 +49 -24
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
- package/src/global-account/react/hooks/useAuthentication.ts +1 -2
|
@@ -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");
|
|
@@ -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
|
}
|
|
@@ -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 {};
|