@b3dotfun/sdk 0.0.51-alpha.0 → 0.0.51-alpha.1

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 (28) hide show
  1. package/dist/cjs/bondkit/bondkitToken.js +40 -6
  2. package/dist/cjs/bondkit/bondkitTokenFactory.js +16 -5
  3. package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -5
  4. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  5. package/dist/cjs/global-account/react/hooks/useFirstEOA.js +1 -21
  6. package/dist/cjs/global-account/react/hooks/useSiwe.js +1 -0
  7. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +4 -0
  8. package/dist/cjs/global-account/react/hooks/useTWAuth.js +33 -0
  9. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +3 -9
  10. package/dist/esm/bondkit/bondkitToken.js +40 -6
  11. package/dist/esm/bondkit/bondkitTokenFactory.js +16 -5
  12. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -6
  13. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  14. package/dist/esm/global-account/react/hooks/useFirstEOA.js +2 -22
  15. package/dist/esm/global-account/react/hooks/useSiwe.js +1 -0
  16. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +4 -0
  17. package/dist/esm/global-account/react/hooks/useTWAuth.js +27 -0
  18. package/dist/esm/shared/constants/chains/b3Chain.d.ts +3 -9
  19. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  20. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +4 -0
  21. package/dist/types/shared/constants/chains/b3Chain.d.ts +3 -9
  22. package/package.json +5 -6
  23. package/src/bondkit/bondkitToken.ts +42 -8
  24. package/src/bondkit/bondkitTokenFactory.ts +16 -5
  25. package/src/global-account/react/hooks/useAuthentication.ts +8 -6
  26. package/src/global-account/react/hooks/useFirstEOA.tsx +2 -20
  27. package/src/global-account/react/hooks/useSiwe.tsx +1 -0
  28. package/src/global-account/react/hooks/useTWAuth.tsx +36 -0
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFirstEOA = useFirstEOA;
4
4
  const react_1 = require("../../../global-account/react");
5
5
  const debug_1 = require("../../../shared/utils/debug");
6
- const thirdweb_1 = require("../../../shared/utils/thirdweb");
7
6
  const react_2 = require("react");
8
- const viem_1 = require("thirdweb/adapters/viem");
9
7
  const react_3 = require("thirdweb/react");
10
8
  const debug = (0, debug_1.debugB3React)("useFirstEOA");
11
- function useFirstEOA(chain) {
9
+ function useFirstEOA() {
12
10
  const wallets = (0, react_3.useConnectedWallets)();
13
11
  const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
14
12
  const [firstEOA, setFirstEOA] = (0, react_2.useState)(undefined);
@@ -35,27 +33,9 @@ function useFirstEOA(chain) {
35
33
  };
36
34
  autoSelectFirstEOAWallet();
37
35
  }, [isConnected, wallets]);
38
- const walletClient = (0, react_2.useMemo)(() => {
39
- if (!firstEOA)
40
- return undefined;
41
- if (!chain)
42
- return undefined;
43
- try {
44
- const viemClientWallet = viem_1.viemAdapter.wallet.toViem({
45
- client: thirdweb_1.client,
46
- chain,
47
- wallet: firstEOA,
48
- });
49
- return viemClientWallet;
50
- }
51
- catch (err) {
52
- console.error("Error setting wallet client", err);
53
- }
54
- }, [firstEOA, chain]);
55
36
  return {
56
37
  account: firstEOA,
57
38
  address,
58
39
  info: walletInfo,
59
- walletClient,
60
40
  };
61
41
  }
