@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.
Files changed (43) hide show
  1. package/dist/cjs/bondkit/bondkitToken.d.ts +36 -1
  2. package/dist/cjs/bondkit/bondkitToken.js +266 -0
  3. package/dist/cjs/bondkit/constants.d.ts +4 -0
  4. package/dist/cjs/bondkit/constants.js +6 -1
  5. package/dist/cjs/bondkit/index.d.ts +1 -0
  6. package/dist/cjs/bondkit/index.js +4 -1
  7. package/dist/cjs/bondkit/swapService.d.ts +43 -0
  8. package/dist/cjs/bondkit/swapService.js +373 -0
  9. package/dist/cjs/bondkit/types.d.ts +10 -4
  10. package/dist/cjs/bondkit/types.js +4 -5
  11. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  12. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +35 -16
  13. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
  14. package/dist/cjs/global-account/react/hooks/useAuthentication.js +1 -2
  15. package/dist/esm/bondkit/bondkitToken.d.ts +36 -1
  16. package/dist/esm/bondkit/bondkitToken.js +266 -0
  17. package/dist/esm/bondkit/constants.d.ts +4 -0
  18. package/dist/esm/bondkit/constants.js +5 -0
  19. package/dist/esm/bondkit/index.d.ts +1 -0
  20. package/dist/esm/bondkit/index.js +2 -0
  21. package/dist/esm/bondkit/swapService.d.ts +43 -0
  22. package/dist/esm/bondkit/swapService.js +369 -0
  23. package/dist/esm/bondkit/types.d.ts +10 -4
  24. package/dist/esm/bondkit/types.js +4 -5
  25. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  26. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +36 -17
  27. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  28. package/dist/esm/global-account/react/hooks/useAuthentication.js +1 -2
  29. package/dist/types/bondkit/bondkitToken.d.ts +36 -1
  30. package/dist/types/bondkit/constants.d.ts +4 -0
  31. package/dist/types/bondkit/index.d.ts +1 -0
  32. package/dist/types/bondkit/swapService.d.ts +43 -0
  33. package/dist/types/bondkit/types.d.ts +10 -4
  34. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  35. package/package.json +6 -5
  36. package/src/bondkit/bondkitToken.ts +321 -1
  37. package/src/bondkit/constants.ts +7 -0
  38. package/src/bondkit/index.ts +3 -0
  39. package/src/bondkit/swapService.ts +461 -0
  40. package/src/bondkit/types.ts +12 -5
  41. package/src/global-account/react/components/B3Provider/B3Provider.tsx +49 -24
  42. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
  43. package/src/global-account/react/hooks/useAuthentication.ts +1 -2
@@ -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 {};
@@ -49,10 +49,9 @@ export type DexMigrationEventArgs = {
49
49
  ethForFeeRecipient: bigint;
50
50
  };
51
51
  export declare enum TokenStatus {
52
- Inactive = 0,// Assuming mapping from ABI, verify actual enum values if specified elsewhere
53
- BondingPhase = 1,
54
- DexPhase = 2,
55
- Migrated = 3
52
+ Uninitialized = 0,
53
+ Bonding = 1,
54
+ Dex = 2
56
55
  }
57
56
  export interface GetTransactionHistoryOptions {
58
57
  userAddress?: Address;
@@ -80,3 +79,10 @@ export interface TransactionResponse {
80
79
  skip: number;
81
80
  data: Transaction[];
82
81
  }
82
+ export interface SwapQuote {
83
+ amountOut: string;
84
+ amountOutMin: string;
85
+ priceImpact: string;
86
+ executionPrice: string;
87
+ fee: string;
88
+ }
@@ -1,12 +1,12 @@
1
1
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
2
+ import "@reservoir0x/relay-kit-ui/styles.css";
2
3
  import { Account } from "thirdweb/wallets";
3
4
  import { ClientType } from "../../../client-manager";
4
5
  import { B3ContextType } from "./types";
5
- import "@reservoir0x/relay-kit-ui/styles.css";
6
6
  /**
7
7
  * Main B3Provider component
8
8
  */
9
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, }: {
9
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
10
10
  theme: "light" | "dark";
11
11
  children: React.ReactNode;
12
12
  accountOverride?: Account;
@@ -19,6 +19,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
19
19
  };
20
20
  clientType?: ClientType;
21
21
  rpcUrls?: Record<number, string>;
22
+ partnerId?: string;
22
23
  }): import("react/jsx-runtime").JSX.Element;
23
24
  /**
24
25
  * Inner provider component that provides the actual B3Context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.40-alpha.5",
3
+ "version": "0.0.40-alpha.7",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -241,8 +241,8 @@
241
241
  "@b3dotfun/basement-api": "0.0.11",
242
242
  "@feathersjs/authentication-client": "5.0.33",
243
243
  "@feathersjs/feathers": "5.0.33",
244
- "@feathersjs/socketio-client": "5.0.33",
245
244
  "@feathersjs/rest-client": "5.0.33",
245
+ "@feathersjs/socketio-client": "5.0.33",
246
246
  "@feathersjs/typebox": "5.0.33",
247
247
  "@fingerprintjs/fingerprintjs-pro-react": "^2.7.0",
248
248
  "@hey-api/client-fetch": "0.8.3",
@@ -261,6 +261,7 @@
261
261
  "@solana/web3.js": "^1.98.2",
262
262
  "@stripe/react-stripe-js": "^3.7.0",
263
263
  "@stripe/stripe-js": "^7.3.1",
264
+ "@thirdweb-dev/wagmi-adapter": "^0.2.141",
264
265
  "@web3icons/react": "3.16.0",
265
266
  "big.js": "^7.0.1",
266
267
  "class-variance-authority": "0.7.0",
@@ -329,10 +330,10 @@
329
330
  "react": "^18.0.0 || ^19.0.0",
330
331
  "react-dom": "^18.0.0 || ^19.0.0",
331
332
  "react-native-mmkv": "^3.2.0",
332
- "thirdweb": "^5.105.20",
333
+ "thirdweb": "5.106.0",
333
334
  "three": "^0.175.0",
334
- "wagmi": "^2.14.15",
335
- "viem": "^2.28.1"
335
+ "viem": "^2.28.1",
336
+ "wagmi": "^2.14.15"
336
337
  },
337
338
  "peerDependenciesMeta": {
338
339
  "@react-three/postprocessing": {
@@ -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,6 +55,7 @@ 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
60
  constructor(contractAddress: string, walletKey?: string, rpcUrl?: string) {
58
61
  const sdkConfig = getConfig(base.id, rpcUrl);
@@ -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
  }
@@ -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";
@@ -12,5 +12,8 @@ export * from "./types";
12
12
  // ABIs
13
13
  export * from "./abis";
14
14
 
15
+ // Swap functionality
16
+ export { BondkitSwapService } from "./swapService";
17
+
15
18
  // Components
16
19
  export { default as TradingView } from "./components/TradingView";