@anywalletkit/protocol-swap2-omniston 0.2.3 → 0.2.4

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/provider.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  inMemorySecretStore,
8
8
  omnistonProvider,
9
9
  validateEvmToTonOrderExtension
10
- } from "./chunk-W3AXGSX3.js";
10
+ } from "./chunk-3CGSN2T6.js";
11
11
  import "./chunk-QDXFC6BC.js";
12
12
  import "./chunk-AIWAM7BS.js";
13
13
  export {
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(validators_exports);
40
40
 
41
41
  // src/validators/evm-output.ts
42
42
  var import_viem = require("viem");
43
+ var import_core = require("@anywalletkit/core");
43
44
  var ESCROW_FACTORY_ABI = [
44
45
  {
45
46
  type: "function",
@@ -210,10 +211,10 @@ function locateImmutables(input, secretHash) {
210
211
  try {
211
212
  const offset = word(7);
212
213
  if (offset % 32n !== 0n || offset < 288n || offset > 4096n) return null;
213
- const lengthAt = start + Number(offset) * 2;
214
+ const lengthAt = start + (0, import_core.bigintToNumber)(offset) * 2;
214
215
  if (data.length < lengthAt + 64) return null;
215
216
  const length = BigInt(`0x${data.slice(lengthAt, lengthAt + 64)}`);
216
- if (length > 1024n || data.length < lengthAt + 64 + Number(length) * 2) return null;
217
+ if (length > 1024n || data.length < lengthAt + 64 + (0, import_core.bigintToNumber)(length) * 2) return null;
217
218
  return {
218
219
  orderHash: `0x${data.slice(start, at)}`,
219
220
  hashlock: `0x${needle}`,
@@ -223,7 +224,7 @@ function locateImmutables(input, secretHash) {
223
224
  amount: word(4),
224
225
  safetyDeposit: word(5),
225
226
  timelocks: word(6),
226
- parameters: `0x${data.slice(lengthAt + 64, lengthAt + 64 + Number(length) * 2)}`
227
+ parameters: `0x${data.slice(lengthAt + 64, lengthAt + 64 + (0, import_core.bigintToNumber)(length) * 2)}`
227
228
  };
228
229
  } catch {
229
230
  return null;
@@ -528,7 +529,8 @@ function createOmnistonEvmInputValidator(options = {}) {
528
529
 
529
530
  // src/validators/ton.ts
530
531
  var import_buffer = require("buffer");
531
- var import_core = require("@ton/core");
532
+ var import_core2 = require("@ton/core");
533
+ var import_core3 = require("@anywalletkit/core");
532
534
  var JETTON_TRANSFER_OP = 260734629;
533
535
  var ESCROW_CREATE_OP = 3232100569;
534
536
  var ESCROW_CONFIG_OP = 4073126499;
@@ -564,7 +566,7 @@ var DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS = [
564
566
  // pTON v2
565
567
  ];
566
568
  function cellFromApi(value) {
567
- const roots = import_core.Cell.fromBoc(import_buffer.Buffer.from(value, /^b5ee9c/i.test(value) ? "hex" : "base64"));
569
+ const roots = import_core2.Cell.fromBoc(import_buffer.Buffer.from(value, /^b5ee9c/i.test(value) ? "hex" : "base64"));
568
570
  if (roots.length !== 1) throw new Error("omniston TON validator: account cell must have one root");
569
571
  return roots[0];
570
572
  }
@@ -606,7 +608,7 @@ function validateOutputPositionState(data, input, expected) {
606
608
  return null;
607
609
  }
608
610
  const partySlice = parties.beginParse();
609
- if (!(partySlice.loadAddressAny() instanceof import_core.Address)) {
611
+ if (!(partySlice.loadAddressAny() instanceof import_core2.Address)) {
610
612
  lastStateRefusal = "state#9: if (!(partySlice.loadAddressAny() instanceof Address)) return null; // owner (resolver) \u2014 any";
611
613
  return null;
612
614
  }
@@ -660,7 +662,7 @@ function validateOutputPositionState(data, input, expected) {
660
662
  lastStateRefusal = "state#20: if (!sameAddress(terms.loadAddressAny(), input.recipientAddress)) return null;";
661
663
  return null;
662
664
  }
663
- if (!(terms.loadAddressAny() instanceof import_core.Address)) {
665
+ if (!(terms.loadAddressAny() instanceof import_core2.Address)) {
664
666
  lastStateRefusal = "state#21: if (!(terms.loadAddressAny() instanceof Address)) return null; // resolver \u2014 any";
665
667
  return null;
666
668
  }
@@ -686,13 +688,13 @@ function validateOutputPositionState(data, input, expected) {
686
688
  }
687
689
  function oneRoot(hex, label) {
688
690
  if (!/^(?:[0-9a-fA-F]{2})+$/.test(hex)) throw new Error(`omniston TON validator: malformed ${label} hex`);
689
- const roots = import_core.Cell.fromBoc(import_buffer.Buffer.from(hex, "hex"));
691
+ const roots = import_core2.Cell.fromBoc(import_buffer.Buffer.from(hex, "hex"));
690
692
  if (roots.length !== 1) throw new Error(`omniston TON validator: ${label} must have one root`);
691
693
  return roots[0];
692
694
  }
693
695
  function sameAddress(actual, expected) {
694
696
  try {
695
- return actual instanceof import_core.Address && actual.equals(import_core.Address.parse(expected));
697
+ return actual instanceof import_core2.Address && actual.equals(import_core2.Address.parse(expected));
696
698
  } catch {
697
699
  return false;
698
700
  }
@@ -778,7 +780,7 @@ function createOmnistonTonValidators(options = {}) {
778
780
  const now = options.now ?? Date.now;
779
781
  const swapInterfaces = new Set(options.swapTargetInterfaces ?? DEFAULT_OMNISTON_TON_SWAP_INTERFACES);
780
782
  const proxyTonMasters = new Set(
781
- (options.proxyTonMasters ?? DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS).map((value) => import_core.Address.parse(value).toRawString())
783
+ (options.proxyTonMasters ?? DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS).map((value) => import_core2.Address.parse(value).toRawString())
782
784
  );
783
785
  const request = options.fetch ?? fetch;
784
786
  const base = (options.tonApiUrl ?? "https://tonapi.io").replace(/\/$/, "");
@@ -800,7 +802,7 @@ function createOmnistonTonValidators(options = {}) {
800
802
  };
801
803
  const stackCell = (entry) => entry && (entry.type === "cell" || entry.type === "slice") && entry.cell ? cellFromApi(entry.cell) : null;
802
804
  const derivedWallet = async (master, owner) => {
803
- const cell = stackCell((await runGet(master, "get_wallet_address", [import_core.Address.parse(owner).toRawString()]))?.[0]);
805
+ const cell = stackCell((await runGet(master, "get_wallet_address", [import_core2.Address.parse(owner).toRawString()]))?.[0]);
804
806
  return cell ? cell.beginParse().loadAddress() : null;
805
807
  };
806
808
  const walletData = async (wallet) => {
@@ -813,10 +815,10 @@ function createOmnistonTonValidators(options = {}) {
813
815
  const response = await getRetry(`/v2/accounts/${encodeURIComponent(address)}`);
814
816
  if (!response.ok) return false;
815
817
  const body = await response.json();
816
- return !!body.address && sameAddress(import_core.Address.parse(body.address), address) && body.is_wallet !== true && (body.interfaces ?? []).includes(iface);
818
+ return !!body.address && sameAddress(import_core2.Address.parse(body.address), address) && body.is_wallet !== true && (body.interfaces ?? []).includes(iface);
817
819
  };
818
820
  const samePair = (pool, leg) => {
819
- const key = (value) => value === null ? "native" : import_core.Address.parse(value).toRawString();
821
+ const key = (value) => value === null ? "native" : import_core2.Address.parse(value).toRawString();
820
822
  const a = pool.map(key).sort();
821
823
  const b = leg.map(key).sort();
822
824
  return a.length === 2 && a[0] === b[0] && a[1] === b[1] && a[0] !== a[1];
@@ -825,7 +827,7 @@ function createOmnistonTonValidators(options = {}) {
825
827
  const response = await get(`/v2/accounts/${encodeURIComponent(address)}`);
826
828
  if (!response.ok) return null;
827
829
  const body = await response.json();
828
- if (!body.address || !sameAddress(import_core.Address.parse(body.address), address)) return null;
830
+ if (!body.address || !sameAddress(import_core2.Address.parse(body.address), address)) return null;
829
831
  return { interfaces: body.interfaces ?? [], isWallet: body.is_wallet === true };
830
832
  };
831
833
  const isDexContract = (account) => !account.isWallet && account.interfaces.some((name) => swapInterfaces.has(name));
@@ -841,8 +843,8 @@ function createOmnistonTonValidators(options = {}) {
841
843
  if (!response.ok) return null;
842
844
  const body = await response.json();
843
845
  const wallet = body.wallet_address?.address;
844
- if (!wallet || body.jetton?.address !== void 0 && !sameAddress(import_core.Address.parse(body.jetton.address), jettonMasterAddress)) return null;
845
- return import_core.Address.parse(wallet).toString();
846
+ if (!wallet || body.jetton?.address !== void 0 && !sameAddress(import_core2.Address.parse(body.jetton.address), jettonMasterAddress)) return null;
847
+ return import_core2.Address.parse(wallet).toString();
846
848
  };
847
849
  return {
848
850
  async validateTonJettonWallet({ ownerAddress, jettonMasterAddress, walletAddress }) {
@@ -854,8 +856,8 @@ function createOmnistonTonValidators(options = {}) {
854
856
  });
855
857
  if (!response.ok) return false;
856
858
  const body = await response.json();
857
- if (!sameAddress(body.wallet_address?.address ? import_core.Address.parse(body.wallet_address.address) : null, walletAddress)) return false;
858
- return body.jetton?.address === void 0 || sameAddress(import_core.Address.parse(body.jetton.address), jettonMasterAddress);
859
+ if (!sameAddress(body.wallet_address?.address ? import_core2.Address.parse(body.wallet_address.address) : null, walletAddress)) return false;
860
+ return body.jetton?.address === void 0 || sameAddress(import_core2.Address.parse(body.jetton.address), jettonMasterAddress);
859
861
  } catch {
860
862
  return false;
861
863
  }
@@ -887,14 +889,14 @@ function createOmnistonTonValidators(options = {}) {
887
889
  };
888
890
  lastStateRefusal = null;
889
891
  try {
890
- import_core.Address.parse(input.positionAddress);
891
- import_core.Address.parse(input.recipientAddress);
892
+ import_core2.Address.parse(input.positionAddress);
893
+ import_core2.Address.parse(input.recipientAddress);
892
894
  const nowSeconds = Math.floor(now() / 1e3);
893
895
  if (!Number.isInteger(input.quoteTimestamp) || input.quoteTimestamp > nowSeconds + 120 || nowSeconds - input.quoteTimestamp > 6 * 60 * 60) return refuse("quote-age");
894
896
  const accountResponse = await get(`/v2/blockchain/accounts/${encodeURIComponent(input.positionAddress)}`);
895
897
  if (!accountResponse.ok) return refuse("account-fetch", { status: accountResponse.status });
896
898
  const account = await accountResponse.json();
897
- if (!account.address || !sameAddress(import_core.Address.parse(account.address), input.positionAddress) || account.status !== "active" || !account.code || !account.data) return refuse("account-state", { status: account.status, hasCode: !!account.code, hasData: !!account.data });
899
+ if (!account.address || !sameAddress(import_core2.Address.parse(account.address), input.positionAddress) || account.status !== "active" || !account.code || !account.data) return refuse("account-state", { status: account.status, hasCode: !!account.code, hasData: !!account.data });
898
900
  if (!trusted.position.has(cellFromApi(account.code).hash().toString("hex"))) return refuse("position-code-hash", { hash: cellFromApi(account.code).hash().toString("hex") });
899
901
  const jettonWallet = await jettonWalletOf(input.protocolAddress, input.outputJettonMasterAddress);
900
902
  if (!jettonWallet) return refuse("jetton-wallet");
@@ -903,7 +905,7 @@ function createOmnistonTonValidators(options = {}) {
903
905
  const txResponse = await get(`/v2/blockchain/accounts/${encodeURIComponent(input.positionAddress)}/transactions?limit=25`);
904
906
  if (!txResponse.ok) return refuse("transactions-fetch", { status: txResponse.status });
905
907
  const body = await txResponse.json();
906
- const deployedByFactory = (body.transactions ?? []).some((tx) => tx.success === true && tx.aborted !== true && tx.in_msg?.op_code?.toLowerCase() === POSITION_DEPLOY_OP && !!tx.in_msg.source?.address && sameAddress(import_core.Address.parse(tx.in_msg.source.address), input.protocolAddress) && typeof tx.utime === "number" && Math.abs(Number(state.withdrawalAt) - 1 - tx.utime) <= 5);
908
+ const deployedByFactory = (body.transactions ?? []).some((tx) => tx.success === true && tx.aborted !== true && tx.in_msg?.op_code?.toLowerCase() === POSITION_DEPLOY_OP && !!tx.in_msg.source?.address && sameAddress(import_core2.Address.parse(tx.in_msg.source.address), input.protocolAddress) && typeof tx.utime === "number" && Math.abs((0, import_core3.bigintToNumber)(BigInt(state.withdrawalAt)) - 1 - tx.utime) <= 5);
907
909
  return deployedByFactory || refuse("deploy-transaction", { transactions: (body.transactions ?? []).length });
908
910
  } catch (error) {
909
911
  return refuse("error", { message: error instanceof Error ? error.message : String(error) });
@@ -922,7 +924,7 @@ function createOmnistonTonValidators(options = {}) {
922
924
  async validateTonSwapLeg(leg) {
923
925
  try {
924
926
  if (leg.kind === "stonfi-router") {
925
- let router = leg.router ? import_core.Address.parse(leg.router) : null;
927
+ let router = leg.router ? import_core2.Address.parse(leg.router) : null;
926
928
  if (leg.proxyTonWallet) {
927
929
  const data = await walletData(leg.proxyTonWallet);
928
930
  if (!data || !proxyTonMasters.has(data.master.toRawString())) return false;
@@ -934,7 +936,7 @@ function createOmnistonTonValidators(options = {}) {
934
936
  const masters = leg.outputJetton ? [leg.outputJetton] : [...proxyTonMasters];
935
937
  for (const master of masters) {
936
938
  const wallet = await derivedWallet(master, router.toString());
937
- if (wallet && wallet.equals(import_core.Address.parse(leg.askWallet))) return true;
939
+ if (wallet && wallet.equals(import_core2.Address.parse(leg.askWallet))) return true;
938
940
  }
939
941
  return false;
940
942
  }
@@ -947,7 +949,7 @@ function createOmnistonTonValidators(options = {}) {
947
949
  const tag = slice.loadUint(4);
948
950
  if (tag === 0) return null;
949
951
  if (tag !== 1) return void 0;
950
- return new import_core.Address(slice.loadInt(8), slice.loadBuffer(32)).toString();
952
+ return new import_core2.Address(slice.loadInt(8), slice.loadBuffer(32)).toString();
951
953
  });
952
954
  if (assets2.some((asset) => asset === void 0)) return false;
953
955
  return samePair(assets2, [leg.inputJetton, leg.outputJetton]);
@@ -958,7 +960,7 @@ function createOmnistonTonValidators(options = {}) {
958
960
  if (!cell) return void 0;
959
961
  const address = cell.beginParse().loadAddressAny();
960
962
  if (address === null) return null;
961
- return address instanceof import_core.Address ? address.toString() : void 0;
963
+ return address instanceof import_core2.Address ? address.toString() : void 0;
962
964
  });
963
965
  if (assets.some((asset) => asset === void 0)) return false;
964
966
  return samePair(assets, [leg.inputJetton, leg.outputJetton]);
@@ -971,7 +973,7 @@ function createOmnistonTonValidators(options = {}) {
971
973
  * resolver-deployed proxy is refused. */
972
974
  async validateTonSwapTarget({ address }) {
973
975
  try {
974
- import_core.Address.parse(address);
976
+ import_core2.Address.parse(address);
975
977
  const account = await readAccount(address);
976
978
  if (!account || account.isWallet) return false;
977
979
  if (isDexContract(account)) return true;
@@ -981,7 +983,7 @@ function createOmnistonTonValidators(options = {}) {
981
983
  const body = await data.json();
982
984
  const owner = body.decoded?.owner;
983
985
  const master = body.decoded?.jetton;
984
- if (!body.success || !owner || !master || !proxyTonMasters.has(import_core.Address.parse(master).toRawString())) return false;
986
+ if (!body.success || !owner || !master || !proxyTonMasters.has(import_core2.Address.parse(master).toRawString())) return false;
985
987
  const ownerAccount = await readAccount(owner);
986
988
  return ownerAccount !== null && isDexContract(ownerAccount);
987
989
  } catch {
@@ -997,9 +999,9 @@ function createOmnistonTonDeliveryLocator(options = {}) {
997
999
  const limit = Math.min(100, Math.max(1, Math.floor(options.limit ?? 20)));
998
1000
  return async (input) => {
999
1001
  try {
1000
- const recipient = import_core.Address.parse(input.recipientAddress);
1001
- const master = import_core.Address.parse(input.jettonMasterAddress);
1002
- const position = input.positionAddress ? import_core.Address.parse(input.positionAddress) : null;
1002
+ const recipient = import_core2.Address.parse(input.recipientAddress);
1003
+ const master = import_core2.Address.parse(input.jettonMasterAddress);
1004
+ const position = input.positionAddress ? import_core2.Address.parse(input.positionAddress) : null;
1003
1005
  const min = BigInt(input.minUnits);
1004
1006
  if (min <= 0n) return null;
1005
1007
  const since = Number.isFinite(input.afterTimestamp) ? `&start_date=${Math.max(0, Math.floor(input.afterTimestamp))}` : "";
@@ -1018,9 +1020,9 @@ function createOmnistonTonDeliveryLocator(options = {}) {
1018
1020
  if (action.type !== "JettonTransfer" || action.status !== "ok") continue;
1019
1021
  const t = action.JettonTransfer;
1020
1022
  if (!t?.jetton?.address || !t.recipient?.address || t.amount === void 0) continue;
1021
- if (!sameAddress(import_core.Address.parse(t.jetton.address), master.toString())) continue;
1022
- if (!sameAddress(import_core.Address.parse(t.recipient.address), recipient.toString())) continue;
1023
- if (position && (!t.sender?.address || !sameAddress(import_core.Address.parse(t.sender.address), position.toString()))) continue;
1023
+ if (!sameAddress(import_core2.Address.parse(t.jetton.address), master.toString())) continue;
1024
+ if (!sameAddress(import_core2.Address.parse(t.recipient.address), recipient.toString())) continue;
1025
+ if (position && (!t.sender?.address || !sameAddress(import_core2.Address.parse(t.sender.address), position.toString()))) continue;
1024
1026
  let amount;
1025
1027
  try {
1026
1028
  amount = BigInt(t.amount);