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

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 (38) hide show
  1. package/dist/cjs/anyspend/types/chain.d.ts +1 -0
  2. package/dist/cjs/anyspend/utils/chain.js +56 -47
  3. package/dist/cjs/bondkit/bondkitToken.js +40 -6
  4. package/dist/cjs/bondkit/bondkitTokenFactory.js +16 -5
  5. package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -5
  6. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  7. package/dist/cjs/global-account/react/hooks/useFirstEOA.js +1 -21
  8. package/dist/cjs/global-account/react/hooks/useSiwe.js +1 -0
  9. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +4 -0
  10. package/dist/cjs/global-account/react/hooks/useTWAuth.js +33 -0
  11. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +3 -9
  12. package/dist/cjs/shared/utils/simplehash.d.ts +1 -1
  13. package/dist/esm/anyspend/types/chain.d.ts +1 -0
  14. package/dist/esm/anyspend/utils/chain.js +57 -48
  15. package/dist/esm/bondkit/bondkitToken.js +40 -6
  16. package/dist/esm/bondkit/bondkitTokenFactory.js +16 -5
  17. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -6
  18. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  19. package/dist/esm/global-account/react/hooks/useFirstEOA.js +2 -22
  20. package/dist/esm/global-account/react/hooks/useSiwe.js +1 -0
  21. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +4 -0
  22. package/dist/esm/global-account/react/hooks/useTWAuth.js +27 -0
  23. package/dist/esm/shared/constants/chains/b3Chain.d.ts +3 -9
  24. package/dist/esm/shared/utils/simplehash.d.ts +1 -1
  25. package/dist/types/anyspend/types/chain.d.ts +1 -0
  26. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
  27. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +4 -0
  28. package/dist/types/shared/constants/chains/b3Chain.d.ts +3 -9
  29. package/dist/types/shared/utils/simplehash.d.ts +1 -1
  30. package/package.json +5 -6
  31. package/src/anyspend/types/chain.ts +1 -0
  32. package/src/anyspend/utils/chain.ts +49 -53
  33. package/src/bondkit/bondkitToken.ts +42 -8
  34. package/src/bondkit/bondkitTokenFactory.ts +16 -5
  35. package/src/global-account/react/hooks/useAuthentication.ts +8 -6
  36. package/src/global-account/react/hooks/useFirstEOA.tsx +2 -20
  37. package/src/global-account/react/hooks/useSiwe.tsx +1 -0
  38. package/src/global-account/react/hooks/useTWAuth.tsx +36 -0
@@ -19,6 +19,7 @@ export interface IEVMChain extends IBaseChain {
19
19
  type: ChainType.EVM;
20
20
  viem: Chain;
21
21
  pollingInterval: number;
22
+ wethAddress: string;
22
23
  zapperEnum?: string;
23
24
  }
