@anywalletkit/protocol-swap2-core 0.7.0 → 0.8.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-CRCDWV3L.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
  }
@@ -1373,8 +1379,13 @@ function validQuote(q, params, provider) {
1373
1379
  }
1374
1380
  }
1375
1381
  function remotePinRefusal(provider, q, chain) {
1376
- if (provider.remote !== true || !chain.startsWith("eip155:")) return null;
1382
+ if (provider.remote !== true) return null;
1377
1383
  const tx = q.txRequest;
1384
+ const plain = tx ? tx.data === void 0 && tx.serializedTx === void 0 : typeof q.depositAddress === "string" && q.depositAddress !== "";
1385
+ if (plain && provider.depositAddressRoutes !== true) {
1386
+ 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)`;
1387
+ }
1388
+ if (!chain.startsWith("eip155:")) return null;
1378
1389
  if (!tx || tx.serializedTx !== void 0) return null;
1379
1390
  const pinned = (list, address) => (list ?? []).some((a) => typeof a === "string" && a.toLowerCase() === address.toLowerCase());
1380
1391
  if (tx.approvalAddress && !pinned(provider.spenders?.(chain), tx.approvalAddress)) {