misc: catapulta introduced in deployment scripts

This commit is contained in:
vicnaum
2023-10-25 18:08:28 +02:00
parent 4eb2162f48
commit 51921eb474
9 changed files with 834 additions and 309 deletions

View File

@@ -20,9 +20,9 @@ import {Types} from 'contracts/libraries/constants/Types.sol';
import {LibString} from 'solady/utils/LibString.sol';
import {LegacyCollectNFT} from 'contracts/misc/LegacyCollectNFT.sol';
import {ArrayHelpers} from 'test/helpers/ArrayHelpers.sol';
import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol';
contract LensV2UpgradeDeployment is Script, ForkManagement, ArrayHelpers {
contract A_DeployLensV2Upgrade is Script, ForkManagement, ArrayHelpers {
// add this to be excluded from coverage report
function testLensV2UpgradeDeployment() public {}
@@ -183,16 +183,6 @@ contract LensV2UpgradeDeployment is Script, ForkManagement, ArrayHelpers {
console.log('Current block:', block.number);
}
function run(string memory targetEnv_) external {
targetEnv = targetEnv_;
loadJson();
checkNetworkParams();
loadPrivateKeys();
loadBaseAddresses();
deploy();
}
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);
@@ -410,4 +400,14 @@ contract LensV2UpgradeDeployment is Script, ForkManagement, ArrayHelpers {
}
revert('Module not found');
}
function run(string memory targetEnv_) external {
targetEnv = targetEnv_;
loadJson();
checkNetworkParams();
loadPrivateKeys();
loadBaseAddresses();
deploy();
}
}

View File

