-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add upgradable smart contracts verification example (#837)
* chore: add upgradable contracts to verify example
- Loading branch information
1 parent
5964e3f
commit 3f37d90
Showing
19 changed files
with
665 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
|
||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
contract Box is Initializable { | ||
uint256 private value; | ||
uint256 private secondValue; | ||
uint256 private thirdValue; | ||
|
||
function initialize(uint256 initValue) public initializer { | ||
value = initValue; | ||
} | ||
|
||
// Reads the last stored value | ||
function retrieve() public view returns (uint256) { | ||
return value; | ||
} | ||
|
||
// Stores a new value in the contract | ||
function store(uint256 newValue) public { | ||
value = newValue; | ||
emit ValueChanged(newValue); | ||
} | ||
// Emitted when the stored value changes | ||
event ValueChanged(uint256 newValue); | ||
} |
This file contains 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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
|
||
contract BoxUups is Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
uint256 private value; | ||
uint256 private secondValue; | ||
uint256 private thirdValue; | ||
|
||
function initialize(uint256 initValue) public initializer { | ||
value = initValue; | ||
__Ownable_init(); | ||
__UUPSUpgradeable_init(); | ||
} | ||
|
||
// Reads the last stored value | ||
function retrieve() public view returns (uint256) { | ||
return value; | ||
} | ||
|
||
// Stores a new value in the contract | ||
function store(uint256 newValue) public { | ||
value = newValue; | ||
emit ValueChanged(newValue); | ||
} | ||
|
||
function _authorizeUpgrade(address) internal override onlyOwner {} | ||
|
||
// Emitted when the stored value changes | ||
event ValueChanged(uint256 newValue); | ||
} |
This file contains 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,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
|
||
contract BoxUupsV2 is Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
uint256 private value; | ||
uint256 private secondValue; | ||
uint256 private thirdValue; | ||
|
||
function initialize(uint256 initValue) public initializer { | ||
value = initValue; | ||
} | ||
|
||
// Reads the last stored value and returns it with a prefix | ||
function retrieve() public view returns (string memory) { | ||
return string(abi.encodePacked('V2: ', uint2str(value))); | ||
} | ||
|
||
// Converts a uint to a string | ||
function uint2str(uint _i) internal pure returns (string memory) { | ||
if (_i == 0) { | ||
return '0'; | ||
} | ||
uint j = _i; | ||
uint len; | ||
while (j != 0) { | ||
len++; | ||
j /= 10; | ||
} | ||
bytes memory bstr = new bytes(len); | ||
uint k = len; | ||
while (_i != 0) { | ||
k = k - 1; | ||
uint8 temp = (48 + uint8(_i - (_i / 10) * 10)); | ||
bytes1 b1 = bytes1(temp); | ||
bstr[k] = b1; | ||
_i /= 10; | ||
} | ||
return string(bstr); | ||
} | ||
|
||
// Stores a new value in the contract | ||
function store(uint256 newValue) public { | ||
value = newValue; | ||
emit ValueChanged(newValue); | ||
} | ||
|
||
function _authorizeUpgrade(address) internal override onlyOwner {} | ||
|
||
// Emitted when the stored value changes | ||
event ValueChanged(uint256 newValue); | ||
} |
This file contains 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,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
|
||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
contract BoxV2 is Initializable{ | ||
uint256 private value; | ||
uint256 private secondValue; | ||
uint256 private thirdValue; | ||
|
||
// Emitted when the stored value changes | ||
event ValueChanged(uint256 newValue); | ||
|
||
function initialize(uint256 initValue) public initializer { | ||
value = initValue; | ||
} | ||
|
||
// Stores a new value in the contract | ||
function store(uint256 newValue) public { | ||
value = newValue; | ||
emit ValueChanged(newValue); | ||
} | ||
|
||
// Reads the last stored value and returns it with a prefix | ||
function retrieve() public view returns (string memory) { | ||
return string(abi.encodePacked("V2: ", uint2str(value))); | ||
} | ||
|
||
// Converts a uint to a string | ||
function uint2str(uint _i) internal pure returns (string memory) { | ||
if (_i == 0) { | ||
return "0"; | ||
} | ||
uint j = _i; | ||
uint len; | ||
while (j != 0) { | ||
len++; | ||
j /= 10; | ||
} | ||
bytes memory bstr = new bytes(len); | ||
uint k = len; | ||
while (_i != 0) { | ||
k = k - 1; | ||
uint8 temp = (48 + uint8(_i - (_i / 10) * 10)); | ||
bytes1 b1 = bytes1(temp); | ||
bstr[k] = b1; | ||
_i /= 10; | ||
} | ||
return string(bstr); | ||
} | ||
} |
This file contains 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,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract EmptyContract { | ||
} |
This file contains 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,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./Empty.sol"; | ||
|
||
contract Factory { | ||
address[] public deployedContracts; | ||
|
||
function initialize() public{ | ||
deployEmptyContract(); | ||
} | ||
|
||
function deployEmptyContract() public { | ||
EmptyContract newContract = new EmptyContract(); | ||
deployedContracts.push(address(newContract)); | ||
} | ||
|
||
function getNumberOfDeployedContracts() public view returns (uint) { | ||
return deployedContracts.length; | ||
} | ||
} |
This file contains 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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import "./Empty.sol"; | ||
|
||
|
||
contract FactoryUups is Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
address[] public deployedContracts; | ||
|
||
function initialize() public initializer{ | ||
__Ownable_init(); | ||
__UUPSUpgradeable_init(); | ||
deployEmptyContract(); | ||
} | ||
|
||
function deployEmptyContract() public { | ||
EmptyContract newContract = new EmptyContract(); | ||
deployedContracts.push(address(newContract)); | ||
} | ||
|
||
function getNumberOfDeployedContracts() public view returns (uint) { | ||
return deployedContracts.length; | ||
} | ||
|
||
function storeNothing() public pure { | ||
|
||
} | ||
|
||
function _authorizeUpgrade(address) internal override onlyOwner {} | ||
} |
This file contains 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,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import "./Empty.sol"; | ||
|
||
|
||
contract FactoryUupsV2 is Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
address[] public deployedContracts; | ||
|
||
function initialize() public initializer{ | ||
deployEmptyContract(); | ||
} | ||
|
||
function deployEmptyContract() public { | ||
EmptyContract newContract = new EmptyContract(); | ||
deployedContracts.push(address(newContract)); | ||
} | ||
|
||
function getNumberOfDeployedContracts() public view returns (uint) { | ||
return deployedContracts.length; | ||
} | ||
|
||
function storeNothing() public pure { | ||
|
||
} | ||
|
||
function _authorizeUpgrade(address) internal override onlyOwner {} | ||
|
||
function uint2str(uint _i) internal pure returns (string memory) { | ||
if (_i == 0) { | ||
return '0'; | ||
} | ||
uint j = _i; | ||
uint len; | ||
while (j != 0) { | ||
len++; | ||
j /= 10; | ||
} | ||
bytes memory bstr = new bytes(len); | ||
uint k = len; | ||
while (_i != 0) { | ||
k = k - 1; | ||
uint8 temp = (48 + uint8(_i - (_i / 10) * 10)); | ||
bytes1 b1 = bytes1(temp); | ||
bstr[k] = b1; | ||
_i /= 10; | ||
} | ||
return string(bstr); | ||
} | ||
} |
Oops, something went wrong.