I am upgrading a simple ERC20 Upgradable token contract.
However, I am trying to upgrade it to a new version and all I want to do in the version 2 is simply mint 10000 more tokens.
Here are my doubts:
-
What’s the effective procedure to do it? Can I include the mint function in the initialize(constructor) of the version 2 contract? But will it up upgrade safe then?
-
Will the new version, on deployment, increase the total supply of the token actual token since I am trying to mint some more tokens in vesrion 2?
-
Since I am using the truffle upgrades package to do this whole thing, should I simply use the upgradeProxy package from truffle upgrades? Or how exactly should the migration files be written in order to achieve the desired execution.
My Token V1
pragma solidity 0.6.2;
// SPDX-License-Identifier: MIT
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
contract PlayTokenV1 is Initializable,OwnableUpgradeable,ERC20PausableUpgradeable{
function initialize(address _PublicSaleAddress) initializer public{
__Ownable_init();
__ERC20_init('Play','PLY');
__ERC20Pausable_init();
_mint(owner(),50600000 ether);
_mint(_PublicSaleAddress,1000000 ether);
}
}
My TokenV2
pragma solidity 0.6.2;
// SPDX-License-Identifier: MIT
import "./PlayTokenV1.sol";
contract PlayTokenV2 is PlayToken{
function initialize() initializer public{
_mint(owner(),999 ether);
}
}
Migration file of TokenV2
const { upgradeProxy } = require('@openzeppelin/truffle-upgrades');
const tokenContract = artifacts.require('PlayToken');
const tokenV2 = artifacts.require('PlayTokenV2');
module.exports = async function (deployer,network,accounts) {
const tokenv1 = await tokenContract.deployed();
const newInstance = await upgradeProxy(tokenv1.address, tokenV2, { deployer, initializer: 'initialize' });
console.log("Upgraded to", newInstance.address);
};
Would really appreciate your help @abcoathup