'use strict';

var PUL6NSHI_cjs = require('./PUL6NSHI.cjs');
var KSZMBVFB_cjs = require('./KSZMBVFB.cjs');
var U7VZULNU_cjs = require('./U7VZULNU.cjs');
var esToolkit = require('es-toolkit');
var layerzeroDefinitions = require('@layerzerolabs/layerzero-definitions');
var fs = require('fs');
var semver = require('semver');
var path = require('path');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var fs__default = /*#__PURE__*/_interopDefault(fs);
var semver__namespace = /*#__PURE__*/_interopNamespace(semver);
var path__default = /*#__PURE__*/_interopDefault(path);

// src/utils/finder.ts
U7VZULNU_cjs.init_cjs_shims();

// src/config/index.ts
U7VZULNU_cjs.init_cjs_shims();

// src/config/tools.ts
U7VZULNU_cjs.init_cjs_shims();

// src/utils/version.ts
U7VZULNU_cjs.init_cjs_shims();

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

// src/utils/version.ts
function versionsSatisfied(current, expected) {
  return semver__namespace.satisfies(current, expected);
}
U7VZULNU_cjs.__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 = fs__default.default.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}`);
}
U7VZULNU_cjs.__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;
}
U7VZULNU_cjs.__name(findSemVersionFromString, "findSemVersionFromString");
function validateToolVersion(toolName, version) {
  const supportedVersions = getToolSupportedVersions(toolName);
  return supportedVersions.includes(version);
}
U7VZULNU_cjs.__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: layerzeroDefinitions.ChainType.EVM,
    defaultVolumes: []
  },
  {
    name: "forge",
    chainType: layerzeroDefinitions.ChainType.EVM
  },
  {
    name: "anchor",
    chainType: layerzeroDefinitions.ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersion: /* @__PURE__ */ U7VZULNU_cjs.__name(({ cwd }) => parseAnchorTomlVersion(cwd, "anchor"), "getSecondaryVersion")
  },
  {
    name: "solana",
    chainType: layerzeroDefinitions.ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersion: /* @__PURE__ */ U7VZULNU_cjs.__name(({ cwd }) => parseAnchorTomlVersion(cwd, "solana"), "getSecondaryVersion")
  },
  {
    name: "solana-verify",
    chainType: layerzeroDefinitions.ChainType.SOLANA,
    privileged: true,
    defaultVolumes: solanaDefaultVolumes
  },
  {
    name: "aptos",
    chainType: layerzeroDefinitions.ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "aptos"
      }
    ]
  },
  {
    name: "initiad",
    chainType: layerzeroDefinitions.ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "initia"
      }
    ]
  },
  {
    name: "movement",
    chainType: layerzeroDefinitions.ChainType.APTOSMOVE,
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "movement"
      }
    ]
  },
  {
    name: "blueprint",
    chainType: layerzeroDefinitions.ChainType.TON
  },
  {
    name: "scarb",
    chainType: layerzeroDefinitions.ChainType.STARKNET
  },
  {
    name: "sui",
    chainType: layerzeroDefinitions.ChainType.SUIMOVE,
    defaultVolumes: suiDefaultVolumes
  },
  {
    name: "iota",
    chainType: layerzeroDefinitions.ChainType.SUIMOVE,
    defaultVolumes: iotaDefaultVolumes
  },
  {
    name: "stellar",
    chainType: layerzeroDefinitions.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: layerzeroDefinitions.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__ */ U7VZULNU_cjs.__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__ */ U7VZULNU_cjs.__name((type) => tools.filter((tool) => tool.chainType === type), "findToolsByType");
var getChainTypeForTool = /* @__PURE__ */ U7VZULNU_cjs.__name((toolName) => findToolByName(toolName).chainType, "getChainTypeForTool");
var getImageName = /* @__PURE__ */ U7VZULNU_cjs.__name((basename) => `${basename}-tooling`, "getImageName");
var findMatrixForTool = /* @__PURE__ */ U7VZULNU_cjs.__name((toolName) => Object.values(PUL6NSHI_cjs.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;
}
U7VZULNU_cjs.__name(getToolDefaultVersion, "getToolDefaultVersion");
var findToolVersionsForCombination = /* @__PURE__ */ U7VZULNU_cjs.__name((combination) => Object.fromEntries(Object.entries(combination.images).map(([tool, imageId]) => {
  const versions = KSZMBVFB_cjs.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__ */ U7VZULNU_cjs.__name((toolName) => [
  ...new Set(findMatrixForTool(toolName).map((combination) => findToolVersionsForCombination(combination)[toolName]).filter(esToolkit.isString))
].sort(), "getToolSupportedVersions");

exports.AWS_ACCOUNT_ID = AWS_ACCOUNT_ID;
exports.AWS_REGION = AWS_REGION;
exports.ECR_IMAGE_DIRECTORY = ECR_IMAGE_DIRECTORY;
exports.ECR_REGISTRY = ECR_REGISTRY;
exports.findMatrixForTool = findMatrixForTool;
exports.findParentDirectoryWithFile = findParentDirectoryWithFile;
exports.findSemVersionFromString = findSemVersionFromString;
exports.findToolByName = findToolByName;
exports.findToolVersionsForCombination = findToolVersionsForCombination;
exports.findToolsByType = findToolsByType;
exports.getChainTypeForTool = getChainTypeForTool;
exports.getCombinationId = getCombinationId;
exports.getImageName = getImageName;
exports.getToolDefaultVersion = getToolDefaultVersion;
exports.getToolSupportedVersions = getToolSupportedVersions;
exports.iotaDefaultVolumes = iotaDefaultVolumes;
exports.parseAnchorTomlVersion = parseAnchorTomlVersion;
exports.suiDefaultVolumes = suiDefaultVolumes;
exports.tools = tools;
exports.validateToolVersion = validateToolVersion;
exports.versionsSatisfied = versionsSatisfied;
//# sourceMappingURL=FOFSZBOK.cjs.map
//# sourceMappingURL=FOFSZBOK.cjs.map