@anywalletkit/protocol-swap2-core 0.7.0 → 0.9.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.
@@ -7,7 +7,7 @@ import {
7
7
  nativeUnits,
8
8
  normalizeTypedDomain,
9
9
  swap2ChainId
10
- } from "../chunk-5E5FWYZQ.js";
10
+ } from "../chunk-PU5NM3Y6.js";
11
11
  import "../chunk-IVR3SREQ.js";
12
12
  import "../chunk-2KC734UX.js";
13
13
  export {
@@ -764,12 +764,15 @@ var BaseSwap2Protocol = class extends import_core.Swap2Protocol {
764
764
  }
765
765
  }
766
766
  const executionModels = [unsigned.data !== void 0, unsigned.bodyBoc !== void 0, unsigned.typedData !== void 0].filter(Boolean).length;
767
- if (executionModels > 1 || unsigned.memo !== void 0 && (unsigned.bodyBoc !== void 0 || unsigned.typedData !== void 0)) {
767
+ if (executionModels > 1 || unsigned.memo !== void 0 && (unsigned.bodyBoc !== void 0 || unsigned.typedData !== void 0) || unsigned.orderExtension !== void 0 && unsigned.typedData === void 0) {
768
768
  throw new Error("swap2: provider returned ambiguous execution payloads");
769
769
  }
770
770
  if (unsigned.approvalAddress && !unsigned.data && !unsigned.typedData) {
771
771
  throw new Error("swap2: approval is only valid for calldata or typed-order execution");
772
772
  }
773
+ if (provider.remote === true && provider.depositAddressRoutes !== true && unsigned.data === void 0 && unsigned.bodyBoc === void 0 && unsigned.typedData === void 0 && !serialized) {
774
+ throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' sends the input to ${unsigned.to}, an address its backend named, and the app did not allow deposit-address routes for it (remoteProvider depositAddressRoutes) \u2014 refused`);
775
+ }
773
776
  const tronSource = this.fromChain.startsWith("tron:");
774
777
  const nearSource = this.fromChain.startsWith("near:");
775
778
  if (unsigned.memo && !this.fromChain.startsWith("ton:") && !tronSource && !nearSource) {
@@ -876,6 +879,9 @@ var BaseSwap2Protocol = class extends import_core.Swap2Protocol {
876
879
  throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to approve ${unsigned.approvalAddress} on ${this.fromChain}, which the app did not pin as a spender (remoteProvider spenders) \u2014 refused`);
877
880
  }
878
881
  if (unsigned.typedData !== void 0) {
882
+ if (remote && provider.verifiesBuilds !== true) {
883
+ throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' asks to sign a typed order, which needs the app's own validator (remoteProvider verifyBuild) \u2014 refused`);
884
+ }
879
885
  const chainId = this.fromChain.startsWith("eip155:") ? Number(this.fromChain.slice("eip155:".length)) : null;
880
886
  assertTypedOrder(unsigned.typedData, unsigned.approvalAddress, { self: selfAddress, token: source.contract ?? void 0, amount: q.sourceAmount, chainId });
881
887
  }
@@ -901,6 +907,8 @@ var BaseSwap2Protocol = class extends import_core.Swap2Protocol {
901
907
  }
902
908
  } else if (remote && !pinnedTargets.includes(unsigned.to.toLowerCase())) {
903
909
  throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' calls ${(0, import_viem.getAddress)(unsigned.to)} on ${this.fromChain}, which the app did not pin as a call target (remoteProvider callTargets) \u2014 refused`);
910
+ } else if (remote && provider.verifiesQuotes !== true && provider.verifiesBuilds !== true) {
911
+ throw new Swap2ValidationError(`swap2: remote provider '${q.provider}' calls ${(0, import_viem.getAddress)(unsigned.to)} with calldata the app does not check (remoteProvider verifyQuote / verifyBuild) \u2014 refused`);
904
912
  }
905
913
  }
906
914
  const needsApproval = !!unsigned.approvalAddress && !!source.contract;
@@ -1373,8 +1381,13 @@ function validQuote(q, params, provider) {
1373
1381
  }
1374
1382
  }
1375
1383
  function remotePinRefusal(provider, q, chain) {
1376
- if (provider.remote !== true || !chain.startsWith("eip155:")) return null;
1384
+ if (provider.remote !== true) return null;
1377
1385
  const tx = q.txRequest;
1386
+ const plain = tx ? tx.data === void 0 && tx.serializedTx === void 0 : typeof q.depositAddress === "string" && q.depositAddress !== "";
1387
+ if (plain && provider.depositAddressRoutes !== true) {
1388
+ return `${provider.name}: the route pays ${tx?.to || q.depositAddress}, an address the backend named, and the app did not allow deposit-address routes for this provider (remoteProvider depositAddressRoutes)`;
1389
+ }
1390
+ if (!chain.startsWith("eip155:")) return null;
1378
1391
  if (!tx || tx.serializedTx !== void 0) return null;
1379
1392
  const pinned = (list, address) => (list ?? []).some((a) => typeof a === "string" && a.toLowerCase() === address.toLowerCase());
1380
1393
  if (tx.approvalAddress && !pinned(provider.spenders?.(chain), tx.approvalAddress)) {
@@ -1383,6 +1396,9 @@ function remotePinRefusal(provider, q, chain) {
1383
1396
  if (tx.data !== void 0 && tx.to && !pinned(provider.callTargets?.(chain), tx.to)) {
1384
1397
  return `${provider.name}: the route calls ${tx.to}, which the app did not pin as a call target on ${chain} (remoteProvider callTargets)`;
1385
1398
  }
1399
+ if (tx.data !== void 0 && provider.verifiesQuotes !== true && provider.verifiesBuilds !== true) {
1400
+ return `${provider.name}: the route's calldata is not checked by the app (remoteProvider verifyQuote / verifyBuild) \u2014 a pinned target alone does not say whom it pays`;
1401
+ }
1386
1402
  return null;
1387
1403
  }
1388
1404