@talken/talkenkit 2.4.16 → 2.4.17
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/abcWallet-54KUGWUZ.js +192 -0
- package/dist/abcWallet-KZHOADBJ.js +192 -0
- package/dist/abcWallet-NZAVB4PI.js +190 -0
- package/dist/chunk-5X3ROW3U.js +8777 -0
- package/dist/chunk-DKA3NVFM.js +8497 -0
- package/dist/chunk-QNZ5HSPM.js +8339 -0
- package/dist/chunk-VE53ZNZV.js +331 -0
- package/dist/components/ConfirmationModal/ApproveSection.css.d.ts +16 -0
- package/dist/components/ConfirmationModal/ApproveSection.d.ts +8 -0
- package/dist/components/ConfirmationModal/NFTPlaceholder.css.d.ts +7 -0
- package/dist/components/ConfirmationModal/NFTPlaceholder.d.ts +8 -0
- package/dist/components/ConfirmationModal/NftApprovalSection.css.d.ts +10 -0
- package/dist/components/ConfirmationModal/NftApprovalSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/SignConfirmationModal.css.d.ts +35 -0
- package/dist/components/ConfirmationModal/SignConfirmationModal.d.ts +17 -0
- package/dist/components/ConfirmationModal/SwapSection.css.d.ts +17 -0
- package/dist/components/ConfirmationModal/SwapSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/TransactionConfirmationModal.css.d.ts +49 -0
- package/dist/components/ConfirmationModal/TransactionConfirmationModal.d.ts +12 -0
- package/dist/components/ConfirmationModal/TransferSection.css.d.ts +17 -0
- package/dist/components/ConfirmationModal/TransferSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/commonStyles.css.d.ts +37 -0
- package/dist/components/ConfirmationModal/constants.d.ts +16 -0
- package/dist/components/ConfirmationModal/index.d.ts +9 -0
- package/dist/components/ConfirmationModal/modalTheme.css.d.ts +20 -0
- package/dist/components/ConfirmationModal/transactionUIRegistry.d.ts +134 -0
- package/dist/components/ConfirmationModal/utils.d.ts +37 -0
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthSections.css.d.ts +1 -0
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthSections.d.ts +1 -1
- package/dist/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasAuth.d.ts +2 -25
- package/dist/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasSocial.d.ts +1 -47
- package/dist/components/ConnectOptions/PinAuth/hooks/useWalletGeneration.d.ts +4 -21
- package/dist/components/GasFeeModal/GasFeeEditModal.css.d.ts +32 -0
- package/dist/components/GasFeeModal/GasFeeEditModal.d.ts +21 -0
- package/dist/components/GasFeeModal/index.d.ts +3 -0
- package/dist/components/GasFeeModal/modalTheme.css.d.ts +19 -0
- package/dist/components/Icons/Close2.d.ts +7 -0
- package/dist/components/Icons/Copy2.d.ts +4 -0
- package/dist/components/Icons/Dropdown2.d.ts +4 -0
- package/dist/components/Icons/Edit.d.ts +4 -0
- package/dist/components/Icons/InfoCircle.d.ts +4 -0
- package/dist/components/Icons/Kakao.d.ts +2 -0
- package/dist/components/Icons/Minus.d.ts +4 -0
- package/dist/components/Icons/Plus.d.ts +4 -0
- package/dist/components/Icons/SettingsGear.d.ts +4 -0
- package/dist/components/Icons/SpeedHigh.d.ts +4 -0
- package/dist/components/Icons/SpeedLow.d.ts +4 -0
- package/dist/components/Icons/SpeedMedium.d.ts +4 -0
- package/dist/components/RainbowKitProvider/InternalPinProvider.d.ts +7 -9
- package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +7 -1
- package/dist/components/Toast/Toast.css.d.ts +2 -0
- package/dist/components/Toast/Toast.d.ts +6 -0
- package/dist/components/Toast/index.d.ts +4 -0
- package/dist/components/Toast/useToast.d.ts +10 -0
- package/dist/config/networks.d.ts +10 -0
- package/dist/css/sprinkles.css.d.ts +1 -1
- package/dist/hooks/useSolanaWallet.d.ts +5 -23
- package/dist/hooks/useTronWallet.d.ts +63 -0
- package/dist/index.css +1903 -236
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7970 -4015
- package/dist/klipWallet-RD5Y4UEK.js +8 -0
- package/dist/providers/SignConfirmationProvider/SignConfirmationProvider.d.ts +22 -0
- package/dist/providers/SignConfirmationProvider/index.d.ts +6 -0
- package/dist/providers/SignConfirmationProvider/requestParsers.d.ts +24 -0
- package/dist/providers/SignConfirmationProvider/types.d.ts +91 -0
- package/dist/providers/SignConfirmationProvider/useApiClient.d.ts +15 -0
- package/dist/providers/SignConfirmationProvider/useTransactionResolver.d.ts +18 -0
- package/dist/secure-AEBFSVWE.js +8 -0
- package/dist/services/AbcAgenticWalletService.d.ts +111 -0
- package/dist/services/AbcAuthService.d.ts +26 -20
- package/dist/types/index.d.ts +3 -0
- package/dist/types/token.d.ts +82 -0
- package/dist/utils/abi/abiDecoder.d.ts +144 -0
- package/dist/utils/apiClientFactory.d.ts +21 -0
- package/dist/utils/blockies.d.ts +12 -0
- package/dist/utils/tokenMapper.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/abcApi.d.ts +4 -1
- package/dist/wallets/walletConnectors/abcWallet/abcApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +6 -8
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +9 -9
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +17 -6
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +5 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +11 -34
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +3 -11
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +17 -80
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +112 -0
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +11 -0
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.d.ts +2 -0
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +11 -10
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.d.ts +9 -11
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.d.ts +45 -0
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/SigningApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +9 -1
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +333 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +11 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.d.ts +18 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +14 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.d.ts +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/TronApi.d.ts +102 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TronApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.d.ts +4 -2
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +60 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/index.d.ts +24 -0
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +35 -17
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +39 -1
- package/dist/wallets/walletConnectors/abcWallet/constants.js +5 -1
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.d.ts +6 -0
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.js +37 -1
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +5 -3
- package/dist/wallets/walletConnectors/abcWallet/index.js +44 -31
- package/dist/wallets/walletConnectors/abcWallet/kakaoAuth.d.ts +27 -0
- package/dist/wallets/walletConnectors/abcWallet/kakaoAuth.js +290 -0
- package/dist/wallets/walletConnectors/abcWallet/networkConfig.d.ts +39 -3
- package/dist/wallets/walletConnectors/abcWallet/networkConfig.js +11 -3
- package/dist/wallets/walletConnectors/abcWallet/secure.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +369 -7
- package/dist/wallets/walletConnectors/abcWallet/types.js +5 -3
- package/dist/wallets/walletConnectors/abcWallet/utils.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.d.ts +10 -19
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +2 -2
- package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
- package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
- package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
- package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
- package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
- package/dist/wallets/walletConnectors/chunk-25V3FW3O.js +282 -0
- package/dist/wallets/walletConnectors/chunk-27346T3J.js +134 -0
- package/dist/wallets/walletConnectors/chunk-5CNLMOB2.js +75 -0
- package/dist/wallets/walletConnectors/chunk-5K45TCAM.js +333 -0
- package/dist/wallets/walletConnectors/chunk-5VDSMZC4.js +286 -0
- package/dist/wallets/walletConnectors/chunk-5W7RBMPH.js +351 -0
- package/dist/wallets/walletConnectors/chunk-5XORKEWE.js +326 -0
- package/dist/wallets/walletConnectors/chunk-63WBO52A.js +77 -0
- package/dist/wallets/walletConnectors/chunk-7IRF225N.js +75 -0
- package/dist/wallets/walletConnectors/chunk-7QHCSJDN.js +726 -0
- package/dist/wallets/walletConnectors/chunk-A27H6PEU.js +739 -0
- package/dist/wallets/walletConnectors/chunk-A4WR3CFN.js +130 -0
- package/dist/wallets/walletConnectors/chunk-A6FUNQWF.js +572 -0
- package/dist/wallets/walletConnectors/chunk-AF4OCS7N.js +46 -0
- package/dist/wallets/walletConnectors/chunk-AFWBXEEC.js +66 -0
- package/dist/wallets/walletConnectors/chunk-AUGP2LJR.js +182 -0
- package/dist/wallets/walletConnectors/chunk-AWLDVQXC.js +317 -0
- package/dist/wallets/walletConnectors/chunk-BLEKTKBN.js +479 -0
- package/dist/wallets/walletConnectors/chunk-BVL6G5HI.js +1757 -0
- package/dist/wallets/walletConnectors/chunk-CMTGEHDI.js +485 -0
- package/dist/wallets/walletConnectors/chunk-D5EFTEOM.js +56 -0
- package/dist/wallets/walletConnectors/chunk-DM5NLSWD.js +346 -0
- package/dist/wallets/walletConnectors/chunk-EBGI4D2T.js +69 -0
- package/dist/wallets/walletConnectors/chunk-EEH2HMFG.js +47 -0
- package/dist/wallets/walletConnectors/chunk-F5JWDBKK.js +47 -0
- package/dist/wallets/walletConnectors/chunk-FN67MIIH.js +75 -0
- package/dist/wallets/walletConnectors/chunk-FWYVBX5F.js +75 -0
- package/dist/wallets/walletConnectors/chunk-GH6ZDY4K.js +58 -0
- package/dist/wallets/walletConnectors/chunk-GIJZMIBD.js +63 -0
- package/dist/wallets/walletConnectors/chunk-GO6OLTNF.js +479 -0
- package/dist/wallets/walletConnectors/chunk-HKXBK3NY.js +75 -0
- package/dist/wallets/walletConnectors/chunk-HMD2WWFQ.js +75 -0
- package/dist/wallets/walletConnectors/chunk-HO5Z2CTL.js +280 -0
- package/dist/wallets/walletConnectors/chunk-I3GFVK5O.js +151 -0
- package/dist/wallets/walletConnectors/chunk-IUHZ5ZCE.js +121 -0
- package/dist/wallets/walletConnectors/chunk-JODNZWWG.js +330 -0
- package/dist/wallets/walletConnectors/chunk-JTST3KMW.js +75 -0
- package/dist/wallets/walletConnectors/chunk-KH2L3ONV.js +1599 -0
- package/dist/wallets/walletConnectors/chunk-LHV22375.js +182 -0
- package/dist/wallets/walletConnectors/chunk-LZZE462U.js +315 -0
- package/dist/wallets/walletConnectors/chunk-MGCRUAHX.js +276 -0
- package/dist/wallets/walletConnectors/chunk-MURSKRMJ.js +63 -0
- package/dist/wallets/walletConnectors/chunk-NG7PSAPX.js +115 -0
- package/dist/wallets/walletConnectors/chunk-NHP6D6AH.js +204 -0
- package/dist/wallets/walletConnectors/chunk-O4AU63LK.js +181 -0
- package/dist/wallets/walletConnectors/chunk-OBS74J5N.js +221 -0
- package/dist/wallets/walletConnectors/chunk-ON4U54WO.js +115 -0
- package/dist/wallets/walletConnectors/chunk-PPYBE5TV.js +276 -0
- package/dist/wallets/walletConnectors/chunk-PWWSAM4G.js +309 -0
- package/dist/wallets/walletConnectors/chunk-QB5GDLRU.js +330 -0
- package/dist/wallets/walletConnectors/chunk-QMLG7MAP.js +107 -0
- package/dist/wallets/walletConnectors/chunk-RGIB7FFH.js +47 -0
- package/dist/wallets/walletConnectors/chunk-SHJBMDP4.js +278 -0
- package/dist/wallets/walletConnectors/chunk-SOBJYYIX.js +484 -0
- package/dist/wallets/walletConnectors/chunk-T66U3ADD.js +58 -0
- package/dist/wallets/walletConnectors/chunk-THCKLFSJ.js +75 -0
- package/dist/wallets/walletConnectors/chunk-TS466TDR.js +286 -0
- package/dist/wallets/walletConnectors/chunk-UJGFYQEV.js +459 -0
- package/dist/wallets/walletConnectors/chunk-UXNEBBUV.js +224 -0
- package/dist/wallets/walletConnectors/chunk-VRCNFVPM.js +276 -0
- package/dist/wallets/walletConnectors/chunk-WODNUC65.js +333 -0
- package/dist/wallets/walletConnectors/chunk-X6A2FSHK.js +484 -0
- package/dist/wallets/walletConnectors/chunk-XVRNEES5.js +1541 -0
- package/dist/wallets/walletConnectors/chunk-XWVM2Y5A.js +306 -0
- package/dist/wallets/walletConnectors/chunk-XXG7ABSJ.js +328 -0
- package/dist/wallets/walletConnectors/chunk-YJH4BHSB.js +254 -0
- package/dist/wallets/walletConnectors/chunk-YRDNIP2H.js +90 -0
- package/dist/wallets/walletConnectors/chunk-YTPAWPCA.js +156 -0
- package/dist/wallets/walletConnectors/chunk-ZCSHD7UG.js +562 -0
- package/dist/wallets/walletConnectors/chunk-ZZCZ3RJU.js +272 -0
- package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
- package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
- package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
- package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
- package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
- package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
- package/dist/wallets/walletConnectors/index.js +57 -56
- package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
- package/dist/wallets/walletConnectors/klipWallet/klipWallet.d.ts +3 -0
- package/dist/wallets/walletConnectors/klipWallet/klipWallet.js +8 -0
- package/dist/wallets/walletConnectors/klipWallet-PPTYYB5G.js +7 -0
- package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
- package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
- package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
- package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
- package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
- package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
- package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
- package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
- package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
- package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
BaseApiClient
|
|
4
|
+
} from "./chunk-XWVM2Y5A.js";
|
|
5
|
+
import {
|
|
6
|
+
ABC_ENDPOINTS
|
|
7
|
+
} from "./chunk-OBS74J5N.js";
|
|
8
|
+
|
|
9
|
+
// src/wallets/walletConnectors/abcWallet/api/GasApi.ts
|
|
10
|
+
var GasApi = class extends BaseApiClient {
|
|
11
|
+
parseGasFees(data) {
|
|
12
|
+
return {
|
|
13
|
+
...data,
|
|
14
|
+
networkCongestion: data.networkCongestion != null ? Number(data.networkCongestion) : void 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get suggested gas fees for EIP-1559 transactions
|
|
19
|
+
* GET /wapi/v2/gas/suggestedGasFees?network=xxx
|
|
20
|
+
*
|
|
21
|
+
* @param network - Network name (ethereum, polygon, klaytn, etc.)
|
|
22
|
+
* @returns Suggested gas fees or null if failed
|
|
23
|
+
*/
|
|
24
|
+
async getSuggestedGasFees(network) {
|
|
25
|
+
try {
|
|
26
|
+
const url = `${ABC_ENDPOINTS.GAS_SUGGESTED_FEES}?network=${encodeURIComponent(network)}`;
|
|
27
|
+
const response = await this.request(url, {
|
|
28
|
+
method: "GET",
|
|
29
|
+
skipAuth: false
|
|
30
|
+
});
|
|
31
|
+
if (response.status === "success" && response.data) {
|
|
32
|
+
return this.parseGasFees(response.data);
|
|
33
|
+
}
|
|
34
|
+
if (response.low && response.medium && response.high) {
|
|
35
|
+
return this.parseGasFees(response);
|
|
36
|
+
}
|
|
37
|
+
console.warn("[GasApi] No gas fees in response for network:", network);
|
|
38
|
+
return null;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn(
|
|
41
|
+
"[GasApi] Failed to fetch suggested gas fees:",
|
|
42
|
+
network,
|
|
43
|
+
error
|
|
44
|
+
);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Estimate gas limit for EIP-1559 transaction
|
|
50
|
+
* POST /wapi/v2/gas/estimate/eip1559
|
|
51
|
+
*
|
|
52
|
+
* @param params - Transaction parameters
|
|
53
|
+
* @returns Gas limit (hex string) or null if failed
|
|
54
|
+
*/
|
|
55
|
+
async estimateGas(params) {
|
|
56
|
+
try {
|
|
57
|
+
const response = await this.request(
|
|
58
|
+
ABC_ENDPOINTS.GAS_ESTIMATE_EIP1559,
|
|
59
|
+
{
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: {
|
|
62
|
+
network: params.network,
|
|
63
|
+
from: params.from || "",
|
|
64
|
+
to: params.to,
|
|
65
|
+
value: params.value || "0x0",
|
|
66
|
+
data: params.data || "0x"
|
|
67
|
+
},
|
|
68
|
+
skipAuth: false
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
if (response.status === "success" && response.data?.result) {
|
|
72
|
+
return response.data.result;
|
|
73
|
+
}
|
|
74
|
+
if (response.result) {
|
|
75
|
+
return response.result;
|
|
76
|
+
}
|
|
77
|
+
console.warn("[GasApi] No gas estimate in response");
|
|
78
|
+
return null;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.warn("[GasApi] Failed to estimate gas:", error);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get suggested gas fees with timeout
|
|
86
|
+
*
|
|
87
|
+
* @param network - Network name
|
|
88
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
89
|
+
* @returns Suggested gas fees or null if timeout/failed
|
|
90
|
+
*/
|
|
91
|
+
async getSuggestedGasFeesWithTimeout(network, timeoutMs = 5e3) {
|
|
92
|
+
try {
|
|
93
|
+
const result = await Promise.race([
|
|
94
|
+
this.getSuggestedGasFees(network),
|
|
95
|
+
new Promise(
|
|
96
|
+
(resolve) => setTimeout(() => resolve(null), timeoutMs)
|
|
97
|
+
)
|
|
98
|
+
]);
|
|
99
|
+
return result;
|
|
100
|
+
} catch (_error) {
|
|
101
|
+
console.warn("[GasApi] Gas fees request timed out:", network);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Estimate gas with timeout
|
|
107
|
+
*
|
|
108
|
+
* @param params - Transaction parameters
|
|
109
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
110
|
+
* @returns Gas limit (hex string) or null if timeout/failed
|
|
111
|
+
*/
|
|
112
|
+
async estimateGasWithTimeout(params, timeoutMs = 5e3) {
|
|
113
|
+
try {
|
|
114
|
+
const result = await Promise.race([
|
|
115
|
+
this.estimateGas(params),
|
|
116
|
+
new Promise(
|
|
117
|
+
(resolve) => setTimeout(() => resolve(null), timeoutMs)
|
|
118
|
+
)
|
|
119
|
+
]);
|
|
120
|
+
return result;
|
|
121
|
+
} catch (_error) {
|
|
122
|
+
console.warn("[GasApi] Gas estimate request timed out");
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
GasApi
|
|
130
|
+
};
|
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
getChainKey,
|
|
4
|
+
getNetworkName
|
|
5
|
+
} from "./chunk-7QHCSJDN.js";
|
|
6
|
+
import {
|
|
7
|
+
hexToNumber,
|
|
8
|
+
numberToHex
|
|
9
|
+
} from "./chunk-GO6OLTNF.js";
|
|
10
|
+
|
|
11
|
+
// src/wallets/walletConnectors/abcWallet/abcProvider.ts
|
|
12
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
13
|
+
import { parseGwei } from "viem";
|
|
14
|
+
var EventEmitter = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.events = /* @__PURE__ */ new Map();
|
|
17
|
+
}
|
|
18
|
+
on(event, listener) {
|
|
19
|
+
if (!this.events.has(event)) {
|
|
20
|
+
this.events.set(event, []);
|
|
21
|
+
}
|
|
22
|
+
this.events.get(event).push(listener);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
off(event, listener) {
|
|
26
|
+
const listeners = this.events.get(event);
|
|
27
|
+
if (listeners) {
|
|
28
|
+
const index = listeners.indexOf(listener);
|
|
29
|
+
if (index !== -1) {
|
|
30
|
+
listeners.splice(index, 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
removeListener(event, listener) {
|
|
36
|
+
return this.off(event, listener);
|
|
37
|
+
}
|
|
38
|
+
emit(event, ...args) {
|
|
39
|
+
const listeners = this.events.get(event);
|
|
40
|
+
if (listeners) {
|
|
41
|
+
for (const listener of listeners) {
|
|
42
|
+
listener(...args);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
removeAllListeners(event) {
|
|
49
|
+
if (event) {
|
|
50
|
+
this.events.delete(event);
|
|
51
|
+
} else {
|
|
52
|
+
this.events.clear();
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var ProviderRpcError = class extends Error {
|
|
58
|
+
constructor(code, message, data) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.data = data;
|
|
62
|
+
this.name = "ProviderRpcError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var ErrorCode = {
|
|
66
|
+
USER_REJECTED: 4001,
|
|
67
|
+
UNAUTHORIZED: 4100,
|
|
68
|
+
UNSUPPORTED_METHOD: 4200,
|
|
69
|
+
DISCONNECTED: 4900,
|
|
70
|
+
CHAIN_DISCONNECTED: 4901,
|
|
71
|
+
INVALID_PARAMS: -32602,
|
|
72
|
+
INTERNAL_ERROR: -32603
|
|
73
|
+
};
|
|
74
|
+
var AbcEvmProvider = class extends EventEmitter {
|
|
75
|
+
constructor(client) {
|
|
76
|
+
super();
|
|
77
|
+
this.wallet = null;
|
|
78
|
+
this.chainId = 1;
|
|
79
|
+
// Default to Ethereum mainnet
|
|
80
|
+
this.connected = false;
|
|
81
|
+
this.client = client;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Set wallet information
|
|
85
|
+
*/
|
|
86
|
+
setWallet(wallet) {
|
|
87
|
+
const previousAddress = this.wallet?.address;
|
|
88
|
+
const previousChainId = this.chainId;
|
|
89
|
+
this.wallet = wallet;
|
|
90
|
+
this.chainId = wallet.chainId;
|
|
91
|
+
this.connected = true;
|
|
92
|
+
if (previousAddress !== wallet.address) {
|
|
93
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
94
|
+
}
|
|
95
|
+
if (previousChainId !== wallet.chainId) {
|
|
96
|
+
this.emit("chainChanged", numberToHex(wallet.chainId));
|
|
97
|
+
}
|
|
98
|
+
this.emit("connect", { chainId: numberToHex(wallet.chainId) });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Clear wallet (disconnect)
|
|
102
|
+
*/
|
|
103
|
+
clearWallet() {
|
|
104
|
+
this.wallet = null;
|
|
105
|
+
this.connected = false;
|
|
106
|
+
this.emit("disconnect", {
|
|
107
|
+
code: ErrorCode.DISCONNECTED,
|
|
108
|
+
message: "User disconnected"
|
|
109
|
+
});
|
|
110
|
+
this.emit("accountsChanged", []);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Set request interceptor for sign confirmation
|
|
114
|
+
* The interceptor is called before signing operations to show confirmation UI
|
|
115
|
+
*/
|
|
116
|
+
setRequestInterceptor(interceptor) {
|
|
117
|
+
this.requestInterceptor = interceptor;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Set TalkenApiClient for backend-proxied transaction flow
|
|
121
|
+
* When set, transaction methods will use a single API call instead of multi-step WaaS
|
|
122
|
+
*/
|
|
123
|
+
setTalkenApi(talkenApi) {
|
|
124
|
+
this.talkenApi = talkenApi;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Call request interceptor if configured
|
|
128
|
+
* Called by specific signing/transaction methods that need user confirmation
|
|
129
|
+
* @returns Resolved transaction with user modifications if changed in confirmation modal
|
|
130
|
+
*/
|
|
131
|
+
async callInterceptor(method, params) {
|
|
132
|
+
if (!this.requestInterceptor) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
const request = {
|
|
136
|
+
method,
|
|
137
|
+
params,
|
|
138
|
+
chainId: this.chainId,
|
|
139
|
+
address: this.wallet?.address || ""
|
|
140
|
+
};
|
|
141
|
+
return this.requestInterceptor(request);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* EIP-1193 request method
|
|
145
|
+
*/
|
|
146
|
+
async request(args) {
|
|
147
|
+
const { method, params } = args;
|
|
148
|
+
switch (method) {
|
|
149
|
+
case "eth_requestAccounts":
|
|
150
|
+
return this.eth_requestAccounts();
|
|
151
|
+
case "eth_accounts":
|
|
152
|
+
return this.eth_accounts();
|
|
153
|
+
case "eth_chainId":
|
|
154
|
+
return this.eth_chainId();
|
|
155
|
+
case "eth_sendTransaction":
|
|
156
|
+
case "wallet_sendTransaction":
|
|
157
|
+
return this.eth_sendTransaction(params);
|
|
158
|
+
case "eth_signTransaction":
|
|
159
|
+
return this.eth_signTransaction(params);
|
|
160
|
+
case "personal_sign":
|
|
161
|
+
return this.personal_sign(params);
|
|
162
|
+
case "eth_sign":
|
|
163
|
+
return this.eth_sign(params);
|
|
164
|
+
case "eth_signTypedData":
|
|
165
|
+
case "eth_signTypedData_v3":
|
|
166
|
+
case "eth_signTypedData_v4":
|
|
167
|
+
return this.eth_signTypedData(params);
|
|
168
|
+
case "wallet_switchEthereumChain":
|
|
169
|
+
return this.wallet_switchEthereumChain(params);
|
|
170
|
+
case "wallet_addEthereumChain":
|
|
171
|
+
return this.wallet_addEthereumChain(params);
|
|
172
|
+
case "eth_estimateGas":
|
|
173
|
+
return this.eth_estimateGas(params);
|
|
174
|
+
case "eth_getTransactionCount":
|
|
175
|
+
return this.eth_getTransactionCount(
|
|
176
|
+
Array.isArray(params) ? params : []
|
|
177
|
+
);
|
|
178
|
+
case "eth_blockNumber":
|
|
179
|
+
case "eth_call":
|
|
180
|
+
case "eth_gasPrice":
|
|
181
|
+
case "eth_getBalance":
|
|
182
|
+
case "eth_getBlockByHash":
|
|
183
|
+
case "eth_getBlockByNumber":
|
|
184
|
+
case "eth_getCode":
|
|
185
|
+
case "eth_getStorageAt":
|
|
186
|
+
case "eth_getTransactionByHash":
|
|
187
|
+
case "eth_getTransactionReceipt":
|
|
188
|
+
throw new ProviderRpcError(
|
|
189
|
+
ErrorCode.UNSUPPORTED_METHOD,
|
|
190
|
+
`Method ${method} should be handled by RPC provider`
|
|
191
|
+
);
|
|
192
|
+
default:
|
|
193
|
+
throw new ProviderRpcError(
|
|
194
|
+
ErrorCode.UNSUPPORTED_METHOD,
|
|
195
|
+
`Method ${method} not supported`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Request accounts (EIP-1193)
|
|
201
|
+
*/
|
|
202
|
+
async eth_requestAccounts() {
|
|
203
|
+
if (!this.wallet) {
|
|
204
|
+
throw new ProviderRpcError(
|
|
205
|
+
ErrorCode.UNAUTHORIZED,
|
|
206
|
+
"Wallet not connected"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return [this.wallet.address];
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get accounts
|
|
213
|
+
*/
|
|
214
|
+
async eth_accounts() {
|
|
215
|
+
if (!this.wallet) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
return [this.wallet.address];
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get chain ID
|
|
222
|
+
*/
|
|
223
|
+
async eth_chainId() {
|
|
224
|
+
return numberToHex(this.chainId);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Send transaction
|
|
228
|
+
*/
|
|
229
|
+
async eth_sendTransaction(params) {
|
|
230
|
+
if (!this.wallet) {
|
|
231
|
+
throw new ProviderRpcError(
|
|
232
|
+
ErrorCode.UNAUTHORIZED,
|
|
233
|
+
"Wallet not connected"
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
237
|
+
throw new ProviderRpcError(
|
|
238
|
+
ErrorCode.INVALID_PARAMS,
|
|
239
|
+
"Invalid transaction params"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const resolved = await this.callInterceptor("eth_sendTransaction", params);
|
|
243
|
+
const tx = params[0];
|
|
244
|
+
if (resolved) {
|
|
245
|
+
if (resolved.data) {
|
|
246
|
+
tx.data = resolved.data;
|
|
247
|
+
}
|
|
248
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
249
|
+
try {
|
|
250
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
251
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.error(
|
|
254
|
+
"[AbcProvider] \u274C Failed to parse maxFeePerGas:",
|
|
255
|
+
error
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
260
|
+
try {
|
|
261
|
+
const priorityFeeWei = parseGwei(
|
|
262
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
263
|
+
);
|
|
264
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error(
|
|
267
|
+
"[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
|
|
268
|
+
error
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const isContractDeployment = !tx.to || tx.to === "0x" || tx.to === "0x0" || tx.to === "0x0000000000000000000000000000000000000000";
|
|
274
|
+
if (isContractDeployment) {
|
|
275
|
+
tx.to = "0x";
|
|
276
|
+
} else if (!tx.to) {
|
|
277
|
+
throw new ProviderRpcError(
|
|
278
|
+
ErrorCode.INVALID_PARAMS,
|
|
279
|
+
'Transaction must have "to" field'
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
283
|
+
if (!pinHash) {
|
|
284
|
+
throw new ProviderRpcError(
|
|
285
|
+
ErrorCode.INTERNAL_ERROR,
|
|
286
|
+
"PIN hash not found. Please login again."
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
const hexValue = tx.value || "0x0";
|
|
290
|
+
const amountWei = BigInt(hexValue).toString();
|
|
291
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
292
|
+
const result = await api.evm.sendTransaction({
|
|
293
|
+
chainKey: getChainKey(this.chainId),
|
|
294
|
+
toAddress: tx.to,
|
|
295
|
+
amountWei,
|
|
296
|
+
pin: pinHash,
|
|
297
|
+
data: tx.data || "0x",
|
|
298
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
299
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
300
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
301
|
+
});
|
|
302
|
+
return result.txHash;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Sign transaction (without sending)
|
|
306
|
+
*/
|
|
307
|
+
async eth_signTransaction(params) {
|
|
308
|
+
if (!this.wallet) {
|
|
309
|
+
throw new ProviderRpcError(
|
|
310
|
+
ErrorCode.UNAUTHORIZED,
|
|
311
|
+
"Wallet not connected"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
315
|
+
throw new ProviderRpcError(
|
|
316
|
+
ErrorCode.INVALID_PARAMS,
|
|
317
|
+
"Invalid transaction params"
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
const resolved = await this.callInterceptor("eth_signTransaction", params);
|
|
321
|
+
const tx = params[0];
|
|
322
|
+
if (resolved) {
|
|
323
|
+
if (resolved.data) {
|
|
324
|
+
tx.data = resolved.data;
|
|
325
|
+
}
|
|
326
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
327
|
+
try {
|
|
328
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
329
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
console.error(
|
|
332
|
+
"[AbcProvider] \u274C Failed to parse maxFeePerGas:",
|
|
333
|
+
error
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
338
|
+
try {
|
|
339
|
+
const priorityFeeWei = parseGwei(
|
|
340
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
341
|
+
);
|
|
342
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error(
|
|
345
|
+
"[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
|
|
346
|
+
error
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
352
|
+
const result = await api.evm.signTransaction({
|
|
353
|
+
network: getNetworkName(this.chainId),
|
|
354
|
+
to: tx.to,
|
|
355
|
+
value: tx.value || "0x0",
|
|
356
|
+
data: tx.data || "0x",
|
|
357
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
358
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
359
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
360
|
+
nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0
|
|
361
|
+
});
|
|
362
|
+
return result.signature;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Personal sign (EIP-191)
|
|
366
|
+
*/
|
|
367
|
+
async personal_sign(params) {
|
|
368
|
+
if (!this.wallet) {
|
|
369
|
+
console.error("[AbcProvider] \u274C Wallet not connected");
|
|
370
|
+
throw new ProviderRpcError(
|
|
371
|
+
ErrorCode.UNAUTHORIZED,
|
|
372
|
+
"Wallet not connected"
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
376
|
+
console.error("[AbcProvider] \u274C Invalid params:", params);
|
|
377
|
+
throw new ProviderRpcError(
|
|
378
|
+
ErrorCode.INVALID_PARAMS,
|
|
379
|
+
"Invalid personal_sign params"
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
await this.callInterceptor("personal_sign", params);
|
|
383
|
+
const [message, address] = params;
|
|
384
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
385
|
+
console.error("[AbcProvider] \u274C Address mismatch");
|
|
386
|
+
throw new ProviderRpcError(
|
|
387
|
+
ErrorCode.INVALID_PARAMS,
|
|
388
|
+
"Address does not match connected wallet"
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
392
|
+
const result = await api.evm.signPersonal({
|
|
393
|
+
network: getNetworkName(this.chainId),
|
|
394
|
+
message,
|
|
395
|
+
address: this.wallet.address
|
|
396
|
+
});
|
|
397
|
+
return result.signature;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Eth sign
|
|
401
|
+
*/
|
|
402
|
+
async eth_sign(params) {
|
|
403
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
404
|
+
throw new ProviderRpcError(
|
|
405
|
+
ErrorCode.INVALID_PARAMS,
|
|
406
|
+
"Invalid eth_sign params"
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
const [address, message] = params;
|
|
410
|
+
return this.personal_sign([message, address]);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Sign typed data (EIP-712)
|
|
414
|
+
*/
|
|
415
|
+
async eth_signTypedData(params) {
|
|
416
|
+
if (!this.wallet) {
|
|
417
|
+
throw new ProviderRpcError(
|
|
418
|
+
ErrorCode.UNAUTHORIZED,
|
|
419
|
+
"Wallet not connected"
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
423
|
+
throw new ProviderRpcError(
|
|
424
|
+
ErrorCode.INVALID_PARAMS,
|
|
425
|
+
"Invalid signTypedData params"
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
await this.callInterceptor("eth_signTypedData_v4", params);
|
|
429
|
+
const [address, typedData] = params;
|
|
430
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
431
|
+
throw new ProviderRpcError(
|
|
432
|
+
ErrorCode.INVALID_PARAMS,
|
|
433
|
+
"Address does not match connected wallet"
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
437
|
+
const network = getNetworkName(this.chainId);
|
|
438
|
+
const result = await api.evm.signTypedData({
|
|
439
|
+
network,
|
|
440
|
+
typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData)
|
|
441
|
+
});
|
|
442
|
+
return result.signature;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Switch Ethereum chain
|
|
446
|
+
*/
|
|
447
|
+
async wallet_switchEthereumChain(params) {
|
|
448
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
449
|
+
throw new ProviderRpcError(
|
|
450
|
+
ErrorCode.INVALID_PARAMS,
|
|
451
|
+
"Invalid switchEthereumChain params"
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
const { chainId } = params[0];
|
|
455
|
+
const newChainId = hexToNumber(chainId);
|
|
456
|
+
if (this.chainId === newChainId) {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
const _previousChainId = this.chainId;
|
|
460
|
+
this.chainId = newChainId;
|
|
461
|
+
if (this.wallet) {
|
|
462
|
+
this.wallet.chainId = newChainId;
|
|
463
|
+
}
|
|
464
|
+
this.emit("chainChanged", numberToHex(newChainId));
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Add Ethereum chain
|
|
469
|
+
*/
|
|
470
|
+
async wallet_addEthereumChain(params) {
|
|
471
|
+
return this.wallet_switchEthereumChain(params);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Get transaction count (nonce) using ABC WaaS API
|
|
475
|
+
*/
|
|
476
|
+
async eth_getTransactionCount(params) {
|
|
477
|
+
const address = params[0]?.toLowerCase();
|
|
478
|
+
if (!address) {
|
|
479
|
+
throw new ProviderRpcError(
|
|
480
|
+
ErrorCode.INVALID_PARAMS,
|
|
481
|
+
"Missing address parameter"
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
const currentChainId = this.chainId;
|
|
485
|
+
try {
|
|
486
|
+
const nonce = await this.client.getTransactionCount({
|
|
487
|
+
chainId: currentChainId,
|
|
488
|
+
address
|
|
489
|
+
});
|
|
490
|
+
return nonce;
|
|
491
|
+
} catch (error) {
|
|
492
|
+
console.error(
|
|
493
|
+
"[AbcEvmProvider] \u274C Failed to get transaction count from ABC WaaS:",
|
|
494
|
+
error
|
|
495
|
+
);
|
|
496
|
+
throw new ProviderRpcError(
|
|
497
|
+
ErrorCode.INTERNAL_ERROR,
|
|
498
|
+
`Failed to get transaction count: ${error instanceof Error ? error.message : String(error)}`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Estimate gas for transaction
|
|
504
|
+
* Uses ABC WaaS gas estimation API with fallback
|
|
505
|
+
*/
|
|
506
|
+
async eth_estimateGas(params) {
|
|
507
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
508
|
+
throw new ProviderRpcError(
|
|
509
|
+
ErrorCode.INVALID_PARAMS,
|
|
510
|
+
"Invalid estimateGas params"
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
const tx = params[0];
|
|
514
|
+
if (!tx.to) {
|
|
515
|
+
throw new ProviderRpcError(
|
|
516
|
+
ErrorCode.INVALID_PARAMS,
|
|
517
|
+
'Transaction must have "to" field'
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const gasLimit = await this.client.estimateGas({
|
|
522
|
+
chainId: this.chainId,
|
|
523
|
+
from: tx.from || this.wallet?.address,
|
|
524
|
+
to: tx.to,
|
|
525
|
+
value: tx.value,
|
|
526
|
+
data: tx.data
|
|
527
|
+
});
|
|
528
|
+
return gasLimit;
|
|
529
|
+
} catch (error) {
|
|
530
|
+
console.warn(
|
|
531
|
+
"[AbcEvmProvider] Gas estimation failed, using fallback:",
|
|
532
|
+
error
|
|
533
|
+
);
|
|
534
|
+
if (tx.data && tx.data !== "0x") {
|
|
535
|
+
return "0x493e0";
|
|
536
|
+
}
|
|
537
|
+
return "0x5208";
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Check if connected
|
|
542
|
+
*/
|
|
543
|
+
isConnected() {
|
|
544
|
+
return this.connected;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get current wallet
|
|
548
|
+
*/
|
|
549
|
+
getWallet() {
|
|
550
|
+
return this.wallet;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Get current chain ID
|
|
554
|
+
*/
|
|
555
|
+
getChainId() {
|
|
556
|
+
return this.chainId;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
function createAbcEvmProvider(client, talkenApi) {
|
|
560
|
+
const provider = new AbcEvmProvider(client);
|
|
561
|
+
if (talkenApi) {
|
|
562
|
+
provider.setTalkenApi(talkenApi);
|
|
563
|
+
}
|
|
564
|
+
return provider;
|
|
565
|
+
}
|
|
566
|
+
var createAbcProvider = createAbcEvmProvider;
|
|
567
|
+
|
|
568
|
+
export {
|
|
569
|
+
AbcEvmProvider,
|
|
570
|
+
createAbcEvmProvider,
|
|
571
|
+
createAbcProvider
|
|
572
|
+
};
|