1

I have the following upgradeable contract using @import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract StargateSwap is Initializable, AccessControlUpgradeable, PausableUpgradeable {
using SafeERC20 for IERC20;
    
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
uint16 public constant ETH_POOL_ID = 13;

address public stargateRouter;
address public stargateEthVault;
uint16 public dstPoolId;

mapping (address => bool) public validOutputTokens;

function initialize(
    address _stargateRouter, 
    address _stargateEthVault, 
    uint16 _destPoolId, 
    address[] memory _validOutputTokens
) public initializer {
    __Context_init_unchained();
    __AccessControl_init_unchained();
    _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
    _setupRole(OPERATOR_ROLE, _msgSender());
    stargateRouter = _stargateRouter;
    stargateEthVault = _stargateEthVault;
    dstPoolId = _destPoolId;
    for(uint i; i < _validOutputTokens.length; i++) {
        validOutputTokens[_validOutputTokens[i]] = true;
    }
}

And I am using the following deployment script using hardhat-deploy (https://www.npmjs.com/package/hardhat-deploy)

const STARGATE = require("../constants/stargate.json")

module.exports = async function ({ deployments, getNamedAccounts }) {
    const { deploy } = deployments
    const { deployer } = await getNamedAccounts()

    const stargateRouter = STARGATE.router[hre.network.name];
    const stargateEthVault = STARGATE.ethVault[hre.network.name];
    console.log(`[${hre.network.name}] Stargate Router address: ${stargateRouter}`);
    console.log(`[${hre.network.name}] Stargate ETH vault address: ${stargateEthVault}`);
    console.log(`[${hre.network.name}] Deployer: ${deployer}`);
    
    await deploy("Fiat24StargateSwap", {
        from: deployer,
        log: true,
        proxy: {
            owner: deployer,
            proxyContract: 'OpenZeppelinTransparentProxy',
            methodName: 'init',
        },
        args: [ stargateRouter, 
                stargateEthVault, 
                1, 
                ["0xbE00f3db78688d9704BCb4e0a827aea3a9Cc0D62", 
                "0x2c5d06f591D0d8cd43Ac232c2B654475a142c7DA", 
                "0xd41F1f0cf89fD239ca4c1F8E8ADA46345c86b0a4", 
                "0x5fc17218196581864974574d715cFC7334794cBE"]],
        waitConfirmations: 1,
    })
}

And I get the following error message:

Error: The number of arguments passed to not match the number of argument in the implementation constructor. Please specify the correct number of arguments as part of the deploy options: "args"

2 Answers 2

0

Looks like your function names don't match. Your script claims it's init but your contract has function initialize. Fix that.

Read more info about hardhat-deploy proxy deployment here.

1
  • Thank you very much @Lauri Peltonen. I've changed to initialize, but still get the same error.
    – user66732
    Jan 16, 2023 at 18:08
0

The args option expects the constructor to have the specified arguments. When you need to pass arguments only to a proxy init function then you can do it like this instead:

const deployed = await deploy("YourContract", {
  from: deployer,
  proxy: {
    execute: {
      init: {
        methodName: "initialize",
        args: ["arg1", "arg2"],
      },
    },
    proxyContract: "OpenZeppelinTransparentProxy",
  },
  log: true,
  autoMine: true,
});

Note that the we use execute instead and don’t specify any args for the constructor itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.