import { versionMatrices } from './F35TPZS3.js';
import { images } from './D3JHHTB6.js';
import { init_esm_shims, __name } from './4RNWLMHM.js';
import { isString } from 'es-toolkit';
import { ChainType } from '@layerzerolabs/layerzero-definitions';
import fs2 from 'fs';
import * as semver from 'semver';
import fs from 'node:fs';
import path from 'node:path';

// src/utils/finder.ts
init_esm_shims();

// src/config/index.ts
init_esm_shims();

// src/config/tools.ts
init_esm_shims();

// src/utils/version.ts
init_esm_shims();

// src/utils.ts
init_esm_shims();
function findParentDirectoryWithFile(dir, filename) {
  let cur = dir;
  while (cur !== "/") {
    const filePath = path.join(cur, filename);
    if (fs.existsSync(filePath)) {
      return {
        directory: cur,
        file: filePath
      };
    }
    cur = path.dirname(cur);
  }
  return null;
}
__name(findParentDirectoryWithFile, "findParentDirectoryWithFile");
var getCombinationId = /* @__PURE__ */ __name((combination) => Object.entries(findToolVersionsForCombination(combination)).toSorted().flat().join("-"), "getCombinationId");

// src/utils/version.ts
function versionsSatisfied(current, expected) {
  return semver.satisfies(current, expected);
}
__name(versionsSatisfied, "versionsSatisfied");
function parseAnchorTomlVersion(cwd, name) {
  const projectFolder = findParentDirectoryWithFile(cwd, "Anchor.toml");
  if (projectFolder === null) {
    throw new Error("Anchor project not found");
  }
  const toml = fs2.readFileSync(projectFolder.file, "utf-8");
  const test = /^([a-z]+)(?:_version ?= ?")((?:[0-9]+\.?){3})(?:")$/gm;
  let match;
  while (match = test.exec(toml)) {
    const [, matchedName, version] = match;
    if (matchedName === name && version) {
      return version;
    }
  }
  throw new Error(`${name} version not found in ${projectFolder.file}`);
}
__name(parseAnchorTomlVersion, "parseAnchorTomlVersion");
function findSemVersionFromString(input) {
  const version = input.match(/^(solana-cli|anchor-cli|aptos)\s+(([0-9]+\.?){3}).*?/m)?.[2];
  if (!version) {
    throw new Error(`Invalid semver version: ${input}`);
  }
  return version;
}
__name(findSemVersionFromString, "findSemVersionFromString");
function validateToolVersion(toolName, version) {
  const supportedVersions = getToolSupportedVersions(toolName);
  return supportedVersions.includes(version);
}
__name(validateToolVersion, "validateToolVersion");

// src/config/tools.ts
var solanaDefaultVolumes = [
  {
    type: "isolate",
    containerPath: "/usr/local/cargo",
    name: "solana-cargo",
    shared: true
  },
  {
    // Rustup installs Rust toolchain binaries into the Cargo binary directory.
    // Thus, we can share neither the directory nor its Docker volume.
    type: "isolate",
    containerPath: "/usr/local/cargo/bin",
    name: "solana-cargo-bin"
  },
  {
    type: "isolate",
    containerPath: "/usr/local/rustup",
    name: "solana-rustup"
  },
  {
    type: "isolate",
    containerPath: "/var/lib/docker",
    name: "docker"
  }
];
var suiDefaultVolumes = [
  {
    type: "isolate",
    containerPath: "/root/.move",
    name: "sui",
    shared: true
  },
  {
    type: "isolate",
    containerPath: "/root/.sui",
    name: "sui-config",
    shared: true
  }
];
var iotaDefaultVolumes = [
  {
    type: "isolate",
    containerPath: "/root/.move",
    name: "iota",
    shared: true
  },
  {
    type: "isolate",
    containerPath: "/root/.iota",
    name: "iota-config",
    shared: true
  }
];
var tools = [
  {
    name: "hardhat",
    chainType: ChainType.EVM,
    defaultVolumes: []
  },
  {
    name: "forge",
    chainType: ChainType.EVM
  },
  {
    name: "anchor",
    chainType: ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersion: /* @__PURE__ */ __name(({ cwd }) => parseAnchorTomlVersion(cwd, "anchor"), "getSecondaryVersion")
  },
  {
    name: "solana",
    chainType: ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersion: /* @__PURE__ */ __name(({ cwd }) => parseAnchorTomlVersion(cwd, "solana"), "getSecondaryVersion")
  },
  {
    name: "solana-verify",
    chainType: ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes
  },
  {
    name: "aptos",
    chainType: ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "aptos"
      }
    ]
  },
  {
    name: "initiad",
    chainType: ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "initia"
      }
    ]
  },
  {
    name: "movement",
    chainType: ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "movement"
      }
    ]
  },
  {
    name: "blueprint",
    chainType: ChainType.TON
  },
  {
    name: "scarb",
    chainType: ChainType.STARKNET
  },
  {
    name: "sui",
    chainType: ChainType.SUIMOVE,
    defaultVolumes: suiDefaultVolumes
  },
  {
    name: "iota",
    chainType: ChainType.SUIMOVE,
    defaultVolumes: iotaDefaultVolumes
  },
  {
    name: "stellar",
    chainType: ChainType.STELLAR,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.config/stellar",
        name: "stellar-config",
        shared: true,
        locked: true
      },
      {
        type: "isolate",
        containerPath: "/usr/local/cargo",
        name: "stellar-cargo",
        shared: true,
        locked: true
      },
      {
        type: "isolate",
        containerPath: "/usr/local/rustup",
        name: "stellar-rustup",
        shared: true,
        locked: true
      }
    ]
  },
  {
    name: "daml",
    chainType: ChainType.CANTON,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.daml",
        name: "canton-daml-cache",
        shared: true,
        locked: false
      }
    ]
  }
];

