@trustware/sdk-staging 1.1.9-staging.6 → 1.1.10-staging.0

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.
Files changed (40) hide show
  1. package/LICENSE +5 -4
  2. package/README.md +32 -1
  3. package/THIRD_PARTY_NOTICES.md +118 -0
  4. package/dist/constants.cjs +1 -1
  5. package/dist/constants.mjs +1 -1
  6. package/dist/{core-BTPkApRH.d.cts → core-B7Ez-5-r.d.cts} +3 -2
  7. package/dist/{core-2oZuxC1J.d.ts → core-BPLiD1UG.d.ts} +3 -2
  8. package/dist/core.cjs +246 -48
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/core.d.cts +2 -2
  11. package/dist/core.d.ts +2 -2
  12. package/dist/core.mjs +247 -48
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/index.cjs +300 -76
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +5 -5
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.mjs +325 -103
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{manager-BMO1O-cW.d.ts → manager-B6NNV-E_.d.ts} +129 -18
  21. package/dist/{manager-BZwbtOyf.d.cts → manager-BwjyFjjz.d.cts} +129 -18
  22. package/dist/{detect-B8xXLwHK.d.ts → metadata-BiTMMvlY.d.ts} +5 -2
  23. package/dist/{detect-C8xpZRrL.d.cts → metadata-HCflXcsF.d.cts} +5 -2
  24. package/dist/smart-account.cjs +117 -39
  25. package/dist/smart-account.cjs.map +1 -1
  26. package/dist/smart-account.d.cts +235 -222
  27. package/dist/smart-account.d.ts +235 -222
  28. package/dist/smart-account.mjs +117 -39
  29. package/dist/smart-account.mjs.map +1 -1
  30. package/dist/wallet.cjs +113 -36
  31. package/dist/wallet.cjs.map +1 -1
  32. package/dist/wallet.d.cts +4 -7
  33. package/dist/wallet.d.ts +4 -7
  34. package/dist/wallet.mjs +113 -36
  35. package/dist/wallet.mjs.map +1 -1
  36. package/dist/widget.cjs +239 -54
  37. package/dist/widget.cjs.map +1 -1
  38. package/dist/widget.mjs +267 -81
  39. package/dist/widget.mjs.map +1 -1
  40. package/package.json +3 -2
package/dist/widget.mjs CHANGED
@@ -563,7 +563,7 @@ var init_constants = __esm({
563
563
  "src/constants.ts"() {
564
564
  "use strict";
565
565
  SDK_NAME = "@trustware/sdk";
566
- SDK_VERSION = "1.1.9-staging.6";
566
+ SDK_VERSION = "1.1.10-staging.0";
567
567
  API_ROOT = "https://bv-staging-api.trustware.io";
568
568
  GTM_ID = "GTM-TZDGNCXB";
569
569
  API_PREFIX = "/api";
@@ -774,7 +774,9 @@ var init_chains = __esm({
774
774
  btc: "bitcoin",
775
775
  bitcoin: "bitcoin",
776
776
  sei: "cosmos",
777
- "pacific-1": "cosmos"
777
+ "pacific-1": "cosmos",
778
+ nibiru: "cosmos",
779
+ "cataclysm-1": "cosmos"
778
780
  };
779
781
  }
780
782
  });
@@ -1971,16 +1973,23 @@ function validateEvmAddress(address) {
1971
1973
  }
1972
1974
  return { isValid: true };
1973
1975
  }
