var pt = Object.defineProperty;
var wt = (a, t, e) => t in a ? pt(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
var c = (a, t, e) => wt(a, typeof t != "symbol" ? t + "" : t, e);
import { b4 as Ct, aL as bt, b5 as Et, b6 as At, b7 as yt, b8 as xt, b9 as Dt, ba as Ft, bb as vt, bc as Bt, bd as St, aJ as Oe, D as E, be as W, aP as A, ac as Le, aR as te, aU as T, aV as Ge, aN as Qe, a_ as q, a3 as k, aW as je, q as Tt, af as C, as as We, aG as Ie, av as qe, d as O, ao as It, at as Ke, b1 as ne, b2 as Mt, ap as Pt, aX as kt, b3 as Ut, E as zt, W as B, aA as v, bf as Xe, u as ue, p as Ze, bg as He, _ as Vt, y as Je, T as b, A as Ye, x as et, f as x, ag as fe, i as L, ak as I, z as ae, B as se, c as R } from "./address-BkeBsCZD.mjs";
import { r as U } from "./chain-uXEmLNMk.mjs";
import { l as Me } from "./chunk-KJH4KKG6-CCerRpgp.mjs";
import { A as $t } from "./platform-BVScq6Cn.mjs";
import { A as Pe, _ as Rt } from "./address-xvE59bSC.mjs";
import { A as Nt } from "./unsignedTransaction-BDOQhqcZ.mjs";
import { E as G } from "./platform-tSU41623.mjs";
import { C as N } from "./contract-C26uilM9.mjs";
import { E as tt } from "./unsignedTransaction-C0V0UbsS.mjs";
import { b as ke, T as _t, a as Ot, _ as Lt } from "./platform-ByoVE-An.mjs";
import { suiCircleObjects as Gt } from "./index-CRYNS9pm.mjs";
import { S as Qt, R as nt } from "./address-CHEvC20V.mjs";
import { S as jt } from "./unsignedTransaction-BD81leu1.mjs";
import { createDepositForBurnInstruction as Wt } from "./index-B2v8cGyE.mjs";
import { P as qt } from "./index-CIGkn9tA.mjs";
import { p as Ue, u as at, b as Kt } from "./web3-L0yKkQfC.mjs";
import { a as Xt, S as Zt } from "./unsignedTransaction-DkC9OIgh.mjs";
import { d as Ht } from "./account-DRrQuG9b.mjs";
const Jt = {
  binary: "uint",
  size: 1,
  custom: {
    to: (a) => a > 0,
    from: (a) => a ? 1 : 0
  }
}, Yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  amountItem: Ct,
  boolItem: Jt,
  chainItem: bt,
  circleDomainItem: Et,
  circleNonceItem: At,
  fixedChainItem: yt,
  fixedLengthStringItem: xt,
  guardianSetItem: Dt,
  payloadIdItem: Ft,
  sequenceItem: vt,
  signatureItem: Bt,
  stringConversion: St,
  universalAddressItem: Oe
}, Symbol.toStringTag, { value: "Module" })), me = {
  Testnet: "https://executor-testnet.labsapis.com",
  Mainnet: "https://executor.labsapis.com"
}, le = {
  Testnet: {
    Aptos: "0x14a12d1fd6ef371b70c2113155534ec152ec7f779e281b54866c796c9a4a58d3",
    Avalanche: "0x2cfEC91B50f657Cc86Ec693542527ac3e03bF742",
    BaseSepolia: "0x4983C6bD3bB7DA9EECe71cfa7AE4C67CAbf362F0",
    Sepolia: "0x0F78904c750801391EbBf308181e9d6fc892B0f3",
    Solana: "CXGRA5SCc8jxDbaQPZrmmZNu2JV34DP7gFW4m31uC1zs"
  },
  Mainnet: {
    Aptos: "0x9f5ad7d5c2d067ca4abb6d8d6aba44c15596b71a1def8eb4596089b527bb2eb1",
    Arbitrum: "0x55Dd4466BFec29527C54A72fd306efb54e5F7027",
    Avalanche: "0xd331819478b74d8a7B8EA631118B4a4e50F6EbD1",
    Base: "0x08FEB1838C3d7F8509DA1EBb9a11a94c1f006cb2",
    Ethereum: "0xeEFb36c4458dA7798742cf038C5c27E07aB9c51E",
    Optimism: "0xBC6f9d1CBa49DB365728478cefa02F6743617637",
    Polygon: "0x007995f2AEcfBC745f20a7AE8D3a02c0EbF46264",
    Unichain: "0xA7aBDb8f2108901c586543BD5e10E4fA263F4A47",
    Solana: "CXGRA5SCc8jxDbaQPZrmmZNu2JV34DP7gFW4m31uC1zs"
  }
}, en = {
  Testnet: {
    Avalanche: "0x4058F0C3924eDaB19c15597C438968ed49C1a213",
    BaseSepolia: "0xC400FcC0e92d3406747FBb6f513D3aa8B038fcE9",
    Sepolia: "0x0F18DD26D0B41fb1eaa9cF34D1Ec6022aA69a8e2"
  },
  Mainnet: {
    Arbitrum: "0x8442d68524217601ed126f6859694E4B0C7c66A1",
    Avalanche: "0x3952914628650Ca510404872D84DfF10A844C5B5",
    Base: "0xbd8d42f40a11b37bD1b3770D754f9629F7cd5679",
    Ethereum: "0x2cCf230467FE7387674BAa657747F0B5485c7fEC",
    Linea: "0xc48c126468BE919068dE1983F00F65af759a4E87",
    Sonic: "0xc39BF082ec91D9bC385F956D24a8D66C0c26223d"
  }
}, ze = {
  Testnet: {
    executorId: "0x4000cfe2955d8355b3d3cf186f854fea9f787a457257056926fde1ec977670eb",
    executorRequestsId: "0x2d9ccf3cce3f7dce408e5455e90b80a8161ad9673d1366c2a5def60ad93657a8"
  },
  Mainnet: {
    executorId: "0xdb0fe8bb1e2b5be628adbea0636063325073e1070ee11e4281457dfd7f158235",
    executorRequestsId: "0xc030df7a3eed1494fa4b64aa8ab63a79041cf1114f4ff2b7ab5aca1c684a21a7"
  }
}, tn = {
  Testnet: "execXUrAsMnqMmTHj5m7N1YQgsDz3cwGLYCYyuDRciV",
  Mainnet: "execXUrAsMnqMmTHj5m7N1YQgsDz3cwGLYCYyuDRciV"
}, nn = 5001n, an = {
  Testnet: {
    Aptos: 5000n,
    ArbitrumSepolia: 500000n,
    Avalanche: 200000n,
    BaseSepolia: 200000n,
    Linea: 250000n,
    Sepolia: 200000n,
    Solana: 250000n,
    Sonic: 250000n,
    Sui: 8000000n
  },
  Mainnet: {
    Aptos: 5000n,
    Arbitrum: 500000n,
    Avalanche: 250000n,
    Base: 250000n,
    Ethereum: 250000n,
    Linea: 250000n,
    Optimism: 250000n,
    Polygon: 250000n,
    Unichain: 250000n,
    Solana: 250000n,
    Sonic: 250000n,
    Sui: 8000000n
  }
}, sn = {
  Testnet: {
    Aptos: "0x23b54f6e29bba7f4123d088f4cfcd83f5e23a049de15895b119ce5a6cb5faa91",
    Avalanche: "0x8F26A0025dcCc6Cfc07A7d38756280a10E295ad7",
    BaseSepolia: "0x8F26A0025dcCc6Cfc07A7d38756280a10E295ad7",
    Sepolia: "0x8F26A0025dcCc6Cfc07A7d38756280a10E295ad7",
    Solana: "9r6q2iEg4MBevjC8reaLmQUDxueF3vabUoqDkZ2LoAYe",
    Sui: "0x30bd9b3d5ad00f38fd0c314139ba47ccb3c78353d99880d81125ca0c370b415e"
  },
  Mainnet: {
    Aptos: "0x1f177e724a874ab6267172a3049291c480fc665883e6a3ac95d0909492c09dc8",
    Arbitrum: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Avalanche: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Base: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Ethereum: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Optimism: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Linea: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Polygon: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Unichain: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Solana: "JB3rmygUVuVZzgkxvMdV8mSKLJeQAkSXEK284Dqsziah",
    Sonic: "0xF11e0efF8b11Ce382645dd75352fC16b3aB3551E",
    Sui: "0xbfa1240e48c622d97881473953be730091161b7931d89bd6afe667841cf69ef4"
  }
}, rn = {
  Testnet: {
    ArbitrumSepolia: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    },
    Avalanche: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    },
    BaseSepolia: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    },
    Linea: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    },
    Sepolia: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    },
    Sonic: {
      tokenMessengerV2: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
      messageTransmitterV2: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275"
    }
  },
  Mainnet: {
    Arbitrum: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Avalanche: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Base: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Ethereum: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Linea: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Sonic: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    }
  }
}, st = {
  Testnet: {
    Sepolia: 0,
    Avalanche: 1,
    OptimismSepolia: 2,
    ArbitrumSepolia: 3,
    Solana: 5,
    BaseSepolia: 6,
    Polygon: 7,
    Sui: 8,
    Aptos: 9,
    Unichain: 10
  },
  Mainnet: {
    Ethereum: 0,
    Avalanche: 1,
    Optimism: 2,
    Arbitrum: 3,
    Solana: 5,
    Base: 6,
    Polygon: 7,
    Sui: 8,
    Aptos: 9,
    Unichain: 10
  }
}, z = (a, t) => {
  var e;
  return ((e = st[a]) == null ? void 0 : e[t]) !== void 0;
}, K = {
  Testnet: {
    Sepolia: 0,
    Avalanche: 1,
    ArbitrumSepolia: 3,
    BaseSepolia: 6,
    Linea: 11,
    Sonic: 13
  },
  Mainnet: {
    Ethereum: 0,
    Avalanche: 1,
    Arbitrum: 3,
    Base: 6,
    Linea: 11,
    Sonic: 13
  }
}, re = (a, t) => {
  var e;
  return ((e = K[a]) == null ? void 0 : e[t]) !== void 0;
}, Q = (a, t) => {
  var n;
  const e = (n = K[a]) == null ? void 0 : n[t];
  if (e === void 0)
    throw new Error(`CircleV2 domain not found for network ${a} and chain ${t}`);
  return e;
}, rt = (a, t) => {
  var n;
  const e = (n = Object.entries(K[a] ?? {}).find(([, s]) => s === t)) == null ? void 0 : n[0];
  if (e === void 0)
    throw new Error(`CircleV2 chain not found for network ${a} and domain ${t}`);
  return e;
}, X = {
  Testnet: "https://iris-api-sandbox.circle.com/v2",
  Mainnet: "https://iris-api.circle.com/v2"
};
var j;
(function(a) {
  a[a.CONFIRMED = 1e3] = "CONFIRMED", a[a.FINALIZED = 2e3] = "FINALIZED";
})(j || (j = {}));
const it = {
  // milliseconds
  Testnet: {
    ArbitrumSepolia: 8e3,
    BaseSepolia: 8e3,
    Sepolia: 2e4,
    Linea: 8e3
  },
  Mainnet: {
    Arbitrum: 8e3,
    Base: 8e3,
    Ethereum: 2e4,
    Linea: 8e3
  }
}, on = (a, t) => {
  var e;
  return ((e = it[a]) == null ? void 0 : e[t]) !== void 0;
};
class he {
  constructor(t, e, n, s) {
    c(this, "network");
    c(this, "chain");
    c(this, "provider");
    c(this, "contracts");
    c(this, "usdcId");
    c(this, "shimContract");
    var o;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = s, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    const r = E.get(this.network, this.chain);
    if (!r)
      throw new Error(`No USDC contract configured for network=${this.network} chain=${this.chain}`);
    this.usdcId = r;
    const i = (o = le[t]) == null ? void 0 : o[e];
    if (!i)
      throw new Error(`Shim contract for ${e} not found`);
    this.shimContract = i;
  }
  static async fromRpc(t, e) {
    const [n, s] = await $t.chainFromRpc(t), r = e[s];
    if (!r)
      throw new Error(`No config found for ${s}`);
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new he(n, s, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const s = new Pe(t).unwrap(), r = Me.from(e.address.toUniversalAddress().toUint8Array()), i = Me.from(this.usdcId), o = n.remainingAmount + n.referrerFee, d = W.get(this.network, e.chain), u = s, f = new Pe(n.referrer.address.toString()).unwrap(), m = [
      o,
      d,
      r.toString(),
      i.toString(),
      n.estimatedCost,
      A(e.chain),
      u,
      n.signedQuote,
      n.relayInstructions,
      n.referrerFeeDbps,
      f
    ], l = {
      function: `${this.shimContract}::cctp_v1_with_executor::deposit_for_burn_entry`,
      functionArguments: m
    };
    yield this.createUnsignedTx(l, "AtposCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new Nt(t, this.network, this.chain, e, n);
  }
}
U(Rt, "CCTPExecutor", he);
class ge {
  constructor(t, e, n, s) {
    c(this, "network");
    c(this, "chain");
    c(this, "provider");
    c(this, "contracts");
    c(this, "chainId");
    c(this, "shimContract");
    var i;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = s, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    this.chainId = Le.get(t, e);
    const r = (i = le[t]) == null ? void 0 : i[e];
    if (!r)
      throw new Error(`Shim contract for ${e} not found`);
    this.shimContract = r;
  }
  static async fromRpc(t, e) {
    const [n, s] = await G.chainFromRpc(t), r = e[s];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new ge(n, s, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const s = new te(t).toString(), r = e.address.toUniversalAddress().toUint8Array(), i = n.remainingAmount + n.referrerFee, o = E.get(this.network, this.chain), d = G.getTokenImplementation(this.provider, o);
    if (await d.allowance(s, this.shimContract) < i) {
      const h = await d.approve.populateTransaction(this.shimContract, i);
      yield this.createUnsignedTx(T(h, s), "ERC20.approve of EvmCCTPExecutor", !1);
    }
    const f = [
      "function depositForBurn(uint256 amount, uint16 destinationChain, uint32 destinationDomain, bytes32 mintRecipient, address burnToken, (address refundAddress, bytes signedQuote, bytes instructions) executorArgs, (uint16 dbps, address payee) feeArgs) external payable returns (uint64 nonce)"
    ], l = await new N(this.shimContract, f, this.provider).getFunction("depositForBurn").populateTransaction(i, A(e.chain), W.get(this.network, e.chain), r, o, {
      refundAddress: s,
      signedQuote: n.signedQuote,
      instructions: n.relayInstructions
    }, {
      dbps: n.referrerFeeDbps,
      payee: n.referrer.address.toString()
    });
    l.value = n.estimatedCost, yield this.createUnsignedTx(T(l, s), "EvmCCTPExecutor.depositForBurn");
  }
  createUnsignedTx(t, e, n = !1) {
    return new tt(Ge(t, this.chainId), this.network, this.chain, e, n);
  }
}
const { amountItem: V, circleDomainItem: Ve, universalAddressItem: S } = Yt, ot = {
  binary: "uint",
  size: 4,
  custom: 1,
  omit: !1
}, cn = {
  binary: "bytes",
  size: 32
}, $e = {
  binary: "uint",
  size: 4
}, dn = [
  { name: "version", ...ot },
  { name: "burnToken", ...S },
  { name: "mintRecipient", ...S },
  { name: "amount", ...V },
  { name: "messageSender", ...S },
  { name: "maxFee", ...V },
  { name: "feeExecuted", ...V },
  { name: "expirationBlock", ...V },
  { name: "hookData", binary: "bytes" }
], ct = [
  { name: "version", ...ot },
  { name: "sourceDomain", ...Ve },
  { name: "destinationDomain", ...Ve },
  { name: "nonce", ...cn },
  { name: "sender", ...S },
  { name: "recipient", ...S },
  { name: "destinationCaller", ...S },
  { name: "minFinalityThreshold", ...$e },
  { name: "finalityThresholdExecuted", ...$e },
  { name: "messageBody", binary: "bytes", layout: dn }
], un = (a) => q(ct, a), fn = (a) => Qe(ct, a), mn = [
  { name: "gasLimit", binary: "uint", size: 16 },
  { name: "msgValue", binary: "uint", size: 16 }
], ln = [
  { name: "dropOff", binary: "uint", size: 16 },
  { name: "recipient", ...Oe }
], hn = [
  {
    name: "request",
    binary: "switch",
    idSize: 1,
    idTag: "type",
    layouts: [
      [[1, "GasInstruction"], mn],
      [[2, "GasDropOffInstruction"], ln]
    ]
  }
], dt = [
  {
    name: "requests",
    binary: "array",
    layout: hn
  }
], gn = {
  to: (a) => new Date(Number(a * 1000n)),
  from: (a) => BigInt(a.getTime()) / 1000n
}, pn = [
  {
    name: "quote",
    binary: "switch",
    idSize: 4,
    idTag: "prefix",
    layouts: [
      [
        [1162948657, "EQ01"],
        [
          {
            name: "quoterAddress",
            binary: "bytes",
            size: 20
          },
          {
            name: "payeeAddress",
            binary: "bytes",
            size: 32
          },
          { name: "srcChain", binary: "uint", size: 2 },
          { name: "dstChain", binary: "uint", size: 2 },
          {
            name: "expiryTime",
            binary: "uint",
            size: 8,
            custom: gn
          },
          { name: "baseFee", binary: "uint", size: 8 },
          { name: "dstGasPrice", binary: "uint", size: 8 },
          { name: "srcPrice", binary: "uint", size: 8 },
          { name: "dstPrice", binary: "uint", size: 8 }
        ]
      ]
    ]
  }
], ut = [
  ...pn,
  { name: "signature", binary: "bytes", size: 65 }
];
class pe {
  constructor(t, e, n, s) {
    c(this, "network");
    c(this, "chain");
    c(this, "provider");
    c(this, "contracts");
    c(this, "chainId");
    c(this, "shimContract");
    c(this, "messageTransmitter");
    c(this, "usdcContract");
    var d, u, f;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = s, t === "Devnet")
      throw new Error("CCTPv2Executor not supported on Devnet");
    this.chainId = Le.get(t, e);
    const r = (d = en[t]) == null ? void 0 : d[e];
    if (!r)
      throw new Error(`Shim contract for ${e} not found`);
    this.shimContract = r;
    const i = (f = (u = rn[t]) == null ? void 0 : u[e]) == null ? void 0 : f.messageTransmitterV2;
    if (!i)
      throw new Error(`MessageTransmitter contract for ${e} not found`);
    this.messageTransmitter = i;
    const o = E.get(t, e);
    if (!o)
      throw new Error(`USDC contract for ${e} not found`);
    this.usdcContract = o;
  }
  static async fromRpc(t, e) {
    const [n, s] = await G.chainFromRpc(t), r = e[s];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new pe(n, s, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const s = new te(t).toString(), r = e.address.toUniversalAddress().toUint8Array(), i = n.remainingAmount + n.referrerFee, o = G.getTokenImplementation(this.provider, this.usdcContract);
    if (await o.allowance(s, this.shimContract) < i) {
      const g = await o.approve.populateTransaction(this.shimContract, i);
      yield this.createUnsignedTx(T(g, s), "ERC20.approve of EvmCCTPv2Executor", !1);
    }
    const u = [
      "function depositForBurn(uint256 amount, uint16 destinationChain, uint32 destinationDomain, bytes32 mintRecipient, address burnToken, bytes32 destinationCaller, uint256 maxFee, uint32 minFinalityThreshold, (address refundAddress, bytes signedQuote, bytes instructions) executorArgs, (uint16 dbps, address payee) feeArgs) external payable returns (uint64 nonce)"
    ], f = new Uint8Array(32), m = new N(this.shimContract, u, this.provider), l = Q(this.network, e.chain), h = await m.getFunction("depositForBurn").populateTransaction(i, A(e.chain), l, r, this.usdcContract, f, n.fastTransferMaxFee, n.minFinalityThreshold, {
      refundAddress: s,
      signedQuote: n.signedQuote,
      instructions: n.relayInstructions
    }, {
      dbps: n.referrerFeeDbps,
      payee: n.referrer.address.toString()
    });
    h.value = n.estimatedCost, yield this.createUnsignedTx(T(h, s), "EvmCCTPv2Executor.depositForBurn");
  }
  async isTransferCompleted(t) {
    return await new N(this.messageTransmitter, ["function usedNonces(bytes32) public view returns (uint256)"], this.provider).getFunction("usedNonces").staticCall(t.nonce) === 1n;
  }
  async *redeem(t, e, n) {
    const s = new te(t).toString(), i = await new N(this.messageTransmitter, ["function receiveMessage(bytes message, bytes attestation)"], this.provider).getFunction("receiveMessage").populateTransaction(fn(e), k.decode(n));
    yield this.createUnsignedTx(T(i, s), "MessageTransmitterV2.receiveMessage");
  }
  async getCurrentBlock() {
    return BigInt(await this.provider.getBlockNumber());
  }
  createUnsignedTx(t, e, n = !1) {
    return new tt(Ge(t, this.chainId), this.network, this.chain, e, n);
  }
}
U(je, "CCTPExecutor", ge);
U(je, "CCTPv2Executor", pe);
class we {
  constructor(t, e, n, s) {
    c(this, "network");
    c(this, "chain");
    c(this, "provider");
    c(this, "contracts");
    c(this, "usdcId");
    c(this, "usdcTreasuryId");
    c(this, "tokenMessengerId");
    c(this, "tokenMessengerStateId");
    c(this, "messageTransmitterId");
    c(this, "messageTransmitterStateId");
    c(this, "executorId");
    c(this, "executorRequestsId");
    var u, f, m, l;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = s, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    const r = (h, g) => {
      if (!h)
        throw new Error(g);
      return h;
    };
    this.usdcId = r(E.get(this.network, this.chain), `No USDC contract configured for network=${this.network} chain=${this.chain}`);
    const { tokenMessengerState: i, messageTransmitterState: o, usdcTreasury: d } = Gt(t);
    this.usdcTreasuryId = d, this.tokenMessengerId = r((u = s.cctp) == null ? void 0 : u.tokenMessenger, `Circle Token Messenger contract for domain ${e} not found`), this.messageTransmitterId = r((f = s.cctp) == null ? void 0 : f.messageTransmitter, `Circle Message Transmitter contract for domain ${e} not found`), this.tokenMessengerStateId = i, this.messageTransmitterStateId = o, this.executorId = r((m = ze[t]) == null ? void 0 : m.executorId, `Executor contract for ${t} not found`), this.executorRequestsId = r((l = ze[t]) == null ? void 0 : l.executorRequestsId, `Executor requests contract for ${t} not found`);
  }
  static async fromRpc(t, e) {
    const [n, s] = await ke.chainFromRpc(t), r = e[s];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new we(n, s, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const s = new _t(), r = new Qt(t).unwrap(), i = W.get(this.network, e.chain), [o, ...d] = await ke.getCoins(this.provider, t, this.usdcId);
    if (o === void 0)
      throw new Error("No USDC in wallet");
    const u = s.object(o.coinObjectId);
    d.length > 0 && s.mergeCoins(u, d.map((p) => s.object(p.coinObjectId)));
    let f;
    if (n.referrerFee > 0n) {
      const [p, F] = s.splitCoins(u, [
        n.remainingAmount,
        n.referrerFee
      ]);
      f = p, s.transferObjects([F], Tt(n.referrer));
    } else {
      const [p] = s.splitCoins(u, [
        n.remainingAmount
      ]);
      f = p;
    }
    const [m, l] = s.moveCall({
      target: `${this.tokenMessengerId}::deposit_for_burn::deposit_for_burn`,
      arguments: [
        f,
        s.pure.u32(i),
        // destination_domain
        s.pure.address(e.address.toUniversalAddress().toString()),
        // mint_recipient
        s.object(this.tokenMessengerStateId),
        // token_messenger_minter state
        s.object(this.messageTransmitterStateId),
        // message_transmitter state
        s.object("0x403"),
        // deny_list id, fixed address
        s.object(this.usdcTreasuryId)
        // treasury object Treasury<USDC>
      ],
      typeArguments: [this.usdcId]
    }), [h] = s.moveCall({
      target: `${this.messageTransmitterId}::message::source_domain`,
      arguments: [l]
    }), [g] = s.moveCall({
      target: `${this.messageTransmitterId}::message::nonce`,
      arguments: [l]
    }), [y] = s.moveCall({
      target: `${this.executorRequestsId}::executor_requests::make_cctp_v1_request`,
      arguments: [h, g]
    }), [D] = s.splitCoins(s.gas, [
      s.pure.u64(n.estimatedCost)
    ]);
    s.moveCall({
      target: `${this.executorId}::executor::request_execution`,
      arguments: [
        D,
        s.object(Ot),
        s.pure.u16(A(e.chain)),
        s.pure.address("0x0"),
        s.pure.address(r),
        s.pure.vector("u8", n.signedQuote),
        y,
        s.pure.vector("u8", n.relayInstructions)
      ]
    }), yield this.createUnsignedTx(s, "SuiCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new jt(t, this.network, this.chain, e, n);
  }
}
U(Lt, "CCTPExecutor", we);
const Z = new C("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
new C("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
const Ce = new C("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
new C("So11111111111111111111111111111111111111112");
new C("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");
class wn extends Error {
  constructor(t) {
    super(t);
  }
}
class Cn extends wn {
  constructor() {
    super(...arguments), this.name = "TokenOwnerOffCurveError";
  }
}
var ie;
(function(a) {
  a[a.InitializeMint = 0] = "InitializeMint", a[a.InitializeAccount = 1] = "InitializeAccount", a[a.InitializeMultisig = 2] = "InitializeMultisig", a[a.Transfer = 3] = "Transfer", a[a.Approve = 4] = "Approve", a[a.Revoke = 5] = "Revoke", a[a.SetAuthority = 6] = "SetAuthority", a[a.MintTo = 7] = "MintTo", a[a.Burn = 8] = "Burn", a[a.CloseAccount = 9] = "CloseAccount", a[a.FreezeAccount = 10] = "FreezeAccount", a[a.ThawAccount = 11] = "ThawAccount", a[a.TransferChecked = 12] = "TransferChecked", a[a.ApproveChecked = 13] = "ApproveChecked", a[a.MintToChecked = 14] = "MintToChecked", a[a.BurnChecked = 15] = "BurnChecked", a[a.InitializeAccount2 = 16] = "InitializeAccount2", a[a.SyncNative = 17] = "SyncNative", a[a.InitializeAccount3 = 18] = "InitializeAccount3", a[a.InitializeMultisig2 = 19] = "InitializeMultisig2", a[a.InitializeMint2 = 20] = "InitializeMint2", a[a.GetAccountDataSize = 21] = "GetAccountDataSize", a[a.InitializeImmutableOwner = 22] = "InitializeImmutableOwner", a[a.AmountToUiAmount = 23] = "AmountToUiAmount", a[a.UiAmountToAmount = 24] = "UiAmountToAmount", a[a.InitializeMintCloseAuthority = 25] = "InitializeMintCloseAuthority", a[a.TransferFeeExtension = 26] = "TransferFeeExtension", a[a.ConfidentialTransferExtension = 27] = "ConfidentialTransferExtension", a[a.DefaultAccountStateExtension = 28] = "DefaultAccountStateExtension", a[a.Reallocate = 29] = "Reallocate", a[a.MemoTransferExtension = 30] = "MemoTransferExtension", a[a.CreateNativeMint = 31] = "CreateNativeMint", a[a.InitializeNonTransferableMint = 32] = "InitializeNonTransferableMint", a[a.InterestBearingMintExtension = 33] = "InterestBearingMintExtension", a[a.CpiGuardExtension = 34] = "CpiGuardExtension", a[a.InitializePermanentDelegate = 35] = "InitializePermanentDelegate", a[a.TransferHookExtension = 36] = "TransferHookExtension", a[a.MetadataPointerExtension = 39] = "MetadataPointerExtension";
})(ie || (ie = {}));
function bn(a, t, e) {
  if (e.length) {
    a.push({ pubkey: t, isSigner: !1, isWritable: !1 });
    for (const n of e)
      a.push({
        pubkey: n instanceof C ? n : n.publicKey,
        isSigner: !0,
        isWritable: !1
      });
  } else
    a.push({ pubkey: t, isSigner: !0, isWritable: !1 });
  return a;
}
const En = We([
  Ie("mintAuthorityOption"),
  Ue("mintAuthority"),
  at("supply"),
  qe("decimals"),
  Kt("isInitialized"),
  Ie("freezeAuthorityOption"),
  Ue("freezeAuthority")
]);
En.span;
function Re(a, t, e = !1, n = Z, s = Ce) {
  if (!e && !C.isOnCurve(t.toBuffer()))
    throw new Cn();
  const [r] = C.findProgramAddressSync([t.toBuffer(), n.toBuffer(), a.toBuffer()], s);
  return r;
}
function An(a, t, e, n, s = Z, r = Ce) {
  return yn(a, t, e, n, O.Buffer.from([1]), s, r);
}
function yn(a, t, e, n, s, r = Z, i = Ce) {
  const o = [
    { pubkey: a, isSigner: !0, isWritable: !0 },
    { pubkey: t, isSigner: !1, isWritable: !0 },
    { pubkey: e, isSigner: !1, isWritable: !1 },
    { pubkey: n, isSigner: !1, isWritable: !1 },
    { pubkey: It.programId, isSigner: !1, isWritable: !1 },
    { pubkey: r, isSigner: !1, isWritable: !1 }
  ];
  return new Ke({
    keys: o,
    programId: i,
    data: s
  });
}
const Ne = We([qe("instruction"), at("amount")]);
function xn(a, t, e, n, s = [], r = Z) {
  const i = bn([
    { pubkey: a, isSigner: !1, isWritable: !0 },
    { pubkey: t, isSigner: !1, isWritable: !0 }
  ], e, s), o = O.Buffer.alloc(Ne.span);
  return Ne.encode({
    instruction: ie.Transfer,
    amount: BigInt(n)
  }, o), new Ke({ keys: i, programId: r, data: o });
}
const Dn = {
  version: "0.1.0",
  name: "example_cctp_with_executor",
  instructions: [
    {
      name: "relayLastMessage",
      accounts: [
        {
          name: "payer",
          isMut: !0,
          isSigner: !0
        },
        {
          name: "payee",
          isMut: !0,
          isSigner: !1
        },
        {
          name: "messageTransmitter",
          isMut: !1,
          isSigner: !1
        },
        {
          name: "executorProgram",
          isMut: !1,
          isSigner: !1
        },
        {
          name: "systemProgram",
          isMut: !1,
          isSigner: !1
        }
      ],
      args: [
        {
          name: "args",
          type: {
            defined: "relayLastMessageArgs"
          }
        }
      ]
    }
  ],
  types: [
    {
      name: "relayLastMessageArgs",
      type: {
        kind: "struct",
        fields: [
          {
            name: "recipientChain",
            type: "u16"
          },
          {
            name: "execAmount",
            type: "u64"
          },
          {
            name: "signedQuoteBytes",
            type: "bytes"
          },
          {
            name: "relayInstructions",
            type: "bytes"
          }
        ]
      }
    }
  ]
};
class be {
  constructor(t, e, n, s) {
    c(this, "network");
    c(this, "chain");
    c(this, "connection");
    c(this, "contracts");
    c(this, "tokenMessengerProgramId");
    c(this, "messageTransmitterProgramId");
    c(this, "shimProgramId");
    c(this, "executorProgramId");
    var i, o, d;
    if (this.network = t, this.chain = e, this.connection = n, this.contracts = s, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    const r = (u, f) => {
      if (!u)
        throw new Error(f);
      return new C(u);
    };
    this.tokenMessengerProgramId = r((i = s.cctp) == null ? void 0 : i.tokenMessenger, `Circle Token Messenger contract for domain ${e} not found`), this.messageTransmitterProgramId = r((o = s.cctp) == null ? void 0 : o.messageTransmitter, `Circle Message Transmitter contract for domain ${e} not found`), this.shimProgramId = r((d = le[t]) == null ? void 0 : d[e], `Shim contract for ${e} not found`), this.executorProgramId = r(tn[t], `Executor contract for ${t} not found`);
  }
  static async fromRpc(t, e) {
    const [n, s] = await Xt.chainFromRpc(t), r = e[s];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new be(n, s, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const s = new C(E.get(this.network, this.chain)), r = new ne(t).unwrap(), i = Re(s, r), o = new ne(n.referrer.address).unwrap(), d = new Mt();
    if (d.feePayer = r, n.referrerFee > 0n) {
      const y = Re(s, o, !0);
      await this.connection.getAccountInfo(y) || d.add(An(r, y, o, s)), d.add(xn(i, y, r, n.referrerFee));
    }
    const u = W.get(this.network, e.chain), f = e.address.toUniversalAddress(), m = Pt.generate();
    d.add(await Wt(this.messageTransmitterProgramId, this.tokenMessengerProgramId, s, u, r, i, f, n.remainingAmount, m.publicKey));
    const l = new qt(Dn, this.shimProgramId, { connection: null }), h = q(ut, n.signedQuote), g = Ht("message_transmitter", this.messageTransmitterProgramId);
    d.add(await l.methods.relayLastMessage({
      execAmount: new kt(n.estimatedCost.toString()),
      recipientChain: A(e.chain),
      signedQuoteBytes: O.Buffer.from(n.signedQuote),
      relayInstructions: O.Buffer.from(n.relayInstructions)
    }).accounts({
      payer: r,
      messageTransmitter: g,
      payee: new C(h.quote.payeeAddress),
      executorProgram: this.executorProgramId
    }).instruction()), yield this.createUnsignedTx({ transaction: d, signers: [m] }, "SvmCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new Zt(t, this.network, this.chain, e, n);
  }
}
U(Ut, "CCTPExecutor", be);
var w;
(function(a) {
  a.Pending = "pending", a.Failed = "failed", a.Unsupported = "unsupported", a.Submitted = "submitted", a.Underpaid = "underpaid", a.Aborted = "aborted";
})(w || (w = {}));
var _e;
(function(a) {
  a.ERM1 = "ERM1", a.ERV1 = "ERV1", a.ERN1 = "ERN1", a.ERC1 = "ERC1", a.ERC2 = "ERC2";
})(_e || (_e = {}));
async function Fn(a) {
  const t = `${me[a]}/v0/capabilities`;
  try {
    return (await v.get(t)).data;
  } catch {
    throw new Error(`Failed to fetch capabilities for network: ${a}.`);
  }
}
async function vn(a, t, e, n) {
  const s = `${me[a]}/v0/quote`;
  try {
    return (await v.post(s, {
      srcChain: A(t),
      dstChain: A(e),
      relayInstructions: n
    })).data;
  } catch {
    throw new Error("Failed to fetch signed quote.");
  }
}
async function Ee(a, t, e) {
  const n = `${me[a]}/v0/status/tx`;
  try {
    return (await v.post(n, {
      txHash: t,
      chainId: A(e)
    })).data;
  } catch {
    throw new Error(`Failed to fetch status for txHash: ${t}.`);
  }
}
const Bn = 65535n;
function Sn(a, t, e) {
  if (t > Bn)
    throw new Error("dBps exceeds max u16");
  let n = t, s = a, r = 0n;
  if (t > 0) {
    if (e !== void 0 && a > 0) {
      const i = Ze(e.toString(), 6), o = ue(i) / a, d = t < o ? t : o;
      r = a * d / 100000n, n = d;
    } else
      r = a * t / 100000n;
    s = a - r;
  }
  return { referrerFee: r, remainingAmount: s, referrerFeeDbps: n };
}
function Tn(a) {
  return new Promise((t) => setTimeout(t, a));
}
async function oe(a, t, e = Xe) {
  const n = Q(t, a.chain);
  return He(async () => {
    var r;
    const s = `${X[t]}/messages/${n}?transactionHash=${a.txid}`;
    try {
      const o = (await v.get(s)).data.messages[0];
      if (!o)
        return null;
      if (o.cctpVersion !== 2)
        throw new Error("CCTPv1 attestation found");
      return o.status === "pending_confirmations" ? null : {
        message: un(k.decode(o.message)),
        attestation: o.attestation
      };
    } catch (i) {
      if (!i || typeof i == "object" && (v.isAxiosError(i) && ((r = i.response) == null ? void 0 : r.status) === 404 || "status" in i && i.status === 404))
        return null;
      throw i;
    }
  }, 2e3, e, "CCTPv2:GetMessage");
}
async function In(a, t, e) {
  const n = Q(a, t), s = Q(a, e), r = `${X[a]}/fastBurn/USDC/fees/${n}/${s}`, i = await v.get(r);
  return BigInt(i.data.minimumFee);
}
async function Mn(a, t) {
  const e = k.encode(t.attestation.message.nonce, !0), n = `${X[a]}/reattest/${e}`, s = await v.post(n);
  if (s.data.error) {
    if (s.data.error.includes("Message is already finalized"))
      return t.attestation;
    throw new Error(`Error re-attesting message: ${s.data.error}`);
  }
  const r = rt(a, t.attestation.message.sourceDomain);
  return He(async () => {
    const i = await oe({ txid: t.id, chain: r }, a);
    return !i || i.message.messageBody.expirationBlock !== 0n ? null : i;
  }, 2e3, Xe, "CCTPv2:Reattest");
}
async function Pn(a) {
  const t = `${X[a]}/fastBurn/USDC/allowance`, e = await v.get(t);
  return ue(Ze(e.data.allowance, 6));
}
function Ae(a, t, e) {
  const n = E.get(t.network, t.chain);
  if (!(n && zt(a, B.tokenId(t.chain, n))))
    return [];
  const { network: s, chain: r } = e, i = E.get(s, r);
  return i ? [B.chainAddress(r, i)] : [];
}
let $;
async function ye(a, t, e, n) {
  var Be, Se;
  const { fromChain: s, toChain: r } = a;
  if (!E.get(s.network, s.chain))
    throw new Error("Invalid transfer, no USDC contract on source");
  const o = E.get(r.network, r.chain);
  if (!o)
    throw new Error("Invalid transfer, no USDC contract on destination");
  const d = (Be = sn[s.network]) == null ? void 0 : Be[s.chain];
  if (!d)
    throw new Error("No referrer address found");
  const u = B.chainAddress(s.chain, d), { referrerFee: f, remainingAmount: m, referrerFeeDbps: l } = Sn(ue(t.normalizedParams.amount), e.referrerFeeDbps, e.referrerFeeThreshold);
  if (m <= 0n)
    throw new Error("Amount after fee <= 0");
  const h = (Se = an[r.network]) == null ? void 0 : Se[r.chain];
  if (!h)
    throw new Error("Gas limit not found");
  const g = await Fn(s.network);
  if (!g[A(s.chain)])
    throw new Error("Unsupported source chain");
  const D = g[A(r.chain)];
  if (!D || !D.requestPrefixes.includes(n))
    throw new Error("Unsupported destination chain");
  const { recipient: p } = a;
  let F = !0;
  if (p && r.chain === "Solana") {
    const ht = B.parseAddress("Solana", o), gt = await r.getTokenAccount(p.address, ht), Te = await r.getRpc();
    F = await Te.getAccountInfo(new ne(gt.address).unwrap()) !== null, !F && !$ && ($ = BigInt(await Te.getMinimumBalanceForRentExemption(165)));
  }
  let H = 0n;
  r.chain === "Solana" && (H += nn, !F && $ && (H += $));
  const J = [];
  J.push({
    request: {
      type: "GasInstruction",
      gasLimit: h,
      msgValue: H
    }
  });
  const De = BigInt(D.gasDropOffLimit), Y = t.options.nativeGas && De > 0n ? BigInt(Math.round(t.options.nativeGas * 100)) * De / 100n : 0n;
  (Y > 0n || !F) && J.push({
    request: {
      type: "GasDropOffInstruction",
      dropOff: Y,
      // If the recipient is undefined (e.g. the user hasn’t connected their wallet yet),
      // we temporarily use a dummy address to fetch a quote.
      // The recipient address is validated later in the `initiate` method, which will throw if it's still missing.
      recipient: p ? p.address.toUniversalAddress() : new Vt(new Uint8Array(32))
    }
  });
  const Fe = Qe(dt, {
    requests: J
  }), ee = await vn(s.network, s.chain, r.chain, k.encode(Fe, !0));
  if (!ee.estimatedCost)
    throw new Error("No estimated cost");
  const ve = k.decode(ee.signedQuote), mt = q(ut, ve), lt = BigInt(ee.estimatedCost);
  return {
    signedQuote: ve,
    relayInstructions: Fe,
    estimatedCost: lt,
    referrer: u,
    referrerFee: f,
    remainingAmount: m,
    referrerFeeDbps: l,
    expiryTime: mt.quote.expiryTime,
    gasDropOff: Y
  };
}
async function ft(a, t, e, n) {
  q(dt, n.details.relayInstructions).requests.forEach(({ request: m }) => {
    if (m.type === "GasDropOffInstruction" && !m.recipient.equals(e.address.toUniversalAddress()))
      throw new Error("Gas drop-off recipient does not match");
  });
  const r = B.parseAddress(t.chain(), t.address()), i = await kn(e, a);
  let o;
  n.protocol === "CCTPExecutor" ? o = await (await a.fromChain.getProtocol(n.protocol)).transfer(r, i, n.details) : o = await (await a.fromChain.getProtocol(n.protocol)).transfer(r, i, n.details);
  const d = await Je(a.fromChain, o, t);
  let u = 0;
  return (async () => {
    for (; u < 20; ) {
      try {
        const [m] = await Ee(a.fromChain.network, d.at(-1).txid, a.fromChain.chain);
        if (m)
          break;
      } catch {
      }
      u++, await Tn(2e3);
    }
  })(), {
    from: a.fromChain.chain,
    to: a.toChain.chain,
    state: b.SourceInitiated,
    originTxs: d
  };
}
async function kn(a, t) {
  if (a.chain !== "Solana")
    return a;
  const e = E.get(t.toChain.network, t.toChain.chain);
  if (!e)
    throw new Error("No USDC contract found for Solana");
  const n = B.parseAddress("Solana", e);
  return t.toChain.getTokenAccount(a.address, n);
}
function ta(a = { referrerFeeDbps: 0n }) {
  if (a.referrerFeeDbps < 0 || a.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends _ {
  }
  return c(t, "config", a), t;
}
class _ extends Ye {
  constructor() {
    super(...arguments);
    // @ts-ignore
    // Since we set the config on the static class, access it with this param
    // the CCTPExecutorRoute.config will always be empty
    c(this, "staticConfig", this.constructor.config);
  }
  static supportedNetworks() {
    return ["Mainnet", "Testnet"];
  }
  static supportedChains(e) {
    return [...Object.keys(st[e] ?? {})];
  }
  static async supportedDestinationTokens(e, n, s) {
    return !z(n.network, n.chain) || !z(s.network, s.chain) ? [] : Ae(e, n, s);
  }
  getDefaultOptions() {
    return {
      nativeGas: 0
    };
  }
  async validate(e, n) {
    var o;
    const { fromChain: s, toChain: r } = e;
    return !z(s.network, s.chain) || !z(r.network, r.chain) ? {
      valid: !1,
      error: new Error("Unsupported source or destination chain"),
      params: n
    } : (o = n.options) != null && o.nativeGas && (n.options.nativeGas < 0 || n.options.nativeGas > 1) ? {
      valid: !1,
      error: new Error("Invalid native gas percentage"),
      params: n
    } : { valid: !0, params: {
      normalizedParams: {
        amount: e.parseAmount(n.amount)
      },
      options: n.options ?? this.getDefaultOptions(),
      ...n
    } };
  }
  async quote(e, n) {
    const { fromChain: s, toChain: r } = e;
    try {
      const i = await ye(e, n, this.staticConfig, "ERC1"), { remainingAmount: o, estimatedCost: d, gasDropOff: u, expiryTime: f } = i, m = s.chain === "Polygon" ? 2e3 * 200 : et(s.chain) + 1e3, [l, h] = await Promise.all([
        s.getDecimals("native"),
        r.getDecimals("native")
      ]);
      return {
        success: !0,
        params: n,
        sourceToken: {
          token: e.source.id,
          amount: n.normalizedParams.amount
        },
        destinationToken: {
          token: e.destination.id,
          amount: x(o, e.destination.decimals)
        },
        relayFee: {
          token: fe(s.chain),
          amount: x(d, l)
        },
        destinationNativeGas: x(u, h),
        eta: m,
        expires: f,
        details: i
      };
    } catch (i) {
      return {
        success: !1,
        error: new Error(i instanceof Error ? i.message : `${i}`)
      };
    }
  }
  async initiate(e, n, s, r) {
    if (!s.details)
      throw new Error("Missing quote details");
    return await ft(e, n, r, {
      protocol: "CCTPExecutor",
      details: s.details
    });
  }
  async *track(e, n) {
    if (L(e) || I(e))
      return e;
    let s = n || 60 * 60 * 1e3;
    for (; s > 0; ) {
      const r = Date.now();
      if (ae(e) || se(e) || R(e))
        try {
          const [i] = await Ee(this.wh.network, e.originTxs.at(-1).txid, e.from);
          if (!i)
            throw new Error("No transaction status found");
          const o = i == null ? void 0 : i.status;
          if ((o === w.Failed || // this could happen if simulation fails
          o === w.Underpaid || // only happens if you don't pay at least the costEstimate
          o === w.Unsupported || // capabilities check didn't pass
          o === w.Aborted) && (e = {
            ...e,
            state: b.Failed,
            error: new nt(`Relay failed with status: ${o}`)
          }), o === w.Submitted && (e = {
            ...e,
            state: b.DestinationFinalized,
            attestation: { id: i.id, attestation: {} }
          }), yield e, L(e) || I(e))
            return e;
        } catch (i) {
          console.error(`Error fetching transaction status: ${i.message || i}`);
        }
      await new Promise((i) => setTimeout(i, 3e3)), s -= Date.now() - r;
    }
    return e;
  }
}
c(_, "NATIVE_GAS_DROPOFF_SUPPORTED", !0), c(_, "config", { referrerFeeDbps: 0n }), c(_, "meta", {
  name: "CCTPExecutorRoute",
  provider: "Circle"
});
class xe extends Ye {
  static supportedNetworks() {
    return ["Mainnet", "Testnet"];
  }
  static supportedChains(t) {
    return Object.keys(K[t] ?? {});
  }
  getDefaultOptions() {
    return {
      nativeGas: 0
    };
  }
  async initiate(t, e, n, s) {
    if (!n.details)
      throw new Error("Missing quote details");
    return await ft(t, e, s, {
      protocol: "CCTPv2Executor",
      details: n.details
    });
  }
  async *track(t, e) {
    if (L(t))
      return t;
    let n = e || 60 * 60 * 1e3;
    for (; n > 0; ) {
      const s = Date.now();
      if (ae(t) || se(t) || R(t) || I(t))
        try {
          const r = t.originTxs.at(-1).txid;
          if (ae(t) || se(t)) {
            const i = await oe({ chain: t.from, txid: r }, this.wh.network);
            i && (t = {
              ...t,
              state: b.Attested,
              attestation: {
                id: r,
                attestation: i
              }
            }), yield t;
          }
          if (R(t)) {
            const [i] = await Ee(this.wh.network, r, t.from);
            if (!i)
              throw new Error("No transaction status found");
            const o = i == null ? void 0 : i.status;
            o === w.Submitted ? t = {
              ...t,
              state: b.DestinationFinalized
            } : (o === w.Failed || // this could happen if simulation fails
            o === w.Underpaid || // only happens if you don't pay at least the costEstimate
            o === w.Unsupported || // capabilities check didn't pass
            o === w.Aborted) && (t = {
              ...t,
              state: b.Failed,
              error: new nt(`Relay failed with status: ${o}`)
            });
          }
          if (I(t)) {
            if (!t.attestation)
              throw new Error("Receipt is missing attestation");
            const i = t.attestation;
            await (await this.wh.getChain(t.to).getProtocol("CCTPv2Executor")).isTransferCompleted(i.attestation.message) && (t = {
              ...t,
              state: b.DestinationFinalized,
              attestation: i
            });
          }
          if (yield t, L(t))
            return t;
        } catch (r) {
          console.error(`Error fetching transaction status: ${r.message || r}`);
        }
      await new Promise((r) => setTimeout(r, 3e3)), n -= Date.now() - s;
    }
    return t;
  }
  async complete(t, e) {
    if (!R(e) && !I(e))
      throw new Error("Transfer is not attested");
    if (!e.attestation)
      throw new Error("No attestation found");
    const n = this.wh.getChain(e.to), s = await n.getProtocol("CCTPv2Executor");
    let { attestation: r, message: i } = e.attestation.attestation;
    const { expirationBlock: o } = i.messageBody, d = await s.getCurrentBlock();
    if (o !== 0n && o < d) {
      const l = await Mn(n.network, e.attestation);
      if (!l)
        throw new Error("Failed to reattest message");
      r = l.attestation, i = l.message;
    }
    const u = B.parseAddress(t.chain(), t.address()), f = s.redeem(u, i, r), m = await Je(this.wh.getChain(e.to), f, t);
    return {
      ...e,
      state: b.DestinationInitiated,
      attestation: e.attestation,
      destinationTxs: m
    };
  }
  async resume(t) {
    const e = await oe(t, this.wh.network);
    if (!e)
      throw new Error("No attestation found");
    const { message: n } = e, s = rt(this.wh.network, n.destinationDomain);
    return await (await this.wh.getChain(s).getProtocol("CCTPv2Executor")).isTransferCompleted(n) ? {
      from: t.chain,
      to: s,
      state: b.DestinationFinalized,
      originTxs: [t],
      attestation: { id: t.txid, attestation: e }
    } : {
      from: t.chain,
      to: s,
      state: b.Attested,
      originTxs: [t],
      attestation: { id: t.txid, attestation: e }
    };
  }
}
c(xe, "NATIVE_GAS_DROPOFF_SUPPORTED", !0);
function na(a = { referrerFeeDbps: 0n }) {
  if (a.referrerFeeDbps < 0 || a.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends ce {
  }
  return c(t, "config", a), t;
}
const M = class M extends xe {
  constructor() {
    super(...arguments);
    // @ts-ignore
    // Since we set the config on the static class, access it with this param
    // the CCTPv2FastExecutorRoute.config will always be empty
    c(this, "staticConfig", this.constructor.config);
  }
  static isPathSupported(e, n) {
    return on(e.network, e.chain) && re(n.network, n.chain);
  }
  static async supportedDestinationTokens(e, n, s) {
    return this.isPathSupported(n, s) ? Ae(e, n, s) : [];
  }
  async validate(e, n) {
    var r;
    return M.isPathSupported(e.fromChain, e.toChain) ? (r = n.options) != null && r.nativeGas && (n.options.nativeGas < 0 || n.options.nativeGas > 1) ? {
      valid: !1,
      error: new Error("Invalid native gas percentage"),
      params: n
    } : { valid: !0, params: {
      normalizedParams: {
        amount: e.parseAmount(n.amount)
      },
      options: n.options ?? this.getDefaultOptions(),
      ...n
    } } : {
      valid: !1,
      error: new Error("Can only transfer from a Circle V2 fast chain to a Circle V2 chain"),
      params: n
    };
  }
  async quote(e, n) {
    var i;
    const { fromChain: s, toChain: r } = e;
    try {
      const o = await ye(e, n, this.staticConfig, "ERC2"), { remainingAmount: d, estimatedCost: u, gasDropOff: f, expiryTime: m } = o;
      if (await Pn(s.network) <= d)
        return {
          success: !1,
          error: new Error("Insufficient allowance for fast transfer")
        };
      const h = await In(s.network, s.chain, r.chain), g = (d * h + 10000n - 1n) / 10000n, y = d - g;
      if (y <= 0n)
        return {
          success: !1,
          error: new Error("Amount after fast transfer fee <= 0")
        };
      const D = (i = it[s.network]) == null ? void 0 : i[s.chain], [p, F] = await Promise.all([
        s.getDecimals("native"),
        r.getDecimals("native")
      ]);
      return {
        success: !0,
        params: n,
        sourceToken: {
          token: e.source.id,
          amount: n.normalizedParams.amount
        },
        destinationToken: {
          token: e.destination.id,
          amount: x(y, e.destination.decimals)
        },
        relayFee: {
          token: fe(s.chain),
          amount: x(u, p)
        },
        destinationNativeGas: x(f, F),
        eta: D,
        expires: m,
        details: {
          ...o,
          minFinalityThreshold: j.CONFIRMED,
          fastTransferMaxFee: g
        }
      };
    } catch (o) {
      return {
        success: !1,
        error: new Error(o instanceof Error ? o.message : `${o}`)
      };
    }
  }
};
c(M, "config", { referrerFeeDbps: 0n }), c(M, "meta", {
  name: "CCTPv2FastExecutorRoute",
  provider: "Circle"
});
let ce = M;
function aa(a = { referrerFeeDbps: 0n }) {
  if (a.referrerFeeDbps < 0 || a.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends de {
  }
  return c(t, "config", a), t;
}
const P = class P extends xe {
  constructor() {
    super(...arguments);
    // @ts-ignore
    // Since we set the config on the static class, access it with this param
    // the CCTPv2StandardExecutorRoute.config will always be empty
    c(this, "staticConfig", this.constructor.config);
  }
  static isPathSupported(e, n) {
    return re(e.network, e.chain) && re(n.network, n.chain) && // We don't support slow transfers from Linea because the attestation time
    // can be anywhere between 6 and 32 hours! Fast transfer should be used instead.
    e.chain !== "Linea";
  }
  static async supportedDestinationTokens(e, n, s) {
    return this.isPathSupported(n, s) ? Ae(e, n, s) : [];
  }
  async validate(e, n) {
    var r;
    return P.isPathSupported(e.fromChain, e.toChain) ? (r = n.options) != null && r.nativeGas && (n.options.nativeGas < 0 || n.options.nativeGas > 1) ? {
      valid: !1,
      error: new Error("Invalid native gas percentage"),
      params: n
    } : { valid: !0, params: {
      normalizedParams: {
        amount: e.parseAmount(n.amount)
      },
      options: n.options ?? this.getDefaultOptions(),
      ...n
    } } : {
      valid: !1,
      error: new Error("Can only transfer between Circle V2 chains"),
      params: n
    };
  }
  async quote(e, n) {
    const { fromChain: s, toChain: r } = e;
    try {
      const i = await ye(e, n, this.staticConfig, "ERC2"), { remainingAmount: o, estimatedCost: d, gasDropOff: u, expiryTime: f } = i, m = s.chain === "Polygon" ? 2e3 * 200 : et(s.chain) + 1e3, [l, h] = await Promise.all([
        s.getDecimals("native"),
        r.getDecimals("native")
      ]);
      return {
        success: !0,
        params: n,
        sourceToken: {
          token: e.source.id,
          amount: n.normalizedParams.amount
        },
        destinationToken: {
          token: e.destination.id,
          amount: x(o, e.destination.decimals)
        },
        relayFee: {
          token: fe(s.chain),
          amount: x(d, l)
        },
        destinationNativeGas: x(u, h),
        eta: m,
        expires: f,
        details: {
          ...i,
          minFinalityThreshold: j.FINALIZED,
          fastTransferMaxFee: 0n
          // no fee for standard / slow transfer
        }
      };
    } catch (i) {
      return {
        success: !1,
        error: new Error(i instanceof Error ? i.message : `${i}`)
      };
    }
  }
};
c(P, "config", { referrerFeeDbps: 0n }), c(P, "meta", {
  name: "CCTPv2StandardExecutorRoute",
  provider: "Circle"
});
let de = P;
export {
  ta as cctpExecutorRoute,
  na as cctpV2FastExecutorRoute,
  aa as cctpV2StandardExecutorRoute
};