// src/config/index.ts
var AWS_ACCOUNT_ID = "438003944538";
var AWS_REGION = "us-east-1";
var ECR_REGISTRY = `${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com`;
var ECR_IMAGE_DIRECTORY = "layerzerolabs";

// src/utils/finder.ts
var findToolByName = /* @__PURE__ */ __name((toolName) => {
  const tool = tools.find((tool2) => tool2.name === toolName);
  if (!tool) {
    throw new Error(`Tool '${toolName}' not found`);
  }
  return tool;
}, "findToolByName");
var findToolsByType = /* @__PURE__ */ __name((type) => tools.filter((tool) => tool.chainType === type), "findToolsByType");
var getChainTypeForTool = /* @__PURE__ */ __name((toolName) => findToolByName(toolName).chainType, "getChainTypeForTool");
var getImageName = /* @__PURE__ */ __name((basename) => `${basename}-tooling`, "getImageName");
var findMatrixForTool = /* @__PURE__ */ __name((toolName) => Object.values(versionMatrices).find((combinations) => combinations.some(({ images: images2 }) => images2[toolName])) ?? [], "findMatrixForTool");
function getToolDefaultVersion(toolName) {
  const combination = findMatrixForTool(toolName)[0];
  if (!combination) {
    return null;
  }
  const version = findToolVersionsForCombination(combination)[toolName];
  if (!version) {
    console.warn(`No default version found for tool '${toolName}' in matrix`);
    return null;
  }
  return version;
}
__name(getToolDefaultVersion, "getToolDefaultVersion");
var findToolVersionsForCombination = /* @__PURE__ */ __name((combination) => Object.fromEntries(Object.entries(combination.images).map(([tool, imageId]) => {
  const versions = images[imageId].versions;
  const version = versions[tool];
  if (!version) {
    throw new Error(`Tool ${tool} not found in Docker image: ${imageId}`);
  }
  return [
    tool,
    version
  ];
})), "findToolVersionsForCombination");
var getToolSupportedVersions = /* @__PURE__ */ __name((toolName) => [
  ...new Set(findMatrixForTool(toolName).map((combination) => findToolVersionsForCombination(combination)[toolName]).filter(isString))
].sort(), "getToolSupportedVersions");

export { AWS_ACCOUNT_ID, AWS_REGION, ECR_IMAGE_DIRECTORY, ECR_REGISTRY, findMatrixForTool, findParentDirectoryWithFile, findSemVersionFromString, findToolByName, findToolVersionsForCombination, findToolsByType, getChainTypeForTool, getCombinationId, getImageName, getToolDefaultVersion, getToolSupportedVersions, iotaDefaultVolumes, parseAnchorTomlVersion, suiDefaultVolumes, tools, validateToolVersion, versionsSatisfied };
//# sourceMappingURL=H7LPHZJT.js.map
//# sourceMappingURL=H7LPHZJT.js.map