Hi everyone, I've a question about an upgrade that I should apply to an upgradable contract.
I'm following the guidelines and best practices but I'm not sure the change would have any issue.
I would like to:
-
create a new contract V2 starting from the deployed one
-
add on this contract a new bool variable
bool private isLocked;
(as last variable in the variables list declaration and without a starting value, since the initialize has been called with the proxy contract deployment)
- the first contract deployed has this function
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override (ERC721Upgradeable,ERC721EnumerableUpgradeable) {
super._beforeTokenTransfer(from, to, tokenId);
}
I would change it this way, to let the transfer only when isLocked is false or the users are minting
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override (ERC721Upgradeable,ERC721EnumerableUpgradeable) {
require(!isLocked || from == address(0));
super._beforeTokenTransfer(from, to, tokenId);
}
and then adding set and get methods to change and retrieve the isLocked variable.
Then I would deploy using the original contract address as in the documentation
async function main () {
const ContractV2 = await ethers.getContractFactory('ContractV2');
console.log('Upgrading ContractV2...');
await upgrades.upgradeProxy(FIRST_CONTRACT_ADDRESS, ContractV2);
console.log('Contract upgraded');
}
main();
Do you see any issue with these changes?
The new functions, for example the get and set of the isLocked variable, need to follow a specific order in the code (for example at the end of the contract code) or can be placed anywhere, any other aspect to consider?
Thank you