diff --git a/addresses.json b/addresses.json index a25c796..db2d0a8 100644 --- a/addresses.json +++ b/addresses.json @@ -127,14 +127,14 @@ "Treasury": "0x6b5d40412956b8546bA2210810C100219f7011B6", "TreasuryFee": "0", "LegacyCollectNFTImpl": "0x5886B1Db98a3f5AaFBDeE2DEC4783C6927655B7e", - "FollowNFTImpl": "0x01d27aB196e10469203B556e244100f6DCe3bAd6", - "LensHandlesImpl": "0x17A0c50e61935e2b56EB9BEDc2785EC8F804cccb", + "FollowNFTImpl": "0x288715E67B7b184fD299143280CA6c1Eb7F31e1B", + "LensHandlesImpl": "0x0326e542257dDdd592DFfD0F0dFCBEa30E9acbbC", "LensHandles": "0xe7E7EaD361f3AaCD73A61A9bD6C10cA17F38E945", "TokenHandleRegistryImpl": "0x52fa68D73C83df39B9a637F82361d9b70aAb74F4", "TokenHandleRegistry": "0xD4F2F33680FCCb36748FA9831851643781608844", "ModuleRegistryImpl": "0xeD935AcE8f82FcAB4cae41F240c3a4aE51931313", "ModuleRegistry": "0x1eD5983F0c883B96f7C35528a1e22EEA67DE3Ff9", - "LensHubV2Impl": "0xc37554Aa89B2A4Bbcdb8AD9b5528BddaD9DF4341", + "LensHubV2Impl": "0xd1fd1d7EdaA0Ac4b065f01Eb728764c4d19fFF90", "GovernanceContract": "0xB03B8801cF9D074Ea468aAA8eBd9B5EeD67Ac5B6", "GovernanceContractAdmin": "0xf94b90BbEee30996019bABD12cEcdDCcf68331DE", "ProxyAdminContract": "0x573FDF61727436a38ec6C5f6408B1F50cd69e015", @@ -145,7 +145,10 @@ "CollectNFT": "0x0c2a7761E2971D906338F5da1ecF0027E4247fd7", "CollectPublicationActionImpl": "0xcc3f120f3d3bf860b910b228d2114f474b382c1d", "LitAccessControlImpl": "0x79dcA158B2A019EA2377f5989066a1ac0aC20e10", - "LitAccessControl": "0x98a6C31E43b158198da95Ef1242faCA868424187" + "LitAccessControl": "0x98a6C31E43b158198da95Ef1242faCA868424187", + "ProfileTokenURI": "0xE01e1017Eb1D49Aa7034628cd2e3021536cdeBE5", + "HandleTokenURI": "0x9632dC8eb31CEC8fcd166a99C1Da179716aE2E48", + "FollowTokenURI": "0x07D8a9FEdef6DC7004b9ae0935eA178bFa8bBdF1" }, "testnet": { "chainId": 80001, diff --git a/foundry.toml b/foundry.toml index 4a8cf10..899ad0b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -13,22 +13,19 @@ optimizer_runs = 10 ignored_error_codes = [] no_match_path = "script/svg/*" -# via_ir = true +via_ir = true -# libraries = [ -# 'contracts/libraries/ActionLib.sol:ActionLib:0x7990dac84e3241fe314b980bba1466ac08715c4f', -# 'contracts/libraries/FollowLib.sol:FollowLib:0xe280cb21fb36b6b2d584428b809a6b822a5c2260', -# 'contracts/libraries/GovernanceLib.sol:GovernanceLib:0x5268512d20bf7653cf6d54b7c485ae3fbc658451', -# 'contracts/libraries/LegacyCollectLib.sol:LegacyCollectLib:0x5f0f24377c00f1517b4de496cf49eec8beb4ecb4', -# 'contracts/libraries/MetaTxLib.sol:MetaTxLib:0xf191c489e4ba0f448ea08a5fd27e9c928643f5c7', -# 'contracts/libraries/MigrationLib.sol:MigrationLib:0x0deced9ac3833b687d69d4eac6655f0f1279acee', -# 'contracts/libraries/ProfileLib.sol:ProfileLib:0x3fce2475a92c185f9634f5638f6b33306d77bb10', -# 'contracts/libraries/PublicationLib.sol:PublicationLib:0x90654f24a2c164a4da8f763ac8bc032d3d083a1b', -# 'contracts/libraries/ValidationLib.sol:ValidationLib:0x9cafd24d2851d9eb56e5a8fd394ab2ac0ef99849', -# 'contracts/libraries/token-uris/FollowTokenURILib.sol:FollowTokenURILib:0xc58f0e2a361e35c08619ef5f6122dc15180d783e', -# 'contracts/libraries/token-uris/HandleTokenURILib.sol:HandleTokenURILib:0x0e20f112689c7894ab8142108574e45d2650f529', -# 'contracts/libraries/token-uris/ProfileTokenURILib.sol:ProfileTokenURILib:0xf167835e74eecfe4bc571701d34fd38f4b61a830' -# ] +libraries = [ + 'contracts/libraries/ActionLib.sol:ActionLib:0x7990dac84e3241fe314b980bba1466ac08715c4f', + 'contracts/libraries/FollowLib.sol:FollowLib:0xe280cb21fb36b6b2d584428b809a6b822a5c2260', + 'contracts/libraries/GovernanceLib.sol:GovernanceLib:0x8a83227dbf5c80b1f693de63babe168c59fefd6b', +# 'contracts/libraries/LegacyCollectLib.sol:LegacyCollectLib:0x5f0f24377c00f1517b4de496cf49eec8beb4ecb4', + 'contracts/libraries/MetaTxLib.sol:MetaTxLib:0xf191c489e4ba0f448ea08a5fd27e9c928643f5c7', + 'contracts/libraries/MigrationLib.sol:MigrationLib:0x0deced9ac3833b687d69d4eac6655f0f1279acee', + 'contracts/libraries/ProfileLib.sol:ProfileLib:0x3fce2475a92c185f9634f5638f6b33306d77bb10', + 'contracts/libraries/PublicationLib.sol:PublicationLib:0x90654f24a2c164a4da8f763ac8bc032d3d083a1b', + 'contracts/libraries/ValidationLib.sol:ValidationLib:0x9cafd24d2851d9eb56e5a8fd394ab2ac0ef99849', +] [rpc_endpoints] polygon = "${POLYGON_RPC_URL}" diff --git a/script/DeployLegacyCollectFix.s.sol b/script/DeployLegacyCollectFix.s.sol new file mode 100644 index 0000000..1ecf858 --- /dev/null +++ b/script/DeployLegacyCollectFix.s.sol @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.13; + +import {ForkManagement} from 'script/helpers/ForkManagement.sol'; +import 'forge-std/Script.sol'; +import {LibString} from 'solady/utils/LibString.sol'; +import {LensHubInitializable} from 'contracts/misc/LensHubInitializable.sol'; +import {Types} from 'contracts/libraries/constants/Types.sol'; +import {Governance} from 'contracts/misc/access/Governance.sol'; +import {LensHandles} from 'contracts/namespaces/LensHandles.sol'; + +contract DeployLegacyCollectFix is Script, ForkManagement { + using stdJson for string; + + struct LensAccount { + uint256 ownerPk; + address owner; + uint256 profileId; + } + + LensAccount _deployer; + + string mnemonic; + + uint256 internal PROFILE_GUARDIAN_COOLDOWN; + uint256 internal HANDLE_GUARDIAN_COOLDOWN; + + address lensHub; + address legacyCollectNFTImpl; + address followNFTImpl; + address moduleRegistry; + + address lensHandlesAddress; + address tokenHandleRegistryAddress; + address legacyFeeFollowModule; + address legacyProfileFollowModule; + address newFeeFollowModule; + address lensHandlesOwner; + address lensHandlesImpl; + + address governanceContract; + address governanceAdmin; + address lensHubV2Impl; + + string addressesFile = 'addressesV2.txt'; + + // TODO: Use from test/ContractAddresses + struct Module { + address addy; + string name; + } + + // TODO: Move this somewhere common (also in UpgradeForkTest) + 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); + inputs[0] = 'node'; + inputs[1] = 'script/helpers/saveAddress.js'; + inputs[2] = targetEnv; + inputs[3] = contractName; + inputs[4] = vm.toString(deployedAddress); + // bytes memory res = + vm.ffi(inputs); + // string memory output = abi.decode(res, (string)); + // console.log(output); + } + + function loadPrivateKeys() internal { + if (isEnvSet('MNEMONIC')) { + mnemonic = vm.envString('MNEMONIC'); + } + + if (bytes(mnemonic).length == 0) { + revert('Missing mnemonic'); + } + + console.log('\n'); + + (_deployer.owner, _deployer.ownerPk) = deriveRememberKey(mnemonic, 0); + console.logBytes32(bytes32(_deployer.ownerPk)); + console.log('Deployer address: %s', address(_deployer.owner)); + + console.log('\n'); + + console.log('Current block:', block.number); + } + + function loadBaseAddresses() internal override { + lensHub = json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHubProxy'))); + vm.label(lensHub, 'LensHub'); + console.log('Lens Hub Proxy: %s', lensHub); + + followNFTImpl = json.readAddress(string(abi.encodePacked('.', targetEnv, '.FollowNFTImpl'))); + vm.label(followNFTImpl, 'FollowNFTImpl'); + console.log('FollowNFTImpl: %s', followNFTImpl); + + legacyCollectNFTImpl = json.readAddress(string(abi.encodePacked('.', targetEnv, '.LegacyCollectNFTImpl'))); + vm.label(legacyCollectNFTImpl, 'LegacyCollectNFTImpl'); + console.log('LegacyCollectNFTImpl: %s', legacyCollectNFTImpl); + + moduleRegistry = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ModuleRegistry'))); + vm.label(moduleRegistry, 'ModuleRegistry'); + console.log('ModuleRegistry: %s', moduleRegistry); + + PROFILE_GUARDIAN_COOLDOWN = json.readUint( + string(abi.encodePacked('.', targetEnv, '.LensProfilesGuardianTimelock')) + ); + console.log('PROFILE_GUARDIAN_COOLDOWN: %s', PROFILE_GUARDIAN_COOLDOWN); + + HANDLE_GUARDIAN_COOLDOWN = json.readUint( + string(abi.encodePacked('.', targetEnv, '.LensHandlesGuardianTimelock')) + ); + console.log('HANDLE_GUARDIAN_COOLDOWN: %s', HANDLE_GUARDIAN_COOLDOWN); + + lensHandlesAddress = json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHandles'))); + + tokenHandleRegistryAddress = json.readAddress(string(abi.encodePacked('.', targetEnv, '.TokenHandleRegistry'))); + + Module[] memory followModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v1.follow'))), + (Module[]) + ); + + legacyFeeFollowModule = findModuleHelper(followModules, 'FeeFollowModule').addy; + vm.label(legacyFeeFollowModule, 'LegacyFeeFollowModule'); + console.log('Legacy Fee Follow Module: %s', legacyFeeFollowModule); + + legacyProfileFollowModule = findModuleHelper(followModules, 'ProfileFollowModule').addy; + vm.label(legacyProfileFollowModule, 'LegacyProfileFollowModule'); + console.log('Legacy Profile Follow Module: %s', legacyProfileFollowModule); + + followModules = abi.decode( + vm.parseJson(json, string(abi.encodePacked('.', targetEnv, '.Modules.v2.follow'))), + (Module[]) + ); + + newFeeFollowModule = findModuleHelper(followModules, 'FeeFollowModule').addy; + vm.label(newFeeFollowModule, 'NewFeeFollowModule'); + console.log('New Fee Follow Module: %s', newFeeFollowModule); + + governanceContract = LensHubInitializable(lensHub).getGovernance(); + governanceAdmin = Governance(governanceContract).owner(); + + lensHandlesOwner = governanceAdmin; + vm.label(lensHandlesOwner, 'LensHandlesOwner'); + console.log('LensHandlesOwner: %s', lensHandlesOwner); + } + + function deploy() internal { + if (lensHub == address(0)) { + console.log('LensHub not set'); + revert('LensHub not set'); + } + + if (lensHandlesOwner == address(0)) { + console.log('lensHandlesOwner not set'); + revert('lensHandlesOwner not set'); + } + + if (HANDLE_GUARDIAN_COOLDOWN == 0) { + console.log('HANDLE_GUARDIAN_COOLDOWN not set'); + revert('HANDLE_GUARDIAN_COOLDOWN not set'); + } + + vm.startBroadcast(_deployer.ownerPk); + + // Deploy LensHandles(owner, hub) implementation + lensHandlesImpl = address(new LensHandles(lensHandlesOwner, lensHub, HANDLE_GUARDIAN_COOLDOWN)); + vm.stopBroadcast(); + + vm.writeLine(addressesFile, string.concat('FollowNFTImpl: ', vm.toString(followNFTImpl))); + saveContractAddress('FollowNFTImpl', followNFTImpl); + console.log('FollowNFTImpl: %s', followNFTImpl); + + vm.writeLine(addressesFile, string.concat('LensHandlesImpl: ', vm.toString(lensHandlesImpl))); + saveContractAddress('LensHandlesImpl', lensHandlesImpl); + console.log('LensHandlesImpl: %s', lensHandlesImpl); + + if (legacyCollectNFTImpl == address(0)) { + console.log('LegacyCollectNFTImpl not set'); + revert('LegacyCollectNFTImpl not set'); + } + + if (moduleRegistry == address(0)) { + console.log('ModuleRegistry not set'); + revert('ModuleRegistry not set'); + } + + if (PROFILE_GUARDIAN_COOLDOWN == 0) { + console.log('PROFILE_GUARDIAN_COOLDOWN not set'); + revert('PROFILE_GUARDIAN_COOLDOWN not set'); + } + + console.log('PROFILE_GUARDIAN_COOLDOWN: %s', PROFILE_GUARDIAN_COOLDOWN); + + // Pass all the fucking shit and deploy LensHub V2 Impl with: + vm.startBroadcast(_deployer.ownerPk); + lensHubV2Impl = address( + new LensHubInitializable( + followNFTImpl, + legacyCollectNFTImpl, + moduleRegistry, + PROFILE_GUARDIAN_COOLDOWN, + Types.MigrationParams({ + lensHandlesAddress: lensHandlesAddress, + tokenHandleRegistryAddress: tokenHandleRegistryAddress, + legacyFeeFollowModule: legacyFeeFollowModule, + legacyProfileFollowModule: legacyProfileFollowModule, + newFeeFollowModule: newFeeFollowModule + }) + ) + ); + vm.stopBroadcast(); + + console.log('"arguments": ['); + console.log('\t"%s"', followNFTImpl); + console.log('\t"%s"', legacyCollectNFTImpl); + console.log('\t"%s"', moduleRegistry); + console.log('\t"%s"', PROFILE_GUARDIAN_COOLDOWN); + console.log( + '\t"%s"', + string.concat( + '(', + vm.toString(lensHandlesAddress), + ', ', + vm.toString(tokenHandleRegistryAddress), + ', ', + vm.toString(legacyFeeFollowModule), + ', ', + vm.toString(legacyProfileFollowModule), + ', ', + vm.toString(newFeeFollowModule), + ')' + ) + ); + console.log(']'); + + vm.writeLine(addressesFile, string.concat('LensHubV2Impl: ', vm.toString(lensHubV2Impl))); + saveContractAddress('LensHubV2Impl', lensHubV2Impl); + console.log('LensHubV2Impl: %s', lensHubV2Impl); + } + + function run(string memory targetEnv_) external { + targetEnv = targetEnv_; + loadJson(); + checkNetworkParams(); + loadBaseAddresses(); + loadPrivateKeys(); + deploy(); + } +}