-
Notifications
You must be signed in to change notification settings - Fork 4
add semantic versioning to contracts #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "AddressDojangResolver": "0x692009FE206C3F897867F6BF7B5B45506B747F9e", | ||
| "AttestationIndexer": "0x9C9Bf29880448aB39795a11b669e22A0f1d790ec", | ||
| "BalanceDojangResolver": "0x6FFa7ABc1E380Bb967C78D5E648EF804e1fE6dAd", | ||
| "DojangAttesterBook": "0xDA282E89244424E297Ce8e78089B54D043FB28B6", | ||
| "DojangScroll": "0xd5077b67dcb56caC8b270C7788FC3E6ee03F17B9", | ||
| "SchemaBook": "0x78cBb3413FBb6aF05EF1D21e646440e56baE3AD6" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {console2 as console} from "forge-std/console2.sol"; | ||
| import {Script} from "forge-std/Script.sol"; | ||
| import {VmSafe} from "forge-std/Vm.sol"; | ||
| import {ISemver} from "../../src/interfaces/ISemver.sol"; | ||
| import {Strings} from "@openzeppelin-contracts/utils/Strings.sol"; | ||
| import {DeployConfig} from "../utils/DeployConfig.s.sol"; | ||
| import {UUPSUpgradeable} from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
|
||
| contract Upgrade is Script, DeployConfig { | ||
| uint256 internal deployerKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); | ||
| address internal deployer = vm.addr(deployerKey); | ||
|
|
||
| uint256 internal upgraderKey = vm.envUint("UPGRADER_PRIVATE_KEY"); | ||
| address internal upgrader = vm.addr(upgraderKey); | ||
|
|
||
| function run() public { | ||
| upgradeUUPSContract(getAddress(".SchemaBook"), "SchemaBook.sol", new bytes(0), new bytes(0)); | ||
| upgradeUUPSContract(getAddress(".DojangAttesterBook"), "DojangAttesterBook.sol", new bytes(0), new bytes(0)); | ||
| upgradeUUPSContract(getAddress(".AttestationIndexer"), "AttestationIndexer.sol", new bytes(0), new bytes(0)); | ||
| upgradeUUPSContract( | ||
| getAddress(".AddressDojangResolver"), "AddressDojangResolver.sol", new bytes(0), new bytes(0) | ||
| ); | ||
| upgradeUUPSContract( | ||
| getAddress(".BalanceDojangResolver"), "BalanceDojangResolver.sol", new bytes(0), new bytes(0) | ||
| ); | ||
| upgradeUUPSContract(getAddress(".DojangScroll"), "DojangScroll.sol", new bytes(0), new bytes(0)); | ||
| } | ||
|
|
||
| function upgradeUUPSContract( | ||
| address proxy, | ||
| string memory contractName, | ||
| bytes memory constructorData, | ||
| bytes memory initData | ||
| ) | ||
| public | ||
| { | ||
| if (!_needsUpgrade(proxy, contractName, constructorData)) { | ||
| return; | ||
| } | ||
|
|
||
| console.log("\nStarting upgrade for %s", contractName); | ||
|
|
||
| vm.startBroadcast(deployerKey); | ||
| address newImpl = vm.deployCode(contractName, constructorData); | ||
| vm.stopBroadcast(); | ||
|
|
||
| console.log("New Implementation contract at %s", newImpl); | ||
|
|
||
| vm.startBroadcast(upgraderKey); | ||
| UUPSUpgradeable(proxy).upgradeToAndCall(newImpl, initData); | ||
| vm.stopBroadcast(); | ||
|
|
||
| console.log("Upgrade complete \n"); | ||
| } | ||
|
|
||
| function _needsUpgrade( | ||
| address proxy, | ||
| string memory contractName, | ||
| bytes memory constructorData | ||
| ) | ||
| internal | ||
| returns (bool) | ||
| { | ||
| (VmSafe.CallerMode m,,) = vm.readCallers(); | ||
| require(m == VmSafe.CallerMode.None, "Only offchain"); | ||
|
|
||
| (bool success,) = proxy.staticcall(abi.encodeWithSelector(ISemver.version.selector)); | ||
| if (!success) { | ||
| return true; | ||
| } | ||
|
Comment on lines
+70
to
+73
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
|
|
||
| ISemver proxyContract = ISemver(proxy); | ||
| ISemver newImplContract = ISemver(vm.deployCode(contractName, constructorData)); | ||
|
|
||
| return !Strings.equal(proxyContract.version(), newImplContract.version()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {console2 as console} from "forge-std/console2.sol"; | ||
| import {stdJson} from "forge-std/StdJson.sol"; | ||
| import {Vm} from "forge-std/Vm.sol"; | ||
|
|
||
| abstract contract DeployConfig { | ||
| /// @notice Foundry cheatcode VM. | ||
| Vm private constant _vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); | ||
|
|
||
| string private _deployConfigJson; | ||
|
|
||
| function setUp() public virtual { | ||
| string memory deployConfigFilePath = | ||
| string.concat(_vm.projectRoot(), "/deploy-config/", _vm.toString(block.chainid), ".json"); | ||
| _deployConfigJson = _vm.readFile(deployConfigFilePath); | ||
|
|
||
| console.log("Fetching deploy config from %s", deployConfigFilePath); | ||
| console.log("Connected to network with chainid %s", block.chainid); | ||
| } | ||
|
|
||
| function keyExists(string memory key) internal view returns (bool) { | ||
| return stdJson.keyExists(_deployConfigJson, key); | ||
| } | ||
|
|
||
| function getAddress(string memory key) internal view returns (address) { | ||
| return stdJson.readAddress(_deployConfigJson, key); | ||
| } | ||
|
|
||
| function getAddresses(string memory key) internal view returns (address[] memory) { | ||
| return stdJson.readAddressArray(_deployConfigJson, key); | ||
| } | ||
|
|
||
| function getBytes32(string memory key) internal view returns (bytes32) { | ||
| return stdJson.readBytes32(_deployConfigJson, key); | ||
| } | ||
|
|
||
| function getBytes(string memory key) internal view returns (bytes memory) { | ||
| return stdJson.readBytes(_deployConfigJson, key); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| interface ISemver { | ||
| /// @notice Returns the current semantic version of the contract | ||
| /// @return The semantic version string of the contract (e.g. `1.2.3`) | ||
| function version() external view returns (string memory); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensure that this function should be simulated, not broadcast.