@talken/talkenkit 2.7.5-beta.4 → 2.7.5-beta.5
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-WR2MVEWD.js +184 -0
- package/dist/chunk-5LXELITG.js +7875 -0
- package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +1 -1
- package/dist/index.js +93 -39
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +8 -8
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +8 -8
- package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/index.js +13 -13
- package/dist/wallets/walletConnectors/abcWallet/types.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/utils.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +1 -1
- 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-AK7AES7Q.js +58 -0
- package/dist/wallets/walletConnectors/chunk-GBARK6FR.js +341 -0
- package/dist/wallets/walletConnectors/chunk-NTZTRAVC.js +3053 -0
- package/dist/wallets/walletConnectors/chunk-UDOKYIOD.js +370 -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 +78 -78
- 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/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 +1 -1
|
@@ -0,0 +1,3053 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
hexToNumber,
|
|
4
|
+
numberToHex
|
|
5
|
+
} from "./chunk-VVXSRRXI.js";
|
|
6
|
+
import {
|
|
7
|
+
AbstractChainProvider
|
|
8
|
+
} from "./chunk-TLRR3FFT.js";
|
|
9
|
+
import {
|
|
10
|
+
ProviderErrorCode,
|
|
11
|
+
ProviderRpcError
|
|
12
|
+
} from "./chunk-YXWHHI4S.js";
|
|
13
|
+
import {
|
|
14
|
+
getTalkenApiClient
|
|
15
|
+
} from "./chunk-R6ZE7JAZ.js";
|
|
16
|
+
import {
|
|
17
|
+
createLogger
|
|
18
|
+
} from "./chunk-762I67R6.js";
|
|
19
|
+
import {
|
|
20
|
+
getCredentialManager
|
|
21
|
+
} from "./chunk-YNE2UX2Z.js";
|
|
22
|
+
import {
|
|
23
|
+
TalkenApiError
|
|
24
|
+
} from "./chunk-BUAWEYGV.js";
|
|
25
|
+
import {
|
|
26
|
+
TALKEN_API_ENDPOINTS
|
|
27
|
+
} from "./chunk-3Z5DO42M.js";
|
|
28
|
+
|
|
29
|
+
// src/wallets/walletConnectors/abcWallet/abcProvider.ts
|
|
30
|
+
import { parseGwei } from "viem";
|
|
31
|
+
|
|
32
|
+
// src/config/networks.ts
|
|
33
|
+
var NETWORK_CONFIGS = {
|
|
34
|
+
// Ethereum Mainnet
|
|
35
|
+
1: {
|
|
36
|
+
chainId: 1,
|
|
37
|
+
network: "ethereum",
|
|
38
|
+
name: "Ethereum",
|
|
39
|
+
type: "EVM" /* EVM */,
|
|
40
|
+
isTestnet: false,
|
|
41
|
+
explorer: "https://etherscan.io",
|
|
42
|
+
website: "https://ethereum.org",
|
|
43
|
+
nativeCurrency: {
|
|
44
|
+
name: "Ether",
|
|
45
|
+
symbol: "ETH",
|
|
46
|
+
decimals: 18
|
|
47
|
+
},
|
|
48
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
49
|
+
signSupport: { legacy: true, eip1559: true }
|
|
50
|
+
},
|
|
51
|
+
// Ethereum Sepolia Testnet
|
|
52
|
+
11155111: {
|
|
53
|
+
chainId: 11155111,
|
|
54
|
+
network: "ethereum_sepolia",
|
|
55
|
+
name: "Ethereum Sepolia",
|
|
56
|
+
type: "EVM" /* EVM */,
|
|
57
|
+
isTestnet: true,
|
|
58
|
+
explorer: "https://sepolia.etherscan.io",
|
|
59
|
+
website: "https://ethereum.org",
|
|
60
|
+
nativeCurrency: {
|
|
61
|
+
name: "Sepolia Ether",
|
|
62
|
+
symbol: "ETH",
|
|
63
|
+
decimals: 18
|
|
64
|
+
},
|
|
65
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
66
|
+
signSupport: { legacy: true, eip1559: true }
|
|
67
|
+
},
|
|
68
|
+
// Ethereum Holesky Testnet
|
|
69
|
+
17e3: {
|
|
70
|
+
chainId: 17e3,
|
|
71
|
+
network: "ethereum_holesky",
|
|
72
|
+
name: "Ethereum Holesky",
|
|
73
|
+
type: "EVM" /* EVM */,
|
|
74
|
+
isTestnet: true,
|
|
75
|
+
explorer: "https://holesky.etherscan.io",
|
|
76
|
+
website: "https://ethereum.org",
|
|
77
|
+
nativeCurrency: {
|
|
78
|
+
name: "Holesky Ether",
|
|
79
|
+
symbol: "ETH",
|
|
80
|
+
decimals: 18
|
|
81
|
+
},
|
|
82
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
83
|
+
signSupport: { legacy: true, eip1559: true }
|
|
84
|
+
},
|
|
85
|
+
// Kaia Mainnet (formerly Klaytn)
|
|
86
|
+
8217: {
|
|
87
|
+
chainId: 8217,
|
|
88
|
+
network: "kaia",
|
|
89
|
+
name: "Kaia Mainnet",
|
|
90
|
+
type: "EVM" /* EVM */,
|
|
91
|
+
isTestnet: false,
|
|
92
|
+
explorer: "https://kaiascan.io",
|
|
93
|
+
website: "https://kaia.io",
|
|
94
|
+
nativeCurrency: {
|
|
95
|
+
name: "Kaia",
|
|
96
|
+
symbol: "KAIA",
|
|
97
|
+
decimals: 18
|
|
98
|
+
},
|
|
99
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
100
|
+
signSupport: { legacy: true, eip1559: true }
|
|
101
|
+
},
|
|
102
|
+
// Kaia Kairos Testnet
|
|
103
|
+
1001: {
|
|
104
|
+
chainId: 1001,
|
|
105
|
+
network: "kaia_kairos",
|
|
106
|
+
name: "Kaia Kairos Testnet",
|
|
107
|
+
type: "EVM" /* EVM */,
|
|
108
|
+
isTestnet: true,
|
|
109
|
+
explorer: "https://kairos.kaiascan.io",
|
|
110
|
+
website: "https://kaia.io",
|
|
111
|
+
nativeCurrency: {
|
|
112
|
+
name: "Kaia",
|
|
113
|
+
symbol: "KAIA",
|
|
114
|
+
decimals: 18
|
|
115
|
+
},
|
|
116
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
117
|
+
signSupport: { legacy: true, eip1559: true }
|
|
118
|
+
},
|
|
119
|
+
// Polygon Mainnet
|
|
120
|
+
137: {
|
|
121
|
+
chainId: 137,
|
|
122
|
+
network: "polygon",
|
|
123
|
+
name: "Polygon",
|
|
124
|
+
type: "EVM" /* EVM */,
|
|
125
|
+
isTestnet: false,
|
|
126
|
+
explorer: "https://polygonscan.com",
|
|
127
|
+
website: "https://polygon.technology",
|
|
128
|
+
nativeCurrency: {
|
|
129
|
+
name: "MATIC",
|
|
130
|
+
symbol: "MATIC",
|
|
131
|
+
decimals: 18
|
|
132
|
+
},
|
|
133
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
134
|
+
signSupport: { legacy: true, eip1559: true }
|
|
135
|
+
},
|
|
136
|
+
// Polygon Amoy Testnet
|
|
137
|
+
80002: {
|
|
138
|
+
chainId: 80002,
|
|
139
|
+
network: "polygon_amoy",
|
|
140
|
+
name: "Polygon Amoy Testnet",
|
|
141
|
+
type: "EVM" /* EVM */,
|
|
142
|
+
isTestnet: true,
|
|
143
|
+
explorer: "https://amoy.polygonscan.com",
|
|
144
|
+
website: "https://polygon.technology",
|
|
145
|
+
nativeCurrency: {
|
|
146
|
+
name: "MATIC",
|
|
147
|
+
symbol: "MATIC",
|
|
148
|
+
decimals: 18
|
|
149
|
+
},
|
|
150
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
151
|
+
signSupport: { legacy: true, eip1559: true }
|
|
152
|
+
},
|
|
153
|
+
// Binance Smart Chain Mainnet
|
|
154
|
+
56: {
|
|
155
|
+
chainId: 56,
|
|
156
|
+
network: "binance",
|
|
157
|
+
name: "Binance Smart Chain Mainnet",
|
|
158
|
+
type: "EVM" /* EVM */,
|
|
159
|
+
isTestnet: false,
|
|
160
|
+
explorer: "https://bscscan.com",
|
|
161
|
+
website: "https://www.bnbchain.org/en/bnb-smart-chain",
|
|
162
|
+
nativeCurrency: {
|
|
163
|
+
name: "BNB",
|
|
164
|
+
symbol: "BNB",
|
|
165
|
+
decimals: 18
|
|
166
|
+
},
|
|
167
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
168
|
+
signSupport: { legacy: true, eip1559: true }
|
|
169
|
+
},
|
|
170
|
+
// Binance Smart Chain Testnet
|
|
171
|
+
97: {
|
|
172
|
+
chainId: 97,
|
|
173
|
+
network: "binance_testnet",
|
|
174
|
+
name: "Binance Smart Chain Testnet",
|
|
175
|
+
type: "EVM" /* EVM */,
|
|
176
|
+
isTestnet: true,
|
|
177
|
+
explorer: "https://testnet.bscscan.com",
|
|
178
|
+
website: "https://www.bnbchain.org/en/bnb-smart-chain",
|
|
179
|
+
nativeCurrency: {
|
|
180
|
+
name: "BNB",
|
|
181
|
+
symbol: "BNB",
|
|
182
|
+
decimals: 18
|
|
183
|
+
},
|
|
184
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
185
|
+
signSupport: { legacy: true, eip1559: true }
|
|
186
|
+
},
|
|
187
|
+
// Arbitrum One
|
|
188
|
+
42161: {
|
|
189
|
+
chainId: 42161,
|
|
190
|
+
network: "arbitrum",
|
|
191
|
+
name: "Arbitrum One",
|
|
192
|
+
type: "EVM" /* EVM */,
|
|
193
|
+
isTestnet: false,
|
|
194
|
+
explorer: "https://arbiscan.io",
|
|
195
|
+
website: "https://arbitrum.io",
|
|
196
|
+
nativeCurrency: {
|
|
197
|
+
name: "Ether",
|
|
198
|
+
symbol: "ETH",
|
|
199
|
+
decimals: 18
|
|
200
|
+
},
|
|
201
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
202
|
+
signSupport: { legacy: true, eip1559: true }
|
|
203
|
+
},
|
|
204
|
+
// Arbitrum Sepolia
|
|
205
|
+
421614: {
|
|
206
|
+
chainId: 421614,
|
|
207
|
+
network: "arbitrum_sepolia",
|
|
208
|
+
name: "Arbitrum Sepolia",
|
|
209
|
+
type: "EVM" /* EVM */,
|
|
210
|
+
isTestnet: true,
|
|
211
|
+
explorer: "https://sepolia.arbiscan.io",
|
|
212
|
+
website: "https://arbitrum.io",
|
|
213
|
+
nativeCurrency: {
|
|
214
|
+
name: "Ether",
|
|
215
|
+
symbol: "ETH",
|
|
216
|
+
decimals: 18
|
|
217
|
+
},
|
|
218
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
219
|
+
signSupport: { legacy: true, eip1559: true }
|
|
220
|
+
},
|
|
221
|
+
// Optimism Mainnet
|
|
222
|
+
10: {
|
|
223
|
+
chainId: 10,
|
|
224
|
+
network: "optimism",
|
|
225
|
+
name: "Optimism",
|
|
226
|
+
type: "EVM" /* EVM */,
|
|
227
|
+
isTestnet: false,
|
|
228
|
+
explorer: "https://optimistic.etherscan.io",
|
|
229
|
+
website: "https://optimism.io",
|
|
230
|
+
nativeCurrency: {
|
|
231
|
+
name: "Ether",
|
|
232
|
+
symbol: "ETH",
|
|
233
|
+
decimals: 18
|
|
234
|
+
},
|
|
235
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
236
|
+
signSupport: { legacy: true, eip1559: true }
|
|
237
|
+
},
|
|
238
|
+
// Optimism Sepolia
|
|
239
|
+
420: {
|
|
240
|
+
chainId: 420,
|
|
241
|
+
network: "optimism_sepolia",
|
|
242
|
+
name: "Optimism Sepolia",
|
|
243
|
+
type: "EVM" /* EVM */,
|
|
244
|
+
isTestnet: true,
|
|
245
|
+
explorer: "https://sepolia-optimism.etherscan.io",
|
|
246
|
+
website: "https://optimism.io",
|
|
247
|
+
nativeCurrency: {
|
|
248
|
+
name: "Ether",
|
|
249
|
+
symbol: "ETH",
|
|
250
|
+
decimals: 18
|
|
251
|
+
},
|
|
252
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
253
|
+
signSupport: { legacy: true, eip1559: true }
|
|
254
|
+
},
|
|
255
|
+
// Avalanche C-Chain
|
|
256
|
+
43114: {
|
|
257
|
+
chainId: 43114,
|
|
258
|
+
network: "avalanche",
|
|
259
|
+
name: "Avalanche C-Chain",
|
|
260
|
+
type: "EVM" /* EVM */,
|
|
261
|
+
isTestnet: false,
|
|
262
|
+
explorer: "https://avascan.info/blockchain/c/home",
|
|
263
|
+
website: "https://avax.network",
|
|
264
|
+
nativeCurrency: {
|
|
265
|
+
name: "Avalanche",
|
|
266
|
+
symbol: "AVAX",
|
|
267
|
+
decimals: 18
|
|
268
|
+
},
|
|
269
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
270
|
+
signSupport: { legacy: true, eip1559: true }
|
|
271
|
+
},
|
|
272
|
+
// Avalanche Fuji Testnet
|
|
273
|
+
43113: {
|
|
274
|
+
chainId: 43113,
|
|
275
|
+
network: "avalanche_fuji",
|
|
276
|
+
name: "Avalanche Fuji Testnet",
|
|
277
|
+
type: "EVM" /* EVM */,
|
|
278
|
+
isTestnet: true,
|
|
279
|
+
explorer: "https://testnet.avascan.info",
|
|
280
|
+
website: "https://avax.network",
|
|
281
|
+
nativeCurrency: {
|
|
282
|
+
name: "Avalanche",
|
|
283
|
+
symbol: "AVAX",
|
|
284
|
+
decimals: 18
|
|
285
|
+
},
|
|
286
|
+
apiSupport: { tokens: false, nft: false, transactions: false },
|
|
287
|
+
signSupport: { legacy: true, eip1559: true }
|
|
288
|
+
},
|
|
289
|
+
// Mantle Mainnet
|
|
290
|
+
5e3: {
|
|
291
|
+
chainId: 5e3,
|
|
292
|
+
network: "mantle",
|
|
293
|
+
name: "Mantle Mainnet",
|
|
294
|
+
type: "EVM" /* EVM */,
|
|
295
|
+
isTestnet: false,
|
|
296
|
+
explorer: "https://explorer.mantle.xyz",
|
|
297
|
+
website: "https://www.mantle.xyz",
|
|
298
|
+
nativeCurrency: {
|
|
299
|
+
name: "Mantle",
|
|
300
|
+
symbol: "MNT",
|
|
301
|
+
decimals: 18
|
|
302
|
+
},
|
|
303
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
304
|
+
signSupport: { legacy: true, eip1559: true }
|
|
305
|
+
},
|
|
306
|
+
// Mantle Testnet
|
|
307
|
+
5001: {
|
|
308
|
+
chainId: 5001,
|
|
309
|
+
network: "mantle_testnet",
|
|
310
|
+
name: "Mantle Testnet",
|
|
311
|
+
type: "EVM" /* EVM */,
|
|
312
|
+
isTestnet: true,
|
|
313
|
+
explorer: "https://sepolia.mantlescan.xyz",
|
|
314
|
+
website: "https://www.mantle.xyz",
|
|
315
|
+
nativeCurrency: {
|
|
316
|
+
name: "Mantle",
|
|
317
|
+
symbol: "MNT",
|
|
318
|
+
decimals: 18
|
|
319
|
+
},
|
|
320
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
321
|
+
signSupport: { legacy: true, eip1559: true }
|
|
322
|
+
},
|
|
323
|
+
// Moonbeam
|
|
324
|
+
1284: {
|
|
325
|
+
chainId: 1284,
|
|
326
|
+
network: "moonbeam",
|
|
327
|
+
name: "Moonbeam",
|
|
328
|
+
type: "EVM" /* EVM */,
|
|
329
|
+
isTestnet: false,
|
|
330
|
+
explorer: "https://moonbeam.moonscan.io",
|
|
331
|
+
website: "https://moonbeam.network",
|
|
332
|
+
nativeCurrency: {
|
|
333
|
+
name: "Glimmer",
|
|
334
|
+
symbol: "GLMR",
|
|
335
|
+
decimals: 18
|
|
336
|
+
},
|
|
337
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
338
|
+
signSupport: { legacy: true, eip1559: true }
|
|
339
|
+
},
|
|
340
|
+
// Moonriver
|
|
341
|
+
1285: {
|
|
342
|
+
chainId: 1285,
|
|
343
|
+
network: "moonriver",
|
|
344
|
+
name: "Moonriver",
|
|
345
|
+
type: "EVM" /* EVM */,
|
|
346
|
+
isTestnet: false,
|
|
347
|
+
explorer: "https://moonriver.moonscan.io",
|
|
348
|
+
website: "https://moonbeam.network/networks/moonriver",
|
|
349
|
+
nativeCurrency: {
|
|
350
|
+
name: "Moonriver",
|
|
351
|
+
symbol: "MOVR",
|
|
352
|
+
decimals: 18
|
|
353
|
+
},
|
|
354
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
355
|
+
signSupport: { legacy: true, eip1559: true }
|
|
356
|
+
},
|
|
357
|
+
// Scroll Mainnet
|
|
358
|
+
534352: {
|
|
359
|
+
chainId: 534352,
|
|
360
|
+
network: "scroll",
|
|
361
|
+
name: "Scroll",
|
|
362
|
+
type: "EVM" /* EVM */,
|
|
363
|
+
isTestnet: false,
|
|
364
|
+
explorer: "https://scrollscan.co",
|
|
365
|
+
website: "https://scroll.io",
|
|
366
|
+
nativeCurrency: {
|
|
367
|
+
name: "Ether",
|
|
368
|
+
symbol: "ETH",
|
|
369
|
+
decimals: 18
|
|
370
|
+
},
|
|
371
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
372
|
+
signSupport: { legacy: true, eip1559: true }
|
|
373
|
+
},
|
|
374
|
+
// Scroll Testnet
|
|
375
|
+
534351: {
|
|
376
|
+
chainId: 534351,
|
|
377
|
+
network: "scroll_testnet",
|
|
378
|
+
name: "Scroll Testnet",
|
|
379
|
+
type: "EVM" /* EVM */,
|
|
380
|
+
isTestnet: true,
|
|
381
|
+
explorer: "https://sepolia.scrollscan.com",
|
|
382
|
+
website: "https://scroll.io",
|
|
383
|
+
nativeCurrency: {
|
|
384
|
+
name: "Ether",
|
|
385
|
+
symbol: "ETH",
|
|
386
|
+
decimals: 18
|
|
387
|
+
},
|
|
388
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
389
|
+
signSupport: { legacy: true, eip1559: true }
|
|
390
|
+
},
|
|
391
|
+
// Silicon Mainnet
|
|
392
|
+
2355: {
|
|
393
|
+
chainId: 2355,
|
|
394
|
+
network: "silicon",
|
|
395
|
+
name: "Silicon",
|
|
396
|
+
type: "EVM" /* EVM */,
|
|
397
|
+
isTestnet: false,
|
|
398
|
+
explorer: "https://scope.silicon.network",
|
|
399
|
+
website: "https://silicon.network",
|
|
400
|
+
nativeCurrency: {
|
|
401
|
+
name: "Ether",
|
|
402
|
+
symbol: "ETH",
|
|
403
|
+
decimals: 18
|
|
404
|
+
},
|
|
405
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
406
|
+
signSupport: { legacy: true, eip1559: true }
|
|
407
|
+
},
|
|
408
|
+
// Silicon Sepolia
|
|
409
|
+
1722641160: {
|
|
410
|
+
chainId: 1722641160,
|
|
411
|
+
network: "silicon_sepolia",
|
|
412
|
+
name: "Silicon Sepolia",
|
|
413
|
+
type: "EVM" /* EVM */,
|
|
414
|
+
isTestnet: true,
|
|
415
|
+
explorer: "https://scope-sepolia.silicon.network",
|
|
416
|
+
website: "https://silicon.network",
|
|
417
|
+
nativeCurrency: {
|
|
418
|
+
name: "Ether",
|
|
419
|
+
symbol: "ETH",
|
|
420
|
+
decimals: 18
|
|
421
|
+
},
|
|
422
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
423
|
+
signSupport: { legacy: true, eip1559: true }
|
|
424
|
+
},
|
|
425
|
+
// Six Protocol
|
|
426
|
+
98: {
|
|
427
|
+
chainId: 98,
|
|
428
|
+
network: "six_evm",
|
|
429
|
+
name: "Six Protocol",
|
|
430
|
+
type: "EVM" /* EVM */,
|
|
431
|
+
isTestnet: false,
|
|
432
|
+
explorer: "https://v2.sixscan.io",
|
|
433
|
+
website: "https://www.six.network",
|
|
434
|
+
nativeCurrency: {
|
|
435
|
+
name: "SIX",
|
|
436
|
+
symbol: "SIX",
|
|
437
|
+
decimals: 18
|
|
438
|
+
},
|
|
439
|
+
apiSupport: { tokens: true, nft: false, transactions: true },
|
|
440
|
+
signSupport: { legacy: true, eip1559: false }
|
|
441
|
+
},
|
|
442
|
+
// Six Protocol Testnet
|
|
443
|
+
150: {
|
|
444
|
+
chainId: 150,
|
|
445
|
+
network: "six_evm_testnet",
|
|
446
|
+
name: "Six Protocol Testnet",
|
|
447
|
+
type: "EVM" /* EVM */,
|
|
448
|
+
isTestnet: true,
|
|
449
|
+
explorer: "https://v2.fivenet.sixscan.io",
|
|
450
|
+
website: "https://www.six.network",
|
|
451
|
+
nativeCurrency: {
|
|
452
|
+
name: "SIX",
|
|
453
|
+
symbol: "SIX",
|
|
454
|
+
decimals: 18
|
|
455
|
+
},
|
|
456
|
+
apiSupport: { tokens: true, nft: false, transactions: true },
|
|
457
|
+
signSupport: { legacy: true, eip1559: false }
|
|
458
|
+
},
|
|
459
|
+
// Wemix Mainnet
|
|
460
|
+
1111: {
|
|
461
|
+
chainId: 1111,
|
|
462
|
+
network: "wemix",
|
|
463
|
+
name: "Wemix3.0 Mainnet",
|
|
464
|
+
type: "EVM" /* EVM */,
|
|
465
|
+
isTestnet: false,
|
|
466
|
+
explorer: "https://explorer.wemix.com",
|
|
467
|
+
website: "https://wemix.com",
|
|
468
|
+
nativeCurrency: {
|
|
469
|
+
name: "WEMIX",
|
|
470
|
+
symbol: "WEMIX",
|
|
471
|
+
decimals: 18
|
|
472
|
+
},
|
|
473
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
474
|
+
signSupport: { legacy: true, eip1559: true }
|
|
475
|
+
},
|
|
476
|
+
// Wemix Testnet
|
|
477
|
+
1112: {
|
|
478
|
+
chainId: 1112,
|
|
479
|
+
network: "wemix_testnet",
|
|
480
|
+
name: "Wemix3.0 Testnet",
|
|
481
|
+
type: "EVM" /* EVM */,
|
|
482
|
+
isTestnet: true,
|
|
483
|
+
explorer: "https://explorer.test.wemix.com",
|
|
484
|
+
website: "https://wemix.com",
|
|
485
|
+
nativeCurrency: {
|
|
486
|
+
name: "WEMIX",
|
|
487
|
+
symbol: "WEMIX",
|
|
488
|
+
decimals: 18
|
|
489
|
+
},
|
|
490
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
491
|
+
signSupport: { legacy: true, eip1559: true }
|
|
492
|
+
},
|
|
493
|
+
// Taiko Mainnet
|
|
494
|
+
167e3: {
|
|
495
|
+
chainId: 167e3,
|
|
496
|
+
network: "taiko",
|
|
497
|
+
name: "Taiko Mainnet",
|
|
498
|
+
type: "EVM" /* EVM */,
|
|
499
|
+
isTestnet: false,
|
|
500
|
+
explorer: "https://taikoscan.io",
|
|
501
|
+
website: "https://taiko.xyz",
|
|
502
|
+
nativeCurrency: {
|
|
503
|
+
name: "Ether",
|
|
504
|
+
symbol: "ETH",
|
|
505
|
+
decimals: 18
|
|
506
|
+
},
|
|
507
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
508
|
+
signSupport: { legacy: true, eip1559: true }
|
|
509
|
+
},
|
|
510
|
+
// Taiko Hekla Testnet
|
|
511
|
+
167009: {
|
|
512
|
+
chainId: 167009,
|
|
513
|
+
network: "taiko_hekla",
|
|
514
|
+
name: "Taiko Hekla Testnet",
|
|
515
|
+
type: "EVM" /* EVM */,
|
|
516
|
+
isTestnet: true,
|
|
517
|
+
explorer: "https://hekla.taikoscan.io",
|
|
518
|
+
website: "https://taiko.xyz",
|
|
519
|
+
nativeCurrency: {
|
|
520
|
+
name: "Ether",
|
|
521
|
+
symbol: "ETH",
|
|
522
|
+
decimals: 18
|
|
523
|
+
},
|
|
524
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
525
|
+
signSupport: { legacy: true, eip1559: true }
|
|
526
|
+
},
|
|
527
|
+
// Base Mainnet
|
|
528
|
+
8453: {
|
|
529
|
+
chainId: 8453,
|
|
530
|
+
network: "base",
|
|
531
|
+
name: "Base",
|
|
532
|
+
type: "EVM" /* EVM */,
|
|
533
|
+
isTestnet: false,
|
|
534
|
+
explorer: "https://basescan.org",
|
|
535
|
+
website: "https://base.org",
|
|
536
|
+
nativeCurrency: {
|
|
537
|
+
name: "Ether",
|
|
538
|
+
symbol: "ETH",
|
|
539
|
+
decimals: 18
|
|
540
|
+
},
|
|
541
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
542
|
+
signSupport: { legacy: true, eip1559: true }
|
|
543
|
+
},
|
|
544
|
+
// Base Sepolia Testnet
|
|
545
|
+
84532: {
|
|
546
|
+
chainId: 84532,
|
|
547
|
+
network: "base_sepolia",
|
|
548
|
+
name: "Base Sepolia",
|
|
549
|
+
type: "EVM" /* EVM */,
|
|
550
|
+
isTestnet: true,
|
|
551
|
+
explorer: "https://sepolia.basescan.org",
|
|
552
|
+
website: "https://base.org",
|
|
553
|
+
nativeCurrency: {
|
|
554
|
+
name: "Ether",
|
|
555
|
+
symbol: "ETH",
|
|
556
|
+
decimals: 18
|
|
557
|
+
},
|
|
558
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
559
|
+
signSupport: { legacy: true, eip1559: true }
|
|
560
|
+
},
|
|
561
|
+
// ChainBounty Mainnet
|
|
562
|
+
51828: {
|
|
563
|
+
chainId: 51828,
|
|
564
|
+
network: "chainbounty",
|
|
565
|
+
name: "ChainBounty Mainnet",
|
|
566
|
+
type: "EVM" /* EVM */,
|
|
567
|
+
isTestnet: false,
|
|
568
|
+
explorer: "https://scan.chainbounty.io",
|
|
569
|
+
website: "https://chainbounty.io",
|
|
570
|
+
nativeCurrency: {
|
|
571
|
+
name: "ChainBounty",
|
|
572
|
+
symbol: "CBY",
|
|
573
|
+
decimals: 18
|
|
574
|
+
},
|
|
575
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
576
|
+
signSupport: { legacy: true, eip1559: true }
|
|
577
|
+
},
|
|
578
|
+
// ChainBounty Testnet
|
|
579
|
+
56580: {
|
|
580
|
+
chainId: 56580,
|
|
581
|
+
network: "chainbounty_testnet",
|
|
582
|
+
name: "ChainBounty Testnet",
|
|
583
|
+
type: "EVM" /* EVM */,
|
|
584
|
+
isTestnet: true,
|
|
585
|
+
explorer: "https://test.scan.chainbounty.io",
|
|
586
|
+
website: "https://chainbounty.io",
|
|
587
|
+
nativeCurrency: {
|
|
588
|
+
name: "ChainBounty",
|
|
589
|
+
symbol: "CBY",
|
|
590
|
+
decimals: 18
|
|
591
|
+
},
|
|
592
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
593
|
+
signSupport: { legacy: true, eip1559: true }
|
|
594
|
+
},
|
|
595
|
+
// Aptos Mainnet (Non-EVM)
|
|
596
|
+
aptos: {
|
|
597
|
+
chainId: null,
|
|
598
|
+
network: "aptos",
|
|
599
|
+
name: "Aptos",
|
|
600
|
+
type: "Non-EVM" /* NON_EVM */,
|
|
601
|
+
isTestnet: false,
|
|
602
|
+
explorer: "https://explorer.aptoslabs.com/?network=mainnet",
|
|
603
|
+
website: "https://aptos.dev",
|
|
604
|
+
nativeCurrency: {
|
|
605
|
+
name: "Aptos",
|
|
606
|
+
symbol: "APT",
|
|
607
|
+
decimals: 8
|
|
608
|
+
},
|
|
609
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
610
|
+
signSupport: { legacy: true, eip1559: false }
|
|
611
|
+
},
|
|
612
|
+
// Aptos Testnet (Non-EVM)
|
|
613
|
+
aptos_testnet: {
|
|
614
|
+
chainId: null,
|
|
615
|
+
network: "aptos_testnet",
|
|
616
|
+
name: "Aptos Testnet",
|
|
617
|
+
type: "Non-EVM" /* NON_EVM */,
|
|
618
|
+
isTestnet: true,
|
|
619
|
+
explorer: "https://explorer.aptoslabs.com/?network=testnet",
|
|
620
|
+
website: "https://aptos.dev",
|
|
621
|
+
nativeCurrency: {
|
|
622
|
+
name: "Aptos",
|
|
623
|
+
symbol: "APT",
|
|
624
|
+
decimals: 8
|
|
625
|
+
},
|
|
626
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
627
|
+
signSupport: { legacy: true, eip1559: false }
|
|
628
|
+
},
|
|
629
|
+
// Bitcoin Mainnet
|
|
630
|
+
bitcoin: {
|
|
631
|
+
chainId: null,
|
|
632
|
+
network: "bitcoin",
|
|
633
|
+
name: "Bitcoin Mainnet",
|
|
634
|
+
type: "Bitcoin" /* BITCOIN */,
|
|
635
|
+
isTestnet: false,
|
|
636
|
+
explorer: "https://blockstream.info",
|
|
637
|
+
website: "https://bitcoin.org",
|
|
638
|
+
nativeCurrency: {
|
|
639
|
+
name: "Bitcoin",
|
|
640
|
+
symbol: "BTC",
|
|
641
|
+
decimals: 8
|
|
642
|
+
},
|
|
643
|
+
apiSupport: { tokens: true, nft: false, transactions: true },
|
|
644
|
+
signSupport: { legacy: true, eip1559: false }
|
|
645
|
+
},
|
|
646
|
+
// Bitcoin Testnet
|
|
647
|
+
bitcoin_testnet: {
|
|
648
|
+
chainId: null,
|
|
649
|
+
network: "bitcoin_testnet",
|
|
650
|
+
name: "Bitcoin Testnet",
|
|
651
|
+
type: "Bitcoin" /* BITCOIN */,
|
|
652
|
+
isTestnet: true,
|
|
653
|
+
explorer: "https://blockstream.info/testnet",
|
|
654
|
+
website: "https://bitcoin.org",
|
|
655
|
+
nativeCurrency: {
|
|
656
|
+
name: "Bitcoin",
|
|
657
|
+
symbol: "BTC",
|
|
658
|
+
decimals: 8
|
|
659
|
+
},
|
|
660
|
+
apiSupport: { tokens: true, nft: false, transactions: true },
|
|
661
|
+
signSupport: { legacy: true, eip1559: false }
|
|
662
|
+
},
|
|
663
|
+
// Tron Mainnet
|
|
664
|
+
tron: {
|
|
665
|
+
chainId: null,
|
|
666
|
+
network: "tron",
|
|
667
|
+
name: "Tron Mainnet",
|
|
668
|
+
type: "TRX" /* TRON */,
|
|
669
|
+
isTestnet: false,
|
|
670
|
+
explorer: "https://tronscan.org",
|
|
671
|
+
website: "https://tron.network",
|
|
672
|
+
nativeCurrency: {
|
|
673
|
+
name: "Tronix",
|
|
674
|
+
symbol: "TRX",
|
|
675
|
+
decimals: 6
|
|
676
|
+
},
|
|
677
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
678
|
+
signSupport: { legacy: true, eip1559: true }
|
|
679
|
+
},
|
|
680
|
+
// Tron Nile Testnet
|
|
681
|
+
tron_nile: {
|
|
682
|
+
chainId: null,
|
|
683
|
+
network: "tron_nile",
|
|
684
|
+
name: "Tron Nile Testnet",
|
|
685
|
+
type: "TRX" /* TRON */,
|
|
686
|
+
isTestnet: true,
|
|
687
|
+
explorer: "https://nile.tronscan.org",
|
|
688
|
+
website: "https://tron.network",
|
|
689
|
+
nativeCurrency: {
|
|
690
|
+
name: "Tronix",
|
|
691
|
+
symbol: "TRX",
|
|
692
|
+
decimals: 6
|
|
693
|
+
},
|
|
694
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
695
|
+
signSupport: { legacy: true, eip1559: true }
|
|
696
|
+
},
|
|
697
|
+
// ICP Mainnet
|
|
698
|
+
icp: {
|
|
699
|
+
chainId: null,
|
|
700
|
+
network: "icp",
|
|
701
|
+
name: "Internet Computer",
|
|
702
|
+
type: "ICP" /* ICP */,
|
|
703
|
+
isTestnet: false,
|
|
704
|
+
explorer: "https://dashboard.internetcomputer.org",
|
|
705
|
+
website: "https://internetcomputer.org",
|
|
706
|
+
nativeCurrency: {
|
|
707
|
+
name: "ICP",
|
|
708
|
+
symbol: "ICP",
|
|
709
|
+
decimals: 8
|
|
710
|
+
},
|
|
711
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
712
|
+
signSupport: { legacy: true, eip1559: true }
|
|
713
|
+
},
|
|
714
|
+
// XRP
|
|
715
|
+
xrpl: {
|
|
716
|
+
chainId: null,
|
|
717
|
+
network: "xrpl",
|
|
718
|
+
name: "XRP",
|
|
719
|
+
type: "XRPL" /* XRPL */,
|
|
720
|
+
isTestnet: false,
|
|
721
|
+
explorer: "https://xrpscan.com",
|
|
722
|
+
website: "https://xrpl.org",
|
|
723
|
+
nativeCurrency: {
|
|
724
|
+
name: "XRP",
|
|
725
|
+
symbol: "XRP",
|
|
726
|
+
decimals: 6
|
|
727
|
+
},
|
|
728
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
729
|
+
signSupport: { legacy: true, eip1559: false }
|
|
730
|
+
},
|
|
731
|
+
// XRP Testnet
|
|
732
|
+
xrpl_testnet: {
|
|
733
|
+
chainId: null,
|
|
734
|
+
network: "xrpl_testnet",
|
|
735
|
+
name: "XRP Testnet",
|
|
736
|
+
type: "XRPL" /* XRPL */,
|
|
737
|
+
isTestnet: true,
|
|
738
|
+
explorer: "https://testnet.xrpscan.com",
|
|
739
|
+
website: "https://xrpl.org",
|
|
740
|
+
nativeCurrency: {
|
|
741
|
+
name: "XRP",
|
|
742
|
+
symbol: "XRP",
|
|
743
|
+
decimals: 6
|
|
744
|
+
},
|
|
745
|
+
apiSupport: { tokens: true, nft: true, transactions: true },
|
|
746
|
+
signSupport: { legacy: true, eip1559: false }
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
var NETWORK_BY_PARAM = Object.values(
|
|
750
|
+
NETWORK_CONFIGS
|
|
751
|
+
).reduce(
|
|
752
|
+
(acc, config) => {
|
|
753
|
+
acc[config.network] = config;
|
|
754
|
+
return acc;
|
|
755
|
+
},
|
|
756
|
+
{}
|
|
757
|
+
);
|
|
758
|
+
function getNetworkByChainId(chainId) {
|
|
759
|
+
return NETWORK_CONFIGS[chainId];
|
|
760
|
+
}
|
|
761
|
+
function getNetworkByParam(network) {
|
|
762
|
+
return NETWORK_BY_PARAM[network];
|
|
763
|
+
}
|
|
764
|
+
function getNetworkName(chainId, fallback = "ethereum") {
|
|
765
|
+
return NETWORK_CONFIGS[chainId]?.network ?? fallback;
|
|
766
|
+
}
|
|
767
|
+
var CHAIN_ID_TO_KEY = {
|
|
768
|
+
// Mainnet
|
|
769
|
+
1: "ethereum",
|
|
770
|
+
42161: "arbitrum",
|
|
771
|
+
8217: "kaia",
|
|
772
|
+
56: "bsc",
|
|
773
|
+
8453: "base",
|
|
774
|
+
137: "polygon",
|
|
775
|
+
43114: "avalanche",
|
|
776
|
+
5e3: "mantle",
|
|
777
|
+
51828: "chainbounty",
|
|
778
|
+
// Testnet
|
|
779
|
+
11155111: "sepolia",
|
|
780
|
+
421614: "arbitrumSepolia",
|
|
781
|
+
1001: "kaiaKairos",
|
|
782
|
+
97: "bscTestnet",
|
|
783
|
+
84532: "baseSepolia",
|
|
784
|
+
80002: "polygonAmoy",
|
|
785
|
+
43113: "avalancheFuji",
|
|
786
|
+
5003: "mantleSepolia",
|
|
787
|
+
56580: "chainbountyTestnet",
|
|
788
|
+
998: "hyperevmTestnet"
|
|
789
|
+
};
|
|
790
|
+
function getChainKey(chainId) {
|
|
791
|
+
const key = CHAIN_ID_TO_KEY[chainId];
|
|
792
|
+
if (!key) {
|
|
793
|
+
throw new Error(`Unsupported chainId for tx endpoint: ${chainId}`);
|
|
794
|
+
}
|
|
795
|
+
return key;
|
|
796
|
+
}
|
|
797
|
+
function getExplorerTxUrl(chainIdOrNetwork, txHash) {
|
|
798
|
+
const config = typeof chainIdOrNetwork === "number" ? getNetworkByChainId(chainIdOrNetwork) : getNetworkByParam(chainIdOrNetwork);
|
|
799
|
+
if (!config) {
|
|
800
|
+
throw new Error(`Unknown network: ${chainIdOrNetwork}`);
|
|
801
|
+
}
|
|
802
|
+
return `${config.explorer}/tx/${txHash}`;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// src/gasless/GaslessConfigSingleton.ts
|
|
806
|
+
var _gaslessConfig = null;
|
|
807
|
+
function getGaslessConfig() {
|
|
808
|
+
return _gaslessConfig;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/gasless/api/RelayerApi.ts
|
|
812
|
+
var RelayerApi = class {
|
|
813
|
+
async estimateFee(params) {
|
|
814
|
+
const api = getTalkenApiClient();
|
|
815
|
+
if (!api)
|
|
816
|
+
throw new Error("TalkenApiClient not initialized");
|
|
817
|
+
return api.post(
|
|
818
|
+
TALKEN_API_ENDPOINTS.RELAYER_FEE_ESTIMATE,
|
|
819
|
+
params
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
async execute(params) {
|
|
823
|
+
const api = getTalkenApiClient();
|
|
824
|
+
if (!api)
|
|
825
|
+
throw new Error("TalkenApiClient not initialized");
|
|
826
|
+
const isEip7702 = params.auth?.method === "eip7702";
|
|
827
|
+
return api.post(
|
|
828
|
+
TALKEN_API_ENDPOINTS.RELAYER_EXECUTE,
|
|
829
|
+
params,
|
|
830
|
+
{ timeout: isEip7702 ? 12e4 : 6e4 }
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
async getRelayerBalance(chainKey) {
|
|
834
|
+
const api = getTalkenApiClient();
|
|
835
|
+
if (!api)
|
|
836
|
+
throw new Error("TalkenApiClient not initialized");
|
|
837
|
+
return api.get(
|
|
838
|
+
`${TALKEN_API_ENDPOINTS.RELAYER_BALANCE}/${encodeURIComponent(chainKey)}`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Get EIP-7702 execution nonce for an address on a chain.
|
|
843
|
+
*
|
|
844
|
+
* Known issue (testnet only): The server's /wallet/execution-nonce endpoint
|
|
845
|
+
* reads the wrong storage slot on testnet due to an older delegate contract
|
|
846
|
+
* (Sepolia), causing it to always return a stale nonce of 0. Production
|
|
847
|
+
* contracts are unaffected.
|
|
848
|
+
*
|
|
849
|
+
* Previously, a client-side dev-only fallback (devNonceFallback.ts) worked
|
|
850
|
+
* around this by calling eth_getStorageAt directly via hardcoded testnet
|
|
851
|
+
* public RPCs. That fallback has been removed to eliminate external RPC
|
|
852
|
+
* dependencies. The proper fix is to update the server endpoint to read
|
|
853
|
+
* the correct storage slot (0x1). Note that the Talken API does not expose
|
|
854
|
+
* an eth_getStorageAt proxy (AbcEvmProvider treats it as UNSUPPORTED_METHOD),
|
|
855
|
+
* so there is no client-side alternative.
|
|
856
|
+
*
|
|
857
|
+
* @see https://sepolia.etherscan.io/address/0x0733De884289DA5D1349db8d09D7b14f4Ab1EF5c
|
|
858
|
+
*/
|
|
859
|
+
async getExecutionNonce(chainKey, address) {
|
|
860
|
+
const api = getTalkenApiClient();
|
|
861
|
+
if (!api)
|
|
862
|
+
throw new Error("TalkenApiClient not initialized");
|
|
863
|
+
const response = await api.get(
|
|
864
|
+
`${TALKEN_API_ENDPOINTS.EXECUTION_NONCE}/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
|
|
865
|
+
);
|
|
866
|
+
return response.executionNonce ?? "0";
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// src/gasless/api/ChainConfigApi.ts
|
|
871
|
+
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
872
|
+
var BALANCE_CACHE_TTL_MS = 30 * 1e3;
|
|
873
|
+
var ChainConfigApi = class {
|
|
874
|
+
constructor() {
|
|
875
|
+
this.configCache = /* @__PURE__ */ new Map();
|
|
876
|
+
this.balanceCache = /* @__PURE__ */ new Map();
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Get runtime chain config (eip7702Delegate, token addresses, etc.).
|
|
880
|
+
* GET /config/chain/{chainKey}
|
|
881
|
+
*
|
|
882
|
+
* Cached for 60 minutes.
|
|
883
|
+
*/
|
|
884
|
+
async getChainConfig(chainKey) {
|
|
885
|
+
const cached = this.configCache.get(chainKey);
|
|
886
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
|
|
887
|
+
return cached.data;
|
|
888
|
+
}
|
|
889
|
+
const api = getTalkenApiClient();
|
|
890
|
+
if (!api)
|
|
891
|
+
throw new Error("TalkenApiClient not initialized");
|
|
892
|
+
const response = await api.get(
|
|
893
|
+
`${TALKEN_API_ENDPOINTS.CONFIG_CHAIN}/${encodeURIComponent(chainKey)}`
|
|
894
|
+
);
|
|
895
|
+
this.configCache.set(chainKey, {
|
|
896
|
+
data: response,
|
|
897
|
+
timestamp: Date.now()
|
|
898
|
+
});
|
|
899
|
+
return response;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Get token balances for an address on a chain.
|
|
903
|
+
* GET /tokens/balances?address={address}&chainKey={chainKey}
|
|
904
|
+
*
|
|
905
|
+
* Cached for 30 seconds.
|
|
906
|
+
*/
|
|
907
|
+
async getTokenBalances(address, chainKey) {
|
|
908
|
+
const cacheKey = `${chainKey}:${address.toLowerCase()}`;
|
|
909
|
+
const cached = this.balanceCache.get(cacheKey);
|
|
910
|
+
if (cached && Date.now() - cached.timestamp < BALANCE_CACHE_TTL_MS) {
|
|
911
|
+
return cached.data;
|
|
912
|
+
}
|
|
913
|
+
const api = getTalkenApiClient();
|
|
914
|
+
if (!api)
|
|
915
|
+
throw new Error("TalkenApiClient not initialized");
|
|
916
|
+
const response = await api.get(
|
|
917
|
+
`${TALKEN_API_ENDPOINTS.TOKENS_BALANCES}?address=${encodeURIComponent(address)}&chainKey=${encodeURIComponent(chainKey)}`
|
|
918
|
+
);
|
|
919
|
+
const balances = Array.isArray(response) ? response : [];
|
|
920
|
+
this.balanceCache.set(cacheKey, {
|
|
921
|
+
data: balances,
|
|
922
|
+
timestamp: Date.now()
|
|
923
|
+
});
|
|
924
|
+
return balances;
|
|
925
|
+
}
|
|
926
|
+
clearCache() {
|
|
927
|
+
this.configCache.clear();
|
|
928
|
+
this.balanceCache.clear();
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
// src/gasless/api/TokenCapabilityApi.ts
|
|
933
|
+
var CACHE_TTL_MS2 = 60 * 60 * 1e3;
|
|
934
|
+
var TokenCapabilityApi = class {
|
|
935
|
+
constructor() {
|
|
936
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Get EIP-3009 / ERC-2612 capabilities for a token on a chain.
|
|
940
|
+
* GET /tokens/capabilities/{chainKey}/{tokenAddress}
|
|
941
|
+
*
|
|
942
|
+
* Results are cached for 60 minutes.
|
|
943
|
+
*/
|
|
944
|
+
async getCapabilities(chainKey, tokenAddress) {
|
|
945
|
+
const cacheKey = `${chainKey}:${tokenAddress.toLowerCase()}`;
|
|
946
|
+
const cached = this.cache.get(cacheKey);
|
|
947
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS2) {
|
|
948
|
+
return cached.data;
|
|
949
|
+
}
|
|
950
|
+
const api = getTalkenApiClient();
|
|
951
|
+
if (!api)
|
|
952
|
+
throw new Error("TalkenApiClient not initialized");
|
|
953
|
+
const response = await api.get(
|
|
954
|
+
`${TALKEN_API_ENDPOINTS.TOKENS_CAPABILITIES}/${encodeURIComponent(chainKey)}/${encodeURIComponent(tokenAddress)}`
|
|
955
|
+
);
|
|
956
|
+
this.cache.set(cacheKey, {
|
|
957
|
+
data: response,
|
|
958
|
+
timestamp: Date.now()
|
|
959
|
+
});
|
|
960
|
+
return response;
|
|
961
|
+
}
|
|
962
|
+
clearCache() {
|
|
963
|
+
this.cache.clear();
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/gasless/utils/feeTokenResolver.ts
|
|
968
|
+
function resolveFeeTokensFromConfig(chainConfig, chainId, gaslessConfig) {
|
|
969
|
+
const tokens = [];
|
|
970
|
+
if (chainConfig.usdt) {
|
|
971
|
+
const isBsc = chainConfig.chainKey === "bsc" || chainConfig.chainKey === "bscTestnet";
|
|
972
|
+
tokens.push({
|
|
973
|
+
symbol: "USDT",
|
|
974
|
+
address: chainConfig.usdt,
|
|
975
|
+
decimals: isBsc ? 18 : 6
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
if (chainConfig.usdc) {
|
|
979
|
+
const isBsc = chainConfig.chainKey === "bsc" || chainConfig.chainKey === "bscTestnet";
|
|
980
|
+
tokens.push({
|
|
981
|
+
symbol: "USDC",
|
|
982
|
+
address: chainConfig.usdc,
|
|
983
|
+
decimals: isBsc ? 18 : 6
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
if (gaslessConfig.projectFeeTokens) {
|
|
987
|
+
for (const pt of gaslessConfig.projectFeeTokens) {
|
|
988
|
+
if (pt.chainId !== chainId)
|
|
989
|
+
continue;
|
|
990
|
+
const exists = tokens.some(
|
|
991
|
+
(t) => t.address.toLowerCase() === pt.address.toLowerCase()
|
|
992
|
+
);
|
|
993
|
+
if (exists)
|
|
994
|
+
continue;
|
|
995
|
+
tokens.push({
|
|
996
|
+
symbol: pt.symbol,
|
|
997
|
+
address: pt.address,
|
|
998
|
+
decimals: pt.decimals,
|
|
999
|
+
icon: pt.icon,
|
|
1000
|
+
isProjectToken: true
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return applyFeeTokenPriority(tokens, gaslessConfig.feeTokenPriority);
|
|
1005
|
+
}
|
|
1006
|
+
function applyFeeTokenPriority(tokens, priority) {
|
|
1007
|
+
if (!priority || priority.length === 0)
|
|
1008
|
+
return tokens;
|
|
1009
|
+
const upperPriority = priority.map((s) => s.toUpperCase());
|
|
1010
|
+
const result = [];
|
|
1011
|
+
for (const symbol of upperPriority) {
|
|
1012
|
+
const match = tokens.find((t) => t.symbol.toUpperCase() === symbol);
|
|
1013
|
+
if (match)
|
|
1014
|
+
result.push(match);
|
|
1015
|
+
}
|
|
1016
|
+
return result;
|
|
1017
|
+
}
|
|
1018
|
+
function selectDefaultFeeToken(feeTokens, chainId, gaslessConfig) {
|
|
1019
|
+
if (feeTokens.length === 0)
|
|
1020
|
+
return null;
|
|
1021
|
+
const defaultAddr = gaslessConfig.defaultFeeToken?.[chainId];
|
|
1022
|
+
if (defaultAddr) {
|
|
1023
|
+
const match = feeTokens.find(
|
|
1024
|
+
(t) => t.address.toLowerCase() === defaultAddr.toLowerCase()
|
|
1025
|
+
);
|
|
1026
|
+
if (match)
|
|
1027
|
+
return match;
|
|
1028
|
+
}
|
|
1029
|
+
return feeTokens[0];
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// src/gasless/services/GaslessFeeService.ts
|
|
1033
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1034
|
+
var PRICE_UNAVAILABLE_COOLDOWN_MS = 5 * 60 * 1e3;
|
|
1035
|
+
var NOT_FOUND_COOLDOWN_MS = 60 * 1e3;
|
|
1036
|
+
var GaslessFeeService = class {
|
|
1037
|
+
constructor(deps) {
|
|
1038
|
+
/** Per-chain cooldown for 404 (unsupported chain) */
|
|
1039
|
+
this.chainCooldown = /* @__PURE__ */ new Map();
|
|
1040
|
+
/** Per-token cooldown for PRICE_UNAVAILABLE */
|
|
1041
|
+
this.tokenCooldown = /* @__PURE__ */ new Map();
|
|
1042
|
+
this.relayerApi = deps?.relayerApi ?? new RelayerApi();
|
|
1043
|
+
this.tokenCapabilityApi = deps?.tokenCapabilityApi ?? new TokenCapabilityApi();
|
|
1044
|
+
this.chainConfigApi = deps?.chainConfigApi ?? new ChainConfigApi();
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Estimate gasless fee for a transfer across all tiers.
|
|
1048
|
+
*
|
|
1049
|
+
* Iterates fee token candidates in order, tries Tier 1 first,
|
|
1050
|
+
* then Tier 2, finally Tier 3 (if getRewardsBalance provided).
|
|
1051
|
+
*
|
|
1052
|
+
* Returns null if gasless is not possible.
|
|
1053
|
+
*/
|
|
1054
|
+
async estimateFee(params) {
|
|
1055
|
+
const {
|
|
1056
|
+
chainKey,
|
|
1057
|
+
chainId,
|
|
1058
|
+
tokenAddress,
|
|
1059
|
+
fromAddress,
|
|
1060
|
+
amount,
|
|
1061
|
+
gaslessConfig,
|
|
1062
|
+
supportsAuthorization = true
|
|
1063
|
+
} = params;
|
|
1064
|
+
const chainCooldownUntil = this.chainCooldown.get(chainKey);
|
|
1065
|
+
if (chainCooldownUntil && Date.now() < chainCooldownUntil) {
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
const allModes = gaslessConfig.modePreference ?? [
|
|
1069
|
+
"generic",
|
|
1070
|
+
"eip7702-fee",
|
|
1071
|
+
"eip7702-points"
|
|
1072
|
+
];
|
|
1073
|
+
const modePreference = supportsAuthorization ? allModes : allModes.filter((m) => m === "generic");
|
|
1074
|
+
let chainConfig;
|
|
1075
|
+
let balances;
|
|
1076
|
+
try {
|
|
1077
|
+
[chainConfig, balances] = await Promise.all([
|
|
1078
|
+
this.chainConfigApi.getChainConfig(chainKey),
|
|
1079
|
+
this.chainConfigApi.getTokenBalances(fromAddress, chainKey)
|
|
1080
|
+
]);
|
|
1081
|
+
} catch (err) {
|
|
1082
|
+
console.warn(
|
|
1083
|
+
"[GaslessFeeService] Chain config/balance fetch failed:",
|
|
1084
|
+
err
|
|
1085
|
+
);
|
|
1086
|
+
return null;
|
|
1087
|
+
}
|
|
1088
|
+
const feeTokens = resolveFeeTokensFromConfig(
|
|
1089
|
+
chainConfig,
|
|
1090
|
+
chainId,
|
|
1091
|
+
gaslessConfig
|
|
1092
|
+
);
|
|
1093
|
+
if (feeTokens.length === 0)
|
|
1094
|
+
return null;
|
|
1095
|
+
let inputTokenCaps;
|
|
1096
|
+
try {
|
|
1097
|
+
inputTokenCaps = await this.tokenCapabilityApi.getCapabilities(
|
|
1098
|
+
chainKey,
|
|
1099
|
+
tokenAddress
|
|
1100
|
+
);
|
|
1101
|
+
} catch (err) {
|
|
1102
|
+
console.warn("[GaslessFeeService] Token capability fetch failed:", err);
|
|
1103
|
+
inputTokenCaps = null;
|
|
1104
|
+
}
|
|
1105
|
+
let eip7702FeeCandidate = null;
|
|
1106
|
+
for (const feeToken of feeTokens) {
|
|
1107
|
+
const tokenCooldownUntil = this.tokenCooldown.get(
|
|
1108
|
+
feeToken.symbol.toUpperCase()
|
|
1109
|
+
);
|
|
1110
|
+
if (tokenCooldownUntil && Date.now() < tokenCooldownUntil) {
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
let feeEstimateRaw;
|
|
1114
|
+
try {
|
|
1115
|
+
feeEstimateRaw = await this.relayerApi.estimateFee({
|
|
1116
|
+
chainKey,
|
|
1117
|
+
user: fromAddress,
|
|
1118
|
+
tokenIn: tokenAddress,
|
|
1119
|
+
amountIn: amount,
|
|
1120
|
+
tokenOut: ZERO_ADDRESS,
|
|
1121
|
+
minAmountOut: "0",
|
|
1122
|
+
deadline: Math.floor(Date.now() / 1e3) + 20 * 60,
|
|
1123
|
+
dexType: 2,
|
|
1124
|
+
dexData: "0x",
|
|
1125
|
+
feeToken: feeToken.symbol
|
|
1126
|
+
});
|
|
1127
|
+
} catch (err) {
|
|
1128
|
+
const status = err?.statusCode ?? err?.response?.status;
|
|
1129
|
+
const errCode = err?.code ?? err?.response?.data?.code;
|
|
1130
|
+
if (status === 404) {
|
|
1131
|
+
this.chainCooldown.set(chainKey, Date.now() + NOT_FOUND_COOLDOWN_MS);
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
if (errCode === "PRICE_UNAVAILABLE" || status === 400 && String(err).includes("price")) {
|
|
1135
|
+
this.tokenCooldown.set(
|
|
1136
|
+
feeToken.symbol.toUpperCase(),
|
|
1137
|
+
Date.now() + PRICE_UNAVAILABLE_COOLDOWN_MS
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
console.warn(
|
|
1141
|
+
`[GaslessFeeService] Fee estimate failed for ${feeToken.symbol}:`,
|
|
1142
|
+
err
|
|
1143
|
+
);
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
const feeAmountRaw = feeEstimateRaw.feeInToken;
|
|
1147
|
+
const feeAmountBig = BigInt(feeAmountRaw);
|
|
1148
|
+
const isSameTokenAsInput = feeToken.address.toLowerCase() === tokenAddress.toLowerCase();
|
|
1149
|
+
if (isSameTokenAsInput && feeAmountBig * BigInt(2) > BigInt(amount)) {
|
|
1150
|
+
console.warn(
|
|
1151
|
+
`[GaslessFeeService] Fee ${feeAmountRaw} exceeds 50% of amount ${amount} for ${feeToken.symbol}, skipping`
|
|
1152
|
+
);
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
const formattedFee = this.formatFee(feeAmountRaw, feeToken.decimals);
|
|
1156
|
+
const feeTokenBalance = this.getBalance(balances, feeToken.address);
|
|
1157
|
+
const inputBalance = this.getBalance(balances, tokenAddress);
|
|
1158
|
+
if (modePreference.includes("generic")) {
|
|
1159
|
+
let canGeneric = false;
|
|
1160
|
+
if (isSameTokenAsInput) {
|
|
1161
|
+
canGeneric = !!(inputTokenCaps?.supportsEIP3009 || inputTokenCaps?.supportsERC2612);
|
|
1162
|
+
if (canGeneric && BigInt(amount) <= feeAmountBig)
|
|
1163
|
+
canGeneric = false;
|
|
1164
|
+
} else if (inputTokenCaps?.supportsEIP3009 || inputTokenCaps?.supportsERC2612) {
|
|
1165
|
+
try {
|
|
1166
|
+
const feeCaps = await this.tokenCapabilityApi.getCapabilities(
|
|
1167
|
+
chainKey,
|
|
1168
|
+
feeToken.address
|
|
1169
|
+
);
|
|
1170
|
+
canGeneric = !!(feeCaps.supportsEIP3009 || feeCaps.supportsERC2612);
|
|
1171
|
+
} catch {
|
|
1172
|
+
canGeneric = false;
|
|
1173
|
+
}
|
|
1174
|
+
if (canGeneric && feeTokenBalance < feeAmountBig)
|
|
1175
|
+
canGeneric = false;
|
|
1176
|
+
}
|
|
1177
|
+
if (canGeneric) {
|
|
1178
|
+
return this.buildEstimate(
|
|
1179
|
+
feeToken,
|
|
1180
|
+
formattedFee,
|
|
1181
|
+
feeAmountRaw,
|
|
1182
|
+
"generic"
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (modePreference.includes("eip7702-fee") && chainConfig.eip7702Delegate && !eip7702FeeCandidate) {
|
|
1187
|
+
let canEip7702Fee = true;
|
|
1188
|
+
if (isSameTokenAsInput) {
|
|
1189
|
+
if (inputBalance < BigInt(amount) + feeAmountBig)
|
|
1190
|
+
canEip7702Fee = false;
|
|
1191
|
+
} else {
|
|
1192
|
+
if (feeTokenBalance < feeAmountBig)
|
|
1193
|
+
canEip7702Fee = false;
|
|
1194
|
+
}
|
|
1195
|
+
if (canEip7702Fee) {
|
|
1196
|
+
eip7702FeeCandidate = this.buildEstimate(
|
|
1197
|
+
feeToken,
|
|
1198
|
+
formattedFee,
|
|
1199
|
+
feeAmountRaw,
|
|
1200
|
+
"eip7702-fee"
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
if (eip7702FeeCandidate)
|
|
1206
|
+
return eip7702FeeCandidate;
|
|
1207
|
+
if (modePreference.includes("eip7702-points") && chainConfig.eip7702Delegate && gaslessConfig.getRewardsBalance) {
|
|
1208
|
+
const pointsFeeToken = feeTokens.find((t) => t.isProjectToken) ?? selectDefaultFeeToken(feeTokens, chainId, gaslessConfig);
|
|
1209
|
+
if (pointsFeeToken) {
|
|
1210
|
+
const pointsCooldownUntil = this.tokenCooldown.get(
|
|
1211
|
+
pointsFeeToken.symbol.toUpperCase()
|
|
1212
|
+
);
|
|
1213
|
+
if (pointsCooldownUntil && Date.now() < pointsCooldownUntil) {
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1216
|
+
try {
|
|
1217
|
+
const rewards = await gaslessConfig.getRewardsBalance({
|
|
1218
|
+
address: fromAddress,
|
|
1219
|
+
chainId
|
|
1220
|
+
});
|
|
1221
|
+
if (!rewards || BigInt(rewards.balance) <= BigInt(0)) {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
let feeEstimateRaw;
|
|
1225
|
+
try {
|
|
1226
|
+
feeEstimateRaw = await this.relayerApi.estimateFee({
|
|
1227
|
+
chainKey,
|
|
1228
|
+
user: fromAddress,
|
|
1229
|
+
tokenIn: tokenAddress,
|
|
1230
|
+
amountIn: amount,
|
|
1231
|
+
tokenOut: ZERO_ADDRESS,
|
|
1232
|
+
minAmountOut: "0",
|
|
1233
|
+
deadline: Math.floor(Date.now() / 1e3) + 20 * 60,
|
|
1234
|
+
dexType: 2,
|
|
1235
|
+
dexData: "0x",
|
|
1236
|
+
feeToken: pointsFeeToken.symbol
|
|
1237
|
+
});
|
|
1238
|
+
} catch (feeErr) {
|
|
1239
|
+
const feeStatus = feeErr?.statusCode ?? feeErr?.response?.status;
|
|
1240
|
+
const feeErrCode = feeErr?.code ?? feeErr?.response?.data?.code;
|
|
1241
|
+
if (feeErrCode === "PRICE_UNAVAILABLE" || feeStatus === 400 && String(feeErr).includes("price")) {
|
|
1242
|
+
this.tokenCooldown.set(
|
|
1243
|
+
pointsFeeToken.symbol.toUpperCase(),
|
|
1244
|
+
Date.now() + PRICE_UNAVAILABLE_COOLDOWN_MS
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
throw feeErr;
|
|
1248
|
+
}
|
|
1249
|
+
const rewardsInSmallest = BigInt(rewards.balance) * BigInt(10) ** BigInt(pointsFeeToken.decimals);
|
|
1250
|
+
if (rewardsInSmallest < BigInt(feeEstimateRaw.feeInToken)) {
|
|
1251
|
+
return null;
|
|
1252
|
+
}
|
|
1253
|
+
const formattedFee = this.formatFee(
|
|
1254
|
+
feeEstimateRaw.feeInToken,
|
|
1255
|
+
pointsFeeToken.decimals
|
|
1256
|
+
);
|
|
1257
|
+
return this.buildEstimate(
|
|
1258
|
+
pointsFeeToken,
|
|
1259
|
+
formattedFee,
|
|
1260
|
+
feeEstimateRaw.feeInToken,
|
|
1261
|
+
"eip7702-points"
|
|
1262
|
+
);
|
|
1263
|
+
} catch (err) {
|
|
1264
|
+
console.warn(
|
|
1265
|
+
"[GaslessFeeService] Points (Tier 3) estimation failed:",
|
|
1266
|
+
err
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
/** Access the chain config API for external use */
|
|
1274
|
+
getChainConfigApi() {
|
|
1275
|
+
return this.chainConfigApi;
|
|
1276
|
+
}
|
|
1277
|
+
/** Access the relayer API for shared use */
|
|
1278
|
+
getRelayerApi() {
|
|
1279
|
+
return this.relayerApi;
|
|
1280
|
+
}
|
|
1281
|
+
/** Clear all API caches (call on disconnect or chain switch) */
|
|
1282
|
+
clearCache() {
|
|
1283
|
+
this.chainConfigApi.clearCache();
|
|
1284
|
+
this.tokenCapabilityApi.clearCache();
|
|
1285
|
+
this.chainCooldown.clear();
|
|
1286
|
+
this.tokenCooldown.clear();
|
|
1287
|
+
}
|
|
1288
|
+
getBalance(balances, tokenAddress) {
|
|
1289
|
+
const entry = balances.find(
|
|
1290
|
+
(b) => b.address?.toLowerCase() === tokenAddress.toLowerCase()
|
|
1291
|
+
);
|
|
1292
|
+
if (!entry?.balance)
|
|
1293
|
+
return BigInt(0);
|
|
1294
|
+
try {
|
|
1295
|
+
return BigInt(entry.balance);
|
|
1296
|
+
} catch {
|
|
1297
|
+
return BigInt(0);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
formatFee(raw, decimals) {
|
|
1301
|
+
try {
|
|
1302
|
+
const value = BigInt(raw);
|
|
1303
|
+
const divisor = BigInt(10) ** BigInt(decimals);
|
|
1304
|
+
const whole = value / divisor;
|
|
1305
|
+
const remainder = value % divisor;
|
|
1306
|
+
const fractional = remainder.toString().padStart(decimals, "0").slice(0, Math.min(decimals, 6)).replace(/0+$/, "");
|
|
1307
|
+
return fractional ? `${whole}.${fractional}` : whole.toString();
|
|
1308
|
+
} catch {
|
|
1309
|
+
return "0";
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
buildEstimate(feeToken, feeAmount, feeAmountRaw, gaslessMode) {
|
|
1313
|
+
return { feeToken, feeAmount, feeAmountRaw, gaslessMode };
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
var _sharedInstance = null;
|
|
1317
|
+
function getSharedGaslessFeeService() {
|
|
1318
|
+
if (!_sharedInstance) {
|
|
1319
|
+
_sharedInstance = new GaslessFeeService();
|
|
1320
|
+
}
|
|
1321
|
+
return _sharedInstance;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/gasless/services/GaslessTransferService.ts
|
|
1325
|
+
import { encodeFunctionData, erc20Abi, isAddress as isAddress2 } from "viem";
|
|
1326
|
+
|
|
1327
|
+
// src/gasless/utils/revokeDelegation.ts
|
|
1328
|
+
import {
|
|
1329
|
+
isAddress,
|
|
1330
|
+
keccak256,
|
|
1331
|
+
recoverAddress,
|
|
1332
|
+
toHex,
|
|
1333
|
+
toRlp
|
|
1334
|
+
} from "viem";
|
|
1335
|
+
var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
1336
|
+
var DEFAULT_GAS_LIMIT = BigInt(1e5);
|
|
1337
|
+
var DEFAULT_MAX_FEE = BigInt(3e10);
|
|
1338
|
+
var DEFAULT_MAX_PRIORITY_FEE = BigInt(15e8);
|
|
1339
|
+
function rlpUint(n) {
|
|
1340
|
+
if (n === 0 || n === BigInt(0))
|
|
1341
|
+
return "0x";
|
|
1342
|
+
return toHex(BigInt(n));
|
|
1343
|
+
}
|
|
1344
|
+
function stripLeadingZeroBytes(hex) {
|
|
1345
|
+
const stripped = hex.replace(/^0x0*/, "0x");
|
|
1346
|
+
return stripped === "0x" ? "0x00" : stripped;
|
|
1347
|
+
}
|
|
1348
|
+
async function recoverYParity(hash, r, s, expectedAddress) {
|
|
1349
|
+
for (const yp of [0, 1]) {
|
|
1350
|
+
try {
|
|
1351
|
+
const recovered = await recoverAddress({
|
|
1352
|
+
hash,
|
|
1353
|
+
signature: { r, s, yParity: yp }
|
|
1354
|
+
});
|
|
1355
|
+
if (recovered.toLowerCase() === expectedAddress.toLowerCase())
|
|
1356
|
+
return yp;
|
|
1357
|
+
} catch {
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
throw new Error("Failed to recover yParity from tx signature");
|
|
1361
|
+
}
|
|
1362
|
+
async function sendRevokeTx(userAddress, _chainKey, chainId) {
|
|
1363
|
+
const api = getTalkenApiClient();
|
|
1364
|
+
if (!api)
|
|
1365
|
+
throw new Error("TalkenApiClient not initialized");
|
|
1366
|
+
const credentialManager = getCredentialManager();
|
|
1367
|
+
const pinHash = credentialManager.getPinHash() || "";
|
|
1368
|
+
const email = credentialManager.getEmail() ?? void 0;
|
|
1369
|
+
const network = getNetworkName(chainId);
|
|
1370
|
+
const nonceResult = await api.evm.getNonce(network, userAddress);
|
|
1371
|
+
const nonceRaw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
|
|
1372
|
+
const currentNonce = Number(nonceRaw);
|
|
1373
|
+
if (!Number.isFinite(currentNonce)) {
|
|
1374
|
+
throw new Error("Failed to resolve wallet nonce for revoke");
|
|
1375
|
+
}
|
|
1376
|
+
const authNonce = currentNonce + 1;
|
|
1377
|
+
const authResult = await api.evm.signAuthorization({
|
|
1378
|
+
network,
|
|
1379
|
+
authorization: {
|
|
1380
|
+
chainId,
|
|
1381
|
+
address: ZERO_ADDRESS2,
|
|
1382
|
+
nonce: String(authNonce)
|
|
1383
|
+
},
|
|
1384
|
+
pin: pinHash,
|
|
1385
|
+
...email && { email }
|
|
1386
|
+
});
|
|
1387
|
+
const auth = authResult?.authorization ?? authResult;
|
|
1388
|
+
if (!auth?.r || !auth?.s) {
|
|
1389
|
+
throw new Error("signAuthorization returned empty r/s for revoke");
|
|
1390
|
+
}
|
|
1391
|
+
const authYParity = Number(auth.yParity ?? auth.v ?? 0);
|
|
1392
|
+
const normalizedYParity = authYParity === 27 ? 0 : authYParity === 28 ? 1 : authYParity;
|
|
1393
|
+
const authR = stripLeadingZeroBytes(auth.r);
|
|
1394
|
+
const authS = stripLeadingZeroBytes(auth.s);
|
|
1395
|
+
let maxFeePerGas = DEFAULT_MAX_FEE;
|
|
1396
|
+
let maxPriorityFeePerGas = DEFAULT_MAX_PRIORITY_FEE;
|
|
1397
|
+
try {
|
|
1398
|
+
const suggested = await api.evm.getGasSuggested(network);
|
|
1399
|
+
if (suggested?.high) {
|
|
1400
|
+
maxPriorityFeePerGas = BigInt(
|
|
1401
|
+
Math.round(Number(suggested.high.suggestedMaxPriorityFeePerGas) * 1e9)
|
|
1402
|
+
);
|
|
1403
|
+
maxFeePerGas = BigInt(
|
|
1404
|
+
Math.round(Number(suggested.high.suggestedMaxFeePerGas) * 1e9)
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1407
|
+
} catch {
|
|
1408
|
+
}
|
|
1409
|
+
const authEntry = [
|
|
1410
|
+
rlpUint(chainId),
|
|
1411
|
+
ZERO_ADDRESS2,
|
|
1412
|
+
rlpUint(authNonce),
|
|
1413
|
+
normalizedYParity ? "0x01" : "0x",
|
|
1414
|
+
authR,
|
|
1415
|
+
authS
|
|
1416
|
+
];
|
|
1417
|
+
const unsignedFields = [
|
|
1418
|
+
rlpUint(chainId),
|
|
1419
|
+
rlpUint(currentNonce),
|
|
1420
|
+
rlpUint(maxPriorityFeePerGas),
|
|
1421
|
+
rlpUint(maxFeePerGas),
|
|
1422
|
+
rlpUint(DEFAULT_GAS_LIMIT),
|
|
1423
|
+
userAddress,
|
|
1424
|
+
"0x",
|
|
1425
|
+
// value
|
|
1426
|
+
"0x",
|
|
1427
|
+
// data
|
|
1428
|
+
[],
|
|
1429
|
+
// accessList
|
|
1430
|
+
[authEntry]
|
|
1431
|
+
// authorizationList
|
|
1432
|
+
];
|
|
1433
|
+
const signingPayload = `0x04${toRlp(unsignedFields).slice(2)}`;
|
|
1434
|
+
const signingHash = keccak256(signingPayload);
|
|
1435
|
+
const signResult = await api.post("/wallet/sign/hash", {
|
|
1436
|
+
hash: signingHash,
|
|
1437
|
+
pin: pinHash,
|
|
1438
|
+
...network && { network },
|
|
1439
|
+
...email && { email }
|
|
1440
|
+
});
|
|
1441
|
+
const signStr = signResult?.signstr ?? signResult?.signature ?? "";
|
|
1442
|
+
if (!signStr)
|
|
1443
|
+
throw new Error("signHash returned empty signature");
|
|
1444
|
+
let txRRaw;
|
|
1445
|
+
let txSRaw;
|
|
1446
|
+
try {
|
|
1447
|
+
const parsed = JSON.parse(signStr);
|
|
1448
|
+
const sig = parsed.sig_list?.[0];
|
|
1449
|
+
if (!sig?.r || !sig?.s)
|
|
1450
|
+
throw new Error("Missing r/s in sig_list");
|
|
1451
|
+
txRRaw = sig.r.startsWith("0x") ? sig.r : `0x${sig.r}`;
|
|
1452
|
+
txSRaw = sig.s.startsWith("0x") ? sig.s : `0x${sig.s}`;
|
|
1453
|
+
} catch (_parseErr) {
|
|
1454
|
+
const sigHex = signStr.startsWith("0x") ? signStr.slice(2) : signStr;
|
|
1455
|
+
if (sigHex.length < 128)
|
|
1456
|
+
throw new Error(`signHash response too short: ${sigHex.length}`);
|
|
1457
|
+
txRRaw = `0x${sigHex.slice(0, 64)}`;
|
|
1458
|
+
txSRaw = `0x${sigHex.slice(64, 128)}`;
|
|
1459
|
+
}
|
|
1460
|
+
const txR = stripLeadingZeroBytes(txRRaw);
|
|
1461
|
+
const txS = stripLeadingZeroBytes(txSRaw);
|
|
1462
|
+
const txYParity = await recoverYParity(
|
|
1463
|
+
signingHash,
|
|
1464
|
+
txRRaw,
|
|
1465
|
+
txSRaw,
|
|
1466
|
+
userAddress
|
|
1467
|
+
);
|
|
1468
|
+
const signedFields = [...unsignedFields, txYParity ? "0x01" : "0x", txR, txS];
|
|
1469
|
+
const signedTx = `0x04${toRlp(signedFields).slice(2)}`;
|
|
1470
|
+
const result = await api.post(
|
|
1471
|
+
"/wallet/tx/raw",
|
|
1472
|
+
{
|
|
1473
|
+
chain: "evm",
|
|
1474
|
+
network,
|
|
1475
|
+
signedSerializeTx: signedTx,
|
|
1476
|
+
waitForConfirmation: true
|
|
1477
|
+
}
|
|
1478
|
+
);
|
|
1479
|
+
const txHash = result?.txHash ?? result?.hash ?? keccak256(signedTx);
|
|
1480
|
+
console.log(`[RevokeDelegation] Revoke tx confirmed: ${txHash}`);
|
|
1481
|
+
return { txHash };
|
|
1482
|
+
}
|
|
1483
|
+
async function sendRevokeViaWalletClient(walletClient, chainId, userAddress) {
|
|
1484
|
+
if (!isAddress(userAddress)) {
|
|
1485
|
+
throw new Error(`Invalid address for revoke: ${userAddress}`);
|
|
1486
|
+
}
|
|
1487
|
+
const txHash = await walletClient.sendTransaction({
|
|
1488
|
+
authorizationList: [
|
|
1489
|
+
{ contractAddress: ZERO_ADDRESS2, chainId }
|
|
1490
|
+
],
|
|
1491
|
+
to: userAddress,
|
|
1492
|
+
value: BigInt(0)
|
|
1493
|
+
});
|
|
1494
|
+
console.log(`[RevokeDelegation] External wallet revoke tx sent: ${txHash}`);
|
|
1495
|
+
if (walletClient.waitForTransactionReceipt) {
|
|
1496
|
+
const receipt = await walletClient.waitForTransactionReceipt({
|
|
1497
|
+
hash: txHash
|
|
1498
|
+
});
|
|
1499
|
+
if (receipt.status === "reverted") {
|
|
1500
|
+
throw new Error(`Revoke transaction reverted: ${txHash}`);
|
|
1501
|
+
}
|
|
1502
|
+
console.log(
|
|
1503
|
+
`[RevokeDelegation] External wallet revoke tx confirmed: ${txHash}`
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
return { txHash };
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// src/gasless/utils/delegationGuard.ts
|
|
1510
|
+
var EIP7702_CODE_PREFIX = "0xef0100";
|
|
1511
|
+
var POLL_INTERVAL_MS = 2e3;
|
|
1512
|
+
var POLL_TIMEOUT_MS = 3e4;
|
|
1513
|
+
var _locks = /* @__PURE__ */ new Map();
|
|
1514
|
+
function lockKey(chainKey, address) {
|
|
1515
|
+
return `${chainKey}:${address.toLowerCase()}`;
|
|
1516
|
+
}
|
|
1517
|
+
async function checkDelegation(chainKey, address) {
|
|
1518
|
+
const api = getTalkenApiClient();
|
|
1519
|
+
if (!api) {
|
|
1520
|
+
return { hasDelegation: false, delegateAddress: "", code: "0x" };
|
|
1521
|
+
}
|
|
1522
|
+
try {
|
|
1523
|
+
const response = await api.get(
|
|
1524
|
+
`${TALKEN_API_ENDPOINTS.WALLET_CODE}/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
|
|
1525
|
+
);
|
|
1526
|
+
const code = response?.code ?? response?.data?.code ?? "0x";
|
|
1527
|
+
const hasDelegation = !!code && code.startsWith(EIP7702_CODE_PREFIX);
|
|
1528
|
+
const delegateAddress = hasDelegation ? `0x${code.slice(EIP7702_CODE_PREFIX.length, EIP7702_CODE_PREFIX.length + 40)}` : "";
|
|
1529
|
+
return { hasDelegation, delegateAddress, code };
|
|
1530
|
+
} catch (err) {
|
|
1531
|
+
console.warn("[DelegationGuard] eth_getCode check failed:", err);
|
|
1532
|
+
return { hasDelegation: false, delegateAddress: "", code: "0x" };
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
async function ensureDelegationCleared(chainKey, chainId, address, options) {
|
|
1536
|
+
const key = lockKey(chainKey, address);
|
|
1537
|
+
const existing = _locks.get(key);
|
|
1538
|
+
if (existing) {
|
|
1539
|
+
try {
|
|
1540
|
+
await existing;
|
|
1541
|
+
return;
|
|
1542
|
+
} catch {
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
const check = async () => {
|
|
1546
|
+
const initial = await checkDelegation(chainKey, address);
|
|
1547
|
+
if (!initial.hasDelegation)
|
|
1548
|
+
return;
|
|
1549
|
+
console.warn(
|
|
1550
|
+
`[DelegationGuard] Stale delegation detected on ${chainKey}: delegate=${initial.delegateAddress}. Sending revoke tx...`
|
|
1551
|
+
);
|
|
1552
|
+
try {
|
|
1553
|
+
const { txHash } = options?.walletClient ? await sendRevokeViaWalletClient(
|
|
1554
|
+
options.walletClient,
|
|
1555
|
+
chainId,
|
|
1556
|
+
address
|
|
1557
|
+
) : await sendRevokeTx(address, chainKey, chainId);
|
|
1558
|
+
console.log(
|
|
1559
|
+
`[DelegationGuard] Revoke tx sent: ${txHash}. Polling for clearance...`
|
|
1560
|
+
);
|
|
1561
|
+
} catch (revokeErr) {
|
|
1562
|
+
if (revokeErr && typeof revokeErr === "object" && "code" in revokeErr && revokeErr.code === 4001) {
|
|
1563
|
+
throw revokeErr;
|
|
1564
|
+
}
|
|
1565
|
+
console.warn(
|
|
1566
|
+
"[DelegationGuard] Revoke tx failed, falling back to passive wait:",
|
|
1567
|
+
revokeErr
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
1571
|
+
while (Date.now() < deadline) {
|
|
1572
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
1573
|
+
const current = await checkDelegation(chainKey, address);
|
|
1574
|
+
if (!current.hasDelegation) {
|
|
1575
|
+
console.log("[DelegationGuard] Delegation cleared");
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
const message = "Previous transaction delegation is still active. Please wait a moment and try again.";
|
|
1580
|
+
if (options?.onDelegationError) {
|
|
1581
|
+
options.onDelegationError({
|
|
1582
|
+
chainId,
|
|
1583
|
+
address,
|
|
1584
|
+
delegateAddress: initial.delegateAddress,
|
|
1585
|
+
message
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
throw new Error(message);
|
|
1589
|
+
};
|
|
1590
|
+
const promise = check().finally(() => {
|
|
1591
|
+
_locks.delete(key);
|
|
1592
|
+
});
|
|
1593
|
+
_locks.set(key, promise);
|
|
1594
|
+
return promise;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// src/gasless/services/Eip7702Service.ts
|
|
1598
|
+
import { encodeAbiParameters, keccak256 as keccak2562, parseAbiParameters } from "viem";
|
|
1599
|
+
var Eip7702Service = class {
|
|
1600
|
+
constructor(deps) {
|
|
1601
|
+
this.chainConfigApi = deps.chainConfigApi ?? new ChainConfigApi();
|
|
1602
|
+
this.relayerApi = deps.relayerApi ?? new RelayerApi();
|
|
1603
|
+
this.signer = deps.signer;
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Pre-flight check: detect and wait for stale delegation to clear.
|
|
1607
|
+
* If a previous relay's revoke tx is still pending, waits for it
|
|
1608
|
+
* to be mined before proceeding (prevents nonce collision).
|
|
1609
|
+
*/
|
|
1610
|
+
async preflight(chainKey, chainId, address, options) {
|
|
1611
|
+
try {
|
|
1612
|
+
await ensureDelegationCleared(chainKey, chainId, address, options);
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
console.warn(
|
|
1615
|
+
"[Eip7702Service] Pre-flight delegation check failed:",
|
|
1616
|
+
error
|
|
1617
|
+
);
|
|
1618
|
+
throw error;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Sign EIP-7702 delegate authorization.
|
|
1623
|
+
*
|
|
1624
|
+
* Revoke authorization is intentionally omitted: the server previously
|
|
1625
|
+
* broadcast revoke as a separate TX, which caused nonce competition
|
|
1626
|
+
* (2-TX pattern). Delegation persists across relays but each new relay
|
|
1627
|
+
* overwrites the previous delegate authorization, so this is safe.
|
|
1628
|
+
* If the server adds single-TX delegate+revoke support in the future,
|
|
1629
|
+
* add revokeAuth signing here (nonce + 1) and include it in the relay
|
|
1630
|
+
* request.
|
|
1631
|
+
*/
|
|
1632
|
+
async signDelegate(chainKey, chainId, address) {
|
|
1633
|
+
if (!this.signer.supportsAuthorization()) {
|
|
1634
|
+
throw new Error("Signer does not support EIP-7702 authorization");
|
|
1635
|
+
}
|
|
1636
|
+
const chainConfig = await this.chainConfigApi.getChainConfig(chainKey);
|
|
1637
|
+
if (!chainConfig.eip7702Delegate) {
|
|
1638
|
+
throw new Error(`No EIP-7702 delegate configured for chain ${chainKey}`);
|
|
1639
|
+
}
|
|
1640
|
+
const nonce = await this.signer.getNonce(address);
|
|
1641
|
+
const delegateAuth = await this.signer.signAuthorization({
|
|
1642
|
+
chainId,
|
|
1643
|
+
address: chainConfig.eip7702Delegate,
|
|
1644
|
+
nonce
|
|
1645
|
+
});
|
|
1646
|
+
return { delegateAuth };
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Sign the EIP-712 execution typed data for the relay.
|
|
1650
|
+
*/
|
|
1651
|
+
async signExecutionTypedData(typedData) {
|
|
1652
|
+
const sig = await this.signer.signTypedData(typedData);
|
|
1653
|
+
if (!sig || sig === "0x") {
|
|
1654
|
+
throw new Error("signTypedData returned empty signature");
|
|
1655
|
+
}
|
|
1656
|
+
const hex = sig.startsWith("0x") ? sig.slice(2) : sig;
|
|
1657
|
+
if (hex.length !== 130) {
|
|
1658
|
+
throw new Error(
|
|
1659
|
+
`Unexpected signature length: ${hex.length} (expected 130)`
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
return {
|
|
1663
|
+
nonce: String(typedData.message.nonce ?? "0"),
|
|
1664
|
+
deadline: Number(typedData.message.deadline ?? 0),
|
|
1665
|
+
v: Number.parseInt(hex.slice(128, 130), 16),
|
|
1666
|
+
r: `0x${hex.slice(0, 64)}`,
|
|
1667
|
+
s: `0x${hex.slice(64, 128)}`
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Get relayer info needed for EIP-7702 execution.
|
|
1672
|
+
*/
|
|
1673
|
+
async getRelayerInfo(chainKey, address) {
|
|
1674
|
+
const [balanceInfo, executionNonce] = await Promise.all([
|
|
1675
|
+
this.relayerApi.getRelayerBalance(chainKey),
|
|
1676
|
+
this.relayerApi.getExecutionNonce(chainKey, address)
|
|
1677
|
+
]);
|
|
1678
|
+
return {
|
|
1679
|
+
relayerAddress: balanceInfo.relayer,
|
|
1680
|
+
executionNonce
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
/** Access chain config API */
|
|
1684
|
+
getChainConfigApi() {
|
|
1685
|
+
return this.chainConfigApi;
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
var EIP7702_DOMAIN_NAME = "Talken EIP7702 Delegate";
|
|
1689
|
+
var EIP7702_DOMAIN_VERSION = "1";
|
|
1690
|
+
function hashSingleBatchCall(target, calldata) {
|
|
1691
|
+
const calldataHash = keccak2562(calldata);
|
|
1692
|
+
const encoded = encodeAbiParameters(
|
|
1693
|
+
parseAbiParameters("address, uint256, bytes32"),
|
|
1694
|
+
[target, BigInt(0), calldataHash]
|
|
1695
|
+
);
|
|
1696
|
+
const callHash = keccak2562(encoded);
|
|
1697
|
+
return keccak2562(callHash);
|
|
1698
|
+
}
|
|
1699
|
+
function buildExecuteBatchWithFeeTypedData(params) {
|
|
1700
|
+
return {
|
|
1701
|
+
types: {
|
|
1702
|
+
EIP712Domain: [
|
|
1703
|
+
{ name: "name", type: "string" },
|
|
1704
|
+
{ name: "version", type: "string" },
|
|
1705
|
+
{ name: "chainId", type: "uint256" },
|
|
1706
|
+
{ name: "verifyingContract", type: "address" }
|
|
1707
|
+
],
|
|
1708
|
+
ExecuteBatchWithFee: [
|
|
1709
|
+
{ name: "router", type: "address" },
|
|
1710
|
+
{ name: "callsHash", type: "bytes32" },
|
|
1711
|
+
{ name: "feeToken", type: "address" },
|
|
1712
|
+
{ name: "feeAmount", type: "uint256" },
|
|
1713
|
+
{ name: "feeRecipient", type: "address" },
|
|
1714
|
+
{ name: "relayer", type: "address" },
|
|
1715
|
+
{ name: "nonce", type: "uint256" },
|
|
1716
|
+
{ name: "deadline", type: "uint256" }
|
|
1717
|
+
]
|
|
1718
|
+
},
|
|
1719
|
+
domain: {
|
|
1720
|
+
name: EIP7702_DOMAIN_NAME,
|
|
1721
|
+
version: EIP7702_DOMAIN_VERSION,
|
|
1722
|
+
chainId: params.chainId,
|
|
1723
|
+
verifyingContract: params.fromAddress
|
|
1724
|
+
},
|
|
1725
|
+
primaryType: "ExecuteBatchWithFee",
|
|
1726
|
+
message: {
|
|
1727
|
+
router: params.tokenAddress,
|
|
1728
|
+
callsHash: hashSingleBatchCall(
|
|
1729
|
+
params.tokenAddress,
|
|
1730
|
+
params.transferCalldata
|
|
1731
|
+
),
|
|
1732
|
+
feeToken: params.feeToken,
|
|
1733
|
+
feeAmount: params.feeAmount,
|
|
1734
|
+
feeRecipient: params.relayerAddress,
|
|
1735
|
+
relayer: params.relayerAddress,
|
|
1736
|
+
nonce: params.executionNonce,
|
|
1737
|
+
deadline: String(params.deadline)
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
function buildExecuteDelegatedSwapTypedData(params) {
|
|
1742
|
+
return {
|
|
1743
|
+
types: {
|
|
1744
|
+
EIP712Domain: [
|
|
1745
|
+
{ name: "name", type: "string" },
|
|
1746
|
+
{ name: "version", type: "string" },
|
|
1747
|
+
{ name: "chainId", type: "uint256" },
|
|
1748
|
+
{ name: "verifyingContract", type: "address" }
|
|
1749
|
+
],
|
|
1750
|
+
ExecuteDelegatedSwap: [
|
|
1751
|
+
{ name: "router", type: "address" },
|
|
1752
|
+
{ name: "token", type: "address" },
|
|
1753
|
+
{ name: "usePermit2", type: "bool" },
|
|
1754
|
+
{ name: "dataHash", type: "bytes32" },
|
|
1755
|
+
{ name: "relayer", type: "address" },
|
|
1756
|
+
{ name: "nonce", type: "uint256" },
|
|
1757
|
+
{ name: "deadline", type: "uint256" }
|
|
1758
|
+
]
|
|
1759
|
+
},
|
|
1760
|
+
domain: {
|
|
1761
|
+
name: EIP7702_DOMAIN_NAME,
|
|
1762
|
+
version: EIP7702_DOMAIN_VERSION,
|
|
1763
|
+
chainId: params.chainId,
|
|
1764
|
+
verifyingContract: params.fromAddress
|
|
1765
|
+
},
|
|
1766
|
+
primaryType: "ExecuteDelegatedSwap",
|
|
1767
|
+
message: {
|
|
1768
|
+
router: params.tokenAddress,
|
|
1769
|
+
token: params.tokenAddress,
|
|
1770
|
+
usePermit2: false,
|
|
1771
|
+
dataHash: keccak2562(params.transferCalldata),
|
|
1772
|
+
relayer: params.relayerAddress,
|
|
1773
|
+
nonce: params.executionNonce,
|
|
1774
|
+
deadline: String(params.deadline)
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
// src/gasless/services/PermitSignService.ts
|
|
1780
|
+
var PermitSignService = class {
|
|
1781
|
+
constructor(signer) {
|
|
1782
|
+
this.signer = signer;
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Sign all signature requests from the relayer's Phase 1 response.
|
|
1786
|
+
* Returns an array of signed signatures keyed by purpose.
|
|
1787
|
+
*/
|
|
1788
|
+
async signAll(requests) {
|
|
1789
|
+
const results = [];
|
|
1790
|
+
for (const req of requests) {
|
|
1791
|
+
const typedData = this.buildTypedData(req);
|
|
1792
|
+
const signature = await this.signer.signTypedData(typedData);
|
|
1793
|
+
results.push({
|
|
1794
|
+
purpose: req.purpose,
|
|
1795
|
+
...this.parseSignature(signature)
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
return results;
|
|
1799
|
+
}
|
|
1800
|
+
buildTypedData(req) {
|
|
1801
|
+
const typedData = {
|
|
1802
|
+
domain: req.domain,
|
|
1803
|
+
message: req.message,
|
|
1804
|
+
primaryType: req.primaryType ?? this.inferPrimaryType(req),
|
|
1805
|
+
types: {}
|
|
1806
|
+
};
|
|
1807
|
+
if (req.types) {
|
|
1808
|
+
typedData.types = {
|
|
1809
|
+
...req.types,
|
|
1810
|
+
EIP712Domain: [
|
|
1811
|
+
{ name: "name", type: "string" },
|
|
1812
|
+
{ name: "version", type: "string" },
|
|
1813
|
+
{ name: "chainId", type: "uint256" },
|
|
1814
|
+
{ name: "verifyingContract", type: "address" }
|
|
1815
|
+
]
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
return typedData;
|
|
1819
|
+
}
|
|
1820
|
+
inferPrimaryType(req) {
|
|
1821
|
+
switch (req.type) {
|
|
1822
|
+
case "eip3009":
|
|
1823
|
+
return "TransferWithAuthorization";
|
|
1824
|
+
case "erc2612":
|
|
1825
|
+
return "Permit";
|
|
1826
|
+
case "eip712":
|
|
1827
|
+
return "RelayRequest";
|
|
1828
|
+
default:
|
|
1829
|
+
return "RelayRequest";
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
parseSignature(sig) {
|
|
1833
|
+
if (!sig || sig === "0x") {
|
|
1834
|
+
return { raw: sig };
|
|
1835
|
+
}
|
|
1836
|
+
const hex = sig.startsWith("0x") ? sig.slice(2) : sig;
|
|
1837
|
+
if (hex.length === 130) {
|
|
1838
|
+
const r = `0x${hex.slice(0, 64)}`;
|
|
1839
|
+
const s = `0x${hex.slice(64, 128)}`;
|
|
1840
|
+
const v = Number.parseInt(hex.slice(128, 130), 16);
|
|
1841
|
+
return { v, r, s };
|
|
1842
|
+
}
|
|
1843
|
+
return { raw: sig };
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
// src/gasless/services/GaslessTransferService.ts
|
|
1848
|
+
var ZERO_ADDRESS3 = "0x0000000000000000000000000000000000000000";
|
|
1849
|
+
var RelayPhase2Error = class extends Error {
|
|
1850
|
+
constructor(requestId, cause) {
|
|
1851
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
1852
|
+
super(
|
|
1853
|
+
`Relay Phase 2 failed (requestId: ${requestId}). The transaction may have been submitted on-chain. Check the explorer before retrying. Original: ${message}`
|
|
1854
|
+
);
|
|
1855
|
+
this.name = "RelayPhase2Error";
|
|
1856
|
+
this.requestId = requestId;
|
|
1857
|
+
this.originalError = cause;
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
var GaslessTransferService = class {
|
|
1861
|
+
constructor(deps) {
|
|
1862
|
+
this.relayerApi = deps.relayerApi ?? new RelayerApi();
|
|
1863
|
+
this.signer = deps.signer;
|
|
1864
|
+
this.walletClient = deps.walletClient;
|
|
1865
|
+
this.permitService = new PermitSignService(deps.signer);
|
|
1866
|
+
this.eip7702Service = deps.eip7702Service ?? new Eip7702Service({
|
|
1867
|
+
relayerApi: this.relayerApi,
|
|
1868
|
+
signer: deps.signer
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
async execute(params, gaslessConfig) {
|
|
1872
|
+
switch (params.gaslessMode) {
|
|
1873
|
+
case "generic":
|
|
1874
|
+
return this.executeGenericRelay(params);
|
|
1875
|
+
case "eip7702-fee":
|
|
1876
|
+
case "eip7702-points":
|
|
1877
|
+
return this.executeEip7702Relay(params, gaslessConfig);
|
|
1878
|
+
default:
|
|
1879
|
+
throw new Error(`Unknown gasless mode: ${params.gaslessMode}`);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Generic 2-phase relay execution.
|
|
1884
|
+
*
|
|
1885
|
+
* Phase 1: POST /relayer/execute { auth: { method: 'auto' } }
|
|
1886
|
+
* → Server responds with signatureRequests
|
|
1887
|
+
* Phase 2: Sign all requests → POST /relayer/execute { requestId, signatures }
|
|
1888
|
+
* → Server responds with txHash
|
|
1889
|
+
*/
|
|
1890
|
+
async executeGenericRelay(params) {
|
|
1891
|
+
try {
|
|
1892
|
+
await this.eip7702Service.preflight(
|
|
1893
|
+
params.chainKey,
|
|
1894
|
+
params.chainId,
|
|
1895
|
+
params.fromAddress,
|
|
1896
|
+
{ walletClient: this.walletClient }
|
|
1897
|
+
);
|
|
1898
|
+
} catch (err) {
|
|
1899
|
+
console.warn(
|
|
1900
|
+
"[GaslessTransferService] Preflight check failed (non-blocking):",
|
|
1901
|
+
err
|
|
1902
|
+
);
|
|
1903
|
+
}
|
|
1904
|
+
const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
1905
|
+
const feeMaxAmount = (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
|
|
1906
|
+
const baseRequest = {
|
|
1907
|
+
chainKey: params.chainKey,
|
|
1908
|
+
user: params.fromAddress,
|
|
1909
|
+
tokenIn: params.tokenAddress,
|
|
1910
|
+
amountIn: params.amount,
|
|
1911
|
+
target: ZERO_ADDRESS3,
|
|
1912
|
+
targetCalldata: "0x",
|
|
1913
|
+
tokenOut: ZERO_ADDRESS3,
|
|
1914
|
+
minAmountOut: "0",
|
|
1915
|
+
recipient: params.toAddress,
|
|
1916
|
+
deadline,
|
|
1917
|
+
fee: {
|
|
1918
|
+
token: params.feeToken.symbol,
|
|
1919
|
+
amount: params.feeAmountRaw,
|
|
1920
|
+
maxAmount: feeMaxAmount
|
|
1921
|
+
},
|
|
1922
|
+
auth: { method: "auto" }
|
|
1923
|
+
};
|
|
1924
|
+
const phase1 = await this.relayerApi.execute(baseRequest);
|
|
1925
|
+
if (phase1.phase !== "sign") {
|
|
1926
|
+
return this.extractResult(phase1, params);
|
|
1927
|
+
}
|
|
1928
|
+
const signatures = await this.permitService.signAll(
|
|
1929
|
+
phase1.signatureRequests
|
|
1930
|
+
);
|
|
1931
|
+
let phase2;
|
|
1932
|
+
try {
|
|
1933
|
+
phase2 = await this.relayerApi.execute({
|
|
1934
|
+
...baseRequest,
|
|
1935
|
+
requestId: phase1.requestId,
|
|
1936
|
+
signatures
|
|
1937
|
+
});
|
|
1938
|
+
} catch (err) {
|
|
1939
|
+
throw new RelayPhase2Error(phase1.requestId, err);
|
|
1940
|
+
}
|
|
1941
|
+
return this.extractResult(phase2, params);
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* EIP-7702 relay execution (fee or points mode).
|
|
1945
|
+
*
|
|
1946
|
+
* 1. Pre-flight delegation check
|
|
1947
|
+
* 2. Sign delegate authorization
|
|
1948
|
+
* 3. Get relayer info (address + execution nonce)
|
|
1949
|
+
* 4. Build and sign execution typed data
|
|
1950
|
+
* 5. Submit to relayer
|
|
1951
|
+
* 6. On failure: cleanup delegation
|
|
1952
|
+
*/
|
|
1953
|
+
async executeEip7702Relay(params, gaslessConfig) {
|
|
1954
|
+
await this.eip7702Service.preflight(
|
|
1955
|
+
params.chainKey,
|
|
1956
|
+
params.chainId,
|
|
1957
|
+
params.fromAddress,
|
|
1958
|
+
{
|
|
1959
|
+
walletClient: this.walletClient,
|
|
1960
|
+
onDelegationError: gaslessConfig.onDelegationError
|
|
1961
|
+
}
|
|
1962
|
+
);
|
|
1963
|
+
try {
|
|
1964
|
+
const { delegateAuth } = await this.eip7702Service.signDelegate(
|
|
1965
|
+
params.chainKey,
|
|
1966
|
+
params.chainId,
|
|
1967
|
+
params.fromAddress
|
|
1968
|
+
);
|
|
1969
|
+
const { relayerAddress, executionNonce } = await this.eip7702Service.getRelayerInfo(
|
|
1970
|
+
params.chainKey,
|
|
1971
|
+
params.fromAddress
|
|
1972
|
+
);
|
|
1973
|
+
const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
1974
|
+
const isPointsMode = params.gaslessMode === "eip7702-points";
|
|
1975
|
+
const transferCalldata = this.encodeErc20Transfer(
|
|
1976
|
+
params.toAddress,
|
|
1977
|
+
params.amount
|
|
1978
|
+
);
|
|
1979
|
+
const executionTypedData = isPointsMode ? buildExecuteDelegatedSwapTypedData({
|
|
1980
|
+
chainId: params.chainId,
|
|
1981
|
+
fromAddress: params.fromAddress,
|
|
1982
|
+
tokenAddress: params.tokenAddress,
|
|
1983
|
+
transferCalldata,
|
|
1984
|
+
executionNonce,
|
|
1985
|
+
deadline,
|
|
1986
|
+
relayerAddress
|
|
1987
|
+
}) : buildExecuteBatchWithFeeTypedData({
|
|
1988
|
+
chainId: params.chainId,
|
|
1989
|
+
fromAddress: params.fromAddress,
|
|
1990
|
+
tokenAddress: params.tokenAddress,
|
|
1991
|
+
transferCalldata,
|
|
1992
|
+
executionNonce,
|
|
1993
|
+
deadline,
|
|
1994
|
+
relayerAddress,
|
|
1995
|
+
feeToken: params.feeToken.address,
|
|
1996
|
+
feeAmount: params.feeAmountRaw
|
|
1997
|
+
});
|
|
1998
|
+
const executionAuth = await this.eip7702Service.signExecutionTypedData(executionTypedData);
|
|
1999
|
+
const feeAmount = isPointsMode ? "0" : params.feeAmountRaw;
|
|
2000
|
+
const feeMaxAmount = isPointsMode ? "0" : (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
|
|
2001
|
+
const result = await this.relayerApi.execute({
|
|
2002
|
+
chainKey: params.chainKey,
|
|
2003
|
+
user: params.fromAddress,
|
|
2004
|
+
tokenIn: params.tokenAddress,
|
|
2005
|
+
amountIn: params.amount,
|
|
2006
|
+
target: params.tokenAddress,
|
|
2007
|
+
targetCalldata: transferCalldata,
|
|
2008
|
+
tokenOut: ZERO_ADDRESS3,
|
|
2009
|
+
minAmountOut: "0",
|
|
2010
|
+
recipient: params.toAddress,
|
|
2011
|
+
deadline,
|
|
2012
|
+
fee: {
|
|
2013
|
+
token: isPointsMode ? "USDC" : params.feeToken.symbol,
|
|
2014
|
+
amount: feeAmount,
|
|
2015
|
+
maxAmount: feeMaxAmount
|
|
2016
|
+
},
|
|
2017
|
+
auth: {
|
|
2018
|
+
method: "eip7702",
|
|
2019
|
+
usePermit2: false,
|
|
2020
|
+
authorization: delegateAuth,
|
|
2021
|
+
executionAuth
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
return this.extractResult(result, params);
|
|
2025
|
+
} catch (error) {
|
|
2026
|
+
try {
|
|
2027
|
+
await ensureDelegationCleared(
|
|
2028
|
+
params.chainKey,
|
|
2029
|
+
params.chainId,
|
|
2030
|
+
params.fromAddress,
|
|
2031
|
+
{
|
|
2032
|
+
walletClient: this.walletClient,
|
|
2033
|
+
onDelegationError: gaslessConfig.onDelegationError
|
|
2034
|
+
}
|
|
2035
|
+
);
|
|
2036
|
+
} catch (cleanupError) {
|
|
2037
|
+
console.error(
|
|
2038
|
+
"[GaslessTransferService] Post-failure delegation cleanup failed:",
|
|
2039
|
+
cleanupError
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
throw error;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
extractResult(response, params) {
|
|
2046
|
+
if (response.phase === "sign") {
|
|
2047
|
+
throw new Error("Unexpected sign phase in final response");
|
|
2048
|
+
}
|
|
2049
|
+
if (response.error) {
|
|
2050
|
+
const err = new Error(
|
|
2051
|
+
`Relay failed: ${response.error.code}: ${response.error.message}`
|
|
2052
|
+
);
|
|
2053
|
+
err.txHash = response.data?.txHash ?? "";
|
|
2054
|
+
throw err;
|
|
2055
|
+
}
|
|
2056
|
+
const txHash = response.data?.txHash ?? response.txHash;
|
|
2057
|
+
if (!txHash) {
|
|
2058
|
+
throw new Error("Relay did not return txHash");
|
|
2059
|
+
}
|
|
2060
|
+
return {
|
|
2061
|
+
txHash,
|
|
2062
|
+
gaslessMode: params.gaslessMode,
|
|
2063
|
+
feeToken: params.feeToken.symbol,
|
|
2064
|
+
feeAmount: params.feeAmountRaw,
|
|
2065
|
+
cleanup: response.data?.cleanup
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
/** Encode ERC-20 transfer(address,uint256) calldata */
|
|
2069
|
+
encodeErc20Transfer(to, amount) {
|
|
2070
|
+
if (!isAddress2(to)) {
|
|
2071
|
+
throw new Error(`Invalid recipient address: ${to}`);
|
|
2072
|
+
}
|
|
2073
|
+
return encodeFunctionData({
|
|
2074
|
+
abi: erc20Abi,
|
|
2075
|
+
functionName: "transfer",
|
|
2076
|
+
args: [to, BigInt(amount)]
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
};
|
|
2080
|
+
|
|
2081
|
+
// src/gasless/signer/AbcWaasSigner.ts
|
|
2082
|
+
var MAX_SIGN_ATTEMPTS = 3;
|
|
2083
|
+
var RETRY_BASE_MS = 500;
|
|
2084
|
+
function sleep(ms) {
|
|
2085
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2086
|
+
}
|
|
2087
|
+
var AbcWaasSigner = class {
|
|
2088
|
+
constructor(params) {
|
|
2089
|
+
this.pinHash = params.pinHash;
|
|
2090
|
+
this.network = params.network;
|
|
2091
|
+
this.email = params.email;
|
|
2092
|
+
}
|
|
2093
|
+
supportsAuthorization() {
|
|
2094
|
+
return true;
|
|
2095
|
+
}
|
|
2096
|
+
async signTypedData(typedData) {
|
|
2097
|
+
const api = this.getApiOrThrow();
|
|
2098
|
+
let lastError = null;
|
|
2099
|
+
for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
|
|
2100
|
+
try {
|
|
2101
|
+
const result = await api.evm.signTypedData({
|
|
2102
|
+
network: this.network,
|
|
2103
|
+
typedData: JSON.stringify(typedData),
|
|
2104
|
+
...this.pinHash && { pin: this.pinHash },
|
|
2105
|
+
...this.email && { email: this.email }
|
|
2106
|
+
});
|
|
2107
|
+
const sig = typeof result === "string" ? result : result?.signature ?? result?.result;
|
|
2108
|
+
if (sig)
|
|
2109
|
+
return sig;
|
|
2110
|
+
throw new Error("signTypedData returned empty signature");
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2113
|
+
if (attempt < MAX_SIGN_ATTEMPTS - 1) {
|
|
2114
|
+
await sleep(RETRY_BASE_MS * 2 ** attempt);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
throw lastError ?? new Error("Failed to sign typed data");
|
|
2119
|
+
}
|
|
2120
|
+
async signAuthorization(authorization) {
|
|
2121
|
+
const api = this.getApiOrThrow();
|
|
2122
|
+
let lastError = null;
|
|
2123
|
+
for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
|
|
2124
|
+
try {
|
|
2125
|
+
const result = await api.evm.signAuthorization({
|
|
2126
|
+
network: this.network,
|
|
2127
|
+
authorization: {
|
|
2128
|
+
chainId: authorization.chainId,
|
|
2129
|
+
address: authorization.address,
|
|
2130
|
+
nonce: String(authorization.nonce)
|
|
2131
|
+
},
|
|
2132
|
+
...this.pinHash && { pin: this.pinHash },
|
|
2133
|
+
...this.email && { email: this.email }
|
|
2134
|
+
});
|
|
2135
|
+
const auth = result?.authorization ?? result;
|
|
2136
|
+
if (!auth?.r || !auth?.s) {
|
|
2137
|
+
throw new Error("signAuthorization returned empty r/s");
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
chainId: authorization.chainId,
|
|
2141
|
+
address: authorization.address,
|
|
2142
|
+
nonce: authorization.nonce,
|
|
2143
|
+
yParity: normalizeYParity(auth.yParity ?? auth.v),
|
|
2144
|
+
r: auth.r,
|
|
2145
|
+
s: auth.s
|
|
2146
|
+
};
|
|
2147
|
+
} catch (error) {
|
|
2148
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2149
|
+
if (attempt < MAX_SIGN_ATTEMPTS - 1) {
|
|
2150
|
+
await sleep(RETRY_BASE_MS * 2 ** attempt);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
throw lastError ?? new Error("Failed to sign authorization");
|
|
2155
|
+
}
|
|
2156
|
+
async getNonce(address) {
|
|
2157
|
+
const api = this.getApiOrThrow();
|
|
2158
|
+
const nonceResult = await api.evm.getNonce(this.network, address);
|
|
2159
|
+
const raw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
|
|
2160
|
+
const nonce = Number(raw);
|
|
2161
|
+
if (!Number.isFinite(nonce)) {
|
|
2162
|
+
throw new Error("Failed to resolve wallet nonce");
|
|
2163
|
+
}
|
|
2164
|
+
return nonce;
|
|
2165
|
+
}
|
|
2166
|
+
getApiOrThrow() {
|
|
2167
|
+
const api = getTalkenApiClient();
|
|
2168
|
+
if (!api)
|
|
2169
|
+
throw new Error("TalkenApiClient not initialized");
|
|
2170
|
+
return api;
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
function normalizeYParity(value) {
|
|
2174
|
+
if (value === void 0 || value === null)
|
|
2175
|
+
return 0;
|
|
2176
|
+
if (value === 27)
|
|
2177
|
+
return 0;
|
|
2178
|
+
if (value === 28)
|
|
2179
|
+
return 1;
|
|
2180
|
+
if (value === 0 || value === 1)
|
|
2181
|
+
return value;
|
|
2182
|
+
throw new Error(
|
|
2183
|
+
`Invalid yParity/v value: ${value}. Expected 0, 1, 27, or 28.`
|
|
2184
|
+
);
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
// src/gasless/utils/transferDetector.ts
|
|
2188
|
+
var ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
2189
|
+
var MIN_TRANSFER_DATA_LENGTH = 138;
|
|
2190
|
+
function detectErc20Transfer(data) {
|
|
2191
|
+
if (!data || data.length < MIN_TRANSFER_DATA_LENGTH)
|
|
2192
|
+
return null;
|
|
2193
|
+
const selector = data.slice(0, 10).toLowerCase();
|
|
2194
|
+
if (selector !== ERC20_TRANSFER_SELECTOR)
|
|
2195
|
+
return null;
|
|
2196
|
+
try {
|
|
2197
|
+
const toHex2 = data.slice(10, 74);
|
|
2198
|
+
const amountHex = data.slice(74, 138);
|
|
2199
|
+
const to = `0x${toHex2.slice(24)}`;
|
|
2200
|
+
const amount = BigInt(`0x${amountHex}`).toString();
|
|
2201
|
+
if (to.length !== 42)
|
|
2202
|
+
return null;
|
|
2203
|
+
return { to, amount };
|
|
2204
|
+
} catch {
|
|
2205
|
+
return null;
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
function isGaslessEligible(tx) {
|
|
2209
|
+
if (!tx.to || tx.to === "0x" || tx.to === "0x0")
|
|
2210
|
+
return false;
|
|
2211
|
+
const ZERO_ADDR = "0x0000000000000000000000000000000000000000";
|
|
2212
|
+
if (tx.to.toLowerCase() === ZERO_ADDR)
|
|
2213
|
+
return false;
|
|
2214
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(tx.to))
|
|
2215
|
+
return false;
|
|
2216
|
+
if (tx.value && tx.value !== "0x0" && tx.value !== "0x" && tx.value !== "0") {
|
|
2217
|
+
try {
|
|
2218
|
+
if (BigInt(tx.value) > BigInt(0))
|
|
2219
|
+
return false;
|
|
2220
|
+
} catch {
|
|
2221
|
+
return false;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
const transfer = detectErc20Transfer(tx.data);
|
|
2225
|
+
if (!transfer)
|
|
2226
|
+
return false;
|
|
2227
|
+
if (transfer.amount === "0")
|
|
2228
|
+
return false;
|
|
2229
|
+
return true;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
// src/wallets/walletConnectors/abcWallet/abcProvider.ts
|
|
2233
|
+
var logger = createLogger("AbcProvider");
|
|
2234
|
+
var AbcEvmProvider = class extends AbstractChainProvider {
|
|
2235
|
+
constructor() {
|
|
2236
|
+
super(...arguments);
|
|
2237
|
+
this.chainId = 1;
|
|
2238
|
+
// Default to Ethereum mainnet
|
|
2239
|
+
// Gasless: shared singleton preserves cooldown state across all callers
|
|
2240
|
+
this._sharedRelayerApi = new RelayerApi();
|
|
2241
|
+
this.gaslessFeeService = getSharedGaslessFeeService();
|
|
2242
|
+
this.gaslessLock = Promise.resolve();
|
|
2243
|
+
}
|
|
2244
|
+
getRecoveryEmail() {
|
|
2245
|
+
const walletEmail = this.wallet?.email?.trim();
|
|
2246
|
+
if (walletEmail) {
|
|
2247
|
+
return walletEmail;
|
|
2248
|
+
}
|
|
2249
|
+
return getCredentialManager().getEmail() || void 0;
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Set wallet — EVM override for chainId tracking + chainChanged event
|
|
2253
|
+
*/
|
|
2254
|
+
setWallet(wallet) {
|
|
2255
|
+
const previousChainId = this.chainId;
|
|
2256
|
+
this.chainId = wallet.chainId;
|
|
2257
|
+
super.setWallet(wallet);
|
|
2258
|
+
if (previousChainId !== wallet.chainId) {
|
|
2259
|
+
this.emit("chainChanged", numberToHex(wallet.chainId));
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
onWalletSet(wallet) {
|
|
2263
|
+
this.emit("connect", { chainId: numberToHex(wallet.chainId) });
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Clear wallet — override to reset gasless state
|
|
2267
|
+
*/
|
|
2268
|
+
clearWallet() {
|
|
2269
|
+
this.gaslessFeeService.clearCache();
|
|
2270
|
+
this.gaslessLock = Promise.resolve();
|
|
2271
|
+
super.clearWallet();
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Check if an error is a "Missing required wallet fields" 502 from the server.
|
|
2275
|
+
* When the server's in-memory signing credential cache is cold, it needs
|
|
2276
|
+
* a wallet.generate() call (idempotent create/recover) to repopulate.
|
|
2277
|
+
*/
|
|
2278
|
+
isSigningCredentialError(error) {
|
|
2279
|
+
return error instanceof TalkenApiError && error.statusCode === 502 && error.message.includes("Missing required wallet fields");
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Refresh server-side signing credentials.
|
|
2283
|
+
*
|
|
2284
|
+
* Strategy (in priority order):
|
|
2285
|
+
* 1. PIN hash in memory → wallet.generate() to repopulate server cache
|
|
2286
|
+
* 2. Neither available → throw UNAUTHORIZED
|
|
2287
|
+
*
|
|
2288
|
+
* Note: sessionStorage-cached credentials (evmCreds) are automatically
|
|
2289
|
+
* attached to every signing request by TalkenApiClient, so the server
|
|
2290
|
+
* can use them as fallback without a separate refresh call.
|
|
2291
|
+
*/
|
|
2292
|
+
async refreshSigningCredentials() {
|
|
2293
|
+
const credMgr = getCredentialManager();
|
|
2294
|
+
const pinHash = credMgr.getPinHash();
|
|
2295
|
+
const email = this.getRecoveryEmail();
|
|
2296
|
+
if (pinHash && email) {
|
|
2297
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2298
|
+
logger.info("Refreshing signing credentials via wallet.generate...");
|
|
2299
|
+
await api.wallet.generate(pinHash, email);
|
|
2300
|
+
logger.info("Signing credentials refreshed via PIN");
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
logger.warn(
|
|
2304
|
+
"Cannot refresh signing credentials \u2014 PIN hash or email missing"
|
|
2305
|
+
);
|
|
2306
|
+
throw new ProviderRpcError(
|
|
2307
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2308
|
+
"Session expired. Please reconnect and verify your PIN."
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Wrap a signing operation with auto-retry on "Missing required wallet fields" error.
|
|
2313
|
+
* On first failure, refreshes the server's signing credential cache and retries once.
|
|
2314
|
+
*/
|
|
2315
|
+
async withSigningCredentialRetry(operation) {
|
|
2316
|
+
try {
|
|
2317
|
+
return await operation();
|
|
2318
|
+
} catch (error) {
|
|
2319
|
+
if (this.isSigningCredentialError(error)) {
|
|
2320
|
+
logger.info(
|
|
2321
|
+
"Signing credentials missing on server \u2014 attempting refresh and retry"
|
|
2322
|
+
);
|
|
2323
|
+
await this.refreshSigningCredentials();
|
|
2324
|
+
return await operation();
|
|
2325
|
+
}
|
|
2326
|
+
throw error;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Call request interceptor if configured
|
|
2331
|
+
* Called by specific signing/transaction methods that need user confirmation
|
|
2332
|
+
* @returns Resolved transaction with user modifications if changed in confirmation modal
|
|
2333
|
+
*/
|
|
2334
|
+
async callInterceptor(method, params) {
|
|
2335
|
+
if (!this.requestInterceptor) {
|
|
2336
|
+
return void 0;
|
|
2337
|
+
}
|
|
2338
|
+
const request = {
|
|
2339
|
+
method,
|
|
2340
|
+
params,
|
|
2341
|
+
chainId: this.chainId,
|
|
2342
|
+
address: this.wallet?.address || ""
|
|
2343
|
+
};
|
|
2344
|
+
return this.requestInterceptor(request);
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* EIP-1193 request method
|
|
2348
|
+
*/
|
|
2349
|
+
async request(args) {
|
|
2350
|
+
const { method, params } = args;
|
|
2351
|
+
switch (method) {
|
|
2352
|
+
case "eth_requestAccounts":
|
|
2353
|
+
return this.eth_requestAccounts();
|
|
2354
|
+
case "eth_accounts":
|
|
2355
|
+
return this.eth_accounts();
|
|
2356
|
+
case "eth_chainId":
|
|
2357
|
+
return this.eth_chainId();
|
|
2358
|
+
case "eth_sendTransaction":
|
|
2359
|
+
case "wallet_sendTransaction":
|
|
2360
|
+
return this.eth_sendTransaction(params);
|
|
2361
|
+
case "eth_signTransaction":
|
|
2362
|
+
return this.eth_signTransaction(params);
|
|
2363
|
+
case "personal_sign":
|
|
2364
|
+
return this.personal_sign(params);
|
|
2365
|
+
case "eth_sign":
|
|
2366
|
+
return this.eth_sign(params);
|
|
2367
|
+
case "eth_signTypedData":
|
|
2368
|
+
case "eth_signTypedData_v3":
|
|
2369
|
+
case "eth_signTypedData_v4":
|
|
2370
|
+
return this.eth_signTypedData(params);
|
|
2371
|
+
case "wallet_getCapabilities":
|
|
2372
|
+
return this.wallet_getCapabilities();
|
|
2373
|
+
case "eth_signAuthorization":
|
|
2374
|
+
return this.eth_signAuthorization(params);
|
|
2375
|
+
case "wallet_switchEthereumChain":
|
|
2376
|
+
return this.wallet_switchEthereumChain(params);
|
|
2377
|
+
case "wallet_addEthereumChain":
|
|
2378
|
+
return this.wallet_addEthereumChain(params);
|
|
2379
|
+
case "eth_estimateGas":
|
|
2380
|
+
return this.eth_estimateGas(params);
|
|
2381
|
+
case "eth_getTransactionCount":
|
|
2382
|
+
return this.eth_getTransactionCount(
|
|
2383
|
+
Array.isArray(params) ? params : []
|
|
2384
|
+
);
|
|
2385
|
+
case "eth_call":
|
|
2386
|
+
return this.eth_call(params);
|
|
2387
|
+
case "eth_getBalance":
|
|
2388
|
+
return this.eth_getBalance(params);
|
|
2389
|
+
case "eth_blockNumber":
|
|
2390
|
+
case "eth_gasPrice":
|
|
2391
|
+
case "eth_getBlockByHash":
|
|
2392
|
+
case "eth_getBlockByNumber":
|
|
2393
|
+
case "eth_getCode":
|
|
2394
|
+
case "eth_getStorageAt":
|
|
2395
|
+
case "eth_getTransactionByHash":
|
|
2396
|
+
case "eth_getTransactionReceipt":
|
|
2397
|
+
throw new ProviderRpcError(
|
|
2398
|
+
ProviderErrorCode.UNSUPPORTED_METHOD,
|
|
2399
|
+
`Method ${method} should be handled by RPC provider`
|
|
2400
|
+
);
|
|
2401
|
+
default:
|
|
2402
|
+
throw new ProviderRpcError(
|
|
2403
|
+
ProviderErrorCode.UNSUPPORTED_METHOD,
|
|
2404
|
+
`Method ${method} not supported`
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Request accounts (EIP-1193)
|
|
2410
|
+
*/
|
|
2411
|
+
async eth_requestAccounts() {
|
|
2412
|
+
if (!this.wallet) {
|
|
2413
|
+
throw new ProviderRpcError(
|
|
2414
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2415
|
+
"Wallet not connected"
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
return [this.wallet.address];
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Get accounts
|
|
2422
|
+
*/
|
|
2423
|
+
async eth_accounts() {
|
|
2424
|
+
if (!this.wallet) {
|
|
2425
|
+
return [];
|
|
2426
|
+
}
|
|
2427
|
+
return [this.wallet.address];
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Get chain ID
|
|
2431
|
+
*/
|
|
2432
|
+
async eth_chainId() {
|
|
2433
|
+
return numberToHex(this.chainId);
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* Send transaction
|
|
2437
|
+
*/
|
|
2438
|
+
async eth_sendTransaction(params) {
|
|
2439
|
+
if (!this.wallet) {
|
|
2440
|
+
throw new ProviderRpcError(
|
|
2441
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2442
|
+
"Wallet not connected"
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
2446
|
+
throw new ProviderRpcError(
|
|
2447
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2448
|
+
"Invalid transaction params"
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2451
|
+
const resolved = await this.callInterceptor("eth_sendTransaction", params);
|
|
2452
|
+
const tx = params[0];
|
|
2453
|
+
logger.debug("eth_sendTransaction incoming gas params:", {
|
|
2454
|
+
gas: tx.gas ?? tx.gasLimit,
|
|
2455
|
+
gasPrice: tx.gasPrice,
|
|
2456
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
2457
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
2458
|
+
});
|
|
2459
|
+
if (resolved) {
|
|
2460
|
+
if (resolved.data) {
|
|
2461
|
+
tx.data = resolved.data;
|
|
2462
|
+
}
|
|
2463
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
2464
|
+
try {
|
|
2465
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
2466
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
2467
|
+
} catch (error) {
|
|
2468
|
+
logger.error("Failed to parse maxFeePerGas:", error);
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
2472
|
+
try {
|
|
2473
|
+
const priorityFeeWei = parseGwei(
|
|
2474
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
2475
|
+
);
|
|
2476
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
2477
|
+
} catch (error) {
|
|
2478
|
+
logger.error("Failed to parse maxPriorityFeePerGas:", error);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
logger.debug("eth_sendTransaction final gas params:", {
|
|
2483
|
+
gas: tx.gas ?? tx.gasLimit,
|
|
2484
|
+
gasPrice: tx.gasPrice,
|
|
2485
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
2486
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
2487
|
+
});
|
|
2488
|
+
const isContractDeployment = !tx.to || tx.to === "0x" || tx.to === "0x0" || tx.to === "0x0000000000000000000000000000000000000000";
|
|
2489
|
+
if (isContractDeployment) {
|
|
2490
|
+
tx.to = "0x";
|
|
2491
|
+
} else if (!tx.to) {
|
|
2492
|
+
throw new ProviderRpcError(
|
|
2493
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2494
|
+
'Transaction must have "to" field'
|
|
2495
|
+
);
|
|
2496
|
+
}
|
|
2497
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2498
|
+
const pinHash = api.isAccessKeyMode() ? void 0 : getCredentialManager().getPinHash() || void 0;
|
|
2499
|
+
if (!pinHash && !api.isAccessKeyMode()) {
|
|
2500
|
+
throw new ProviderRpcError(
|
|
2501
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
2502
|
+
"PIN hash not found. Please login again."
|
|
2503
|
+
);
|
|
2504
|
+
}
|
|
2505
|
+
const email = this.getRecoveryEmail();
|
|
2506
|
+
const chainKey = getChainKey(this.chainId);
|
|
2507
|
+
const gaslessConfig = getGaslessConfig();
|
|
2508
|
+
const preEstimatedFee = resolved?.gaslessInfo?.canGasless ? resolved.gaslessInfo.feeEstimate : void 0;
|
|
2509
|
+
this.showPendingTx({ network: chainKey, chain: "evm" });
|
|
2510
|
+
const shouldTryGasless = (preEstimatedFee || gaslessConfig?.enabled) && isGaslessEligible(tx);
|
|
2511
|
+
if (shouldTryGasless) {
|
|
2512
|
+
const effectiveConfig = gaslessConfig ?? { enabled: true };
|
|
2513
|
+
const attempt = this.gaslessLock.catch(() => {
|
|
2514
|
+
}).then(
|
|
2515
|
+
() => this.tryGaslessTransfer(
|
|
2516
|
+
tx,
|
|
2517
|
+
chainKey,
|
|
2518
|
+
pinHash,
|
|
2519
|
+
email,
|
|
2520
|
+
effectiveConfig,
|
|
2521
|
+
preEstimatedFee
|
|
2522
|
+
)
|
|
2523
|
+
);
|
|
2524
|
+
this.gaslessLock = attempt;
|
|
2525
|
+
try {
|
|
2526
|
+
const gaslessResult = await attempt;
|
|
2527
|
+
if (gaslessResult)
|
|
2528
|
+
return gaslessResult;
|
|
2529
|
+
} catch (gaslessError) {
|
|
2530
|
+
const failedTxHash = gaslessError?.txHash || "";
|
|
2531
|
+
this.updateTxResult({
|
|
2532
|
+
txHash: failedTxHash,
|
|
2533
|
+
network: chainKey,
|
|
2534
|
+
chain: "evm",
|
|
2535
|
+
receipt: { status: 0, blockNumber: null, gasUsed: null },
|
|
2536
|
+
...failedTxHash && {
|
|
2537
|
+
explorerUrl: getExplorerTxUrl(this.chainId, failedTxHash)
|
|
2538
|
+
}
|
|
2539
|
+
});
|
|
2540
|
+
console.error("[AbcProvider] Gasless relay failed:", gaslessError);
|
|
2541
|
+
if (failedTxHash)
|
|
2542
|
+
return failedTxHash;
|
|
2543
|
+
throw gaslessError;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
const rawValue = tx.value || "0x0";
|
|
2547
|
+
const hexValue = rawValue === "0x" ? "0x0" : rawValue;
|
|
2548
|
+
const amountWei = BigInt(hexValue).toString();
|
|
2549
|
+
try {
|
|
2550
|
+
const gasLimit = tx.gas || tx.gasLimit;
|
|
2551
|
+
const result = await this.withSigningCredentialRetry(
|
|
2552
|
+
() => api.evm.sendTransaction({
|
|
2553
|
+
chainKey,
|
|
2554
|
+
to: tx.to,
|
|
2555
|
+
amountWei,
|
|
2556
|
+
pin: pinHash,
|
|
2557
|
+
data: tx.data || "0x",
|
|
2558
|
+
waitForReceipt: true,
|
|
2559
|
+
...gasLimit && { gasLimit },
|
|
2560
|
+
...tx.gasPrice && { gasPrice: tx.gasPrice },
|
|
2561
|
+
...tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas },
|
|
2562
|
+
...tx.maxPriorityFeePerGas && {
|
|
2563
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
2564
|
+
},
|
|
2565
|
+
...email && { email }
|
|
2566
|
+
})
|
|
2567
|
+
);
|
|
2568
|
+
this.updateTxResult({
|
|
2569
|
+
txHash: result.txHash,
|
|
2570
|
+
network: chainKey,
|
|
2571
|
+
chain: "evm",
|
|
2572
|
+
receipt: result.receipt,
|
|
2573
|
+
explorerUrl: getExplorerTxUrl(this.chainId, result.txHash)
|
|
2574
|
+
});
|
|
2575
|
+
return result.txHash;
|
|
2576
|
+
} catch (error) {
|
|
2577
|
+
this.failTxResult({
|
|
2578
|
+
network: chainKey,
|
|
2579
|
+
chain: "evm",
|
|
2580
|
+
errorMessage: error.message
|
|
2581
|
+
});
|
|
2582
|
+
throw error;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Attempt gasless relay for an ERC-20 transfer.
|
|
2587
|
+
*
|
|
2588
|
+
* Return semantics (important for double-spend prevention):
|
|
2589
|
+
* - `string` → success, txHash returned
|
|
2590
|
+
* - `null` → estimation found no viable mode, caller should fall back to normal gas
|
|
2591
|
+
* - `throw` → relay execution was attempted and failed, caller must NOT fall back
|
|
2592
|
+
*/
|
|
2593
|
+
async tryGaslessTransfer(tx, chainKey, pinHash, email, gaslessConfig, preEstimatedFee) {
|
|
2594
|
+
const detected = detectErc20Transfer(tx.data);
|
|
2595
|
+
if (!detected)
|
|
2596
|
+
return null;
|
|
2597
|
+
let feeEstimate = preEstimatedFee ?? null;
|
|
2598
|
+
if (!feeEstimate) {
|
|
2599
|
+
try {
|
|
2600
|
+
feeEstimate = await this.gaslessFeeService.estimateFee({
|
|
2601
|
+
chainKey,
|
|
2602
|
+
chainId: this.chainId,
|
|
2603
|
+
tokenAddress: tx.to,
|
|
2604
|
+
fromAddress: this.wallet.address,
|
|
2605
|
+
toAddress: detected.to,
|
|
2606
|
+
amount: detected.amount,
|
|
2607
|
+
gaslessConfig
|
|
2608
|
+
});
|
|
2609
|
+
} catch (err) {
|
|
2610
|
+
console.warn("[AbcProvider] Gasless fee estimation failed:", err);
|
|
2611
|
+
return null;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
if (!feeEstimate)
|
|
2615
|
+
return null;
|
|
2616
|
+
const signer = new AbcWaasSigner({
|
|
2617
|
+
pinHash,
|
|
2618
|
+
network: getNetworkName(this.chainId),
|
|
2619
|
+
email
|
|
2620
|
+
});
|
|
2621
|
+
const transferService = new GaslessTransferService({
|
|
2622
|
+
relayerApi: this._sharedRelayerApi,
|
|
2623
|
+
signer
|
|
2624
|
+
});
|
|
2625
|
+
const gaslessResult = await transferService.execute(
|
|
2626
|
+
{
|
|
2627
|
+
chainId: this.chainId,
|
|
2628
|
+
chainKey,
|
|
2629
|
+
fromAddress: this.wallet.address,
|
|
2630
|
+
toAddress: detected.to,
|
|
2631
|
+
tokenAddress: tx.to,
|
|
2632
|
+
amount: detected.amount,
|
|
2633
|
+
feeToken: feeEstimate.feeToken,
|
|
2634
|
+
gaslessMode: feeEstimate.gaslessMode,
|
|
2635
|
+
feeAmountRaw: feeEstimate.feeAmountRaw
|
|
2636
|
+
},
|
|
2637
|
+
gaslessConfig
|
|
2638
|
+
);
|
|
2639
|
+
this.updateTxResult({
|
|
2640
|
+
txHash: gaslessResult.txHash,
|
|
2641
|
+
network: chainKey,
|
|
2642
|
+
chain: "evm",
|
|
2643
|
+
receipt: { status: 1, blockNumber: null, gasUsed: null },
|
|
2644
|
+
explorerUrl: getExplorerTxUrl(this.chainId, gaslessResult.txHash),
|
|
2645
|
+
gasless: {
|
|
2646
|
+
mode: gaslessResult.gaslessMode,
|
|
2647
|
+
fee: feeEstimate.feeAmount,
|
|
2648
|
+
feeSymbol: gaslessResult.feeToken
|
|
2649
|
+
}
|
|
2650
|
+
});
|
|
2651
|
+
console.log(
|
|
2652
|
+
`[AbcProvider] Gasless transfer success: ${gaslessResult.gaslessMode}, fee=${gaslessResult.feeAmount} ${gaslessResult.feeToken}`
|
|
2653
|
+
);
|
|
2654
|
+
return gaslessResult.txHash;
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* Sign transaction (without sending)
|
|
2658
|
+
*/
|
|
2659
|
+
async eth_signTransaction(params) {
|
|
2660
|
+
if (!this.wallet) {
|
|
2661
|
+
throw new ProviderRpcError(
|
|
2662
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2663
|
+
"Wallet not connected"
|
|
2664
|
+
);
|
|
2665
|
+
}
|
|
2666
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
2667
|
+
throw new ProviderRpcError(
|
|
2668
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2669
|
+
"Invalid transaction params"
|
|
2670
|
+
);
|
|
2671
|
+
}
|
|
2672
|
+
const resolved = await this.callInterceptor("eth_signTransaction", params);
|
|
2673
|
+
const tx = params[0];
|
|
2674
|
+
if (resolved) {
|
|
2675
|
+
if (resolved.data) {
|
|
2676
|
+
tx.data = resolved.data;
|
|
2677
|
+
}
|
|
2678
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
2679
|
+
try {
|
|
2680
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
2681
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
2682
|
+
} catch (error) {
|
|
2683
|
+
logger.error("Failed to parse maxFeePerGas:", error);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
2687
|
+
try {
|
|
2688
|
+
const priorityFeeWei = parseGwei(
|
|
2689
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
2690
|
+
);
|
|
2691
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
2692
|
+
} catch (error) {
|
|
2693
|
+
logger.error("Failed to parse maxPriorityFeePerGas:", error);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2698
|
+
const pinHash = getCredentialManager().getPinHash() || void 0;
|
|
2699
|
+
const email = this.getRecoveryEmail();
|
|
2700
|
+
const result = await this.withSigningCredentialRetry(
|
|
2701
|
+
() => api.evm.signTransaction({
|
|
2702
|
+
network: getNetworkName(this.chainId),
|
|
2703
|
+
to: tx.to,
|
|
2704
|
+
value: tx.value || "0x0",
|
|
2705
|
+
data: tx.data || "0x",
|
|
2706
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
2707
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
2708
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
2709
|
+
nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0,
|
|
2710
|
+
...pinHash && { pin: pinHash },
|
|
2711
|
+
...email && { email }
|
|
2712
|
+
})
|
|
2713
|
+
);
|
|
2714
|
+
return result.signature;
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* Personal sign (EIP-191)
|
|
2718
|
+
*/
|
|
2719
|
+
async personal_sign(params) {
|
|
2720
|
+
if (!this.wallet) {
|
|
2721
|
+
logger.error("Wallet not connected");
|
|
2722
|
+
throw new ProviderRpcError(
|
|
2723
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2724
|
+
"Wallet not connected"
|
|
2725
|
+
);
|
|
2726
|
+
}
|
|
2727
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
2728
|
+
logger.error("Invalid params:", params);
|
|
2729
|
+
throw new ProviderRpcError(
|
|
2730
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2731
|
+
"Invalid personal_sign params"
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2734
|
+
await this.callInterceptor("personal_sign", params);
|
|
2735
|
+
const [message, address] = params;
|
|
2736
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
2737
|
+
logger.error("Address mismatch");
|
|
2738
|
+
throw new ProviderRpcError(
|
|
2739
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2740
|
+
"Address does not match connected wallet"
|
|
2741
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2744
|
+
const network = getNetworkName(this.chainId);
|
|
2745
|
+
const pinHash = getCredentialManager().getPinHash() || void 0;
|
|
2746
|
+
const email = this.getRecoveryEmail();
|
|
2747
|
+
const rawOpts = Array.isArray(params) && params.length > 2 ? params[2] : null;
|
|
2748
|
+
const validPrefixes = ["eip191", "native"];
|
|
2749
|
+
const signaturePrefix = rawOpts != null && typeof rawOpts === "object" && "signaturePrefix" in rawOpts && validPrefixes.includes(rawOpts.signaturePrefix) ? rawOpts.signaturePrefix : void 0;
|
|
2750
|
+
const result = await this.withSigningCredentialRetry(
|
|
2751
|
+
() => api.evm.signPersonal({
|
|
2752
|
+
network,
|
|
2753
|
+
message,
|
|
2754
|
+
address,
|
|
2755
|
+
pin: pinHash,
|
|
2756
|
+
...email && { email },
|
|
2757
|
+
...signaturePrefix && { signaturePrefix }
|
|
2758
|
+
})
|
|
2759
|
+
);
|
|
2760
|
+
return result.signature;
|
|
2761
|
+
}
|
|
2762
|
+
/**
|
|
2763
|
+
* Eth sign
|
|
2764
|
+
*/
|
|
2765
|
+
async eth_sign(params) {
|
|
2766
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
2767
|
+
throw new ProviderRpcError(
|
|
2768
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2769
|
+
"Invalid eth_sign params"
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2772
|
+
const [address, message] = params;
|
|
2773
|
+
return this.personal_sign([message, address]);
|
|
2774
|
+
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Sign typed data (EIP-712)
|
|
2777
|
+
*/
|
|
2778
|
+
async eth_signTypedData(params) {
|
|
2779
|
+
if (!this.wallet) {
|
|
2780
|
+
throw new ProviderRpcError(
|
|
2781
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2782
|
+
"Wallet not connected"
|
|
2783
|
+
);
|
|
2784
|
+
}
|
|
2785
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
2786
|
+
throw new ProviderRpcError(
|
|
2787
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2788
|
+
"Invalid signTypedData params"
|
|
2789
|
+
);
|
|
2790
|
+
}
|
|
2791
|
+
await this.callInterceptor("eth_signTypedData_v4", params);
|
|
2792
|
+
const [address, typedData] = params;
|
|
2793
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
2794
|
+
throw new ProviderRpcError(
|
|
2795
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2796
|
+
"Address does not match connected wallet"
|
|
2797
|
+
);
|
|
2798
|
+
}
|
|
2799
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2800
|
+
const network = getNetworkName(this.chainId);
|
|
2801
|
+
const pinHash = getCredentialManager().getPinHash() || void 0;
|
|
2802
|
+
const email = this.getRecoveryEmail();
|
|
2803
|
+
const result = await this.withSigningCredentialRetry(
|
|
2804
|
+
() => api.evm.signTypedData({
|
|
2805
|
+
network,
|
|
2806
|
+
typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
|
|
2807
|
+
pin: pinHash,
|
|
2808
|
+
...email && { email }
|
|
2809
|
+
})
|
|
2810
|
+
);
|
|
2811
|
+
return result.signature;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Return normalized wallet capabilities for ABC embedded wallets.
|
|
2815
|
+
* ABC supports EIP-7702 authorization signing via talken-api.
|
|
2816
|
+
*/
|
|
2817
|
+
async wallet_getCapabilities() {
|
|
2818
|
+
return {
|
|
2819
|
+
supportsTypedDataV4: true,
|
|
2820
|
+
supports7702Authorization: true,
|
|
2821
|
+
supports5792Batch: false,
|
|
2822
|
+
supportsPaymasterService: false,
|
|
2823
|
+
supportsPermit2RelayHints: true,
|
|
2824
|
+
walletType: "abc-embedded"
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Sign EIP-7702 authorization via Talken API.
|
|
2829
|
+
*/
|
|
2830
|
+
async eth_signAuthorization(params) {
|
|
2831
|
+
if (!this.wallet) {
|
|
2832
|
+
throw new ProviderRpcError(
|
|
2833
|
+
ProviderErrorCode.UNAUTHORIZED,
|
|
2834
|
+
"Wallet not connected"
|
|
2835
|
+
);
|
|
2836
|
+
}
|
|
2837
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
2838
|
+
throw new ProviderRpcError(
|
|
2839
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2840
|
+
"Invalid signAuthorization params"
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2843
|
+
const [address, authorization] = params;
|
|
2844
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
2845
|
+
throw new ProviderRpcError(
|
|
2846
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2847
|
+
"Address does not match connected wallet"
|
|
2848
|
+
);
|
|
2849
|
+
}
|
|
2850
|
+
if (!authorization?.address || authorization.chainId == null || authorization.nonce == null) {
|
|
2851
|
+
throw new ProviderRpcError(
|
|
2852
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2853
|
+
"Authorization payload is incomplete"
|
|
2854
|
+
);
|
|
2855
|
+
}
|
|
2856
|
+
await this.callInterceptor("eth_signAuthorization", params);
|
|
2857
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2858
|
+
const network = getNetworkName(this.chainId);
|
|
2859
|
+
const pinHash = getCredentialManager().getPinHash() || void 0;
|
|
2860
|
+
const email = this.getRecoveryEmail();
|
|
2861
|
+
const chainIdValue = typeof authorization.chainId === "string" ? Number(BigInt(authorization.chainId)) : Number(authorization.chainId);
|
|
2862
|
+
const nonceValue = typeof authorization.nonce === "string" ? BigInt(authorization.nonce).toString() : String(authorization.nonce);
|
|
2863
|
+
const authAddress = authorization.address;
|
|
2864
|
+
const result = await this.withSigningCredentialRetry(
|
|
2865
|
+
() => api.evm.signAuthorization({
|
|
2866
|
+
network,
|
|
2867
|
+
authorization: {
|
|
2868
|
+
chainId: chainIdValue,
|
|
2869
|
+
address: authAddress,
|
|
2870
|
+
nonce: nonceValue
|
|
2871
|
+
},
|
|
2872
|
+
pin: pinHash,
|
|
2873
|
+
...email && { email }
|
|
2874
|
+
})
|
|
2875
|
+
);
|
|
2876
|
+
return result.authorization;
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2879
|
+
* Switch Ethereum chain
|
|
2880
|
+
*/
|
|
2881
|
+
async wallet_switchEthereumChain(params) {
|
|
2882
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
2883
|
+
throw new ProviderRpcError(
|
|
2884
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2885
|
+
"Invalid switchEthereumChain params"
|
|
2886
|
+
);
|
|
2887
|
+
}
|
|
2888
|
+
const { chainId } = params[0];
|
|
2889
|
+
const newChainId = hexToNumber(chainId);
|
|
2890
|
+
if (this.chainId === newChainId) {
|
|
2891
|
+
return null;
|
|
2892
|
+
}
|
|
2893
|
+
const _previousChainId = this.chainId;
|
|
2894
|
+
this.chainId = newChainId;
|
|
2895
|
+
if (this.wallet) {
|
|
2896
|
+
this.wallet.chainId = newChainId;
|
|
2897
|
+
}
|
|
2898
|
+
this.gaslessFeeService.clearCache();
|
|
2899
|
+
this.emit("chainChanged", numberToHex(newChainId));
|
|
2900
|
+
return null;
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Add Ethereum chain
|
|
2904
|
+
*/
|
|
2905
|
+
async wallet_addEthereumChain(params) {
|
|
2906
|
+
return this.wallet_switchEthereumChain(params);
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Get transaction count (nonce) using ABC WaaS API
|
|
2910
|
+
*/
|
|
2911
|
+
async eth_getTransactionCount(params) {
|
|
2912
|
+
const address = params[0]?.toLowerCase();
|
|
2913
|
+
if (!address) {
|
|
2914
|
+
throw new ProviderRpcError(
|
|
2915
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2916
|
+
"Missing address parameter"
|
|
2917
|
+
);
|
|
2918
|
+
}
|
|
2919
|
+
const currentChainId = this.chainId;
|
|
2920
|
+
try {
|
|
2921
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2922
|
+
const response = await api.evm.getNonce(
|
|
2923
|
+
getNetworkName(currentChainId),
|
|
2924
|
+
address
|
|
2925
|
+
);
|
|
2926
|
+
const nonce = response.result !== void 0 ? typeof response.result === "number" ? `0x${response.result.toString(16)}` : response.result : void 0;
|
|
2927
|
+
if (!nonce) {
|
|
2928
|
+
throw new Error("No result in nonce response");
|
|
2929
|
+
}
|
|
2930
|
+
return nonce;
|
|
2931
|
+
} catch (error) {
|
|
2932
|
+
logger.error("Failed to get transaction count from ABC WaaS:", error);
|
|
2933
|
+
throw new ProviderRpcError(
|
|
2934
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
2935
|
+
`Failed to get transaction count: ${error instanceof Error ? error.message : String(error)}`
|
|
2936
|
+
);
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Estimate gas for transaction
|
|
2941
|
+
* Uses ABC WaaS gas estimation API with fallback
|
|
2942
|
+
*/
|
|
2943
|
+
async eth_estimateGas(params) {
|
|
2944
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
2945
|
+
throw new ProviderRpcError(
|
|
2946
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2947
|
+
"Invalid estimateGas params"
|
|
2948
|
+
);
|
|
2949
|
+
}
|
|
2950
|
+
const tx = params[0];
|
|
2951
|
+
if (!tx.to) {
|
|
2952
|
+
throw new ProviderRpcError(
|
|
2953
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2954
|
+
'Transaction must have "to" field'
|
|
2955
|
+
);
|
|
2956
|
+
}
|
|
2957
|
+
try {
|
|
2958
|
+
const response = await this.getTalkenApiClientOrThrow().evm.estimateGas({
|
|
2959
|
+
network: getNetworkName(this.chainId),
|
|
2960
|
+
from: tx.from || this.wallet?.address || "",
|
|
2961
|
+
to: tx.to,
|
|
2962
|
+
value: tx.value,
|
|
2963
|
+
data: tx.data
|
|
2964
|
+
});
|
|
2965
|
+
if (!response.result) {
|
|
2966
|
+
throw new Error("No result in gas estimate response");
|
|
2967
|
+
}
|
|
2968
|
+
return response.result;
|
|
2969
|
+
} catch (error) {
|
|
2970
|
+
logger.warn("Gas estimation failed, using fallback:", error);
|
|
2971
|
+
if (tx.data && tx.data !== "0x") {
|
|
2972
|
+
return "0x493e0";
|
|
2973
|
+
}
|
|
2974
|
+
return "0x5208";
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
/**
|
|
2978
|
+
* Execute read-only eth_call via talken-api
|
|
2979
|
+
*/
|
|
2980
|
+
async eth_call(params) {
|
|
2981
|
+
const p = Array.isArray(params) ? params : [];
|
|
2982
|
+
const tx = p[0];
|
|
2983
|
+
if (!tx?.to || !tx?.data) {
|
|
2984
|
+
throw new ProviderRpcError(
|
|
2985
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
2986
|
+
"eth_call requires to and data"
|
|
2987
|
+
);
|
|
2988
|
+
}
|
|
2989
|
+
try {
|
|
2990
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
2991
|
+
const response = await api.evm.ethCall({
|
|
2992
|
+
network: getNetworkName(this.chainId),
|
|
2993
|
+
to: tx.to,
|
|
2994
|
+
data: tx.data,
|
|
2995
|
+
from: tx.from || this.wallet?.address
|
|
2996
|
+
});
|
|
2997
|
+
return response?.result ?? response?.data ?? "0x";
|
|
2998
|
+
} catch (error) {
|
|
2999
|
+
throw new ProviderRpcError(
|
|
3000
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
3001
|
+
`eth_call failed: ${error instanceof Error ? error.message : String(error)}`
|
|
3002
|
+
);
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
/**
|
|
3006
|
+
* Get native balance via talken-api
|
|
3007
|
+
*/
|
|
3008
|
+
async eth_getBalance(params) {
|
|
3009
|
+
const p = Array.isArray(params) ? params : [];
|
|
3010
|
+
const address = p[0] || this.wallet?.address;
|
|
3011
|
+
if (!address) {
|
|
3012
|
+
throw new ProviderRpcError(
|
|
3013
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
3014
|
+
"Missing address parameter"
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
try {
|
|
3018
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
3019
|
+
const response = await api.evm.getBalance(
|
|
3020
|
+
getNetworkName(this.chainId),
|
|
3021
|
+
address
|
|
3022
|
+
);
|
|
3023
|
+
return response?.balance ?? "0x0";
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
throw new ProviderRpcError(
|
|
3026
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
3027
|
+
`eth_getBalance failed: ${error instanceof Error ? error.message : String(error)}`
|
|
3028
|
+
);
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
/**
|
|
3032
|
+
* Get current wallet
|
|
3033
|
+
*/
|
|
3034
|
+
getWallet() {
|
|
3035
|
+
return this.wallet;
|
|
3036
|
+
}
|
|
3037
|
+
/**
|
|
3038
|
+
* Get current chain ID
|
|
3039
|
+
*/
|
|
3040
|
+
getChainId() {
|
|
3041
|
+
return this.chainId;
|
|
3042
|
+
}
|
|
3043
|
+
};
|
|
3044
|
+
function createAbcEvmProvider(talkenApi) {
|
|
3045
|
+
return new AbcEvmProvider(talkenApi);
|
|
3046
|
+
}
|
|
3047
|
+
var createAbcProvider = createAbcEvmProvider;
|
|
3048
|
+
|
|
3049
|
+
export {
|
|
3050
|
+
AbcEvmProvider,
|
|
3051
|
+
createAbcEvmProvider,
|
|
3052
|
+
createAbcProvider
|
|
3053
|
+
};
|