@tenderly/hardhat-integration
Version:
Hardhat plugin for integration with Tenderly
52 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VersionCompatibilityChecker = void 0;
class VersionCompatibilityChecker {
areEthersAndHardhatTenderlyVersionsCompatible(hre, hardhatTenderlyVersion) {
// todo: there should be an interface VersionProvider from this tenderly-hardhat package.
// the hre-extender-v1 and hre-extender-v2 packages should implement that interface on their own
// for both EthersVersionProvider and TenderlyVersionProvider.
// I am casting this to `any` just for the sake of time.
// With this approach, this can easily be tested as well.
let ethersVersion = hre.ethers.version;
ethersVersion = this._trimVersion(ethersVersion, "ethers/");
const ethersMajorVersion = this._majorVersion(ethersVersion);
const hardhatTenderlyMajorVersion = this._majorVersion(hardhatTenderlyVersion);
return [this._areCompatible(ethersMajorVersion, hardhatTenderlyMajorVersion), ethersVersion, hardhatTenderlyVersion];
}
// todo: change this function once we have the available data of which hardhat-tenderly version is the newest.
// Then,
// the function will call the API to get the newest hardhat-tenderly version
// and we can use that to print out the command to upgrade the plugin.
compatibleHardhatTenderlyVersionForEthersVersion(ethersVersion) {
ethersVersion = this._trimVersion(ethersVersion, "ethers/");
const ethersMajorVersion = this._majorVersion(ethersVersion);
if (ethersMajorVersion === 5) {
return "^1.0.0.";
}
if (ethersMajorVersion === 6) {
return "^2.0.0";
}
throw new Error(`Unsupported ethers version: ${ethersVersion}`);
}
_trimVersion(version, toTrim) {
if (version.startsWith(toTrim)) {
return version.slice(toTrim.length);
}
return version;
}
_majorVersion(version) {
return parseInt(version.split(".")[0], 10);
}
_areCompatible(ethersMajorVersion, hardhatTenderlyMajorVersion) {
if (ethersMajorVersion === 5 && hardhatTenderlyMajorVersion === 1) {
return true;
}
if (ethersMajorVersion === 6 && hardhatTenderlyMajorVersion === 2) {
return true;
}
return false;
}
}
exports.VersionCompatibilityChecker = VersionCompatibilityChecker;
//# sourceMappingURL=VersionCompatibilityChecker.js.map