openzeppelin-upgrades
openzeppelin-upgrades copied to clipboard
Retrieve ProxyDeployment by ContractName
Hi there, coming from using the hardhat-deploy-ethers plugin to retrieve a contract by its name, I found a deployed proxy through hardhat upgrades plugin cannot be retrieved the same way. See this link for how getContract<T>(contractName)
works under the hood.
Wondering if proxy deployment could be retreived by contract name in the same way. If this is already possible, how is it achieved? Thanks.
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers, upgrades } from "hardhat";
import { Manifest } from '@openzeppelin/upgrades-core';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployProxy } = upgrades;
const { deployer } = await getNamedAccounts();
const { provider } = hre.network;
const manifest = await Manifest.forNetwork(provider);
const get = deployments.getOrNull;
const Box = await ethers.getContractFactory("Box");
const box = await deployProxy(Box, [], { kind: "uups" });
await box.connect(deployer).deployed();
console.log(await get("Box"));
const proxies = (await manifest.read()).proxies;
console.log(proxies);
console.log(await manifest.getProxyFromAddress(proxies[0].address));
};
export default func;
@simontianx followed this ticket here from the oz forum. the manifest
you are referring to does have the proxy addresses, implantation addresses & storage layout which then has contract name. I am look at the files here projectRootFolder/.openzeppelin/chainName-chainId.json
. So it should be possible to get proxy address by name by processing info in this file and then reading from the chain to see which proxy has which implementation file.