@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.
- package/dist/cjs/anyspend/types/chain.d.ts +1 -0
- package/dist/cjs/anyspend/utils/chain.js +56 -47
- 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/cjs/shared/utils/simplehash.d.ts +1 -1
- package/dist/esm/anyspend/types/chain.d.ts +1 -0
- package/dist/esm/anyspend/utils/chain.js +57 -48
- 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/esm/shared/utils/simplehash.d.ts +1 -1
- package/dist/types/anyspend/types/chain.d.ts +1 -0
- 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/dist/types/shared/utils/simplehash.d.ts +1 -1
- package/package.json +5 -6
- package/src/anyspend/types/chain.ts +1 -0
- package/src/anyspend/utils/chain.ts +49 -53
- 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
|
@@ -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(
|
|
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,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
|
-
|
|
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"];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as SimpleHashTypes from "../../global-account/types/simplehash.types";
|
|
2
2
|
export * from "../../global-account/types/simplehash.types";
|
|
3
|
-
export declare const simpleHashChainToChainId: (chain: string) => 8453 | 8333 |
|
|
3
|
+
export declare const simpleHashChainToChainId: (chain: string) => 8453 | 8333 | 1993 | 84532 | null;
|
|
4
4
|
export declare const simpleHashChainToChainName: (chain: number) => "base" | "b3" | "b3-sepolia" | "base-sepolia" | null;
|
|
5
5
|
type SimpleHashRoute = `/v0/nfts/${string}/${string}/${string}` | `/v0/nfts/${string}` | `/v0/nfts/collections/${string}/${string}` | `/v0/nfts/transfers/${string}/${string}` | `/v0/fungibles/assets` | `/v0/native_tokens/balances` | string;
|
|
6
6
|
type RouteReturnType<T extends SimpleHashRoute> = T extends `/v0/nfts/collections/${string}/${string}` ? SimpleHashTypes.SimpleHashNFTResponse : T extends `/v0/nfts/transfers/${string}/${string}` ? {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RELAY_SOLANA_MAINNET_CHAIN_ID } from "../../anyspend/constants/index.js";
|
|
2
2
|
import invariant from "invariant";
|
|
3
3
|
import { createPublicClient, createWalletClient, defineChain, http, parseEther, } from "viem";
|
|
4
|
-
import { abstract, arbitrum, avalanche, b3,
|
|
4
|
+
import { abstract, arbitrum, avalanche, b3, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
5
5
|
import { ChainType } from "../types/chain.js";
|
|
6
6
|
import { getAvaxToken, getBnbToken, getEthToken, getPolToken, getSolanaToken } from "./token.js";
|
|
7
7
|
function getCustomEvmChain(chain, rpcUrl) {
|
|
@@ -28,6 +28,7 @@ export const EVM_MAINNET = {
|
|
|
28
28
|
pollingInterval: 4000, // 4 seconds for Ethereum mainnet
|
|
29
29
|
zapperEnum: "ETHEREUM_MAINNET",
|
|
30
30
|
coingeckoName: "eth",
|
|
31
|
+
wethAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
31
32
|
},
|
|
32
33
|
[arbitrum.id]: {
|
|
33
34
|
id: arbitrum.id,
|
|
@@ -42,6 +43,7 @@ export const EVM_MAINNET = {
|
|
|
42
43
|
pollingInterval: 500, // 500ms for Arbitrum's fast blocks
|
|
43
44
|
zapperEnum: "ARBITRUM_MAINNET",
|
|
44
45
|
coingeckoName: "arbitrum",
|
|
46
|
+
wethAddress: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
|
45
47
|
},
|
|
46
48
|
[base.id]: {
|
|
47
49
|
id: base.id,
|
|
@@ -56,6 +58,7 @@ export const EVM_MAINNET = {
|
|
|
56
58
|
pollingInterval: 1000, // 1 second for Base
|
|
57
59
|
zapperEnum: "BASE_MAINNET",
|
|
58
60
|
coingeckoName: "base",
|
|
61
|
+
wethAddress: "0x4200000000000000000000000000000000000006",
|
|
59
62
|
},
|
|
60
63
|
[optimism.id]: {
|
|
61
64
|
id: optimism.id,
|
|
@@ -70,6 +73,7 @@ export const EVM_MAINNET = {
|
|
|
70
73
|
pollingInterval: 1000, // 1 second for Optimism
|
|
71
74
|
zapperEnum: "OPTIMISM_MAINNET",
|
|
72
75
|
coingeckoName: "optimism",
|
|
76
|
+
wethAddress: "0x4200000000000000000000000000000000000006",
|
|
73
77
|
},
|
|
74
78
|
[polygon.id]: {
|
|
75
79
|
id: polygon.id,
|
|
@@ -84,6 +88,7 @@ export const EVM_MAINNET = {
|
|
|
84
88
|
pollingInterval: 1000, // 1 second for Polygon
|
|
85
89
|
zapperEnum: "POLYGON_MAINNET",
|
|
86
90
|
coingeckoName: "polygon_pos",
|
|
91
|
+
wethAddress: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
|
|
87
92
|
},
|
|
88
93
|
[avalanche.id]: {
|
|
89
94
|
id: avalanche.id,
|
|
@@ -98,6 +103,7 @@ export const EVM_MAINNET = {
|
|
|
98
103
|
pollingInterval: 1000, // 1 second for Avalanche
|
|
99
104
|
zapperEnum: "AVALANCHE_MAINNET",
|
|
100
105
|
coingeckoName: "avax",
|
|
106
|
+
wethAddress: "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
|
|
101
107
|
},
|
|
102
108
|
[bsc.id]: {
|
|
103
109
|
id: bsc.id,
|
|
@@ -112,6 +118,7 @@ export const EVM_MAINNET = {
|
|
|
112
118
|
pollingInterval: 1000, // 1 second for BSC
|
|
113
119
|
zapperEnum: "BSC_MAINNET",
|
|
114
120
|
coingeckoName: "bsc",
|
|
121
|
+
wethAddress: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
|
|
115
122
|
},
|
|
116
123
|
[b3.id]: {
|
|
117
124
|
id: b3.id,
|
|
@@ -126,6 +133,7 @@ export const EVM_MAINNET = {
|
|
|
126
133
|
pollingInterval: 1000, // 1 second for B3
|
|
127
134
|
zapperEnum: "B3_MAINNET",
|
|
128
135
|
coingeckoName: "b3",
|
|
136
|
+
wethAddress: "0x4200000000000000000000000000000000000006",
|
|
129
137
|
},
|
|
130
138
|
[abstract.id]: {
|
|
131
139
|
id: abstract.id,
|
|
@@ -140,56 +148,57 @@ export const EVM_MAINNET = {
|
|
|
140
148
|
pollingInterval: 3000, // 3 seconds for Abstract
|
|
141
149
|
zapperEnum: "ABSTRACT_MAINNET",
|
|
142
150
|
coingeckoName: "abstract",
|
|
151
|
+
wethAddress: "0x3439153eb7af838ad19d56e1571fbd09333c2809",
|
|
143
152
|
},
|
|
144
153
|
};
|
|
145
154
|
export const EVM_TESTNET = {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
155
|
+
// [sepolia.id]: {
|
|
156
|
+
// id: sepolia.id,
|
|
157
|
+
// name: sepolia.name,
|
|
158
|
+
// logoUrl: "https://assets.relay.link/icons/square/1/light.png",
|
|
159
|
+
// type: ChainType.EVM,
|
|
160
|
+
// nativeRequired: parseEther("0.00001"),
|
|
161
|
+
// canDepositNative: true,
|
|
162
|
+
// defaultToken: getEthToken(sepolia.id),
|
|
163
|
+
// nativeToken: getEthToken(sepolia.id),
|
|
164
|
+
// viem: sepolia,
|
|
165
|
+
// pollingInterval: 1000, // 1 second for Sepolia
|
|
166
|
+
// coingeckoName: "sepolia-testnet",
|
|
167
|
+
// },
|
|
168
|
+
// [baseSepolia.id]: {
|
|
169
|
+
// id: baseSepolia.id,
|
|
170
|
+
// name: baseSepolia.name,
|
|
171
|
+
// logoUrl: "https://assets.relay.link/icons/square/8453/light.png",
|
|
172
|
+
// type: ChainType.EVM,
|
|
173
|
+
// nativeRequired: parseEther("0.00001"),
|
|
174
|
+
// canDepositNative: true,
|
|
175
|
+
// defaultToken: getEthToken(baseSepolia.id),
|
|
176
|
+
// nativeToken: getEthToken(baseSepolia.id),
|
|
177
|
+
// viem: baseSepolia,
|
|
178
|
+
// pollingInterval: 1000, // 1 second for Base Sepolia
|
|
179
|
+
// coingeckoName: null,
|
|
180
|
+
// },
|
|
181
|
+
// [b3Sepolia.id]: {
|
|
182
|
+
// id: b3Sepolia.id,
|
|
183
|
+
// name: b3Sepolia.name,
|
|
184
|
+
// logoUrl: "https://assets.relay.link/icons/square/8333/light.png",
|
|
185
|
+
// type: ChainType.EVM,
|
|
186
|
+
// nativeRequired: parseEther("0.00001"),
|
|
187
|
+
// canDepositNative: true,
|
|
188
|
+
// defaultToken: getEthToken(b3Sepolia.id),
|
|
189
|
+
// nativeToken: getEthToken(b3Sepolia.id),
|
|
190
|
+
// viem: b3Sepolia,
|
|
191
|
+
// pollingInterval: 1000, // 1 second for B3 Sepolia
|
|
192
|
+
// coingeckoName: null,
|
|
193
|
+
// },
|
|
194
|
+
// [b4testnet.id]: {
|
|
195
|
+
// id: b4testnet.id,
|
|
196
|
+
// logoUrl: "https://cdn.b3.fun/b4-logo.png",
|
|
197
|
+
// type: ChainType.EVM,
|
|
198
|
+
// viem: b4testnet,
|
|
199
|
+
// requireNativeBalance: parseEther("0.00001"),
|
|
200
|
+
// supportDepositNative: true,
|
|
201
|
+
// },
|
|
193
202
|
};
|
|
194
203
|
export const SOLANA_MAINNET = {
|
|
195
204
|
id: RELAY_SOLANA_MAINNET_CHAIN_ID,
|
|
@@ -41,9 +41,18 @@ export class BondkitToken {
|
|
|
41
41
|
this.contract = getContract({
|
|
42
42
|
address: this.contractAddress,
|
|
43
43
|
abi: BondkitTokenABI,
|
|
44
|
-
client:
|
|
44
|
+
client: {
|
|
45
|
+
public: this.publicClient,
|
|
46
|
+
wallet: this.walletClientInstance,
|
|
47
|
+
},
|
|
45
48
|
});
|
|
46
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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 } =
|
|
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
|
-
|
|
104
|
-
|
|
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(
|
|
125
|
+
const userAuth = await authenticate(wallet, partnerId);
|
|
125
126
|
setUser(userAuth.user);
|
|
126
127
|
setIsAuthenticated(true);
|
|
127
128
|
setIsAuthenticating(false);
|