UNPKG

@solarity/hardhat-migrate

Version:
67 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sleep = void 0; exports.getPossibleImplementationAddress = getPossibleImplementationAddress; exports.castAmount = castAmount; exports.toGWei = toGWei; exports.resolvePathToFile = resolvePathToFile; exports.getInstanceNameFromClass = getInstanceNameFromClass; exports.deepCopy = deepCopy; exports.toJSON = toJSON; const path_1 = require("path"); const ethers_1 = require("ethers"); const constants_1 = require("../constants"); const NetworkManager_1 = require("../tools/network/NetworkManager"); async function getPossibleImplementationAddress(proxyAddress) { const provider = (await NetworkManager_1.networkManager.getSigner()).provider; let implementationAddress = (0, ethers_1.toBeHex)(await provider.getStorage(proxyAddress, constants_1.DEFAULT_IMPLEMENTATION_SLOT), 20); if (implementationAddress !== ethers_1.ethers.ZeroAddress) { return implementationAddress; } implementationAddress = (0, ethers_1.toBeHex)(await provider.getStorage(proxyAddress, constants_1.BEACON_IMPLEMENTATION_SLOT), 20); if (implementationAddress !== ethers_1.ethers.ZeroAddress) { return implementationAddress; } return ethers_1.ethers.ZeroAddress; } function castAmount(value, nativeSymbol = "ETH") { if (value > 0n && value < 10n ** 12n) { return toGWei(value) + " GWei"; } return (0, ethers_1.formatEther)(value) + ` ${nativeSymbol}`; } function toGWei(value) { return (0, ethers_1.formatUnits)(value, "gwei"); } function resolvePathToFile(hre, path, file = "") { const pathToMigration = (0, path_1.join)(hre.config.paths.root, path, file); return pathToMigration.endsWith(path_1.sep) ? pathToMigration.slice(0, -1) : pathToMigration; } function getInstanceNameFromClass(instance) { const className = parseClassName(instance.toString()); return className === undefined ? constants_1.UNKNOWN_CONTRACT_NAME : className.replace("__factory", ""); } function parseClassName(classDefinitionString) { // Regular expression to match the class name const classNameRegex = /class\s+([^\s]+)\s*\{/; const match = classDefinitionString.match(classNameRegex); if (match && match.length > 1) { return match[1]; } return undefined; } function deepCopy(obj) { return JSON.parse(toJSON(obj)); } const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); exports.sleep = sleep; function toJSON(data) { return JSON.stringify(data, JSONConvertor); } function JSONConvertor(_key, value) { if (typeof value === "bigint") { return value.toString(); } return value; } //# sourceMappingURL=common.js.map