Upgrade Contract by adding new parameter to initialize()

Hi, I am having an issue upgrading my contract using upgradeProxy when I adding a new parameter.
I am using truffle to do migration using upgradeProxy:

await upgradeProxy(existing.address, BoxV3, { deployer });

How do I add an extra parameter to BoxV3? the expectation is as below:

Before upgrade

    function initialize( USDToken _usdToken) public {
        usdToken = _usdToken;
    }

After upgrade

  function initialize( USDToken _usdToken, SGDToken _sgdToken) public {
        usdToken = _usdToken;
        sgdToken = _sgdToken
    }

Thanks in advance.

Have you tried this? What error did you get?

Hi Frangio, thank you for helping. as upgradeProxy does not provide any args as parameter like deployProxy, i tried to deploy the BoxV3 using deployProxy before I pass it into upgradeProxy but also not working

Here is my code:

 const x = await deployProxy(BoxV3, [USDToken.address,SGDToken.address], { deployer, initializer: 'initialize' });
    await upgradeProxy(existing.address, x, { deployer });

I was wondering is that any reference to add extra parameter into initialize function when upgrade the contract like from 1 parameter into 2.

Ok, the thing is when you use upgradeProxy you’re changing the implementation of a contract that has already been initialized. So calling the initializer wouldn’t make sense. It would definitely make sense to call a function that “migrates” to the new version and initializes only the new state variables. There is nothing currently in the plugin to help you with that, although we do want to add it soon:

In the meantime you have to define a function and call it manually.