wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.2k stars 296 forks source link

OpenZeppelin UUPS proxy support #146

Open jaypaik opened 3 years ago

jaypaik commented 3 years ago

I see that OpenZeppelinTransparentProxy is supported. Are there any plans to add UUPS proxy support in the near future?

sbaranov commented 1 year ago

Will this avoid having to set _ADMIN_SLOT? UUPS generally isn't supposed to use _ADMIN_SLOT.

wighawag commented 1 year ago

I guess you refers to this comment : https://github.com/wighawag/hardhat-deploy/issues/146#issuecomment-1244674006

UUPS idea is that proxy upgrade are handled in the implementation. so setting proxyContract: 'UUPS', will not change that and you can handle admin check the way you want.

As I mentioned here, you do not need to use the proxied modifier (that use _ADMIN_SLOTS)

sbaranov commented 1 year ago

This is exactly right. And the contract is not using the proxied modifier.

For UUPSUpgradeable, the plugin code should not assume that the upgrades are controlled by _ADMIN_SLOT, owner(), or any other fixed logic. If needed, the plugin could perhaps invoke _authorizeUpgrade() and see if it succeeds.

But the point is that the following check in the plugin should be skipped for UUPS: https://github.com/wighawag/hardhat-deploy/blob/ee7e872fc8f8fa5ed63a00deaf25c6c7cd464a18/src/helpers.ts#L1543

There are several other comments above that all attempt to describe this same problem: #1, #2, #3, #4, #5, #6. They all seem correct to me, so I'm curious to understand what exactly is the disconnect here :-)

wighawag commented 1 year ago

Ha yes, sorry, my bad, did not consider that the plugin would fails there.

I will indeed need to add an option to skip that condition checkk. The plugin cannot call _authorizeUpgrade though as this is an internal function.

0xTimepunk commented 1 year ago

I'll wait for that condition fix :) Thanks

wighawag commented 1 year ago

fix in 0.11.22

Let me know if there are any issues

0xTimepunk commented 1 year ago

@wighawag

Thank you so much!

It is finally working!!!!!!!!!

omryozgrappa commented 1 year ago

@0xTimepunk Just added the UUPS option in v0.11.21

you just do the following :

await deploy('MyContract', {
  from: deployer,
  proxy: {
    proxyContract: 'UUPS',
  }
});

or if you need some initialization:

await deploy('MyContract', {
  from: deployer,
  proxy: {
    proxyContract: 'UUPS',
    execute: {
      init: {
        methodName: 'init',
        args: ['hello'],
      },
    },
  },
});

Thanks for this update! I had an issue with init function which is not being executed. I had to change the proxy options:

proxy: {
 proxyContract: 'UUPS',
  execute: {
     methodName: 'init',
        args: ['hello'],
   },
  },

also, it is not clear how do i upgrade the implementation . can you share a snippet ?

Sotatek-HaiTrieu2 commented 1 year ago

@omryozgrappa did you find a snippet for upgrading?

omryozgrappa commented 1 year ago

yes... @Sotatek-HaiTrieu2


await deploy('ProxyContractName', {
        from: deployerAddress,
        args: constructorArgs,
        libraries: libraries,
        proxy:{
            proxyContract: 'UUPS',
            upgradeIndex: 1,
            execute: {
                methodName: 'anReinitializerMethod',
                args: theMethodArgs,
            },
            implementationName: 'TheNameOfTheNewImplementationContract',
        },,
        contract: 'TheNameOfTheNewImplementationContract',
    }) 
n00b21337 commented 1 year ago

@0xTimepunk Just added the UUPS option in v0.11.21 you just do the following :

await deploy('MyContract', {
  from: deployer,
  proxy: {
    proxyContract: 'UUPS',
  }
});

or if you need some initialization:

await deploy('MyContract', {
  from: deployer,
  proxy: {
    proxyContract: 'UUPS',
    execute: {
      init: {
        methodName: 'init',
        args: ['hello'],
      },
    },
  },
});

Thanks for this update! I had an issue with init function which is not being executed. I had to change the proxy options:

proxy: {
 proxyContract: 'UUPS',
  execute: {
     methodName: 'init',
        args: ['hello'],
   },
  },

also, it is not clear how do i upgrade the implementation . can you share a snippet ?

Its not called "init" in UUPS but "initialize" so you need to have it like this

 execute: {
        init: {
          methodName: 'initialize',
          args: args,
        },
      },