From 01b2b7d43ed706d459d1450b9cc548e9dbf91cd9 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 3 May 2024 13:25:23 +0200 Subject: [PATCH] fix: Events added to ProtocolSharedRevenue module, deploy script improved --- .../ProtocolSharedRevenueMinFeeMintModule.sol | 11 ++- script/DeployMintFeeModule.s.sol | 72 +++++++++++++++---- ...rotocolSharedRevenueMinFeeMintModule.t.sol | 12 +++- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/contracts/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.sol b/contracts/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.sol index 2e4b843..90412d7 100644 --- a/contracts/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.sol +++ b/contracts/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.sol @@ -60,6 +60,9 @@ contract ProtocolSharedRevenueMinFeeMintModule is BaseFeeCollectModule, LensModu uint256 mintFeeAmount; ProtocolSharedRevenueDistribution protocolSharedRevenueDistribution; + event MintFeeParamsSet(address token, uint256 amount, uint256 timestamp); + event ProtocolSharedRevenueDistributionSet(ProtocolSharedRevenueDistribution distribution, uint256 timestamp); + mapping(uint256 profileId => mapping(uint256 pubId => address creatorClient)) internal _creatorClientByPublicationByProfile; @@ -111,7 +114,7 @@ contract ProtocolSharedRevenueMinFeeMintModule is BaseFeeCollectModule, LensModu _validateBaseInitData(baseInitData); _storeBasePublicationCollectParameters(profileId, pubId, baseInitData); - return ''; + return data; } function processCollect( @@ -175,7 +178,7 @@ contract ProtocolSharedRevenueMinFeeMintModule is BaseFeeCollectModule, LensModu executorClientAmount ); } else { - // If there's no creatorClient specified - we give that amount to the publication creator + // If there's no executorClient specified - we give that amount to the publication creator creatorAmount += executorClientAmount; } @@ -198,6 +201,8 @@ contract ProtocolSharedRevenueMinFeeMintModule is BaseFeeCollectModule, LensModu } mintFeeToken = token; mintFeeAmount = amount; + + emit MintFeeParamsSet(token, amount, block.timestamp); } function setProtocolSharedRevenueDistribution( @@ -213,6 +218,8 @@ contract ProtocolSharedRevenueMinFeeMintModule is BaseFeeCollectModule, LensModu revert Errors.InvalidParams(); } protocolSharedRevenueDistribution = distribution; + + emit ProtocolSharedRevenueDistributionSet(distribution, block.timestamp); } // Getters diff --git a/script/DeployMintFeeModule.s.sol b/script/DeployMintFeeModule.s.sol index 920dbe8..3aee1fb 100644 --- a/script/DeployMintFeeModule.s.sol +++ b/script/DeployMintFeeModule.s.sol @@ -20,6 +20,7 @@ contract DeployMintFeeModule is Script, ForkManagement { LensAccount _deployer; LensAccount governance; + LensAccount proxyAdmin; string mnemonic; @@ -31,6 +32,8 @@ contract DeployMintFeeModule is Script, ForkManagement { address bonsai; ProtocolSharedRevenueMinFeeMintModule mintFeeModule; + address mintFeeModuleImpl; + address payable mintFeeModuleProxyAddr; function loadPrivateKeys() internal { if (isEnvSet('MNEMONIC')) { @@ -49,6 +52,9 @@ contract DeployMintFeeModule is Script, ForkManagement { (governance.owner, governance.ownerPk) = deriveRememberKey(mnemonic, 1); console.log('\n- - - GOVERNANCE: %s', governance.owner); + (proxyAdmin.owner, proxyAdmin.ownerPk) = deriveRememberKey(mnemonic, 2); + console.log('\n- - - PROXY ADMIN: %s', proxyAdmin.owner); + console.log('\n'); console.log('Current block:', block.number); @@ -78,6 +84,18 @@ contract DeployMintFeeModule is Script, ForkManagement { revert('Module not found'); } + function findModuleHelper_noFail( + 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]; + } + } + return Module(address(0), ''); + } + function saveModule( string memory moduleName, address moduleAddress, @@ -118,6 +136,14 @@ contract DeployMintFeeModule is Script, ForkManagement { 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[]) + ); + mintFeeModuleProxyAddr = payable( + findModuleHelper_noFail(collectModules, 'ProtocolSharedRevenueMinFeeMintModule').addy + ); + moduleRegistry = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ModuleRegistry'))); vm.label(moduleRegistry, 'ModuleRegistry'); console.log('ModuleRegistry: %s', moduleRegistry); @@ -160,7 +186,7 @@ contract DeployMintFeeModule is Script, ForkManagement { function deploy() internal { vm.startBroadcast(_deployer.ownerPk); { - address mintFeeModuleImpl = address( + mintFeeModuleImpl = address( new ProtocolSharedRevenueMinFeeMintModule({ hub: lensHub, actionModule: collectPublicationAction, @@ -177,20 +203,38 @@ contract DeployMintFeeModule is Script, ForkManagement { console.log('\tAction Module: ', collectPublicationAction); console.log('\tModule Registry: ', moduleRegistry); console.log('\tModule Owner: ', governanceOwner); - - mintFeeModule = ProtocolSharedRevenueMinFeeMintModule( - address( - new TransparentUpgradeableProxy( - mintFeeModuleImpl, - proxyAdminContractAdmin, - abi.encodeCall(mintFeeModule.initialize, (governanceOwner)) - ) - ) - ); - - _logDeployedModule(address(mintFeeModule), 'ProtocolSharedRevenueMinFeeMintModule', 'collect'); } vm.stopBroadcast(); + + if (mintFeeModuleProxyAddr == address(0)) { + console.log('\n* * * MintFeeModule proxy not found - deploying from scratch...'); + vm.startBroadcast(_deployer.ownerPk); + { + mintFeeModule = ProtocolSharedRevenueMinFeeMintModule( + address( + new TransparentUpgradeableProxy( + mintFeeModuleImpl, + proxyAdminContractAdmin, + abi.encodeCall(mintFeeModule.initialize, (governanceOwner)) + ) + ) + ); + } + vm.stopBroadcast(); + + _logDeployedModule(address(mintFeeModule), 'ProtocolSharedRevenueMinFeeMintModule', 'collect'); + } else { + console.log('\n* * * MintFeeModule proxy found - upgrading...'); + console.log('\tProxyAdminContractAdmin: ', proxyAdminContractAdmin); + console.log('\tproxyAdmin.owner: ', proxyAdmin.owner); + vm.startBroadcast(proxyAdmin.ownerPk); + { + TransparentUpgradeableProxy(mintFeeModuleProxyAddr).upgradeTo(mintFeeModuleImpl); + } + vm.stopBroadcast(); + mintFeeModule = ProtocolSharedRevenueMinFeeMintModule(mintFeeModuleProxyAddr); + console.log('\n* * * MintFeeModule upgraded to new implementation: ', mintFeeModuleImpl); + } } function moduleRegistryActions() internal { @@ -204,7 +248,7 @@ contract DeployMintFeeModule is Script, ForkManagement { } function governanceActions() internal { - console.log('Owner of mintFeeModule:', mintFeeModule.owner()); + console.log('\n* * * Owner of mintFeeModule:', mintFeeModule.owner()); vm.startBroadcast(governance.ownerPk); { mintFeeModule.setMintFeeParams(bonsai, 10 ether); diff --git a/test/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.t.sol b/test/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.t.sol index 492509d..2501572 100644 --- a/test/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.t.sol +++ b/test/modules/act/collect/ProtocolSharedRevenueMinFeeMintModule.t.sol @@ -105,7 +105,7 @@ contract ProtocolSharedRevenueMinFeeMintModule_Initialization is mintFeeModuleExampleInitData.creatorClient = creatorClient; vm.prank(collectPublicationAction); - IBaseFeeCollectModule(baseFeeCollectModule).initializePublicationCollectModule( + bytes memory returnedData = IBaseFeeCollectModule(baseFeeCollectModule).initializePublicationCollectModule( profileId, pubId, transactionExecutor, @@ -142,6 +142,7 @@ contract ProtocolSharedRevenueMinFeeMintModule_Initialization is mintFeeModuleExampleInitData.creatorClient, 'CreatorClient initialization mismatch' ); + assertEq(keccak256(returnedData), keccak256(getEncodedInitData()), 'Returned data mismatch'); } } @@ -469,6 +470,9 @@ contract ProtocolSharedRevenueMinFeeMintModule_OwnerMethods is ProtocolSharedRev ProtocolSharedRevenueMinFeeMintModuleBase.setUp(); } + event MintFeeParamsSet(address token, uint256 amount, uint256 timestamp); + event ProtocolSharedRevenueDistributionSet(ProtocolSharedRevenueDistribution distribution, uint256 timestamp); + // Negatives function testCannotSetMintFeeParams_ifNotOwner(address currency, uint256 mintFee, address notOwner) public { @@ -563,6 +567,9 @@ contract ProtocolSharedRevenueMinFeeMintModule_OwnerMethods is ProtocolSharedRev currency = address(0); } + vm.expectEmit(true, true, true, true, address(mintFeeModule)); + emit MintFeeParamsSet(currency, mintFee, block.timestamp); + vm.prank(mintFeeModule.owner()); mintFeeModule.setMintFeeParams(currency, mintFee); @@ -589,6 +596,9 @@ contract ProtocolSharedRevenueMinFeeMintModule_OwnerMethods is ProtocolSharedRev executorClientSplit: executorClientSplit }); + vm.expectEmit(true, true, true, true, address(mintFeeModule)); + emit ProtocolSharedRevenueDistributionSet(expectedDistribution, block.timestamp); + vm.prank(mintFeeModule.owner()); mintFeeModule.setProtocolSharedRevenueDistribution(expectedDistribution);