var I = Object.defineProperty;
var M = (r, t, e) => t in r ? I(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var c = (r, t, e) => M(r, typeof t != "symbol" ? t + "" : t, e);
import { bs as u, br as y, bz as B, by as x, bD as E, bA as A, bM as N, aF as O, bN as R, y as S, W as P, bO as m, n as D, m as h, bP as $, ay as T, bQ as U, h as F } from "./address-QpeLv2yn.mjs";
import { C as V } from "./chain-B7MIR9_r.mjs";
import { i as W, J as j } from "./provider-jsonrpc-BXNY8lbA.mjs";
import { I as k, B as g, e as q, r as z, C as G } from "./contract-D4Vzf62E.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 = k.from(t);
    e instanceof Uint8Array ? e = u(y(e)) : (typeof e == "object" && (e = e.object), e.startsWith("0x") || (e = "0x" + e), e = u(y(e))), B(this, {
      bytecode: e,
      interface: n,
      runner: a || null
    });
  }
  attach(t) {
    return new g(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 q(t.pop())), a.inputs.length !== t.length)
      throw new Error("incorrect number of arguments to constructor");
    const n = await z(this.runner, a.inputs, t), f = x([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);
    E(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 = W(a);
    return new g(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) {
    A(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"
  }
], w = " ", H = (r) => r.length > 1;
class p extends l {
  constructor(...t) {
    H(t) ? super(...t) : super(d, w, t[0]);
  }
  getDeployTransaction(t) {
    return super.getDeployTransaction(t || {});
  }
  deploy(t) {
    return super.deploy(t || {});
  }
  connect(t) {
    return super.connect(t);
  }
  static createInterface() {
    return new k(d);
  }
  static connect(t, e) {
    return new G(t, d, e);
  }
}
c(p, "bytecode", w), c(p, "abi", d);
class J extends V {
}
const v = {
  Mainnet: {
    Ethereum: "eth-mainnet",
    Polygon: "matic-mainnet",
    Bsc: "bsc-mainnet",
    Optimism: "optimism-mainnet",
    Base: "base-mainnet",
    Worldchain: "world-mainnet",
    Sei: "sei-mainnet",
    Ink: "ink-mainnet",
    Solana: "solana-mainnet"
  },
  Testnet: {
    Ethereum: "eth-sepolia",
    Polygon: "polygon-amoy-testnet",
    Bsc: "bsc-testnet",
    Optimism: "optimism-sepolia",
    Base: "base-sepolia-testnet",
    Worldchain: "world-sepolia-testnet",
    Unichain: "unichain-sepolia-testnet",
    Berachain: "berachain-testnet",
    Ink: "ink-sepolia-testnet"
  },
  Devnet: {}
};
class L {
  constructor(t) {
    c(this, "key");
    this.key = t;
  }
  supportsChain(t, e) {
    return v[t][e] !== void 0;
  }
  async getBalances(t, e, a) {
    const n = v[t][e];
    if (!n)
      throw new Error("Chain not supported by GoldRush indexer");
    const { data: f } = await (await fetch(`https://api.covalenthq.com/v1/${n}/address/${a}/balances_v2/?key=${this.key}`)).json(), b = {};
    for (let i of f.items)
      b[i.contract_address] = BigInt(i.balance);
    return b;
  }
}
const _ = {
  Mainnet: {
    Ethereum: "eth-mainnet",
    Base: "base-mainnet",
    Arbitrum: "arb-mainnet",
    Optimism: "opt-mainnet",
    Polygon: "polygon-mainnet",
    Worldchain: "worldchain-mainnet",
    Ink: "ink-mainnet",
    Unichain: "unichain-mainnet",
    Berachain: "berachain-mainnet"
  },
  Testnet: {
    Ethereum: "eth-sepolia",
    Base: "base-sepolia",
    Arbitrum: "arb-sepolia",
    Optimism: "opt-sepolia",
    Polygon: "polygon-amoy",
    Worldchain: "worldchain-sepolia",
    Ink: "ink-sepolia",
    Unichain: "unichain-sepolia",
    Berachain: "berachain-bartio",
    Monad: "monad-testnet"
  },
  Devnet: {}
};
class Q {
  constructor(t) {
    c(this, "key");
    this.key = t;
  }
  supportsChain(t, e) {
    return _[t][e] !== void 0;
  }
  async getBalances(t, e, a) {
    const n = _[t][e];
    if (!n)
      throw new Error("Chain not supported by Alchemy indexer");
    const { result: f } = await (await fetch(`https://${n}.g.alchemy.com/v2/${this.key}`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        jsonrpc: "2.0",
        id: 1,
        method: "alchemy_getTokenBalances",
        params: [a]
      })
    })).json(), b = {};
    for (let i of f.tokenBalances)
      b[i.contractAddress] = BigInt(parseInt(i.balance, 16));
    return b;
  }
}
const s = class s extends N {
  constructor(e, a) {
    super(e, a ?? R(e, s._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 j(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 J(e, this, a);
    throw new Error("No configuration available for chain: " + e);
  }
  static nativeTokenId(e, a) {
    if (!s.isSupportedChain(a))
      throw new Error(`invalid chain for EVM: ${a}`);
    return P.tokenId(a, m);
  }
  static isNativeTokenId(e, a, n) {
    return !s.isSupportedChain(a) || n.chain !== a ? !1 : n.address.toString() === m;
  }
  static isSupportedChain(e) {
    return D(e) === s._platform;
  }
  static async getDecimals(e, a, n, f) {
    if (h(f))
      return $(s._platform);
    const b = s.getTokenImplementation(n, new T(f).toString());
    return Number(await b.decimals());
  }
  static async getBalance(e, a, n, f, b) {
    return h(b) ? n.getBalance(f) : s.getTokenImplementation(n, new T(b).toString()).balanceOf(f);
  }
  static async getBalances(e, a, n, f, b) {
    if (b) {
      if (b.goldRush)
        try {
          const i = new L(b.goldRush);
          if (i.supportsChain(e, a)) {
            const o = await i.getBalances(e, a, f);
            return o.native = await n.getBalance(f), o;
          } else
            console.error(`Network=${e} Chain=${a} not supported by Gold Rush indexer API`);
        } catch (i) {
          console.error(`Error querying Gold Rush indexer API: ${i}`);
        }
      if (b.alchemy)
        try {
          const i = new Q(b.alchemy);
          if (i.supportsChain(e, a)) {
            const o = await i.getBalances(e, a, f);
            return o.native = await n.getBalance(f), o;
          } else
            console.error(`Network=${e} Chain=${a} not supported by Alchemy indexer API`);
        } catch (i) {
          console.error(`Error querying Alchemy indexer API: ${i}`);
        }
    } else
      throw new Error("Can't get all EVM balances without an indexer. Use getBalance to make individual calls instead.");
    throw new Error("Failed to get a successful response from an EVM indexer");
  }
  static async sendWait(e, a, n) {
    const f = [];
    for (const b of n) {
      const i = await a.broadcastTransaction(b);
      if (f.push(i.hash), e === "Celo") {
        console.error("TODO: override celo block fetching");
        continue;
      }
      if (await i.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 = U(s._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 s.chainFromChainId(F.encode(a, !0));
  }
  static getTokenImplementation(e, a) {
    const n = p.connect(a, e);
    if (!n)
      throw new Error(`No token implementation available for: ${a}`);
    return n;
  }
};
c(s, "_platform", O);
let C = s;
export {
  l as C,
  C as E,
  J as a
};
