Skip to content

Commit

Permalink
Merge pull request #383 from 0xPolygon/feat/child-deploy
Browse files Browse the repository at this point in the history
feat(child): add `GenesisProxy` and dummy deploy scripts
  • Loading branch information
ZeroEkkusu authored Sep 19, 2023
2 parents de71996 + dad40b7 commit 8de1af2
Show file tree
Hide file tree
Showing 31 changed files with 1,608 additions and 2 deletions.
56 changes: 56 additions & 0 deletions contracts/lib/GenesisProxy.sol
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)
}
}
}
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ffi = true
fs_permissions = [
{ access = "read", path = "script/deployment/sharedRootContractsConfig.json" },
{ access = "read", path = "script/deployment/rootContractSetConfig.json" },
{ access = "read", path = "script/deployment/rootTokenContractsConfig.json" }
{ access = "read", path = "script/deployment/rootTokenContractsConfig.json" },
{ access = "read", path = "out/GenesisProxy.sol/GenesisProxy.json" }
]

# do not use for computationally expensive tests
Expand Down
43 changes: 43 additions & 0 deletions script/deployment/test/child/DeployChildERC1155.s.sol
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 script/deployment/test/child/DeployChildERC1155Predicate.s.sol
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
);
}
}
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
);
}
}
43 changes: 43 additions & 0 deletions script/deployment/test/child/DeployChildERC20.s.sol
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 script/deployment/test/child/DeployChildERC20Predicate.s.sol
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
);
}
}
Loading

0 comments on commit 8de1af2

Please sign in to comment.