24
25
  export interface ISolanaChain extends IBaseChain {
@@ -52,6 +52,7 @@ exports.EVM_MAINNET = {
52
52
  pollingInterval: 4000, // 4 seconds for Ethereum mainnet
53
53
  zapperEnum: "ETHEREUM_MAINNET",
54
54
  coingeckoName: "eth",
55
+ wethAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
55
56
  },
56
57
  [chains_1.arbitrum.id]: {
57
58
  id: chains_1.arbitrum.id,
@@ -66,6 +67,7 @@ exports.EVM_MAINNET = {
66
67
  pollingInterval: 500, // 500ms for Arbitrum's fast blocks
67
68
  zapperEnum: "ARBITRUM_MAINNET",
68
69
  coingeckoName: "arbitrum",
70
+ wethAddress: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
69
71
  },
70
72
  [chains_1.base.id]: {
71
73
  id: chains_1.base.id,
@@ -80,6 +82,7 @@ exports.EVM_MAINNET = {
80
82
  pollingInterval: 1000, // 1 second for Base
81
83
  zapperEnum: "BASE_MAINNET",
82
84
  coingeckoName: "base",
85
+ wethAddress: "0x4200000000000000000000000000000000000006",
83
86
  },
84
87
  [chains_1.optimism.id]: {
85
88
  id: chains_1.optimism.id,
@@ -94,6 +97,7 @@ exports.EVM_MAINNET = {
94
97
  pollingInterval: 1000, // 1 second for Optimism
95
98
  zapperEnum: "OPTIMISM_MAINNET",
96
99
  coingeckoName: "optimism",
100
+ wethAddress: "0x4200000000000000000000000000000000000006",
97
101
  },
98
102
  [chains_1.polygon.id]: {
99
103
  id: chains_1.polygon.id,
@@ -108,6 +112,7 @@ exports.EVM_MAINNET = {
108
112
  pollingInterval: 1000, // 1 second for Polygon
109
113
  zapperEnum: "POLYGON_MAINNET",
110
114
  coingeckoName: "polygon_pos",
115
+ wethAddress: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
111
116
  },
112
117
  [chains_1.avalanche.id]: {
113
118
  id: chains_1.avalanche.id,
@@ -122,6 +127,7 @@ exports.EVM_MAINNET = {
122
127
  pollingInterval: 1000, // 1 second for Avalanche
123
128
  zapperEnum: "AVALANCHE_MAINNET",
124
129
  coingeckoName: "avax",
130
+ wethAddress: "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
125
131
  },
126
132
  [chains_1.bsc.id]: {
127
133
  id: chains_1.bsc.id,
@@ -136,6 +142,7 @@ exports.EVM_MAINNET = {
136
142
  pollingInterval: 1000, // 1 second for BSC
137
143
  zapperEnum: "BSC_MAINNET",
138
144
  coingeckoName: "bsc",
145
+ wethAddress: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
139
146
  },
140
147
  [chains_1.b3.id]: {
141
148
  id: chains_1.b3.id,
@@ -150,6 +157,7 @@ exports.EVM_MAINNET = {
150
157
  pollingInterval: 1000, // 1 second for B3
151
158
  zapperEnum: "B3_MAINNET",
152
159
  coingeckoName: "b3",
160
+ wethAddress: "0x4200000000000000000000000000000000000006",
153
161
  },
154
162
  [chains_1.abstract.id]: {
155
163
  id: chains_1.abstract.id,
@@ -164,56 +172,57 @@ exports.EVM_MAINNET = {
164
172
  pollingInterval: 3000, // 3 seconds for Abstract
165
173
  zapperEnum: "ABSTRACT_MAINNET",
166
174
  coingeckoName: "abstract",
175
+ wethAddress: "0x3439153eb7af838ad19d56e1571fbd09333c2809",
167
176
  },
168
177
  };
169
178
  exports.EVM_TESTNET = {
170
- [chains_1.sepolia.id]: {
171
- id: chains_1.sepolia.id,
172
- name: chains_1.sepolia.name,
173
- logoUrl: "https://assets.relay.link/icons/square/1/light.png",
174
- type: chain_1.ChainType.EVM,
175
- nativeRequired: (0, viem_1.parseEther)("0.00001"),
176
- canDepositNative: true,
177
- defaultToken: (0, token_1.getEthToken)(chains_1.sepolia.id),
178
- nativeToken: (0, token_1.getEthToken)(chains_1.sepolia.id),
179
- viem: chains_1.sepolia,
180
- pollingInterval: 1000, // 1 second for Sepolia
181
- coingeckoName: "sepolia-testnet",
182
- },
183
- [chains_1.baseSepolia.id]: {
184
- id: chains_1.baseSepolia.id,
185
- name: chains_1.baseSepolia.name,
186
- logoUrl: "https://assets.relay.link/icons/square/8453/light.png",
187
- type: chain_1.ChainType.EVM,
188
- nativeRequired: (0, viem_1.parseEther)("0.00001"),
189
- canDepositNative: true,
190
- defaultToken: (0, token_1.getEthToken)(chains_1.baseSepolia.id),
191
- nativeToken: (0, token_1.getEthToken)(chains_1.baseSepolia.id),
192
- viem: chains_1.baseSepolia,
193
- pollingInterval: 1000, // 1 second for Base Sepolia
194
- coingeckoName: null,
195
- },
196
- [chains_1.b3Sepolia.id]: {
197
- id: chains_1.b3Sepolia.id,
198
- name: chains_1.b3Sepolia.name,
199
- logoUrl: "https://assets.relay.link/icons/square/8333/light.png",
200
- type: chain_1.ChainType.EVM,
201
- nativeRequired: (0, viem_1.parseEther)("0.00001"),
202
- canDepositNative: true,
203
- defaultToken: (0, token_1.getEthToken)(chains_1.b3Sepolia.id),
204
- nativeToken: (0, token_1.getEthToken)(chains_1.b3Sepolia.id),
205
- viem: chains_1.b3Sepolia,
206
- pollingInterval: 1000, // 1 second for B3 Sepolia
207
- coingeckoName: null,
208
- },
209
- // [b4testnet.id]: {
210
- // id: b4testnet.id,
211
- // logoUrl: "https://cdn.b3.fun/b4-logo.png",
212
- // type: ChainType.EVM,
213
- // viem: b4testnet,
214
- // requireNativeBalance: parseEther("0.00001"),
215
- // supportDepositNative: true,
216
- // },
179
+ // [sepolia.id]: {
180
+ // id: sepolia.id,
181
+ // name: sepolia.name,
182
+ // logoUrl: "https://assets.relay.link/icons/square/1/light.png",
183
+ // type: ChainType.EVM,
184
+ // nativeRequired: parseEther("0.00001"),
185
+ // canDepositNative: true,
186
+ // defaultToken: getEthToken(sepolia.id),
187
+ // nativeToken: getEthToken(sepolia.id),
188
+ // viem: sepolia,
189
+ // pollingInterval: 1000, // 1 second for Sepolia
190
+ // coingeckoName: "sepolia-testnet",
191
+ // },
192
+ // [baseSepolia.id]: {
193
+ // id: baseSepolia.id,
194
+ // name: baseSepolia.name,
195
+ // logoUrl: "https://assets.relay.link/icons/square/8453/light.png",
196
+ // type: ChainType.EVM,
197
+ // nativeRequired: parseEther("0.00001"),
198
+ // canDepositNative: true,
199
+ // defaultToken: getEthToken(baseSepolia.id),
200
+ // nativeToken: getEthToken(baseSepolia.id),
201
+ // viem: baseSepolia,
202
+ // pollingInterval: 1000, // 1 second for Base Sepolia
203
+ // coingeckoName: null,
204
+ // },
205
+ // [b3Sepolia.id]: {
206
+ // id: b3Sepolia.id,
207
+ // name: b3Sepolia.name,
208
+ // logoUrl: "https://assets.relay.link/icons/square/8333/light.png",
209
+ // type: ChainType.EVM,
210
+ // nativeRequired: parseEther("0.00001"),
211
+ // canDepositNative: true,
212
+ // defaultToken: getEthToken(b3Sepolia.id),
213
+ // nativeToken: getEthToken(b3Sepolia.id),
214
+ // viem: b3Sepolia,
215
+ // pollingInterval: 1000, // 1 second for B3 Sepolia
216
+ // coingeckoName: null,
217
+ // },
218
+ // [b4testnet.id]: {
219
+ // id: b4testnet.id,
220
+ // logoUrl: "https://cdn.b3.fun/b4-logo.png",
221
+ // type: ChainType.EVM,
222
+ // viem: b4testnet,
223
+ // requireNativeBalance: parseEther("0.00001"),
224
+ // supportDepositNative: true,
225
+ // },
217
226
  };
218
227
  exports.SOLANA_MAINNET = {
219
228
  id: constants_1.RELAY_SOLANA_MAINNET_CHAIN_ID,
@@ -44,9 +44,18 @@ class BondkitToken {
44
44
  this.contract = (0, viem_1.getContract)({
45
45
  address: this.contractAddress,
46
46
  abi: abis_1.BondkitTokenABI,
47
- client: this.walletClientInstance,
47
+ client: {
48
+ public: this.publicClient,
49
+ wallet: this.walletClientInstance,
50
+ },
48
51
  });
49
- this.contract.read.tradingToken().then(tradingToken => {
52
+ (0, viem_1.getContract)({
53
+ address: this.contractAddress,
54
+ abi: abis_1.BondkitTokenABI,
55
+ client: this.publicClient, // Use public client for read operations
56
+ })
57
+ .read.tradingToken()
58
+ .then(tradingToken => {
50
59
  this.tradingToken = tradingToken;
51
60
  });
52
61
  }
@@ -66,7 +75,10 @@ class BondkitToken {
66
75
  this.contract = (0, viem_1.getContract)({
67
76
  address: this.contractAddress,
68
77
  abi: abis_1.BondkitTokenABI,
69
- client: this.walletClientInstance,
78
+ client: {
79
+ public: this.publicClient,
80
+ wallet: this.walletClientInstance,
81
+ },
70
82
  });
71
83
  return true;
72
84
  }
@@ -113,7 +125,10 @@ class BondkitToken {
113
125
  this.contract = (0, viem_1.getContract)({
114
126
  address: this.contractAddress,
115
127
  abi: abis_1.BondkitTokenABI,
116
- client: this.walletClientInstance,
128
+ client: {
129
+ public: this.publicClient,
130
+ wallet: this.walletClientInstance,
131
+ },
117
132
  });
118
133
  return true;
119
134
  }
@@ -426,7 +441,10 @@ class BondkitToken {
426
441
  this.contract = (0, viem_1.getContract)({
427
442
  address: this.contractAddress,
428
443
  abi: abis_1.BondkitTokenABI,
429
- client: this.walletClientInstance,
444
+ client: {
445
+ public: this.publicClient,
446
+ wallet: this.walletClientInstance,
447
+ },
430
448
  });
431
449
  }
432
450
  }
@@ -436,6 +454,19 @@ class BondkitToken {
436
454
  throw new Error("Wallet key not set or client not connected for write operation.");
437
455
  }
438
456
  }
457
+ // Only attempt chain switching for browser wallet providers
458
+ // Private key users cannot switch chains programmatically
459
+ if (this.connectedProvider && this.walletClientInstance.account) {
460
+ const walletChainId = await this.walletClientInstance.getChainId();
461
+ if (walletChainId !== this.chain.id) {
462
+ try {
463
+ await this.walletClientInstance.switchChain({ id: this.chain.id });
464
+ }
465
+ catch (switchErr) {
466
+ throw new Error(`Please switch your wallet to ${this.chain.name} (${this.chain.id}).`);
467
+ }
468
+ }
469
+ }
439
470
  const accountToUse = this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey) : this.walletClientInstance.account;
440
471
  if (!accountToUse)
441
472
  throw new Error("Account for transaction could not be determined.");
@@ -530,7 +561,10 @@ class BondkitToken {
530
561
  const tradingTokenContract = (0, viem_1.getContract)({
531
562
  address: this.tradingToken,
532
563
  abi: viem_1.erc20Abi,
533
- client: this.walletClientInstance,
564
+ client: {
565
+ public: this.publicClient,
566
+ wallet: this.walletClientInstance,
567
+ },
534
568
  });
535
569
  const currentAllowance = await tradingTokenContract.read.allowance([
536
570
  this.walletClientInstance.account?.address,
@@ -31,7 +31,10 @@ class BondkitTokenFactory {
31
31
  this.contract = (0, viem_1.getContract)({
32
32
  address: this.contractAddress,
33
33
  abi: abis_1.BondkitTokenFactoryABI,
34
- client: this.walletClientInstance,
34
+ client: {
35
+ public: this.publicClient,
36
+ wallet: this.walletClientInstance,
37
+ },
35
38
  });
36
39
  }
37
40
  connect(provider) {
@@ -46,7 +49,10 @@ class BondkitTokenFactory {
46
49
  this.contract = (0, viem_1.getContract)({
47
50
  address: this.contractAddress,
48
51
  abi: abis_1.BondkitTokenFactoryABI,
49
- client: this.walletClientInstance,
52
+ client: {
53
+ public: this.publicClient,
54
+ wallet: this.walletClientInstance,
55
+ },
50
56
  });
51
57
  this.publicClient = (0, viem_1.createPublicClient)({
52
58
  chain: this.chain,
@@ -95,7 +101,10 @@ class BondkitTokenFactory {
95
101
  this.contract = (0, viem_1.getContract)({
96
102
  address: this.contractAddress,
97
103
  abi: abis_1.BondkitTokenFactoryABI,
98
- client: this.walletClientInstance,
104
+ client: {
105
+ public: this.publicClient,
106
+ wallet: this.walletClientInstance,
107
+ },
99
108
  });
100
109
  return true;
101
110
  }
@@ -126,7 +135,10 @@ class BondkitTokenFactory {
126
135
  this.contract = (0, viem_1.getContract)({
127
136
  address: this.contractAddress,
128
137
  abi: abis_1.BondkitTokenFactoryABI,
129
- client: this.walletClientInstance,
138
+ client: {
139
+ public: this.publicClient,
140
+ wallet: this.walletClientInstance,
141
+ },
130
142
  });
131
143
  }
132
144
  }
@@ -164,7 +176,6 @@ class BondkitTokenFactory {
164
176
  account: accountToUse,
165
177
  chain: this.chain,
166
178
  });
167
- console.log("hash", hash);
168
179
  const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
169
180
  for (const log of receipt.logs) {
170
181
  try {
@@ -16,6 +16,7 @@ const react_3 = require("thirdweb/react");
16
16
  const wallets_1 = require("thirdweb/wallets");
17
17
  const in_app_1 = require("thirdweb/wallets/in-app");
18
18
  const wagmi_1 = require("wagmi");
19
+ const useTWAuth_1 = require("./useTWAuth");
19
20
  const useUserQuery_1 = require("./useUserQuery");
20
21
  const useWagmiConfig_1 = require("./useWagmiConfig");
21
22
  const debug = (0, debug_1.debugB3React)("useAuthentication");
@@ -33,7 +34,7 @@ function useAuthentication(partnerId) {
33
34
  const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
34
35
  const setActiveWallet = (0, react_3.useSetActiveWallet)();
35
36
  const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
36
- const { authenticate } = (0, react_1.useSiwe)();
37
+ const { authenticate } = (0, useTWAuth_1.useTWAuth)();
37
38
  const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
38
39
  const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
39
40
  const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
@@ -106,10 +107,10 @@ function useAuthentication(partnerId) {
106
107
  }, [wallets, syncWagmi]);
107
108
  const authenticateUser = (0, react_2.useCallback)(async (wallet) => {
108
109
  setHasStartedConnecting(true);
109
- const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
110
- if (!account) {
111
- throw new Error("No account found during auto-connect");
110
+ if (!wallet) {
111
+ throw new Error("No wallet found during auto-connect");
112
112
  }
113
+ const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
113
114
  if (!account) {
114
115
  throw new Error("No account found during auto-connect");
115
116
  }
@@ -127,7 +128,7 @@ function useAuthentication(partnerId) {
127
128
  catch (error) {
128
129
  // If re-authentication fails, try fresh authentication
129
130
  debug("Re-authentication failed, attempting fresh authentication");
130
- const userAuth = await authenticate(account, partnerId);
131
+ const userAuth = await authenticate(wallet, partnerId);
131
132
  setUser(userAuth.user);
132
133
  setIsAuthenticated(true);
133
134
  setIsAuthenticating(false);