-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from 0xPolygon/feat/child-deploy
feat(child): add `GenesisProxy` and dummy deploy scripts
- Loading branch information
Showing
31 changed files
with
1,608 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
/** | ||
@title GenesisProxy | ||
@author Polygon Technology | ||
@notice wrapper for OpenZeppelin's Transparent Upgreadable Proxy, intended for use during genesis for genesis contracts | ||
@notice one GenesisProxy should be deployed for each genesis contract | ||
*/ | ||
contract GenesisProxy is TransparentUpgradeableProxy { | ||
// keccak256("GenesisProxy INITIATOR_SLOT") | ||
bytes32 private constant INITIATOR_SLOT = hex"16561015e0650c143c10fb1907c52a56b654e2f0922ca3245bde5beff81a333d"; | ||
|
||
constructor() TransparentUpgradeableProxy(address(0), address(0), "") { | ||
revert(); | ||
} | ||
|
||
function protectSetUpProxy(address initiator) external { | ||
bytes32 protected; | ||
|
||
// slither-disable-next-line assembly | ||
assembly { | ||
protected := sload(INITIATOR_SLOT) | ||
sstore(INITIATOR_SLOT, initiator) | ||
} | ||
|
||
require(protected == "", "Already protected"); | ||
} | ||
|
||
function setUpProxy(address logic, address admin, bytes memory data) external { | ||
address initiator; | ||
|
||
// slither-disable-next-line assembly | ||
assembly { | ||
initiator := sload(INITIATOR_SLOT) | ||
} | ||
|
||
require(initiator != address(1), "Already set-up"); | ||
|
||
require(msg.sender == initiator, "Unauthorized"); | ||
|
||
// TransparentUpgradeableProxy constructor | ||
_changeAdmin(admin); | ||
|
||
// ERC1967Proxy constructor | ||
_upgradeToAndCall(logic, data, false); | ||
|
||
// slither-disable-next-line assembly | ||
assembly { | ||
sstore(INITIATOR_SLOT, 1) | ||
} | ||
} | ||
} |
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
Submodule forge-std
updated
28 files
+48 −6 | .github/workflows/ci.yml | |
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | lib/ds-test | |
+2 −2 | package.json | |
+5 −3 | src/Base.sol | |
+4 −3 | src/Script.sol | |
+91 −40 | src/StdAssertions.sol | |
+37 −24 | src/StdChains.sol | |
+286 −34 | src/StdCheats.sol | |
+20 −5 | src/StdInvariant.sol | |
+18 −14 | src/StdJson.sol | |
+54 −3 | src/StdStorage.sol | |
+333 −0 | src/StdStyle.sol | |
+83 −8 | src/StdUtils.sol | |
+7 −2 | src/Test.sol | |
+198 −25 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+73 −0 | src/interfaces/IMulticall3.sol | |
+13,248 −0 | src/safeconsole.sol | |
+258 −66 | test/StdAssertions.t.sol | |
+121 −48 | test/StdChains.t.sol | |
+334 −29 | test/StdCheats.t.sol | |
+10 −10 | test/StdError.t.sol | |
+27 −12 | test/StdMath.t.sol | |
+66 −34 | test/StdStorage.t.sol | |
+110 −0 | test/StdStyle.t.sol | |
+185 −34 | test/StdUtils.t.sol |
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
import {ChildERC1155} from "contracts/child/ChildERC1155.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
abstract contract ChildERC1155Deployer is Script { | ||
function deployChildERC1155( | ||
address proxyAdmin, | ||
address rootToken_, | ||
string calldata uri_ | ||
) internal returns (address logicAddr, address proxyAddr) { | ||
bytes memory initData = abi.encodeCall(ChildERC1155.initialize, (rootToken_, uri_)); | ||
|
||
vm.startBroadcast(); | ||
|
||
ChildERC1155 childERC1155 = new ChildERC1155(); | ||
|
||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( | ||
address(childERC1155), | ||
proxyAdmin, | ||
initData | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
logicAddr = address(childERC1155); | ||
proxyAddr = address(proxy); | ||
} | ||
} | ||
|
||
contract DeployChildERC1155 is ChildERC1155Deployer { | ||
function run( | ||
address proxyAdmin, | ||
address rootToken_, | ||
string calldata uri_ | ||
) external returns (address logicAddr, address proxyAddr) { | ||
return deployChildERC1155(proxyAdmin, rootToken_, uri_); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
script/deployment/test/child/DeployChildERC1155Predicate.s.sol
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,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
import {ChildERC1155Predicate} from "contracts/child/ChildERC1155Predicate.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
abstract contract ChildERC1155PredicateDeployer is Script { | ||
function deployChildERC1155Predicate( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC1155Predicate, | ||
address newChildTokenTemplate | ||
) internal returns (address logicAddr, address proxyAddr) { | ||
bytes memory initData = abi.encodeCall( | ||
ChildERC1155Predicate.initialize, | ||
(newL2StateSender, newStateReceiver, newRootERC1155Predicate, newChildTokenTemplate) | ||
); | ||
|
||
vm.startBroadcast(); | ||
|
||
ChildERC1155Predicate childERC1155Predicate = new ChildERC1155Predicate(); | ||
|
||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( | ||
address(childERC1155Predicate), | ||
proxyAdmin, | ||
initData | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
logicAddr = address(childERC1155Predicate); | ||
proxyAddr = address(proxy); | ||
} | ||
} | ||
|
||
contract DeployChildERC1155Predicate is ChildERC1155PredicateDeployer { | ||
function run( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC1155Predicate, | ||
address newChildTokenTemplate | ||
) external returns (address logicAddr, address proxyAddr) { | ||
return | ||
deployChildERC1155Predicate( | ||
proxyAdmin, | ||
newL2StateSender, | ||
newStateReceiver, | ||
newRootERC1155Predicate, | ||
newChildTokenTemplate | ||
); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
script/deployment/test/child/DeployChildERC1155PredicateAccessList.s.sol
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,74 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
import {ChildERC1155PredicateAccessList} from "contracts/child/ChildERC1155PredicateAccessList.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
abstract contract ChildERC1155PredicateAccessListDeployer is Script { | ||
function deployChildERC1155PredicateAccessList( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC1155Predicate, | ||
address newChildTokenTemplate, | ||
bool newUseAllowList, | ||
bool newUseBlockList, | ||
address newOwner | ||
) internal returns (address logicAddr, address proxyAddr) { | ||
bytes memory initData = abi.encodeCall( | ||
ChildERC1155PredicateAccessList.initialize, | ||
( | ||
newL2StateSender, | ||
newStateReceiver, | ||
newRootERC1155Predicate, | ||
newChildTokenTemplate, | ||
newUseAllowList, | ||
newUseBlockList, | ||
newOwner | ||
) | ||
); | ||
|
||
vm.startBroadcast(); | ||
|
||
ChildERC1155PredicateAccessList childERC1155PredicateAccessList = new ChildERC1155PredicateAccessList(); | ||
|
||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( | ||
address(childERC1155PredicateAccessList), | ||
proxyAdmin, | ||
initData | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
logicAddr = address(childERC1155PredicateAccessList); | ||
proxyAddr = address(proxy); | ||
} | ||
} | ||
|
||
contract DeployChildERC1155PredicateAccessList is ChildERC1155PredicateAccessListDeployer { | ||
function run( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC1155Predicate, | ||
address newChildTokenTemplate, | ||
bool newUseAllowList, | ||
bool newUseBlockList, | ||
address newOwner | ||
) external returns (address logicAddr, address proxyAddr) { | ||
return | ||
deployChildERC1155PredicateAccessList( | ||
proxyAdmin, | ||
newL2StateSender, | ||
newStateReceiver, | ||
newRootERC1155Predicate, | ||
newChildTokenTemplate, | ||
newUseAllowList, | ||
newUseBlockList, | ||
newOwner | ||
); | ||
} | ||
} |
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
import {ChildERC20} from "contracts/child/ChildERC20.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
abstract contract ChildERC20Deployer is Script { | ||
function deployChildERC20( | ||
address proxyAdmin, | ||
address rootToken_, | ||
string calldata name_, | ||
string calldata symbol_, | ||
uint8 decimals_ | ||
) internal returns (address logicAddr, address proxyAddr) { | ||
bytes memory initData = abi.encodeCall(ChildERC20.initialize, (rootToken_, name_, symbol_, decimals_)); | ||
|
||
vm.startBroadcast(); | ||
|
||
ChildERC20 childERC20 = new ChildERC20(); | ||
|
||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(childERC20), proxyAdmin, initData); | ||
|
||
vm.stopBroadcast(); | ||
|
||
logicAddr = address(childERC20); | ||
proxyAddr = address(proxy); | ||
} | ||
} | ||
|
||
contract DeployChildERC20 is ChildERC20Deployer { | ||
function run( | ||
address proxyAdmin, | ||
address rootToken_, | ||
string calldata name_, | ||
string calldata symbol_, | ||
uint8 decimals_ | ||
) external returns (address logicAddr, address proxyAddr) { | ||
return deployChildERC20(proxyAdmin, rootToken_, name_, symbol_, decimals_); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
script/deployment/test/child/DeployChildERC20Predicate.s.sol
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,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.19; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
import {ChildERC20Predicate} from "contracts/child/ChildERC20Predicate.sol"; | ||
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
abstract contract ChildERC20PredicateDeployer is Script { | ||
function deployChildERC20Predicate( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC20Predicate, | ||
address newChildTokenTemplate, | ||
address newNativeTokenRootAddress | ||
) internal returns (address logicAddr, address proxyAddr) { | ||
bytes memory initData = abi.encodeCall( | ||
ChildERC20Predicate.initialize, | ||
( | ||
newL2StateSender, | ||
newStateReceiver, | ||
newRootERC20Predicate, | ||
newChildTokenTemplate, | ||
newNativeTokenRootAddress | ||
) | ||
); | ||
|
||
vm.startBroadcast(); | ||
|
||
ChildERC20Predicate childERC20Predicate = new ChildERC20Predicate(); | ||
|
||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( | ||
address(childERC20Predicate), | ||
proxyAdmin, | ||
initData | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
logicAddr = address(childERC20Predicate); | ||
proxyAddr = address(proxy); | ||
} | ||
} | ||
|
||
contract DeployChildERC20Predicate is ChildERC20PredicateDeployer { | ||
function run( | ||
address proxyAdmin, | ||
address newL2StateSender, | ||
address newStateReceiver, | ||
address newRootERC20Predicate, | ||
address newChildTokenTemplate, | ||
address newNativeTokenRootAddress | ||
) external returns (address logicAddr, address proxyAddr) { | ||
return | ||
deployChildERC20Predicate( | ||
proxyAdmin, | ||
newL2StateSender, | ||
newStateReceiver, | ||
newRootERC20Predicate, | ||
newChildTokenTemplate, | ||
newNativeTokenRootAddress | ||
); | ||
} | ||
} |
Oops, something went wrong.