@@ -11,6 +11,7 @@ const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
11
11
  function useSiwe() {
12
12
  const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
13
13
  const authenticate = (0, react_1.useCallback)(async (account, partnerId) => {
14
+ console.warn("@@useSiwe is deprecated, use useTWAuth instead");
14
15
  if (!account || !account.signMessage)
15
16
  throw new Error("Account not found");
16
17
  console.log("@@useAuthenticate:referralCode", referralCode);
@@ -0,0 +1,4 @@
1
+ import { Wallet } from "thirdweb/wallets";
2
+ export declare function useTWAuth(): {
3
+ authenticate: (wallet: Wallet, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
4
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useTWAuth = useTWAuth;
7
+ const app_1 = __importDefault(require("../../../global-account/app"));
8
+ const debug_1 = __importDefault(require("../../../shared/utils/debug"));
9
+ const react_1 = require("react");
10
+ const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
11
+ function useTWAuth() {
12
+ const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
13
+ const authenticate = (0, react_1.useCallback)(async (wallet, partnerId) => {
14
+ if (!wallet || !wallet?.getAuthToken?.())
15
+ throw new Error("Wallet not found");
16
+ const authToken = wallet.getAuthToken();
17
+ (0, debug_1.default)("@@useTWSignIn:authToken", authToken);
18
+ (0, debug_1.default)("@@useTWSignIn:referralCode", referralCode);
19
+ // authenticate
20
+ const response = await app_1.default.authenticate({
21
+ strategy: "thirdweb-jwt",
22
+ accessToken: authToken,
23
+ // http://localhost:5173/?referralCode=GIO2
24
+ referralCode,
25
+ partnerId: partnerId,
26
+ });
27
+ (0, debug_1.default)("@@useTWSignIn:response", response);
28
+ return response;
29
+ }, [referralCode]);
30
+ return {
31
+ authenticate,
32
+ };
33
+ }
@@ -12,7 +12,6 @@ export declare const b3Mainnet: {
12
12
  readonly url: "https://explorer.b3.fun";
13
13
  };
14
14
  };
15
- blockTime?: number | undefined | undefined;
16
15
  contracts?: {
17
16
  [x: string]: import("viem").ChainContract | {
18
17
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -20,7 +19,7 @@ export declare const b3Mainnet: {
20
19
  ensRegistry?: import("viem").ChainContract | undefined;
21
20
  ensUniversalResolver?: import("viem").ChainContract | undefined;
22
21
  multicall3?: import("viem").ChainContract | undefined;
23
- erc6492Verifier?: import("viem").ChainContract | undefined;
22
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
24
23
  } | undefined;
25
24
  ensTlds?: readonly string[] | undefined;
26
25
  id: 8333;
@@ -30,7 +29,6 @@ export declare const b3Mainnet: {
30
29
  readonly symbol: "ETH";
31
30
  readonly decimals: 18;
32
31
  };
33
- experimental_preconfirmationTime?: number | undefined | undefined;
34
32
  rpcUrls: {
35
33
  readonly default: {
36
34
  readonly http: readonly ["https://mainnet-rpc.b3.fun"];
@@ -58,7 +56,6 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
58
56
  readonly url: string;
59
57
  };
60
58
  };
61
- blockTime?: number | undefined | undefined;
62
59
  contracts?: {
63
60
  [x: string]: import("viem").ChainContract | {
64
61
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -66,7 +63,7 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
66
63
  ensRegistry?: import("viem").ChainContract | undefined;
67
64
  ensUniversalResolver?: import("viem").ChainContract | undefined;
68
65
  multicall3?: import("viem").ChainContract | undefined;
69
- erc6492Verifier?: import("viem").ChainContract | undefined;
66
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
70
67
  } | undefined;
71
68
  ensTlds?: readonly string[] | undefined;
72
69
  id: number;
@@ -76,7 +73,6 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
76
73
  name: string;
77
74
  decimals: number;
78
75
  };
79
- experimental_preconfirmationTime?: number | undefined | undefined;
80
76
  rpcUrls: {
81
77
  readonly default: {
82
78
  readonly http: readonly [string];
@@ -107,7 +103,6 @@ export declare const b3Chain: Chain | {
107
103
  readonly url: "https://explorer.b3.fun";
108
104
  };
109
105
  };
110
- blockTime?: number | undefined | undefined;
111
106
  contracts?: {
112
107
  [x: string]: import("viem").ChainContract | {
113
108
  [sourceId: number]: import("viem").ChainContract | undefined;
@@ -115,7 +110,7 @@ export declare const b3Chain: Chain | {
115
110
  ensRegistry?: import("viem").ChainContract | undefined;
116
111
  ensUniversalResolver?: import("viem").ChainContract | undefined;
117
112
  multicall3?: import("viem").ChainContract | undefined;
118
- erc6492Verifier?: import("viem").ChainContract | undefined;
113
+ universalSignatureVerifier?: import("viem").ChainContract | undefined;
119
114
  } | undefined;
120
115
  ensTlds?: readonly string[] | undefined;
121
116
  id: 8333;
@@ -125,7 +120,6 @@ export declare const b3Chain: Chain | {
125
120
  readonly symbol: "ETH";
126
121
  readonly decimals: 18;
127
122
  };
128
- experimental_preconfirmationTime?: number | undefined | undefined;
129
123
  rpcUrls: {
130
124
  readonly default: {
131
125
  readonly http: readonly ["https://mainnet-rpc.b3.fun"];
@@ -41,9 +41,18 @@ export class BondkitToken {
41
41
  this.contract = getContract({
42
42
  address: this.contractAddress,
43
43
  abi: BondkitTokenABI,
44
- client: this.walletClientInstance,
44
+ client: {
45
+ public: this.publicClient,
46
+ wallet: this.walletClientInstance,
47
+ },
45
48
  });
46
- this.contract.read.tradingToken().then(tradingToken => {
49
+ getContract({
50
+ address: this.contractAddress,
51
+ abi: BondkitTokenABI,
52
+ client: this.publicClient, // Use public client for read operations
53
+ })
54
+ .read.tradingToken()
55
+ .then(tradingToken => {
47
56
  this.tradingToken = tradingToken;
48
57
  });
49
58
  }
@@ -63,7 +72,10 @@ export class BondkitToken {
63
72
  this.contract = getContract({
64
73
  address: this.contractAddress,
65
74
  abi: BondkitTokenABI,
66
- client: this.walletClientInstance,
75
+ client: {
76
+ public: this.publicClient,
77
+ wallet: this.walletClientInstance,
78
+ },
67
79
  });
68
80
  return true;
69
81
  }
@@ -110,7 +122,10 @@ export class BondkitToken {
110
122
  this.contract = getContract({
111
123
  address: this.contractAddress,
112
124
  abi: BondkitTokenABI,
113
- client: this.walletClientInstance,
125
+ client: {
126
+ public: this.publicClient,
127
+ wallet: this.walletClientInstance,
128
+ },
114
129
  });
115
130
  return true;
116
131
  }
@@ -423,7 +438,10 @@ export class BondkitToken {
423
438
  this.contract = getContract({
424
439
  address: this.contractAddress,
425
440
  abi: BondkitTokenABI,
426
- client: this.walletClientInstance,
441
+ client: {
442
+ public: this.publicClient,
443
+ wallet: this.walletClientInstance,
444
+ },
427
445
  });
428
446
  }
429
447
  }
@@ -433,6 +451,19 @@ export class BondkitToken {
433
451
  throw new Error("Wallet key not set or client not connected for write operation.");
434
452
  }
435
453
  }
454
+ // Only attempt chain switching for browser wallet providers
455
+ // Private key users cannot switch chains programmatically
456
+ if (this.connectedProvider && this.walletClientInstance.account) {
457
+ const walletChainId = await this.walletClientInstance.getChainId();
458
+ if (walletChainId !== this.chain.id) {
459
+ try {
460
+ await this.walletClientInstance.switchChain({ id: this.chain.id });
461
+ }
462
+ catch (switchErr) {
463
+ throw new Error(`Please switch your wallet to ${this.chain.name} (${this.chain.id}).`);
464
+ }
465
+ }
466
+ }
436
467
  const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
437
468
  if (!accountToUse)
438
469
  throw new Error("Account for transaction could not be determined.");
@@ -527,7 +558,10 @@ export class BondkitToken {
527
558
  const tradingTokenContract = getContract({
528
559
  address: this.tradingToken,
529
560
  abi: erc20Abi,
530
- client: this.walletClientInstance,
561
+ client: {
562
+ public: this.publicClient,
563
+ wallet: this.walletClientInstance,
564
+ },
531
565
  });
532
566
  const currentAllowance = await tradingTokenContract.read.allowance([
533
567
  this.walletClientInstance.account?.address,
@@ -28,7 +28,10 @@ export class BondkitTokenFactory {
28
28
  this.contract = getContract({
29
29
  address: this.contractAddress,
30
30
  abi: BondkitTokenFactoryABI,
31
- client: this.walletClientInstance,
31
+ client: {
32
+ public: this.publicClient,
33
+ wallet: this.walletClientInstance,
34
+ },
32
35
  });
33
36
  }
34
37
  connect(provider) {
@@ -43,7 +46,10 @@ export class BondkitTokenFactory {
43
46
  this.contract = getContract({
44
47
  address: this.contractAddress,
45
48
  abi: BondkitTokenFactoryABI,
46
- client: this.walletClientInstance,
49
+ client: {
50
+ public: this.publicClient,
51
+ wallet: this.walletClientInstance,
52
+ },
47
53
  });
48
54
  this.publicClient = createPublicClient({
49
55
  chain: this.chain,
@@ -92,7 +98,10 @@ export class BondkitTokenFactory {
92
98
  this.contract = getContract({
93
99
  address: this.contractAddress,
94
100
  abi: BondkitTokenFactoryABI,
95
- client: this.walletClientInstance,
101
+ client: {
102
+ public: this.publicClient,
103
+ wallet: this.walletClientInstance,
104
+ },
96
105
  });
97
106
  return true;
98
107
  }
@@ -123,7 +132,10 @@ export class BondkitTokenFactory {
123
132
  this.contract = getContract({
124
133
  address: this.contractAddress,
125
134
  abi: BondkitTokenFactoryABI,
126
- client: this.walletClientInstance,
135
+ client: {
136
+ public: this.publicClient,
137
+ wallet: this.walletClientInstance,
138
+ },
127
139
  });
128
140
  }
129
141
  }
@@ -161,7 +173,6 @@ export class BondkitTokenFactory {
161
173
  account: accountToUse,
162
174
  chain: this.chain,
163
175
  });
164
- console.log("hash", hash);
165
176
  const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
166
177
  for (const log of receipt.logs) {
167
178
  try {
@@ -1,6 +1,6 @@
1
1
  import app from "../../../global-account/app.js";
2
2
  import { authenticateWithB3JWT } from "../../../global-account/bsmnt.js";
3
- import { useAuthStore, useSiwe } from "../../../global-account/react/index.js";
3
+ import { useAuthStore } from "../../../global-account/react/index.js";
4
4
  import { ecosystemWalletId } from "../../../shared/constants/index.js";
5
5
  import { debugB3React } from "../../../shared/utils/debug.js";
6
6
  import { client } from "../../../shared/utils/thirdweb.js";
@@ -10,6 +10,7 @@ import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect, us
10
10
  import { ecosystemWallet } from "thirdweb/wallets";
11
11
  import { preAuthenticate } from "thirdweb/wallets/in-app";
12
12
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
13
+ import { useTWAuth } from "./useTWAuth.js";
13
14
  import { useUserQuery } from "./useUserQuery.js";
14
15
  import { useWagmiConfig } from "./useWagmiConfig.js";
15
16
  const debug = debugB3React("useAuthentication");
@@ -27,7 +28,7 @@ export function useAuthentication(partnerId) {
27
28
  const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
28
29
  const setActiveWallet = useSetActiveWallet();
29
30
  const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
30
- const { authenticate } = useSiwe();
31
+ const { authenticate } = useTWAuth();
31
32
  const { user, setUser } = useUserQuery();
32
33
  const useAutoConnectLoadingPrevious = useRef(false);
33
34
  const wagmiConfig = useWagmiConfig(partnerId);
@@ -100,10 +101,10 @@ export function useAuthentication(partnerId) {
100
101
  }, [wallets, syncWagmi]);
101
102
  const authenticateUser = useCallback(async (wallet) => {
102
103
  setHasStartedConnecting(true);
103
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
104
- if (!account) {
105
- throw new Error("No account found during auto-connect");
104
+ if (!wallet) {
105
+ throw new Error("No wallet found during auto-connect");
106
106
  }
107
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
107
108
  if (!account) {
108
109
  throw new Error("No account found during auto-connect");
109
110
  }
@@ -121,7 +122,7 @@ export function useAuthentication(partnerId) {
121
122
  catch (error) {
122
123
  // If re-authentication fails, try fresh authentication
123
124
  debug("Re-authentication failed, attempting fresh authentication");
124
- const userAuth = await authenticate(account, partnerId);
125
+ const userAuth = await authenticate(wallet, partnerId);
125
126
  setUser(userAuth.user);
126
127
  setIsAuthenticated(true);
127
128
  setIsAuthenticating(false);