@@ -33,9 +33,9 @@ import {Governance} from 'contracts/misc/access/Governance.sol';
import {PublicActProxy} from 'contracts/misc/PublicActProxy.sol';
import {LitAccessControl} from 'contracts/misc/access/LitAccessControl.sol';
import {ArrayHelpers} from 'test/helpers/ArrayHelpers.sol';
import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol';
contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
contract B_DeployLensV2Periphery is Script, ForkManagement, ArrayHelpers {
// add this to be excluded from coverage report
function testLensV2DeployPeriphery() public {}
@@ -58,7 +58,7 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
address profileCreator;
address proxyAdmin;
address proxyAdminContractAdmin;
ModuleRegistry moduleRegistryImpl;
TransparentUpgradeableProxy moduleRegistryProxy;
@@ -173,9 +173,9 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
vm.label(profileCreator, 'ProfileCreator');
console.log('ProfileCreator: %s', profileCreator);
proxyAdmin = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProxyAdminContractAdmin')));
vm.label(proxyAdmin, 'ProxyAdminContractAdmin');
console.log('ProxyAdminContractAdmin: %s', proxyAdmin);
proxyAdminContractAdmin = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProxyAdminContractAdmin')));
vm.label(proxyAdminContractAdmin, 'ProxyAdminContractAdmin');
console.log('ProxyAdminContractAdmin: %s', proxyAdminContractAdmin);
hub = ILensHub(json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHubProxy'))));
vm.label(address(hub), 'LensHub');
@@ -260,7 +260,7 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
collectPublicationActionProxy = new TransparentUpgradeableProxy({
_logic: address(collectPublicationActionImpl),
admin_: proxyAdmin,
admin_: proxyAdminContractAdmin,
_data: ''
});
console.log('\n+ + + CollectPublicationActionProxy: %s', address(collectPublicationActionProxy));
@@ -352,7 +352,7 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
saveContractAddress('LitAccessControlImpl', litAccessControlImpl);
litAccessControl = address(
new TransparentUpgradeableProxy({_logic: litAccessControlImpl, admin_: proxyAdmin, _data: ''})
new TransparentUpgradeableProxy({_logic: litAccessControlImpl, admin_: proxyAdminContractAdmin, _data: ''})
);
console.log('\n+ + + LitAccessControl: %s', litAccessControl);
vm.writeLine(addressesFile, string.concat('LitAccessControl: ', vm.toString(litAccessControl)));
@@ -362,286 +362,6 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
vm.stopBroadcast();
}
function _governanceActions() internal {
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(profileCreationProxy), true);
console.log('\n* * * Profile creator proxy %s registered as profile creator', address(profileCreationProxy));
hub.setState(Types.ProtocolState.Unpaused);
console.log('\n* * * Protocol unpaused');
vm.stopBroadcast();
}
function _registerCurrencies() internal {
vm.startBroadcast(deployer.ownerPk);
// TODO: Get the currency addresses from the addresses.json
moduleRegistry.registerErc20Currency(address(0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e));
console.log('\n* * * USDC registered as currency');
vm.writeLine(
addressesFile,
string.concat('USDC: ', vm.toString(address(0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e)))
);
moduleRegistry.registerErc20Currency(address(0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F));
console.log('\n* * * DAI registered as currency');
vm.writeLine(
addressesFile,
string.concat('DAI: ', vm.toString(address(0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F)))
);
moduleRegistry.registerErc20Currency(address(0x3C68CE8504087f89c640D02d133646d98e64ddd9));
console.log('\n* * * WETH registered as currency');
vm.writeLine(
addressesFile,
string.concat('WETH: ', vm.toString(address(0x3C68CE8504087f89c640D02d133646d98e64ddd9)))
);
moduleRegistry.registerErc20Currency(address(0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889));
console.log('\n* * * WMATIC registered as currency');
vm.writeLine(
addressesFile,
string.concat('WMATIC: ', vm.toString(address(0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889)))
);
vm.stopBroadcast();
}
function _registerModules() internal {
vm.startBroadcast(deployer.ownerPk);
// Follow modules
moduleRegistry.registerModule(address(feeFollowModule), uint256(IModuleRegistry.ModuleType.FOLLOW_MODULE));
console.log('\n* * * FeeFollowModule registered as follow module');
moduleRegistry.registerModule(address(revertFollowModule), uint256(IModuleRegistry.ModuleType.FOLLOW_MODULE));
console.log('\n* * * RevertFollowModule registered as follow module');
// Reference modules
moduleRegistry.registerModule(
address(degreesOfSeparationReferenceModule),
uint256(IModuleRegistry.ModuleType.REFERENCE_MODULE)
);
console.log('\n* * * DegreesOfSeparationReferenceModule registered');
moduleRegistry.registerModule(
address(followerOnlyReferenceModule),
uint256(IModuleRegistry.ModuleType.REFERENCE_MODULE)
);
console.log('\n* * * FollowerOnlyReferenceModule registered');
// Collect modules
moduleRegistry.registerModule(
address(collectPublicationAction),
uint256(IModuleRegistry.ModuleType.PUBLICATION_ACTION_MODULE)
);
console.log('\n* * * CollectPublicationAction registered as action module');
collectPublicationAction.registerCollectModule(address(simpleFeeCollectModule));
console.log('\n* * * SimpleFeeCollectModule registered as collect module');
collectPublicationAction.registerCollectModule(address(multirecipientFeeCollectModule));
console.log('\n* * * MultirecipientFeeCollectModule registered as collect module');
vm.stopBroadcast();
}
function _interact() internal {
vm.startBroadcast(deployer.ownerPk);
ProfileCreationProxy temporarilyCreationProxy = new ProfileCreationProxy({
owner: deployer.owner,
hub: address(hub),
lensHandles: address(handles),
tokenHandleRegistry: address(tokenHandleRegistry)
});
vm.stopBroadcast();
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(temporarilyCreationProxy), true);
vm.stopBroadcast();
vm.startBroadcast(deployer.ownerPk);
(uint256 firstProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'firstprofile'
});
(uint256 secondProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'secondprofile'
});
(uint256 anonymousProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'annoymouse'
});
saveValue('AnonymousProfileId', vm.toString(anonymousProfileId));
// set DE to publicActProxy
hub.changeDelegatedExecutorsConfig({
delegatorProfileId: anonymousProfileId,
delegatedExecutors: _toAddressArray(address(publicActProxy)),
approvals: _toBoolArray(true)
});
hub.follow({
followerProfileId: firstProfileId,
idsOfProfilesToFollow: _toUint256Array(secondProfileId),
followTokenIds: _toUint256Array(0),
datas: _toBytesArray('')
});
hub.post(
Types.PostParams({
profileId: firstProfileId,
contentURI: 'ipfs://HelloWorld',
actionModules: _emptyAddressArray(),
actionModulesInitDatas: _emptyBytesArray(),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// unfollow
hub.unfollow({unfollowerProfileId: firstProfileId, idsOfProfilesToUnfollow: _toUint256Array(secondProfileId)});
FeeConfig memory feeConfig = FeeConfig({
currency: 0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e,
amount: 69000000,
recipient: address(0xcB6C7b2E340D50701d45d55507f19A5cE5d72330)
});
// set a follow module
hub.setFollowModule({
profileId: firstProfileId,
followModule: address(feeFollowModule),
followModuleInitData: abi.encode(feeConfig)
});
// set metadata
hub.setProfileMetadataURI({profileId: firstProfileId, metadataURI: 'ipfs://TestingMetadataURI'});
BaseFeeCollectModuleInitData memory collectModuleInitData = BaseFeeCollectModuleInitData({
amount: 0,
collectLimit: 69,
currency: address(0),
referralFee: 2500,
followerOnly: false,
endTimestamp: 0,
recipient: address(0xcB6C7b2E340D50701d45d55507f19A5cE5d72330)
});
// comment with open action
hub.comment(
Types.CommentParams({
profileId: firstProfileId,
contentURI: 'ipfs://testCommentURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: '',
actionModules: _toAddressArray(address(collectPublicationAction)),
actionModulesInitDatas: _toBytesArray(
abi.encode(simpleFeeCollectModule, abi.encode(collectModuleInitData))
),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// collect it
hub.act(
Types.PublicationActionParams({
publicationActedProfileId: firstProfileId,
publicationActedId: 2,
actorProfileId: firstProfileId,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
actionModuleAddress: address(collectPublicationAction),
actionModuleData: abi.encode(
address(0x1A1cDf59C94a682a067fA2D288C2167a8506abd7),
abi.encode(address(0), 0)
)
})
);
// mirror
hub.mirror(
Types.MirrorParams({
profileId: firstProfileId,
metadataURI: 'ipfs://testMirrorURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: ''
})
);
// quote (all of the same one)
hub.quote(
Types.QuoteParams({
profileId: firstProfileId,
contentURI: 'ipfs://testQuoteURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: '',
actionModules: _emptyAddressArray(),
actionModulesInitDatas: _emptyBytesArray(),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// block
hub.setBlockStatus({
byProfileId: firstProfileId,
idsOfProfilesToSetBlockStatus: _toUint256Array(secondProfileId),
blockStatus: _toBoolArray(true)
});
// unblock
hub.setBlockStatus({
byProfileId: firstProfileId,
idsOfProfilesToSetBlockStatus: _toUint256Array(secondProfileId),
blockStatus: _toBoolArray(false)
});
// set random address for profile manager
hub.changeDelegatedExecutorsConfig({
delegatorProfileId: firstProfileId,
delegatedExecutors: _toAddressArray(address(0x1A1cDf59C94a682a067fA2D288C2167a8506abd7)),
approvals: _toBoolArray(true)
});
// unset profile guardian
hub.DANGER__disableTokenGuardian();
vm.stopBroadcast();
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(temporarilyCreationProxy), false);
vm.stopBroadcast();
}
function _writeBackendEnvFile() internal {
string memory backendEnv = 'backendEnv.txt';
vm.writeLine(backendEnv, '## Hub');
@@ -699,6 +419,5 @@ contract LensV2DeployPeriphery is Script, ForkManagement, ArrayHelpers {
loadBaseAddresses();
deploy();
_writeBackendEnvFile();
_interact();
}
}

View File

@@ -9,7 +9,7 @@ import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {ProxyAdmin} from 'contracts/misc/access/ProxyAdmin.sol';
import {TransparentUpgradeableProxy} from '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
contract LensV1ChangeAdmins is Script, ForkManagement {
contract C_ChangeLensV1Admins is Script, ForkManagement {
// add this to be excluded from coverage report
function testLensV1ChangeAdmins() public {}

View File

@@ -9,7 +9,7 @@ import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {ProxyAdmin} from 'contracts/misc/access/ProxyAdmin.sol';
import {TransparentUpgradeableProxy} from '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
contract LensV1ToV2Upgrade is Script, ForkManagement {
contract D_PerformV2Upgrade is Script, ForkManagement {
// add this to be excluded from coverage report
function testLensV1ToV2Upgrade() public {}

View File

@@ -0,0 +1,301 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {ForkManagement} from 'script/helpers/ForkManagement.sol';
import 'forge-std/Script.sol';
import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {FollowNFT} from 'contracts/FollowNFT.sol';
import {LensHandles} from 'contracts/namespaces/LensHandles.sol';
import {TokenHandleRegistry} from 'contracts/namespaces/TokenHandleRegistry.sol';
import {TransparentUpgradeableProxy} from '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {FeeConfig, FeeFollowModule} from 'contracts/modules/follow/FeeFollowModule.sol';
import {Governance} from 'contracts/misc/access/Governance.sol';
import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {ProxyAdmin} from 'contracts/misc/access/ProxyAdmin.sol';
import {LensHubInitializable} from 'contracts/misc/LensHubInitializable.sol';
import {ILensHub} from 'contracts/interfaces/ILensHub.sol';
import {ILensHandles} from 'contracts/interfaces/ILensHandles.sol';
import {ITokenHandleRegistry} from 'contracts/interfaces/ITokenHandleRegistry.sol';
import {ProfileCreationProxy} from 'contracts/misc/ProfileCreationProxy.sol';
import {CollectNFT} from 'contracts/modules/act/collect/CollectNFT.sol';
import {CollectPublicationAction} from 'contracts/modules/act/collect/CollectPublicationAction.sol';
import {SimpleFeeCollectModule} from 'contracts/modules/act/collect/SimpleFeeCollectModule.sol';
import {MultirecipientFeeCollectModule} from 'contracts/modules/act/collect/MultirecipientFeeCollectModule.sol';
import {RevertFollowModule} from 'contracts/modules/follow/RevertFollowModule.sol';
import {DegreesOfSeparationReferenceModule} from 'contracts/modules/reference/DegreesOfSeparationReferenceModule.sol';
import {FollowerOnlyReferenceModule} from 'contracts/modules/reference/FollowerOnlyReferenceModule.sol';
import {TokenGatedReferenceModule} from 'contracts/modules/reference/TokenGatedReferenceModule.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import {ModuleRegistry} from 'contracts/misc/ModuleRegistry.sol';
import {IModuleRegistry} from 'contracts/interfaces/IModuleRegistry.sol';
import {BaseFeeCollectModuleInitData} from 'contracts/modules/interfaces/IBaseFeeCollectModule.sol';
import {Governance} from 'contracts/misc/access/Governance.sol';
import {PublicActProxy} from 'contracts/misc/PublicActProxy.sol';
import {LitAccessControl} from 'contracts/misc/access/LitAccessControl.sol';
import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol';
contract E_GovernanceActions is Script, ForkManagement, ArrayHelpers {
// add this to be excluded from coverage report
function testLensV2DeployPeriphery() public {}
using stdJson for string;
string addressesFile = 'addressesV2.txt';
string mnemonic;
struct LensAccount {
uint256 ownerPk;
address owner;
uint256 profileId;
}
LensAccount deployer;
LensAccount governance;
Governance governanceContract;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
address profileCreator;
address proxyAdminContractAdmin;
ModuleRegistry moduleRegistryImpl;
TransparentUpgradeableProxy moduleRegistryProxy;
ModuleRegistry moduleRegistry;
FollowNFT followNFT;
LensHubInitializable lensHubImpl;
TransparentUpgradeableProxy hubProxy;
ILensHub hub;
LensHandles handlesImpl;
TransparentUpgradeableProxy handlesProxy;
ILensHandles handles;
TokenHandleRegistry tokenHandleRegistryImpl;
TransparentUpgradeableProxy tokenHandleRegistryProxy;
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;
PublicActProxy publicActProxy;
address litAccessControl;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 saveValue(string memory contractName, string memory str) 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] = str;
// bytes memory res =
vm.ffi(inputs);
// string memory output = abi.decode(res, (string));
// console.log(output);
}
function saveModule(
string memory moduleName,
address moduleAddress,
string memory lensVersion,
string memory moduleType
) internal {
// console.log('Saving %s (%s) into addresses under %s environment', moduleName, moduleAddress, targetEnv);
string[] memory inputs = new string[](7);
inputs[0] = 'node';
inputs[1] = 'script/helpers/saveAddress.js';
inputs[2] = targetEnv;
inputs[3] = moduleName;
inputs[4] = vm.toString(moduleAddress);
inputs[5] = lensVersion;
inputs[6] = moduleType;
// 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- - - CURRENT BLOCK: ', block.number);
(deployer.owner, deployer.ownerPk) = deriveRememberKey(mnemonic, 0);
console.log('\n- - - DEPLOYER: %s', deployer.owner);
(governance.owner, governance.ownerPk) = deriveRememberKey(mnemonic, 1);
console.log('\n- - - GOVERNANCE: %s', governance.owner);
}
function loadBaseAddresses() internal override {
address governanceContractAdmin = json.readAddress(
string(abi.encodePacked('.', targetEnv, '.GovernanceContractAdmin'))
);
if (governance.owner != governanceContractAdmin) {
console.log(
'Mock Governance %s != Governance contract admin %s',
governance.owner,
governanceContractAdmin
);
revert();
}
profileCreator = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProfileCreator')));
vm.label(profileCreator, 'ProfileCreator');
console.log('ProfileCreator: %s', profileCreator);
proxyAdminContractAdmin = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProxyAdminContractAdmin')));
vm.label(proxyAdminContractAdmin, 'ProxyAdminContractAdmin');
console.log('ProxyAdminContractAdmin: %s', proxyAdminContractAdmin);
hub = ILensHub(json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHubProxy'))));
vm.label(address(hub), 'LensHub');
console.log('Lens Hub Proxy: %s', address(hub));
handles = ILensHandles(json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHandles'))));
vm.label(address(handles), 'LensHandles');
console.log('Lens Handles: %s', address(handles));
tokenHandleRegistry = ITokenHandleRegistry(
json.readAddress(string(abi.encodePacked('.', targetEnv, '.TokenHandleRegistry')))
);
vm.label(address(tokenHandleRegistry), 'TokenHandleRegistry');
console.log('Token Handle Registry: %s', address(tokenHandleRegistry));
moduleRegistry = ModuleRegistry(json.readAddress(string(abi.encodePacked('.', targetEnv, '.ModuleRegistry'))));
vm.label(address(moduleRegistry), 'ModuleRegistry');
console.log('Module Registry: %s', address(moduleRegistry));
governanceContract = Governance(
json.readAddress(string(abi.encodePacked('.', targetEnv, '.GovernanceContract')))
);
vm.label(address(governanceContract), 'GovernanceContract');
console.log('Governance Contract: %s', address(governanceContract));
}
function _governanceActions() internal {
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(profileCreationProxy), true);
console.log('\n* * * Profile creator proxy %s registered as profile creator', address(profileCreationProxy));
hub.setState(Types.ProtocolState.Unpaused);
console.log('\n* * * Protocol unpaused');
vm.stopBroadcast();
}
function _registerCurrencies() internal {
vm.startBroadcast(deployer.ownerPk);
// TODO: Get the currency addresses from the addresses.json
moduleRegistry.registerErc20Currency(address(0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e));
console.log('\n* * * USDC registered as currency');
vm.writeLine(
addressesFile,
string.concat('USDC: ', vm.toString(address(0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e)))
);
moduleRegistry.registerErc20Currency(address(0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F));
console.log('\n* * * DAI registered as currency');
vm.writeLine(
addressesFile,
string.concat('DAI: ', vm.toString(address(0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F)))
);
moduleRegistry.registerErc20Currency(address(0x3C68CE8504087f89c640D02d133646d98e64ddd9));
console.log('\n* * * WETH registered as currency');
vm.writeLine(
addressesFile,
string.concat('WETH: ', vm.toString(address(0x3C68CE8504087f89c640D02d133646d98e64ddd9)))
);
moduleRegistry.registerErc20Currency(address(0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889));
console.log('\n* * * WMATIC registered as currency');
vm.writeLine(
addressesFile,
string.concat('WMATIC: ', vm.toString(address(0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889)))
);
vm.stopBroadcast();
}
function _registerModules() internal {
vm.startBroadcast(deployer.ownerPk);
// Follow modules
moduleRegistry.registerModule(address(feeFollowModule), uint256(IModuleRegistry.ModuleType.FOLLOW_MODULE));
console.log('\n* * * FeeFollowModule registered as follow module');
moduleRegistry.registerModule(address(revertFollowModule), uint256(IModuleRegistry.ModuleType.FOLLOW_MODULE));
console.log('\n* * * RevertFollowModule registered as follow module');
// Reference modules
moduleRegistry.registerModule(
address(degreesOfSeparationReferenceModule),
uint256(IModuleRegistry.ModuleType.REFERENCE_MODULE)
);
console.log('\n* * * DegreesOfSeparationReferenceModule registered');
moduleRegistry.registerModule(
address(followerOnlyReferenceModule),
uint256(IModuleRegistry.ModuleType.REFERENCE_MODULE)
);
console.log('\n* * * FollowerOnlyReferenceModule registered');
// Collect modules
moduleRegistry.registerModule(
address(collectPublicationAction),
uint256(IModuleRegistry.ModuleType.PUBLICATION_ACTION_MODULE)
);
console.log('\n* * * CollectPublicationAction registered as action module');
collectPublicationAction.registerCollectModule(address(simpleFeeCollectModule));
console.log('\n* * * SimpleFeeCollectModule registered as collect module');
collectPublicationAction.registerCollectModule(address(multirecipientFeeCollectModule));
console.log('\n* * * MultirecipientFeeCollectModule registered as collect module');
vm.stopBroadcast();
}
function run(string memory targetEnv_) external {
targetEnv = targetEnv_;
loadJson();
checkNetworkParams();
loadPrivateKeys();
loadBaseAddresses();
_governanceActions();
_registerCurrencies();
_registerModules();
}
}

View File

@@ -0,0 +1,408 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {ForkManagement} from 'script/helpers/ForkManagement.sol';
import 'forge-std/Script.sol';
import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {FollowNFT} from 'contracts/FollowNFT.sol';
import {LensHandles} from 'contracts/namespaces/LensHandles.sol';
import {TokenHandleRegistry} from 'contracts/namespaces/TokenHandleRegistry.sol';
import {TransparentUpgradeableProxy} from '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {FeeConfig, FeeFollowModule} from 'contracts/modules/follow/FeeFollowModule.sol';
import {Governance} from 'contracts/misc/access/Governance.sol';
import {LensV2UpgradeContract} from 'contracts/misc/LensV2UpgradeContract.sol';
import {ProxyAdmin} from 'contracts/misc/access/ProxyAdmin.sol';
import {LensHubInitializable} from 'contracts/misc/LensHubInitializable.sol';
import {ILensHub} from 'contracts/interfaces/ILensHub.sol';
import {ILensHandles} from 'contracts/interfaces/ILensHandles.sol';
import {ITokenHandleRegistry} from 'contracts/interfaces/ITokenHandleRegistry.sol';
import {ProfileCreationProxy} from 'contracts/misc/ProfileCreationProxy.sol';
import {CollectNFT} from 'contracts/modules/act/collect/CollectNFT.sol';
import {CollectPublicationAction} from 'contracts/modules/act/collect/CollectPublicationAction.sol';
import {SimpleFeeCollectModule} from 'contracts/modules/act/collect/SimpleFeeCollectModule.sol';
import {MultirecipientFeeCollectModule} from 'contracts/modules/act/collect/MultirecipientFeeCollectModule.sol';
import {RevertFollowModule} from 'contracts/modules/follow/RevertFollowModule.sol';
import {DegreesOfSeparationReferenceModule} from 'contracts/modules/reference/DegreesOfSeparationReferenceModule.sol';
import {FollowerOnlyReferenceModule} from 'contracts/modules/reference/FollowerOnlyReferenceModule.sol';
import {TokenGatedReferenceModule} from 'contracts/modules/reference/TokenGatedReferenceModule.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import {ModuleRegistry} from 'contracts/misc/ModuleRegistry.sol';
import {IModuleRegistry} from 'contracts/interfaces/IModuleRegistry.sol';
import {BaseFeeCollectModuleInitData} from 'contracts/modules/interfaces/IBaseFeeCollectModule.sol';
import {Governance} from 'contracts/misc/access/Governance.sol';
import {PublicActProxy} from 'contracts/misc/PublicActProxy.sol';
import {LitAccessControl} from 'contracts/misc/access/LitAccessControl.sol';
import {ArrayHelpers} from 'script/helpers/ArrayHelpers.sol';
contract F_InteractWithLensV2 is Script, ForkManagement, ArrayHelpers {
// add this to be excluded from coverage report
function testLensV2DeployPeriphery() public {}
using stdJson for string;
string addressesFile = 'addressesV2.txt';
string mnemonic;
struct LensAccount {
uint256 ownerPk;
address owner;
uint256 profileId;
}
LensAccount deployer;
LensAccount governance;
Governance governanceContract;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
address profileCreator;
address proxyAdminContractAdmin;
ModuleRegistry moduleRegistryImpl;
TransparentUpgradeableProxy moduleRegistryProxy;
ModuleRegistry moduleRegistry;
FollowNFT followNFT;
LensHubInitializable lensHubImpl;
TransparentUpgradeableProxy hubProxy;
ILensHub hub;
LensHandles handlesImpl;
TransparentUpgradeableProxy handlesProxy;
ILensHandles handles;
TokenHandleRegistry tokenHandleRegistryImpl;
TransparentUpgradeableProxy tokenHandleRegistryProxy;
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;
PublicActProxy publicActProxy;
address litAccessControl;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 saveValue(string memory contractName, string memory str) 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] = str;
// bytes memory res =
vm.ffi(inputs);
// string memory output = abi.decode(res, (string));
// console.log(output);
}
function saveModule(
string memory moduleName,
address moduleAddress,
string memory lensVersion,
string memory moduleType
) internal {
// console.log('Saving %s (%s) into addresses under %s environment', moduleName, moduleAddress, targetEnv);
string[] memory inputs = new string[](7);
inputs[0] = 'node';
inputs[1] = 'script/helpers/saveAddress.js';
inputs[2] = targetEnv;
inputs[3] = moduleName;
inputs[4] = vm.toString(moduleAddress);
inputs[5] = lensVersion;
inputs[6] = moduleType;
// 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- - - CURRENT BLOCK: ', block.number);
(deployer.owner, deployer.ownerPk) = deriveRememberKey(mnemonic, 0);
console.log('\n- - - DEPLOYER: %s', deployer.owner);
(governance.owner, governance.ownerPk) = deriveRememberKey(mnemonic, 1);
console.log('\n- - - GOVERNANCE: %s', governance.owner);
}
function loadBaseAddresses() internal override {
address governanceContractAdmin = json.readAddress(
string(abi.encodePacked('.', targetEnv, '.GovernanceContractAdmin'))
);
if (governance.owner != governanceContractAdmin) {
console.log(
'Mock Governance %s != Governance contract admin %s',
governance.owner,
governanceContractAdmin
);
revert();
}
profileCreator = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProfileCreator')));
vm.label(profileCreator, 'ProfileCreator');
console.log('ProfileCreator: %s', profileCreator);
proxyAdminContractAdmin = json.readAddress(string(abi.encodePacked('.', targetEnv, '.ProxyAdminContractAdmin')));
vm.label(proxyAdminContractAdmin, 'ProxyAdminContractAdmin');
console.log('ProxyAdminContractAdmin: %s', proxyAdminContractAdmin);
hub = ILensHub(json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHubProxy'))));
vm.label(address(hub), 'LensHub');
console.log('Lens Hub Proxy: %s', address(hub));
handles = ILensHandles(json.readAddress(string(abi.encodePacked('.', targetEnv, '.LensHandles'))));
vm.label(address(handles), 'LensHandles');
console.log('Lens Handles: %s', address(handles));
tokenHandleRegistry = ITokenHandleRegistry(
json.readAddress(string(abi.encodePacked('.', targetEnv, '.TokenHandleRegistry')))
);
vm.label(address(tokenHandleRegistry), 'TokenHandleRegistry');
console.log('Token Handle Registry: %s', address(tokenHandleRegistry));
moduleRegistry = ModuleRegistry(json.readAddress(string(abi.encodePacked('.', targetEnv, '.ModuleRegistry'))));
vm.label(address(moduleRegistry), 'ModuleRegistry');
console.log('Module Registry: %s', address(moduleRegistry));
governanceContract = Governance(
json.readAddress(string(abi.encodePacked('.', targetEnv, '.GovernanceContract')))
);
vm.label(address(governanceContract), 'GovernanceContract');
console.log('Governance Contract: %s', address(governanceContract));
}
function _interact() internal {
vm.startBroadcast(deployer.ownerPk);
ProfileCreationProxy temporarilyCreationProxy = new ProfileCreationProxy({
owner: deployer.owner,
hub: address(hub),
lensHandles: address(handles),
tokenHandleRegistry: address(tokenHandleRegistry)
});
vm.stopBroadcast();
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(temporarilyCreationProxy), true);
vm.stopBroadcast();
vm.startBroadcast(deployer.ownerPk);
(uint256 firstProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'firstprofile'
});
(uint256 secondProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'secondprofile'
});
(uint256 anonymousProfileId, ) = temporarilyCreationProxy.proxyCreateProfileWithHandle({
createProfileParams: Types.CreateProfileParams({
to: deployer.owner,
followModule: address(0),
followModuleInitData: ''
}),
handle: 'annoymouse'
});
saveValue('AnonymousProfileId', vm.toString(anonymousProfileId));
// set DE to publicActProxy
hub.changeDelegatedExecutorsConfig({
delegatorProfileId: anonymousProfileId,
delegatedExecutors: _toAddressArray(address(publicActProxy)),
approvals: _toBoolArray(true)
});
hub.follow({
followerProfileId: firstProfileId,
idsOfProfilesToFollow: _toUint256Array(secondProfileId),
followTokenIds: _toUint256Array(0),
datas: _toBytesArray('')
});
hub.post(
Types.PostParams({
profileId: firstProfileId,
contentURI: 'ipfs://HelloWorld',
actionModules: _emptyAddressArray(),
actionModulesInitDatas: _emptyBytesArray(),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// unfollow
hub.unfollow({unfollowerProfileId: firstProfileId, idsOfProfilesToUnfollow: _toUint256Array(secondProfileId)});
FeeConfig memory feeConfig = FeeConfig({
currency: 0x2058A9D7613eEE744279e3856Ef0eAda5FCbaA7e,
amount: 69000000,
recipient: address(0xcB6C7b2E340D50701d45d55507f19A5cE5d72330)
});
// set a follow module
hub.setFollowModule({
profileId: firstProfileId,
followModule: address(feeFollowModule),
followModuleInitData: abi.encode(feeConfig)
});
// set metadata
hub.setProfileMetadataURI({profileId: firstProfileId, metadataURI: 'ipfs://TestingMetadataURI'});
BaseFeeCollectModuleInitData memory collectModuleInitData = BaseFeeCollectModuleInitData({
amount: 0,
collectLimit: 69,
currency: address(0),
referralFee: 2500,
followerOnly: false,
endTimestamp: 0,
recipient: address(0xcB6C7b2E340D50701d45d55507f19A5cE5d72330)
});
// comment with open action
hub.comment(
Types.CommentParams({
profileId: firstProfileId,
contentURI: 'ipfs://testCommentURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: '',
actionModules: _toAddressArray(address(collectPublicationAction)),
actionModulesInitDatas: _toBytesArray(
abi.encode(simpleFeeCollectModule, abi.encode(collectModuleInitData))
),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// collect it
hub.act(
Types.PublicationActionParams({
publicationActedProfileId: firstProfileId,
publicationActedId: 2,
actorProfileId: firstProfileId,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
actionModuleAddress: address(collectPublicationAction),
actionModuleData: abi.encode(
address(0x1A1cDf59C94a682a067fA2D288C2167a8506abd7),
abi.encode(address(0), 0)
)
})
);
// mirror
hub.mirror(
Types.MirrorParams({
profileId: firstProfileId,
metadataURI: 'ipfs://testMirrorURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: ''
})
);
// quote (all of the same one)
hub.quote(
Types.QuoteParams({
profileId: firstProfileId,
contentURI: 'ipfs://testQuoteURI',
pointedProfileId: firstProfileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referenceModuleData: '',
actionModules: _emptyAddressArray(),
actionModulesInitDatas: _emptyBytesArray(),
referenceModule: address(0),
referenceModuleInitData: ''
})
);
// block
hub.setBlockStatus({
byProfileId: firstProfileId,
idsOfProfilesToSetBlockStatus: _toUint256Array(secondProfileId),
blockStatus: _toBoolArray(true)
});
// unblock
hub.setBlockStatus({
byProfileId: firstProfileId,
idsOfProfilesToSetBlockStatus: _toUint256Array(secondProfileId),
blockStatus: _toBoolArray(false)
});
// set random address for profile manager
hub.changeDelegatedExecutorsConfig({
delegatorProfileId: firstProfileId,
delegatedExecutors: _toAddressArray(address(0x1A1cDf59C94a682a067fA2D288C2167a8506abd7)),
approvals: _toBoolArray(true)
});
// unset profile guardian
hub.DANGER__disableTokenGuardian();
vm.stopBroadcast();
vm.startBroadcast(governance.ownerPk);
governanceContract.lensHub_whitelistProfileCreator(address(temporarilyCreationProxy), false);
vm.stopBroadcast();
}
function run(string memory targetEnv_) external {
targetEnv = targetEnv_;
loadJson();
checkNetworkParams();
loadPrivateKeys();
loadBaseAddresses();
_interact();
}
}

View File

@@ -4,10 +4,20 @@ TARGET=$1
echo "Running Full Lens V2 Deployment on $TARGET environment"
bash script/run.sh LensV2UpgradeDeployment $TARGET
echo "Deploying Lens V2 Implementation and upgrade contracts..."
bash script/run.sh A_DeployLensV2Upgrade $TARGET
bash script/run.sh LensV1ChangeAdmins $TARGET s
echo "Deploying Lens V2 Periphery..."
bash script/run.sh B_DeployLensV2Periphery $TARGET
bash script/run.sh LensV1ToV2Upgrade $TARGET
echo "Changing Lens V1 Admins..."
bash script/run.sh C_ChangeLensV1Admins $TARGET s
bash script/run.sh LensV2DeployPeriphery $TARGET
echo "Performing Lens V2 Upgrade..."
bash script/run.sh D_PerformV2Upgrade $TARGET
echo "Running Governance Actions (whitelisting profile creator, registering currencies and modules)..."
bash script/run.sh E_GovernanceActions $TARGET
echo "Interacting with Lens V2..."
bash script/run.sh F_InteractWithLensV2 $TARGET

View File

@@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Types} from 'contracts/libraries/constants/Types.sol';
contract ArrayHelpers {
function testArrayHelpers() public {
// Prevents being counted in Foundry Coverage
}
function _emptyUint256Array() internal pure returns (uint256[] memory) {
uint256[] memory ret = new uint256[](0);
return ret;
}
function _emptyPubTypesArray() internal pure returns (Types.PublicationType[] memory) {
Types.PublicationType[] memory ret = new Types.PublicationType[](0);
return ret;
}
function _toUint256Array(uint256 n) internal pure returns (uint256[] memory) {
uint256[] memory ret = new uint256[](1);
ret[0] = n;
return ret;
}
function _toUint256Array(uint256 n0, uint256 n1) internal pure returns (uint256[] memory) {
uint256[] memory ret = new uint256[](2);
ret[0] = n0;
ret[1] = n1;
return ret;
}
function _emptyBytesArray() internal pure returns (bytes[] memory) {
bytes[] memory ret = new bytes[](0);
return ret;
}
function _toBytesArray(bytes memory b) internal pure returns (bytes[] memory) {
bytes[] memory ret = new bytes[](1);
ret[0] = b;
return ret;
}
function _toBytesArray(bytes memory b0, bytes memory b1) internal pure returns (bytes[] memory) {
bytes[] memory ret = new bytes[](2);
ret[0] = b0;
ret[1] = b1;
return ret;
}
function _toBoolArray(bool b) internal pure returns (bool[] memory) {
bool[] memory ret = new bool[](1);
ret[0] = b;
return ret;
}
function _toBoolArray(bool b0, bool b1) internal pure returns (bool[] memory) {
bool[] memory ret = new bool[](2);
ret[0] = b0;
ret[1] = b1;
return ret;
}
function _emptyAddressArray() internal pure returns (address[] memory) {
address[] memory ret = new address[](0);
return ret;
}
function _toAddressArray(address a) internal pure returns (address[] memory) {
address[] memory ret = new address[](1);
ret[0] = a;
return ret;
}
function _toAddressArray(address a0, address a1) internal pure returns (address[] memory) {
address[] memory ret = new address[](2);
ret[0] = a0;
ret[1] = a1;
return ret;
}
}

View File

@@ -52,8 +52,13 @@ if [[ "$CONFIRMATION" == "y" || "$CONFIRMATION" == "Y" ]]
then
echo "Broadcasting on-chain..."
FORGE_OUTPUT=$(forge script script/$SCRIPT_NAME.s.sol:$SCRIPT_NAME -s $CALLDATA --rpc-url $NETWORK --broadcast --legacy --skip test --ffi --slow -vv)
echo "$FORGE_OUTPUT"
# 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
else
echo "Deployment cancelled. Execution terminated."
exit 1