1974
- function validateSeiAddress(address) {
1976
+ function resolveCosmosBech32Prefix(chain) {
1977
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1978
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
1979
+ const normalized = String(identifier ?? "").trim().toLowerCase();
1980
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
1981
+ }
1982
+ function validateCosmosAddress(address, chain) {
1975
1983
  const trimmed = address.trim();
1976
- if (isEvmAddress(trimmed)) {
1984
+ const prefix = resolveCosmosBech32Prefix(chain);
1985
+ if (prefix === "sei" && isEvmAddress(trimmed)) {
1977
1986
  return { isValid: true };
1978
1987
  }
1979
- const result = validateBech32LikeAddress(trimmed, "sei");
1988
+ const result = validateBech32LikeAddress(trimmed, prefix);
1980
1989
  if (result.isValid) return result;
1981
1990
  return {
1982
1991
  isValid: false,
1983
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
1992
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
1984
1993
  };
1985
1994
  }
1986
1995
  function validateSolanaAddress(address) {
@@ -2030,15 +2039,12 @@ function validateAddressForChain(address, chain) {
2030
2039
  case "bitcoin":
2031
2040
  return validateBtcAddress(trimmed);
2032
2041
  case "cosmos":
2033
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
2034
- return validateSeiAddress(trimmed);
2035
- }
2036
- return validateBech32LikeAddress(trimmed, "sei");
2042
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
2037
2043
  default:
2038
2044
  return { isValid: false, error: "Unsupported or unknown chain type." };
2039
2045
  }
2040
2046
  }
2041
- function validateAddressForRouteChain(address, chainType) {
2047
+ function validateAddressForRouteChain(address, chainType, chainRef) {
2042
2048
  switch (normalizeChainType(chainType)) {
2043
2049
  case "evm":
2044
2050
  return validateEvmAddress(address);
@@ -2047,7 +2053,7 @@ function validateAddressForRouteChain(address, chainType) {
2047
2053
  case "bitcoin":
2048
2054
  return validateBtcAddress(address);
2049
2055
  case "cosmos":
2050
- return validateSeiAddress(address);
2056
+ return validateCosmosAddress(address, chainRef ?? chainType);
2051
2057
  default:
2052
2058
  return { isValid: false, error: "Unsupported chain type." };
2053
2059
  }
@@ -2069,14 +2075,18 @@ function validateRouteAddresses(params) {
2069
2075
  const normalizedDirection = params.direction?.trim().toLowerCase();
2070
2076
  const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
2071
2077
  if (isDepositFlow) {
2072
- const fromResult2 = validateAddressForRouteChain(fromAddress, fromType);
2078
+ const fromResult2 = validateAddressForRouteChain(
2079
+ fromAddress,
2080
+ fromType,
2081
+ params.fromChain
2082
+ );
2073
2083
  if (!fromResult2.isValid) {
2074
2084
  return {
2075
2085
  isValid: false,
2076
2086
  error: `From address: ${fromResult2.error ?? "Invalid address."}`
2077
2087
  };
2078
2088
  }
2079
- const toResult2 = toType === "cosmos" ? validateSeiAddress(toAddress) : validateEvmAddress(toAddress);
2089
+ const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
2080
2090
  if (!toResult2.isValid) {
2081
2091
  return {
2082
2092
  isValid: false,
@@ -2101,14 +2111,22 @@ function validateRouteAddresses(params) {
2101
2111
  }
2102
2112
  return { isValid: true };
2103
2113
  }
2104
- const fromResult = validateAddressForRouteChain(fromAddress, fromType);
2114
+ const fromResult = validateAddressForRouteChain(
2115
+ fromAddress,
2116
+ fromType,
2117
+ params.fromChain
2118
+ );
2105
2119
  if (!fromResult.isValid) {
2106
2120
  return {
2107
2121
  isValid: false,
2108
2122
  error: `From address: ${fromResult.error ?? "Invalid address."}`
2109
2123
  };
2110
2124
  }
2111
- const toResult = validateAddressForRouteChain(toAddress, toType);
2125
+ const toResult = validateAddressForRouteChain(
2126
+ toAddress,
2127
+ toType,
2128
+ params.toChain
2129
+ );
2112
2130
  if (!toResult.isValid) {
2113
2131
  return {
2114
2132
  isValid: false,
@@ -2117,13 +2135,19 @@ function validateRouteAddresses(params) {
2117
2135
  }
2118
2136
  return { isValid: true };
2119
2137
  }
2120
- var BECH32_CHARSET;
2138
+ var BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
2121
2139
  var init_address = __esm({
2122
2140
  "src/validation/address.ts"() {
2123
2141
  "use strict";
2124
2142
  init_index_node4();
2125
2143
  init_chains();
2126
2144
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
2145
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
2146
+ "pacific-1": "sei",
2147
+ sei: "sei",
2148
+ "cataclysm-1": "nibi",
2149
+ nibiru: "nibi"
2150
+ };
2127
2151
  }
2128
2152
  });
2129
2153
 
@@ -2418,6 +2442,27 @@ var init_balances = __esm({
2418
2442
  });
2419
2443
 
2420
2444
  // src/core/routes.ts
2445
+ function assertValidPostHook(hooks) {
2446
+ const postHook = hooks?.postHook;
2447
+ if (!postHook) return;
2448
+ if (!postHook.target?.trim()) {
2449
+ throw new Error("hooks.postHook.target is required.");
2450
+ }
2451
+ if (!postHook.callData?.trim()) {
2452
+ throw new Error("hooks.postHook.callData is required.");
2453
+ }
2454
+ if (postHook.fullAmount) {
2455
+ if (postHook.amountInputPos === void 0) {
2456
+ throw new Error(
2457
+ "hooks.postHook.amountInputPos is required when fullAmount is true."
2458
+ );
2459
+ }
2460
+ } else if (!postHook.fundAmount?.trim()) {
2461
+ throw new Error(
2462
+ "hooks.postHook.fundAmount is required unless fullAmount is set."
2463
+ );
2464
+ }
2465
+ }
2421
2466
  function isEvmTxRequest(txReq) {
2422
2467
  return Boolean(txReq?.data && (txReq.to || txReq.target));
2423
2468
  }
@@ -2436,6 +2481,7 @@ async function buildRoute(body, signal) {
2436
2481
  if (!addressValidation.isValid) {
2437
2482
  throw new Error(addressValidation.error || "Invalid route addresses.");
2438
2483
  }
2484
+ assertValidPostHook(body.hooks);
2439
2485
  const cfg = TrustwareConfigStore.get();
2440
2486
  const url = `${apiBase()}/v1/routes/route`;
2441
2487
  const payload = {
@@ -2474,6 +2520,7 @@ async function buildRoute(body, signal) {
2474
2520
  return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
2475
2521
  }
2476
2522
  async function buildDepositAddress(body, signal) {
2523
+ assertValidPostHook(body.hooks);
2477
2524
  const cfg = TrustwareConfigStore.get();
2478
2525
  const url = `${apiBase()}/v1/routes/deposit-address`;
2479
2526
  const payload = {
@@ -2515,7 +2562,7 @@ async function buildDepositAddress(body, signal) {
2515
2562
  route
2516
2563
  };
2517
2564
  }
2518
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2565
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
2519
2566
  const r = await rateLimitedFetch(
2520
2567
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
2521
2568
  {
@@ -2523,7 +2570,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2523
2570
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
2524
2571
  body: JSON.stringify({
2525
2572
  txHash,
2526
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
2573
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
2574
+ ...eoaAddress ? { eoaAddress } : {}
2527
2575
  })
2528
2576
  }
2529
2577
  );
@@ -2833,6 +2881,7 @@ function useTrustwareConfig() {
2833
2881
  } catch {
2834
2882
  return {
2835
2883
  apiKey: "",
2884
+ mode: "deposit",
2836
2885
  routes: {
2837
2886
  toChain: "",
2838
2887
  toToken: "",
@@ -3095,7 +3144,9 @@ var init_chainHelpers = __esm({
3095
3144
  btc: "bitcoin",
3096
3145
  bitcoin: "bitcoin",
3097
3146
  sei: "cosmos",
3098
- "pacific-1": "cosmos"
3147
+ "pacific-1": "cosmos",
3148
+ nibiru: "cosmos",
3149
+ "cataclysm-1": "cosmos"
3099
3150
  };
3100
3151
  SEI_EVM_CHAIN_ID = "1329";
3101
3152
  SEI_COSMOS_CHAIN_ID = "pacific-1";
@@ -3311,7 +3362,8 @@ function filterSupportedChains(chains) {
3311
3362
  }
3312
3363
  if (chainType === "cosmos") {
3313
3364
  const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
3314
- if (seiKey !== "sei" && seiKey !== "pacific-1") {
3365
+ const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
3366
+ if (seiKey !== "sei" && !isNibiru) {
3315
3367
  return false;
3316
3368
  }
3317
3369
  }
@@ -3411,7 +3463,7 @@ function useChains() {
3411
3463
  error
3412
3464
  };
3413
3465
  }
3414
- var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
3466
+ var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
3415
3467
  var init_useChains = __esm({
3416
3468
  "src/core/useChains.ts"() {
3417
3469
  "use strict";
@@ -3421,6 +3473,7 @@ var init_useChains = __esm({
3421
3473
  init_popularChains();
3422
3474
  POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
3423
3475
  POPULAR_LIMIT = popularChains_default.popularLimit;
3476
+ NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
3424
3477
  }
3425
3478
  });
3426
3479
 
@@ -8755,46 +8808,80 @@ function normalizeSlippage(v) {
8755
8808
  if (n > 5) return 5;
8756
8809
  return n;
8757
8810
  }
8811
+ function warnDeprecatedSwapModeFlag() {
8812
+ if (hasWarnedDeprecatedSwapModeFlag) return;
8813
+ hasWarnedDeprecatedSwapModeFlag = true;
8814
+ console.warn(
8815
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
8816
+ );
8817
+ }
8818
+ function resolveMode(input) {
8819
+ if (input.mode === "swap") return "swap";
8820
+ if (input.mode === "deposit") return "deposit";
8821
+ if (input.features?.swapMode) {
8822
+ warnDeprecatedSwapModeFlag();
8823
+ return "swap";
8824
+ }
8825
+ return "deposit";
8826
+ }
8758
8827
  function resolveConfig(input) {
8759
8828
  if (!input?.apiKey) {
8760
- throw new Error("TrustwareConfig: 'apiKey' is required.");
8829
+ throw new TrustwareError({
8830
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8831
+ message: "TrustwareConfig: 'apiKey' is required.",
8832
+ userMessage: "Missing required API key configuration."
8833
+ });
8761
8834
  }
8762
- if (!input.routes?.toChain || !input.routes?.toToken) {
8763
- throw new Error(
8764
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
8765
- );
8835
+ const mode = resolveMode(input);
8836
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
8837
+ throw new TrustwareError({
8838
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8839
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
8840
+ userMessage: "Missing required destination chain/token configuration."
8841
+ });
8766
8842
  }
8767
- const toChain = input.routes.toChain;
8768
- if (input.routes.toAddress) {
8843
+ const toChain = input.routes?.toChain;
8844
+ if (input.routes?.toAddress && toChain) {
8769
8845
  const result = validateAddressForChain(input.routes.toAddress, toChain);
8770
8846
  if (!result.isValid) {
8771
8847
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
8772
- throw new Error(`Invalid toAddress: ${result.error}`);
8848
+ throw new TrustwareError({
8849
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8850
+ message: `Invalid toAddress: ${result.error}`,
8851
+ userMessage: "The configured destination address is invalid."
8852
+ });
8773
8853
  }
8774
8854
  }
8775
- if (input.routes.fromAddress) {
8776
- const result = validateAddressForChain(
8777
- input.routes.fromAddress,
8778
- input.routes.fromChain ?? toChain
8779
- );
8780
- if (!result.isValid) {
8781
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8782
- throw new Error(`Invalid fromAddress: ${result.error}`);
8855
+ if (input.routes?.fromAddress) {
8856
+ const fromChain = input.routes.fromChain ?? toChain;
8857
+ if (fromChain) {
8858
+ const result = validateAddressForChain(
8859
+ input.routes.fromAddress,
8860
+ fromChain
8861
+ );
8862
+ if (!result.isValid) {
8863
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8864
+ throw new TrustwareError({
8865
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8866
+ message: `Invalid fromAddress: ${result.error}`,
8867
+ userMessage: "The configured source address is invalid."
8868
+ });
8869
+ }
8783
8870
  }
8784
8871
  }
8785
8872
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
8786
8873
  const routes = {
8787
- toChain: input.routes.toChain,
8788
- toToken: input.routes.toToken,
8789
- fromToken: input.routes.fromToken,
8790
- fromAddress: input.routes.fromAddress,
8791
- fromChain: input.routes.fromChain,
8792
- toAddress: input.routes.toAddress,
8874
+ toChain: input.routes?.toChain ?? "",
8875
+ toToken: input.routes?.toToken ?? "",
8876
+ fromToken: input.routes?.fromToken,
8877
+ fromAddress: input.routes?.fromAddress,
8878
+ fromChain: input.routes?.fromChain,
8879
+ toAddress: input.routes?.toAddress,
8793
8880
  defaultSlippage: normalizeSlippage(
8794
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
8881
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
8795
8882
  ),
8796
8883
  options: {
8797
- ...input.routes.options
8884
+ ...input.routes?.options
8798
8885
  }
8799
8886
  };
8800
8887
  const theme = input.theme ?? "system";
@@ -8813,13 +8900,16 @@ function resolveConfig(input) {
8813
8900
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
8814
8901
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
8815
8902
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
8816
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
8903
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
8904
+ // or the deprecated `features.swapMode` flag).
8905
+ swapMode: mode === "swap",
8817
8906
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
8818
8907
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
8819
8908
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
8820
8909
  };
8821
8910
  return {
8822
8911
  apiKey: input.apiKey,
8912
+ mode,
8823
8913
  routes,
8824
8914
  autoDetectProvider,
8825
8915
  theme,
@@ -8832,12 +8922,15 @@ function resolveConfig(input) {
8832
8922
  onEvent: input.onEvent
8833
8923
  };
8834
8924
  }
8925
+ var hasWarnedDeprecatedSwapModeFlag;
8835
8926
  var init_merge = __esm({
8836
8927
  "src/config/merge.ts"() {
8837
8928
  "use strict";
8838
8929
  init_defaults();
8839
8930
  init_config();
8840
8931
  init_index();
8932
+ init_TrustwareError();
8933
+ hasWarnedDeprecatedSwapModeFlag = false;
8841
8934
  }
8842
8935
  });
8843
8936
 
@@ -8922,11 +9015,92 @@ var init_store = __esm({
8922
9015
  });
8923
9016
 
8924
9017
  // src/core/tx.ts
8925
- import { keccak256 } from "viem";
9018
+ import { keccak256, encodeFunctionData, parseAbi } from "viem";
8926
9019
  function backendChainId(chain, fallback) {
8927
9020
  const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
8928
9021
  return String(preferred ?? fallback ?? "");
8929
9022
  }
9023
+ function sleep2(ms) {
9024
+ return new Promise((resolve) => setTimeout(resolve, ms));
9025
+ }
9026
+ async function sendEvmTx(w, tx) {
9027
+ if (w.type === "eip1193") {
9028
+ const from = await w.getAddress();
9029
+ const params = {
9030
+ from,
9031
+ to: tx.to,
9032
+ data: tx.data,
9033
+ value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
9034
+ };
9035
+ if (tx.chainId !== void 0) {
9036
+ params.chainId = `0x${tx.chainId.toString(16)}`;
9037
+ }
9038
+ const hash = await w.request({
9039
+ method: "eth_sendTransaction",
9040
+ params: [params]
9041
+ });
9042
+ return hash;
9043
+ }
9044
+ const response = await w.sendTransaction({
9045
+ to: tx.to,
9046
+ data: tx.data,
9047
+ value: tx.value,
9048
+ chainId: tx.chainId
9049
+ });
9050
+ return response.hash;
9051
+ }
9052
+ async function waitForTxConfirmation(chainId, txHash) {
9053
+ const timeoutMs = 12e4;
9054
+ const intervalMs = 2e3;
9055
+ const started = Date.now();
9056
+ while (Date.now() - started < timeoutMs) {
9057
+ const status = await getEVMTxStatus({ chainId, txHash });
9058
+ if (status.status === "success") return;
9059
+ if (status.status === "reverted") {
9060
+ throw new Error("Approval transaction reverted");
9061
+ }
9062
+ await sleep2(intervalMs);
9063
+ }
9064
+ throw new Error("Timed out waiting for approval confirmation");
9065
+ }
9066
+ async function ensureApprovals(w, approvals, fallbackChainId) {
9067
+ if (!approvals || approvals.length === 0) return;
9068
+ const owner = await w.getAddress();
9069
+ for (const approval of approvals) {
9070
+ const spender = approval.spender;
9071
+ const tokenAddress = approval.tokenAddress;
9072
+ const amount = approval.amount;
9073
+ if (!spender || !tokenAddress || !amount) continue;
9074
+ const chainId = approval.chainId || String(fallbackChainId ?? "");
9075
+ if (!chainId) continue;
9076
+ const amountWei = BigInt(amount);
9077
+ if (amountWei === 0n) continue;
9078
+ let currentAllowance = 0n;
9079
+ try {
9080
+ const { allowance } = await getEVMAllowance({
9081
+ chainId,
9082
+ tokenAddress,
9083
+ ownerAddress: owner,
9084
+ spenderAddress: spender
9085
+ });
9086
+ currentAllowance = BigInt(allowance || "0");
9087
+ } catch {
9088
+ }
9089
+ if (currentAllowance >= amountWei) continue;
9090
+ const data = encodeFunctionData({
9091
+ abi: erc20ApproveAbi,
9092
+ functionName: "approve",
9093
+ args: [spender, amountWei]
9094
+ });
9095
+ const hash = await sendEvmTx(w, {
9096
+ to: tokenAddress,
9097
+ data,
9098
+ value: 0n,
9099
+ chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
9100
+ });
9101
+ await waitForTxConfirmation(chainId, hash);
9102
+ }
9103
+ }
8930
9104
  function isUserRejected(e2) {
8931
9105
  const code = e2?.code ?? e2?.data?.code;
8932
9106
  if (code === 4001) return true;
@@ -8960,6 +9134,13 @@ async function sendRouteTransaction(b, fallbackChainId) {
8960
9134
  }
8961
9135
  }
8962
9136
  }
9137
+ if (!validatedSponsorship) {
9138
+ await ensureApprovals(
9139
+ w,
9140
+ b.route?.execution?.approvals,
9141
+ Number.isFinite(target) ? target : void 0
9142
+ );
9143
+ }
8963
9144
  if (w.type === "eip1193") {
8964
9145
  const from = await w.getAddress();
8965
9146
  const hexValue = value ? `0x${value.toString(16)}` : "0x0";
@@ -9056,11 +9237,16 @@ async function runTopUp(params) {
9056
9237
  }
9057
9238
  }
9058
9239
  }
9240
+ var erc20ApproveAbi;
9059
9241
  var init_tx = __esm({
9060
9242
  "src/core/tx.ts"() {
9061
9243
  "use strict";
9062
9244
  init_wallets();
9063
9245
  init_routes();
9246
+ init_sdkRpc();
9247
+ erc20ApproveAbi = parseAbi([
9248
+ "function approve(address spender, uint256 amount) returns (bool)"
9249
+ ]);
9064
9250
  }
9065
9251
  });
9066
9252
 
@@ -28174,7 +28360,7 @@ var init_utils5 = __esm({
28174
28360
  });
28175
28361
 
28176
28362
  // node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/base.js
28177
- import { concat as concat5, encodeFunctionData, fromHex as fromHex4, hashMessage, hashTypedData, trim } from "viem";
28363
+ import { concat as concat5, encodeFunctionData as encodeFunctionData2, fromHex as fromHex4, hashMessage, hashTypedData, trim } from "viem";
28178
28364
  async function createLightAccountBase({ transport, chain, signer, abi, version, type, entryPoint, accountAddress, getAccountInitCode }) {
28179
28365
  const client = createBundlerClient({
28180
28366
  transport,
@@ -28193,7 +28379,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
28193
28379
  if (fromHex4(storage, "number") !== 0 && !implementationAddresses.some((x) => x === trim(storage))) {
28194
28380
  throw new Error(`could not determine if smart account implementation is ${type} ${String(version)}`);
28195
28381
  }
28196
- return encodeFunctionData({
28382
+ return encodeFunctionData2({
28197
28383
  abi,
28198
28384
  functionName: "upgradeToAndCall",
28199
28385
  args: [upgradeToAddress, upgradeToInitData]
@@ -28252,7 +28438,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
28252
28438
  prepareSign,
28253
28439
  formatSign,
28254
28440
  encodeExecute: async ({ target, data, value }) => {
28255
- return encodeFunctionData({
28441
+ return encodeFunctionData2({
28256
28442
  abi,
28257
28443
  functionName: "execute",
28258
28444
  args: [target, value ?? 0n, data]
@@ -28265,7 +28451,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
28265
28451
  accum[2].push(curr.data);
28266
28452
  return accum;
28267
28453
  }, [[], [], []]);
28268
- return encodeFunctionData({
28454
+ return encodeFunctionData2({
28269
28455
  abi,
28270
28456
  functionName: "executeBatch",
28271
28457
  args: [targets, values, datas]
@@ -28359,7 +28545,7 @@ var init_OZ_ERC1967Proxy = __esm({
28359
28545
  });
28360
28546
 
28361
28547
  // node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/predictAddress.js
28362
- import { encodeAbiParameters as encodeAbiParameters4, encodeDeployData, keccak256 as keccak2565, getContractAddress, toHex as toHex6, encodeFunctionData as encodeFunctionData2 } from "viem";
28548
+ import { encodeAbiParameters as encodeAbiParameters4, encodeDeployData, keccak256 as keccak2565, getContractAddress, toHex as toHex6, encodeFunctionData as encodeFunctionData3 } from "viem";
28363
28549
  function predictLightAccountAddress({ factoryAddress, salt, ownerAddress, version }) {
28364
28550
  const implementationAddress = (
28365
28551
  // If we aren't using the default factory address, we compute the implementation address from the factory's `create` deployment.
@@ -28383,7 +28569,7 @@ function predictLightAccountAddress({ factoryAddress, salt, ownerAddress, versio
28383
28569
  abi: OZ_ERC1967Proxy_ConstructorAbi,
28384
28570
  args: [
28385
28571
  implementationAddress,
28386
- encodeFunctionData2({
28572
+ encodeFunctionData3({
28387
28573
  abi: LightAccountAbi_v1,
28388
28574
  functionName: "initialize",
28389
28575
  args: [ownerAddress]
@@ -28420,7 +28606,7 @@ var init_predictAddress = __esm({
28420
28606
  });
28421
28607
 
28422
28608
  // node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/account.js
28423
- import { concatHex as concatHex2, encodeFunctionData as encodeFunctionData3 } from "viem";
28609
+ import { concatHex as concatHex2, encodeFunctionData as encodeFunctionData4 } from "viem";
28424
28610
  async function createLightAccount({ transport, chain, signer, initCode, version = defaultLightAccountVersion(), entryPoint = getEntryPoint(chain, {
28425
28611
  version: AccountVersionRegistry["LightAccount"][version].entryPointVersion
28426
28612
  }), accountAddress, factoryAddress = getDefaultLightAccountFactoryAddress(chain, version), salt: salt_ = 0n }) {
@@ -28437,7 +28623,7 @@ async function createLightAccount({ transport, chain, signer, initCode, version
28437
28623
  return initCode;
28438
28624
  return concatHex2([
28439
28625
  factoryAddress,
28440
- encodeFunctionData3({
28626
+ encodeFunctionData4({
28441
28627
  abi: factoryAbi,
28442
28628
  functionName: "createAccount",
28443
28629
  args: [signerAddress, salt]
@@ -28464,7 +28650,7 @@ async function createLightAccount({ transport, chain, signer, initCode, version
28464
28650
  return {
28465
28651
  ...account,
28466
28652
  encodeTransferOwnership: (newOwner) => {
28467
- return encodeFunctionData3({
28653
+ return encodeFunctionData4({
28468
28654
  abi: accountAbi,
28469
28655
  functionName: "transferOwnership",
28470
28656
  args: [newOwner]
@@ -29772,7 +29958,7 @@ var init_feeEstimator2 = __esm({
29772
29958
  });
29773
29959
 
29774
29960
  // node_modules/@account-kit/infra/dist/esm/gas-manager.js
29775
- import { encodeFunctionData as encodeFunctionData4 } from "viem";
29961
+ import { encodeFunctionData as encodeFunctionData5 } from "viem";
29776
29962
  var AlchemyPaymasterAddressV06Unify, AlchemyPaymasterAddressV07Unify, AlchemyPaymasterAddressV4, AlchemyPaymasterAddressV3, AlchemyPaymasterAddressV2, ArbSepoliaPaymasterAddress, AlchemyPaymasterAddressV1, AlchemyPaymasterAddressV07V2, AlchemyPaymasterAddressV07V1, getAlchemyPaymasterAddress, PermitTypes, ERC20Abis, EIP7597Abis;
29777
29963
  var init_gas_manager = __esm({
29778
29964
  "node_modules/@account-kit/infra/dist/esm/gas-manager.js"() {
@@ -29961,7 +30147,7 @@ var init_invalidSignedPermit = __esm({
29961
30147
  });
29962
30148
 
29963
30149
  // node_modules/@account-kit/infra/dist/esm/middleware/gasManager.js
29964
- import { fromHex as fromHex5, isHex as isHex2, encodeAbiParameters as encodeAbiParameters5, encodeFunctionData as encodeFunctionData5, parseAbi } from "viem";
30150
+ import { fromHex as fromHex5, isHex as isHex2, encodeAbiParameters as encodeAbiParameters5, encodeFunctionData as encodeFunctionData6, parseAbi as parseAbi2 } from "viem";
29965
30151
  function alchemyGasManagerMiddleware(policyId, policyToken, webhookData) {
29966
30152
  const buildContext = async (args) => {
29967
30153
  const context = { policyId };
@@ -30143,16 +30329,16 @@ var init_gasManager = __esm({
30143
30329
  }
30144
30330
  let allowanceFuture = client.call({
30145
30331
  to: policyToken.address,
30146
- data: encodeFunctionData5({
30147
- abi: parseAbi(ERC20Abis),
30332
+ data: encodeFunctionData6({
30333
+ abi: parseAbi2(ERC20Abis),
30148
30334
  functionName: "allowance",
30149
30335
  args: [account.address, paymasterAddress]
30150
30336
  })
30151
30337
  });
30152
30338
  let nonceFuture = client.call({
30153
30339
  to: policyToken.address,
30154
- data: encodeFunctionData5({
30155
- abi: parseAbi(EIP7597Abis),
30340
+ data: encodeFunctionData6({
30341
+ abi: parseAbi2(EIP7597Abis),
30156
30342
  functionName: "nonces",
30157
30343
  args: [account.address]
30158
30344
  })
@@ -30605,7 +30791,7 @@ var init_fee_utils = __esm({
30605
30791
 
30606
30792
  // src/smart-account/permit2.ts
30607
30793
  import {
30608
- encodeFunctionData as encodeFunctionData6,
30794
+ encodeFunctionData as encodeFunctionData7,
30609
30795
  keccak256 as keccak2567,
30610
30796
  encodeAbiParameters as encodeAbiParameters6,
30611
30797
  concat as concat6,
@@ -30729,7 +30915,7 @@ async function signPermit2(eip1193Request, params) {
30729
30915
  return sig;
30730
30916
  }
30731
30917
  function encodePermitTransferFrom(token, amount, nonce, deadline, saAddress, eoaAddress, sig) {
30732
- return encodeFunctionData6({
30918
+ return encodeFunctionData7({
30733
30919
  abi: PERMIT2_ABI,
30734
30920
  functionName: "permitTransferFrom",
30735
30921
  args: [
@@ -30741,28 +30927,28 @@ function encodePermitTransferFrom(token, amount, nonce, deadline, saAddress, eoa
30741
30927
  });
30742
30928
  }
30743
30929
  function encodeErc20Approve(spender, amount) {
30744
- return encodeFunctionData6({
30930
+ return encodeFunctionData7({
30745
30931
  abi: ERC20_APPROVE_ABI,
30746
30932
  functionName: "approve",
30747
30933
  args: [spender, amount]
30748
30934
  });
30749
30935
  }
30750
30936
  function encodeErc20Allowance(owner, spender) {
30751
- return encodeFunctionData6({
30937
+ return encodeFunctionData7({
30752
30938
  abi: ERC20_ALLOWANCE_ABI,
30753
30939
  functionName: "allowance",
30754
30940
  args: [owner, spender]
30755
30941
  });
30756
30942
  }
30757
30943
  function encodeErc20BalanceOf(owner) {
30758
- return encodeFunctionData6({
30944
+ return encodeFunctionData7({
30759
30945
  abi: ERC20_BALANCE_OF_ABI,
30760
30946
  functionName: "balanceOf",
30761
30947
  args: [owner]
30762
30948
  });
30763
30949
  }
30764
30950
  function encodeWethWithdraw(amount) {
30765
- return encodeFunctionData6({
30951
+ return encodeFunctionData7({
30766
30952
  abi: WETH_ABI,
30767
30953
  functionName: "withdraw",
30768
30954
  args: [amount]
@@ -30855,9 +31041,9 @@ var init_permit2 = __esm({
30855
31041
  });
30856
31042
 
30857
31043
  // src/smart-account/uniswap.ts
30858
- import { encodeFunctionData as encodeFunctionData7 } from "viem";
31044
+ import { encodeFunctionData as encodeFunctionData8 } from "viem";
30859
31045
  function encodeUniswapExactOutputSingle(tokenIn, tokenOut, fee, recipient, amountOut, amountInMaximum) {
30860
- return encodeFunctionData7({
31046
+ return encodeFunctionData8({
30861
31047
  abi: SWAP_ROUTER_ABI,
30862
31048
  functionName: "exactOutputSingle",
30863
31049
  args: [
@@ -31339,7 +31525,7 @@ async function sendRouteAsUserOperation(params) {
31339
31525
  );
31340
31526
  }
31341
31527
  console.debug("[send] UserOp included", { userOpHash, txHash });
31342
- await submitReceipt(intentId, txHash, getSponsorshipRequestId());
31528
+ await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31343
31529
  return { userOpHash, txHash, intentId };
31344
31530
  }
31345
31531
  var NATIVE_ADDRS;
@@ -31385,14 +31571,14 @@ var init_smart_account2 = __esm({
31385
31571
 
31386
31572
  // src/widget/features/transaction/hooks/useTransactionActionModel.ts
31387
31573
  import { useCallback as useCallback19, useEffect as useEffect26, useMemo as useMemo20, useRef as useRef13, useState as useState26 } from "react";
31388
- import { encodeFunctionData as encodeFunctionData8, erc20Abi } from "viem";
31574
+ import { encodeFunctionData as encodeFunctionData9, erc20Abi } from "viem";
31389
31575
  function normalizeTokenAddressForCompare(chain, addr) {
31390
31576
  const chainType = (chain.type ?? chain.chainType ?? "").toLowerCase();
31391
31577
  const value = (addr ?? "").trim();
31392
31578
  if (chainType === "solana") return value;
31393
31579
  return value.toLowerCase();
31394
31580
  }
31395
- function sleep2(ms) {
31581
+ function sleep3(ms) {
31396
31582
  return new Promise((resolve) => setTimeout(resolve, ms));
31397
31583
  }
31398
31584
  function useTransactionActionModel({
@@ -31510,7 +31696,7 @@ function useTransactionActionModel({
31510
31696
  if (status.status === "reverted") {
31511
31697
  throw new Error("Approval transaction reverted");
31512
31698
  }
31513
- await sleep2(intervalMs);
31699
+ await sleep3(intervalMs);
31514
31700
  }
31515
31701
  throw new Error("Timed out waiting for approval confirmation");
31516
31702
  },
@@ -31550,7 +31736,7 @@ function useTransactionActionModel({
31550
31736
  }
31551
31737
  }
31552
31738
  }
31553
- const data = encodeFunctionData8({
31739
+ const data = encodeFunctionData9({
31554
31740
  abi: erc20Abi,
31555
31741
  functionName: "approve",
31556
31742
  args: [spender, amountWei]
@@ -33160,7 +33346,7 @@ var init_useSwapRoute = __esm({
33160
33346
 
33161
33347
  // src/modes/swap/hooks/useSwapExecution.ts
33162
33348
  import { useCallback as useCallback21, useRef as useRef16, useState as useState29 } from "react";
33163
- import { encodeFunctionData as encodeFunctionData9, erc20Abi as erc20Abi2 } from "viem";
33349
+ import { encodeFunctionData as encodeFunctionData10, erc20Abi as erc20Abi2 } from "viem";
33164
33350
  function normalizeTx(raw) {
33165
33351
  const r = raw;
33166
33352
  return {
@@ -33171,7 +33357,7 @@ function normalizeTx(raw) {
33171
33357
  toChainTxUrl: r.toChainTxUrl || r.to_chain_tx_url || void 0
33172
33358
  };
33173
33359
  }
33174
- function sleep3(ms) {
33360
+ function sleep4(ms) {
33175
33361
  return new Promise((resolve) => setTimeout(resolve, ms));
33176
33362
  }
33177
33363
  function isUserRejection(err) {
@@ -33189,7 +33375,7 @@ async function waitForApprovalConfirmation(chainId, txHash) {
33189
33375
  if (status.status === "success") return;
33190
33376
  if (status.status === "reverted")
33191
33377
  throw new Error("Approval transaction reverted");
33192
- await sleep3(2e3);
33378
+ await sleep4(2e3);
33193
33379
  }
33194
33380
  throw new Error("Timed out waiting for approval confirmation");
33195
33381
  }
@@ -33429,7 +33615,7 @@ function useSwapExecution(fromChain) {
33429
33615
  const approveAmount = maxApproval ? BigInt(
33430
33616
  "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
33431
33617
  ) : fromAmountWei;
33432
- const data = encodeFunctionData9({
33618
+ const data = encodeFunctionData10({
33433
33619
  abi: erc20Abi2,
33434
33620
  functionName: "approve",
33435
33621
  args: [spender, approveAmount]
@@ -39628,7 +39814,7 @@ var init_TrustwareWidgetV2 = __esm({
39628
39814
  if (!isOpen) {
39629
39815
  return null;
39630
39816
  }
39631
- if (config.features.swapMode) {
39817
+ if (config.mode === "swap") {
39632
39818
  return /* @__PURE__ */ jsx60(SwapMode, { theme, style });
39633
39819
  }
39634
39820
  return /* @__PURE__ */ jsx60(DepositProvider, { initialStep: effectiveInitialStep, children: /* @__PURE__ */ jsx60(