Skip to content

Commit

Permalink
feat(evm): skip registration if already deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
Quazia committed Sep 24, 2024
1 parent 4b402b9 commit 3973106
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 40 deletions.
98 changes: 59 additions & 39 deletions packages/evm/script/solidity/Deploy_Modules.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,98 +72,118 @@ contract ModuleBaseDeployer is ScriptUtils {
managedBudget = _getCreate2Address(initCode, "");
console.log("ManagedBudget: ", managedBudget);
deployJson = deployJsonKey.serialize("ManagedBudget", managedBudget);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.BUDGET, "ManagedBudget", managedBudget);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.BUDGET, "ManagedBudget", managedBudget);
}
}

function _deployEventAction(BoostRegistry registry) internal returns (address eventAction) {
bytes memory initCode = type(EventAction).creationCode;
eventAction = _getCreate2Address(initCode, "");
console.log("EventAction: ", eventAction);
deployJson = deployJsonKey.serialize("EventAction", eventAction);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ACTION, "EventAction", eventAction);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ACTION, "EventAction", eventAction);
}
}

function _deployERC20Incentive(BoostRegistry registry) internal returns (address erc20Incentive) {
bytes memory initCode = type(ERC20Incentive).creationCode;
erc20Incentive = _getCreate2Address(initCode, "");
console.log("ERC20Incentive: ", erc20Incentive);
deployJson = deployJsonKey.serialize("ERC20Incentive", erc20Incentive);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "ERC20Incentive", erc20Incentive);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "ERC20Incentive", erc20Incentive);
}
}

function _deployERC20VariableIncentive(BoostRegistry registry) internal returns (address erc20VariableIncentive) {
bytes memory initCode = type(ERC20VariableIncentive).creationCode;
erc20VariableIncentive = _getCreate2Address(initCode, "");
console.log("ERC20VariableIncentive: ", erc20VariableIncentive);
deployJson = deployJsonKey.serialize("ERC20VariableIncentive", erc20VariableIncentive);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "ERC20VariableIncentive", erc20VariableIncentive);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "ERC20VariableIncentive", erc20VariableIncentive);
}
}

function _deployCGDAIncentive(BoostRegistry registry) internal returns (address cgdaIncentive) {
bytes memory initCode = type(CGDAIncentive).creationCode;
cgdaIncentive = _getCreate2Address(initCode, "");
console.log("CGDAIncentive: ", cgdaIncentive);
deployJson = deployJsonKey.serialize("CGDAIncentive", cgdaIncentive);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "CGDAIncentive", cgdaIncentive);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "CGDAIncentive", cgdaIncentive);
}
}

function _deployPointsIncentive(BoostRegistry registry) internal returns (address pointsIncentive) {
bytes memory initCode = type(PointsIncentive).creationCode;
pointsIncentive = _getCreate2Address(initCode, "");
console.log("PointsIncentive: ", pointsIncentive);
deployJson = deployJsonKey.serialize("PointsIncentive", pointsIncentive);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "PointsIncentive", pointsIncentive);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "PointsIncentive", pointsIncentive);
}
}

function _deployAllowListIncentive(BoostRegistry registry) internal returns (address allowListIncentive) {
bytes memory initCode = type(AllowListIncentive).creationCode;
allowListIncentive = _getCreate2Address(initCode, "");
console.log("AllowListIncentive: ", allowListIncentive);
deployJson = deployJsonKey.serialize("AllowListIncentive", allowListIncentive);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "AllowListIncentive", allowListIncentive);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.INCENTIVE, "AllowListIncentive", allowListIncentive);
}
}

function _deploySignerValidator(BoostRegistry registry) internal returns (address signerValidator) {
bytes memory initCode = type(SignerValidator).creationCode;
signerValidator = _getCreate2Address(initCode, "");
console.log("SignerValidator: ", signerValidator);
deployJson = deployJsonKey.serialize("SignerValidator", signerValidator);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.VALIDATOR, "SignerValidator", signerValidator);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.VALIDATOR, "SignerValidator", signerValidator);
}
}

function _deploySimpleAllowList(BoostRegistry registry) internal returns (address simpleAllowList) {
bytes memory initCode = type(SimpleAllowList).creationCode;
simpleAllowList = _getCreate2Address(initCode, "");
console.log("SimpleAllowList: ", simpleAllowList);
deployJson = deployJsonKey.serialize("SimpleAllowList", simpleAllowList);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ALLOW_LIST, "SimpleAllowList", simpleAllowList);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ALLOW_LIST, "SimpleAllowList", simpleAllowList);
}
}

function _deploySimpleDenyList(BoostRegistry registry) internal returns (address simpleDenyList) {
bytes memory initCode = type(SimpleDenyList).creationCode;
simpleDenyList = _getCreate2Address(initCode, "");
console.log("SimpleDenyList: ", simpleDenyList);
deployJson = deployJsonKey.serialize("SimpleDenyList", simpleDenyList);
_deploy2(initCode, "");
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ALLOW_LIST, "SimpleDenyList", simpleDenyList);
bool newDeploy = _deploy2(initCode, "");
if (newDeploy) {
vm.broadcast();
registry.register(BoostRegistry.RegistryType.ALLOW_LIST, "SimpleDenyList", simpleDenyList);
}
}
}
4 changes: 3 additions & 1 deletion packages/evm/script/solidity/Util.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract ScriptUtils is Script {
return vm.computeCreate2Address(salt, codeHash);
}

function _deploy2(bytes memory deployCode, bytes memory args) internal {
function _deploy2(bytes memory deployCode, bytes memory args) internal returns (bool) {
bytes32 salt = keccak256(bytes(vm.envString("BOOST_DEPLOYMENT_SALT")));
bytes32 bytecodeHash = keccak256(abi.encodePacked(deployCode, args));
address computedAddress = address(uint160(uint256(keccak256(abi.encodePacked(
Expand All @@ -34,8 +34,10 @@ contract ScriptUtils is Script {
vm.broadcast();
(bool success,) = CREATE2_FACTORY.call(payload);
if (!success) revert("create2 failed");
return true;
} else {
console.log("Address already deployed at: ", computedAddress);
return false;
}
}

Expand Down

0 comments on commit 3973106

Please sign in to comment.