@trustware/sdk-staging 1.1.8-staging.3 → 1.1.8-staging.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/README.md +27 -0
- package/dist/blockchain-BONedEsU.d.cts +110 -0
- package/dist/blockchain-BONedEsU.d.ts +110 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-u95iahDO.d.cts → core-BcoaMbJ6.d.cts} +3 -2
- package/dist/{core-CVbN3gJy.d.ts → core-BqqBQ5nF.d.ts} +3 -2
- package/dist/core.cjs +2290 -2247
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +4 -3
- package/dist/core.d.ts +4 -3
- package/dist/core.mjs +2277 -2244
- package/dist/core.mjs.map +1 -1
- package/dist/{detect-6MRR4B7g.d.ts → detect-F6garpnf.d.ts} +2 -2
- package/dist/{detect-DVIWcXpl.d.cts → detect-srLQtIzU.d.cts} +2 -2
- package/dist/index.cjs +22382 -3552
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -10
- package/dist/index.d.ts +28 -10
- package/dist/index.mjs +28327 -9497
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-CXSw1h5e.d.cts → manager-BWmNEeZb.d.cts} +72 -121
- package/dist/{manager-CXSw1h5e.d.ts → manager-BojJyYIt.d.ts} +72 -121
- package/dist/smart-account.cjs +14707 -0
- package/dist/smart-account.cjs.map +1 -0
- package/dist/smart-account.d.cts +3962 -0
- package/dist/smart-account.d.ts +3962 -0
- package/dist/smart-account.mjs +14686 -0
- package/dist/smart-account.mjs.map +1 -0
- package/dist/types-B3nKHW6H.d.cts +32 -0
- package/dist/types-MtdjJgwT.d.ts +32 -0
- package/dist/wallet.cjs +29 -9
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +4 -3
- package/dist/wallet.d.ts +4 -3
- package/dist/wallet.mjs +16 -6
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +33067 -14246
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.d.cts +5 -4
- package/dist/widget.d.ts +5 -4
- package/dist/widget.mjs +33007 -14182
- package/dist/widget.mjs.map +1 -1
- package/package.json +17 -4
- package/dist/types-BrVfNxND.d.cts +0 -14
- package/dist/types-BrVfNxND.d.ts +0 -14
package/dist/core.mjs
CHANGED
|
@@ -46,7 +46,11 @@ var init_config = __esm({
|
|
|
46
46
|
DEFAULT_FEATURE_FLAGS = {
|
|
47
47
|
tokensPagination: true,
|
|
48
48
|
balanceStreaming: false,
|
|
49
|
-
shouldAllowGA4: true
|
|
49
|
+
shouldAllowGA4: true,
|
|
50
|
+
swapMode: false,
|
|
51
|
+
swapDefaultDestToken: null,
|
|
52
|
+
swapLockDestToken: false,
|
|
53
|
+
swapAllowedDestTokens: null
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
});
|
|
@@ -57,7 +61,7 @@ var init_constants = __esm({
|
|
|
57
61
|
"src/constants.ts"() {
|
|
58
62
|
"use strict";
|
|
59
63
|
SDK_NAME = "@trustware/sdk";
|
|
60
|
-
SDK_VERSION = "1.1.8-staging.
|
|
64
|
+
SDK_VERSION = "1.1.8-staging.5";
|
|
61
65
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
62
66
|
API_PREFIX = "/api";
|
|
63
67
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -212,370 +216,430 @@ var init_http = __esm({
|
|
|
212
216
|
}
|
|
213
217
|
});
|
|
214
218
|
|
|
215
|
-
// src/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
+
// src/utils/chains.ts
|
|
220
|
+
function inferChainTypeFromValue(normalized) {
|
|
221
|
+
if (!normalized) return void 0;
|
|
222
|
+
const aliased = CHAIN_TYPE_ALIASES[normalized];
|
|
223
|
+
if (aliased) return aliased;
|
|
224
|
+
if (normalized === "evm" || normalized === "solana" || normalized === "cosmos" || normalized === "bitcoin") {
|
|
225
|
+
return normalized;
|
|
219
226
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
// src/wallets/eipWallets.ts
|
|
223
|
-
async function addThenSwitch(eth, chainId) {
|
|
224
|
-
const p = CHAIN_PARAMS[chainId];
|
|
225
|
-
if (!p) throw new Error(`Unknown chain ${chainId} (no params to add)`);
|
|
226
|
-
await eth.request({ method: "wallet_addEthereumChain", params: [p] });
|
|
227
|
-
await eth.request({
|
|
228
|
-
method: "wallet_switchEthereumChain",
|
|
229
|
-
params: [{ chainId: p.chainIdHex }]
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
function useEIP1193(eth) {
|
|
233
|
-
if (!eth?.request) throw new Error("useEIP1193: invalid provider");
|
|
234
|
-
let switching = false;
|
|
235
|
-
return {
|
|
236
|
-
ecosystem: "evm",
|
|
237
|
-
type: "eip1193",
|
|
238
|
-
async getAddress() {
|
|
239
|
-
const [a] = await eth.request({
|
|
240
|
-
method: "eth_requestAccounts"
|
|
241
|
-
});
|
|
242
|
-
if (!a) throw new Error("No connected address");
|
|
243
|
-
return a;
|
|
244
|
-
},
|
|
245
|
-
async getChainId() {
|
|
246
|
-
const hex = await eth.request({ method: "eth_chainId" });
|
|
247
|
-
return parseInt(String(hex), 16);
|
|
248
|
-
},
|
|
249
|
-
async switchChain(chainId) {
|
|
250
|
-
if (switching) return;
|
|
251
|
-
switching = true;
|
|
252
|
-
const hex = CHAIN_PARAMS[chainId]?.chainIdHex ?? `0x${chainId.toString(16)}`;
|
|
253
|
-
try {
|
|
254
|
-
await eth.request({
|
|
255
|
-
method: "wallet_switchEthereumChain",
|
|
256
|
-
params: [{ chainId: hex }]
|
|
257
|
-
});
|
|
258
|
-
} catch (e2) {
|
|
259
|
-
if (e2?.code === 4902) {
|
|
260
|
-
await addThenSwitch(eth, chainId);
|
|
261
|
-
} else if (e2?.code === 4001) {
|
|
262
|
-
} else {
|
|
263
|
-
throw e2;
|
|
264
|
-
}
|
|
265
|
-
} finally {
|
|
266
|
-
switching = false;
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
request: (args) => eth.request(args)
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
var CHAIN_PARAMS;
|
|
273
|
-
var init_eipWallets = __esm({
|
|
274
|
-
"src/wallets/eipWallets.ts"() {
|
|
275
|
-
"use strict";
|
|
276
|
-
CHAIN_PARAMS = {
|
|
277
|
-
8453: {
|
|
278
|
-
chainIdHex: "0x2105",
|
|
279
|
-
chainName: "Base",
|
|
280
|
-
rpcUrls: ["https://mainnet.base.org"],
|
|
281
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
282
|
-
blockExplorerUrls: ["https://basescan.org"]
|
|
283
|
-
},
|
|
284
|
-
42161: {
|
|
285
|
-
chainIdHex: "0xa4b1",
|
|
286
|
-
chainName: "Arbitrum One",
|
|
287
|
-
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
288
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
289
|
-
blockExplorerUrls: ["https://arbiscan.io"]
|
|
290
|
-
},
|
|
291
|
-
43114: {
|
|
292
|
-
chainIdHex: "0xa86a",
|
|
293
|
-
chainName: "Avalanche C-Chain",
|
|
294
|
-
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
295
|
-
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
296
|
-
blockExplorerUrls: ["https://snowtrace.io"]
|
|
297
|
-
}
|
|
298
|
-
};
|
|
227
|
+
if (/^eip155:\d+$/.test(normalized) || /^\d+$/.test(normalized)) {
|
|
228
|
+
return "evm";
|
|
299
229
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// src/core/sdkRpc.ts
|
|
303
|
-
async function requestSDKRPC(path, init = {}) {
|
|
304
|
-
const response = await rateLimitedFetch(`${apiBase()}/v1/sdk/rpc${path}`, {
|
|
305
|
-
...init,
|
|
306
|
-
headers: jsonHeaders()
|
|
307
|
-
});
|
|
308
|
-
let payload = null;
|
|
309
|
-
try {
|
|
310
|
-
payload = await response.json();
|
|
311
|
-
} catch {
|
|
312
|
-
payload = null;
|
|
230
|
+
if (normalized.startsWith("solana:") || normalized.includes("solana")) {
|
|
231
|
+
return "solana";
|
|
313
232
|
}
|
|
314
|
-
if (
|
|
315
|
-
return
|
|
233
|
+
if (normalized.startsWith("cosmos:") || normalized.startsWith("sei:") || normalized === "sei-evm") {
|
|
234
|
+
return "cosmos";
|
|
316
235
|
}
|
|
317
|
-
|
|
318
|
-
payload?.error?.message || `HTTP ${response.status}: ${response.statusText || "SDK RPC request failed"}`,
|
|
319
|
-
{
|
|
320
|
-
code: payload?.error?.code,
|
|
321
|
-
context: payload?.error?.context,
|
|
322
|
-
status: response.status
|
|
323
|
-
}
|
|
324
|
-
);
|
|
236
|
+
return void 0;
|
|
325
237
|
}
|
|
326
|
-
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
238
|
+
function normalizeChainKey(value) {
|
|
239
|
+
if (value === void 0 || value === null) return "";
|
|
240
|
+
return String(value).trim().toLowerCase();
|
|
241
|
+
}
|
|
242
|
+
function normalizeChainType(chain) {
|
|
243
|
+
if (!chain) return void 0;
|
|
244
|
+
const raw = typeof chain === "string" ? chain : chain.type ?? chain.chainType ?? chain.networkIdentifier ?? chain.chainId ?? chain.id ?? chain.networkName ?? chain.axelarChainName;
|
|
245
|
+
if (!raw) return void 0;
|
|
246
|
+
const normalized = String(raw).trim().toLowerCase();
|
|
247
|
+
return inferChainTypeFromValue(normalized) ?? normalized;
|
|
248
|
+
}
|
|
249
|
+
function getNativeTokenAddress(chainType) {
|
|
250
|
+
return normalizeChainType(chainType) === "solana" ? NATIVE_SOLANA : NATIVE_EVM;
|
|
251
|
+
}
|
|
252
|
+
function isSolanaNativeTokenAlias(address) {
|
|
253
|
+
if (!address) return false;
|
|
254
|
+
const trimmed = address.trim();
|
|
255
|
+
if (!trimmed) return false;
|
|
256
|
+
return trimmed === NATIVE_SOLANA || trimmed.toLowerCase() === NATIVE_EVM;
|
|
257
|
+
}
|
|
258
|
+
function normalizeAddress(address, chainType) {
|
|
259
|
+
const trimmed = address.trim();
|
|
260
|
+
if (normalizeChainType(chainType) === "solana") {
|
|
261
|
+
if (isSolanaNativeTokenAlias(trimmed)) {
|
|
262
|
+
return NATIVE_SOLANA;
|
|
332
263
|
}
|
|
333
|
-
|
|
264
|
+
return trimmed;
|
|
265
|
+
}
|
|
266
|
+
return trimmed.toLowerCase();
|
|
334
267
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
{ method: "GET" }
|
|
340
|
-
);
|
|
268
|
+
function isZeroAddressLike(address, chainType) {
|
|
269
|
+
if (!address) return true;
|
|
270
|
+
const normalized = normalizeAddress(address, chainType);
|
|
271
|
+
return normalized === normalizeAddress(getNativeTokenAddress(chainType), chainType) || normalized === "0x0000000000000000000000000000000000000000";
|
|
341
272
|
}
|
|
342
|
-
var
|
|
343
|
-
var
|
|
344
|
-
"src/
|
|
273
|
+
var NATIVE_EVM, NATIVE_SOLANA, CHAIN_TYPE_ALIASES;
|
|
274
|
+
var init_chains = __esm({
|
|
275
|
+
"src/utils/chains.ts"() {
|
|
345
276
|
"use strict";
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
this.status = options?.status;
|
|
354
|
-
}
|
|
277
|
+
NATIVE_EVM = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
278
|
+
NATIVE_SOLANA = "So11111111111111111111111111111111111111111";
|
|
279
|
+
CHAIN_TYPE_ALIASES = {
|
|
280
|
+
btc: "bitcoin",
|
|
281
|
+
bitcoin: "bitcoin",
|
|
282
|
+
sei: "cosmos",
|
|
283
|
+
"pacific-1": "cosmos"
|
|
355
284
|
};
|
|
356
285
|
}
|
|
357
286
|
});
|
|
358
287
|
|
|
359
|
-
// src/
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
288
|
+
// src/registry.ts
|
|
289
|
+
var registry_exports = {};
|
|
290
|
+
__export(registry_exports, {
|
|
291
|
+
NATIVE: () => NATIVE,
|
|
292
|
+
Registry: () => Registry
|
|
293
|
+
});
|
|
294
|
+
function getChainAliases(chain) {
|
|
295
|
+
const values = [
|
|
296
|
+
chain.chainId,
|
|
297
|
+
chain.id,
|
|
298
|
+
chain.networkIdentifier,
|
|
299
|
+
chain.axelarChainName,
|
|
300
|
+
chain.networkName
|
|
301
|
+
];
|
|
302
|
+
return values.map((value) => normalizeChainKey(value)).filter(Boolean);
|
|
366
303
|
}
|
|
367
|
-
function
|
|
368
|
-
|
|
369
|
-
if (typeof Buffer !== "undefined") {
|
|
370
|
-
return Uint8Array.from(Buffer.from(trimmed, "base64"));
|
|
371
|
-
}
|
|
372
|
-
const binary = globalThis.atob(trimmed);
|
|
373
|
-
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
304
|
+
function tokenKey(token) {
|
|
305
|
+
return `${normalizeChainKey(token.chainId)}:${token.address.toLowerCase()}`;
|
|
374
306
|
}
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
307
|
+
function parseTokenPage(payload) {
|
|
308
|
+
if (Array.isArray(payload)) {
|
|
309
|
+
return {
|
|
310
|
+
data: payload,
|
|
311
|
+
pageInfo: { hasNextPage: false }
|
|
312
|
+
};
|
|
381
313
|
}
|
|
314
|
+
const parsed = payload ?? {};
|
|
315
|
+
const data = parsed.data ?? parsed.results ?? parsed.tokens ?? [];
|
|
316
|
+
const info = parsed.pageInfo ?? parsed.pagination;
|
|
317
|
+
return {
|
|
318
|
+
data: Array.isArray(data) ? data : [],
|
|
319
|
+
pageInfo: {
|
|
320
|
+
hasNextPage: info?.hasNextPage ?? parsed.hasNextPage ?? Boolean(info?.nextCursor),
|
|
321
|
+
nextCursor: info?.nextCursor ?? parsed.nextCursor
|
|
322
|
+
}
|
|
323
|
+
};
|
|
382
324
|
}
|
|
383
|
-
function
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
for (const byte of bytes) {
|
|
389
|
-
binary += String.fromCharCode(byte);
|
|
390
|
-
}
|
|
391
|
-
return globalThis.btoa(binary);
|
|
325
|
+
function normalizeToken(token) {
|
|
326
|
+
return {
|
|
327
|
+
...token,
|
|
328
|
+
chainId: token.chainId
|
|
329
|
+
};
|
|
392
330
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return () => {
|
|
415
|
-
provider.off?.("connect", onConnect);
|
|
416
|
-
provider.off?.("accountChanged", onAccountChanged);
|
|
417
|
-
provider.off?.("disconnect", onDisconnect);
|
|
418
|
-
provider.removeListener?.("connect", onConnect);
|
|
419
|
-
provider.removeListener?.("accountChanged", onAccountChanged);
|
|
420
|
-
provider.removeListener?.("disconnect", onDisconnect);
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
function toSolanaWalletInterface(provider) {
|
|
424
|
-
return {
|
|
425
|
-
ecosystem: "solana",
|
|
426
|
-
type: "solana",
|
|
427
|
-
async getAddress() {
|
|
428
|
-
const current = getPublicKeyString(provider);
|
|
429
|
-
if (current) return current;
|
|
430
|
-
if (!provider.connect) {
|
|
431
|
-
throw new Error("Selected Solana wallet cannot connect");
|
|
331
|
+
var NATIVE, PAGE_CACHE_TTL_MS, PAGE_CACHE_LIMIT, Registry;
|
|
332
|
+
var init_registry = __esm({
|
|
333
|
+
"src/registry.ts"() {
|
|
334
|
+
"use strict";
|
|
335
|
+
init_store();
|
|
336
|
+
init_chains();
|
|
337
|
+
NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
338
|
+
PAGE_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
339
|
+
PAGE_CACHE_LIMIT = 100;
|
|
340
|
+
Registry = class {
|
|
341
|
+
constructor(baseURL) {
|
|
342
|
+
this.baseURL = baseURL;
|
|
343
|
+
this._chainsById = /* @__PURE__ */ new Map();
|
|
344
|
+
this._chainAliases = /* @__PURE__ */ new Map();
|
|
345
|
+
this._tokensByChain = /* @__PURE__ */ new Map();
|
|
346
|
+
this._tokensByChainKey = /* @__PURE__ */ new Map();
|
|
347
|
+
this._pageCache = /* @__PURE__ */ new Map();
|
|
348
|
+
this._loaded = false;
|
|
349
|
+
this._chainsLoaded = false;
|
|
350
|
+
this._loadingPromise = null;
|
|
351
|
+
this._chainsLoadingPromise = null;
|
|
432
352
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
353
|
+
async ensureLoaded() {
|
|
354
|
+
if (this._loaded) return;
|
|
355
|
+
if (this._loadingPromise) {
|
|
356
|
+
await this._loadingPromise;
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
this._loadingPromise = this.loadAllTokens();
|
|
360
|
+
try {
|
|
361
|
+
await this._loadingPromise;
|
|
362
|
+
} finally {
|
|
363
|
+
this._loadingPromise = null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async ensureChainsLoaded() {
|
|
367
|
+
if (this._chainsLoaded) return;
|
|
368
|
+
if (this._chainsLoadingPromise) {
|
|
369
|
+
await this._chainsLoadingPromise;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this._chainsLoadingPromise = this.loadChains();
|
|
373
|
+
try {
|
|
374
|
+
await this._chainsLoadingPromise;
|
|
375
|
+
} finally {
|
|
376
|
+
this._chainsLoadingPromise = null;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
get config() {
|
|
380
|
+
return TrustwareConfigStore.get();
|
|
381
|
+
}
|
|
382
|
+
emitPageLoaded(chainRef, query, result, cursor) {
|
|
383
|
+
this.config.onEvent?.({
|
|
384
|
+
type: "token_page_loaded",
|
|
385
|
+
chainRef: String(chainRef),
|
|
386
|
+
query,
|
|
387
|
+
count: result.data.length,
|
|
388
|
+
hasNextPage: result.pageInfo.hasNextPage,
|
|
389
|
+
cursor
|
|
449
390
|
});
|
|
450
|
-
if (typeof result === "string") return result;
|
|
451
|
-
if (result?.signature) return result.signature;
|
|
452
391
|
}
|
|
453
|
-
|
|
454
|
-
|
|
392
|
+
emitPageError(chainRef, query, cursor, error) {
|
|
393
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
394
|
+
this.config.onEvent?.({
|
|
395
|
+
type: "token_page_error",
|
|
396
|
+
chainRef: String(chainRef),
|
|
397
|
+
query,
|
|
398
|
+
cursor,
|
|
399
|
+
message
|
|
400
|
+
});
|
|
455
401
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
"src/wallets/solana.ts"() {
|
|
470
|
-
"use strict";
|
|
471
|
-
init_sdkRpc();
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
// src/wallets/adapters.ts
|
|
476
|
-
function toWalletInterfaceFromDetected(dw) {
|
|
477
|
-
if (!dw?.provider) throw new Error("No provider on detected wallet");
|
|
478
|
-
if (dw.via === "solana-window" || dw.meta.ecosystem === "solana") {
|
|
479
|
-
return toSolanaWalletInterface(dw.provider);
|
|
480
|
-
}
|
|
481
|
-
const eth = dw.provider;
|
|
482
|
-
return useEIP1193(eth);
|
|
483
|
-
}
|
|
484
|
-
var init_adapters = __esm({
|
|
485
|
-
"src/wallets/adapters.ts"() {
|
|
486
|
-
"use strict";
|
|
487
|
-
init_eipWallets();
|
|
488
|
-
init_solana();
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
// src/wallets/connect.ts
|
|
493
|
-
function pickWagmiConnector(wagmi, metaName, metaId, metaCategory) {
|
|
494
|
-
const lower = metaName.toLowerCase();
|
|
495
|
-
const cons = wagmi.connectors();
|
|
496
|
-
return cons.find((c) => c.name.toLowerCase().includes(lower)) || metaId === "coinbase" && cons.find((c) => c.name.toLowerCase().includes("coinbase")) || metaId === "walletconnect" && cons.find((c) => (c.type ?? "").toLowerCase() === "walletconnect") || metaCategory === "injected" && cons.find((c) => (c.type ?? "").toLowerCase() === "injected") || null;
|
|
497
|
-
}
|
|
498
|
-
async function connectDetectedWallet(dw, opts) {
|
|
499
|
-
const { wagmi, touchAddress = true } = opts ?? {};
|
|
500
|
-
if (dw.meta.id === "walletconnect" || dw.via === "walletconnect") {
|
|
501
|
-
if (wagmi) {
|
|
502
|
-
const conn = pickWagmiConnector(
|
|
503
|
-
wagmi,
|
|
504
|
-
dw.meta.name,
|
|
505
|
-
dw.meta.id,
|
|
506
|
-
dw.meta.category
|
|
507
|
-
);
|
|
508
|
-
if (conn) {
|
|
509
|
-
await wagmi.connect(conn);
|
|
510
|
-
return { via: "wagmi", api: null };
|
|
402
|
+
storeChain(chain) {
|
|
403
|
+
const canonical = chain?.chainId ?? chain?.id;
|
|
404
|
+
if (canonical == null) return;
|
|
405
|
+
const normalized = {
|
|
406
|
+
...chain,
|
|
407
|
+
id: chain.id ?? canonical,
|
|
408
|
+
chainId: chain.chainId ?? canonical
|
|
409
|
+
};
|
|
410
|
+
const canonicalKey = normalizeChainKey(canonical);
|
|
411
|
+
this._chainsById.set(canonicalKey, normalized);
|
|
412
|
+
for (const alias of getChainAliases(normalized)) {
|
|
413
|
+
this._chainAliases.set(alias, canonicalKey);
|
|
414
|
+
}
|
|
511
415
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
416
|
+
storeTokenForAlias(chainKey, token) {
|
|
417
|
+
const key = tokenKey(token);
|
|
418
|
+
const existingByKey = this._tokensByChainKey.get(chainKey) ?? /* @__PURE__ */ new Map();
|
|
419
|
+
existingByKey.set(key, token);
|
|
420
|
+
this._tokensByChainKey.set(chainKey, existingByKey);
|
|
421
|
+
this._tokensByChain.set(chainKey, Array.from(existingByKey.values()));
|
|
422
|
+
}
|
|
423
|
+
storeToken(token) {
|
|
424
|
+
const chainRef = token?.chainId;
|
|
425
|
+
if (chainRef == null) return;
|
|
426
|
+
const normalized = normalizeToken(token);
|
|
427
|
+
const resolvedChain = this.chain(chainRef);
|
|
428
|
+
const aliases = resolvedChain ? getChainAliases(resolvedChain) : [normalizeChainKey(chainRef)];
|
|
429
|
+
for (const alias of aliases) {
|
|
430
|
+
this.storeTokenForAlias(alias, normalized);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async loadChains() {
|
|
434
|
+
const chainsRes = await fetch(`${this.baseURL}/v1/routes/chains`, {
|
|
435
|
+
headers: { Accept: "application/json", "X-API-Key": this.config.apiKey }
|
|
436
|
+
});
|
|
437
|
+
if (!chainsRes.ok) throw new Error(`chains: HTTP ${chainsRes.status}`);
|
|
438
|
+
const chains = await chainsRes.json();
|
|
439
|
+
const chainsArr = Array.isArray(chains) ? chains : chains.data ?? [];
|
|
440
|
+
for (const chain of chainsArr) {
|
|
441
|
+
this.storeChain(chain);
|
|
442
|
+
}
|
|
443
|
+
this._chainsLoaded = true;
|
|
444
|
+
}
|
|
445
|
+
async loadAllTokens() {
|
|
446
|
+
await this.ensureChainsLoaded();
|
|
447
|
+
const tokensRes = await fetch(`${this.baseURL}/v1/routes/tokens`, {
|
|
448
|
+
headers: { Accept: "application/json", "X-API-Key": this.config.apiKey }
|
|
449
|
+
});
|
|
450
|
+
if (!tokensRes.ok) throw new Error(`tokens: HTTP ${tokensRes.status}`);
|
|
451
|
+
const tokens = await tokensRes.json();
|
|
452
|
+
const tokensArr = Array.isArray(tokens) ? tokens : tokens.data ?? [];
|
|
453
|
+
for (const token of tokensArr) {
|
|
454
|
+
this.storeToken(token);
|
|
455
|
+
}
|
|
456
|
+
this._loaded = true;
|
|
457
|
+
}
|
|
458
|
+
prunePageCache() {
|
|
459
|
+
const now = Date.now();
|
|
460
|
+
for (const [key, value] of this._pageCache.entries()) {
|
|
461
|
+
if (now - value.storedAt > PAGE_CACHE_TTL_MS) {
|
|
462
|
+
this._pageCache.delete(key);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
while (this._pageCache.size > PAGE_CACHE_LIMIT) {
|
|
466
|
+
const oldestKey = this._pageCache.keys().next().value;
|
|
467
|
+
if (!oldestKey) {
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
this._pageCache.delete(oldestKey);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
pageCacheKey(chainRef, opts = {}) {
|
|
474
|
+
const chain = this.chain(chainRef);
|
|
475
|
+
const canonical = normalizeChainKey(chain?.chainId ?? chainRef);
|
|
476
|
+
return `${canonical}::${opts.q ?? ""}::${opts.limit ?? ""}::${opts.cursor ?? ""}`;
|
|
477
|
+
}
|
|
478
|
+
filterTokens(tokens, chainRef, query) {
|
|
479
|
+
const normalizedChain = normalizeChainKey(chainRef);
|
|
480
|
+
const normalizedQuery = query?.trim().toLowerCase();
|
|
481
|
+
return tokens.filter((token) => {
|
|
482
|
+
if (normalizeChainKey(token.chainId) !== normalizedChain) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
if (!normalizedQuery) {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
return token.symbol?.toLowerCase().includes(normalizedQuery) || token.name?.toLowerCase().includes(normalizedQuery) || token.address?.toLowerCase().includes(normalizedQuery);
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
chains() {
|
|
492
|
+
return Array.from(this._chainsById.values());
|
|
493
|
+
}
|
|
494
|
+
chain(chainRef) {
|
|
495
|
+
const normalized = normalizeChainKey(chainRef);
|
|
496
|
+
const canonicalKey = this._chainAliases.get(normalized) ?? normalized;
|
|
497
|
+
return this._chainsById.get(canonicalKey);
|
|
498
|
+
}
|
|
499
|
+
allTokens() {
|
|
500
|
+
const unique = /* @__PURE__ */ new Map();
|
|
501
|
+
for (const list of this._tokensByChain.values()) {
|
|
502
|
+
for (const token of list) {
|
|
503
|
+
unique.set(tokenKey(token), token);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return Array.from(unique.values());
|
|
507
|
+
}
|
|
508
|
+
tokens(chainRef) {
|
|
509
|
+
return this._tokensByChain.get(normalizeChainKey(chainRef)) ?? [];
|
|
510
|
+
}
|
|
511
|
+
async tokensPage(chainRef, opts = {}) {
|
|
512
|
+
await this.ensureChainsLoaded();
|
|
513
|
+
if (!this.config.features.tokensPagination) {
|
|
514
|
+
await this.ensureLoaded();
|
|
515
|
+
const all = this.filterTokens(this.allTokens(), chainRef, opts.q);
|
|
516
|
+
const start = opts.cursor ? Number(opts.cursor) || 0 : 0;
|
|
517
|
+
const limit = opts.limit ?? all.length;
|
|
518
|
+
const data = all.slice(start, start + limit);
|
|
519
|
+
return {
|
|
520
|
+
data,
|
|
521
|
+
pageInfo: {
|
|
522
|
+
hasNextPage: start + limit < all.length,
|
|
523
|
+
nextCursor: start + limit < all.length ? String(start + limit) : void 0
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const cacheKey = this.pageCacheKey(chainRef, opts);
|
|
528
|
+
const cached = this._pageCache.get(cacheKey);
|
|
529
|
+
if (cached && Date.now() - cached.storedAt <= PAGE_CACHE_TTL_MS) {
|
|
530
|
+
return { data: cached.data, pageInfo: cached.pageInfo };
|
|
531
|
+
}
|
|
532
|
+
const chain = this.chain(chainRef);
|
|
533
|
+
const chainKey = normalizeChainKey(chain?.chainId ?? chainRef);
|
|
534
|
+
const url = new URL(`${this.baseURL}/v1/routes/tokens`);
|
|
535
|
+
url.searchParams.set("chainId", chainKey);
|
|
536
|
+
if (opts.cursor) url.searchParams.set("cursor", opts.cursor);
|
|
537
|
+
if (opts.limit != null) url.searchParams.set("limit", String(opts.limit));
|
|
538
|
+
if (opts.q) url.searchParams.set("q", opts.q);
|
|
539
|
+
try {
|
|
540
|
+
const res = await fetch(url.toString(), {
|
|
541
|
+
headers: {
|
|
542
|
+
Accept: "application/json",
|
|
543
|
+
"X-API-Key": this.config.apiKey
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
if (!res.ok) {
|
|
547
|
+
throw new Error(`tokens page: HTTP ${res.status}`);
|
|
548
|
+
}
|
|
549
|
+
const parsed = parseTokenPage(await res.json());
|
|
550
|
+
const deduped = /* @__PURE__ */ new Map();
|
|
551
|
+
for (const token of parsed.data) {
|
|
552
|
+
const normalized = normalizeToken(token);
|
|
553
|
+
this.storeToken(normalized);
|
|
554
|
+
deduped.set(tokenKey(normalized), normalized);
|
|
555
|
+
}
|
|
556
|
+
const result = {
|
|
557
|
+
data: Array.from(deduped.values()),
|
|
558
|
+
pageInfo: parsed.pageInfo
|
|
559
|
+
};
|
|
560
|
+
this._pageCache.set(cacheKey, { ...result, storedAt: Date.now() });
|
|
561
|
+
this.prunePageCache();
|
|
562
|
+
this.emitPageLoaded(chainRef, opts.q, result, opts.cursor);
|
|
563
|
+
return result;
|
|
564
|
+
} catch (error) {
|
|
565
|
+
this.emitPageError(chainRef, opts.q, opts.cursor, error);
|
|
566
|
+
await this.ensureLoaded();
|
|
567
|
+
const fallback = this.filterTokens(this.allTokens(), chainRef, opts.q);
|
|
568
|
+
return {
|
|
569
|
+
data: fallback,
|
|
570
|
+
pageInfo: { hasNextPage: false }
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
async *iterateTokens(chainRef, opts = {}) {
|
|
575
|
+
let cursor;
|
|
576
|
+
do {
|
|
577
|
+
const page = await this.tokensPage(chainRef, { ...opts, cursor });
|
|
578
|
+
yield page;
|
|
579
|
+
cursor = page.pageInfo.nextCursor;
|
|
580
|
+
if (!page.pageInfo.hasNextPage) {
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
} while (cursor);
|
|
584
|
+
}
|
|
585
|
+
findToken(chainRef, address) {
|
|
586
|
+
const chain = this.chain(chainRef);
|
|
587
|
+
const chainType = normalizeChainType(chain);
|
|
588
|
+
const normalizedAddress = normalizeAddress(address, chainType);
|
|
589
|
+
return this.tokens(chainRef).find((token) => {
|
|
590
|
+
return normalizeAddress(token.address, chainType) === normalizedAddress;
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
resolveToken(chainRef, input) {
|
|
594
|
+
if (!input) return void 0;
|
|
595
|
+
const s = String(input).trim();
|
|
596
|
+
const chain = this.chain(chainRef);
|
|
597
|
+
const chainType = normalizeChainType(chain);
|
|
598
|
+
if (/^0x[0-9a-fA-F]{40}$/.test(s)) return s;
|
|
599
|
+
if (chainType === "solana" && s.length > 20) return s;
|
|
600
|
+
const nativeAddress = getNativeTokenAddress(chainType);
|
|
601
|
+
const nativeSymbol = chain?.nativeCurrency?.symbol?.toUpperCase?.();
|
|
602
|
+
if (nativeSymbol && s.toUpperCase() === nativeSymbol || ["ETH", "MATIC", "AVAX", "BNB", "SOL", "NATIVE"].includes(s.toUpperCase())) {
|
|
603
|
+
return chainType === "solana" ? nativeAddress : NATIVE;
|
|
604
|
+
}
|
|
605
|
+
const hit = this.tokens(chainRef).find((token) => {
|
|
606
|
+
if (!token.symbol) return false;
|
|
607
|
+
return token.symbol.toUpperCase() === s.toUpperCase();
|
|
608
|
+
});
|
|
609
|
+
if (hit) return hit.address;
|
|
610
|
+
return s;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// node_modules/@solana/errors/dist/index.node.mjs
|
|
617
|
+
function encodeValue(value) {
|
|
618
|
+
if (Array.isArray(value)) {
|
|
619
|
+
const commaSeparatedValues = value.map(encodeValue).join(
|
|
620
|
+
"%2C%20"
|
|
621
|
+
/* ", " */
|
|
622
|
+
);
|
|
623
|
+
return "%5B" + commaSeparatedValues + /* "]" */
|
|
624
|
+
"%5D";
|
|
625
|
+
} else if (typeof value === "bigint") {
|
|
626
|
+
return `${value}n`;
|
|
627
|
+
} else {
|
|
628
|
+
return encodeURIComponent(
|
|
629
|
+
String(
|
|
630
|
+
value != null && Object.getPrototypeOf(value) === null ? (
|
|
631
|
+
// Plain objects with no prototype don't have a `toString` method.
|
|
632
|
+
// Convert them before stringifying them.
|
|
633
|
+
{ ...value }
|
|
634
|
+
) : value
|
|
635
|
+
)
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function encodeObjectContextEntry([key, value]) {
|
|
640
|
+
return `${key}=${encodeValue(value)}`;
|
|
641
|
+
}
|
|
642
|
+
function encodeContextObject(context) {
|
|
579
643
|
const searchParamsString = Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
580
644
|
return Buffer.from(searchParamsString, "utf8").toString("base64");
|
|
581
645
|
}
|
|
@@ -1363,95 +1427,26 @@ var init_index_node4 = __esm({
|
|
|
1363
1427
|
}
|
|
1364
1428
|
});
|
|
1365
1429
|
|
|
1366
|
-
// src/
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1430
|
+
// src/validation/address.ts
|
|
1431
|
+
import { isAddress as isEvmAddress } from "viem";
|
|
1432
|
+
function hasMixedCase(value) {
|
|
1433
|
+
return value !== value.toLowerCase() && value !== value.toUpperCase();
|
|
1434
|
+
}
|
|
1435
|
+
function validateBech32LikeAddress(address, prefix) {
|
|
1436
|
+
const trimmed = address.trim();
|
|
1437
|
+
if (!trimmed) {
|
|
1438
|
+
return { isValid: false, error: "Address is required." };
|
|
1373
1439
|
}
|
|
1374
|
-
if (
|
|
1375
|
-
return "
|
|
1440
|
+
if (hasMixedCase(trimmed)) {
|
|
1441
|
+
return { isValid: false, error: "Bech32 addresses cannot mix case." };
|
|
1376
1442
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
}
|
|
1385
|
-
function normalizeChainKey(value) {
|
|
1386
|
-
if (value === void 0 || value === null) return "";
|
|
1387
|
-
return String(value).trim().toLowerCase();
|
|
1388
|
-
}
|
|
1389
|
-
function normalizeChainType(chain) {
|
|
1390
|
-
if (!chain) return void 0;
|
|
1391
|
-
const raw = typeof chain === "string" ? chain : chain.type ?? chain.chainType ?? chain.networkIdentifier ?? chain.chainId ?? chain.id ?? chain.networkName ?? chain.axelarChainName;
|
|
1392
|
-
if (!raw) return void 0;
|
|
1393
|
-
const normalized = String(raw).trim().toLowerCase();
|
|
1394
|
-
return inferChainTypeFromValue(normalized) ?? normalized;
|
|
1395
|
-
}
|
|
1396
|
-
function getNativeTokenAddress(chainType) {
|
|
1397
|
-
return normalizeChainType(chainType) === "solana" ? NATIVE_SOLANA : NATIVE_EVM;
|
|
1398
|
-
}
|
|
1399
|
-
function isSolanaNativeTokenAlias(address) {
|
|
1400
|
-
if (!address) return false;
|
|
1401
|
-
const trimmed = address.trim();
|
|
1402
|
-
if (!trimmed) return false;
|
|
1403
|
-
return trimmed === NATIVE_SOLANA || trimmed.toLowerCase() === NATIVE_EVM;
|
|
1404
|
-
}
|
|
1405
|
-
function normalizeAddress(address, chainType) {
|
|
1406
|
-
const trimmed = address.trim();
|
|
1407
|
-
if (normalizeChainType(chainType) === "solana") {
|
|
1408
|
-
if (isSolanaNativeTokenAlias(trimmed)) {
|
|
1409
|
-
return NATIVE_SOLANA;
|
|
1410
|
-
}
|
|
1411
|
-
return trimmed;
|
|
1412
|
-
}
|
|
1413
|
-
return trimmed.toLowerCase();
|
|
1414
|
-
}
|
|
1415
|
-
function isZeroAddressLike(address, chainType) {
|
|
1416
|
-
if (!address) return true;
|
|
1417
|
-
const normalized = normalizeAddress(address, chainType);
|
|
1418
|
-
return normalized === normalizeAddress(getNativeTokenAddress(chainType), chainType) || normalized === "0x0000000000000000000000000000000000000000";
|
|
1419
|
-
}
|
|
1420
|
-
var NATIVE_EVM, NATIVE_SOLANA, CHAIN_TYPE_ALIASES;
|
|
1421
|
-
var init_chains = __esm({
|
|
1422
|
-
"src/utils/chains.ts"() {
|
|
1423
|
-
"use strict";
|
|
1424
|
-
NATIVE_EVM = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
1425
|
-
NATIVE_SOLANA = "So11111111111111111111111111111111111111111";
|
|
1426
|
-
CHAIN_TYPE_ALIASES = {
|
|
1427
|
-
btc: "bitcoin",
|
|
1428
|
-
bitcoin: "bitcoin",
|
|
1429
|
-
sei: "cosmos",
|
|
1430
|
-
"pacific-1": "cosmos"
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
|
|
1435
|
-
// src/validation/address.ts
|
|
1436
|
-
import { isAddress as isEvmAddress } from "viem";
|
|
1437
|
-
function hasMixedCase(value) {
|
|
1438
|
-
return value !== value.toLowerCase() && value !== value.toUpperCase();
|
|
1439
|
-
}
|
|
1440
|
-
function validateBech32LikeAddress(address, prefix) {
|
|
1441
|
-
const trimmed = address.trim();
|
|
1442
|
-
if (!trimmed) {
|
|
1443
|
-
return { isValid: false, error: "Address is required." };
|
|
1444
|
-
}
|
|
1445
|
-
if (hasMixedCase(trimmed)) {
|
|
1446
|
-
return { isValid: false, error: "Bech32 addresses cannot mix case." };
|
|
1447
|
-
}
|
|
1448
|
-
const lower = trimmed.toLowerCase();
|
|
1449
|
-
const expectedPrefix = `${prefix.toLowerCase()}1`;
|
|
1450
|
-
if (!lower.startsWith(expectedPrefix)) {
|
|
1451
|
-
return {
|
|
1452
|
-
isValid: false,
|
|
1453
|
-
error: `Address must start with ${expectedPrefix}.`
|
|
1454
|
-
};
|
|
1443
|
+
const lower = trimmed.toLowerCase();
|
|
1444
|
+
const expectedPrefix = `${prefix.toLowerCase()}1`;
|
|
1445
|
+
if (!lower.startsWith(expectedPrefix)) {
|
|
1446
|
+
return {
|
|
1447
|
+
isValid: false,
|
|
1448
|
+
error: `Address must start with ${expectedPrefix}.`
|
|
1449
|
+
};
|
|
1455
1450
|
}
|
|
1456
1451
|
const dataPart = lower.slice(expectedPrefix.length);
|
|
1457
1452
|
if (dataPart.length < 6 || !BECH32_CHARSET.test(dataPart)) {
|
|
@@ -1627,2088 +1622,2108 @@ var init_address = __esm({
|
|
|
1627
1622
|
}
|
|
1628
1623
|
});
|
|
1629
1624
|
|
|
1630
|
-
// src/
|
|
1631
|
-
function
|
|
1632
|
-
if (
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
const normalized = String(raw).trim();
|
|
1636
|
-
return normalized || void 0;
|
|
1625
|
+
// src/core/balances.ts
|
|
1626
|
+
function toStringOrUndefined(value) {
|
|
1627
|
+
if (typeof value !== "string") return void 0;
|
|
1628
|
+
const trimmed = value.trim();
|
|
1629
|
+
return trimmed || void 0;
|
|
1637
1630
|
}
|
|
1638
|
-
function
|
|
1639
|
-
if (
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1631
|
+
function toNumberOrUndefined(value) {
|
|
1632
|
+
if (typeof value === "number") {
|
|
1633
|
+
return Number.isFinite(value) ? value : void 0;
|
|
1634
|
+
}
|
|
1635
|
+
if (typeof value === "string") {
|
|
1636
|
+
const parsed = Number(value.trim());
|
|
1637
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
1638
|
+
}
|
|
1639
|
+
return void 0;
|
|
1643
1640
|
}
|
|
1644
|
-
function
|
|
1645
|
-
|
|
1641
|
+
function fallbackTokenSymbol(address, chainType) {
|
|
1642
|
+
if (chainType?.toLowerCase() === "solana") {
|
|
1643
|
+
return "SPL";
|
|
1644
|
+
}
|
|
1645
|
+
return `TOKEN-${address.slice(0, 6)}`;
|
|
1646
1646
|
}
|
|
1647
|
-
function
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (entry.chainType !== next.chainType) return true;
|
|
1653
|
-
if (normalizedChainKey && entry.chainKey === normalizedChainKey)
|
|
1654
|
-
return false;
|
|
1655
|
-
if (normalizedChainId && entry.chainId === normalizedChainId) return false;
|
|
1656
|
-
if (!normalizedChainKey && !normalizedChainId) return false;
|
|
1657
|
-
return true;
|
|
1647
|
+
function emitBalanceStreamChunk(address, chunkSize) {
|
|
1648
|
+
TrustwareConfigStore.get().onEvent?.({
|
|
1649
|
+
type: "balance_stream_chunk",
|
|
1650
|
+
address,
|
|
1651
|
+
chunkSize
|
|
1658
1652
|
});
|
|
1659
|
-
if (!normalizedAddress) return createWalletIdentity(addresses);
|
|
1660
|
-
return createWalletIdentity([
|
|
1661
|
-
...addresses,
|
|
1662
|
-
{
|
|
1663
|
-
...next,
|
|
1664
|
-
address: normalizedAddress,
|
|
1665
|
-
chainKey: normalizedChainKey,
|
|
1666
|
-
chainId: normalizedChainId
|
|
1667
|
-
}
|
|
1668
|
-
]);
|
|
1669
1653
|
}
|
|
1670
|
-
function
|
|
1654
|
+
function emitBalanceStreamFallback(address, error) {
|
|
1655
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1656
|
+
TrustwareConfigStore.get().onEvent?.({
|
|
1657
|
+
type: "balance_stream_fallback",
|
|
1658
|
+
address,
|
|
1659
|
+
message
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
function normalizeRows(rows, chain, address, registry) {
|
|
1663
|
+
const chainKey = chain.networkIdentifier ?? String(chain.chainId ?? chain.id);
|
|
1671
1664
|
const chainType = normalizeChainType(chain);
|
|
1672
|
-
const
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1665
|
+
const nativeAddress = getNativeTokenAddress(chainType);
|
|
1666
|
+
const map = /* @__PURE__ */ new Map();
|
|
1667
|
+
for (const item of rows) {
|
|
1668
|
+
const category = toStringOrUndefined(item.category)?.toLowerCase();
|
|
1669
|
+
const addressRaw = item.contract ?? item.token_address ?? item.address ?? item.addr;
|
|
1670
|
+
const tokenAddress = typeof addressRaw === "string" ? addressRaw.trim() : void 0;
|
|
1671
|
+
const symbol = toStringOrUndefined(item.symbol ?? item.sym);
|
|
1672
|
+
const name = toStringOrUndefined(item.name ?? item.token_name ?? item.token) ?? symbol;
|
|
1673
|
+
const decimals = toNumberOrUndefined(item.decimals ?? item.dec);
|
|
1674
|
+
const balance = String(item.balance ?? item.bal ?? "0");
|
|
1675
|
+
const explicitNative = Boolean(item.native ?? item.is_native);
|
|
1676
|
+
const nativeFlag = explicitNative || category === "native" || isZeroAddressLike(tokenAddress, chainType);
|
|
1677
|
+
if (nativeFlag) {
|
|
1678
|
+
const nativeRow = {
|
|
1679
|
+
chain_key: chainKey,
|
|
1680
|
+
category: "native",
|
|
1681
|
+
contract: nativeAddress,
|
|
1682
|
+
address: nativeAddress,
|
|
1683
|
+
symbol: symbol ?? chain.nativeCurrency?.symbol ?? "NATIVE",
|
|
1684
|
+
name: name ?? chain.nativeCurrency?.name ?? symbol,
|
|
1685
|
+
decimals: decimals ?? chain.nativeCurrency?.decimals ?? 18,
|
|
1686
|
+
balance
|
|
1687
|
+
};
|
|
1688
|
+
map.set(`${chainKey}:${nativeAddress}`, nativeRow);
|
|
1689
|
+
continue;
|
|
1690
|
+
}
|
|
1691
|
+
if (!tokenAddress || decimals === void 0) continue;
|
|
1692
|
+
const metadata = registry.findToken(chain.chainId, tokenAddress);
|
|
1693
|
+
const displaySymbol = symbol ?? metadata?.symbol ?? fallbackTokenSymbol(tokenAddress, chainType);
|
|
1694
|
+
const displayName = name ?? metadata?.name ?? displaySymbol;
|
|
1695
|
+
const normalizedAddress = metadata?.address ?? tokenAddress;
|
|
1696
|
+
map.set(`${chainKey}:${normalizedAddress}`, {
|
|
1697
|
+
chain_key: chainKey,
|
|
1698
|
+
category: category ?? (chainType === "solana" ? "spl" : "erc20"),
|
|
1699
|
+
contract: normalizedAddress,
|
|
1700
|
+
address: normalizedAddress,
|
|
1701
|
+
symbol: displaySymbol,
|
|
1702
|
+
name: displayName,
|
|
1703
|
+
decimals: metadata?.decimals ?? decimals,
|
|
1704
|
+
balance,
|
|
1705
|
+
logoURI: metadata?.logoURI,
|
|
1706
|
+
usdPrice: metadata?.usdPrice
|
|
1707
|
+
});
|
|
1696
1708
|
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
chainKey,
|
|
1709
|
-
chainId
|
|
1710
|
-
};
|
|
1709
|
+
if (!Array.from(map.values()).some((row) => row.category === "native")) {
|
|
1710
|
+
map.set(`${chainKey}:${nativeAddress}`, {
|
|
1711
|
+
chain_key: chainKey,
|
|
1712
|
+
category: "native",
|
|
1713
|
+
contract: nativeAddress,
|
|
1714
|
+
address: nativeAddress,
|
|
1715
|
+
symbol: chain.nativeCurrency?.symbol ?? "NATIVE",
|
|
1716
|
+
name: chain.nativeCurrency?.name ?? chain.nativeCurrency?.symbol,
|
|
1717
|
+
decimals: chain.nativeCurrency?.decimals ?? 18,
|
|
1718
|
+
balance: "0"
|
|
1719
|
+
});
|
|
1711
1720
|
}
|
|
1712
|
-
return {
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
};
|
|
1721
|
+
return Array.from(map.values()).sort((a, b) => {
|
|
1722
|
+
try {
|
|
1723
|
+
return Number(BigInt(b.balance) - BigInt(a.balance));
|
|
1724
|
+
} catch {
|
|
1725
|
+
return 0;
|
|
1726
|
+
}
|
|
1727
|
+
});
|
|
1720
1728
|
}
|
|
1721
|
-
function
|
|
1722
|
-
|
|
1723
|
-
if (!chainType) return null;
|
|
1724
|
-
const address = params.address.trim();
|
|
1725
|
-
const chainId = normalizeIdentityChainId(params.chain);
|
|
1726
|
-
const chainDef = typeof params.chain === "object" && params.chain ? params.chain : void 0;
|
|
1727
|
-
const chainKey = chainDef ? normalizeChainKey(
|
|
1728
|
-
chainDef.networkIdentifier ?? chainDef.chainId ?? chainDef.id
|
|
1729
|
-
) : void 0;
|
|
1730
|
-
return {
|
|
1731
|
-
address,
|
|
1732
|
-
chainType,
|
|
1733
|
-
chainId,
|
|
1734
|
-
chainKey,
|
|
1735
|
-
providerId: params.providerId,
|
|
1736
|
-
source: params.source
|
|
1737
|
-
};
|
|
1729
|
+
function normalizeStreamChunk(chunk) {
|
|
1730
|
+
return Array.isArray(chunk) ? chunk : [chunk];
|
|
1738
1731
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1732
|
+
function mergeBalanceWrappers(current, incoming) {
|
|
1733
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1734
|
+
for (const item of current) {
|
|
1735
|
+
merged.set(item.chain_id, item);
|
|
1736
|
+
}
|
|
1737
|
+
for (const item of incoming) {
|
|
1738
|
+
const existing = merged.get(item.chain_id);
|
|
1739
|
+
if (!existing) {
|
|
1740
|
+
merged.set(item.chain_id, item);
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
const balancesByKey = /* @__PURE__ */ new Map();
|
|
1744
|
+
for (const row of existing.balances ?? []) {
|
|
1745
|
+
balancesByKey.set(`${row.contract ?? row.address ?? row.symbol}`, row);
|
|
1746
|
+
}
|
|
1747
|
+
for (const row of item.balances ?? []) {
|
|
1748
|
+
balancesByKey.set(`${row.contract ?? row.address ?? row.symbol}`, row);
|
|
1749
|
+
}
|
|
1750
|
+
merged.set(item.chain_id, {
|
|
1751
|
+
...existing,
|
|
1752
|
+
...item,
|
|
1753
|
+
balances: Array.from(balancesByKey.values()),
|
|
1754
|
+
count: item.count ?? existing.count
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
return Array.from(merged.values());
|
|
1758
|
+
}
|
|
1759
|
+
async function parseStreamingBalances(response, address, options = {}) {
|
|
1760
|
+
if (!response.body) {
|
|
1761
|
+
throw new Error("balances stream: empty response body");
|
|
1762
|
+
}
|
|
1763
|
+
const decoder = new TextDecoder();
|
|
1764
|
+
const reader = response.body.getReader();
|
|
1765
|
+
async function* stream() {
|
|
1766
|
+
let buffer = "";
|
|
1767
|
+
try {
|
|
1768
|
+
while (true) {
|
|
1769
|
+
const { value, done } = await reader.read();
|
|
1770
|
+
if (done) break;
|
|
1771
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1772
|
+
const frames = buffer.split(/\r?\n/);
|
|
1773
|
+
buffer = frames.pop() ?? "";
|
|
1774
|
+
for (const frame of frames) {
|
|
1775
|
+
const trimmed = frame.trim();
|
|
1776
|
+
if (!trimmed) continue;
|
|
1777
|
+
try {
|
|
1778
|
+
const parsed = JSON.parse(trimmed);
|
|
1779
|
+
if (!parsed.chain_id) continue;
|
|
1780
|
+
const chunk = normalizeStreamChunk(parsed);
|
|
1781
|
+
emitBalanceStreamChunk(address, chunk.length);
|
|
1782
|
+
yield chunk;
|
|
1783
|
+
} catch (error) {
|
|
1784
|
+
if (options.strict) {
|
|
1785
|
+
throw error;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1758
1789
|
}
|
|
1759
|
-
|
|
1760
|
-
|
|
1790
|
+
const tail = buffer.trim();
|
|
1791
|
+
if (tail) {
|
|
1792
|
+
try {
|
|
1793
|
+
const parsed = JSON.parse(tail);
|
|
1794
|
+
if (parsed.chain_id) {
|
|
1795
|
+
const chunk = normalizeStreamChunk(parsed);
|
|
1796
|
+
emitBalanceStreamChunk(address, chunk.length);
|
|
1797
|
+
yield chunk;
|
|
1798
|
+
}
|
|
1799
|
+
} catch (error) {
|
|
1800
|
+
if (options.strict) {
|
|
1801
|
+
throw error;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1761
1804
|
}
|
|
1762
|
-
}
|
|
1805
|
+
} finally {
|
|
1806
|
+
reader.releaseLock();
|
|
1807
|
+
}
|
|
1763
1808
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
const
|
|
1771
|
-
const
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1809
|
+
return stream();
|
|
1810
|
+
}
|
|
1811
|
+
async function getBalances(chainRef, address) {
|
|
1812
|
+
const reg = await ensureRegistry();
|
|
1813
|
+
const chain = reg.chain(chainRef);
|
|
1814
|
+
if (!chain) return [];
|
|
1815
|
+
const trimmedAddress = address.trim();
|
|
1816
|
+
const validation = validateAddressForChain(trimmedAddress, chain);
|
|
1817
|
+
if (!validation.isValid) return [];
|
|
1818
|
+
const chainKey = chain.networkIdentifier ?? String(chain.chainId ?? chain.id);
|
|
1819
|
+
const cacheKey = [
|
|
1820
|
+
chainKey,
|
|
1821
|
+
trimmedAddress,
|
|
1822
|
+
chain.nativeCurrency?.symbol ?? "",
|
|
1823
|
+
chain.nativeCurrency?.decimals ?? "",
|
|
1824
|
+
normalizeChainType(chain) ?? ""
|
|
1825
|
+
].join(":");
|
|
1826
|
+
const cached = balanceCache.get(cacheKey);
|
|
1827
|
+
if (cached) return cached;
|
|
1828
|
+
const url = `${apiBase()}/v1/data/wallets/${encodeURIComponent(chainKey)}/${trimmedAddress}/balances`;
|
|
1829
|
+
const response = await fetch(url, {
|
|
1830
|
+
method: "GET",
|
|
1831
|
+
credentials: "omit",
|
|
1832
|
+
headers: jsonHeaders()
|
|
1833
|
+
});
|
|
1834
|
+
if (!response.ok) throw new Error(`balances: HTTP ${response.status}`);
|
|
1835
|
+
const json = await response.json();
|
|
1836
|
+
const rows = Array.isArray(json) ? json : json.data ?? [];
|
|
1837
|
+
const normalized = normalizeRows(rows, chain, trimmedAddress, reg);
|
|
1838
|
+
balanceCache.set(cacheKey, normalized);
|
|
1839
|
+
return normalized;
|
|
1840
|
+
}
|
|
1841
|
+
async function getBalancesByAddress(address, opts) {
|
|
1842
|
+
if (opts?.stream && TrustwareConfigStore.get().features.balanceStreaming) {
|
|
1843
|
+
const merged = [];
|
|
1844
|
+
for await (const chunk of getBalancesByAddressStream(address, opts)) {
|
|
1845
|
+
const next = mergeBalanceWrappers(merged, chunk);
|
|
1846
|
+
merged.splice(0, merged.length, ...next);
|
|
1847
|
+
}
|
|
1848
|
+
return merged;
|
|
1777
1849
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
};
|
|
1850
|
+
const url = `${apiBase()}/data/balances/${address}`;
|
|
1851
|
+
const r = await rateLimitedFetch(url, {
|
|
1852
|
+
method: "GET",
|
|
1853
|
+
credentials: "omit",
|
|
1854
|
+
headers: jsonHeaders()
|
|
1855
|
+
});
|
|
1856
|
+
if (!r.ok) throw new Error(`balances: HTTP ${r.status}`);
|
|
1857
|
+
const j = await r.json();
|
|
1858
|
+
return Array.isArray(j) ? j : j.results ?? [];
|
|
1784
1859
|
}
|
|
1785
|
-
async function
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
"[Trustware SDK] projectId changed since last init \u2014 reinitializing WalletConnect connector."
|
|
1790
|
-
);
|
|
1791
|
-
universalConnectorPromise = null;
|
|
1792
|
-
initializedProjectId = null;
|
|
1860
|
+
async function* getBalancesByAddressStream(address, opts = {}) {
|
|
1861
|
+
if (!TrustwareConfigStore.get().features.balanceStreaming) {
|
|
1862
|
+
yield await getBalancesByAddress(address);
|
|
1863
|
+
return;
|
|
1793
1864
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
console.error(
|
|
1804
|
-
"[Trustware SDK] Failed to initialize WalletConnect:",
|
|
1805
|
-
error
|
|
1806
|
-
);
|
|
1807
|
-
throw error;
|
|
1865
|
+
const url = `${apiBase()}/data/balances/${address}?stream=1`;
|
|
1866
|
+
try {
|
|
1867
|
+
const response = await rateLimitedFetch(url, {
|
|
1868
|
+
method: "GET",
|
|
1869
|
+
credentials: "omit",
|
|
1870
|
+
headers: jsonHeaders({
|
|
1871
|
+
Accept: "application/x-ndjson, application/json"
|
|
1872
|
+
}),
|
|
1873
|
+
signal: opts.signal
|
|
1808
1874
|
});
|
|
1875
|
+
if (!response.ok) {
|
|
1876
|
+
throw new Error(`balances stream: HTTP ${response.status}`);
|
|
1877
|
+
}
|
|
1878
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1879
|
+
if (contentType.includes("application/json")) {
|
|
1880
|
+
const payload = await response.json();
|
|
1881
|
+
yield Array.isArray(payload) ? payload : payload.results ?? [];
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
const stream = await parseStreamingBalances(response, address, opts);
|
|
1885
|
+
for await (const chunk of stream) {
|
|
1886
|
+
yield chunk;
|
|
1887
|
+
}
|
|
1888
|
+
} catch (error) {
|
|
1889
|
+
emitBalanceStreamFallback(address, error);
|
|
1890
|
+
yield await getBalancesByAddress(address);
|
|
1809
1891
|
}
|
|
1810
|
-
return universalConnectorPromise;
|
|
1811
1892
|
}
|
|
1812
|
-
function
|
|
1813
|
-
|
|
1814
|
-
|
|
1893
|
+
async function ensureRegistry() {
|
|
1894
|
+
if (!_registry) {
|
|
1895
|
+
_registry = new Registry(apiBase());
|
|
1896
|
+
}
|
|
1897
|
+
await _registry.ensureLoaded();
|
|
1898
|
+
return _registry;
|
|
1815
1899
|
}
|
|
1816
|
-
var
|
|
1817
|
-
var
|
|
1818
|
-
"src/
|
|
1900
|
+
var balanceCache, _registry;
|
|
1901
|
+
var init_balances = __esm({
|
|
1902
|
+
"src/core/balances.ts"() {
|
|
1819
1903
|
"use strict";
|
|
1904
|
+
init_http();
|
|
1905
|
+
init_registry();
|
|
1820
1906
|
init_store();
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1907
|
+
init_chains();
|
|
1908
|
+
init_address();
|
|
1909
|
+
balanceCache = /* @__PURE__ */ new Map();
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
|
|
1913
|
+
// src/wallets/eipWallets.ts
|
|
1914
|
+
async function addThenSwitch(eth, chainId) {
|
|
1915
|
+
const p = CHAIN_PARAMS[chainId];
|
|
1916
|
+
if (!p) throw new Error(`Unknown chain ${chainId} (no params to add)`);
|
|
1917
|
+
await eth.request({ method: "wallet_addEthereumChain", params: [p] });
|
|
1918
|
+
await eth.request({
|
|
1919
|
+
method: "wallet_switchEthereumChain",
|
|
1920
|
+
params: [{ chainId: p.chainIdHex }]
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
function useEIP1193(eth) {
|
|
1924
|
+
if (!eth?.request) throw new Error("useEIP1193: invalid provider");
|
|
1925
|
+
let switching = false;
|
|
1926
|
+
return {
|
|
1927
|
+
ecosystem: "evm",
|
|
1928
|
+
type: "eip1193",
|
|
1929
|
+
async getAddress() {
|
|
1930
|
+
const [a] = await eth.request({
|
|
1931
|
+
method: "eth_requestAccounts"
|
|
1932
|
+
});
|
|
1933
|
+
if (!a) throw new Error("No connected address");
|
|
1934
|
+
return a;
|
|
1935
|
+
},
|
|
1936
|
+
async getChainId() {
|
|
1937
|
+
const hex = await eth.request({ method: "eth_chainId" });
|
|
1938
|
+
return parseInt(String(hex), 16);
|
|
1939
|
+
},
|
|
1940
|
+
async switchChain(chainId) {
|
|
1941
|
+
if (switching) return;
|
|
1942
|
+
switching = true;
|
|
1943
|
+
const hex = CHAIN_PARAMS[chainId]?.chainIdHex ?? `0x${chainId.toString(16)}`;
|
|
1944
|
+
try {
|
|
1945
|
+
await eth.request({
|
|
1946
|
+
method: "wallet_switchEthereumChain",
|
|
1947
|
+
params: [{ chainId: hex }]
|
|
1948
|
+
});
|
|
1949
|
+
} catch (e2) {
|
|
1950
|
+
if (e2?.code === 4902) {
|
|
1951
|
+
await addThenSwitch(eth, chainId);
|
|
1952
|
+
} else if (e2?.code === 4001) {
|
|
1953
|
+
} else {
|
|
1954
|
+
throw e2;
|
|
1835
1955
|
}
|
|
1956
|
+
} finally {
|
|
1957
|
+
switching = false;
|
|
1836
1958
|
}
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1959
|
+
},
|
|
1960
|
+
request: (args) => eth.request(args)
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
var CHAIN_PARAMS;
|
|
1964
|
+
var init_eipWallets = __esm({
|
|
1965
|
+
"src/wallets/eipWallets.ts"() {
|
|
1966
|
+
"use strict";
|
|
1967
|
+
CHAIN_PARAMS = {
|
|
1968
|
+
8453: {
|
|
1969
|
+
chainIdHex: "0x2105",
|
|
1970
|
+
chainName: "Base",
|
|
1971
|
+
rpcUrls: ["https://mainnet.base.org"],
|
|
1972
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1973
|
+
blockExplorerUrls: ["https://basescan.org"]
|
|
1847
1974
|
},
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
seiCosmosMainnet = {
|
|
1855
|
-
id: 9001,
|
|
1856
|
-
chainNamespace: "cosmos",
|
|
1857
|
-
caipNetworkId: "cosmos:pacific-1",
|
|
1858
|
-
name: "Sei Cosmos",
|
|
1859
|
-
nativeCurrency: { name: "Sei", symbol: "SEI", decimals: 6 },
|
|
1860
|
-
rpcUrls: {
|
|
1861
|
-
default: { http: ["https://rpc.sei-apis.com"] }
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
ethereumMainnet = {
|
|
1865
|
-
id: 1,
|
|
1866
|
-
chainNamespace: "eip155",
|
|
1867
|
-
caipNetworkId: "eip155:1",
|
|
1868
|
-
name: "Ethereum Mainnet",
|
|
1869
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1870
|
-
rpcUrls: {
|
|
1871
|
-
default: { http: ["https://rpc.ankr.com/eth"] }
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
optimismMainnet = {
|
|
1875
|
-
id: 10,
|
|
1876
|
-
chainNamespace: "eip155",
|
|
1877
|
-
caipNetworkId: "eip155:10",
|
|
1878
|
-
name: "Optimism Mainnet",
|
|
1879
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1880
|
-
rpcUrls: {
|
|
1881
|
-
default: { http: ["https://rpc.ankr.com/optimism"] }
|
|
1882
|
-
}
|
|
1883
|
-
};
|
|
1884
|
-
flareMainnet = {
|
|
1885
|
-
id: 14,
|
|
1886
|
-
chainNamespace: "eip155",
|
|
1887
|
-
caipNetworkId: "eip155:14",
|
|
1888
|
-
name: "Flare",
|
|
1889
|
-
nativeCurrency: { name: "Flare", symbol: "FLR", decimals: 18 },
|
|
1890
|
-
rpcUrls: {
|
|
1891
|
-
default: { http: ["https://flare-api.flare.network/ext/C/rpc"] }
|
|
1892
|
-
}
|
|
1893
|
-
};
|
|
1894
|
-
cronosMainnet = {
|
|
1895
|
-
id: 25,
|
|
1896
|
-
chainNamespace: "eip155",
|
|
1897
|
-
caipNetworkId: "eip155:25",
|
|
1898
|
-
name: "Cronos",
|
|
1899
|
-
nativeCurrency: { name: "Cronos", symbol: "CRO", decimals: 18 },
|
|
1900
|
-
rpcUrls: {
|
|
1901
|
-
default: { http: ["https://evm.cronos.org"] }
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
rootstockMainnet = {
|
|
1905
|
-
id: 30,
|
|
1906
|
-
chainNamespace: "eip155",
|
|
1907
|
-
caipNetworkId: "eip155:30",
|
|
1908
|
-
name: "Rootstock",
|
|
1909
|
-
nativeCurrency: {
|
|
1910
|
-
name: "Rootstock Smart Bitcoin",
|
|
1911
|
-
symbol: "RBTC",
|
|
1912
|
-
decimals: 18
|
|
1975
|
+
42161: {
|
|
1976
|
+
chainIdHex: "0xa4b1",
|
|
1977
|
+
chainName: "Arbitrum One",
|
|
1978
|
+
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
1979
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1980
|
+
blockExplorerUrls: ["https://arbiscan.io"]
|
|
1913
1981
|
},
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
chainNamespace: "eip155",
|
|
1921
|
-
caipNetworkId: "eip155:40",
|
|
1922
|
-
name: "Telos",
|
|
1923
|
-
nativeCurrency: { name: "Telos", symbol: "TLOS", decimals: 18 },
|
|
1924
|
-
rpcUrls: {
|
|
1925
|
-
default: { http: ["https://rpc.telos.net"] }
|
|
1926
|
-
}
|
|
1927
|
-
};
|
|
1928
|
-
xdcMainnet = {
|
|
1929
|
-
id: 50,
|
|
1930
|
-
chainNamespace: "eip155",
|
|
1931
|
-
caipNetworkId: "eip155:50",
|
|
1932
|
-
name: "XDC",
|
|
1933
|
-
nativeCurrency: { name: "XDC", symbol: "XDC", decimals: 18 },
|
|
1934
|
-
rpcUrls: {
|
|
1935
|
-
default: { http: ["https://rpc.xdcrpc.com"] }
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
bscMainnet = {
|
|
1939
|
-
id: 56,
|
|
1940
|
-
chainNamespace: "eip155",
|
|
1941
|
-
caipNetworkId: "eip155:56",
|
|
1942
|
-
name: "BNB Smart Chain",
|
|
1943
|
-
nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
|
|
1944
|
-
rpcUrls: {
|
|
1945
|
-
default: { http: ["https://rpc.ankr.com/bsc"] }
|
|
1982
|
+
43114: {
|
|
1983
|
+
chainIdHex: "0xa86a",
|
|
1984
|
+
chainName: "Avalanche C-Chain",
|
|
1985
|
+
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
1986
|
+
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
1987
|
+
blockExplorerUrls: ["https://snowtrace.io"]
|
|
1946
1988
|
}
|
|
1947
1989
|
};
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1992
|
+
|
|
1993
|
+
// src/core/sdkRpc.ts
|
|
1994
|
+
async function requestSDKRPC(path, init = {}) {
|
|
1995
|
+
const response = await rateLimitedFetch(`${apiBase()}/v1/sdk/rpc${path}`, {
|
|
1996
|
+
...init,
|
|
1997
|
+
headers: jsonHeaders()
|
|
1998
|
+
});
|
|
1999
|
+
let payload = null;
|
|
2000
|
+
try {
|
|
2001
|
+
payload = await response.json();
|
|
2002
|
+
} catch {
|
|
2003
|
+
payload = null;
|
|
2004
|
+
}
|
|
2005
|
+
if (response.ok && payload?.success && payload.data !== void 0) {
|
|
2006
|
+
return payload.data;
|
|
2007
|
+
}
|
|
2008
|
+
throw new SDKRPCError(
|
|
2009
|
+
payload?.error?.message || `HTTP ${response.status}: ${response.statusText || "SDK RPC request failed"}`,
|
|
2010
|
+
{
|
|
2011
|
+
code: payload?.error?.code,
|
|
2012
|
+
context: payload?.error?.context,
|
|
2013
|
+
status: response.status
|
|
2014
|
+
}
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
async function sendSolanaSerialized(body) {
|
|
2018
|
+
return requestSDKRPC(
|
|
2019
|
+
"/solana/send-serialized",
|
|
2020
|
+
{
|
|
2021
|
+
method: "POST",
|
|
2022
|
+
body: JSON.stringify(body)
|
|
2023
|
+
}
|
|
2024
|
+
);
|
|
2025
|
+
}
|
|
2026
|
+
async function getSolanaTxStatus(params) {
|
|
2027
|
+
const search = new URLSearchParams(params);
|
|
2028
|
+
return requestSDKRPC(
|
|
2029
|
+
`/solana/tx-status?${search.toString()}`,
|
|
2030
|
+
{ method: "GET" }
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
var SDKRPCError;
|
|
2034
|
+
var init_sdkRpc = __esm({
|
|
2035
|
+
"src/core/sdkRpc.ts"() {
|
|
2036
|
+
"use strict";
|
|
2037
|
+
init_http();
|
|
2038
|
+
SDKRPCError = class extends Error {
|
|
2039
|
+
constructor(message, options) {
|
|
2040
|
+
super(message);
|
|
2041
|
+
this.name = "SDKRPCError";
|
|
2042
|
+
this.code = options?.code;
|
|
2043
|
+
this.context = options?.context;
|
|
2044
|
+
this.status = options?.status;
|
|
1956
2045
|
}
|
|
1957
2046
|
};
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
rpcUrls: {
|
|
2035
|
-
default: { http: ["https://api.lens.matterhosted.dev"] }
|
|
2036
|
-
}
|
|
2037
|
-
};
|
|
2038
|
-
fantomMainnet = {
|
|
2039
|
-
id: 250,
|
|
2040
|
-
chainNamespace: "eip155",
|
|
2041
|
-
caipNetworkId: "eip155:250",
|
|
2042
|
-
name: "Fantom Opera",
|
|
2043
|
-
nativeCurrency: { name: "Fantom", symbol: "FTM", decimals: 18 },
|
|
2044
|
-
rpcUrls: {
|
|
2045
|
-
default: { http: ["https://rpc.ankr.com/fantom"] }
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
// src/wallets/solana.ts
|
|
2051
|
+
function getPublicKeyString(provider) {
|
|
2052
|
+
const publicKey = provider?.publicKey;
|
|
2053
|
+
if (!publicKey) return null;
|
|
2054
|
+
const text = publicKey.toString().trim();
|
|
2055
|
+
return text || null;
|
|
2056
|
+
}
|
|
2057
|
+
function decodeBase64(serializedTransaction) {
|
|
2058
|
+
const trimmed = serializedTransaction.trim();
|
|
2059
|
+
if (typeof Buffer !== "undefined") {
|
|
2060
|
+
return Uint8Array.from(Buffer.from(trimmed, "base64"));
|
|
2061
|
+
}
|
|
2062
|
+
const binary = globalThis.atob(trimmed);
|
|
2063
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
2064
|
+
}
|
|
2065
|
+
async function decodeBase64Transaction(serializedTransaction) {
|
|
2066
|
+
const bytes = decodeBase64(serializedTransaction);
|
|
2067
|
+
const { Transaction, VersionedTransaction } = await import("@solana/web3.js");
|
|
2068
|
+
try {
|
|
2069
|
+
return VersionedTransaction.deserialize(bytes);
|
|
2070
|
+
} catch {
|
|
2071
|
+
return Transaction.from(bytes);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
function encodeBase64(bytes) {
|
|
2075
|
+
if (typeof Buffer !== "undefined") {
|
|
2076
|
+
return Buffer.from(bytes).toString("base64");
|
|
2077
|
+
}
|
|
2078
|
+
let binary = "";
|
|
2079
|
+
for (const byte of bytes) {
|
|
2080
|
+
binary += String.fromCharCode(byte);
|
|
2081
|
+
}
|
|
2082
|
+
return globalThis.btoa(binary);
|
|
2083
|
+
}
|
|
2084
|
+
async function waitForSolanaConfirmation(chainId, signature) {
|
|
2085
|
+
const started = Date.now();
|
|
2086
|
+
const timeoutMs = 12e4;
|
|
2087
|
+
const intervalMs = 2e3;
|
|
2088
|
+
while (Date.now() - started < timeoutMs) {
|
|
2089
|
+
const status = await getSolanaTxStatus({ chainId, signature });
|
|
2090
|
+
if (status.status === "success") return signature;
|
|
2091
|
+
if (status.status === "failed") {
|
|
2092
|
+
throw new Error("Solana transaction failed");
|
|
2093
|
+
}
|
|
2094
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
2095
|
+
}
|
|
2096
|
+
throw new Error("Timed out waiting for Solana transaction confirmation");
|
|
2097
|
+
}
|
|
2098
|
+
function bindSolanaProviderEvents(provider, handlers) {
|
|
2099
|
+
const onConnect = () => handlers.onConnect?.();
|
|
2100
|
+
const onAccountChanged = () => handlers.onAccountChanged?.();
|
|
2101
|
+
const onDisconnect = () => handlers.onDisconnect?.();
|
|
2102
|
+
provider.on?.("connect", onConnect);
|
|
2103
|
+
provider.on?.("accountChanged", onAccountChanged);
|
|
2104
|
+
provider.on?.("disconnect", onDisconnect);
|
|
2105
|
+
return () => {
|
|
2106
|
+
provider.off?.("connect", onConnect);
|
|
2107
|
+
provider.off?.("accountChanged", onAccountChanged);
|
|
2108
|
+
provider.off?.("disconnect", onDisconnect);
|
|
2109
|
+
provider.removeListener?.("connect", onConnect);
|
|
2110
|
+
provider.removeListener?.("accountChanged", onAccountChanged);
|
|
2111
|
+
provider.removeListener?.("disconnect", onDisconnect);
|
|
2112
|
+
};
|
|
2113
|
+
}
|
|
2114
|
+
function toSolanaWalletInterface(provider) {
|
|
2115
|
+
return {
|
|
2116
|
+
ecosystem: "solana",
|
|
2117
|
+
type: "solana",
|
|
2118
|
+
async getAddress() {
|
|
2119
|
+
const current = getPublicKeyString(provider);
|
|
2120
|
+
if (current) return current;
|
|
2121
|
+
if (!provider.connect) {
|
|
2122
|
+
throw new Error("Selected Solana wallet cannot connect");
|
|
2046
2123
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2124
|
+
await provider.connect();
|
|
2125
|
+
const next = getPublicKeyString(provider);
|
|
2126
|
+
if (!next) throw new Error("No connected Solana address");
|
|
2127
|
+
return next;
|
|
2128
|
+
},
|
|
2129
|
+
async disconnect() {
|
|
2130
|
+
await provider.disconnect?.();
|
|
2131
|
+
},
|
|
2132
|
+
async getChainKey() {
|
|
2133
|
+
return "solana-mainnet-beta";
|
|
2134
|
+
},
|
|
2135
|
+
async sendSerializedTransaction(serializedTransactionBase64, chainId) {
|
|
2136
|
+
const transaction = await decodeBase64Transaction(
|
|
2137
|
+
serializedTransactionBase64
|
|
2138
|
+
);
|
|
2139
|
+
if (provider.signAndSendTransaction) {
|
|
2140
|
+
const result = await provider.signAndSendTransaction(transaction, {
|
|
2141
|
+
preflightCommitment: "confirmed"
|
|
2142
|
+
});
|
|
2143
|
+
if (typeof result === "string") return result;
|
|
2144
|
+
if (result?.signature) return result.signature;
|
|
2056
2145
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
id: 288,
|
|
2060
|
-
chainNamespace: "eip155",
|
|
2061
|
-
caipNetworkId: "eip155:288",
|
|
2062
|
-
name: "Boba",
|
|
2063
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2064
|
-
rpcUrls: {
|
|
2065
|
-
default: { http: ["https://mainnet.boba.network"] }
|
|
2146
|
+
if (!provider.signTransaction) {
|
|
2147
|
+
throw new Error("Connected Solana wallet cannot sign transactions");
|
|
2066
2148
|
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2149
|
+
const signed = await provider.signTransaction(transaction);
|
|
2150
|
+
const resolvedChainId = chainId?.trim() || "solana-mainnet";
|
|
2151
|
+
const serializedSigned = encodeBase64(signed.serialize());
|
|
2152
|
+
const { signature } = await sendSolanaSerialized({
|
|
2153
|
+
chainId: resolvedChainId,
|
|
2154
|
+
serializedTransaction: serializedSigned
|
|
2155
|
+
});
|
|
2156
|
+
await waitForSolanaConfirmation(resolvedChainId, signature);
|
|
2157
|
+
return signature;
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
var init_solana = __esm({
|
|
2162
|
+
"src/wallets/solana.ts"() {
|
|
2163
|
+
"use strict";
|
|
2164
|
+
init_sdkRpc();
|
|
2165
|
+
}
|
|
2166
|
+
});
|
|
2167
|
+
|
|
2168
|
+
// src/wallets/adapters.ts
|
|
2169
|
+
function toWalletInterfaceFromDetected(dw) {
|
|
2170
|
+
if (!dw?.provider) throw new Error("No provider on detected wallet");
|
|
2171
|
+
if (dw.via === "solana-window" || dw.meta.ecosystem === "solana") {
|
|
2172
|
+
return toSolanaWalletInterface(dw.provider);
|
|
2173
|
+
}
|
|
2174
|
+
const eth = dw.provider;
|
|
2175
|
+
return useEIP1193(eth);
|
|
2176
|
+
}
|
|
2177
|
+
var init_adapters = __esm({
|
|
2178
|
+
"src/wallets/adapters.ts"() {
|
|
2179
|
+
"use strict";
|
|
2180
|
+
init_eipWallets();
|
|
2181
|
+
init_solana();
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
|
|
2185
|
+
// src/wallets/connect.ts
|
|
2186
|
+
function pickWagmiConnector(wagmi, metaName, metaId, metaCategory) {
|
|
2187
|
+
const lower = metaName.toLowerCase();
|
|
2188
|
+
const cons = wagmi.connectors();
|
|
2189
|
+
return cons.find((c) => c.name.toLowerCase().includes(lower)) || metaId === "coinbase" && cons.find((c) => c.name.toLowerCase().includes("coinbase")) || metaId === "walletconnect" && cons.find((c) => (c.type ?? "").toLowerCase() === "walletconnect") || metaCategory === "injected" && cons.find((c) => (c.type ?? "").toLowerCase() === "injected") || null;
|
|
2190
|
+
}
|
|
2191
|
+
async function connectDetectedWallet(dw, opts) {
|
|
2192
|
+
const { wagmi, touchAddress = true } = opts ?? {};
|
|
2193
|
+
if (dw.meta.id === "walletconnect" || dw.via === "walletconnect") {
|
|
2194
|
+
if (wagmi) {
|
|
2195
|
+
const conn = pickWagmiConnector(
|
|
2196
|
+
wagmi,
|
|
2197
|
+
dw.meta.name,
|
|
2198
|
+
dw.meta.id,
|
|
2199
|
+
dw.meta.category
|
|
2200
|
+
);
|
|
2201
|
+
if (conn) {
|
|
2202
|
+
await wagmi.connect(conn);
|
|
2203
|
+
return { via: "wagmi", api: null };
|
|
2096
2204
|
}
|
|
2205
|
+
}
|
|
2206
|
+
throw new Error("WalletConnect connection failed. Please try again.");
|
|
2207
|
+
}
|
|
2208
|
+
if (dw.via === "solana-window" || dw.meta.ecosystem === "solana") {
|
|
2209
|
+
try {
|
|
2210
|
+
const provider = dw.provider;
|
|
2211
|
+
await provider.connect();
|
|
2212
|
+
return {
|
|
2213
|
+
via: "eip1193",
|
|
2214
|
+
api: toWalletInterfaceFromDetected(dw),
|
|
2215
|
+
error: null
|
|
2216
|
+
};
|
|
2217
|
+
} catch (err) {
|
|
2218
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
2219
|
+
return { via: "eip1193", api: null, error: errorMsg };
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
if (wagmi) {
|
|
2223
|
+
const conn = pickWagmiConnector(
|
|
2224
|
+
wagmi,
|
|
2225
|
+
dw.meta.name,
|
|
2226
|
+
dw.meta.id,
|
|
2227
|
+
dw.meta.category
|
|
2228
|
+
);
|
|
2229
|
+
if (conn) {
|
|
2230
|
+
await wagmi.connect(conn);
|
|
2231
|
+
return { via: "wagmi", api: null, error: null };
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
const api = toWalletInterfaceFromDetected(dw);
|
|
2235
|
+
if (touchAddress) await api.getAddress();
|
|
2236
|
+
return { via: "eip1193", api, error: null };
|
|
2237
|
+
}
|
|
2238
|
+
var init_connect = __esm({
|
|
2239
|
+
"src/wallets/connect.ts"() {
|
|
2240
|
+
"use strict";
|
|
2241
|
+
init_adapters();
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
|
|
2245
|
+
// src/identity/index.ts
|
|
2246
|
+
function normalizeIdentityChainId(chain) {
|
|
2247
|
+
if (!chain || typeof chain === "string") return void 0;
|
|
2248
|
+
const raw = chain.chainId ?? chain.id;
|
|
2249
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
2250
|
+
const normalized = String(raw).trim();
|
|
2251
|
+
return normalized || void 0;
|
|
2252
|
+
}
|
|
2253
|
+
function identityEntryMatchesChain(entry, chainType, chainKey, chainId) {
|
|
2254
|
+
if (chainKey && entry.chainKey && entry.chainKey === chainKey) return true;
|
|
2255
|
+
if (chainId && entry.chainId && entry.chainId === chainId) return true;
|
|
2256
|
+
if (chainType && entry.chainType === chainType) return true;
|
|
2257
|
+
return false;
|
|
2258
|
+
}
|
|
2259
|
+
function createWalletIdentity(addresses = []) {
|
|
2260
|
+
return { addresses };
|
|
2261
|
+
}
|
|
2262
|
+
function upsertWalletIdentityAddress(identity, next) {
|
|
2263
|
+
const normalizedAddress = next.address.trim();
|
|
2264
|
+
const normalizedChainKey = next.chainKey ? normalizeChainKey(next.chainKey) : void 0;
|
|
2265
|
+
const normalizedChainId = next.chainId?.trim() || void 0;
|
|
2266
|
+
const addresses = identity.addresses.filter((entry) => {
|
|
2267
|
+
if (entry.chainType !== next.chainType) return true;
|
|
2268
|
+
if (normalizedChainKey && entry.chainKey === normalizedChainKey)
|
|
2269
|
+
return false;
|
|
2270
|
+
if (normalizedChainId && entry.chainId === normalizedChainId) return false;
|
|
2271
|
+
if (!normalizedChainKey && !normalizedChainId) return false;
|
|
2272
|
+
return true;
|
|
2273
|
+
});
|
|
2274
|
+
if (!normalizedAddress) return createWalletIdentity(addresses);
|
|
2275
|
+
return createWalletIdentity([
|
|
2276
|
+
...addresses,
|
|
2277
|
+
{
|
|
2278
|
+
...next,
|
|
2279
|
+
address: normalizedAddress,
|
|
2280
|
+
chainKey: normalizedChainKey,
|
|
2281
|
+
chainId: normalizedChainId
|
|
2282
|
+
}
|
|
2283
|
+
]);
|
|
2284
|
+
}
|
|
2285
|
+
function resolveWalletAddressForChain(identity, chain) {
|
|
2286
|
+
const chainType = normalizeChainType(chain);
|
|
2287
|
+
const chainDef = typeof chain === "object" && chain ? chain : void 0;
|
|
2288
|
+
const chainKey = chainDef ? normalizeChainKey(
|
|
2289
|
+
chainDef.networkIdentifier ?? chainDef.chainId ?? chainDef.id
|
|
2290
|
+
) : typeof chain === "string" ? normalizeChainKey(chain) : void 0;
|
|
2291
|
+
const chainId = normalizeIdentityChainId(chain);
|
|
2292
|
+
if (!chainType) {
|
|
2293
|
+
return {
|
|
2294
|
+
status: "missing",
|
|
2295
|
+
reason: "unknown_chain_type",
|
|
2296
|
+
chainKey,
|
|
2297
|
+
chainId
|
|
2097
2298
|
};
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2299
|
+
}
|
|
2300
|
+
const match = identity.addresses.find(
|
|
2301
|
+
(entry) => identityEntryMatchesChain(entry, chainType, chainKey, chainId)
|
|
2302
|
+
);
|
|
2303
|
+
if (!match) {
|
|
2304
|
+
return {
|
|
2305
|
+
status: "missing",
|
|
2306
|
+
reason: "missing_chain_address",
|
|
2307
|
+
chainType,
|
|
2308
|
+
chainKey,
|
|
2309
|
+
chainId
|
|
2109
2310
|
};
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2311
|
+
}
|
|
2312
|
+
const validation = validateAddressForChain(
|
|
2313
|
+
match.address,
|
|
2314
|
+
chainDef ?? chainType
|
|
2315
|
+
);
|
|
2316
|
+
if (!validation.isValid) {
|
|
2317
|
+
return {
|
|
2318
|
+
status: "invalid",
|
|
2319
|
+
reason: validation.error ?? "invalid_chain_address",
|
|
2320
|
+
address: match.address,
|
|
2321
|
+
source: match.source,
|
|
2322
|
+
chainType,
|
|
2323
|
+
chainKey,
|
|
2324
|
+
chainId
|
|
2119
2325
|
};
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2326
|
+
}
|
|
2327
|
+
return {
|
|
2328
|
+
status: "resolved",
|
|
2329
|
+
address: match.address.trim(),
|
|
2330
|
+
source: match.source,
|
|
2331
|
+
chainType,
|
|
2332
|
+
chainKey,
|
|
2333
|
+
chainId
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
function buildWalletIdentityAddress(params) {
|
|
2337
|
+
const chainType = normalizeChainType(params.chain);
|
|
2338
|
+
if (!chainType) return null;
|
|
2339
|
+
const address = params.address.trim();
|
|
2340
|
+
const chainId = normalizeIdentityChainId(params.chain);
|
|
2341
|
+
const chainDef = typeof params.chain === "object" && params.chain ? params.chain : void 0;
|
|
2342
|
+
const chainKey = chainDef ? normalizeChainKey(
|
|
2343
|
+
chainDef.networkIdentifier ?? chainDef.chainId ?? chainDef.id
|
|
2344
|
+
) : void 0;
|
|
2345
|
+
return {
|
|
2346
|
+
address,
|
|
2347
|
+
chainType,
|
|
2348
|
+
chainId,
|
|
2349
|
+
chainKey,
|
|
2350
|
+
providerId: params.providerId,
|
|
2351
|
+
source: params.source
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
var IdentityStore;
|
|
2355
|
+
var init_identity = __esm({
|
|
2356
|
+
"src/identity/index.ts"() {
|
|
2357
|
+
"use strict";
|
|
2358
|
+
init_address();
|
|
2359
|
+
init_chains();
|
|
2360
|
+
IdentityStore = class {
|
|
2361
|
+
constructor() {
|
|
2362
|
+
this._identity = createWalletIdentity();
|
|
2128
2363
|
}
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
id: 999,
|
|
2132
|
-
chainNamespace: "eip155",
|
|
2133
|
-
caipNetworkId: "eip155:999",
|
|
2134
|
-
name: "HyperEVM",
|
|
2135
|
-
nativeCurrency: { name: "Hyperliquid", symbol: "HYPE", decimals: 18 },
|
|
2136
|
-
rpcUrls: {
|
|
2137
|
-
default: { http: ["https://rpc.hyperliquid.xyz/evm"] }
|
|
2364
|
+
get snapshot() {
|
|
2365
|
+
return this._identity;
|
|
2138
2366
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
id: 1088,
|
|
2142
|
-
chainNamespace: "eip155",
|
|
2143
|
-
caipNetworkId: "eip155:1088",
|
|
2144
|
-
name: "Metis",
|
|
2145
|
-
nativeCurrency: { name: "METIS", symbol: "METIS", decimals: 18 },
|
|
2146
|
-
rpcUrls: {
|
|
2147
|
-
default: { http: ["https://metis-public.nodies.app"] }
|
|
2367
|
+
reset() {
|
|
2368
|
+
this._identity = createWalletIdentity();
|
|
2148
2369
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
chainNamespace: "eip155",
|
|
2153
|
-
caipNetworkId: "eip155:1135",
|
|
2154
|
-
name: "Lisk",
|
|
2155
|
-
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2156
|
-
rpcUrls: {
|
|
2157
|
-
default: { http: ["https://rpc.api.lisk.com"] }
|
|
2370
|
+
upsert(next) {
|
|
2371
|
+
this._identity = upsertWalletIdentityAddress(this._identity, next);
|
|
2372
|
+
return this._identity;
|
|
2158
2373
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
id: 1284,
|
|
2162
|
-
chainNamespace: "eip155",
|
|
2163
|
-
caipNetworkId: "eip155:1284",
|
|
2164
|
-
name: "Moonbeam",
|
|
2165
|
-
nativeCurrency: { name: "Moonbeam", symbol: "GLMR", decimals: 18 },
|
|
2166
|
-
rpcUrls: {
|
|
2167
|
-
default: { http: ["https://rpc.api.moonbeam.network"] }
|
|
2374
|
+
resolve(chain) {
|
|
2375
|
+
return resolveWalletAddressForChain(this._identity, chain);
|
|
2168
2376
|
}
|
|
2169
2377
|
};
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2378
|
+
}
|
|
2379
|
+
});
|
|
2380
|
+
|
|
2381
|
+
// src/config/walletconnect.ts
|
|
2382
|
+
import { UniversalConnector } from "@reown/appkit-universal-connector";
|
|
2383
|
+
function resolvedMetadata() {
|
|
2384
|
+
const cfg = TrustwareConfigStore.peek();
|
|
2385
|
+
const walletConnect = cfg ? cfg?.walletConnect : void 0;
|
|
2386
|
+
const configured = walletConnect?.metadata;
|
|
2387
|
+
const pageUrl = typeof window !== "undefined" && window.location?.origin ? window.location.origin : configured?.url;
|
|
2388
|
+
if (!pageUrl) {
|
|
2389
|
+
console.warn(
|
|
2390
|
+
"[Trustware SDK] WalletConnect metadata.url could not be determined from window.location or config. Falling back to 'https://trustware.io'. Pass metadata.url explicitly in your WalletConnectConfig to avoid domain verification failures in production."
|
|
2391
|
+
);
|
|
2392
|
+
}
|
|
2393
|
+
return {
|
|
2394
|
+
name: configured?.name ?? "Trustware",
|
|
2395
|
+
description: configured?.description ?? "Cross-chain bridge & top-up",
|
|
2396
|
+
url: pageUrl ?? "https://trustware.io",
|
|
2397
|
+
icons: configured?.icons?.length ? configured.icons : ["https://app.trustware.io/icon.png"]
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
async function getUniversalConnector(walletCfg) {
|
|
2401
|
+
const projectId = walletCfg?.projectId ?? WALLETCONNECT_PROJECT_ID;
|
|
2402
|
+
if (universalConnectorPromise && initializedProjectId !== projectId) {
|
|
2403
|
+
console.warn(
|
|
2404
|
+
"[Trustware SDK] projectId changed since last init \u2014 reinitializing WalletConnect connector."
|
|
2405
|
+
);
|
|
2406
|
+
universalConnectorPromise = null;
|
|
2407
|
+
initializedProjectId = null;
|
|
2408
|
+
}
|
|
2409
|
+
if (!universalConnectorPromise) {
|
|
2410
|
+
initializedProjectId = projectId;
|
|
2411
|
+
universalConnectorPromise = UniversalConnector.init({
|
|
2412
|
+
projectId,
|
|
2413
|
+
metadata: resolvedMetadata(),
|
|
2414
|
+
networks: namespaceConfig
|
|
2415
|
+
}).catch((error) => {
|
|
2416
|
+
universalConnectorPromise = null;
|
|
2417
|
+
initializedProjectId = null;
|
|
2418
|
+
console.error(
|
|
2419
|
+
"[Trustware SDK] Failed to initialize WalletConnect:",
|
|
2420
|
+
error
|
|
2421
|
+
);
|
|
2422
|
+
throw error;
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
return universalConnectorPromise;
|
|
2426
|
+
}
|
|
2427
|
+
function resetUniversalConnector() {
|
|
2428
|
+
universalConnectorPromise = null;
|
|
2429
|
+
initializedProjectId = null;
|
|
2430
|
+
}
|
|
2431
|
+
var solanaMainnet, bitcoinMainnet, seiCosmosMainnet, ethereumMainnet, optimismMainnet, flareMainnet, cronosMainnet, rootstockMainnet, telosMainnet, xdcMainnet, bscMainnet, victionMainnet, gnosisMainnet, fuseMainnet, unichainMainnet, polygonMainnet, monadMainnet, sonicMainnet, opBnbMainnet, lensMainnet, fantomMainnet, fraxtalMainnet, bobaMainnet, hederaMainnet, filecoinMainnet, zkSyncMainnet, worldchainMainnet, flowMainnet, stableMainnet, hyperEvmMainnet, metisMainnet, liskMainnet, moonbeamMainnet, seiMainnet, hyperliquidMainnet, vanaMainnet, gravityMainnet, pharosMainnet, soneiumMainnet, swellchainMainnet, roninMainnet, kavaEvmMainnet, abstractMainnet, morphMainnet, peaqMainnet, tempoMainnet, megaEthMainnet, mantleMainnet, somniaMainnet, kaiaMainnet, baseMainnet, plasmaMainnet, immutableZkEvmMainnet, apechainMainnet, modeMainnet, arbitrumMainnet, arbitrumNovaMainnet, celoMainnet, etherlinkMainnet, hemiMainnet, avalancheMainnet, sophonMainnet, superpositionMainnet, inkMainnet, lineaMainnet, bobMainnet, berachainMainnet, blastMainnet, plumeMainnet, taikoMainnet, scrollMainnet, katanaMainnet, cornMainnet, evmChains, solanaChains, bitcoinChains, cosmosChains, networks, namespaceConfig, universalConnectorPromise, initializedProjectId;
|
|
2432
|
+
var init_walletconnect = __esm({
|
|
2433
|
+
"src/config/walletconnect.ts"() {
|
|
2434
|
+
"use strict";
|
|
2435
|
+
init_store();
|
|
2436
|
+
init_constants();
|
|
2437
|
+
solanaMainnet = {
|
|
2438
|
+
id: 900,
|
|
2439
|
+
chainNamespace: "solana",
|
|
2440
|
+
caipNetworkId: "solana:5eykt4UsFv8P8NJdTREpY1vzqAQ3H1FQ",
|
|
2441
|
+
name: "Solana Mainnet",
|
|
2442
|
+
nativeCurrency: {
|
|
2443
|
+
name: "Solana",
|
|
2444
|
+
symbol: "SOL",
|
|
2445
|
+
decimals: 9
|
|
2446
|
+
},
|
|
2447
|
+
rpcUrls: {
|
|
2448
|
+
default: {
|
|
2449
|
+
http: ["https://api.mainnet-beta.solana.com"]
|
|
2450
|
+
}
|
|
2178
2451
|
}
|
|
2179
2452
|
};
|
|
2180
|
-
|
|
2181
|
-
id:
|
|
2182
|
-
chainNamespace: "
|
|
2183
|
-
caipNetworkId: "
|
|
2184
|
-
name: "
|
|
2185
|
-
nativeCurrency: {
|
|
2453
|
+
bitcoinMainnet = {
|
|
2454
|
+
id: 8333,
|
|
2455
|
+
chainNamespace: "bip122",
|
|
2456
|
+
caipNetworkId: "bip122:000000000019d6689c085ae165831e93",
|
|
2457
|
+
name: "Bitcoin Mainnet",
|
|
2458
|
+
nativeCurrency: {
|
|
2459
|
+
name: "Bitcoin",
|
|
2460
|
+
symbol: "BTC",
|
|
2461
|
+
decimals: 8
|
|
2462
|
+
},
|
|
2186
2463
|
rpcUrls: {
|
|
2187
|
-
default: {
|
|
2464
|
+
default: {
|
|
2465
|
+
http: ["https://api.blockcypher.com/v1/btc/main"]
|
|
2466
|
+
}
|
|
2188
2467
|
}
|
|
2189
2468
|
};
|
|
2190
|
-
|
|
2191
|
-
id:
|
|
2192
|
-
chainNamespace: "
|
|
2193
|
-
caipNetworkId: "
|
|
2194
|
-
name: "
|
|
2195
|
-
nativeCurrency: { name: "
|
|
2469
|
+
seiCosmosMainnet = {
|
|
2470
|
+
id: 9001,
|
|
2471
|
+
chainNamespace: "cosmos",
|
|
2472
|
+
caipNetworkId: "cosmos:pacific-1",
|
|
2473
|
+
name: "Sei Cosmos",
|
|
2474
|
+
nativeCurrency: { name: "Sei", symbol: "SEI", decimals: 6 },
|
|
2196
2475
|
rpcUrls: {
|
|
2197
|
-
default: { http: ["https://rpc.
|
|
2476
|
+
default: { http: ["https://rpc.sei-apis.com"] }
|
|
2198
2477
|
}
|
|
2199
2478
|
};
|
|
2200
|
-
|
|
2201
|
-
id:
|
|
2479
|
+
ethereumMainnet = {
|
|
2480
|
+
id: 1,
|
|
2202
2481
|
chainNamespace: "eip155",
|
|
2203
|
-
caipNetworkId: "eip155:
|
|
2204
|
-
name: "
|
|
2205
|
-
nativeCurrency: { name: "
|
|
2482
|
+
caipNetworkId: "eip155:1",
|
|
2483
|
+
name: "Ethereum Mainnet",
|
|
2484
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2206
2485
|
rpcUrls: {
|
|
2207
|
-
default: { http: ["https://rpc.
|
|
2486
|
+
default: { http: ["https://rpc.ankr.com/eth"] }
|
|
2208
2487
|
}
|
|
2209
2488
|
};
|
|
2210
|
-
|
|
2211
|
-
id:
|
|
2489
|
+
optimismMainnet = {
|
|
2490
|
+
id: 10,
|
|
2212
2491
|
chainNamespace: "eip155",
|
|
2213
|
-
caipNetworkId: "eip155:
|
|
2214
|
-
name: "
|
|
2215
|
-
nativeCurrency: { name: "
|
|
2492
|
+
caipNetworkId: "eip155:10",
|
|
2493
|
+
name: "Optimism Mainnet",
|
|
2494
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2216
2495
|
rpcUrls: {
|
|
2217
|
-
default: { http: ["https://rpc.
|
|
2496
|
+
default: { http: ["https://rpc.ankr.com/optimism"] }
|
|
2218
2497
|
}
|
|
2219
2498
|
};
|
|
2220
|
-
|
|
2221
|
-
id:
|
|
2499
|
+
flareMainnet = {
|
|
2500
|
+
id: 14,
|
|
2222
2501
|
chainNamespace: "eip155",
|
|
2223
|
-
caipNetworkId: "eip155:
|
|
2224
|
-
name: "
|
|
2225
|
-
nativeCurrency: { name: "
|
|
2502
|
+
caipNetworkId: "eip155:14",
|
|
2503
|
+
name: "Flare",
|
|
2504
|
+
nativeCurrency: { name: "Flare", symbol: "FLR", decimals: 18 },
|
|
2226
2505
|
rpcUrls: {
|
|
2227
|
-
default: { http: ["https://
|
|
2506
|
+
default: { http: ["https://flare-api.flare.network/ext/C/rpc"] }
|
|
2228
2507
|
}
|
|
2229
2508
|
};
|
|
2230
|
-
|
|
2231
|
-
id:
|
|
2509
|
+
cronosMainnet = {
|
|
2510
|
+
id: 25,
|
|
2232
2511
|
chainNamespace: "eip155",
|
|
2233
|
-
caipNetworkId: "eip155:
|
|
2234
|
-
name: "
|
|
2235
|
-
nativeCurrency: { name: "
|
|
2512
|
+
caipNetworkId: "eip155:25",
|
|
2513
|
+
name: "Cronos",
|
|
2514
|
+
nativeCurrency: { name: "Cronos", symbol: "CRO", decimals: 18 },
|
|
2236
2515
|
rpcUrls: {
|
|
2237
|
-
default: { http: ["https://
|
|
2516
|
+
default: { http: ["https://evm.cronos.org"] }
|
|
2238
2517
|
}
|
|
2239
2518
|
};
|
|
2240
|
-
|
|
2241
|
-
id:
|
|
2519
|
+
rootstockMainnet = {
|
|
2520
|
+
id: 30,
|
|
2242
2521
|
chainNamespace: "eip155",
|
|
2243
|
-
caipNetworkId: "eip155:
|
|
2244
|
-
name: "
|
|
2245
|
-
nativeCurrency: {
|
|
2522
|
+
caipNetworkId: "eip155:30",
|
|
2523
|
+
name: "Rootstock",
|
|
2524
|
+
nativeCurrency: {
|
|
2525
|
+
name: "Rootstock Smart Bitcoin",
|
|
2526
|
+
symbol: "RBTC",
|
|
2527
|
+
decimals: 18
|
|
2528
|
+
},
|
|
2246
2529
|
rpcUrls: {
|
|
2247
|
-
default: { http: ["https://
|
|
2530
|
+
default: { http: ["https://public-node.rsk.co"] }
|
|
2248
2531
|
}
|
|
2249
2532
|
};
|
|
2250
|
-
|
|
2251
|
-
id:
|
|
2533
|
+
telosMainnet = {
|
|
2534
|
+
id: 40,
|
|
2252
2535
|
chainNamespace: "eip155",
|
|
2253
|
-
caipNetworkId: "eip155:
|
|
2254
|
-
name: "
|
|
2255
|
-
nativeCurrency: { name: "
|
|
2536
|
+
caipNetworkId: "eip155:40",
|
|
2537
|
+
name: "Telos",
|
|
2538
|
+
nativeCurrency: { name: "Telos", symbol: "TLOS", decimals: 18 },
|
|
2256
2539
|
rpcUrls: {
|
|
2257
|
-
default: { http: ["https://
|
|
2540
|
+
default: { http: ["https://rpc.telos.net"] }
|
|
2258
2541
|
}
|
|
2259
2542
|
};
|
|
2260
|
-
|
|
2261
|
-
id:
|
|
2543
|
+
xdcMainnet = {
|
|
2544
|
+
id: 50,
|
|
2262
2545
|
chainNamespace: "eip155",
|
|
2263
|
-
caipNetworkId: "eip155:
|
|
2264
|
-
name: "
|
|
2265
|
-
nativeCurrency: { name: "
|
|
2546
|
+
caipNetworkId: "eip155:50",
|
|
2547
|
+
name: "XDC",
|
|
2548
|
+
nativeCurrency: { name: "XDC", symbol: "XDC", decimals: 18 },
|
|
2266
2549
|
rpcUrls: {
|
|
2267
|
-
default: { http: ["https://
|
|
2550
|
+
default: { http: ["https://rpc.xdcrpc.com"] }
|
|
2268
2551
|
}
|
|
2269
2552
|
};
|
|
2270
|
-
|
|
2271
|
-
id:
|
|
2553
|
+
bscMainnet = {
|
|
2554
|
+
id: 56,
|
|
2272
2555
|
chainNamespace: "eip155",
|
|
2273
|
-
caipNetworkId: "eip155:
|
|
2274
|
-
name: "
|
|
2275
|
-
nativeCurrency: { name: "
|
|
2556
|
+
caipNetworkId: "eip155:56",
|
|
2557
|
+
name: "BNB Smart Chain",
|
|
2558
|
+
nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
|
|
2276
2559
|
rpcUrls: {
|
|
2277
|
-
default: { http: ["https://rpc.
|
|
2560
|
+
default: { http: ["https://rpc.ankr.com/bsc"] }
|
|
2278
2561
|
}
|
|
2279
2562
|
};
|
|
2280
|
-
|
|
2281
|
-
id:
|
|
2563
|
+
victionMainnet = {
|
|
2564
|
+
id: 88,
|
|
2282
2565
|
chainNamespace: "eip155",
|
|
2283
|
-
caipNetworkId: "eip155:
|
|
2284
|
-
name: "
|
|
2285
|
-
nativeCurrency: { name: "
|
|
2566
|
+
caipNetworkId: "eip155:88",
|
|
2567
|
+
name: "Viction",
|
|
2568
|
+
nativeCurrency: { name: "Viction", symbol: "VIC", decimals: 18 },
|
|
2286
2569
|
rpcUrls: {
|
|
2287
|
-
default: { http: ["https://
|
|
2570
|
+
default: { http: ["https://rpc.viction.xyz"] }
|
|
2288
2571
|
}
|
|
2289
2572
|
};
|
|
2290
|
-
|
|
2291
|
-
id:
|
|
2573
|
+
gnosisMainnet = {
|
|
2574
|
+
id: 100,
|
|
2292
2575
|
chainNamespace: "eip155",
|
|
2293
|
-
caipNetworkId: "eip155:
|
|
2294
|
-
name: "
|
|
2295
|
-
nativeCurrency: { name: "
|
|
2576
|
+
caipNetworkId: "eip155:100",
|
|
2577
|
+
name: "Gnosis Chain",
|
|
2578
|
+
nativeCurrency: { name: "xDAI", symbol: "XDAI", decimals: 18 },
|
|
2296
2579
|
rpcUrls: {
|
|
2297
|
-
default: { http: ["https://rpc.
|
|
2580
|
+
default: { http: ["https://rpc.ankr.com/gnosis"] }
|
|
2298
2581
|
}
|
|
2299
2582
|
};
|
|
2300
|
-
|
|
2301
|
-
id:
|
|
2583
|
+
fuseMainnet = {
|
|
2584
|
+
id: 122,
|
|
2302
2585
|
chainNamespace: "eip155",
|
|
2303
|
-
caipNetworkId: "eip155:
|
|
2304
|
-
name: "
|
|
2305
|
-
nativeCurrency: { name: "
|
|
2586
|
+
caipNetworkId: "eip155:122",
|
|
2587
|
+
name: "FUSE",
|
|
2588
|
+
nativeCurrency: { name: "FUSE", symbol: "FUSE", decimals: 18 },
|
|
2306
2589
|
rpcUrls: {
|
|
2307
|
-
default: { http: ["https://
|
|
2590
|
+
default: { http: ["https://rpc.fuse.io"] }
|
|
2308
2591
|
}
|
|
2309
2592
|
};
|
|
2310
|
-
|
|
2311
|
-
id:
|
|
2593
|
+
unichainMainnet = {
|
|
2594
|
+
id: 130,
|
|
2312
2595
|
chainNamespace: "eip155",
|
|
2313
|
-
caipNetworkId: "eip155:
|
|
2314
|
-
name: "
|
|
2315
|
-
nativeCurrency: { name: "
|
|
2596
|
+
caipNetworkId: "eip155:130",
|
|
2597
|
+
name: "Unichain",
|
|
2598
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2316
2599
|
rpcUrls: {
|
|
2317
|
-
default: { http: ["https://
|
|
2600
|
+
default: { http: ["https://mainnet.unichain.org"] }
|
|
2318
2601
|
}
|
|
2319
2602
|
};
|
|
2320
|
-
|
|
2321
|
-
id:
|
|
2603
|
+
polygonMainnet = {
|
|
2604
|
+
id: 137,
|
|
2322
2605
|
chainNamespace: "eip155",
|
|
2323
|
-
caipNetworkId: "eip155:
|
|
2324
|
-
name: "
|
|
2325
|
-
nativeCurrency: { name: "
|
|
2606
|
+
caipNetworkId: "eip155:137",
|
|
2607
|
+
name: "Polygon Mainnet",
|
|
2608
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
2326
2609
|
rpcUrls: {
|
|
2327
|
-
default: { http: ["https://
|
|
2610
|
+
default: { http: ["https://rpc.ankr.com/polygon"] }
|
|
2328
2611
|
}
|
|
2329
2612
|
};
|
|
2330
|
-
|
|
2331
|
-
id:
|
|
2613
|
+
monadMainnet = {
|
|
2614
|
+
id: 143,
|
|
2332
2615
|
chainNamespace: "eip155",
|
|
2333
|
-
caipNetworkId: "eip155:
|
|
2334
|
-
name: "
|
|
2335
|
-
nativeCurrency: { name: "
|
|
2616
|
+
caipNetworkId: "eip155:143",
|
|
2617
|
+
name: "MONAD",
|
|
2618
|
+
nativeCurrency: { name: "Mon", symbol: "MON", decimals: 18 },
|
|
2336
2619
|
rpcUrls: {
|
|
2337
|
-
default: { http: ["https://
|
|
2620
|
+
default: { http: ["https://rpc.monad.xyz/"] }
|
|
2338
2621
|
}
|
|
2339
2622
|
};
|
|
2340
|
-
|
|
2341
|
-
id:
|
|
2623
|
+
sonicMainnet = {
|
|
2624
|
+
id: 146,
|
|
2342
2625
|
chainNamespace: "eip155",
|
|
2343
|
-
caipNetworkId: "eip155:
|
|
2344
|
-
name: "
|
|
2345
|
-
nativeCurrency: { name: "
|
|
2626
|
+
caipNetworkId: "eip155:146",
|
|
2627
|
+
name: "Sonic",
|
|
2628
|
+
nativeCurrency: { name: "Sonic", symbol: "S", decimals: 18 },
|
|
2346
2629
|
rpcUrls: {
|
|
2347
|
-
default: { http: ["https://
|
|
2630
|
+
default: { http: ["https://rpc.soniclabs.com"] }
|
|
2348
2631
|
}
|
|
2349
2632
|
};
|
|
2350
|
-
|
|
2351
|
-
id:
|
|
2633
|
+
opBnbMainnet = {
|
|
2634
|
+
id: 204,
|
|
2352
2635
|
chainNamespace: "eip155",
|
|
2353
|
-
caipNetworkId: "eip155:
|
|
2354
|
-
name: "
|
|
2355
|
-
nativeCurrency: { name: "
|
|
2636
|
+
caipNetworkId: "eip155:204",
|
|
2637
|
+
name: "opBNB",
|
|
2638
|
+
nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
|
|
2356
2639
|
rpcUrls: {
|
|
2357
|
-
default: { http: ["https://rpc.
|
|
2640
|
+
default: { http: ["https://opbnb-mainnet-rpc.bnbchain.org"] }
|
|
2358
2641
|
}
|
|
2359
2642
|
};
|
|
2360
|
-
|
|
2361
|
-
id:
|
|
2643
|
+
lensMainnet = {
|
|
2644
|
+
id: 232,
|
|
2362
2645
|
chainNamespace: "eip155",
|
|
2363
|
-
caipNetworkId: "eip155:
|
|
2364
|
-
name: "
|
|
2365
|
-
nativeCurrency: { name: "
|
|
2646
|
+
caipNetworkId: "eip155:232",
|
|
2647
|
+
name: "Lens",
|
|
2648
|
+
nativeCurrency: { name: "GHO", symbol: "GHO", decimals: 18 },
|
|
2366
2649
|
rpcUrls: {
|
|
2367
|
-
default: { http: ["https://
|
|
2650
|
+
default: { http: ["https://api.lens.matterhosted.dev"] }
|
|
2368
2651
|
}
|
|
2369
2652
|
};
|
|
2370
|
-
|
|
2371
|
-
id:
|
|
2653
|
+
fantomMainnet = {
|
|
2654
|
+
id: 250,
|
|
2372
2655
|
chainNamespace: "eip155",
|
|
2373
|
-
caipNetworkId: "eip155:
|
|
2374
|
-
name: "
|
|
2375
|
-
nativeCurrency: { name: "
|
|
2656
|
+
caipNetworkId: "eip155:250",
|
|
2657
|
+
name: "Fantom Opera",
|
|
2658
|
+
nativeCurrency: { name: "Fantom", symbol: "FTM", decimals: 18 },
|
|
2376
2659
|
rpcUrls: {
|
|
2377
|
-
default: { http: ["https://rpc.
|
|
2660
|
+
default: { http: ["https://rpc.ankr.com/fantom"] }
|
|
2378
2661
|
}
|
|
2379
2662
|
};
|
|
2380
|
-
|
|
2381
|
-
id:
|
|
2663
|
+
fraxtalMainnet = {
|
|
2664
|
+
id: 252,
|
|
2382
2665
|
chainNamespace: "eip155",
|
|
2383
|
-
caipNetworkId: "eip155:
|
|
2384
|
-
name: "
|
|
2385
|
-
nativeCurrency: { name: "
|
|
2666
|
+
caipNetworkId: "eip155:252",
|
|
2667
|
+
name: "Fraxtal",
|
|
2668
|
+
nativeCurrency: { name: "FRAX", symbol: "FRAX", decimals: 18 },
|
|
2386
2669
|
rpcUrls: {
|
|
2387
|
-
default: { http: ["https://
|
|
2670
|
+
default: { http: ["https://rpc.frax.com"] }
|
|
2388
2671
|
}
|
|
2389
2672
|
};
|
|
2390
|
-
|
|
2391
|
-
id:
|
|
2673
|
+
bobaMainnet = {
|
|
2674
|
+
id: 288,
|
|
2392
2675
|
chainNamespace: "eip155",
|
|
2393
|
-
caipNetworkId: "eip155:
|
|
2394
|
-
name: "
|
|
2676
|
+
caipNetworkId: "eip155:288",
|
|
2677
|
+
name: "Boba",
|
|
2395
2678
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2396
2679
|
rpcUrls: {
|
|
2397
|
-
default: { http: ["https://
|
|
2680
|
+
default: { http: ["https://mainnet.boba.network"] }
|
|
2398
2681
|
}
|
|
2399
2682
|
};
|
|
2400
|
-
|
|
2401
|
-
id:
|
|
2683
|
+
hederaMainnet = {
|
|
2684
|
+
id: 295,
|
|
2402
2685
|
chainNamespace: "eip155",
|
|
2403
|
-
caipNetworkId: "eip155:
|
|
2404
|
-
name: "
|
|
2405
|
-
nativeCurrency: { name: "
|
|
2686
|
+
caipNetworkId: "eip155:295",
|
|
2687
|
+
name: "HEDERA",
|
|
2688
|
+
nativeCurrency: { name: "Hbar", symbol: "HBAR", decimals: 18 },
|
|
2406
2689
|
rpcUrls: {
|
|
2407
|
-
default: { http: ["https://
|
|
2690
|
+
default: { http: ["https://mainnet.hashio.io/api"] }
|
|
2408
2691
|
}
|
|
2409
2692
|
};
|
|
2410
|
-
|
|
2411
|
-
id:
|
|
2693
|
+
filecoinMainnet = {
|
|
2694
|
+
id: 314,
|
|
2412
2695
|
chainNamespace: "eip155",
|
|
2413
|
-
caipNetworkId: "eip155:
|
|
2414
|
-
name: "
|
|
2415
|
-
nativeCurrency: { name: "
|
|
2696
|
+
caipNetworkId: "eip155:314",
|
|
2697
|
+
name: "Filecoin",
|
|
2698
|
+
nativeCurrency: { name: "Filecoin", symbol: "FIL", decimals: 18 },
|
|
2416
2699
|
rpcUrls: {
|
|
2417
|
-
default: { http: ["https://
|
|
2700
|
+
default: { http: ["https://api.node.glif.io"] }
|
|
2418
2701
|
}
|
|
2419
2702
|
};
|
|
2420
|
-
|
|
2421
|
-
id:
|
|
2703
|
+
zkSyncMainnet = {
|
|
2704
|
+
id: 324,
|
|
2422
2705
|
chainNamespace: "eip155",
|
|
2423
|
-
caipNetworkId: "eip155:
|
|
2424
|
-
name: "
|
|
2425
|
-
nativeCurrency: { name: "
|
|
2706
|
+
caipNetworkId: "eip155:324",
|
|
2707
|
+
name: "zkSync Era Mainnet",
|
|
2708
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2426
2709
|
rpcUrls: {
|
|
2427
|
-
default: { http: ["https://
|
|
2710
|
+
default: { http: ["https://mainnet.era.zksync.io"] }
|
|
2428
2711
|
}
|
|
2429
2712
|
};
|
|
2430
|
-
|
|
2431
|
-
id:
|
|
2713
|
+
worldchainMainnet = {
|
|
2714
|
+
id: 480,
|
|
2432
2715
|
chainNamespace: "eip155",
|
|
2433
|
-
caipNetworkId: "eip155:
|
|
2434
|
-
name: "
|
|
2435
|
-
nativeCurrency: { name: "
|
|
2716
|
+
caipNetworkId: "eip155:480",
|
|
2717
|
+
name: "World Chain",
|
|
2718
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2436
2719
|
rpcUrls: {
|
|
2437
|
-
default: {
|
|
2720
|
+
default: {
|
|
2721
|
+
http: ["https://worldchain-mainnet.g.alchemy.com/public"]
|
|
2722
|
+
}
|
|
2438
2723
|
}
|
|
2439
2724
|
};
|
|
2440
|
-
|
|
2441
|
-
id:
|
|
2725
|
+
flowMainnet = {
|
|
2726
|
+
id: 747,
|
|
2442
2727
|
chainNamespace: "eip155",
|
|
2443
|
-
caipNetworkId: "eip155:
|
|
2444
|
-
name: "
|
|
2445
|
-
nativeCurrency: { name: "
|
|
2728
|
+
caipNetworkId: "eip155:747",
|
|
2729
|
+
name: "Flow",
|
|
2730
|
+
nativeCurrency: { name: "FLOW", symbol: "FLOW", decimals: 18 },
|
|
2446
2731
|
rpcUrls: {
|
|
2447
|
-
default: { http: ["https://
|
|
2732
|
+
default: { http: ["https://mainnet.evm.nodes.onflow.org"] }
|
|
2448
2733
|
}
|
|
2449
2734
|
};
|
|
2450
|
-
|
|
2451
|
-
id:
|
|
2735
|
+
stableMainnet = {
|
|
2736
|
+
id: 988,
|
|
2452
2737
|
chainNamespace: "eip155",
|
|
2453
|
-
caipNetworkId: "eip155:
|
|
2454
|
-
name: "
|
|
2455
|
-
nativeCurrency: { name: "
|
|
2738
|
+
caipNetworkId: "eip155:988",
|
|
2739
|
+
name: "Stable",
|
|
2740
|
+
nativeCurrency: { name: "USDT0", symbol: "USDT0", decimals: 6 },
|
|
2456
2741
|
rpcUrls: {
|
|
2457
|
-
default: { http: ["https://rpc.
|
|
2742
|
+
default: { http: ["https://rpc.stable.xyz"] }
|
|
2458
2743
|
}
|
|
2459
2744
|
};
|
|
2460
|
-
|
|
2461
|
-
id:
|
|
2745
|
+
hyperEvmMainnet = {
|
|
2746
|
+
id: 999,
|
|
2462
2747
|
chainNamespace: "eip155",
|
|
2463
|
-
caipNetworkId: "eip155:
|
|
2464
|
-
name: "
|
|
2465
|
-
nativeCurrency: { name: "
|
|
2748
|
+
caipNetworkId: "eip155:999",
|
|
2749
|
+
name: "HyperEVM",
|
|
2750
|
+
nativeCurrency: { name: "Hyperliquid", symbol: "HYPE", decimals: 18 },
|
|
2466
2751
|
rpcUrls: {
|
|
2467
|
-
default: { http: ["https://rpc.
|
|
2752
|
+
default: { http: ["https://rpc.hyperliquid.xyz/evm"] }
|
|
2468
2753
|
}
|
|
2469
2754
|
};
|
|
2470
|
-
|
|
2471
|
-
id:
|
|
2755
|
+
metisMainnet = {
|
|
2756
|
+
id: 1088,
|
|
2472
2757
|
chainNamespace: "eip155",
|
|
2473
|
-
caipNetworkId: "eip155:
|
|
2474
|
-
name: "
|
|
2475
|
-
nativeCurrency: { name: "
|
|
2758
|
+
caipNetworkId: "eip155:1088",
|
|
2759
|
+
name: "Metis",
|
|
2760
|
+
nativeCurrency: { name: "METIS", symbol: "METIS", decimals: 18 },
|
|
2476
2761
|
rpcUrls: {
|
|
2477
|
-
default: { http: ["https://
|
|
2762
|
+
default: { http: ["https://metis-public.nodies.app"] }
|
|
2478
2763
|
}
|
|
2479
2764
|
};
|
|
2480
|
-
|
|
2481
|
-
id:
|
|
2765
|
+
liskMainnet = {
|
|
2766
|
+
id: 1135,
|
|
2482
2767
|
chainNamespace: "eip155",
|
|
2483
|
-
caipNetworkId: "eip155:
|
|
2484
|
-
name: "
|
|
2485
|
-
nativeCurrency: { name: "
|
|
2768
|
+
caipNetworkId: "eip155:1135",
|
|
2769
|
+
name: "Lisk",
|
|
2770
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2486
2771
|
rpcUrls: {
|
|
2487
|
-
default: { http: ["https://rpc.
|
|
2772
|
+
default: { http: ["https://rpc.api.lisk.com"] }
|
|
2488
2773
|
}
|
|
2489
2774
|
};
|
|
2490
|
-
|
|
2491
|
-
id:
|
|
2775
|
+
moonbeamMainnet = {
|
|
2776
|
+
id: 1284,
|
|
2492
2777
|
chainNamespace: "eip155",
|
|
2493
|
-
caipNetworkId: "eip155:
|
|
2494
|
-
name: "
|
|
2495
|
-
nativeCurrency: { name: "
|
|
2778
|
+
caipNetworkId: "eip155:1284",
|
|
2779
|
+
name: "Moonbeam",
|
|
2780
|
+
nativeCurrency: { name: "Moonbeam", symbol: "GLMR", decimals: 18 },
|
|
2496
2781
|
rpcUrls: {
|
|
2497
|
-
default: { http: ["https://rpc.
|
|
2782
|
+
default: { http: ["https://rpc.api.moonbeam.network"] }
|
|
2498
2783
|
}
|
|
2499
2784
|
};
|
|
2500
|
-
|
|
2501
|
-
id:
|
|
2785
|
+
seiMainnet = {
|
|
2786
|
+
id: 1329,
|
|
2502
2787
|
chainNamespace: "eip155",
|
|
2503
|
-
caipNetworkId: "eip155:
|
|
2504
|
-
name: "
|
|
2505
|
-
nativeCurrency: { name: "
|
|
2788
|
+
caipNetworkId: "eip155:1329",
|
|
2789
|
+
name: "Sei Mainnet",
|
|
2790
|
+
nativeCurrency: { name: "Sei", symbol: "SEI", decimals: 18 },
|
|
2506
2791
|
rpcUrls: {
|
|
2507
|
-
default: { http: ["https://rpc.
|
|
2792
|
+
default: { http: ["https://evm-rpc.sei-apis.com"] }
|
|
2508
2793
|
}
|
|
2509
2794
|
};
|
|
2510
|
-
|
|
2511
|
-
id:
|
|
2795
|
+
hyperliquidMainnet = {
|
|
2796
|
+
id: 1337,
|
|
2512
2797
|
chainNamespace: "eip155",
|
|
2513
|
-
caipNetworkId: "eip155:
|
|
2514
|
-
name: "
|
|
2515
|
-
nativeCurrency: { name: "
|
|
2798
|
+
caipNetworkId: "eip155:1337",
|
|
2799
|
+
name: "Hyperliquid",
|
|
2800
|
+
nativeCurrency: { name: "USDC", symbol: "USDC", decimals: 6 },
|
|
2516
2801
|
rpcUrls: {
|
|
2517
|
-
default: { http: ["https://rpc
|
|
2802
|
+
default: { http: ["https://li.quest/v1/rpc/1337"] }
|
|
2518
2803
|
}
|
|
2519
2804
|
};
|
|
2520
|
-
|
|
2521
|
-
id:
|
|
2805
|
+
vanaMainnet = {
|
|
2806
|
+
id: 1480,
|
|
2522
2807
|
chainNamespace: "eip155",
|
|
2523
|
-
caipNetworkId: "eip155:
|
|
2524
|
-
name: "
|
|
2525
|
-
nativeCurrency: { name: "
|
|
2808
|
+
caipNetworkId: "eip155:1480",
|
|
2809
|
+
name: "Vana",
|
|
2810
|
+
nativeCurrency: { name: "VAN", symbol: "VAN", decimals: 18 },
|
|
2526
2811
|
rpcUrls: {
|
|
2527
|
-
default: { http: ["https://rpc.
|
|
2812
|
+
default: { http: ["https://rpc.vana.org"] }
|
|
2528
2813
|
}
|
|
2529
2814
|
};
|
|
2530
|
-
|
|
2531
|
-
id:
|
|
2815
|
+
gravityMainnet = {
|
|
2816
|
+
id: 1625,
|
|
2532
2817
|
chainNamespace: "eip155",
|
|
2533
|
-
caipNetworkId: "eip155:
|
|
2534
|
-
name: "
|
|
2535
|
-
nativeCurrency: { name: "
|
|
2818
|
+
caipNetworkId: "eip155:1625",
|
|
2819
|
+
name: "Gravity",
|
|
2820
|
+
nativeCurrency: { name: "G", symbol: "G", decimals: 18 },
|
|
2536
2821
|
rpcUrls: {
|
|
2537
|
-
default: { http: ["https://rpc.
|
|
2822
|
+
default: { http: ["https://rpc.gravity.xyz/"] }
|
|
2538
2823
|
}
|
|
2539
2824
|
};
|
|
2540
|
-
|
|
2541
|
-
id:
|
|
2825
|
+
pharosMainnet = {
|
|
2826
|
+
id: 1672,
|
|
2542
2827
|
chainNamespace: "eip155",
|
|
2543
|
-
caipNetworkId: "eip155:
|
|
2544
|
-
name: "
|
|
2545
|
-
nativeCurrency: { name: "
|
|
2828
|
+
caipNetworkId: "eip155:1672",
|
|
2829
|
+
name: "Pharos Mainnet",
|
|
2830
|
+
nativeCurrency: { name: "Pharos", symbol: "PROS", decimals: 18 },
|
|
2546
2831
|
rpcUrls: {
|
|
2547
|
-
default: { http: ["https://rpc.
|
|
2832
|
+
default: { http: ["https://rpc.pharos.xyz"] }
|
|
2548
2833
|
}
|
|
2549
2834
|
};
|
|
2550
|
-
|
|
2551
|
-
id:
|
|
2835
|
+
soneiumMainnet = {
|
|
2836
|
+
id: 1868,
|
|
2552
2837
|
chainNamespace: "eip155",
|
|
2553
|
-
caipNetworkId: "eip155:
|
|
2554
|
-
name: "
|
|
2838
|
+
caipNetworkId: "eip155:1868",
|
|
2839
|
+
name: "Soneium",
|
|
2840
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2841
|
+
rpcUrls: {
|
|
2842
|
+
default: { http: ["https://rpc.soneium.org/"] }
|
|
2843
|
+
}
|
|
2844
|
+
};
|
|
2845
|
+
swellchainMainnet = {
|
|
2846
|
+
id: 1923,
|
|
2847
|
+
chainNamespace: "eip155",
|
|
2848
|
+
caipNetworkId: "eip155:1923",
|
|
2849
|
+
name: "Swellchain",
|
|
2555
2850
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2556
2851
|
rpcUrls: {
|
|
2557
|
-
default: { http: ["https://
|
|
2852
|
+
default: { http: ["https://swell-mainnet.alt.technology"] }
|
|
2558
2853
|
}
|
|
2559
2854
|
};
|
|
2560
|
-
|
|
2561
|
-
id:
|
|
2855
|
+
roninMainnet = {
|
|
2856
|
+
id: 2020,
|
|
2562
2857
|
chainNamespace: "eip155",
|
|
2563
|
-
caipNetworkId: "eip155:
|
|
2564
|
-
name: "
|
|
2565
|
-
nativeCurrency: { name: "
|
|
2858
|
+
caipNetworkId: "eip155:2020",
|
|
2859
|
+
name: "Ronin",
|
|
2860
|
+
nativeCurrency: { name: "RON", symbol: "RON", decimals: 18 },
|
|
2566
2861
|
rpcUrls: {
|
|
2567
|
-
default: { http: ["https://
|
|
2862
|
+
default: { http: ["https://api.roninchain.com/rpc"] }
|
|
2568
2863
|
}
|
|
2569
2864
|
};
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
arbitrumNovaMainnet,
|
|
2579
|
-
optimismMainnet,
|
|
2580
|
-
baseMainnet,
|
|
2581
|
-
zkSyncMainnet,
|
|
2582
|
-
lineaMainnet,
|
|
2583
|
-
mantleMainnet,
|
|
2584
|
-
blastMainnet,
|
|
2585
|
-
scrollMainnet,
|
|
2586
|
-
taikoMainnet,
|
|
2587
|
-
modeMainnet,
|
|
2588
|
-
inkMainnet,
|
|
2589
|
-
unichainMainnet,
|
|
2590
|
-
worldchainMainnet,
|
|
2591
|
-
swellchainMainnet,
|
|
2592
|
-
soneiumMainnet,
|
|
2593
|
-
liskMainnet,
|
|
2594
|
-
morphMainnet,
|
|
2595
|
-
abstractMainnet,
|
|
2596
|
-
megaEthMainnet,
|
|
2597
|
-
superpositionMainnet,
|
|
2598
|
-
fraxtalMainnet,
|
|
2599
|
-
// EVM-compatible L1s & app-chains
|
|
2600
|
-
gnosisMainnet,
|
|
2601
|
-
fantomMainnet,
|
|
2602
|
-
celoMainnet,
|
|
2603
|
-
sonicMainnet,
|
|
2604
|
-
berachainMainnet,
|
|
2605
|
-
moonbeamMainnet,
|
|
2606
|
-
metisMainnet,
|
|
2607
|
-
bobaMainnet,
|
|
2608
|
-
roninMainnet,
|
|
2609
|
-
kavaEvmMainnet,
|
|
2610
|
-
cronosMainnet,
|
|
2611
|
-
kaiaMainnet,
|
|
2612
|
-
flareMainnet,
|
|
2613
|
-
telosMainnet,
|
|
2614
|
-
xdcMainnet,
|
|
2615
|
-
fuseMainnet,
|
|
2616
|
-
victionMainnet,
|
|
2617
|
-
rootstockMainnet,
|
|
2618
|
-
hederaMainnet,
|
|
2619
|
-
filecoinMainnet,
|
|
2620
|
-
flowMainnet,
|
|
2621
|
-
opBnbMainnet,
|
|
2622
|
-
lensMainnet,
|
|
2623
|
-
apechainMainnet,
|
|
2624
|
-
etherlinkMainnet,
|
|
2625
|
-
hemiMainnet,
|
|
2626
|
-
immutableZkEvmMainnet,
|
|
2627
|
-
peaqMainnet,
|
|
2628
|
-
sophonMainnet,
|
|
2629
|
-
gravityMainnet,
|
|
2630
|
-
vanaMainnet,
|
|
2631
|
-
hyperliquidMainnet,
|
|
2632
|
-
hyperEvmMainnet,
|
|
2633
|
-
stableMainnet,
|
|
2634
|
-
tempoMainnet,
|
|
2635
|
-
plasmaMainnet,
|
|
2636
|
-
somniaMainnet,
|
|
2637
|
-
monadMainnet,
|
|
2638
|
-
pharosMainnet,
|
|
2639
|
-
bobMainnet,
|
|
2640
|
-
plumeMainnet,
|
|
2641
|
-
katanaMainnet,
|
|
2642
|
-
cornMainnet,
|
|
2643
|
-
// Sei EVM
|
|
2644
|
-
seiMainnet
|
|
2645
|
-
];
|
|
2646
|
-
solanaChains = [solanaMainnet];
|
|
2647
|
-
bitcoinChains = [bitcoinMainnet];
|
|
2648
|
-
cosmosChains = [seiCosmosMainnet];
|
|
2649
|
-
networks = [
|
|
2650
|
-
// ...solanaChains,
|
|
2651
|
-
// ...bitcoinChains,
|
|
2652
|
-
...evmChains
|
|
2653
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2654
|
-
];
|
|
2655
|
-
namespaceConfig = [
|
|
2656
|
-
{
|
|
2657
|
-
namespace: "solana",
|
|
2658
|
-
chains: solanaChains,
|
|
2659
|
-
methods: ["solana_signMessage", "solana_signTransaction"],
|
|
2660
|
-
events: []
|
|
2661
|
-
},
|
|
2662
|
-
{
|
|
2663
|
-
namespace: "eip155",
|
|
2664
|
-
chains: evmChains,
|
|
2665
|
-
methods: [
|
|
2666
|
-
"eth_sendTransaction",
|
|
2667
|
-
"eth_signTransaction",
|
|
2668
|
-
"eth_sign",
|
|
2669
|
-
"personal_sign",
|
|
2670
|
-
"eth_signTypedData_v4"
|
|
2671
|
-
],
|
|
2672
|
-
events: ["accountsChanged", "chainChanged"]
|
|
2673
|
-
},
|
|
2674
|
-
{
|
|
2675
|
-
namespace: "bip122",
|
|
2676
|
-
chains: bitcoinChains,
|
|
2677
|
-
methods: ["signMessage", "sendTransfer"],
|
|
2678
|
-
events: []
|
|
2679
|
-
},
|
|
2680
|
-
{
|
|
2681
|
-
namespace: "cosmos",
|
|
2682
|
-
chains: cosmosChains,
|
|
2683
|
-
methods: ["cosmos_signDirect", "cosmos_signAmino", "cosmos_getAccounts"],
|
|
2684
|
-
events: []
|
|
2865
|
+
kavaEvmMainnet = {
|
|
2866
|
+
id: 2222,
|
|
2867
|
+
chainNamespace: "eip155",
|
|
2868
|
+
caipNetworkId: "eip155:2222",
|
|
2869
|
+
name: "Kava EVM",
|
|
2870
|
+
nativeCurrency: { name: "Kava", symbol: "KAVA", decimals: 18 },
|
|
2871
|
+
rpcUrls: {
|
|
2872
|
+
default: { http: ["https://evm2.kava.io"] }
|
|
2685
2873
|
}
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
const chain = evmChains.find((c) => c.id === chainId);
|
|
2696
|
-
if (!chain) throw new Error(`Chain ${chainId} not configured`);
|
|
2697
|
-
return {
|
|
2698
|
-
chainId: `0x${chainId.toString(16)}`,
|
|
2699
|
-
chainName: chain.name,
|
|
2700
|
-
nativeCurrency: chain.nativeCurrency,
|
|
2701
|
-
rpcUrls: chain.rpcUrls.default.http
|
|
2702
|
-
};
|
|
2703
|
-
}
|
|
2704
|
-
async function buildWalletConnectAPI(walletCfg) {
|
|
2705
|
-
const connector = await getUniversalConnector(walletCfg);
|
|
2706
|
-
const provider = connector.provider;
|
|
2707
|
-
const api = {
|
|
2708
|
-
ecosystem: "evm",
|
|
2709
|
-
type: "eip1193",
|
|
2710
|
-
async getAddress() {
|
|
2711
|
-
const accounts = await provider.request({
|
|
2712
|
-
method: "eth_accounts"
|
|
2713
|
-
});
|
|
2714
|
-
if (!accounts?.[0])
|
|
2715
|
-
throw new Error("No account connected via WalletConnect");
|
|
2716
|
-
return accounts[0];
|
|
2717
|
-
},
|
|
2718
|
-
async getChainId() {
|
|
2719
|
-
const hex = await provider.request({ method: "eth_chainId" });
|
|
2720
|
-
return parseInt(hex, 16);
|
|
2721
|
-
},
|
|
2722
|
-
async switchChain(chainId) {
|
|
2723
|
-
const hexChainId = `0x${chainId.toString(16)}`;
|
|
2724
|
-
try {
|
|
2725
|
-
await provider.request({
|
|
2726
|
-
method: "wallet_switchEthereumChain",
|
|
2727
|
-
params: [{ chainId: hexChainId }]
|
|
2728
|
-
});
|
|
2729
|
-
} catch (err) {
|
|
2730
|
-
const code = err?.code;
|
|
2731
|
-
if (code === 4902) {
|
|
2732
|
-
const chainMeta = getChainMeta(chainId);
|
|
2733
|
-
await provider.request({
|
|
2734
|
-
method: "wallet_addEthereumChain",
|
|
2735
|
-
params: [chainMeta]
|
|
2736
|
-
});
|
|
2737
|
-
} else {
|
|
2738
|
-
throw err;
|
|
2739
|
-
}
|
|
2874
|
+
};
|
|
2875
|
+
abstractMainnet = {
|
|
2876
|
+
id: 2741,
|
|
2877
|
+
chainNamespace: "eip155",
|
|
2878
|
+
caipNetworkId: "eip155:2741",
|
|
2879
|
+
name: "Abstract",
|
|
2880
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2881
|
+
rpcUrls: {
|
|
2882
|
+
default: { http: ["https://api.mainnet.abs.xyz"] }
|
|
2740
2883
|
}
|
|
2741
|
-
}
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
return api;
|
|
2751
|
-
}
|
|
2752
|
-
function bindWalletConnectEvents(provider, callbacks) {
|
|
2753
|
-
const onAccountsChanged = (accounts) => {
|
|
2754
|
-
const list = Array.isArray(accounts) ? accounts : [];
|
|
2755
|
-
callbacks.onAccountsChanged(list);
|
|
2756
|
-
};
|
|
2757
|
-
const onChainChanged = (chainId) => {
|
|
2758
|
-
callbacks.onChainChanged(String(chainId));
|
|
2759
|
-
};
|
|
2760
|
-
const onDisconnect = () => {
|
|
2761
|
-
callbacks.onDisconnect();
|
|
2762
|
-
};
|
|
2763
|
-
provider.on?.("accountsChanged", onAccountsChanged);
|
|
2764
|
-
provider.on?.("chainChanged", onChainChanged);
|
|
2765
|
-
provider.on?.("disconnect", onDisconnect);
|
|
2766
|
-
return () => {
|
|
2767
|
-
provider.removeListener?.("accountsChanged", onAccountsChanged);
|
|
2768
|
-
provider.removeListener?.("chainChanged", onChainChanged);
|
|
2769
|
-
provider.removeListener?.("disconnect", onDisconnect);
|
|
2770
|
-
};
|
|
2771
|
-
}
|
|
2772
|
-
var WalletManager, walletManager;
|
|
2773
|
-
var init_manager = __esm({
|
|
2774
|
-
"src/wallets/manager.ts"() {
|
|
2775
|
-
"use strict";
|
|
2776
|
-
init_connect();
|
|
2777
|
-
init_identity();
|
|
2778
|
-
init_solana();
|
|
2779
|
-
init_walletconnect();
|
|
2780
|
-
WalletManager = class {
|
|
2781
|
-
constructor() {
|
|
2782
|
-
this._status = "idle";
|
|
2783
|
-
this._connectedVia = null;
|
|
2784
|
-
this._wallet = null;
|
|
2785
|
-
this._detected = [];
|
|
2786
|
-
this._listeners = /* @__PURE__ */ new Set();
|
|
2787
|
-
this._error = null;
|
|
2788
|
-
this._identity = new IdentityStore();
|
|
2789
|
-
this._providerCleanup = null;
|
|
2790
|
-
this._connectedWalletId = null;
|
|
2791
|
-
this._address = null;
|
|
2792
|
-
this._onExternalDisconnectCallback = null;
|
|
2793
|
-
this._snapshot = null;
|
|
2884
|
+
};
|
|
2885
|
+
morphMainnet = {
|
|
2886
|
+
id: 2818,
|
|
2887
|
+
chainNamespace: "eip155",
|
|
2888
|
+
caipNetworkId: "eip155:2818",
|
|
2889
|
+
name: "Morph",
|
|
2890
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2891
|
+
rpcUrls: {
|
|
2892
|
+
default: { http: ["https://rpc.morph.network"] }
|
|
2794
2893
|
}
|
|
2795
|
-
|
|
2796
|
-
|
|
2894
|
+
};
|
|
2895
|
+
peaqMainnet = {
|
|
2896
|
+
id: 3338,
|
|
2897
|
+
chainNamespace: "eip155",
|
|
2898
|
+
caipNetworkId: "eip155:3338",
|
|
2899
|
+
name: "Peaq",
|
|
2900
|
+
nativeCurrency: { name: "Peaq", symbol: "PEAQ", decimals: 18 },
|
|
2901
|
+
rpcUrls: {
|
|
2902
|
+
default: { http: ["https://quicknode1.peaq.xyz"] }
|
|
2797
2903
|
}
|
|
2798
|
-
|
|
2799
|
-
|
|
2904
|
+
};
|
|
2905
|
+
tempoMainnet = {
|
|
2906
|
+
id: 4217,
|
|
2907
|
+
chainNamespace: "eip155",
|
|
2908
|
+
caipNetworkId: "eip155:4217",
|
|
2909
|
+
name: "Tempo",
|
|
2910
|
+
nativeCurrency: { name: "PathUSD", symbol: "PathUSD", decimals: 6 },
|
|
2911
|
+
rpcUrls: {
|
|
2912
|
+
default: { http: ["https://rpc.tempo.xyz"] }
|
|
2800
2913
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2914
|
+
};
|
|
2915
|
+
megaEthMainnet = {
|
|
2916
|
+
id: 4326,
|
|
2917
|
+
chainNamespace: "eip155",
|
|
2918
|
+
caipNetworkId: "eip155:4326",
|
|
2919
|
+
name: "MegaETH",
|
|
2920
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
2921
|
+
rpcUrls: {
|
|
2922
|
+
default: { http: ["https://mainnet.megaeth.com/rpc"] }
|
|
2803
2923
|
}
|
|
2804
|
-
|
|
2805
|
-
|
|
2924
|
+
};
|
|
2925
|
+
mantleMainnet = {
|
|
2926
|
+
id: 5e3,
|
|
2927
|
+
chainNamespace: "eip155",
|
|
2928
|
+
caipNetworkId: "eip155:5000",
|
|
2929
|
+
name: "Mantle Mainnet",
|
|
2930
|
+
nativeCurrency: { name: "Mantle", symbol: "MNT", decimals: 18 },
|
|
2931
|
+
rpcUrls: {
|
|
2932
|
+
default: { http: ["https://rpc.mantle.xyz"] }
|
|
2806
2933
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2934
|
+
};
|
|
2935
|
+
somniaMainnet = {
|
|
2936
|
+
id: 5031,
|
|
2937
|
+
chainNamespace: "eip155",
|
|
2938
|
+
caipNetworkId: "eip155:5031",
|
|
2939
|
+
name: "Somnia",
|
|
2940
|
+
nativeCurrency: { name: "Somnia", symbol: "SOMI", decimals: 18 },
|
|
2941
|
+
rpcUrls: {
|
|
2942
|
+
default: { http: ["https://api.infra.mainnet.somnia.network/"] }
|
|
2809
2943
|
}
|
|
2810
|
-
|
|
2811
|
-
|
|
2944
|
+
};
|
|
2945
|
+
kaiaMainnet = {
|
|
2946
|
+
id: 8217,
|
|
2947
|
+
chainNamespace: "eip155",
|
|
2948
|
+
caipNetworkId: "eip155:8217",
|
|
2949
|
+
name: "Kaia",
|
|
2950
|
+
nativeCurrency: { name: "KAIA", symbol: "KAIA", decimals: 18 },
|
|
2951
|
+
rpcUrls: {
|
|
2952
|
+
default: { http: ["https://public-en.node.kaia.io"] }
|
|
2812
2953
|
}
|
|
2813
|
-
|
|
2814
|
-
|
|
2954
|
+
};
|
|
2955
|
+
baseMainnet = {
|
|
2956
|
+
id: 8453,
|
|
2957
|
+
chainNamespace: "eip155",
|
|
2958
|
+
caipNetworkId: "eip155:8453",
|
|
2959
|
+
name: "Base Mainnet",
|
|
2960
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2961
|
+
rpcUrls: {
|
|
2962
|
+
default: { http: ["https://mainnet.base.org"] }
|
|
2815
2963
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2964
|
+
};
|
|
2965
|
+
plasmaMainnet = {
|
|
2966
|
+
id: 9745,
|
|
2967
|
+
chainNamespace: "eip155",
|
|
2968
|
+
caipNetworkId: "eip155:9745",
|
|
2969
|
+
name: "Plasma",
|
|
2970
|
+
nativeCurrency: { name: "XPL", symbol: "XPL", decimals: 18 },
|
|
2971
|
+
rpcUrls: {
|
|
2972
|
+
default: { http: ["https://rpc.plasma.to"] }
|
|
2818
2973
|
}
|
|
2819
|
-
|
|
2820
|
-
|
|
2974
|
+
};
|
|
2975
|
+
immutableZkEvmMainnet = {
|
|
2976
|
+
id: 13371,
|
|
2977
|
+
chainNamespace: "eip155",
|
|
2978
|
+
caipNetworkId: "eip155:13371",
|
|
2979
|
+
name: "Immutable zkEVM",
|
|
2980
|
+
nativeCurrency: { name: "IMX", symbol: "IMX", decimals: 18 },
|
|
2981
|
+
rpcUrls: {
|
|
2982
|
+
default: { http: ["https://rpc.immutable.com"] }
|
|
2821
2983
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2984
|
+
};
|
|
2985
|
+
apechainMainnet = {
|
|
2986
|
+
id: 33139,
|
|
2987
|
+
chainNamespace: "eip155",
|
|
2988
|
+
caipNetworkId: "eip155:33139",
|
|
2989
|
+
name: "Apechain",
|
|
2990
|
+
nativeCurrency: { name: "ApeCoin", symbol: "APE", decimals: 18 },
|
|
2991
|
+
rpcUrls: {
|
|
2992
|
+
default: { http: ["https://rpc.apechain.com"] }
|
|
2826
2993
|
}
|
|
2827
|
-
|
|
2828
|
-
|
|
2994
|
+
};
|
|
2995
|
+
modeMainnet = {
|
|
2996
|
+
id: 34443,
|
|
2997
|
+
chainNamespace: "eip155",
|
|
2998
|
+
caipNetworkId: "eip155:34443",
|
|
2999
|
+
name: "Mode",
|
|
3000
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3001
|
+
rpcUrls: {
|
|
3002
|
+
default: { http: ["https://mainnet.mode.network"] }
|
|
2829
3003
|
}
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
3004
|
+
};
|
|
3005
|
+
arbitrumMainnet = {
|
|
3006
|
+
id: 42161,
|
|
3007
|
+
chainNamespace: "eip155",
|
|
3008
|
+
caipNetworkId: "eip155:42161",
|
|
3009
|
+
name: "Arbitrum One",
|
|
3010
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3011
|
+
rpcUrls: {
|
|
3012
|
+
default: { http: ["https://rpc.ankr.com/arbitrum"] }
|
|
2835
3013
|
}
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
identity: this.identity,
|
|
2846
|
-
connectedWalletId: this._connectedWalletId,
|
|
2847
|
-
address: this._address,
|
|
2848
|
-
isConnected: this.isConnected
|
|
2849
|
-
};
|
|
3014
|
+
};
|
|
3015
|
+
arbitrumNovaMainnet = {
|
|
3016
|
+
id: 42170,
|
|
3017
|
+
chainNamespace: "eip155",
|
|
3018
|
+
caipNetworkId: "eip155:42170",
|
|
3019
|
+
name: "Arbitrum Nova",
|
|
3020
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3021
|
+
rpcUrls: {
|
|
3022
|
+
default: { http: ["https://arbitrum-nova-rpc.publicnode.com"] }
|
|
2850
3023
|
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
3024
|
+
};
|
|
3025
|
+
celoMainnet = {
|
|
3026
|
+
id: 42220,
|
|
3027
|
+
chainNamespace: "eip155",
|
|
3028
|
+
caipNetworkId: "eip155:42220",
|
|
3029
|
+
name: "Celo Mainnet",
|
|
3030
|
+
nativeCurrency: { name: "Celo", symbol: "CELO", decimals: 18 },
|
|
3031
|
+
rpcUrls: {
|
|
3032
|
+
default: { http: ["https://rpc.ankr.com/celo"] }
|
|
2854
3033
|
}
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
3034
|
+
};
|
|
3035
|
+
etherlinkMainnet = {
|
|
3036
|
+
id: 42793,
|
|
3037
|
+
chainNamespace: "eip155",
|
|
3038
|
+
caipNetworkId: "eip155:42793",
|
|
3039
|
+
name: "Etherlink",
|
|
3040
|
+
nativeCurrency: { name: "Tezos", symbol: "XTZ", decimals: 18 },
|
|
3041
|
+
rpcUrls: {
|
|
3042
|
+
default: { http: ["https://node.mainnet.etherlink.com"] }
|
|
2858
3043
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
3044
|
+
};
|
|
3045
|
+
hemiMainnet = {
|
|
3046
|
+
id: 43111,
|
|
3047
|
+
chainNamespace: "eip155",
|
|
3048
|
+
caipNetworkId: "eip155:43111",
|
|
3049
|
+
name: "Hemi",
|
|
3050
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3051
|
+
rpcUrls: {
|
|
3052
|
+
default: { http: ["https://rpc.hemi.network/rpc"] }
|
|
2866
3053
|
}
|
|
2867
|
-
|
|
2868
|
-
|
|
3054
|
+
};
|
|
3055
|
+
avalancheMainnet = {
|
|
3056
|
+
id: 43114,
|
|
3057
|
+
chainNamespace: "eip155",
|
|
3058
|
+
caipNetworkId: "eip155:43114",
|
|
3059
|
+
name: "Avalanche C-Chain",
|
|
3060
|
+
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
3061
|
+
rpcUrls: {
|
|
3062
|
+
default: { http: ["https://rpc.ankr.com/avalanche"] }
|
|
2869
3063
|
}
|
|
2870
|
-
|
|
2871
|
-
|
|
3064
|
+
};
|
|
3065
|
+
sophonMainnet = {
|
|
3066
|
+
id: 50104,
|
|
3067
|
+
chainNamespace: "eip155",
|
|
3068
|
+
caipNetworkId: "eip155:50104",
|
|
3069
|
+
name: "Sophon",
|
|
3070
|
+
nativeCurrency: { name: "SOPH", symbol: "SOPH", decimals: 18 },
|
|
3071
|
+
rpcUrls: {
|
|
3072
|
+
default: { http: ["https://rpc.sophon.xyz"] }
|
|
2872
3073
|
}
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
3074
|
+
};
|
|
3075
|
+
superpositionMainnet = {
|
|
3076
|
+
id: 55244,
|
|
3077
|
+
chainNamespace: "eip155",
|
|
3078
|
+
caipNetworkId: "eip155:55244",
|
|
3079
|
+
name: "Superposition",
|
|
3080
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3081
|
+
rpcUrls: {
|
|
3082
|
+
default: { http: ["https://rpc.superposition.so"] }
|
|
2878
3083
|
}
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
const { api, error } = await connectDetectedWallet(target, {
|
|
2889
|
-
wagmi: opts?.wagmi
|
|
2890
|
-
});
|
|
2891
|
-
if (api && !error) {
|
|
2892
|
-
this._wallet = api;
|
|
2893
|
-
this._connectedVia = "extension";
|
|
2894
|
-
this._connectedWalletId = target.meta.id;
|
|
2895
|
-
this.bindExtensionProviderEvents(target);
|
|
2896
|
-
await this.syncIdentityFromWallet(target.meta.id);
|
|
2897
|
-
this._status = "connected";
|
|
2898
|
-
this._error = null;
|
|
2899
|
-
return { error: null, api };
|
|
2900
|
-
}
|
|
2901
|
-
if (error) {
|
|
2902
|
-
this._status = "error";
|
|
2903
|
-
this._error = error;
|
|
2904
|
-
return { error, api };
|
|
2905
|
-
}
|
|
2906
|
-
} catch (e2) {
|
|
2907
|
-
this._error = e2 instanceof Error ? e2.message : String(e2);
|
|
2908
|
-
this._status = "error";
|
|
2909
|
-
this.clearConnectedState();
|
|
2910
|
-
} finally {
|
|
2911
|
-
this.emit();
|
|
2912
|
-
}
|
|
3084
|
+
};
|
|
3085
|
+
inkMainnet = {
|
|
3086
|
+
id: 57073,
|
|
3087
|
+
chainNamespace: "eip155",
|
|
3088
|
+
caipNetworkId: "eip155:57073",
|
|
3089
|
+
name: "Ink",
|
|
3090
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3091
|
+
rpcUrls: {
|
|
3092
|
+
default: { http: ["https://rpc-gel.inkonchain.com"] }
|
|
2913
3093
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
const connector = await getUniversalConnector(walletCfg);
|
|
2924
|
-
await connector.connect();
|
|
2925
|
-
const api = await buildWalletConnectAPI(walletCfg);
|
|
2926
|
-
this._wallet = api;
|
|
2927
|
-
this._connectedVia = "walletconnect";
|
|
2928
|
-
this._connectedWalletId = "walletconnect";
|
|
2929
|
-
const provider = connector.provider;
|
|
2930
|
-
this._providerCleanup = bindWalletConnectEvents(provider, {
|
|
2931
|
-
onAccountsChanged: (accounts) => {
|
|
2932
|
-
if (accounts.length === 0) {
|
|
2933
|
-
this.fullReset();
|
|
2934
|
-
this.triggerExternalDisconnect();
|
|
2935
|
-
this.emit();
|
|
2936
|
-
return;
|
|
2937
|
-
}
|
|
2938
|
-
void this.syncIdentityFromWallet("walletconnect");
|
|
2939
|
-
this.emit();
|
|
2940
|
-
},
|
|
2941
|
-
onChainChanged: () => {
|
|
2942
|
-
void this.syncIdentityFromWallet("walletconnect");
|
|
2943
|
-
this.emit();
|
|
2944
|
-
},
|
|
2945
|
-
onDisconnect: () => {
|
|
2946
|
-
this.fullReset();
|
|
2947
|
-
resetUniversalConnector();
|
|
2948
|
-
this.triggerExternalDisconnect();
|
|
2949
|
-
this.emit();
|
|
2950
|
-
}
|
|
2951
|
-
});
|
|
2952
|
-
await this.syncIdentityFromWallet("walletconnect");
|
|
2953
|
-
this._status = "connected";
|
|
2954
|
-
this._error = null;
|
|
2955
|
-
this.emit();
|
|
2956
|
-
return { error: null, api };
|
|
2957
|
-
} catch (e2) {
|
|
2958
|
-
const message = e2 instanceof Error ? e2.message : String(e2);
|
|
2959
|
-
this._error = message;
|
|
2960
|
-
this._status = "error";
|
|
2961
|
-
this.clearConnectedState();
|
|
2962
|
-
this.emit();
|
|
2963
|
-
return { error: message, api: null };
|
|
2964
|
-
}
|
|
3094
|
+
};
|
|
3095
|
+
lineaMainnet = {
|
|
3096
|
+
id: 59144,
|
|
3097
|
+
chainNamespace: "eip155",
|
|
3098
|
+
caipNetworkId: "eip155:59144",
|
|
3099
|
+
name: "Linea Mainnet",
|
|
3100
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3101
|
+
rpcUrls: {
|
|
3102
|
+
default: { http: ["https://rpc.linea.build"] }
|
|
2965
3103
|
}
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
}
|
|
2975
|
-
if (this._connectedVia === "walletconnect") {
|
|
2976
|
-
resetUniversalConnector();
|
|
2977
|
-
}
|
|
2978
|
-
this.fullReset();
|
|
2979
|
-
this.emit();
|
|
3104
|
+
};
|
|
3105
|
+
bobMainnet = {
|
|
3106
|
+
id: 60808,
|
|
3107
|
+
chainNamespace: "eip155",
|
|
3108
|
+
caipNetworkId: "eip155:60808",
|
|
3109
|
+
name: "BOB",
|
|
3110
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3111
|
+
rpcUrls: {
|
|
3112
|
+
default: { http: ["https://rpc.gobob.xyz"] }
|
|
2980
3113
|
}
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
3114
|
+
};
|
|
3115
|
+
berachainMainnet = {
|
|
3116
|
+
id: 80094,
|
|
3117
|
+
chainNamespace: "eip155",
|
|
3118
|
+
caipNetworkId: "eip155:80094",
|
|
3119
|
+
name: "Berachain",
|
|
3120
|
+
nativeCurrency: { name: "BERA", symbol: "BERA", decimals: 18 },
|
|
3121
|
+
rpcUrls: {
|
|
3122
|
+
default: { http: ["https://rpc.berachain.com/"] }
|
|
2989
3123
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3124
|
+
};
|
|
3125
|
+
blastMainnet = {
|
|
3126
|
+
id: 81457,
|
|
3127
|
+
chainNamespace: "eip155",
|
|
3128
|
+
caipNetworkId: "eip155:81457",
|
|
3129
|
+
name: "Blast Mainnet",
|
|
3130
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3131
|
+
rpcUrls: {
|
|
3132
|
+
default: { http: ["https://rpc.blast.io"] }
|
|
2993
3133
|
}
|
|
2994
|
-
|
|
2995
|
-
|
|
3134
|
+
};
|
|
3135
|
+
plumeMainnet = {
|
|
3136
|
+
id: 98866,
|
|
3137
|
+
chainNamespace: "eip155",
|
|
3138
|
+
caipNetworkId: "eip155:98866",
|
|
3139
|
+
name: "Plume",
|
|
3140
|
+
nativeCurrency: { name: "PLUME", symbol: "PLUME", decimals: 18 },
|
|
3141
|
+
rpcUrls: {
|
|
3142
|
+
default: { http: ["https://rpc.plume.org"] }
|
|
2996
3143
|
}
|
|
2997
|
-
|
|
2998
|
-
|
|
3144
|
+
};
|
|
3145
|
+
taikoMainnet = {
|
|
3146
|
+
id: 167e3,
|
|
3147
|
+
chainNamespace: "eip155",
|
|
3148
|
+
caipNetworkId: "eip155:167000",
|
|
3149
|
+
name: "Taiko",
|
|
3150
|
+
nativeCurrency: { name: "Ethereum", symbol: "ETH", decimals: 18 },
|
|
3151
|
+
rpcUrls: {
|
|
3152
|
+
default: { http: ["https://rpc.mainnet.taiko.xyz"] }
|
|
2999
3153
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3154
|
+
};
|
|
3155
|
+
scrollMainnet = {
|
|
3156
|
+
id: 534352,
|
|
3157
|
+
chainNamespace: "eip155",
|
|
3158
|
+
caipNetworkId: "eip155:534352",
|
|
3159
|
+
name: "Scroll",
|
|
3160
|
+
nativeCurrency: { name: "Scroll", symbol: "ETH", decimals: 18 },
|
|
3161
|
+
rpcUrls: {
|
|
3162
|
+
default: { http: ["https://rpc.scroll.io"] }
|
|
3003
3163
|
}
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3164
|
+
};
|
|
3165
|
+
katanaMainnet = {
|
|
3166
|
+
id: 747474,
|
|
3167
|
+
chainNamespace: "eip155",
|
|
3168
|
+
caipNetworkId: "eip155:747474",
|
|
3169
|
+
name: "Katana",
|
|
3170
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
3171
|
+
rpcUrls: {
|
|
3172
|
+
default: { http: ["https://rpc.katana.network"] }
|
|
3009
3173
|
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
}
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
if (target.via === "solana-window") {
|
|
3020
|
-
this._providerCleanup = bindSolanaProviderEvents(target.provider, {
|
|
3021
|
-
onConnect: () => {
|
|
3022
|
-
this._status = "connected";
|
|
3023
|
-
void this.syncIdentityFromWallet(target.meta.id);
|
|
3024
|
-
this.emit();
|
|
3025
|
-
},
|
|
3026
|
-
onAccountChanged: () => {
|
|
3027
|
-
void this.syncIdentityFromWallet(target.meta.id);
|
|
3028
|
-
this.emit();
|
|
3029
|
-
},
|
|
3030
|
-
onDisconnect: () => {
|
|
3031
|
-
this.fullReset();
|
|
3032
|
-
this.triggerExternalDisconnect();
|
|
3033
|
-
this.emit();
|
|
3034
|
-
}
|
|
3035
|
-
});
|
|
3036
|
-
return;
|
|
3037
|
-
}
|
|
3038
|
-
const provider = target.provider;
|
|
3039
|
-
const onAccountsChanged = (accounts) => {
|
|
3040
|
-
const nextAccounts = Array.isArray(accounts) ? accounts : [];
|
|
3041
|
-
if (nextAccounts.length === 0) {
|
|
3042
|
-
this.fullReset();
|
|
3043
|
-
this.triggerExternalDisconnect();
|
|
3044
|
-
this.emit();
|
|
3045
|
-
return;
|
|
3046
|
-
}
|
|
3047
|
-
this._status = "connected";
|
|
3048
|
-
void this.syncIdentityFromWallet(target.meta.id);
|
|
3049
|
-
this.emit();
|
|
3050
|
-
};
|
|
3051
|
-
const onDisconnect = () => {
|
|
3052
|
-
this.fullReset();
|
|
3053
|
-
this.triggerExternalDisconnect();
|
|
3054
|
-
this.emit();
|
|
3055
|
-
};
|
|
3056
|
-
provider.on?.("accountsChanged", onAccountsChanged);
|
|
3057
|
-
provider.on?.("disconnect", onDisconnect);
|
|
3058
|
-
this._providerCleanup = () => {
|
|
3059
|
-
provider.off?.("accountsChanged", onAccountsChanged);
|
|
3060
|
-
provider.off?.("disconnect", onDisconnect);
|
|
3061
|
-
provider.removeListener?.("accountsChanged", onAccountsChanged);
|
|
3062
|
-
provider.removeListener?.("disconnect", onDisconnect);
|
|
3063
|
-
};
|
|
3064
|
-
}
|
|
3065
|
-
async syncIdentityFromWallet(providerId) {
|
|
3066
|
-
if (!this._wallet) return;
|
|
3067
|
-
try {
|
|
3068
|
-
const address = await this._wallet.getAddress();
|
|
3069
|
-
this._address = address;
|
|
3070
|
-
const chain = this._wallet.ecosystem === "evm" ? { chainId: String(await this._wallet.getChainId()), type: "evm" } : this._wallet.ecosystem === "solana" ? {
|
|
3071
|
-
chainId: "solana-mainnet-beta",
|
|
3072
|
-
networkIdentifier: "solana-mainnet-beta",
|
|
3073
|
-
type: "solana"
|
|
3074
|
-
} : {
|
|
3075
|
-
chainId: "bip122:000000000019d6689c085ae165831e93",
|
|
3076
|
-
networkIdentifier: "bitcoin-mainnet",
|
|
3077
|
-
type: "bitcoin"
|
|
3078
|
-
};
|
|
3079
|
-
const identityAddress = buildWalletIdentityAddress({
|
|
3080
|
-
address,
|
|
3081
|
-
chain,
|
|
3082
|
-
source: "provider",
|
|
3083
|
-
providerId
|
|
3084
|
-
});
|
|
3085
|
-
if (identityAddress) {
|
|
3086
|
-
this._identity.upsert(identityAddress);
|
|
3087
|
-
}
|
|
3088
|
-
} catch {
|
|
3089
|
-
}
|
|
3174
|
+
};
|
|
3175
|
+
cornMainnet = {
|
|
3176
|
+
id: 21e6,
|
|
3177
|
+
chainNamespace: "eip155",
|
|
3178
|
+
caipNetworkId: "eip155:21000000",
|
|
3179
|
+
name: "Corn",
|
|
3180
|
+
nativeCurrency: { name: "Bitcorn", symbol: "BTCN", decimals: 18 },
|
|
3181
|
+
rpcUrls: {
|
|
3182
|
+
default: { http: ["https://mainnet.corn-rpc.com"] }
|
|
3090
3183
|
}
|
|
3091
3184
|
};
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3185
|
+
evmChains = [
|
|
3186
|
+
// Major L1s
|
|
3187
|
+
ethereumMainnet,
|
|
3188
|
+
bscMainnet,
|
|
3189
|
+
avalancheMainnet,
|
|
3190
|
+
polygonMainnet,
|
|
3191
|
+
// L2s / rollups
|
|
3192
|
+
arbitrumMainnet,
|
|
3193
|
+
arbitrumNovaMainnet,
|
|
3194
|
+
optimismMainnet,
|
|
3195
|
+
baseMainnet,
|
|
3196
|
+
zkSyncMainnet,
|
|
3197
|
+
lineaMainnet,
|
|
3198
|
+
mantleMainnet,
|
|
3199
|
+
blastMainnet,
|
|
3200
|
+
scrollMainnet,
|
|
3201
|
+
taikoMainnet,
|
|
3202
|
+
modeMainnet,
|
|
3203
|
+
inkMainnet,
|
|
3204
|
+
unichainMainnet,
|
|
3205
|
+
worldchainMainnet,
|
|
3206
|
+
swellchainMainnet,
|
|
3207
|
+
soneiumMainnet,
|
|
3208
|
+
liskMainnet,
|
|
3209
|
+
morphMainnet,
|
|
3210
|
+
abstractMainnet,
|
|
3211
|
+
megaEthMainnet,
|
|
3212
|
+
superpositionMainnet,
|
|
3213
|
+
fraxtalMainnet,
|
|
3214
|
+
// EVM-compatible L1s & app-chains
|
|
3215
|
+
gnosisMainnet,
|
|
3216
|
+
fantomMainnet,
|
|
3217
|
+
celoMainnet,
|
|
3218
|
+
sonicMainnet,
|
|
3219
|
+
berachainMainnet,
|
|
3220
|
+
moonbeamMainnet,
|
|
3221
|
+
metisMainnet,
|
|
3222
|
+
bobaMainnet,
|
|
3223
|
+
roninMainnet,
|
|
3224
|
+
kavaEvmMainnet,
|
|
3225
|
+
cronosMainnet,
|
|
3226
|
+
kaiaMainnet,
|
|
3227
|
+
flareMainnet,
|
|
3228
|
+
telosMainnet,
|
|
3229
|
+
xdcMainnet,
|
|
3230
|
+
fuseMainnet,
|
|
3231
|
+
victionMainnet,
|
|
3232
|
+
rootstockMainnet,
|
|
3233
|
+
hederaMainnet,
|
|
3234
|
+
filecoinMainnet,
|
|
3235
|
+
flowMainnet,
|
|
3236
|
+
opBnbMainnet,
|
|
3237
|
+
lensMainnet,
|
|
3238
|
+
apechainMainnet,
|
|
3239
|
+
etherlinkMainnet,
|
|
3240
|
+
hemiMainnet,
|
|
3241
|
+
immutableZkEvmMainnet,
|
|
3242
|
+
peaqMainnet,
|
|
3243
|
+
sophonMainnet,
|
|
3244
|
+
gravityMainnet,
|
|
3245
|
+
vanaMainnet,
|
|
3246
|
+
hyperliquidMainnet,
|
|
3247
|
+
hyperEvmMainnet,
|
|
3248
|
+
stableMainnet,
|
|
3249
|
+
tempoMainnet,
|
|
3250
|
+
plasmaMainnet,
|
|
3251
|
+
somniaMainnet,
|
|
3252
|
+
monadMainnet,
|
|
3253
|
+
pharosMainnet,
|
|
3254
|
+
bobMainnet,
|
|
3255
|
+
plumeMainnet,
|
|
3256
|
+
katanaMainnet,
|
|
3257
|
+
cornMainnet,
|
|
3258
|
+
// Sei EVM
|
|
3259
|
+
seiMainnet
|
|
3260
|
+
];
|
|
3261
|
+
solanaChains = [solanaMainnet];
|
|
3262
|
+
bitcoinChains = [bitcoinMainnet];
|
|
3263
|
+
cosmosChains = [seiCosmosMainnet];
|
|
3264
|
+
networks = [
|
|
3265
|
+
// ...solanaChains,
|
|
3266
|
+
// ...bitcoinChains,
|
|
3267
|
+
...evmChains
|
|
3268
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3269
|
+
];
|
|
3270
|
+
namespaceConfig = [
|
|
3271
|
+
{
|
|
3272
|
+
namespace: "solana",
|
|
3273
|
+
chains: solanaChains,
|
|
3274
|
+
methods: ["solana_signMessage", "solana_signTransaction"],
|
|
3275
|
+
events: []
|
|
3276
|
+
},
|
|
3277
|
+
{
|
|
3278
|
+
namespace: "eip155",
|
|
3279
|
+
chains: evmChains,
|
|
3280
|
+
methods: [
|
|
3281
|
+
"eth_sendTransaction",
|
|
3282
|
+
"eth_signTransaction",
|
|
3283
|
+
"eth_sign",
|
|
3284
|
+
"personal_sign",
|
|
3285
|
+
"eth_signTypedData_v4"
|
|
3286
|
+
],
|
|
3287
|
+
events: ["accountsChanged", "chainChanged"]
|
|
3288
|
+
},
|
|
3289
|
+
{
|
|
3290
|
+
namespace: "bip122",
|
|
3291
|
+
chains: bitcoinChains,
|
|
3292
|
+
methods: ["signMessage", "sendTransfer"],
|
|
3293
|
+
events: []
|
|
3294
|
+
},
|
|
3295
|
+
{
|
|
3296
|
+
namespace: "cosmos",
|
|
3297
|
+
chains: cosmosChains,
|
|
3298
|
+
methods: ["cosmos_signDirect", "cosmos_signAmino", "cosmos_getAccounts"],
|
|
3299
|
+
events: []
|
|
3300
|
+
}
|
|
3301
|
+
];
|
|
3302
|
+
universalConnectorPromise = null;
|
|
3303
|
+
initializedProjectId = null;
|
|
3105
3304
|
}
|
|
3106
3305
|
});
|
|
3107
3306
|
|
|
3108
|
-
// src/
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
});
|
|
3114
|
-
function getChainAliases(chain) {
|
|
3115
|
-
const values = [
|
|
3116
|
-
chain.chainId,
|
|
3117
|
-
chain.id,
|
|
3118
|
-
chain.networkIdentifier,
|
|
3119
|
-
chain.axelarChainName,
|
|
3120
|
-
chain.networkName
|
|
3121
|
-
];
|
|
3122
|
-
return values.map((value) => normalizeChainKey(value)).filter(Boolean);
|
|
3123
|
-
}
|
|
3124
|
-
function tokenKey(token) {
|
|
3125
|
-
return `${normalizeChainKey(token.chainId)}:${token.address.toLowerCase()}`;
|
|
3126
|
-
}
|
|
3127
|
-
function parseTokenPage(payload) {
|
|
3128
|
-
if (Array.isArray(payload)) {
|
|
3129
|
-
return {
|
|
3130
|
-
data: payload,
|
|
3131
|
-
pageInfo: { hasNextPage: false }
|
|
3132
|
-
};
|
|
3133
|
-
}
|
|
3134
|
-
const parsed = payload ?? {};
|
|
3135
|
-
const data = parsed.data ?? parsed.results ?? parsed.tokens ?? [];
|
|
3136
|
-
const info = parsed.pageInfo ?? parsed.pagination;
|
|
3137
|
-
return {
|
|
3138
|
-
data: Array.isArray(data) ? data : [],
|
|
3139
|
-
pageInfo: {
|
|
3140
|
-
hasNextPage: info?.hasNextPage ?? parsed.hasNextPage ?? Boolean(info?.nextCursor),
|
|
3141
|
-
nextCursor: info?.nextCursor ?? parsed.nextCursor
|
|
3142
|
-
}
|
|
3143
|
-
};
|
|
3144
|
-
}
|
|
3145
|
-
function normalizeToken(token) {
|
|
3307
|
+
// src/wallets/manager.ts
|
|
3308
|
+
import { useCallback, useEffect, useSyncExternalStore } from "react";
|
|
3309
|
+
function getChainMeta(chainId) {
|
|
3310
|
+
const chain = evmChains.find((c) => c.id === chainId);
|
|
3311
|
+
if (!chain) throw new Error(`Chain ${chainId} not configured`);
|
|
3146
3312
|
return {
|
|
3147
|
-
|
|
3148
|
-
|
|
3313
|
+
chainId: `0x${chainId.toString(16)}`,
|
|
3314
|
+
chainName: chain.name,
|
|
3315
|
+
nativeCurrency: chain.nativeCurrency,
|
|
3316
|
+
rpcUrls: chain.rpcUrls.default.http
|
|
3149
3317
|
};
|
|
3150
3318
|
}
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
|
-
async ensureChainsLoaded() {
|
|
3187
|
-
if (this._chainsLoaded) return;
|
|
3188
|
-
if (this._chainsLoadingPromise) {
|
|
3189
|
-
await this._chainsLoadingPromise;
|
|
3190
|
-
return;
|
|
3191
|
-
}
|
|
3192
|
-
this._chainsLoadingPromise = this.loadChains();
|
|
3193
|
-
try {
|
|
3194
|
-
await this._chainsLoadingPromise;
|
|
3195
|
-
} finally {
|
|
3196
|
-
this._chainsLoadingPromise = null;
|
|
3319
|
+
async function buildWalletConnectAPI(walletCfg) {
|
|
3320
|
+
const connector = await getUniversalConnector(walletCfg);
|
|
3321
|
+
const provider = connector.provider;
|
|
3322
|
+
const api = {
|
|
3323
|
+
ecosystem: "evm",
|
|
3324
|
+
type: "eip1193",
|
|
3325
|
+
async getAddress() {
|
|
3326
|
+
const accounts = await provider.request({
|
|
3327
|
+
method: "eth_accounts"
|
|
3328
|
+
});
|
|
3329
|
+
if (!accounts?.[0])
|
|
3330
|
+
throw new Error("No account connected via WalletConnect");
|
|
3331
|
+
return accounts[0];
|
|
3332
|
+
},
|
|
3333
|
+
async getChainId() {
|
|
3334
|
+
const hex = await provider.request({ method: "eth_chainId" });
|
|
3335
|
+
return parseInt(hex, 16);
|
|
3336
|
+
},
|
|
3337
|
+
async switchChain(chainId) {
|
|
3338
|
+
const hexChainId = `0x${chainId.toString(16)}`;
|
|
3339
|
+
try {
|
|
3340
|
+
await provider.request({
|
|
3341
|
+
method: "wallet_switchEthereumChain",
|
|
3342
|
+
params: [{ chainId: hexChainId }]
|
|
3343
|
+
});
|
|
3344
|
+
} catch (err) {
|
|
3345
|
+
const code = err?.code;
|
|
3346
|
+
if (code === 4902) {
|
|
3347
|
+
const chainMeta = getChainMeta(chainId);
|
|
3348
|
+
await provider.request({
|
|
3349
|
+
method: "wallet_addEthereumChain",
|
|
3350
|
+
params: [chainMeta]
|
|
3351
|
+
});
|
|
3352
|
+
} else {
|
|
3353
|
+
throw err;
|
|
3197
3354
|
}
|
|
3198
3355
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3356
|
+
},
|
|
3357
|
+
async request(args) {
|
|
3358
|
+
return provider.request(args);
|
|
3359
|
+
},
|
|
3360
|
+
async disconnect() {
|
|
3361
|
+
await connector.disconnect().catch(() => {
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
};
|
|
3365
|
+
return api;
|
|
3366
|
+
}
|
|
3367
|
+
function bindWalletConnectEvents(provider, callbacks) {
|
|
3368
|
+
const onAccountsChanged = (accounts) => {
|
|
3369
|
+
const list = Array.isArray(accounts) ? accounts : [];
|
|
3370
|
+
callbacks.onAccountsChanged(list);
|
|
3371
|
+
};
|
|
3372
|
+
const onChainChanged = (chainId) => {
|
|
3373
|
+
callbacks.onChainChanged(String(chainId));
|
|
3374
|
+
};
|
|
3375
|
+
const onDisconnect = () => {
|
|
3376
|
+
callbacks.onDisconnect();
|
|
3377
|
+
};
|
|
3378
|
+
provider.on?.("accountsChanged", onAccountsChanged);
|
|
3379
|
+
provider.on?.("chainChanged", onChainChanged);
|
|
3380
|
+
provider.on?.("disconnect", onDisconnect);
|
|
3381
|
+
return () => {
|
|
3382
|
+
provider.removeListener?.("accountsChanged", onAccountsChanged);
|
|
3383
|
+
provider.removeListener?.("chainChanged", onChainChanged);
|
|
3384
|
+
provider.removeListener?.("disconnect", onDisconnect);
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
var WalletManager, walletManager;
|
|
3388
|
+
var init_manager = __esm({
|
|
3389
|
+
"src/wallets/manager.ts"() {
|
|
3390
|
+
"use strict";
|
|
3391
|
+
init_connect();
|
|
3392
|
+
init_identity();
|
|
3393
|
+
init_solana();
|
|
3394
|
+
init_walletconnect();
|
|
3395
|
+
WalletManager = class {
|
|
3396
|
+
constructor() {
|
|
3397
|
+
this._status = "idle";
|
|
3398
|
+
this._connectedVia = null;
|
|
3399
|
+
this._wallet = null;
|
|
3400
|
+
this._detected = [];
|
|
3401
|
+
this._listeners = /* @__PURE__ */ new Set();
|
|
3402
|
+
this._error = null;
|
|
3403
|
+
this._identity = new IdentityStore();
|
|
3404
|
+
this._providerCleanup = null;
|
|
3405
|
+
this._connectedWalletId = null;
|
|
3406
|
+
this._address = null;
|
|
3407
|
+
this._onExternalDisconnectCallback = null;
|
|
3408
|
+
this._snapshot = null;
|
|
3201
3409
|
}
|
|
3202
|
-
|
|
3203
|
-
this.
|
|
3204
|
-
type: "token_page_loaded",
|
|
3205
|
-
chainRef: String(chainRef),
|
|
3206
|
-
query,
|
|
3207
|
-
count: result.data.length,
|
|
3208
|
-
hasNextPage: result.pageInfo.hasNextPage,
|
|
3209
|
-
cursor
|
|
3210
|
-
});
|
|
3410
|
+
get status() {
|
|
3411
|
+
return this._status;
|
|
3211
3412
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
this.config.onEvent?.({
|
|
3215
|
-
type: "token_page_error",
|
|
3216
|
-
chainRef: String(chainRef),
|
|
3217
|
-
query,
|
|
3218
|
-
cursor,
|
|
3219
|
-
message
|
|
3220
|
-
});
|
|
3413
|
+
get error() {
|
|
3414
|
+
return this._error;
|
|
3221
3415
|
}
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
if (canonical == null) return;
|
|
3225
|
-
const normalized = {
|
|
3226
|
-
...chain,
|
|
3227
|
-
id: chain.id ?? canonical,
|
|
3228
|
-
chainId: chain.chainId ?? canonical
|
|
3229
|
-
};
|
|
3230
|
-
const canonicalKey = normalizeChainKey(canonical);
|
|
3231
|
-
this._chainsById.set(canonicalKey, normalized);
|
|
3232
|
-
for (const alias of getChainAliases(normalized)) {
|
|
3233
|
-
this._chainAliases.set(alias, canonicalKey);
|
|
3234
|
-
}
|
|
3416
|
+
get detected() {
|
|
3417
|
+
return this._detected;
|
|
3235
3418
|
}
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
const existingByKey = this._tokensByChainKey.get(chainKey) ?? /* @__PURE__ */ new Map();
|
|
3239
|
-
existingByKey.set(key, token);
|
|
3240
|
-
this._tokensByChainKey.set(chainKey, existingByKey);
|
|
3241
|
-
this._tokensByChain.set(chainKey, Array.from(existingByKey.values()));
|
|
3419
|
+
get wallet() {
|
|
3420
|
+
return this._wallet;
|
|
3242
3421
|
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
if (chainRef == null) return;
|
|
3246
|
-
const normalized = normalizeToken(token);
|
|
3247
|
-
const resolvedChain = this.chain(chainRef);
|
|
3248
|
-
const aliases = resolvedChain ? getChainAliases(resolvedChain) : [normalizeChainKey(chainRef)];
|
|
3249
|
-
for (const alias of aliases) {
|
|
3250
|
-
this.storeTokenForAlias(alias, normalized);
|
|
3251
|
-
}
|
|
3422
|
+
get connectedVia() {
|
|
3423
|
+
return this._connectedVia;
|
|
3252
3424
|
}
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
headers: { Accept: "application/json", "X-API-Key": this.config.apiKey }
|
|
3256
|
-
});
|
|
3257
|
-
if (!chainsRes.ok) throw new Error(`chains: HTTP ${chainsRes.status}`);
|
|
3258
|
-
const chains = await chainsRes.json();
|
|
3259
|
-
const chainsArr = Array.isArray(chains) ? chains : chains.data ?? [];
|
|
3260
|
-
for (const chain of chainsArr) {
|
|
3261
|
-
this.storeChain(chain);
|
|
3262
|
-
}
|
|
3263
|
-
this._chainsLoaded = true;
|
|
3425
|
+
get connectedWalletId() {
|
|
3426
|
+
return this._connectedWalletId;
|
|
3264
3427
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
const tokensRes = await fetch(`${this.baseURL}/v1/routes/tokens`, {
|
|
3268
|
-
headers: { Accept: "application/json", "X-API-Key": this.config.apiKey }
|
|
3269
|
-
});
|
|
3270
|
-
if (!tokensRes.ok) throw new Error(`tokens: HTTP ${tokensRes.status}`);
|
|
3271
|
-
const tokens = await tokensRes.json();
|
|
3272
|
-
const tokensArr = Array.isArray(tokens) ? tokens : tokens.data ?? [];
|
|
3273
|
-
for (const token of tokensArr) {
|
|
3274
|
-
this.storeToken(token);
|
|
3275
|
-
}
|
|
3276
|
-
this._loaded = true;
|
|
3428
|
+
get address() {
|
|
3429
|
+
return this._address;
|
|
3277
3430
|
}
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
for (const [key, value] of this._pageCache.entries()) {
|
|
3281
|
-
if (now - value.storedAt > PAGE_CACHE_TTL_MS) {
|
|
3282
|
-
this._pageCache.delete(key);
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
while (this._pageCache.size > PAGE_CACHE_LIMIT) {
|
|
3286
|
-
const oldestKey = this._pageCache.keys().next().value;
|
|
3287
|
-
if (!oldestKey) {
|
|
3288
|
-
break;
|
|
3289
|
-
}
|
|
3290
|
-
this._pageCache.delete(oldestKey);
|
|
3291
|
-
}
|
|
3431
|
+
get isConnected() {
|
|
3432
|
+
return this._status === "connected";
|
|
3292
3433
|
}
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
const canonical = normalizeChainKey(chain?.chainId ?? chainRef);
|
|
3296
|
-
return `${canonical}::${opts.q ?? ""}::${opts.limit ?? ""}::${opts.cursor ?? ""}`;
|
|
3434
|
+
get walletType() {
|
|
3435
|
+
return this._connectedVia === "walletconnect" ? "walletconnect" : "other";
|
|
3297
3436
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
const
|
|
3301
|
-
return
|
|
3302
|
-
if (normalizeChainKey(token.chainId) !== normalizedChain) {
|
|
3303
|
-
return false;
|
|
3304
|
-
}
|
|
3305
|
-
if (!normalizedQuery) {
|
|
3306
|
-
return true;
|
|
3307
|
-
}
|
|
3308
|
-
return token.symbol?.toLowerCase().includes(normalizedQuery) || token.name?.toLowerCase().includes(normalizedQuery) || token.address?.toLowerCase().includes(normalizedQuery);
|
|
3309
|
-
});
|
|
3437
|
+
get simple() {
|
|
3438
|
+
if (!this._wallet) return null;
|
|
3439
|
+
const { getAddress, disconnect } = this._wallet;
|
|
3440
|
+
return { getAddress, disconnect };
|
|
3310
3441
|
}
|
|
3311
|
-
|
|
3312
|
-
return
|
|
3442
|
+
get identity() {
|
|
3443
|
+
return this._identity.snapshot;
|
|
3313
3444
|
}
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3445
|
+
get snapshot() {
|
|
3446
|
+
if (!this._snapshot) {
|
|
3447
|
+
this._snapshot = this.buildSnapshot();
|
|
3448
|
+
}
|
|
3449
|
+
return this._snapshot;
|
|
3318
3450
|
}
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3451
|
+
buildSnapshot() {
|
|
3452
|
+
return {
|
|
3453
|
+
status: this._status,
|
|
3454
|
+
connectedVia: this._connectedVia,
|
|
3455
|
+
walletType: this.walletType,
|
|
3456
|
+
error: this._error,
|
|
3457
|
+
detected: this._detected,
|
|
3458
|
+
wallet: this._wallet,
|
|
3459
|
+
simple: this.simple,
|
|
3460
|
+
identity: this.identity,
|
|
3461
|
+
connectedWalletId: this._connectedWalletId,
|
|
3462
|
+
address: this._address,
|
|
3463
|
+
isConnected: this.isConnected
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
onChange(fn) {
|
|
3467
|
+
this._listeners.add(fn);
|
|
3468
|
+
return () => this._listeners.delete(fn);
|
|
3469
|
+
}
|
|
3470
|
+
emit() {
|
|
3471
|
+
this._snapshot = null;
|
|
3472
|
+
for (const fn of this._listeners) fn(this._status);
|
|
3473
|
+
}
|
|
3474
|
+
onExternalDisconnect(cb) {
|
|
3475
|
+
this._onExternalDisconnectCallback = cb;
|
|
3476
|
+
return () => {
|
|
3477
|
+
if (this._onExternalDisconnectCallback === cb) {
|
|
3478
|
+
this._onExternalDisconnectCallback = null;
|
|
3324
3479
|
}
|
|
3325
|
-
}
|
|
3326
|
-
return Array.from(unique.values());
|
|
3480
|
+
};
|
|
3327
3481
|
}
|
|
3328
|
-
|
|
3329
|
-
|
|
3482
|
+
triggerExternalDisconnect() {
|
|
3483
|
+
this._onExternalDisconnectCallback?.();
|
|
3330
3484
|
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
}
|
|
3345
|
-
};
|
|
3346
|
-
}
|
|
3347
|
-
const cacheKey = this.pageCacheKey(chainRef, opts);
|
|
3348
|
-
const cached = this._pageCache.get(cacheKey);
|
|
3349
|
-
if (cached && Date.now() - cached.storedAt <= PAGE_CACHE_TTL_MS) {
|
|
3350
|
-
return { data: cached.data, pageInfo: cached.pageInfo };
|
|
3485
|
+
setDetected(list) {
|
|
3486
|
+
this._detected = list;
|
|
3487
|
+
}
|
|
3488
|
+
async autoAttach(opts) {
|
|
3489
|
+
if (!this._detected.length) return;
|
|
3490
|
+
const target = (opts?.pick ?? ((l) => l[0]))(this._detected);
|
|
3491
|
+
if (!target) return;
|
|
3492
|
+
await this.connectDetected(target, opts);
|
|
3493
|
+
}
|
|
3494
|
+
async connectDetected(target, opts) {
|
|
3495
|
+
if (this._status === "connected" && this._connectedVia === "extension" && this._connectedWalletId === target.meta.id && this._wallet) {
|
|
3496
|
+
this.emit();
|
|
3497
|
+
return;
|
|
3351
3498
|
}
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
url.searchParams.set("chainId", chainKey);
|
|
3356
|
-
if (opts.cursor) url.searchParams.set("cursor", opts.cursor);
|
|
3357
|
-
if (opts.limit != null) url.searchParams.set("limit", String(opts.limit));
|
|
3358
|
-
if (opts.q) url.searchParams.set("q", opts.q);
|
|
3499
|
+
this._status = "connecting";
|
|
3500
|
+
this.clearConnectedState();
|
|
3501
|
+
this.emit();
|
|
3359
3502
|
try {
|
|
3360
|
-
const
|
|
3361
|
-
|
|
3362
|
-
Accept: "application/json",
|
|
3363
|
-
"X-API-Key": this.config.apiKey
|
|
3364
|
-
}
|
|
3503
|
+
const { api, error } = await connectDetectedWallet(target, {
|
|
3504
|
+
wagmi: opts?.wagmi
|
|
3365
3505
|
});
|
|
3366
|
-
if (!
|
|
3367
|
-
|
|
3506
|
+
if (api && !error) {
|
|
3507
|
+
this._wallet = api;
|
|
3508
|
+
this._connectedVia = "extension";
|
|
3509
|
+
this._connectedWalletId = target.meta.id;
|
|
3510
|
+
this.bindExtensionProviderEvents(target);
|
|
3511
|
+
await this.syncIdentityFromWallet(target.meta.id);
|
|
3512
|
+
this._status = "connected";
|
|
3513
|
+
this._error = null;
|
|
3514
|
+
return { error: null, api };
|
|
3368
3515
|
}
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
this.storeToken(normalized);
|
|
3374
|
-
deduped.set(tokenKey(normalized), normalized);
|
|
3516
|
+
if (error) {
|
|
3517
|
+
this._status = "error";
|
|
3518
|
+
this._error = error;
|
|
3519
|
+
return { error, api };
|
|
3375
3520
|
}
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
this.
|
|
3382
|
-
this.emitPageLoaded(chainRef, opts.q, result, opts.cursor);
|
|
3383
|
-
return result;
|
|
3384
|
-
} catch (error) {
|
|
3385
|
-
this.emitPageError(chainRef, opts.q, opts.cursor, error);
|
|
3386
|
-
await this.ensureLoaded();
|
|
3387
|
-
const fallback = this.filterTokens(this.allTokens(), chainRef, opts.q);
|
|
3388
|
-
return {
|
|
3389
|
-
data: fallback,
|
|
3390
|
-
pageInfo: { hasNextPage: false }
|
|
3391
|
-
};
|
|
3521
|
+
} catch (e2) {
|
|
3522
|
+
this._error = e2 instanceof Error ? e2.message : String(e2);
|
|
3523
|
+
this._status = "error";
|
|
3524
|
+
this.clearConnectedState();
|
|
3525
|
+
} finally {
|
|
3526
|
+
this.emit();
|
|
3392
3527
|
}
|
|
3393
3528
|
}
|
|
3394
|
-
async
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
yield page;
|
|
3399
|
-
cursor = page.pageInfo.nextCursor;
|
|
3400
|
-
if (!page.pageInfo.hasNextPage) {
|
|
3401
|
-
break;
|
|
3402
|
-
}
|
|
3403
|
-
} while (cursor);
|
|
3404
|
-
}
|
|
3405
|
-
findToken(chainRef, address) {
|
|
3406
|
-
const chain = this.chain(chainRef);
|
|
3407
|
-
const chainType = normalizeChainType(chain);
|
|
3408
|
-
const normalizedAddress = normalizeAddress(address, chainType);
|
|
3409
|
-
return this.tokens(chainRef).find((token) => {
|
|
3410
|
-
return normalizeAddress(token.address, chainType) === normalizedAddress;
|
|
3411
|
-
});
|
|
3412
|
-
}
|
|
3413
|
-
resolveToken(chainRef, input) {
|
|
3414
|
-
if (!input) return void 0;
|
|
3415
|
-
const s = String(input).trim();
|
|
3416
|
-
const chain = this.chain(chainRef);
|
|
3417
|
-
const chainType = normalizeChainType(chain);
|
|
3418
|
-
if (/^0x[0-9a-fA-F]{40}$/.test(s)) return s;
|
|
3419
|
-
if (chainType === "solana" && s.length > 20) return s;
|
|
3420
|
-
const nativeAddress = getNativeTokenAddress(chainType);
|
|
3421
|
-
const nativeSymbol = chain?.nativeCurrency?.symbol?.toUpperCase?.();
|
|
3422
|
-
if (nativeSymbol && s.toUpperCase() === nativeSymbol || ["ETH", "MATIC", "AVAX", "BNB", "SOL", "NATIVE"].includes(s.toUpperCase())) {
|
|
3423
|
-
return chainType === "solana" ? nativeAddress : NATIVE;
|
|
3529
|
+
async connectWalletConnect(walletCfg) {
|
|
3530
|
+
if (this._status === "connected" && this._connectedVia === "walletconnect" && this._wallet) {
|
|
3531
|
+
this.emit();
|
|
3532
|
+
return { error: null, api: this._wallet };
|
|
3424
3533
|
}
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
}
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
function normalizeStreamChunk(chunk) {
|
|
3541
|
-
return Array.isArray(chunk) ? chunk : [chunk];
|
|
3542
|
-
}
|
|
3543
|
-
function mergeBalanceWrappers(current, incoming) {
|
|
3544
|
-
const merged = /* @__PURE__ */ new Map();
|
|
3545
|
-
for (const item of current) {
|
|
3546
|
-
merged.set(item.chain_id, item);
|
|
3547
|
-
}
|
|
3548
|
-
for (const item of incoming) {
|
|
3549
|
-
const existing = merged.get(item.chain_id);
|
|
3550
|
-
if (!existing) {
|
|
3551
|
-
merged.set(item.chain_id, item);
|
|
3552
|
-
continue;
|
|
3553
|
-
}
|
|
3554
|
-
const balancesByKey = /* @__PURE__ */ new Map();
|
|
3555
|
-
for (const row of existing.balances ?? []) {
|
|
3556
|
-
balancesByKey.set(`${row.contract ?? row.address ?? row.symbol}`, row);
|
|
3557
|
-
}
|
|
3558
|
-
for (const row of item.balances ?? []) {
|
|
3559
|
-
balancesByKey.set(`${row.contract ?? row.address ?? row.symbol}`, row);
|
|
3560
|
-
}
|
|
3561
|
-
merged.set(item.chain_id, {
|
|
3562
|
-
...existing,
|
|
3563
|
-
...item,
|
|
3564
|
-
balances: Array.from(balancesByKey.values()),
|
|
3565
|
-
count: item.count ?? existing.count
|
|
3566
|
-
});
|
|
3567
|
-
}
|
|
3568
|
-
return Array.from(merged.values());
|
|
3569
|
-
}
|
|
3570
|
-
async function parseStreamingBalances(response, address, options = {}) {
|
|
3571
|
-
if (!response.body) {
|
|
3572
|
-
throw new Error("balances stream: empty response body");
|
|
3573
|
-
}
|
|
3574
|
-
const decoder = new TextDecoder();
|
|
3575
|
-
const reader = response.body.getReader();
|
|
3576
|
-
async function* stream() {
|
|
3577
|
-
let buffer = "";
|
|
3578
|
-
try {
|
|
3579
|
-
while (true) {
|
|
3580
|
-
const { value, done } = await reader.read();
|
|
3581
|
-
if (done) break;
|
|
3582
|
-
buffer += decoder.decode(value, { stream: true });
|
|
3583
|
-
const frames = buffer.split(/\r?\n/);
|
|
3584
|
-
buffer = frames.pop() ?? "";
|
|
3585
|
-
for (const frame of frames) {
|
|
3586
|
-
const trimmed = frame.trim();
|
|
3587
|
-
if (!trimmed) continue;
|
|
3588
|
-
try {
|
|
3589
|
-
const chunk = normalizeStreamChunk(
|
|
3590
|
-
JSON.parse(trimmed)
|
|
3591
|
-
);
|
|
3592
|
-
emitBalanceStreamChunk(address, chunk.length);
|
|
3593
|
-
yield chunk;
|
|
3594
|
-
} catch (error) {
|
|
3595
|
-
if (options.strict) {
|
|
3596
|
-
throw error;
|
|
3534
|
+
this._status = "connecting";
|
|
3535
|
+
this.clearConnectedState();
|
|
3536
|
+
this.emit();
|
|
3537
|
+
try {
|
|
3538
|
+
const connector = await getUniversalConnector(walletCfg);
|
|
3539
|
+
await connector.connect();
|
|
3540
|
+
const api = await buildWalletConnectAPI(walletCfg);
|
|
3541
|
+
this._wallet = api;
|
|
3542
|
+
this._connectedVia = "walletconnect";
|
|
3543
|
+
this._connectedWalletId = "walletconnect";
|
|
3544
|
+
const provider = connector.provider;
|
|
3545
|
+
this._providerCleanup = bindWalletConnectEvents(provider, {
|
|
3546
|
+
onAccountsChanged: (accounts) => {
|
|
3547
|
+
if (accounts.length === 0) {
|
|
3548
|
+
this.fullReset();
|
|
3549
|
+
this.triggerExternalDisconnect();
|
|
3550
|
+
this.emit();
|
|
3551
|
+
return;
|
|
3552
|
+
}
|
|
3553
|
+
void this.syncIdentityFromWallet("walletconnect");
|
|
3554
|
+
this.emit();
|
|
3555
|
+
},
|
|
3556
|
+
onChainChanged: () => {
|
|
3557
|
+
void this.syncIdentityFromWallet("walletconnect");
|
|
3558
|
+
this.emit();
|
|
3559
|
+
},
|
|
3560
|
+
onDisconnect: () => {
|
|
3561
|
+
this.fullReset();
|
|
3562
|
+
resetUniversalConnector();
|
|
3563
|
+
this.triggerExternalDisconnect();
|
|
3564
|
+
this.emit();
|
|
3565
|
+
}
|
|
3566
|
+
});
|
|
3567
|
+
await this.syncIdentityFromWallet("walletconnect");
|
|
3568
|
+
this._status = "connected";
|
|
3569
|
+
this._error = null;
|
|
3570
|
+
this.emit();
|
|
3571
|
+
return { error: null, api };
|
|
3572
|
+
} catch (e2) {
|
|
3573
|
+
const message = e2 instanceof Error ? e2.message : String(e2);
|
|
3574
|
+
this._error = message;
|
|
3575
|
+
this._status = "error";
|
|
3576
|
+
this.clearConnectedState();
|
|
3577
|
+
this.emit();
|
|
3578
|
+
return { error: message, api: null };
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
async disconnect(wagmi) {
|
|
3582
|
+
if (wagmi && this._connectedVia === "extension") {
|
|
3583
|
+
await wagmi.disconnect().catch(() => {
|
|
3584
|
+
});
|
|
3585
|
+
}
|
|
3586
|
+
if (this._wallet?.disconnect) {
|
|
3587
|
+
await this._wallet.disconnect().catch(() => {
|
|
3588
|
+
});
|
|
3589
|
+
}
|
|
3590
|
+
if (this._connectedVia === "walletconnect") {
|
|
3591
|
+
resetUniversalConnector();
|
|
3592
|
+
}
|
|
3593
|
+
this.fullReset();
|
|
3594
|
+
this.emit();
|
|
3595
|
+
}
|
|
3596
|
+
attachWallet(api) {
|
|
3597
|
+
this.clearConnectedState();
|
|
3598
|
+
this._wallet = api;
|
|
3599
|
+
this._connectedVia = "direct";
|
|
3600
|
+
this._connectedWalletId = null;
|
|
3601
|
+
this._status = "connected";
|
|
3602
|
+
void this.syncIdentityFromWallet();
|
|
3603
|
+
this.emit();
|
|
3604
|
+
}
|
|
3605
|
+
setStatus(s) {
|
|
3606
|
+
this._status = s;
|
|
3607
|
+
this.emit();
|
|
3608
|
+
}
|
|
3609
|
+
addIdentityAddress(address) {
|
|
3610
|
+
this._identity.upsert(address);
|
|
3611
|
+
}
|
|
3612
|
+
resolveAddressForChain(chain) {
|
|
3613
|
+
return this._identity.resolve(chain);
|
|
3614
|
+
}
|
|
3615
|
+
clearProviderCleanup() {
|
|
3616
|
+
this._providerCleanup?.();
|
|
3617
|
+
this._providerCleanup = null;
|
|
3618
|
+
}
|
|
3619
|
+
clearConnectedState() {
|
|
3620
|
+
this.clearProviderCleanup();
|
|
3621
|
+
this._wallet = null;
|
|
3622
|
+
this._connectedVia = null;
|
|
3623
|
+
this._connectedWalletId = null;
|
|
3624
|
+
}
|
|
3625
|
+
fullReset() {
|
|
3626
|
+
this.clearConnectedState();
|
|
3627
|
+
this._address = null;
|
|
3628
|
+
this._identity = new IdentityStore();
|
|
3629
|
+
this._status = "idle";
|
|
3630
|
+
this._error = null;
|
|
3631
|
+
}
|
|
3632
|
+
bindExtensionProviderEvents(target) {
|
|
3633
|
+
if (!target.provider) return;
|
|
3634
|
+
if (target.via === "solana-window") {
|
|
3635
|
+
this._providerCleanup = bindSolanaProviderEvents(target.provider, {
|
|
3636
|
+
onConnect: () => {
|
|
3637
|
+
this._status = "connected";
|
|
3638
|
+
void this.syncIdentityFromWallet(target.meta.id);
|
|
3639
|
+
this.emit();
|
|
3640
|
+
},
|
|
3641
|
+
onAccountChanged: () => {
|
|
3642
|
+
void this.syncIdentityFromWallet(target.meta.id);
|
|
3643
|
+
this.emit();
|
|
3644
|
+
},
|
|
3645
|
+
onDisconnect: () => {
|
|
3646
|
+
this.fullReset();
|
|
3647
|
+
this.triggerExternalDisconnect();
|
|
3648
|
+
this.emit();
|
|
3597
3649
|
}
|
|
3598
|
-
}
|
|
3650
|
+
});
|
|
3651
|
+
return;
|
|
3599
3652
|
}
|
|
3653
|
+
const provider = target.provider;
|
|
3654
|
+
const onAccountsChanged = (accounts) => {
|
|
3655
|
+
const nextAccounts = Array.isArray(accounts) ? accounts : [];
|
|
3656
|
+
if (nextAccounts.length === 0) {
|
|
3657
|
+
this.fullReset();
|
|
3658
|
+
this.triggerExternalDisconnect();
|
|
3659
|
+
this.emit();
|
|
3660
|
+
return;
|
|
3661
|
+
}
|
|
3662
|
+
this._status = "connected";
|
|
3663
|
+
void this.syncIdentityFromWallet(target.meta.id);
|
|
3664
|
+
this.emit();
|
|
3665
|
+
};
|
|
3666
|
+
const onDisconnect = () => {
|
|
3667
|
+
this.fullReset();
|
|
3668
|
+
this.triggerExternalDisconnect();
|
|
3669
|
+
this.emit();
|
|
3670
|
+
};
|
|
3671
|
+
provider.on?.("accountsChanged", onAccountsChanged);
|
|
3672
|
+
provider.on?.("disconnect", onDisconnect);
|
|
3673
|
+
this._providerCleanup = () => {
|
|
3674
|
+
provider.off?.("accountsChanged", onAccountsChanged);
|
|
3675
|
+
provider.off?.("disconnect", onDisconnect);
|
|
3676
|
+
provider.removeListener?.("accountsChanged", onAccountsChanged);
|
|
3677
|
+
provider.removeListener?.("disconnect", onDisconnect);
|
|
3678
|
+
};
|
|
3600
3679
|
}
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3680
|
+
async syncIdentityFromWallet(providerId) {
|
|
3681
|
+
if (!this._wallet) return;
|
|
3682
|
+
try {
|
|
3683
|
+
const address = await this._wallet.getAddress();
|
|
3684
|
+
this._address = address;
|
|
3685
|
+
const chain = this._wallet.ecosystem === "evm" ? { chainId: String(await this._wallet.getChainId()), type: "evm" } : this._wallet.ecosystem === "solana" ? {
|
|
3686
|
+
chainId: "solana-mainnet-beta",
|
|
3687
|
+
networkIdentifier: "solana-mainnet-beta",
|
|
3688
|
+
type: "solana"
|
|
3689
|
+
} : {
|
|
3690
|
+
chainId: "bip122:000000000019d6689c085ae165831e93",
|
|
3691
|
+
networkIdentifier: "bitcoin-mainnet",
|
|
3692
|
+
type: "bitcoin"
|
|
3693
|
+
};
|
|
3694
|
+
const identityAddress = buildWalletIdentityAddress({
|
|
3695
|
+
address,
|
|
3696
|
+
chain,
|
|
3697
|
+
source: "provider",
|
|
3698
|
+
providerId
|
|
3699
|
+
});
|
|
3700
|
+
if (identityAddress) {
|
|
3701
|
+
this._identity.upsert(identityAddress);
|
|
3702
|
+
}
|
|
3703
|
+
} catch {
|
|
3704
|
+
}
|
|
3606
3705
|
}
|
|
3607
|
-
}
|
|
3608
|
-
|
|
3609
|
-
}
|
|
3610
|
-
}
|
|
3611
|
-
return stream();
|
|
3612
|
-
}
|
|
3613
|
-
async function getBalances(chainRef, address) {
|
|
3614
|
-
const reg = await ensureRegistry();
|
|
3615
|
-
const chain = reg.chain(chainRef);
|
|
3616
|
-
if (!chain) return [];
|
|
3617
|
-
const trimmedAddress = address.trim();
|
|
3618
|
-
const validation = validateAddressForChain(trimmedAddress, chain);
|
|
3619
|
-
if (!validation.isValid) return [];
|
|
3620
|
-
const chainKey = chain.networkIdentifier ?? String(chain.chainId ?? chain.id);
|
|
3621
|
-
const cacheKey = [
|
|
3622
|
-
chainKey,
|
|
3623
|
-
trimmedAddress,
|
|
3624
|
-
chain.nativeCurrency?.symbol ?? "",
|
|
3625
|
-
chain.nativeCurrency?.decimals ?? "",
|
|
3626
|
-
normalizeChainType(chain) ?? ""
|
|
3627
|
-
].join(":");
|
|
3628
|
-
const cached = balanceCache.get(cacheKey);
|
|
3629
|
-
if (cached) return cached;
|
|
3630
|
-
const url = `${apiBase()}/v1/data/wallets/${encodeURIComponent(chainKey)}/${trimmedAddress}/balances`;
|
|
3631
|
-
const response = await fetch(url, {
|
|
3632
|
-
method: "GET",
|
|
3633
|
-
credentials: "omit",
|
|
3634
|
-
headers: jsonHeaders()
|
|
3635
|
-
});
|
|
3636
|
-
if (!response.ok) throw new Error(`balances: HTTP ${response.status}`);
|
|
3637
|
-
const json = await response.json();
|
|
3638
|
-
const rows = Array.isArray(json) ? json : json.data ?? [];
|
|
3639
|
-
const normalized = normalizeRows(rows, chain, trimmedAddress, reg);
|
|
3640
|
-
balanceCache.set(cacheKey, normalized);
|
|
3641
|
-
return normalized;
|
|
3642
|
-
}
|
|
3643
|
-
async function getBalancesByAddress(address, opts) {
|
|
3644
|
-
if (opts?.stream && TrustwareConfigStore.get().features.balanceStreaming) {
|
|
3645
|
-
const merged = [];
|
|
3646
|
-
for await (const chunk of getBalancesByAddressStream(address, opts)) {
|
|
3647
|
-
const next = mergeBalanceWrappers(merged, chunk);
|
|
3648
|
-
merged.splice(0, merged.length, ...next);
|
|
3649
|
-
}
|
|
3650
|
-
return merged;
|
|
3651
|
-
}
|
|
3652
|
-
const url = `${apiBase()}/data/balances/${address}`;
|
|
3653
|
-
const r = await rateLimitedFetch(url, {
|
|
3654
|
-
method: "GET",
|
|
3655
|
-
credentials: "omit",
|
|
3656
|
-
headers: jsonHeaders()
|
|
3657
|
-
});
|
|
3658
|
-
if (!r.ok) throw new Error(`balances: HTTP ${r.status}`);
|
|
3659
|
-
const j = await r.json();
|
|
3660
|
-
return Array.isArray(j) ? j : j.results ?? [];
|
|
3661
|
-
}
|
|
3662
|
-
async function* getBalancesByAddressStream(address, opts = {}) {
|
|
3663
|
-
if (!TrustwareConfigStore.get().features.balanceStreaming) {
|
|
3664
|
-
yield await getBalancesByAddress(address);
|
|
3665
|
-
return;
|
|
3666
|
-
}
|
|
3667
|
-
const url = `${apiBase()}/data/balances/${address}?stream=1`;
|
|
3668
|
-
try {
|
|
3669
|
-
const response = await rateLimitedFetch(url, {
|
|
3670
|
-
method: "GET",
|
|
3671
|
-
credentials: "omit",
|
|
3672
|
-
headers: jsonHeaders({
|
|
3673
|
-
Accept: "application/x-ndjson, application/json"
|
|
3674
|
-
}),
|
|
3675
|
-
signal: opts.signal
|
|
3676
|
-
});
|
|
3677
|
-
if (!response.ok) {
|
|
3678
|
-
throw new Error(`balances stream: HTTP ${response.status}`);
|
|
3679
|
-
}
|
|
3680
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
3681
|
-
if (contentType.includes("application/json")) {
|
|
3682
|
-
const payload = await response.json();
|
|
3683
|
-
yield Array.isArray(payload) ? payload : payload.results ?? [];
|
|
3684
|
-
return;
|
|
3685
|
-
}
|
|
3686
|
-
const stream = await parseStreamingBalances(response, address, opts);
|
|
3687
|
-
for await (const chunk of stream) {
|
|
3688
|
-
yield chunk;
|
|
3689
|
-
}
|
|
3690
|
-
} catch (error) {
|
|
3691
|
-
emitBalanceStreamFallback(address, error);
|
|
3692
|
-
yield await getBalancesByAddress(address);
|
|
3706
|
+
};
|
|
3707
|
+
walletManager = new WalletManager();
|
|
3693
3708
|
}
|
|
3694
|
-
}
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3709
|
+
});
|
|
3710
|
+
|
|
3711
|
+
// src/wallets/bridges.ts
|
|
3712
|
+
var init_bridges = __esm({
|
|
3713
|
+
"src/wallets/bridges.ts"() {
|
|
3714
|
+
"use strict";
|
|
3698
3715
|
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
var
|
|
3703
|
-
|
|
3704
|
-
"src/core/balances.ts"() {
|
|
3716
|
+
});
|
|
3717
|
+
|
|
3718
|
+
// src/wallets/index.ts
|
|
3719
|
+
var init_wallets = __esm({
|
|
3720
|
+
"src/wallets/index.ts"() {
|
|
3705
3721
|
"use strict";
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
balanceCache = /* @__PURE__ */ new Map();
|
|
3722
|
+
init_bridges();
|
|
3723
|
+
init_connect();
|
|
3724
|
+
init_manager();
|
|
3725
|
+
init_adapters();
|
|
3726
|
+
init_solana();
|
|
3712
3727
|
}
|
|
3713
3728
|
});
|
|
3714
3729
|
|
|
@@ -3758,6 +3773,7 @@ async function buildRoute(body, signal) {
|
|
|
3758
3773
|
const txReq = route?.execution?.transaction;
|
|
3759
3774
|
const actions = Array.isArray(route?.steps) ? route.steps : [];
|
|
3760
3775
|
const estimate = route?.estimate ?? {};
|
|
3776
|
+
const sponsorship = json?.data?.sponsorship ?? json?.sponsorship ?? void 0;
|
|
3761
3777
|
const finalExchangeRate = {
|
|
3762
3778
|
fromAmountUSD: estimate.fromAmountUsd,
|
|
3763
3779
|
toAmountMinUSD: estimate?.toAmountMinUsd ?? estimate?.toAmountUsd
|
|
@@ -3765,7 +3781,7 @@ async function buildRoute(body, signal) {
|
|
|
3765
3781
|
if (!txReq?.data) {
|
|
3766
3782
|
throw new Error("Invalid route: missing transaction data");
|
|
3767
3783
|
}
|
|
3768
|
-
return { intentId, txReq, actions, finalExchangeRate, route };
|
|
3784
|
+
return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
|
|
3769
3785
|
}
|
|
3770
3786
|
async function buildDepositAddress(body, signal) {
|
|
3771
3787
|
const cfg = TrustwareConfigStore.get();
|
|
@@ -3809,13 +3825,16 @@ async function buildDepositAddress(body, signal) {
|
|
|
3809
3825
|
route
|
|
3810
3826
|
};
|
|
3811
3827
|
}
|
|
3812
|
-
async function submitReceipt(intentId, txHash) {
|
|
3828
|
+
async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
|
|
3813
3829
|
const r = await rateLimitedFetch(
|
|
3814
3830
|
`${apiBase()}/v1/route-intent/${intentId}/receipt`,
|
|
3815
3831
|
{
|
|
3816
3832
|
method: "POST",
|
|
3817
3833
|
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
3818
|
-
body: JSON.stringify({
|
|
3834
|
+
body: JSON.stringify({
|
|
3835
|
+
txHash,
|
|
3836
|
+
...sponsorshipRequestId ? { sponsorshipRequestId } : {}
|
|
3837
|
+
})
|
|
3819
3838
|
}
|
|
3820
3839
|
);
|
|
3821
3840
|
await assertOK(r);
|
|
@@ -4571,7 +4590,11 @@ function resolveConfig(input) {
|
|
|
4571
4590
|
const features = {
|
|
4572
4591
|
tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
|
|
4573
4592
|
balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
|
|
4574
|
-
shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4
|
|
4593
|
+
shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
|
|
4594
|
+
swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
|
|
4595
|
+
swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
|
|
4596
|
+
swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
|
|
4597
|
+
swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
|
|
4575
4598
|
};
|
|
4576
4599
|
return {
|
|
4577
4600
|
apiKey: input.apiKey,
|
|
@@ -4680,6 +4703,7 @@ var init_store = __esm({
|
|
|
4680
4703
|
});
|
|
4681
4704
|
|
|
4682
4705
|
// src/core/tx.ts
|
|
4706
|
+
import { keccak256 } from "viem";
|
|
4683
4707
|
function backendChainId(chain, fallback) {
|
|
4684
4708
|
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
4685
4709
|
return String(preferred ?? fallback ?? "");
|
|
@@ -4702,6 +4726,12 @@ async function sendRouteTransaction(b, fallbackChainId) {
|
|
|
4702
4726
|
const data = txReq.data;
|
|
4703
4727
|
const value = txReq.value ? BigInt(txReq.value) : 0n;
|
|
4704
4728
|
const target = Number(txReq.chainId ?? fallbackChainId);
|
|
4729
|
+
let validatedSponsorship;
|
|
4730
|
+
if (b.sponsorship) {
|
|
4731
|
+
if (keccak256(data) === b.sponsorship.callDataHash) {
|
|
4732
|
+
validatedSponsorship = b.sponsorship;
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4705
4735
|
if (Number.isFinite(target)) {
|
|
4706
4736
|
const current = await w.getChainId();
|
|
4707
4737
|
if (current !== target) {
|
|
@@ -4733,7 +4763,10 @@ async function sendRouteTransaction(b, fallbackChainId) {
|
|
|
4733
4763
|
to,
|
|
4734
4764
|
data,
|
|
4735
4765
|
value,
|
|
4736
|
-
chainId: Number.isFinite(target) ? target : void 0
|
|
4766
|
+
chainId: Number.isFinite(target) ? target : void 0,
|
|
4767
|
+
...validatedSponsorship ? {
|
|
4768
|
+
paymasterAndData: validatedSponsorship.paymasterAndData
|
|
4769
|
+
} : {}
|
|
4737
4770
|
});
|
|
4738
4771
|
return response.hash;
|
|
4739
4772
|
}
|