@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.
- package/dist/cjs/bondkit/bondkitToken.js +40 -6
- package/dist/cjs/bondkit/bondkitTokenFactory.js +16 -5
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -5
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
- package/dist/cjs/global-account/react/hooks/useFirstEOA.js +1 -21
- package/dist/cjs/global-account/react/hooks/useSiwe.js +1 -0
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +4 -0
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +33 -0
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +3 -9
- package/dist/esm/bondkit/bondkitToken.js +40 -6
- package/dist/esm/bondkit/bondkitTokenFactory.js +16 -5
- package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -6
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
- package/dist/esm/global-account/react/hooks/useFirstEOA.js +2 -22
- package/dist/esm/global-account/react/hooks/useSiwe.js +1 -0
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +4 -0
- package/dist/esm/global-account/react/hooks/useTWAuth.js +27 -0
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +3 -9
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +1 -7670
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +4 -0
- package/dist/types/shared/constants/chains/b3Chain.d.ts +3 -9
- package/package.json +5 -6
- package/src/bondkit/bondkitToken.ts +42 -8
- package/src/bondkit/bondkitTokenFactory.ts +16 -5
- package/src/global-account/react/hooks/useAuthentication.ts +8 -6
- package/src/global-account/react/hooks/useFirstEOA.tsx +2 -20
- package/src/global-account/react/hooks/useSiwe.tsx +1 -0
- package/src/global-account/react/hooks/useTWAuth.tsx +36 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b3dotfun/sdk",
|
|
3
|
-
"version": "0.0.51-alpha.
|
|
3
|
+
"version": "0.0.51-alpha.1",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/cjs/index.native.js",
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
"@solana/web3.js": "^1.98.2",
|
|
302
302
|
"@stripe/react-stripe-js": "^3.7.0",
|
|
303
303
|
"@stripe/stripe-js": "^7.3.1",
|
|
304
|
-
"@thirdweb-dev/wagmi-adapter": "0.2.
|
|
304
|
+
"@thirdweb-dev/wagmi-adapter": "0.2.159",
|
|
305
305
|
"@web3icons/react": "3.16.0",
|
|
306
306
|
"big.js": "^7.0.1",
|
|
307
307
|
"class-variance-authority": "0.7.0",
|
|
@@ -374,11 +374,10 @@
|
|
|
374
374
|
"react": "^18.0.0 || ^19.0.0",
|
|
375
375
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
376
376
|
"react-native-mmkv": "^3.2.0",
|
|
377
|
-
"thirdweb": "5.108.
|
|
377
|
+
"thirdweb": "5.108.9",
|
|
378
378
|
"three": "^0.175.0",
|
|
379
|
-
"viem": "2.
|
|
380
|
-
"wagmi": "2.
|
|
381
|
-
"@wagmi/core": "2.20.3"
|
|
379
|
+
"viem": "^2.28.1",
|
|
380
|
+
"wagmi": "^2.14.15"
|
|
382
381
|
},
|
|
383
382
|
"peerDependenciesMeta": {
|
|
384
383
|
"@react-three/postprocessing": {
|
|
@@ -91,12 +91,21 @@ export class BondkitToken {
|
|
|
91
91
|
this.contract = getContract({
|
|
92
92
|
address: this.contractAddress,
|
|
93
93
|
abi: BondkitTokenABI,
|
|
94
|
-
client:
|
|
94
|
+
client: {
|
|
95
|
+
public: this.publicClient,
|
|
96
|
+
wallet: this.walletClientInstance,
|
|
97
|
+
},
|
|
95
98
|
});
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
+
getContract({
|
|
101
|
+
address: this.contractAddress,
|
|
102
|
+
abi: BondkitTokenABI,
|
|
103
|
+
client: this.publicClient, // Use public client for read operations
|
|
104
|
+
})
|
|
105
|
+
.read.tradingToken()
|
|
106
|
+
.then(tradingToken => {
|
|
107
|
+
this.tradingToken = tradingToken as Address;
|
|
108
|
+
});
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
public connect(provider?: EIP1193Provider): boolean {
|
|
@@ -119,7 +128,10 @@ export class BondkitToken {
|
|
|
119
128
|
this.contract = getContract({
|
|
120
129
|
address: this.contractAddress,
|
|
121
130
|
abi: BondkitTokenABI,
|
|
122
|
-
client:
|
|
131
|
+
client: {
|
|
132
|
+
public: this.publicClient,
|
|
133
|
+
wallet: this.walletClientInstance,
|
|
134
|
+
},
|
|
123
135
|
});
|
|
124
136
|
return true;
|
|
125
137
|
} catch (error) {
|
|
@@ -167,7 +179,10 @@ export class BondkitToken {
|
|
|
167
179
|
this.contract = getContract({
|
|
168
180
|
address: this.contractAddress,
|
|
169
181
|
abi: BondkitTokenABI,
|
|
170
|
-
client:
|
|
182
|
+
client: {
|
|
183
|
+
public: this.publicClient,
|
|
184
|
+
wallet: this.walletClientInstance,
|
|
185
|
+
},
|
|
171
186
|
});
|
|
172
187
|
|
|
173
188
|
return true;
|
|
@@ -505,7 +520,10 @@ export class BondkitToken {
|
|
|
505
520
|
this.contract = getContract({
|
|
506
521
|
address: this.contractAddress,
|
|
507
522
|
abi: BondkitTokenABI,
|
|
508
|
-
client:
|
|
523
|
+
client: {
|
|
524
|
+
public: this.publicClient,
|
|
525
|
+
wallet: this.walletClientInstance,
|
|
526
|
+
},
|
|
509
527
|
});
|
|
510
528
|
}
|
|
511
529
|
} catch (_) {}
|
|
@@ -514,6 +532,19 @@ export class BondkitToken {
|
|
|
514
532
|
throw new Error("Wallet key not set or client not connected for write operation.");
|
|
515
533
|
}
|
|
516
534
|
}
|
|
535
|
+
|
|
536
|
+
// Only attempt chain switching for browser wallet providers
|
|
537
|
+
// Private key users cannot switch chains programmatically
|
|
538
|
+
if (this.connectedProvider && this.walletClientInstance.account) {
|
|
539
|
+
const walletChainId = await this.walletClientInstance.getChainId();
|
|
540
|
+
if (walletChainId !== this.chain.id) {
|
|
541
|
+
try {
|
|
542
|
+
await this.walletClientInstance.switchChain({ id: this.chain.id });
|
|
543
|
+
} catch (switchErr) {
|
|
544
|
+
throw new Error(`Please switch your wallet to ${this.chain.name} (${this.chain.id}).`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
517
548
|
const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
|
|
518
549
|
if (!accountToUse) throw new Error("Account for transaction could not be determined.");
|
|
519
550
|
|
|
@@ -624,7 +655,10 @@ export class BondkitToken {
|
|
|
624
655
|
const tradingTokenContract = getContract({
|
|
625
656
|
address: this.tradingToken as Address,
|
|
626
657
|
abi: erc20Abi,
|
|
627
|
-
client:
|
|
658
|
+
client: {
|
|
659
|
+
public: this.publicClient,
|
|
660
|
+
wallet: this.walletClientInstance,
|
|
661
|
+
},
|
|
628
662
|
});
|
|
629
663
|
|
|
630
664
|
const currentAllowance = await tradingTokenContract.read.allowance([
|
|
@@ -56,7 +56,10 @@ export class BondkitTokenFactory {
|
|
|
56
56
|
this.contract = getContract({
|
|
57
57
|
address: this.contractAddress,
|
|
58
58
|
abi: BondkitTokenFactoryABI,
|
|
59
|
-
client:
|
|
59
|
+
client: {
|
|
60
|
+
public: this.publicClient,
|
|
61
|
+
wallet: this.walletClientInstance,
|
|
62
|
+
},
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -75,7 +78,10 @@ export class BondkitTokenFactory {
|
|
|
75
78
|
this.contract = getContract({
|
|
76
79
|
address: this.contractAddress,
|
|
77
80
|
abi: BondkitTokenFactoryABI,
|
|
78
|
-
client:
|
|
81
|
+
client: {
|
|
82
|
+
public: this.publicClient,
|
|
83
|
+
wallet: this.walletClientInstance,
|
|
84
|
+
},
|
|
79
85
|
});
|
|
80
86
|
|
|
81
87
|
this.publicClient = createPublicClient({
|
|
@@ -127,7 +133,10 @@ export class BondkitTokenFactory {
|
|
|
127
133
|
this.contract = getContract({
|
|
128
134
|
address: this.contractAddress,
|
|
129
135
|
abi: BondkitTokenFactoryABI,
|
|
130
|
-
client:
|
|
136
|
+
client: {
|
|
137
|
+
public: this.publicClient,
|
|
138
|
+
wallet: this.walletClientInstance,
|
|
139
|
+
},
|
|
131
140
|
});
|
|
132
141
|
|
|
133
142
|
return true;
|
|
@@ -157,7 +166,10 @@ export class BondkitTokenFactory {
|
|
|
157
166
|
this.contract = getContract({
|
|
158
167
|
address: this.contractAddress,
|
|
159
168
|
abi: BondkitTokenFactoryABI,
|
|
160
|
-
client:
|
|
169
|
+
client: {
|
|
170
|
+
public: this.publicClient,
|
|
171
|
+
wallet: this.walletClientInstance,
|
|
172
|
+
},
|
|
161
173
|
});
|
|
162
174
|
}
|
|
163
175
|
} catch (_) {}
|
|
@@ -201,7 +213,6 @@ export class BondkitTokenFactory {
|
|
|
201
213
|
chain: this.chain,
|
|
202
214
|
});
|
|
203
215
|
|
|
204
|
-
console.log("hash", hash);
|
|
205
216
|
const receipt: TransactionReceipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
206
217
|
|
|
207
218
|
for (const log of receipt.logs) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
2
|
import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
|
|
3
|
-
import { useAuthStore
|
|
3
|
+
import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
4
4
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
5
5
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
6
6
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { Wallet, ecosystemWallet } from "thirdweb/wallets";
|
|
18
18
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
19
19
|
import { useAccount, useConnect, useSwitchAccount } from "wagmi";
|
|
20
|
+
import { useTWAuth } from "./useTWAuth";
|
|
20
21
|
import { useUserQuery } from "./useUserQuery";
|
|
21
22
|
import { useWagmiConfig } from "./useWagmiConfig";
|
|
22
23
|
|
|
@@ -36,7 +37,7 @@ export function useAuthentication(partnerId: string) {
|
|
|
36
37
|
const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
|
|
37
38
|
const setActiveWallet = useSetActiveWallet();
|
|
38
39
|
const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
|
|
39
|
-
const { authenticate } =
|
|
40
|
+
const { authenticate } = useTWAuth();
|
|
40
41
|
const { user, setUser } = useUserQuery();
|
|
41
42
|
const useAutoConnectLoadingPrevious = useRef(false);
|
|
42
43
|
const wagmiConfig = useWagmiConfig(partnerId);
|
|
@@ -119,10 +120,11 @@ export function useAuthentication(partnerId: string) {
|
|
|
119
120
|
async (wallet?: Wallet) => {
|
|
120
121
|
setHasStartedConnecting(true);
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
throw new Error("No account found during auto-connect");
|
|
123
|
+
if (!wallet) {
|
|
124
|
+
throw new Error("No wallet found during auto-connect");
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
|
|
126
128
|
if (!account) {
|
|
127
129
|
throw new Error("No account found during auto-connect");
|
|
128
130
|
}
|
|
@@ -141,7 +143,7 @@ export function useAuthentication(partnerId: string) {
|
|
|
141
143
|
} catch (error) {
|
|
142
144
|
// If re-authentication fails, try fresh authentication
|
|
143
145
|
debug("Re-authentication failed, attempting fresh authentication");
|
|
144
|
-
const userAuth = await authenticate(
|
|
146
|
+
const userAuth = await authenticate(wallet, partnerId);
|
|
145
147
|
setUser(userAuth.user);
|
|
146
148
|
setIsAuthenticated(true);
|
|
147
149
|
setIsAuthenticating(false);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect, useMemo, useState } from "react";
|
|
5
|
-
import { viemAdapter } from "thirdweb/adapters/viem";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
6
4
|
import { useConnectedWallets, useWalletInfo } from "thirdweb/react";
|
|
7
5
|
import { Wallet } from "thirdweb/wallets";
|
|
8
6
|
|
|
9
7
|
const debug = debugB3React("useFirstEOA");
|
|
10
8
|
|
|
11
|
-
export function useFirstEOA(
|
|
9
|
+
export function useFirstEOA() {
|
|
12
10
|
const wallets = useConnectedWallets();
|
|
13
11
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
14
12
|
const [firstEOA, setFirstEOA] = useState<Wallet | undefined>(undefined);
|
|
@@ -41,25 +39,9 @@ export function useFirstEOA(chain?: { id: number; name: string; rpc: string }) {
|
|
|
41
39
|
autoSelectFirstEOAWallet();
|
|
42
40
|
}, [isConnected, wallets]);
|
|
43
41
|
|
|
44
|
-
const walletClient = useMemo(() => {
|
|
45
|
-
if (!firstEOA) return undefined;
|
|
46
|
-
if (!chain) return undefined;
|
|
47
|
-
try {
|
|
48
|
-
const viemClientWallet = viemAdapter.wallet.toViem({
|
|
49
|
-
client,
|
|
50
|
-
chain,
|
|
51
|
-
wallet: firstEOA,
|
|
52
|
-
});
|
|
53
|
-
return viemClientWallet;
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.error("Error setting wallet client", err);
|
|
56
|
-
}
|
|
57
|
-
}, [firstEOA, chain]);
|
|
58
|
-
|
|
59
42
|
return {
|
|
60
43
|
account: firstEOA,
|
|
61
44
|
address,
|
|
62
45
|
info: walletInfo,
|
|
63
|
-
walletClient,
|
|
64
46
|
};
|
|
65
47
|
}
|
|
@@ -9,6 +9,7 @@ export function useSiwe() {
|
|
|
9
9
|
|
|
10
10
|
const authenticate = useCallback(
|
|
11
11
|
async (account: Account, partnerId: string) => {
|
|
12
|
+
console.warn("@@useSiwe is deprecated, use useTWAuth instead");
|
|
12
13
|
if (!account || !account.signMessage) throw new Error("Account not found");
|
|
13
14
|
|
|
14
15
|
console.log("@@useAuthenticate:referralCode", referralCode);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
|
+
import debug from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { Wallet } from "thirdweb/wallets";
|
|
5
|
+
import { useSearchParam } from "./useSearchParamsSSR";
|
|
6
|
+
|
|
7
|
+
export function useTWAuth() {
|
|
8
|
+
const referralCode = useSearchParam("referralCode");
|
|
9
|
+
|
|
10
|
+
const authenticate = useCallback(
|
|
11
|
+
async (wallet: Wallet, partnerId: string) => {
|
|
12
|
+
if (!wallet || !wallet?.getAuthToken?.()) throw new Error("Wallet not found");
|
|
13
|
+
|
|
14
|
+
const authToken = wallet.getAuthToken();
|
|
15
|
+
debug("@@useTWSignIn:authToken", authToken);
|
|
16
|
+
debug("@@useTWSignIn:referralCode", referralCode);
|
|
17
|
+
|
|
18
|
+
// authenticate
|
|
19
|
+
const response = await app.authenticate({
|
|
20
|
+
strategy: "thirdweb-jwt",
|
|
21
|
+
accessToken: authToken,
|
|
22
|
+
// http://localhost:5173/?referralCode=GIO2
|
|
23
|
+
referralCode,
|
|
24
|
+
partnerId: partnerId,
|
|
25
|
+
});
|
|
26
|
+
debug("@@useTWSignIn:response", response);
|
|
27
|
+
|
|
28
|
+
return response;
|
|
29
|
+
},
|
|
30
|
+
[referralCode],
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
authenticate,
|
|
35
|
+
};
|
|
36
|
+
}
|