var wt = Object.defineProperty;
var Ct = (s, t, e) => t in s ? wt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
var c = (s, t, e) => Ct(s, typeof t != "symbol" ? t + "" : t, e);
import { aW as bt, as as Et, aX as At, aY as yt, aZ as xt, a_ as Dt, a$ as Ft, b0 as vt, b1 as Bt, b2 as Tt, b3 as St, b4 as Pt, aq as Ge, D as y, b5 as j, aw as x, aE as U, y as Le, ay as te, aB as S, aC as Qe, au as We, aJ as q, k, aF as je, o as Mt, P as E, a2 as qe, an as Me, a5 as Ke, d as O, _ as It, a3 as Xe, aM as ne, aN as kt, $ as Ut, aG as Vt, aO as zt, A as $t, W as B, aa as v, b6 as Ze, F as ue, G as He, b7 as Je, U as Rt, aT as Ye, T as A, ad as et, aR as tt, u as F, J as me, O as G, V as P, al as se, am as ae, Q as R, R as nt } from "./address-QpeLv2yn.mjs";
import { l as Ie } from "./chunk-KJH4KKG6-qC3BvugF.mjs";
import { A as Nt } from "./platform-IW8iV_CA.mjs";
import { d as ke, _ as _t, r as Ot } from "./address-BJhcbdG9.mjs";
import { A as Gt } from "./unsignedTransaction-BDOQhqcZ.mjs";
import { E as L } from "./platform-B0QvkHbE.mjs";
import { C as N } from "./contract-D4Vzf62E.mjs";
import { E as st } from "./unsignedTransaction-C0V0UbsS.mjs";
import { b as Ue, T as Lt, a as Qt, _ as Wt } from "./platform-lg76WojY.mjs";
import { suiCircleObjects as jt } from "./index-Czoo2lwG.mjs";
import { S as qt } from "./address-C4qO2bMD.mjs";
import { S as Kt } from "./unsignedTransaction-BD81leu1.mjs";
import { createDepositForBurnInstruction as Xt } from "./index-CBHIr2qc.mjs";
import { P as Zt } from "./index-t4mLpVUg.mjs";
import { p as Ve, u as at, b as Ht } from "./web3-Atnj-SZ3.mjs";
import { a as Jt, S as Yt } from "./unsignedTransaction-Brbbx5Uc.mjs";
import { d as en } from "./account-DtI49BC9.mjs";
const tn = {
  binary: "uint",
  size: 1,
  custom: {
    to: (s) => s > 0,
    from: (s) => s ? 1 : 0
  }
}, nn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  amountItem: bt,
  boolItem: tn,
  chainItem: Et,
  circleDomainItem: At,
  circleNonceItem: yt,
  dateConversion: xt,
  fixedChainItem: Dt,
  fixedLengthStringItem: Ft,
  guardianSetItem: vt,
  payloadIdItem: Bt,
  sequenceItem: Tt,
  signatureItem: St,
  stringConversion: Pt,
  universalAddressItem: Ge
}, Symbol.toStringTag, { value: "Module" })), fe = {
  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"
  }
}, sn = {
  Testnet: {
    Avalanche: "0x4058F0C3924eDaB19c15597C438968ed49C1a213",
    BaseSepolia: "0xC400FcC0e92d3406747FBb6f513D3aa8B038fcE9",
    Sepolia: "0x0F18DD26D0B41fb1eaa9cF34D1Ec6022aA69a8e2"
  },
  Mainnet: {
    Arbitrum: "0x8442d68524217601ed126f6859694E4B0C7c66A1",
    Avalanche: "0x3952914628650Ca510404872D84DfF10A844C5B5",
    Base: "0xbd8d42f40a11b37bD1b3770D754f9629F7cd5679",
    Ethereum: "0x2cCf230467FE7387674BAa657747F0B5485c7fEC",
    Linea: "0xc48c126468BE919068dE1983F00F65af759a4E87",
    Optimism: "0xd0a8940b2e743e33b682daec4d52b46713606c9d",
    Polygon: "0xc8a8e6d760dcbd5d6746e2f66cd2ffa722dd1e59",
    Unichain: "0xD5D5D640D8b758672Cc7A078734175c4433866d5",
    Sonic: "0xc39BF082ec91D9bC385F956D24a8D66C0c26223d",
    Worldchain: "0x789f2b91f7B35D5B890983328340c4600339B354"
  }
}, ze = {
  Testnet: {
    executorId: "0x4000cfe2955d8355b3d3cf186f854fea9f787a457257056926fde1ec977670eb",
    executorRequestsId: "0x2d9ccf3cce3f7dce408e5455e90b80a8161ad9673d1366c2a5def60ad93657a8"
  },
  Mainnet: {
    executorId: "0xdb0fe8bb1e2b5be628adbea0636063325073e1070ee11e4281457dfd7f158235",
    executorRequestsId: "0xc030df7a3eed1494fa4b64aa8ab63a79041cf1114f4ff2b7ab5aca1c684a21a7"
  }
}, an = {
  Testnet: "execXUrAsMnqMmTHj5m7N1YQgsDz3cwGLYCYyuDRciV",
  Mainnet: "execXUrAsMnqMmTHj5m7N1YQgsDz3cwGLYCYyuDRciV"
}, rn = 5001n, on = {
  Testnet: {
    Aptos: 5000n,
    ArbitrumSepolia: 800000n,
    Avalanche: 200000n,
    BaseSepolia: 200000n,
    Linea: 250000n,
    Sepolia: 200000n,
    Solana: 250000n,
    Sonic: 250000n,
    Sui: 8000000n
  },
  Mainnet: {
    Aptos: 5000n,
    Arbitrum: 800000n,
    Avalanche: 250000n,
    Base: 250000n,
    Ethereum: 250000n,
    Linea: 250000n,
    Optimism: 250000n,
    Polygon: 250000n,
    Unichain: 250000n,
    Solana: 250000n,
    Sonic: 250000n,
    Sui: 8000000n,
    Worldchain: 250000n
  }
}, cn = {
  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"
    },
    Optimism: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Polygon: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Unichain: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Sonic: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    },
    Worldchain: {
      tokenMessengerV2: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
      messageTransmitterV2: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64"
    }
  }
}, rt = {
  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
  }
}, V = (s, t) => {
  var e;
  return ((e = rt[s]) == 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,
    Optimism: 2,
    Arbitrum: 3,
    Base: 6,
    Polygon: 7,
    Unichain: 10,
    Linea: 11,
    Sonic: 13,
    Worldchain: 14
  }
}, re = (s, t) => {
  var e;
  return ((e = K[s]) == null ? void 0 : e[t]) !== void 0;
}, Q = (s, t) => {
  var n;
  const e = (n = K[s]) == null ? void 0 : n[t];
  if (e === void 0)
    throw new Error(`CircleV2 domain not found for network ${s} and chain ${t}`);
  return e;
}, it = (s, t) => {
  var n;
  const e = (n = Object.entries(K[s] ?? {}).find(([, a]) => a === t)) == null ? void 0 : n[0];
  if (e === void 0)
    throw new Error(`CircleV2 chain not found for network ${s} and domain ${t}`);
  return e;
}, X = {
  Testnet: "https://iris-api-sandbox.circle.com/v2",
  Mainnet: "https://iris-api.circle.com/v2"
};
var W;
(function(s) {
  s[s.CONFIRMED = 1e3] = "CONFIRMED", s[s.FINALIZED = 2e3] = "FINALIZED";
})(W || (W = {}));
const ot = {
  // milliseconds
  Testnet: {
    ArbitrumSepolia: 8e3,
    BaseSepolia: 8e3,
    Sepolia: 2e4,
    Linea: 8e3
  },
  Mainnet: {
    Arbitrum: 8e3,
    Base: 8e3,
    Ethereum: 2e4,
    Linea: 8e3,
    Optimism: 8e3,
    Polygon: 8e3,
    Unichain: 8e3,
    Worldchain: 8e3
  }
}, dn = (s, t) => {
  var e;
  return ((e = ot[s]) == null ? void 0 : e[t]) !== void 0;
};
class he {
  constructor(t, e, n, a) {
    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 = a, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    const r = y.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, a] = await Nt.chainFromRpc(t), r = e[a];
    if (!r)
      throw new Error(`No config found for ${a}`);
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new he(n, a, t, r.contracts);
  }
  async *transfer(t, e, n) {
    var h, g;
    const a = new ke(t).unwrap(), r = Ie.from(e.address.toUniversalAddress().toUint8Array()), i = Ie.from(this.usdcId), o = n.remainingAmount + n.referrerFee, d = j.get(this.network, e.chain), u = a, m = new ke(((g = (h = n.referrer) == null ? void 0 : h.address) == null ? void 0 : g.toString()) ?? a).unwrap(), f = [
      o,
      d,
      r.toString(),
      i.toString(),
      n.estimatedCost,
      x(e.chain),
      u,
      n.signedQuote,
      n.relayInstructions,
      n.referrerFeeDbps,
      m
    ], l = {
      function: `${this.shimContract}::cctp_v1_with_executor::deposit_for_burn_entry`,
      functionArguments: f
    };
    yield this.createUnsignedTx(l, "AtposCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new Gt(t, this.network, this.chain, e, n);
  }
}
U(_t, "CCTPExecutor", he);
class ge {
  constructor(t, e, n, a) {
    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 = a, 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, a] = await L.chainFromRpc(t), r = e[a];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new ge(n, a, t, r.contracts);
  }
  async *transfer(t, e, n) {
    var h, g;
    const a = new te(t).toString(), r = e.address.toUniversalAddress().toUint8Array(), i = n.remainingAmount + n.referrerFee, o = y.get(this.network, this.chain), d = L.getTokenImplementation(this.provider, o);
    if (await d.allowance(a, this.shimContract) < i) {
      const w = await d.approve.populateTransaction(this.shimContract, i);
      yield this.createUnsignedTx(S(w, a), "ERC20.approve of EvmCCTPExecutor", !1);
    }
    const m = [
      "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, m, this.provider).getFunction("depositForBurn").populateTransaction(i, x(e.chain), j.get(this.network, e.chain), r, o, {
      refundAddress: a,
      signedQuote: n.signedQuote,
      instructions: n.relayInstructions
    }, {
      dbps: n.referrerFeeDbps,
      payee: ((g = (h = n.referrer) == null ? void 0 : h.address) == null ? void 0 : g.toString()) ?? a
    });
    l.value = n.estimatedCost, yield this.createUnsignedTx(S(l, a), "EvmCCTPExecutor.depositForBurn");
  }
  createUnsignedTx(t, e, n = !1) {
    return new st(Qe(t, this.chainId), this.network, this.chain, e, n);
  }
}
const { amountItem: z, circleDomainItem: $e, universalAddressItem: T } = nn, ct = {
  binary: "uint",
  size: 4,
  custom: 1,
  omit: !1
}, un = {
  binary: "bytes",
  size: 32
}, Re = {
  binary: "uint",
  size: 4
}, mn = [
  { name: "version", ...ct },
  { name: "burnToken", ...T },
  { name: "mintRecipient", ...T },
  { name: "amount", ...z },
  { name: "messageSender", ...T },
  { name: "maxFee", ...z },
  { name: "feeExecuted", ...z },
  { name: "expirationBlock", ...z },
  { name: "hookData", binary: "bytes" }
], dt = [
  { name: "version", ...ct },
  { name: "sourceDomain", ...$e },
  { name: "destinationDomain", ...$e },
  { name: "nonce", ...un },
  { name: "sender", ...T },
  { name: "recipient", ...T },
  { name: "destinationCaller", ...T },
  { name: "minFinalityThreshold", ...Re },
  { name: "finalityThresholdExecuted", ...Re },
  { name: "messageBody", binary: "bytes", layout: mn }
], fn = (s) => q(dt, s), ln = (s) => We(dt, s), hn = [
  { name: "gasLimit", binary: "uint", size: 16 },
  { name: "msgValue", binary: "uint", size: 16 }
], gn = [
  { name: "dropOff", binary: "uint", size: 16 },
  { name: "recipient", ...Ge }
], pn = [
  {
    name: "request",
    binary: "switch",
    idSize: 1,
    idTag: "type",
    layouts: [
      [[1, "GasInstruction"], hn],
      [[2, "GasDropOffInstruction"], gn]
    ]
  }
], ut = [
  {
    name: "requests",
    binary: "array",
    layout: pn
  }
], wn = {
  to: (s) => new Date(Number(s * 1000n)),
  from: (s) => BigInt(s.getTime()) / 1000n
}, Cn = [
  {
    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: wn
          },
          { name: "baseFee", binary: "uint", size: 8 },
          { name: "dstGasPrice", binary: "uint", size: 8 },
          { name: "srcPrice", binary: "uint", size: 8 },
          { name: "dstPrice", binary: "uint", size: 8 }
        ]
      ]
    ]
  }
], mt = [
  ...Cn,
  { name: "signature", binary: "bytes", size: 65 }
];
class pe {
  constructor(t, e, n, a) {
    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, m;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = a, t === "Devnet")
      throw new Error("CCTPv2Executor not supported on Devnet");
    this.chainId = Le.get(t, e);
    const r = (d = sn[t]) == null ? void 0 : d[e];
    if (!r)
      throw new Error(`Shim contract for ${e} not found`);
    this.shimContract = r;
    const i = (m = (u = cn[t]) == null ? void 0 : u[e]) == null ? void 0 : m.messageTransmitterV2;
    if (!i)
      throw new Error(`MessageTransmitter contract for ${e} not found`);
    this.messageTransmitter = i;
    const o = y.get(t, e);
    if (!o)
      throw new Error(`USDC contract for ${e} not found`);
    this.usdcContract = o;
  }
  static async fromRpc(t, e) {
    const [n, a] = await L.chainFromRpc(t), r = e[a];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new pe(n, a, t, r.contracts);
  }
  async *transfer(t, e, n) {
    var g, w;
    const a = new te(t).toString(), r = e.address.toUniversalAddress().toUint8Array(), i = n.remainingAmount + n.referrerFee, o = L.getTokenImplementation(this.provider, this.usdcContract);
    if (await o.allowance(a, this.shimContract) < i) {
      const C = await o.approve.populateTransaction(this.shimContract, i);
      yield this.createUnsignedTx(S(C, a), "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)"
    ], m = new Uint8Array(32), f = new N(this.shimContract, u, this.provider), l = Q(this.network, e.chain), h = await f.getFunction("depositForBurn").populateTransaction(i, x(e.chain), l, r, this.usdcContract, m, n.fastTransferMaxFee, n.minFinalityThreshold, {
      refundAddress: a,
      signedQuote: n.signedQuote,
      instructions: n.relayInstructions
    }, {
      dbps: n.referrerFeeDbps,
      payee: ((w = (g = n.referrer) == null ? void 0 : g.address) == null ? void 0 : w.toString()) ?? a
    });
    h.value = n.estimatedCost, yield this.createUnsignedTx(S(h, a), "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 a = new te(t).toString(), i = await new N(this.messageTransmitter, ["function receiveMessage(bytes message, bytes attestation)"], this.provider).getFunction("receiveMessage").populateTransaction(ln(e), k.decode(n));
    yield this.createUnsignedTx(S(i, a), "MessageTransmitterV2.receiveMessage");
  }
  async getCurrentBlock() {
    return BigInt(await this.provider.getBlockNumber());
  }
  createUnsignedTx(t, e, n = !1) {
    return new st(Qe(t, this.chainId), this.network, this.chain, e, n);
  }
}
U(je, "CCTPExecutor", ge);
U(je, "CCTPv2Executor", pe);
class we {
  constructor(t, e, n, a) {
    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, m, f, l;
    if (this.network = t, this.chain = e, this.provider = n, this.contracts = a, 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(y.get(this.network, this.chain), `No USDC contract configured for network=${this.network} chain=${this.chain}`);
    const { tokenMessengerState: i, messageTransmitterState: o, usdcTreasury: d } = jt(t);
    this.usdcTreasuryId = d, this.tokenMessengerId = r((u = a.cctp) == null ? void 0 : u.tokenMessenger, `Circle Token Messenger contract for domain ${e} not found`), this.messageTransmitterId = r((m = a.cctp) == null ? void 0 : m.messageTransmitter, `Circle Message Transmitter contract for domain ${e} not found`), this.tokenMessengerStateId = i, this.messageTransmitterStateId = o, this.executorId = r((f = ze[t]) == null ? void 0 : f.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, a] = await Ue.chainFromRpc(t), r = e[a];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new we(n, a, t, r.contracts);
  }
  async *transfer(t, e, n) {
    const a = new Lt(), r = new qt(t).unwrap(), i = j.get(this.network, e.chain), [o, ...d] = await Ue.getCoins(this.provider, t, this.usdcId);
    if (o === void 0)
      throw new Error("No USDC in wallet");
    const u = a.object(o.coinObjectId);
    d.length > 0 && a.mergeCoins(u, d.map((p) => a.object(p.coinObjectId)));
    let m;
    if (n.referrerFee > 0n) {
      const [p, D] = a.splitCoins(u, [
        n.remainingAmount,
        n.referrerFee
      ]);
      m = p, a.transferObjects([D], n.referrer ? Mt(n.referrer) : r);
    } else {
      const [p] = a.splitCoins(u, [
        n.remainingAmount
      ]);
      m = p;
    }
    const [f, l] = a.moveCall({
      target: `${this.tokenMessengerId}::deposit_for_burn::deposit_for_burn`,
      arguments: [
        m,
        a.pure.u32(i),
        // destination_domain
        a.pure.address(e.address.toUniversalAddress().toString()),
        // mint_recipient
        a.object(this.tokenMessengerStateId),
        // token_messenger_minter state
        a.object(this.messageTransmitterStateId),
        // message_transmitter state
        a.object("0x403"),
        // deny_list id, fixed address
        a.object(this.usdcTreasuryId)
        // treasury object Treasury<USDC>
      ],
      typeArguments: [this.usdcId]
    }), [h] = a.moveCall({
      target: `${this.messageTransmitterId}::message::source_domain`,
      arguments: [l]
    }), [g] = a.moveCall({
      target: `${this.messageTransmitterId}::message::nonce`,
      arguments: [l]
    }), [w] = a.moveCall({
      target: `${this.executorRequestsId}::executor_requests::make_cctp_v1_request`,
      arguments: [h, g]
    }), [C] = a.splitCoins(a.gas, [
      a.pure.u64(n.estimatedCost)
    ]);
    a.moveCall({
      target: `${this.executorId}::executor::request_execution`,
      arguments: [
        C,
        a.object(Qt),
        a.pure.u16(x(e.chain)),
        a.pure.address("0x0"),
        a.pure.address(r),
        a.pure.vector("u8", n.signedQuote),
        w,
        a.pure.vector("u8", n.relayInstructions)
      ]
    }), yield this.createUnsignedTx(a, "SuiCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new Kt(t, this.network, this.chain, e, n);
  }
}
U(Wt, "CCTPExecutor", we);
const Z = new E("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
new E("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
const Ce = new E("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
new E("So11111111111111111111111111111111111111112");
new E("9pan9bMn5HatX4EJdBwg9VgCa7Uz5HL8N1m5D3NdXejP");
class bn extends Error {
  constructor(t) {
    super(t);
  }
}
class En extends bn {
  constructor() {
    super(...arguments), this.name = "TokenOwnerOffCurveError";
  }
}
var ie;
(function(s) {
  s[s.InitializeMint = 0] = "InitializeMint", s[s.InitializeAccount = 1] = "InitializeAccount", s[s.InitializeMultisig = 2] = "InitializeMultisig", s[s.Transfer = 3] = "Transfer", s[s.Approve = 4] = "Approve", s[s.Revoke = 5] = "Revoke", s[s.SetAuthority = 6] = "SetAuthority", s[s.MintTo = 7] = "MintTo", s[s.Burn = 8] = "Burn", s[s.CloseAccount = 9] = "CloseAccount", s[s.FreezeAccount = 10] = "FreezeAccount", s[s.ThawAccount = 11] = "ThawAccount", s[s.TransferChecked = 12] = "TransferChecked", s[s.ApproveChecked = 13] = "ApproveChecked", s[s.MintToChecked = 14] = "MintToChecked", s[s.BurnChecked = 15] = "BurnChecked", s[s.InitializeAccount2 = 16] = "InitializeAccount2", s[s.SyncNative = 17] = "SyncNative", s[s.InitializeAccount3 = 18] = "InitializeAccount3", s[s.InitializeMultisig2 = 19] = "InitializeMultisig2", s[s.InitializeMint2 = 20] = "InitializeMint2", s[s.GetAccountDataSize = 21] = "GetAccountDataSize", s[s.InitializeImmutableOwner = 22] = "InitializeImmutableOwner", s[s.AmountToUiAmount = 23] = "AmountToUiAmount", s[s.UiAmountToAmount = 24] = "UiAmountToAmount", s[s.InitializeMintCloseAuthority = 25] = "InitializeMintCloseAuthority", s[s.TransferFeeExtension = 26] = "TransferFeeExtension", s[s.ConfidentialTransferExtension = 27] = "ConfidentialTransferExtension", s[s.DefaultAccountStateExtension = 28] = "DefaultAccountStateExtension", s[s.Reallocate = 29] = "Reallocate", s[s.MemoTransferExtension = 30] = "MemoTransferExtension", s[s.CreateNativeMint = 31] = "CreateNativeMint", s[s.InitializeNonTransferableMint = 32] = "InitializeNonTransferableMint", s[s.InterestBearingMintExtension = 33] = "InterestBearingMintExtension", s[s.CpiGuardExtension = 34] = "CpiGuardExtension", s[s.InitializePermanentDelegate = 35] = "InitializePermanentDelegate", s[s.TransferHookExtension = 36] = "TransferHookExtension", s[s.MetadataPointerExtension = 39] = "MetadataPointerExtension";
})(ie || (ie = {}));
function An(s, t, e) {
  if (e.length) {
    s.push({ pubkey: t, isSigner: !1, isWritable: !1 });
    for (const n of e)
      s.push({
        pubkey: n instanceof E ? n : n.publicKey,
        isSigner: !0,
        isWritable: !1
      });
  } else
    s.push({ pubkey: t, isSigner: !0, isWritable: !1 });
  return s;
}
const yn = qe([
  Me("mintAuthorityOption"),
  Ve("mintAuthority"),
  at("supply"),
  Ke("decimals"),
  Ht("isInitialized"),
  Me("freezeAuthorityOption"),
  Ve("freezeAuthority")
]);
yn.span;
function Ne(s, t, e = !1, n = Z, a = Ce) {
  if (!e && !E.isOnCurve(t.toBuffer()))
    throw new En();
  const [r] = E.findProgramAddressSync([t.toBuffer(), n.toBuffer(), s.toBuffer()], a);
  return r;
}
function xn(s, t, e, n, a = Z, r = Ce) {
  return Dn(s, t, e, n, O.Buffer.from([1]), a, r);
}
function Dn(s, t, e, n, a, r = Z, i = Ce) {
  const o = [
    { pubkey: s, 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 Xe({
    keys: o,
    programId: i,
    data: a
  });
}
const _e = qe([Ke("instruction"), at("amount")]);
function Fn(s, t, e, n, a = [], r = Z) {
  const i = An([
    { pubkey: s, isSigner: !1, isWritable: !0 },
    { pubkey: t, isSigner: !1, isWritable: !0 }
  ], e, a), o = O.Buffer.alloc(_e.span);
  return _e.encode({
    instruction: ie.Transfer,
    amount: BigInt(n)
  }, o), new Xe({ keys: i, programId: r, data: o });
}
const vn = {
  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, a) {
    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 = a, t === "Devnet")
      throw new Error("CCTPExecutor not supported on Devnet");
    const r = (u, m) => {
      if (!u)
        throw new Error(m);
      return new E(u);
    };
    this.tokenMessengerProgramId = r((i = a.cctp) == null ? void 0 : i.tokenMessenger, `Circle Token Messenger contract for domain ${e} not found`), this.messageTransmitterProgramId = r((o = a.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(an[t], `Executor contract for ${t} not found`);
  }
  static async fromRpc(t, e) {
    const [n, a] = await Jt.chainFromRpc(t), r = e[a];
    if (r.network !== n)
      throw new Error(`Network mismatch: ${r.network} != ${n}`);
    return new be(n, a, t, r.contracts);
  }
  async *transfer(t, e, n) {
    var w, C;
    const a = new E(y.get(this.network, this.chain)), r = new ne(t).unwrap(), i = Ne(a, r), o = new ne(((C = (w = n.referrer) == null ? void 0 : w.address) == null ? void 0 : C.toString()) ?? r).unwrap(), d = new kt();
    if (d.feePayer = r, n.referrerFee > 0n) {
      const p = Ne(a, o, !0);
      await this.connection.getAccountInfo(p) || d.add(xn(r, p, o, a)), d.add(Fn(i, p, r, n.referrerFee));
    }
    const u = j.get(this.network, e.chain), m = e.address.toUniversalAddress(), f = Ut.generate();
    d.add(await Xt(this.messageTransmitterProgramId, this.tokenMessengerProgramId, a, u, r, i, m, n.remainingAmount, f.publicKey));
    const l = new Zt(vn, this.shimProgramId, { connection: null }), h = q(mt, n.signedQuote), g = en("message_transmitter", this.messageTransmitterProgramId);
    d.add(await l.methods.relayLastMessage({
      execAmount: new Vt(n.estimatedCost.toString()),
      recipientChain: x(e.chain),
      signedQuoteBytes: O.Buffer.from(n.signedQuote),
      relayInstructions: O.Buffer.from(n.relayInstructions)
    }).accounts({
      payer: r,
      messageTransmitter: g,
      payee: new E(h.quote.payeeAddress),
      executorProgram: this.executorProgramId
    }).instruction()), yield this.createUnsignedTx({ transaction: d, signers: [f] }, "SvmCCTPExecutor.Transfer");
  }
  createUnsignedTx(t, e, n = !1) {
    return new Yt(t, this.network, this.chain, e, n);
  }
}
U(zt, "CCTPExecutor", be);
var b;
(function(s) {
  s.Pending = "pending", s.Failed = "failed", s.Unsupported = "unsupported", s.Submitted = "submitted", s.Underpaid = "underpaid", s.Aborted = "aborted";
})(b || (b = {}));
var Oe;
(function(s) {
  s.ERM1 = "ERM1", s.ERV1 = "ERV1", s.ERN1 = "ERN1", s.ERC1 = "ERC1", s.ERC2 = "ERC2";
})(Oe || (Oe = {}));
async function Bn(s) {
  const t = `${fe[s]}/v0/capabilities`;
  try {
    return (await v.get(t)).data;
  } catch {
    throw new Error(`Failed to fetch capabilities for network: ${s}.`);
  }
}
async function Tn(s, t, e, n) {
  const a = `${fe[s]}/v0/quote`;
  try {
    return (await v.post(a, {
      srcChain: x(t),
      dstChain: x(e),
      relayInstructions: n
    })).data;
  } catch {
    throw new Error("Failed to fetch signed quote.");
  }
}
async function Ee(s, t, e) {
  const n = `${fe[s]}/v0/status/tx`;
  try {
    return (await v.post(n, {
      txHash: t,
      chainId: x(e)
    })).data;
  } catch {
    throw new Error(`Failed to fetch status for txHash: ${t}.`);
  }
}
const Sn = 65535n;
function Pn(s, t, e) {
  if (t > Sn)
    throw new Error("dBps exceeds max u16");
  let n = t, a = s, r = 0n;
  if (t > 0) {
    if (e !== void 0 && s > 0) {
      const i = He(e.toString(), 6), o = ue(i) / s, d = t < o ? t : o;
      r = s * d / 100000n, n = d;
    } else
      r = s * t / 100000n;
    a = s - r;
  }
  return { referrerFee: r, remainingAmount: a, referrerFeeDbps: n };
}
function Mn(s) {
  return new Promise((t) => setTimeout(t, s));
}
async function oe(s, t, e = Ze) {
  const n = Q(t, s.chain);
  return Je(async () => {
    var r;
    const a = `${X[t]}/messages/${n}?transactionHash=${s.txid}`;
    try {
      const o = (await v.get(a)).data.messages[0];
      if (!o)
        return null;
      if (o.cctpVersion !== 2)
        throw new Error("CCTPv1 attestation found");
      return o.status === "pending_confirmations" ? null : {
        message: fn(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(s, t, e) {
  const n = Q(s, t), a = Q(s, e), r = `${X[s]}/fastBurn/USDC/fees/${n}/${a}`, i = await v.get(r);
  return BigInt(i.data.minimumFee);
}
async function kn(s, t) {
  const e = k.encode(t.attestation.message.nonce, !0), n = `${X[s]}/reattest/${e}`, a = await v.post(n);
  if (a.data.error) {
    if (a.data.error.includes("Message is already finalized"))
      return t.attestation;
    throw new Error(`Error re-attesting message: ${a.data.error}`);
  }
  const r = it(s, t.attestation.message.sourceDomain);
  return Je(async () => {
    const i = await oe({ txid: t.id, chain: r }, s);
    return !i || i.message.messageBody.expirationBlock !== 0n ? null : i;
  }, 2e3, Ze, "CCTPv2:Reattest");
}
async function Un(s) {
  const t = `${X[s]}/fastBurn/USDC/allowance`, e = await v.get(t);
  return ue(He(e.data.allowance, 6));
}
function Ae(s, t, e) {
  const n = y.get(t.network, t.chain);
  if (!(n && $t(s, B.tokenId(t.chain, n))))
    return [];
  const { network: a, chain: r } = e, i = y.get(a, r);
  return i ? [B.chainAddress(r, i)] : [];
}
let $;
async function ye(s, t, e, n) {
  var Be, Te, Se;
  const { fromChain: a, toChain: r } = s;
  if (!y.get(a.network, a.chain))
    throw new Error("Invalid transfer, no USDC contract on source");
  const o = y.get(r.network, r.chain);
  if (!o)
    throw new Error("Invalid transfer, no USDC contract on destination");
  let d;
  if (e.referrerFeeDbps > 0n && (d = (Te = (Be = e.referrerAddresses) == null ? void 0 : Be[a.network]) == null ? void 0 : Te[a.chain], !d))
    throw new Error(`Referrer address not configured for ${a.chain}`);
  const u = d ? B.chainAddress(a.chain, d) : void 0, { referrerFee: m, remainingAmount: f, referrerFeeDbps: l } = Pn(ue(t.normalizedParams.amount), e.referrerFeeDbps, e.referrerFeeThreshold);
  if (f <= 0n)
    throw new Error("Amount after fee <= 0");
  const h = (Se = on[r.network]) == null ? void 0 : Se[r.chain];
  if (!h)
    throw new Error("Gas limit not found");
  const g = await Bn(a.network);
  if (!g[x(a.chain)])
    throw new Error("Unsupported source chain");
  const C = g[x(r.chain)];
  if (!C || !C.requestPrefixes.includes(n))
    throw new Error("Unsupported destination chain");
  const { recipient: p } = s;
  let D = !0;
  if (p && r.chain === "Solana") {
    const gt = B.parseAddress("Solana", o), pt = await r.getTokenAccount(p.address, gt), Pe = await r.getRpc();
    D = await Pe.getAccountInfo(new ne(pt.address).unwrap()) !== null, !D && !$ && ($ = BigInt(await Pe.getMinimumBalanceForRentExemption(165)));
  }
  let H = 0n;
  r.chain === "Solana" && (H += rn, !D && $ && (H += $));
  const J = [];
  J.push({
    request: {
      type: "GasInstruction",
      gasLimit: h,
      msgValue: H
    }
  });
  const De = BigInt(C.gasDropOffLimit), Y = t.options.nativeGas && De > 0n ? BigInt(Math.round(t.options.nativeGas * 100)) * De / 100n : 0n;
  (Y > 0n || !D) && 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 Rt(new Uint8Array(32))
    }
  });
  const Fe = We(ut, {
    requests: J
  }), ee = await Tn(a.network, a.chain, r.chain, k.encode(Fe, !0));
  if (!ee.estimatedCost)
    throw new Error("No estimated cost");
  const ve = k.decode(ee.signedQuote), lt = q(mt, ve), ht = BigInt(ee.estimatedCost);
  return {
    signedQuote: ve,
    relayInstructions: Fe,
    estimatedCost: ht,
    referrer: u,
    referrerFee: m,
    remainingAmount: f,
    referrerFeeDbps: l,
    expiryTime: lt.quote.expiryTime,
    gasDropOff: Y
  };
}
async function ft(s, t, e, n) {
  q(ut, n.details.relayInstructions).requests.forEach(({ request: f }) => {
    if (f.type === "GasDropOffInstruction" && !f.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 Vn(e, s);
  let o;
  n.protocol === "CCTPExecutor" ? o = await (await s.fromChain.getProtocol(n.protocol)).transfer(r, i, n.details) : o = await (await s.fromChain.getProtocol(n.protocol)).transfer(r, i, n.details);
  const d = await Ye(s.fromChain, o, t);
  let u = 0;
  return (async () => {
    for (; u < 20; ) {
      try {
        const [f] = await Ee(s.fromChain.network, d.at(-1).txid, s.fromChain.chain);
        if (f)
          break;
      } catch {
      }
      u++, await Mn(2e3);
    }
  })(), {
    from: s.fromChain.chain,
    to: s.toChain.chain,
    state: A.SourceInitiated,
    originTxs: d
  };
}
async function Vn(s, t) {
  if (s.chain !== "Solana")
    return s;
  const e = y.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(s.address, n);
}
function ns(s = { referrerFeeDbps: 0n }) {
  if (s.referrerFeeDbps < 0 || s.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends _ {
  }
  return c(t, "config", s), t;
}
class _ extends et {
  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(rt[e] ?? {})];
  }
  static async supportedDestinationTokens(e, n, a) {
    return !V(n.network, n.chain) || !V(a.network, a.chain) ? [] : Ae(e, n, a);
  }
  getDefaultOptions() {
    return {
      nativeGas: 0
    };
  }
  async validate(e, n) {
    var o;
    const { fromChain: a, toChain: r } = e;
    return !V(a.network, a.chain) || !V(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: a, toChain: r } = e;
    try {
      const i = await ye(e, n, this.staticConfig, "ERC1"), { remainingAmount: o, estimatedCost: d, gasDropOff: u, expiryTime: m } = i, f = a.chain === "Polygon" ? 2e3 * 200 : tt(a.chain) + 1e3, [l, h] = await Promise.all([
        a.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: F(o, e.destination.decimals)
        },
        relayFee: {
          token: me(a.chain),
          amount: F(d, l)
        },
        destinationNativeGas: F(u, h),
        eta: f,
        expires: m,
        details: i
      };
    } catch (i) {
      return {
        success: !1,
        error: new Error(i instanceof Error ? i.message : `${i}`)
      };
    }
  }
  async initiate(e, n, a, r) {
    if (!a.details)
      throw new Error("Missing quote details");
    return await ft(e, n, r, {
      protocol: "CCTPExecutor",
      details: a.details
    });
  }
  async *track(e, n) {
    if (G(e) || P(e))
      return e;
    let a = n || 60 * 60 * 1e3;
    for (; a > 0; ) {
      const r = Date.now();
      if (se(e) || ae(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 === b.Failed || // this could happen if simulation fails
          o === b.Underpaid || // only happens if you don't pay at least the costEstimate
          o === b.Unsupported || // capabilities check didn't pass
          o === b.Aborted) && (e = {
            ...e,
            state: A.Failed,
            error: new nt(`Relay failed with status: ${o}`)
          }), o === b.Submitted && (e = {
            ...e,
            state: A.DestinationFinalized,
            attestation: { id: i.id, attestation: {} }
          }), yield e, G(e) || P(e))
            return e;
        } catch (i) {
          console.error(`Error fetching transaction status: ${i.message || i}`);
        }
      await new Promise((i) => setTimeout(i, 3e3)), a -= Date.now() - r;
    }
    return e;
  }
}
c(_, "NATIVE_GAS_DROPOFF_SUPPORTED", !0), c(_, "config", { referrerFeeDbps: 0n }), c(_, "meta", {
  name: "CCTPExecutorRoute",
  provider: "Circle CCTP"
});
class xe extends et {
  static supportedNetworks() {
    return ["Mainnet", "Testnet"];
  }
  static supportedChains(t) {
    return Object.keys(K[t] ?? {});
  }
  getDefaultOptions() {
    return {
      nativeGas: 0
    };
  }
  async initiate(t, e, n, a) {
    if (!n.details)
      throw new Error("Missing quote details");
    return await ft(t, e, a, {
      protocol: "CCTPv2Executor",
      details: n.details
    });
  }
  async *track(t, e) {
    if (G(t))
      return t;
    let n = e || 60 * 60 * 1e3;
    for (; n > 0; ) {
      const a = Date.now();
      if (se(t) || ae(t) || R(t) || P(t))
        try {
          const r = t.originTxs.at(-1).txid;
          if (se(t) || ae(t)) {
            const i = await oe({ chain: t.from, txid: r }, this.wh.network);
            i && (t = {
              ...t,
              state: A.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 === b.Submitted ? t = {
              ...t,
              state: A.DestinationFinalized
            } : (o === b.Failed || // this could happen if simulation fails
            o === b.Underpaid || // only happens if you don't pay at least the costEstimate
            o === b.Unsupported || // capabilities check didn't pass
            o === b.Aborted) && (t = {
              ...t,
              state: A.Failed,
              error: new nt(`Relay failed with status: ${o}`)
            });
          }
          if (P(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: A.DestinationFinalized,
              attestation: i
            });
          }
          if (yield t, G(t))
            return t;
        } catch (r) {
          console.error(`Error fetching transaction status: ${r.message || r}`);
        }
      await new Promise((r) => setTimeout(r, 3e3)), n -= Date.now() - a;
    }
    return t;
  }
  async complete(t, e) {
    if (!R(e) && !P(e))
      throw new Error("Transfer is not attested");
    if (!e.attestation)
      throw new Error("No attestation found");
    const n = this.wh.getChain(e.to), a = await n.getProtocol("CCTPv2Executor");
    let { attestation: r, message: i } = e.attestation.attestation;
    const { expirationBlock: o } = i.messageBody, d = await a.getCurrentBlock();
    if (o !== 0n && o < d) {
      const l = await kn(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()), m = a.redeem(u, i, r), f = await Ye(this.wh.getChain(e.to), m, t);
    return {
      ...e,
      state: A.DestinationInitiated,
      attestation: e.attestation,
      destinationTxs: f
    };
  }
  async resume(t) {
    const e = await oe(t, this.wh.network);
    if (!e)
      throw new Error("No attestation found");
    const { message: n } = e, a = it(this.wh.network, n.destinationDomain);
    return await (await this.wh.getChain(a).getProtocol("CCTPv2Executor")).isTransferCompleted(n) ? {
      from: t.chain,
      to: a,
      state: A.DestinationFinalized,
      originTxs: [t],
      attestation: { id: t.txid, attestation: e }
    } : {
      from: t.chain,
      to: a,
      state: A.Attested,
      originTxs: [t],
      attestation: { id: t.txid, attestation: e }
    };
  }
}
c(xe, "NATIVE_GAS_DROPOFF_SUPPORTED", !0);
function ss(s = { referrerFeeDbps: 0n }) {
  if (s.referrerFeeDbps < 0 || s.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends ce {
  }
  return c(t, "config", s), 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 dn(e.network, e.chain) && re(n.network, n.chain);
  }
  static async supportedDestinationTokens(e, n, a) {
    return this.isPathSupported(n, a) ? Ae(e, n, a) : [];
  }
  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: a, toChain: r } = e;
    try {
      const o = await ye(e, n, this.staticConfig, "ERC2"), { remainingAmount: d, estimatedCost: u, gasDropOff: m, expiryTime: f } = o;
      if (await Un(a.network) <= d)
        return {
          success: !1,
          error: new Error("Insufficient allowance for fast transfer")
        };
      const h = await In(a.network, a.chain, r.chain), g = (d * h + 10000n - 1n) / 10000n, w = d - g;
      if (w <= 0n)
        return {
          success: !1,
          error: new Error("Amount after fast transfer fee <= 0")
        };
      const C = (i = ot[a.network]) == null ? void 0 : i[a.chain], [p, D] = await Promise.all([
        a.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: F(w, e.destination.decimals)
        },
        relayFee: {
          token: me(a.chain),
          amount: F(u, p)
        },
        destinationNativeGas: F(m, D),
        eta: C,
        expires: f,
        details: {
          ...o,
          minFinalityThreshold: W.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 CCTP"
});
let ce = M;
function as(s = { referrerFeeDbps: 0n }) {
  if (s.referrerFeeDbps < 0 || s.referrerFeeDbps > 65535n)
    throw new Error("Referrer fee must be between 0 and 65535");
  class t extends de {
  }
  return c(t, "config", s), t;
}
const I = class I 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, a) {
    return this.isPathSupported(n, a) ? Ae(e, n, a) : [];
  }
  async validate(e, n) {
    var r;
    return I.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: a, toChain: r } = e;
    try {
      const i = await ye(e, n, this.staticConfig, "ERC2"), { remainingAmount: o, estimatedCost: d, gasDropOff: u, expiryTime: m } = i, f = a.chain === "Polygon" ? 2e3 * 200 : tt(a.chain) + 1e3, [l, h] = await Promise.all([
        a.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: F(o, e.destination.decimals)
        },
        relayFee: {
          token: me(a.chain),
          amount: F(d, l)
        },
        destinationNativeGas: F(u, h),
        eta: f,
        expires: m,
        details: {
          ...i,
          minFinalityThreshold: W.FINALIZED,
          fastTransferMaxFee: 0n
          // no fee for standard / slow transfer
        }
      };
    } catch (i) {
      return {
        success: !1,
        error: new Error(i instanceof Error ? i.message : `${i}`)
      };
    }
  }
};
c(I, "config", { referrerFeeDbps: 0n }), c(I, "meta", {
  name: "CCTPv2StandardExecutorRoute",
  provider: "Circle CCTP"
});
let de = I;
const { executorTokenBridgeRoute: rs } = Ot;
export {
  ns as cctpExecutorRoute,
  ss as cctpV2FastExecutorRoute,
  as as cctpV2StandardExecutorRoute,
  rs as executorTokenBridgeRoute
};
