-
Notifications
You must be signed in to change notification settings - Fork 1
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 #88 from smart-transaction/refactor/faucet-deployment
Faucet redeployment and upgradeability
- Loading branch information
Showing
4 changed files
with
60 additions
and
29 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 |
---|---|---|
@@ -1,24 +1,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity 0.8.26; | ||
|
||
import "forge-std/Script.sol"; | ||
import "src/utilities/Faucet.sol"; | ||
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; | ||
import {BaseDeployer} from "./BaseDeployer.s.sol"; | ||
|
||
/* solhint-disable no-console*/ | ||
import {console2} from "forge-std/console2.sol"; | ||
|
||
contract DeployFaucet is Script, BaseDeployer { | ||
/// @dev Compute the CREATE2 address for Faucet contract. | ||
/// @param salt The salt for the Faucet contract. | ||
modifier computeCreate2(bytes32 salt) { | ||
_create2addr = computeCreate2Address(salt, hashInitCode(type(Faucet).creationCode)); | ||
|
||
_; | ||
} | ||
|
||
contract DeployFaucet is Script { | ||
function run() external returns (address, address) { | ||
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
/// @dev Helper to iterate over chains and select fork. | ||
/// @param deployForks The chains to deploy to. | ||
/// @return address of the deployed contract | ||
function createDeployMultichain(Chains[] memory deployForks) | ||
internal | ||
override | ||
computeCreate2(_salt) | ||
returns (address) | ||
{ | ||
console2.log("Faucet create2 address:", _create2addr, "\n"); | ||
|
||
// Deploy the upgradeable contract | ||
address _proxyAddress = | ||
Upgrades.deployTransparentProxy("Faucet.sol", msg.sender, abi.encodeCall(Faucet.initialize, ())); | ||
for (uint256 i; i < deployForks.length;) { | ||
console2.log("Deploying Faucet to chain: ", uint256(deployForks[i]), "\n"); | ||
|
||
createSelectFork(deployForks[i]); | ||
|
||
_chainDeployCallBreaker(); | ||
|
||
unchecked { | ||
++i; | ||
} | ||
} | ||
return _create2addr; | ||
} | ||
|
||
// Get the implementation address | ||
address implementationAddress = Upgrades.getImplementationAddress(_proxyAddress); | ||
/// @dev Function to perform actual deployment. | ||
function _chainDeployCallBreaker() private broadcast(_deployerPrivateKey) { | ||
Faucet faucet = new Faucet{salt: _salt}(); | ||
|
||
vm.stopBroadcast(); | ||
require(_create2addr == address(faucet), "Address mismatch Faucet"); | ||
|
||
return (implementationAddress, _proxyAddress); | ||
console2.log("Faucet deployed at address:", address(faucet), "\n"); | ||
} | ||
} |
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