From 54726adbb7e95543d56e53c9849c3cffd8a2794b Mon Sep 17 00:00:00 2001 From: vicnaum Date: Wed, 25 Oct 2023 19:59:23 +0200 Subject: [PATCH] misc: deployment scripts fixed and improved --- script/E_GovernanceActions.s.sol | 99 +++++++++++++++++++++++++++---- script/F_InteractWithLensV2.s.sol | 43 ++++++++++++++ script/addBalance.sh | 6 ++ script/fullV2Run.sh | 14 ++++- script/run.sh | 27 +++++++-- 5 files changed, 170 insertions(+), 19 deletions(-) create mode 100644 script/addBalance.sh diff --git a/script/E_GovernanceActions.s.sol b/script/E_GovernanceActions.s.sol index 12fb363..93e9cbf 100644 --- a/script/E_GovernanceActions.s.sol +++ b/script/E_GovernanceActions.s.sol @@ -32,10 +32,17 @@ import {BaseFeeCollectModuleInitData} from 'contracts/modules/interfaces/IBaseFe import {Governance} from 'contracts/misc/access/Governance.sol'; import {PublicActProxy} from 'contracts/misc/PublicActProxy.sol'; import {LitAccessControl} from 'contracts/misc/access/LitAccessControl.sol'; +import {LibString} from 'solady/utils/LibString.sol'; import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol'; contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { + // TODO: Use from test/ContractAddresses + struct Module { + address addy; + string name; + } + // add this to be excluded from coverage report function testLensV2DeployPeriphery() public {} @@ -75,21 +82,32 @@ contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { ITokenHandleRegistry tokenHandleRegistry; ProfileCreationProxy profileCreationProxy; CollectNFT collectNFT; - CollectPublicationAction collectPublicationActionImpl; - TransparentUpgradeableProxy collectPublicationActionProxy; - CollectPublicationAction collectPublicationAction; - SimpleFeeCollectModule simpleFeeCollectModule; - MultirecipientFeeCollectModule multirecipientFeeCollectModule; - FeeFollowModule feeFollowModule; - RevertFollowModule revertFollowModule; - DegreesOfSeparationReferenceModule degreesOfSeparationReferenceModule; - FollowerOnlyReferenceModule followerOnlyReferenceModule; - TokenGatedReferenceModule tokenGatedReferenceModule; + address collectPublicationAction; + address simpleFeeCollectModule; + address multirecipientFeeCollectModule; + address feeFollowModule; + address revertFollowModule; + address degreesOfSeparationReferenceModule; + address followerOnlyReferenceModule; + address tokenGatedReferenceModule; PublicActProxy publicActProxy; address litAccessControl; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TODO: Move this to helpers somewhere + function findModuleHelper( + Module[] memory modules, + string memory moduleNameToFind + ) internal pure returns (Module memory) { + for (uint256 i = 0; i < modules.length; i++) { + if (LibString.eq(modules[i].name, moduleNameToFind)) { + return modules[i]; + } + } + revert('Module not found'); + } + function saveContractAddress(string memory contractName, address deployedAddress) internal { // console.log('Saving %s (%s) into addresses under %s environment', contractName, deployedAddress, targetEnv); string[] memory inputs = new string[](5); @@ -157,6 +175,55 @@ contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { } function loadBaseAddresses() internal override { + Module[] memory followModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.follow'))), + (Module[]) + ); + + feeFollowModule = findModuleHelper(followModules, 'FeeFollowModule').addy; + vm.label(feeFollowModule, 'FeeFollowModule'); + console.log('FeeFollowModule: %s', feeFollowModule); + + revertFollowModule = findModuleHelper(followModules, 'RevertFollowModule').addy; + vm.label(revertFollowModule, 'RevertFollowModule'); + console.log('RevertFollowModule: %s', revertFollowModule); + + Module[] memory referenceModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.reference'))), + (Module[]) + ); + + degreesOfSeparationReferenceModule = findModuleHelper(referenceModules, 'DegreesOfSeparationReferenceModule') + .addy; + vm.label(degreesOfSeparationReferenceModule, 'DegreesOfSeparationReferenceModule'); + console.log('DegreesOfSeparationReferenceModule: %s', degreesOfSeparationReferenceModule); + + followerOnlyReferenceModule = findModuleHelper(referenceModules, 'FollowerOnlyReferenceModule').addy; + vm.label(followerOnlyReferenceModule, 'FollowerOnlyReferenceModule'); + console.log('FollowerOnlyReferenceModule: %s', followerOnlyReferenceModule); + + Module[] memory actModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.act'))), + (Module[]) + ); + + collectPublicationAction = findModuleHelper(actModules, 'CollectPublicationAction').addy; + vm.label(collectPublicationAction, 'CollectPublicationAction'); + console.log('CollectPublicationAction: %s', collectPublicationAction); + + Module[] memory collectModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.collect'))), + (Module[]) + ); + + simpleFeeCollectModule = findModuleHelper(collectModules, 'SimpleFeeCollectModule').addy; + vm.label(simpleFeeCollectModule, 'SimpleFeeCollectModule'); + console.log('SimpleFeeCollectModule: %s', simpleFeeCollectModule); + + multirecipientFeeCollectModule = findModuleHelper(collectModules, 'MultirecipientFeeCollectModule').addy; + vm.label(multirecipientFeeCollectModule, 'MultirecipientFeeCollectModule'); + console.log('MultirecipientFeeCollectModule: %s', multirecipientFeeCollectModule); + address governanceContractAdmin = json.readAddress( string(abi.encodePacked('.', targetEnv, '.GovernanceContractAdmin')) ); @@ -200,6 +267,12 @@ contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { ); vm.label(address(governanceContract), 'GovernanceContract'); console.log('Governance Contract: %s', address(governanceContract)); + + profileCreationProxy = ProfileCreationProxy( + json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProfileCreationProxy'))) + ); + vm.label(address(profileCreationProxy), 'ProfileCreationProxy'); + console.log('Profile Creation Proxy: %s', address(profileCreationProxy)); } function _governanceActions() internal { @@ -208,7 +281,7 @@ contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { governanceContract.lensHub_whitelistProfileCreator(address(profileCreationProxy), true); console.log('\n* * * Profile creator proxy %s registered as profile creator', address(profileCreationProxy)); - hub.setState(Types.ProtocolState.Unpaused); + governanceContract.lensHub_setState(Types.ProtocolState.Unpaused); console.log('\n* * * Protocol unpaused'); vm.stopBroadcast(); @@ -278,10 +351,10 @@ contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers { ); console.log('\n* * * CollectPublicationAction registered as action module'); - collectPublicationAction.registerCollectModule(address(simpleFeeCollectModule)); + CollectPublicationAction(collectPublicationAction).registerCollectModule(address(simpleFeeCollectModule)); console.log('\n* * * SimpleFeeCollectModule registered as collect module'); - collectPublicationAction.registerCollectModule(address(multirecipientFeeCollectModule)); + CollectPublicationAction(collectPublicationAction).registerCollectModule(address(multirecipientFeeCollectModule)); console.log('\n* * * MultirecipientFeeCollectModule registered as collect module'); vm.stopBroadcast(); diff --git a/script/F_InteractWithLensV2.s.sol b/script/F_InteractWithLensV2.s.sol index ca5f70f..f55a9d1 100644 --- a/script/F_InteractWithLensV2.s.sol +++ b/script/F_InteractWithLensV2.s.sol @@ -32,10 +32,17 @@ import {BaseFeeCollectModuleInitData} from 'contracts/modules/interfaces/IBaseFe import {Governance} from 'contracts/misc/access/Governance.sol'; import {PublicActProxy} from 'contracts/misc/PublicActProxy.sol'; import {LitAccessControl} from 'contracts/misc/access/LitAccessControl.sol'; +import {LibString} from 'solady/utils/LibString.sol'; import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol'; contract F_InteractWithLensV2 is Script, ForkManagement, ArrayHelpers { + // TODO: Use from test/ContractAddresses + struct Module { + address addy; + string name; + } + // add this to be excluded from coverage report function testLensV2DeployPeriphery() public {} @@ -90,6 +97,19 @@ contract F_InteractWithLensV2 is Script, ForkManagement, ArrayHelpers { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TODO: Move this to helpers somewhere + function findModuleHelper( + Module[] memory modules, + string memory moduleNameToFind + ) internal pure returns (Module memory) { + for (uint256 i = 0; i < modules.length; i++) { + if (LibString.eq(modules[i].name, moduleNameToFind)) { + return modules[i]; + } + } + revert('Module not found'); + } + function saveContractAddress(string memory contractName, address deployedAddress) internal { // console.log('Saving %s (%s) into addresses under %s environment', contractName, deployedAddress, targetEnv); string[] memory inputs = new string[](5); @@ -200,6 +220,29 @@ contract F_InteractWithLensV2 is Script, ForkManagement, ArrayHelpers { ); vm.label(address(governanceContract), 'GovernanceContract'); console.log('Governance Contract: %s', address(governanceContract)); + + + Module[] memory actModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.act'))), + (Module[]) + ); + + collectPublicationAction = CollectPublicationAction(findModuleHelper(actModules, 'CollectPublicationAction').addy); + vm.label(address(collectPublicationAction), 'CollectPublicationAction'); + console.log('CollectPublicationAction: %s', address(collectPublicationAction)); + + Module[] memory collectModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.collect'))), + (Module[]) + ); + + simpleFeeCollectModule = SimpleFeeCollectModule(findModuleHelper(collectModules, 'SimpleFeeCollectModule').addy); + vm.label(address(simpleFeeCollectModule), 'SimpleFeeCollectModule'); + console.log('SimpleFeeCollectModule: %s', address(simpleFeeCollectModule)); + + multirecipientFeeCollectModule = MultirecipientFeeCollectModule(findModuleHelper(collectModules, 'MultirecipientFeeCollectModule').addy); + vm.label(address(multirecipientFeeCollectModule), 'MultirecipientFeeCollectModule'); + console.log('MultirecipientFeeCollectModule: %s', address(multirecipientFeeCollectModule)); } function _interact() internal { diff --git a/script/addBalance.sh b/script/addBalance.sh new file mode 100644 index 0000000..9e89db5 --- /dev/null +++ b/script/addBalance.sh @@ -0,0 +1,6 @@ +# This script adds 10 Ether to the address specified in the first CLI argument + +# Get the first CLI argument and save it to $ADDRESS variable +ADDRESS=$1 + +cast rpc --rpc-url mumbai tenderly_addBalance "[[\"$ADDRESS\"], \"0x8AC7230489E80000\"]" --raw diff --git a/script/fullV2Run.sh b/script/fullV2Run.sh index a9f32e3..9180ea7 100644 --- a/script/fullV2Run.sh +++ b/script/fullV2Run.sh @@ -1,14 +1,24 @@ set -e TARGET=$1 +CATAPULTA=$2 + +# If $CATAPULTA is defined, but it's not 'catapulta' then we exit with error +if [[ "$CATAPULTA" != "" && "$CATAPULTA" != "catapulta" ]] + then + echo "To deploy use catapulta add 'catapulta' to params. Terminating" + exit 1 +fi echo "Running Full Lens V2 Deployment on $TARGET environment" echo "Deploying Lens V2 Implementation and upgrade contracts..." -bash script/run.sh A_DeployLensV2Upgrade $TARGET +bash script/run.sh A_DeployLensV2Upgrade $TARGET $CATAPULTA echo "Deploying Lens V2 Periphery..." -bash script/run.sh B_DeployLensV2Periphery $TARGET +bash script/run.sh B_DeployLensV2Periphery $TARGET $CATAPULTA + +# Run addBalance script if the following fails: echo "Changing Lens V1 Admins..." bash script/run.sh C_ChangeLensV1Admins $TARGET s diff --git a/script/run.sh b/script/run.sh index 1fe5f58..990da6c 100644 --- a/script/run.sh +++ b/script/run.sh @@ -5,6 +5,7 @@ set -e SCRIPT_NAME=$1 TARGET=$2 CONFIRMATION_OVERRIDE=$3 +CATAPULTA=$4 if [[ "$TARGET" == "" ]] then @@ -21,6 +22,13 @@ if [[ "$NETWORK" == "" ]] fi echo "Using network: $NETWORK" +# If $CATAPULTA is defined, but it's not 'catapulta' then we exit with error +if [[ "$CATAPULTA" != "" && "$CATAPULTA" != "catapulta" ]] + then + echo "To use catapulta add 'catapulta' to params. Terminating" + exit 1 +fi + CALLDATA=$(cast calldata "run(string)" $TARGET) echo "Interactions calldata:" @@ -52,13 +60,24 @@ if [[ "$CONFIRMATION" == "y" || "$CONFIRMATION" == "Y" ]] then echo "Broadcasting on-chain..." - # If $NETWORK is "mumbai" change it to "maticMumbai" for catapulta - if [[ "$NETWORK" == "mumbai" ]] + # If $CATAPULTA is defined, use catapulta instead of forge + + if [[ "$CATAPULTA" == "catapulta" ]] then - NETWORK="maticMumbai" + echo "Using catapulta" + + # If $NETWORK is "mumbai" change it to "maticMumbai" for catapulta + if [[ "$NETWORK" == "mumbai" ]] + then + NETWORK="maticMumbai" + fi + + catapulta script script/$SCRIPT_NAME.s.sol --chain $NETWORK -s $CALLDATA --legacy --skip test --ffi --slow --skip-git + exit 0 + else + forge script script/$SCRIPT_NAME.s.sol:$SCRIPT_NAME -s $CALLDATA --rpc-url $NETWORK -vv --legacy --skip test --ffi --slow --broadcast fi - catapulta script script/$SCRIPT_NAME.s.sol --chain $NETWORK -s $CALLDATA --legacy --skip test --ffi --slow --skip-git else echo "Deployment cancelled. Execution terminated." exit 1