Open kanej opened 2 months ago
Does hardhat-ignition currently support deploying UUPS contracts? I can’t find any documentation, is there any plan to support this feature?
There is no explicit feature supporting UUPS, the API allows you to express contract deployments and calls. This task is to provide documentation for how to do that.
you just need to use the generic ERC1967Proxy
:
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
const ProxyModule = buildModule('ProxyModule', (builder) => {
// Deploy the implementation contract
const implementation = builder.contract('MyContract');
// Encode the initialize function call for the contract.
const initialize = builder.encodeFunctionCall(implementation, 'initialize', [
'param1',
'param2',
]);
// Deploy the ERC1967 Proxy, pointing to the implementation
const proxy = builder.contract('ERC1967Proxy', [implementation, initialize]);
return { proxy };
});
export const MyContractModule = buildModule('MyContractModule', (builder) => {
// Get the proxy from the previous module.
const { proxy } = builder.useModule(ProxyModule);
// Create a contract instance using the deployed proxy's address.
const instance = builder.contractAt('MyContract', proxy);
return { instance, proxy };
});
export default MyContractModule;
you just need to use the generic
ERC1967Proxy
:import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; const ProxyModule = buildModule('ProxyModule', (builder) => { // Deploy the implementation contract const implementation = builder.contract('MyContract'); // Encode the initialize function call for the contract. const initialize = builder.encodeFunctionCall(implementation, 'initialize', [ 'param1', 'param2', ]); // Deploy the ERC1967 Proxy, pointing to the implementation const proxy = builder.contract('ERC1967Proxy', [implementation, initialize]); return { proxy }; }); export const MyContractModule = buildModule('MyContractModule', (builder) => { // Get the proxy from the previous module. const { proxy } = builder.useModule(ProxyModule); // Create a contract instance using the deployed proxy's address. const instance = builder.contractAt('MyContract', proxy); return { instance, proxy }; }); export default MyContractModule;
Thank you for providing the solution.
If my contract is inherited from @openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
, can I use this method for deployment? Or is there a specific deployment method for UUPSUpgradeable
?
how would you approach an upgrade module based on this example?
The current upgrade-able contract docs guide is based around the TransparentUpgradeableProxy pattern:
https://hardhat.org/ignition/docs/guides/upgradeable-proxies
We should add a guide for the Universal Upgradeable Proxy Standard pattern.
See the Open Zeppelin docs for a description of the difference: https://docs.openzeppelin.com/contracts/4.x/api/proxy#transparent-vs-uups