@trustware/sdk-staging 1.1.17-staging.7 → 1.1.18-staging.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.mjs CHANGED
@@ -110,7 +110,7 @@ var init_constants = __esm({
110
110
  "src/constants.ts"() {
111
111
  "use strict";
112
112
  SDK_NAME = "@trustware/sdk";
113
- SDK_VERSION = "1.1.17-staging.7";
113
+ SDK_VERSION = "1.1.18-staging.1";
114
114
  API_ROOT = "https://bv-staging-api.trustware.io";
115
115
  API_PREFIX = "/api";
116
116
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -4601,6 +4601,32 @@ var init_routeError = __esm({
4601
4601
  }
4602
4602
  });
4603
4603
 
4604
+ // src/core/routeApprovals.ts
4605
+ function approvalAmountWei(approval, stepIndex) {
4606
+ const { amount } = approval;
4607
+ if (amount === void 0 || amount === "") {
4608
+ throw new Error(
4609
+ `Route approval ${stepIndex} (spender ${String(approval.spender)}) has no amount.`
4610
+ );
4611
+ }
4612
+ if (!DECIMAL_INTEGER.test(amount)) {
4613
+ throw new Error(
4614
+ `Route approval ${stepIndex} (spender ${String(approval.spender)}) has an invalid amount "${amount}".`
4615
+ );
4616
+ }
4617
+ return BigInt(amount);
4618
+ }
4619
+ function assertValidRouteApprovals(approvals) {
4620
+ (approvals ?? []).forEach(approvalAmountWei);
4621
+ }
4622
+ var DECIMAL_INTEGER;
4623
+ var init_routeApprovals = __esm({
4624
+ "src/core/routeApprovals.ts"() {
4625
+ "use strict";
4626
+ DECIMAL_INTEGER = /^\d+$/;
4627
+ }
4628
+ });
4629
+
4604
4630
  // src/core/routeValue.ts
4605
4631
  function parseUsd(value) {
4606
4632
  if (value == null) return null;
@@ -4761,6 +4787,7 @@ async function buildRoute(body, signal) {
4761
4787
  if (!txReq?.data) {
4762
4788
  throw new Error("Invalid route: missing transaction data");
4763
4789
  }
4790
+ assertValidRouteApprovals(route?.execution?.approvals);
4764
4791
  assertRouteDeliversValue(route);
4765
4792
  return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
4766
4793
  }
@@ -4881,6 +4908,7 @@ var init_routes = __esm({
4881
4908
  "use strict";
4882
4909
  init_http();
4883
4910
  init_routeError();
4911
+ init_routeApprovals();
4884
4912
  init_routeValue();
4885
4913
  init_store();
4886
4914
  init_address();
@@ -5176,11 +5204,13 @@ async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmo
5176
5204
  for (const [stepIndex, approval] of approvals.entries()) {
5177
5205
  const spender = approval.spender;
5178
5206
  const tokenAddress = approval.tokenAddress;
5179
- const amount = approval.amount;
5180
- if (!spender || !tokenAddress || !amount) continue;
5207
+ if (!spender || !tokenAddress) continue;
5181
5208
  const chainId = approval.chainId || String(fallbackChainId ?? "");
5182
5209
  if (!chainId) continue;
5183
- const amountWei = requiredApprovalAmount(BigInt(amount), routeAmountWei);
5210
+ const amountWei = requiredApprovalAmount(
5211
+ approvalAmountWei(approval, stepIndex),
5212
+ routeAmountWei
5213
+ );
5184
5214
  let currentAllowance = 0n;
5185
5215
  try {
5186
5216
  const { allowance } = await getEVMAllowance({
@@ -5266,7 +5296,6 @@ async function sendRouteTransactionReporting(b, fallbackChainId, options, onAcce
5266
5296
  )}).`
5267
5297
  );
5268
5298
  }
5269
- await ensureWalletOnChain(w, target);
5270
5299
  if (!validatedSponsorship && !options?.approvalsEnsured) {
5271
5300
  await ensureApprovals(
5272
5301
  w,
@@ -5276,6 +5305,7 @@ async function sendRouteTransactionReporting(b, fallbackChainId, options, onAcce
5276
5305
  BigInt(b.route?.estimate?.fromAmount ?? "0")
5277
5306
  );
5278
5307
  }
5308
+ await ensureWalletOnChain(w, target);
5279
5309
  if (w.type === "eip1193") {
5280
5310
  const from = await w.getAddress();
5281
5311
  const hexValue = value ? `0x${value.toString(16)}` : "0x0";
@@ -5442,6 +5472,7 @@ var erc20ApproveAbi, NOT_FOUND_GRACE_MS, UNLIMITED_APPROVAL_FLOOR;
5442
5472
  var init_tx = __esm({
5443
5473
  "src/core/tx.ts"() {
5444
5474
  "use strict";
5475
+ init_routeApprovals();
5445
5476
  init_routeValue();
5446
5477
  init_wallets();
5447
5478
  init_routes();