Complete the code to declare a new version number for a smart contract upgrade.
uint256 public constant VERSION = [1];The version number should be a numeric constant, so 1 is correct.
Complete the code to emit an event when the contract is upgraded.
event Upgraded(address indexed [1]);owner which may not reflect the upgrader.sender which is less descriptive here.The event should log the address of the upgrader, so upgrader is the best choice.
Fix the error in the upgrade function to correctly call the new implementation.
function upgradeTo(address newImplementation) external [1] { require(newImplementation != address(0), "Invalid address"); _implementation = newImplementation; emit Upgraded(msg.sender); }
private which prevents external calls.The upgrade function should be restricted to the contract owner, so the onlyOwner modifier is needed.
Fill both blanks to create a mapping that stores upgrade timestamps and a function to check if upgrade is allowed.
mapping(address => uint256) public [1]; function canUpgrade(address upgrader) public view returns (bool) { return block.timestamp >= [2][upgrader] + 1 days; }
The mapping and the function should use the same name lastUpgradeTime to track timestamps.
Fill all three blanks to implement a function that upgrades the contract only if the new version is higher and updates the version number.
function upgradeToVersion(uint256 newVersion, address newImplementation) external [1] { require(newVersion > [2], "Version must be higher"); upgradeTo(newImplementation); [3] = newVersion; }
The function should be restricted to the owner (onlyOwner), compare with currentVersion, and update _version.