diff --git a/packages/contracts/scripts/generate-proposal-json.ts b/packages/contracts/scripts/generate-proposal-json.ts index cf8247c86..af7a46f0f 100644 --- a/packages/contracts/scripts/generate-proposal-json.ts +++ b/packages/contracts/scripts/generate-proposal-json.ts @@ -1,3 +1,6 @@ +// note using version 1.3.0 due to is the one currently installed on the managing dao change it once it's upgraded +import {Multisig__factory as Multisig_v1_3_0__factory} from '../typechain/@aragon/osx-v1.3.0/plugins/governance/multisig/Multisig.sol'; +import {ethers} from 'ethers'; import * as fs from 'fs'; import * as path from 'path'; @@ -8,6 +11,12 @@ interface Action { description: string; } +interface ProposalAction { + to: string; + value: number; + data: string; +} + const deployedContractsPath = path.join( __dirname, '../deployed_contracts.json' @@ -19,6 +28,8 @@ const mergedProposalActionsPath = path.join( './merged-proposals.json' ); +const calldataPath = path.join(__dirname, './calldata.json'); + async function generateProposalJson() { try { // check if the file exists @@ -86,4 +97,103 @@ async function generateProposalJson() { } } -generateProposalJson(); +export function generateHexCalldataInJson(functionArgs: any[]) { + try { + const abi = Multisig_v1_3_0__factory.abi; + const iface = new ethers.utils.Interface(abi); + + const calldata = iface.encodeFunctionData('createProposal', functionArgs); + + const jsonOutput = { + functionName: 'createProposal', + functionArgs: functionArgs, + calldata: calldata, + }; + + // write the call information in the json file + fs.writeFileSync( + calldataPath, + JSON.stringify(jsonOutput, null, 2), + 'utf-8' + ); + console.log( + 'Successfully created calldata.json with the function call information!' + ); + } catch (error) { + console.error('Error encoding function data:', error); + throw error; + } +} + +function main() { + generateProposalJson(); + + // get the actions to send it to the createHexCalldata function + const jsonFile = JSON.parse( + fs.readFileSync(mergedProposalActionsPath, 'utf-8') + ); + + let args = []; + // push the metadata + if (!jsonFile.metadata) { + console.error('No metadata found in merged-proposals.json'); + return 1; + } + args.push(ethers.utils.hexlify(ethers.utils.toUtf8Bytes(jsonFile.metadata))); + + // push the actions + if (!jsonFile.managementDAOActions) { + console.error('No actions found in merged-proposals.json'); + return 1; + } + // remove the description from the actions + let proposalActions: ProposalAction[] = []; + jsonFile.managementDAOActions.forEach((action: Action) => { + proposalActions.push({ + to: action.to, + value: action.value, + data: action.data, + }); + }); + args.push(proposalActions); + + // push allow failure map + if ( + jsonFile.allowFailureMap === null || + jsonFile.allowFailureMap === undefined + ) { + console.error('No allow failure map found in merged-proposals.json'); + return 1; + } + args.push(jsonFile.allowFailureMap); + + // push approve proposal + if ( + jsonFile.approveProposal === null || + jsonFile.approveProposal === undefined + ) { + console.error('No approve proposal found in merged-proposals.json'); + return 1; + } + args.push(jsonFile.approveProposal); + + // push try execution + if (jsonFile.tryExecution === null || jsonFile.tryExecution === undefined) { + console.error('No try execution found in merged-proposals.json'); + return 1; + } + args.push(jsonFile.tryExecution); + + // push the start and end dates + if (!jsonFile.startDate || !jsonFile.endDate) { + console.error('No start or end date found in merged-proposals.json'); + return 1; + } + args.push(jsonFile.startDate); + args.push(jsonFile.endDate); + + // generate the calldata in a json file + generateHexCalldataInJson(args); +} + +main(); diff --git a/packages/contracts/src/test/Migration.sol b/packages/contracts/src/test/Migration.sol index 0eb78ee6c..49db5d76b 100644 --- a/packages/contracts/src/test/Migration.sol +++ b/packages/contracts/src/test/Migration.sol @@ -40,6 +40,9 @@ import {PluginRepoRegistry as PluginRepoRegistry_v1_3_0} from "@aragon/osx-v1.3. import {ENSSubdomainRegistrar as ENSSubdomainRegistrar_v1_0_0} from "@aragon/osx-v1.0.1/framework/utils/ens/ENSSubdomainRegistrar.sol"; import {ENSSubdomainRegistrar as ENSSubdomainRegistrar_v1_3_0} from "@aragon/osx-v1.3.0/framework/utils/ens/ENSSubdomainRegistrar.sol"; +// needed in the script to generate the managing dao proposal when upgrading +import {Multisig as Multisig_v1_3_0} from "@aragon/osx-v1.3.0/plugins/governance/multisig/Multisig.sol"; + // Integration Testing import {ProxyFactory} from "@aragon/osx-commons-contracts/src/utils/deployment/ProxyFactory.sol";