var C = Object.defineProperty;
var x = (i, t, e) => t in i ? C(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
var c = (i, t, e) => x(i, typeof t != "symbol" ? t + "" : t, e);
import { bk as m, bj as T, br as M, bq as k, bv as I, bs as E, aW as N, bE as A, ac as S, W as O, bF as w, a5 as R, j as p, bG as B, aR as u, bH as D, a0 as P } from "./address-BkeBsCZD.mjs";
import { C as F, P as j } from "./chain-uXEmLNMk.mjs";
import { i as V, J as W } from "./provider-jsonrpc-pHUX5SqN.mjs";
import { I as _, B as h, e as z, r as U, C as q } from "./contract-C26uilM9.mjs";
class l {
  /**
   *  Create a new **ContractFactory** with %%abi%% and %%bytecode%%,
   *  optionally connected to %%runner%%.
   *
   *  The %%bytecode%% may be the ``bytecode`` property within the
   *  standard Solidity JSON output.
   */
  constructor(t, e, a) {
    /**
     *  The Contract Interface.
     */
    c(this, "interface");
    /**
     *  The Contract deployment bytecode. Often called the initcode.
     */
    c(this, "bytecode");
    /**
     *  The ContractRunner to deploy the Contract as.
     */
    c(this, "runner");
    const n = _.from(t);
    e instanceof Uint8Array ? e = m(T(e)) : (typeof e == "object" && (e = e.object), e.startsWith("0x") || (e = "0x" + e), e = m(T(e))), M(this, {
      bytecode: e,
      interface: n,
      runner: a || null
    });
  }
  attach(t) {
    return new h(t, this.interface, this.runner);
  }
  /**
   *  Resolves to the transaction to deploy the contract, passing %%args%%
   *  into the constructor.
   */
  async getDeployTransaction(...t) {
    let e = {};
    const a = this.interface.deploy;
    if (a.inputs.length + 1 === t.length && (e = await z(t.pop())), a.inputs.length !== t.length)
      throw new Error("incorrect number of arguments to constructor");
    const n = await U(this.runner, a.inputs, t), f = k([this.bytecode, this.interface.encodeDeploy(n)]);
    return Object.assign({}, e, { data: f });
  }
  /**
   *  Resolves to the Contract deployed by passing %%args%% into the
   *  constructor.
   *
   *  This will resolve to the Contract before it has been deployed to the
   *  network, so the [[BaseContract-waitForDeployment]] should be used before
   *  sending any transactions to it.
   */
  async deploy(...t) {
    const e = await this.getDeployTransaction(...t);
    I(this.runner && typeof this.runner.sendTransaction == "function", "factory runner does not support sending transactions", "UNSUPPORTED_OPERATION", {
      operation: "sendTransaction"
    });
    const a = await this.runner.sendTransaction(e), n = V(a);
    return new h(n, this.interface, this.runner, a);
  }
  /**
   *  Return a new **ContractFactory** with the same ABI and bytecode,
   *  but connected to %%runner%%.
   */
  connect(t) {
    return new l(this.interface, this.bytecode, t);
  }
  /**
   *  Create a new **ContractFactory** from the standard Solidity JSON output.
   */
  static fromSolidity(t, e) {
    E(t != null, "bad compiler output", "output", t), typeof t == "string" && (t = JSON.parse(t));
    const a = t.abi;
    let n = "";
    return t.bytecode ? n = t.bytecode : t.evm && t.evm.bytecode && (n = t.evm.bytecode), new this(a, n, e);
  }
}
const d = [
  {
    anonymous: !1,
    inputs: [
      {
        indexed: !0,
        internalType: "address",
        name: "owner",
        type: "address"
      },
      {
        indexed: !0,
        internalType: "address",
        name: "spender",
        type: "address"
      },
      {
        indexed: !1,
        internalType: "uint256",
        name: "value",
        type: "uint256"
      }
    ],
    name: "Approval",
    type: "event"
  },
  {
    anonymous: !1,
    inputs: [
      {
        indexed: !0,
        internalType: "address",
        name: "from",
        type: "address"
      },
      {
        indexed: !0,
        internalType: "address",
        name: "to",
        type: "address"
      },
      {
        indexed: !1,
        internalType: "uint256",
        name: "value",
        type: "uint256"
      }
    ],
    name: "Transfer",
    type: "event"
  },
  {
    inputs: [],
    name: "DOMAIN_SEPARATOR",
    outputs: [
      {
        internalType: "bytes32",
        name: "",
        type: "bytes32"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "owner_",
        type: "address"
      },
      {
        internalType: "address",
        name: "spender_",
        type: "address"
      }
    ],
    name: "allowance",
    outputs: [
      {
        internalType: "uint256",
        name: "",
        type: "uint256"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "spender_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "amount_",
        type: "uint256"
      }
    ],
    name: "approve",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool"
      }
    ],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "account_",
        type: "address"
      }
    ],
    name: "balanceOf",
    outputs: [
      {
        internalType: "uint256",
        name: "",
        type: "uint256"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "account_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "amount_",
        type: "uint256"
      }
    ],
    name: "burn",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [],
    name: "chainId",
    outputs: [
      {
        internalType: "uint16",
        name: "",
        type: "uint16"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [],
    name: "decimals",
    outputs: [
      {
        internalType: "uint8",
        name: "",
        type: "uint8"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "spender_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "subtractedValue_",
        type: "uint256"
      }
    ],
    name: "decreaseAllowance",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool"
      }
    ],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [],
    name: "eip712Domain",
    outputs: [
      {
        internalType: "bytes1",
        name: "domainFields",
        type: "bytes1"
      },
      {
        internalType: "string",
        name: "domainName",
        type: "string"
      },
      {
        internalType: "string",
        name: "domainVersion",
        type: "string"
      },
      {
        internalType: "uint256",
        name: "domainChainId",
        type: "uint256"
      },
      {
        internalType: "address",
        name: "domainVerifyingContract",
        type: "address"
      },
      {
        internalType: "bytes32",
        name: "domainSalt",
        type: "bytes32"
      },
      {
        internalType: "uint256[]",
        name: "domainExtensions",
        type: "uint256[]"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "spender_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "addedValue_",
        type: "uint256"
      }
    ],
    name: "increaseAllowance",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool"
      }
    ],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "string",
        name: "name_",
        type: "string"
      },
      {
        internalType: "string",
        name: "symbol_",
        type: "string"
      },
      {
        internalType: "uint8",
        name: "decimals_",
        type: "uint8"
      },
      {
        internalType: "uint64",
        name: "sequence_",
        type: "uint64"
      },
      {
        internalType: "address",
        name: "owner_",
        type: "address"
      },
      {
        internalType: "uint16",
        name: "chainId_",
        type: "uint16"
      },
      {
        internalType: "bytes32",
        name: "nativeContract_",
        type: "bytes32"
      }
    ],
    name: "initialize",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "account_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "amount_",
        type: "uint256"
      }
    ],
    name: "mint",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [],
    name: "name",
    outputs: [
      {
        internalType: "string",
        name: "",
        type: "string"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [],
    name: "nativeContract",
    outputs: [
      {
        internalType: "bytes32",
        name: "",
        type: "bytes32"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "owner_",
        type: "address"
      }
    ],
    name: "nonces",
    outputs: [
      {
        internalType: "uint256",
        name: "",
        type: "uint256"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [],
    name: "owner",
    outputs: [
      {
        internalType: "address",
        name: "",
        type: "address"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "owner_",
        type: "address"
      },
      {
        internalType: "address",
        name: "spender_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "value_",
        type: "uint256"
      },
      {
        internalType: "uint256",
        name: "deadline_",
        type: "uint256"
      },
      {
        internalType: "uint8",
        name: "v_",
        type: "uint8"
      },
      {
        internalType: "bytes32",
        name: "r_",
        type: "bytes32"
      },
      {
        internalType: "bytes32",
        name: "s_",
        type: "bytes32"
      }
    ],
    name: "permit",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [],
    name: "symbol",
    outputs: [
      {
        internalType: "string",
        name: "",
        type: "string"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [],
    name: "totalSupply",
    outputs: [
      {
        internalType: "uint256",
        name: "",
        type: "uint256"
      }
    ],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "recipient_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "amount_",
        type: "uint256"
      }
    ],
    name: "transfer",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool"
      }
    ],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "sender_",
        type: "address"
      },
      {
        internalType: "address",
        name: "recipient_",
        type: "address"
      },
      {
        internalType: "uint256",
        name: "amount_",
        type: "uint256"
      }
    ],
    name: "transferFrom",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool"
      }
    ],
    stateMutability: "nonpayable",
    type: "function"
  },
  {
    inputs: [
      {
        internalType: "string",
        name: "name_",
        type: "string"
      },
      {
        internalType: "string",
        name: "symbol_",
        type: "string"
      },
      {
        internalType: "uint64",
        name: "sequence_",
        type: "uint64"
      }
    ],
    name: "updateDetails",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function"
  }
], g = " ", J = (i) => i.length > 1;
class y extends l {
  constructor(...t) {
    J(t) ? super(...t) : super(d, g, t[0]);
  }
  getDeployTransaction(t) {
    return super.getDeployTransaction(t || {});
  }
  deploy(t) {
    return super.deploy(t || {});
  }
  connect(t) {
    return super.connect(t);
  }
  static createInterface() {
    return new _(d);
  }
  static connect(t, e) {
    return new q(t, d, e);
  }
}
c(y, "bytecode", g), c(y, "abi", d);
class $ extends F {
}
const b = class b extends j {
  constructor(e, a) {
    super(e, a ?? A(e, b._platform));
    c(this, "_providers", {});
  }
  getRpc(e) {
    const a = this._providers[e];
    if (a)
      return a;
    if (e in this.config && this.config[e].rpc) {
      const n = new W(this.config[e].rpc, S.get(this.network, e), {
        staticNetwork: !0
      });
      return this._providers[e] = n, n;
    } else
      throw new Error("No configuration available for chain: " + e);
  }
  getChain(e, a) {
    if (e in this.config)
      return new $(e, this, a);
    throw new Error("No configuration available for chain: " + e);
  }
  static nativeTokenId(e, a) {
    if (!b.isSupportedChain(a))
      throw new Error(`invalid chain for EVM: ${a}`);
    return O.tokenId(a, w);
  }
  static isNativeTokenId(e, a, n) {
    return !b.isSupportedChain(a) || n.chain !== a ? !1 : n.address.toString() === w;
  }
  static isSupportedChain(e) {
    return R(e) === b._platform;
  }
  static async getDecimals(e, a, n) {
    if (p(n))
      return B(b._platform);
    const f = b.getTokenImplementation(a, new u(n).toString());
    return Number(await f.decimals());
  }
  static async getBalance(e, a, n, f) {
    return p(f) ? a.getBalance(n) : b.getTokenImplementation(a, new u(f).toString()).balanceOf(n);
  }
  static async getBalances(e, a, n, f) {
    return (await Promise.all(f.map(async (s) => {
      const r = await this.getBalance(e, a, n, s);
      return { [p(s) ? "native" : new u(s).toString()]: r };
    }))).reduce((s, r) => Object.assign(s, r), {});
  }
  static async sendWait(e, a, n) {
    const f = [];
    for (const o of n) {
      const s = await a.broadcastTransaction(o);
      if (f.push(s.hash), e === "Celo") {
        console.error("TODO: override celo block fetching");
        continue;
      }
      if (await s.wait() === null)
        throw new Error("Received null TxReceipt");
    }
    return f;
  }
  static async getLatestBlock(e) {
    return await e.getBlockNumber();
  }
  static async getLatestFinalizedBlock(e) {
    const a = await e.getBlock("finalized");
    if (!a)
      throw new Error("Could not get finalized block");
    return a == null ? void 0 : a.number;
  }
  // Look up the Wormhole Canonical Network and Chain from the EVM chainId
  static chainFromChainId(e) {
    const a = D(b._platform, BigInt(e));
    if (a === void 0)
      throw new Error(`Unknown EVM chainId ${e}`);
    const [n, f] = a;
    return [n, f];
  }
  static async chainFromRpc(e) {
    const { chainId: a } = await e.getNetwork();
    return b.chainFromChainId(P.encode(a, !0));
  }
  static getTokenImplementation(e, a) {
    const n = y.connect(a, e);
    if (!n)
      throw new Error(`No token implementation available for: ${a}`);
    return n;
  }
};
c(b, "_platform", N);
let v = b;
export {
  l as C,
  v as E,
  $ as a
};
