@trustware/sdk-staging 1.1.12-staging.5 → 1.1.12-staging.7
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 +100 -16
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/core.cjs +166 -59
- package/dist/core.cjs.map +1 -1
- package/dist/core.mjs +166 -59
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +254 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +254 -114
- package/dist/index.mjs.map +1 -1
- package/dist/smart-account.cjs +1 -1
- package/dist/smart-account.mjs +1 -1
- package/dist/wallet.cjs +54 -45
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.mjs +54 -45
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +253 -111
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +253 -111
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,20 +39,32 @@ The current widget flow is:
|
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
42
|
-
Supports React `18.2+` and `19`.
|
|
43
|
-
|
|
44
42
|
```bash
|
|
45
43
|
npm install @trustware/sdk
|
|
46
44
|
# or
|
|
47
45
|
pnpm add @trustware/sdk
|
|
48
46
|
```
|
|
49
47
|
|
|
48
|
+
Supports React `18.2+` and `19`.
|
|
49
|
+
|
|
50
50
|
## Main Exports
|
|
51
51
|
|
|
52
52
|
- `TrustwareProvider`
|
|
53
|
+
- `useTrustware`
|
|
53
54
|
- `TrustwareWidget`
|
|
54
55
|
- `Trustware`
|
|
55
|
-
- `
|
|
56
|
+
- `TrustwareError`
|
|
57
|
+
- `RateLimitError`
|
|
58
|
+
- `assertValidPostHook`
|
|
59
|
+
- `walletManager`
|
|
60
|
+
- `useWalletDetection`
|
|
61
|
+
- `useWalletInfo`
|
|
62
|
+
- `connectDetectedWallet`
|
|
63
|
+
- `WagmiBridge`
|
|
64
|
+
- `useWagmi`
|
|
65
|
+
- `useEIP1193`
|
|
66
|
+
- `WALLETS`
|
|
67
|
+
- `./identity`, `./validation/address`, `./types`, `./constants`
|
|
56
68
|
|
|
57
69
|
## Quick Start
|
|
58
70
|
|
|
@@ -102,6 +114,7 @@ type TrustwareConfigOptions = {
|
|
|
102
114
|
toChain: string;
|
|
103
115
|
toToken: string;
|
|
104
116
|
fromToken?: string;
|
|
117
|
+
fromChain?: string;
|
|
105
118
|
fromAddress?: string;
|
|
106
119
|
toAddress?: string;
|
|
107
120
|
defaultSlippage?: number;
|
|
@@ -156,10 +169,14 @@ type TrustwareConfigOptions = {
|
|
|
156
169
|
- `routes.toChain`: destination chain key or chain id string.
|
|
157
170
|
- `routes.toToken`: destination token address or registry token identifier.
|
|
158
171
|
- `routes.fromToken`: optional source token preference.
|
|
172
|
+
- `routes.fromChain`: optional source chain preference.
|
|
159
173
|
- `routes.fromAddress`: optional source wallet override.
|
|
160
174
|
- `routes.toAddress`: optional destination address override.
|
|
161
175
|
- `routes.defaultSlippage`: optional slippage percentage. Defaults to `1`.
|
|
162
176
|
|
|
177
|
+
Chain and token fields are strings, including numeric chain ids — `"8453"`, not
|
|
178
|
+
`8453`.
|
|
179
|
+
|
|
163
180
|
### Route Options
|
|
164
181
|
|
|
165
182
|
- `routes.options.routeRefreshMs`: auto-refresh cadence for route previews.
|
|
@@ -169,14 +186,15 @@ type TrustwareConfigOptions = {
|
|
|
169
186
|
|
|
170
187
|
### Other Config Groups
|
|
171
188
|
|
|
172
|
-
- `autoDetectProvider`: enables Trustware-managed wallet discovery.
|
|
189
|
+
- `autoDetectProvider`: enables Trustware-managed wallet discovery. Defaults to
|
|
190
|
+
`false` — set it to `true` if you are not attaching a wallet yourself.
|
|
173
191
|
- `theme`: widget color mode — `"light" | "dark" | "system"` (default
|
|
174
192
|
`"system"`). Switch it at runtime with `Trustware.setTheme("dark")`.
|
|
175
193
|
- `messages`: top-level copy overrides.
|
|
176
|
-
- `retry`:
|
|
194
|
+
- `retry`: rate-limit observability callbacks — see [Rate Limiting](#rate-limiting).
|
|
177
195
|
- `walletConnect`: WalletConnect overrides.
|
|
178
196
|
- `features`: feature rollout controls, including swap-mode token selection constraints.
|
|
179
|
-
- `onError`, `onSuccess`, `onEvent`: lifecycle callbacks.
|
|
197
|
+
- `onError`, `onSuccess`, `onEvent`: lifecycle callbacks — see [Events](#events).
|
|
180
198
|
|
|
181
199
|
## Widget Usage Patterns
|
|
182
200
|
|
|
@@ -204,7 +222,7 @@ Use this mode when:
|
|
|
204
222
|
|
|
205
223
|
### 2. Widget With a Host-Managed Wallet
|
|
206
224
|
|
|
207
|
-
Use this when your app already controls wallet connection through Wagmi
|
|
225
|
+
Use this when your app already controls wallet connection through Wagmi or another adapter.
|
|
208
226
|
|
|
209
227
|
```tsx
|
|
210
228
|
import { useMemo } from "react";
|
|
@@ -250,11 +268,9 @@ Use this mode when:
|
|
|
250
268
|
|
|
251
269
|
```tsx
|
|
252
270
|
import { useRef } from "react";
|
|
253
|
-
import {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
type TrustwareWidgetRef,
|
|
257
|
-
} from "@trustware/sdk";
|
|
271
|
+
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
|
|
272
|
+
// The widget's prop and ref types live on the widget entry, not the root barrel.
|
|
273
|
+
import type { TrustwareWidgetRef } from "@trustware/sdk/react";
|
|
258
274
|
|
|
259
275
|
export function ControlledWidget() {
|
|
260
276
|
const widgetRef = useRef<TrustwareWidgetRef>(null);
|
|
@@ -277,12 +293,17 @@ export function ControlledWidget() {
|
|
|
277
293
|
|
|
278
294
|
Current widget props:
|
|
279
295
|
|
|
280
|
-
- `theme?: "light" | "dark" | "system"`
|
|
296
|
+
- `theme?: "light" | "dark" | "system"` — initial mode only; `Trustware.setTheme()` drives it afterwards
|
|
281
297
|
- `initialStep?: "home" | "select-token" | "crypto-pay" | "processing" | "success" | "error"`
|
|
282
|
-
- `defaultOpen?: boolean`
|
|
298
|
+
- `defaultOpen?: boolean` — defaults to `true`, which is what you want for inline usage
|
|
299
|
+
- `style?: React.CSSProperties` — merged onto the widget shell
|
|
283
300
|
- `onOpen?: () => void`
|
|
284
301
|
- `onClose?: () => void`
|
|
285
|
-
- `showThemeToggle?: boolean`
|
|
302
|
+
- `showThemeToggle?: boolean` — defaults to `true`
|
|
303
|
+
|
|
304
|
+
And the ref (`TrustwareWidgetRef`): `open()`, `close()`, `isOpen()`. `close()`
|
|
305
|
+
asks for confirmation first if a transaction is in flight, so it is safe to wire
|
|
306
|
+
straight to a dismiss button.
|
|
286
307
|
|
|
287
308
|
### 4. Headless Core API
|
|
288
309
|
|
|
@@ -355,10 +376,73 @@ Trustware.setDestinationAddress("0xDestination...");
|
|
|
355
376
|
|
|
356
377
|
## Headless / Core Notes
|
|
357
378
|
|
|
379
|
+
`Trustware` is a plain object, not a class or an event emitter — there is no
|
|
380
|
+
`Trustware.on()`. Events reach you through `config.onEvent`.
|
|
381
|
+
|
|
382
|
+
**Lifecycle and config**
|
|
383
|
+
|
|
384
|
+
- `Trustware.init(config)` loads the config and validates the API key once.
|
|
358
385
|
- `Trustware.getConfig()` returns the resolved config.
|
|
359
|
-
- `Trustware.
|
|
386
|
+
- `Trustware.setTheme(mode)` / `getTheme()` switch the widget's color mode at runtime.
|
|
387
|
+
- `Trustware.setDestinationAddress/Chain/Token()` update the route defaults in place.
|
|
388
|
+
|
|
389
|
+
**Wallets**
|
|
390
|
+
|
|
360
391
|
- `Trustware.useWallet(wallet)` attaches a wallet imperatively.
|
|
392
|
+
- `Trustware.getWallet()` and `Trustware.getAddress()` expose the active wallet.
|
|
361
393
|
- `Trustware.autoDetect()` can still be used if you want SDK-managed discovery outside the widget.
|
|
394
|
+
- `Trustware.getIdentity()` / `resolveAddressForChain()` / `addIdentityAddress()` handle
|
|
395
|
+
multi-chain identities, so an EVM address and a Solana address can belong to one user.
|
|
396
|
+
|
|
397
|
+
**Routes, status and balances**
|
|
398
|
+
|
|
399
|
+
- `buildRoute`, `buildDepositAddress` — build a route, or an address to deposit into.
|
|
400
|
+
- `submitReceipt`, `submitStepReceipt`, `sendRouteTransaction`, `runTopUp` — execution.
|
|
401
|
+
- `getStatus`, `pollStatus` — read a transaction through to a terminal state.
|
|
402
|
+
- `getBalances`, `getBalancesByAddress`, `getBalancesByAddressStream`.
|
|
403
|
+
- `useChains`, `useTokens` — React hooks over the chain and token registries.
|
|
404
|
+
- `validateAddressForChain`, `validateRouteAddresses` — check addresses before you spend a request.
|
|
405
|
+
|
|
406
|
+
There is no `getQuote`: the estimate is part of the route, on
|
|
407
|
+
`route.route?.estimate` and `route.finalExchangeRate`.
|
|
408
|
+
|
|
409
|
+
### Provider Context
|
|
410
|
+
|
|
411
|
+
`useTrustware()` returns `{ status, errors, core, emitError, emitSuccess,
|
|
412
|
+
emitEvent, revalidate }`. `status` is `"idle" | "initializing" | "ready" |
|
|
413
|
+
"error"` — gate anything that calls the API on `"ready"`. `core` is the same
|
|
414
|
+
`Trustware` facade, handed to you so you don't have to import it separately, and
|
|
415
|
+
`revalidate()` re-runs init after a failure (an API key arriving late, for
|
|
416
|
+
instance).
|
|
417
|
+
|
|
418
|
+
## Smart Accounts
|
|
419
|
+
|
|
420
|
+
For ERC-4337 flows, `@trustware/sdk/smart-account` sends a route as a user
|
|
421
|
+
operation rather than a wallet transaction:
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
import {
|
|
425
|
+
createTrustwareSmartAccountClient,
|
|
426
|
+
sendRouteAsUserOperation,
|
|
427
|
+
} from "@trustware/sdk/smart-account";
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
It is a separate entry point on purpose — 65 KB gzipped, and nothing pulls it in
|
|
431
|
+
unless you import it.
|
|
432
|
+
|
|
433
|
+
## Events
|
|
434
|
+
|
|
435
|
+
`config.onEvent` receives a discriminated `TrustwareEvent`:
|
|
436
|
+
|
|
437
|
+
- `error`
|
|
438
|
+
- `transaction_started`
|
|
439
|
+
- `transaction_success`
|
|
440
|
+
- `wallet_connected`
|
|
441
|
+
- `token_page_loaded`
|
|
442
|
+
- `token_page_error`
|
|
443
|
+
- `balance_stream_chunk`
|
|
444
|
+
- `balance_stream_fallback`
|
|
445
|
+
- `swap_route_changed`
|
|
362
446
|
|
|
363
447
|
## Rate Limiting
|
|
364
448
|
|
package/dist/constants.cjs
CHANGED
|
@@ -30,7 +30,7 @@ __export(constants_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(constants_exports);
|
|
32
32
|
var SDK_NAME = "@trustware/sdk";
|
|
33
|
-
var SDK_VERSION = "1.1.12-staging.
|
|
33
|
+
var SDK_VERSION = "1.1.12-staging.7";
|
|
34
34
|
var API_ROOT = "https://bv-staging-api.trustware.io";
|
|
35
35
|
var GTM_ID = "GTM-TZDGNCXB";
|
|
36
36
|
var API_PREFIX = "/api";
|
package/dist/constants.mjs
CHANGED
package/dist/core.cjs
CHANGED
|
@@ -83,7 +83,7 @@ var init_constants = __esm({
|
|
|
83
83
|
"src/constants.ts"() {
|
|
84
84
|
"use strict";
|
|
85
85
|
SDK_NAME = "@trustware/sdk";
|
|
86
|
-
SDK_VERSION = "1.1.12-staging.
|
|
86
|
+
SDK_VERSION = "1.1.12-staging.7";
|
|
87
87
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
88
88
|
API_PREFIX = "/api";
|
|
89
89
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -307,6 +307,104 @@ var init_chains = __esm({
|
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
+
// src/wallets/chainParams.ts
|
|
311
|
+
function chainParamsFor(chainId) {
|
|
312
|
+
return registered.get(chainId) ?? BUILTIN_CHAIN_PARAMS[chainId];
|
|
313
|
+
}
|
|
314
|
+
function registerChainParams(chainId, params) {
|
|
315
|
+
registered.set(chainId, params);
|
|
316
|
+
}
|
|
317
|
+
function usableRpcUrls(chain) {
|
|
318
|
+
const candidates = [
|
|
319
|
+
...Array.isArray(chain.rpcList) ? chain.rpcList : [],
|
|
320
|
+
...chain.rpc ? [chain.rpc] : []
|
|
321
|
+
];
|
|
322
|
+
const seen = /* @__PURE__ */ new Set();
|
|
323
|
+
const out = [];
|
|
324
|
+
for (const raw of candidates) {
|
|
325
|
+
const url = String(raw ?? "").trim();
|
|
326
|
+
if (!/^https?:\/\//i.test(url) || seen.has(url)) continue;
|
|
327
|
+
seen.add(url);
|
|
328
|
+
out.push(url);
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
function chainParamsFromChainDef(chain) {
|
|
333
|
+
const chainType = String(
|
|
334
|
+
chain.chainType ?? chain.type ?? "evm"
|
|
335
|
+
).toLowerCase();
|
|
336
|
+
if (chainType !== "evm") return void 0;
|
|
337
|
+
const numericId = Number(chain.chainId ?? chain.id);
|
|
338
|
+
if (!Number.isSafeInteger(numericId) || numericId <= 0) return void 0;
|
|
339
|
+
const rpcUrls = usableRpcUrls(chain);
|
|
340
|
+
if (rpcUrls.length === 0) return void 0;
|
|
341
|
+
const native = chain.nativeCurrency;
|
|
342
|
+
const symbol = String(native?.symbol ?? "").trim();
|
|
343
|
+
if (!symbol) return void 0;
|
|
344
|
+
const decimals = Number(native?.decimals);
|
|
345
|
+
const chainName = String(
|
|
346
|
+
chain.networkName ?? chain.axelarChainName ?? chain.networkIdentifier ?? ""
|
|
347
|
+
).trim();
|
|
348
|
+
const explorers = (chain.blockExplorerUrls ?? []).filter(
|
|
349
|
+
(u) => /^https?:\/\//i.test(String(u ?? ""))
|
|
350
|
+
);
|
|
351
|
+
return {
|
|
352
|
+
chainIdHex: `0x${numericId.toString(16)}`,
|
|
353
|
+
chainName: chainName || `Chain ${numericId}`,
|
|
354
|
+
rpcUrls,
|
|
355
|
+
nativeCurrency: {
|
|
356
|
+
name: String(native?.name ?? symbol),
|
|
357
|
+
symbol,
|
|
358
|
+
decimals: Number.isFinite(decimals) ? decimals : 18
|
|
359
|
+
},
|
|
360
|
+
...explorers.length > 0 ? { blockExplorerUrls: explorers } : {}
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
var BUILTIN_CHAIN_PARAMS, registered;
|
|
364
|
+
var init_chainParams = __esm({
|
|
365
|
+
"src/wallets/chainParams.ts"() {
|
|
366
|
+
"use strict";
|
|
367
|
+
BUILTIN_CHAIN_PARAMS = {
|
|
368
|
+
1: {
|
|
369
|
+
chainIdHex: "0x1",
|
|
370
|
+
chainName: "Ethereum",
|
|
371
|
+
rpcUrls: ["https://eth.llamarpc.com"],
|
|
372
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
373
|
+
blockExplorerUrls: ["https://etherscan.io"]
|
|
374
|
+
},
|
|
375
|
+
137: {
|
|
376
|
+
chainIdHex: "0x89",
|
|
377
|
+
chainName: "Polygon",
|
|
378
|
+
rpcUrls: ["https://polygon-rpc.com"],
|
|
379
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
380
|
+
blockExplorerUrls: ["https://polygonscan.com"]
|
|
381
|
+
},
|
|
382
|
+
8453: {
|
|
383
|
+
chainIdHex: "0x2105",
|
|
384
|
+
chainName: "Base",
|
|
385
|
+
rpcUrls: ["https://mainnet.base.org"],
|
|
386
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
387
|
+
blockExplorerUrls: ["https://basescan.org"]
|
|
388
|
+
},
|
|
389
|
+
42161: {
|
|
390
|
+
chainIdHex: "0xa4b1",
|
|
391
|
+
chainName: "Arbitrum One",
|
|
392
|
+
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
393
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
394
|
+
blockExplorerUrls: ["https://arbiscan.io"]
|
|
395
|
+
},
|
|
396
|
+
43114: {
|
|
397
|
+
chainIdHex: "0xa86a",
|
|
398
|
+
chainName: "Avalanche C-Chain",
|
|
399
|
+
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
400
|
+
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
401
|
+
blockExplorerUrls: ["https://snowtrace.io"]
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
registered = /* @__PURE__ */ new Map();
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
310
408
|
// src/registry.ts
|
|
311
409
|
function getChainAliases(chain) {
|
|
312
410
|
const values = [
|
|
@@ -351,6 +449,7 @@ var init_registry = __esm({
|
|
|
351
449
|
"use strict";
|
|
352
450
|
init_store();
|
|
353
451
|
init_chains();
|
|
452
|
+
init_chainParams();
|
|
354
453
|
NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
355
454
|
PAGE_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
356
455
|
PAGE_CACHE_LIMIT = 100;
|
|
@@ -429,6 +528,10 @@ var init_registry = __esm({
|
|
|
429
528
|
for (const alias of getChainAliases(normalized)) {
|
|
430
529
|
this._chainAliases.set(alias, canonicalKey);
|
|
431
530
|
}
|
|
531
|
+
const addParams = chainParamsFromChainDef(normalized);
|
|
532
|
+
if (addParams) {
|
|
533
|
+
registerChainParams(Number(normalized.chainId ?? canonical), addParams);
|
|
534
|
+
}
|
|
432
535
|
}
|
|
433
536
|
storeTokenForAlias(chainKey, token) {
|
|
434
537
|
const key = tokenKey(token);
|
|
@@ -2006,7 +2109,7 @@ var init_balances = __esm({
|
|
|
2006
2109
|
|
|
2007
2110
|
// src/wallets/eipWallets.ts
|
|
2008
2111
|
async function addThenSwitch(eth, chainId) {
|
|
2009
|
-
const p =
|
|
2112
|
+
const p = chainParamsFor(chainId);
|
|
2010
2113
|
if (!p) throw new Error(`Unknown chain ${chainId} (no params to add)`);
|
|
2011
2114
|
await eth.request({ method: "wallet_addEthereumChain", params: [p] });
|
|
2012
2115
|
await eth.request({
|
|
@@ -2034,7 +2137,7 @@ function useEIP1193(eth) {
|
|
|
2034
2137
|
async switchChain(chainId) {
|
|
2035
2138
|
if (switching) return;
|
|
2036
2139
|
switching = true;
|
|
2037
|
-
const hex =
|
|
2140
|
+
const hex = chainParamsFor(chainId)?.chainIdHex ?? `0x${chainId.toString(16)}`;
|
|
2038
2141
|
try {
|
|
2039
2142
|
await eth.request({
|
|
2040
2143
|
method: "wallet_switchEthereumChain",
|
|
@@ -2043,7 +2146,6 @@ function useEIP1193(eth) {
|
|
|
2043
2146
|
} catch (e2) {
|
|
2044
2147
|
if (e2?.code === 4902) {
|
|
2045
2148
|
await addThenSwitch(eth, chainId);
|
|
2046
|
-
} else if (e2?.code === 4001) {
|
|
2047
2149
|
} else {
|
|
2048
2150
|
throw e2;
|
|
2049
2151
|
}
|
|
@@ -2054,47 +2156,10 @@ function useEIP1193(eth) {
|
|
|
2054
2156
|
request: (args) => eth.request(args)
|
|
2055
2157
|
};
|
|
2056
2158
|
}
|
|
2057
|
-
var CHAIN_PARAMS;
|
|
2058
2159
|
var init_eipWallets = __esm({
|
|
2059
2160
|
"src/wallets/eipWallets.ts"() {
|
|
2060
2161
|
"use strict";
|
|
2061
|
-
|
|
2062
|
-
1: {
|
|
2063
|
-
chainIdHex: "0x1",
|
|
2064
|
-
chainName: "Ethereum",
|
|
2065
|
-
rpcUrls: ["https://eth.llamarpc.com"],
|
|
2066
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2067
|
-
blockExplorerUrls: ["https://etherscan.io"]
|
|
2068
|
-
},
|
|
2069
|
-
137: {
|
|
2070
|
-
chainIdHex: "0x89",
|
|
2071
|
-
chainName: "Polygon",
|
|
2072
|
-
rpcUrls: ["https://polygon-rpc.com"],
|
|
2073
|
-
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
2074
|
-
blockExplorerUrls: ["https://polygonscan.com"]
|
|
2075
|
-
},
|
|
2076
|
-
8453: {
|
|
2077
|
-
chainIdHex: "0x2105",
|
|
2078
|
-
chainName: "Base",
|
|
2079
|
-
rpcUrls: ["https://mainnet.base.org"],
|
|
2080
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2081
|
-
blockExplorerUrls: ["https://basescan.org"]
|
|
2082
|
-
},
|
|
2083
|
-
42161: {
|
|
2084
|
-
chainIdHex: "0xa4b1",
|
|
2085
|
-
chainName: "Arbitrum One",
|
|
2086
|
-
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
2087
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2088
|
-
blockExplorerUrls: ["https://arbiscan.io"]
|
|
2089
|
-
},
|
|
2090
|
-
43114: {
|
|
2091
|
-
chainIdHex: "0xa86a",
|
|
2092
|
-
chainName: "Avalanche C-Chain",
|
|
2093
|
-
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
2094
|
-
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
2095
|
-
blockExplorerUrls: ["https://snowtrace.io"]
|
|
2096
|
-
}
|
|
2097
|
-
};
|
|
2162
|
+
init_chainParams();
|
|
2098
2163
|
}
|
|
2099
2164
|
});
|
|
2100
2165
|
|
|
@@ -6319,6 +6384,25 @@ function backendChainId(chain, fallback) {
|
|
|
6319
6384
|
function sleep2(ms) {
|
|
6320
6385
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6321
6386
|
}
|
|
6387
|
+
async function ensureWalletOnChain(wallet, target) {
|
|
6388
|
+
if (!Number.isSafeInteger(target) || target <= 0) {
|
|
6389
|
+
throw new Error(`Invalid chain id: ${target}`);
|
|
6390
|
+
}
|
|
6391
|
+
if (await wallet.getChainId() === target) return;
|
|
6392
|
+
let switchError;
|
|
6393
|
+
try {
|
|
6394
|
+
await wallet.switchChain(target);
|
|
6395
|
+
} catch (e2) {
|
|
6396
|
+
switchError = e2;
|
|
6397
|
+
}
|
|
6398
|
+
if (await wallet.getChainId() === target) return;
|
|
6399
|
+
if (switchError && isUserRejected(switchError)) {
|
|
6400
|
+
throw switchError;
|
|
6401
|
+
}
|
|
6402
|
+
throw new Error(
|
|
6403
|
+
`Wallet is on the wrong network. Switch to chain ${target} and try again.`
|
|
6404
|
+
);
|
|
6405
|
+
}
|
|
6322
6406
|
async function sendEvmTx(w, tx) {
|
|
6323
6407
|
if (w.type === "eip1193") {
|
|
6324
6408
|
const from = await w.getAddress();
|
|
@@ -6345,19 +6429,37 @@ async function sendEvmTx(w, tx) {
|
|
|
6345
6429
|
});
|
|
6346
6430
|
return response.hash;
|
|
6347
6431
|
}
|
|
6348
|
-
async function
|
|
6349
|
-
const
|
|
6350
|
-
|
|
6432
|
+
async function waitForEvmTxConfirmation(chainId, txHash, label, options = {}) {
|
|
6433
|
+
const {
|
|
6434
|
+
readStatus = getEVMTxStatus,
|
|
6435
|
+
timeoutMs = 12e4,
|
|
6436
|
+
intervalMs = 2e3,
|
|
6437
|
+
notFoundGraceMs = NOT_FOUND_GRACE_MS
|
|
6438
|
+
} = options;
|
|
6351
6439
|
const started = Date.now();
|
|
6440
|
+
let notFoundSince = null;
|
|
6352
6441
|
while (Date.now() - started < timeoutMs) {
|
|
6353
|
-
const status = await
|
|
6442
|
+
const status = await readStatus({ chainId, txHash });
|
|
6354
6443
|
if (status.status === "success") return;
|
|
6355
6444
|
if (status.status === "reverted") {
|
|
6356
|
-
throw new Error(
|
|
6445
|
+
throw new Error(`${label} transaction reverted`);
|
|
6446
|
+
}
|
|
6447
|
+
if (status.status === "not_found") {
|
|
6448
|
+
notFoundSince ?? (notFoundSince = Date.now());
|
|
6449
|
+
if (Date.now() - notFoundSince >= notFoundGraceMs) {
|
|
6450
|
+
throw new Error(
|
|
6451
|
+
`${label} transaction ${txHash} was not found on chain ${chainId}. It may have been sent on a different network \u2014 check your wallet's selected network and try again.`
|
|
6452
|
+
);
|
|
6453
|
+
}
|
|
6454
|
+
} else {
|
|
6455
|
+
notFoundSince = null;
|
|
6357
6456
|
}
|
|
6358
6457
|
await sleep2(intervalMs);
|
|
6359
6458
|
}
|
|
6360
|
-
throw new Error(
|
|
6459
|
+
throw new Error(`Timed out waiting for ${label.toLowerCase()} confirmation`);
|
|
6460
|
+
}
|
|
6461
|
+
function waitForApprovalConfirmation(chainId, txHash, options) {
|
|
6462
|
+
return waitForEvmTxConfirmation(chainId, txHash, "Approval", options);
|
|
6361
6463
|
}
|
|
6362
6464
|
function requiredApprovalAmount(planAmountWei, routeAmountWei) {
|
|
6363
6465
|
if (planAmountWei >= UNLIMITED_APPROVAL_FLOOR && routeAmountWei !== void 0 && routeAmountWei > 0n) {
|
|
@@ -6397,17 +6499,22 @@ async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmo
|
|
|
6397
6499
|
functionName: "approve",
|
|
6398
6500
|
args: [spender, amountWei]
|
|
6399
6501
|
});
|
|
6502
|
+
const approvalChainId = Number(chainId);
|
|
6503
|
+
if (!Number.isSafeInteger(approvalChainId) || approvalChainId <= 0) {
|
|
6504
|
+
throw new Error(`Approval has an invalid chain id: ${chainId}`);
|
|
6505
|
+
}
|
|
6506
|
+
await ensureWalletOnChain(w, approvalChainId);
|
|
6400
6507
|
const hash = await sendEvmTx(w, {
|
|
6401
6508
|
to: tokenAddress,
|
|
6402
6509
|
data,
|
|
6403
6510
|
value: 0n,
|
|
6404
|
-
chainId:
|
|
6511
|
+
chainId: approvalChainId
|
|
6405
6512
|
});
|
|
6406
6513
|
if (intentId) {
|
|
6407
6514
|
void submitStepReceipt(intentId, stepIndex, hash).catch(() => {
|
|
6408
6515
|
});
|
|
6409
6516
|
}
|
|
6410
|
-
await
|
|
6517
|
+
await waitForApprovalConfirmation(chainId, hash);
|
|
6411
6518
|
}
|
|
6412
6519
|
}
|
|
6413
6520
|
function isUserRejected(e2) {
|
|
@@ -6434,15 +6541,14 @@ async function sendRouteTransaction(b, fallbackChainId, options) {
|
|
|
6434
6541
|
validatedSponsorship = b.sponsorship;
|
|
6435
6542
|
}
|
|
6436
6543
|
}
|
|
6437
|
-
if (Number.
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
}
|
|
6444
|
-
}
|
|
6544
|
+
if (!Number.isSafeInteger(target) || target <= 0) {
|
|
6545
|
+
throw new Error(
|
|
6546
|
+
`Route is missing a usable chain id (got ${String(
|
|
6547
|
+
txReq.chainId ?? fallbackChainId
|
|
6548
|
+
)}).`
|
|
6549
|
+
);
|
|
6445
6550
|
}
|
|
6551
|
+
await ensureWalletOnChain(w, target);
|
|
6446
6552
|
if (!validatedSponsorship && !options?.approvalsEnsured) {
|
|
6447
6553
|
await ensureApprovals(
|
|
6448
6554
|
w,
|
|
@@ -6548,7 +6654,7 @@ async function runTopUp(params) {
|
|
|
6548
6654
|
}
|
|
6549
6655
|
}
|
|
6550
6656
|
}
|
|
6551
|
-
var import_viem2, erc20ApproveAbi, UNLIMITED_APPROVAL_FLOOR;
|
|
6657
|
+
var import_viem2, erc20ApproveAbi, NOT_FOUND_GRACE_MS, UNLIMITED_APPROVAL_FLOOR;
|
|
6552
6658
|
var init_tx = __esm({
|
|
6553
6659
|
"src/core/tx.ts"() {
|
|
6554
6660
|
"use strict";
|
|
@@ -6559,6 +6665,7 @@ var init_tx = __esm({
|
|
|
6559
6665
|
erc20ApproveAbi = (0, import_viem2.parseAbi)([
|
|
6560
6666
|
"function approve(address spender, uint256 amount) returns (bool)"
|
|
6561
6667
|
]);
|
|
6668
|
+
NOT_FOUND_GRACE_MS = 2e4;
|
|
6562
6669
|
UNLIMITED_APPROVAL_FLOOR = 1n << 255n;
|
|
6563
6670
|
}
|
|
6564
6671
|
});
|