Skip to content

Commit

Permalink
feat: create the proposal creation call information to the script
Browse files Browse the repository at this point in the history
  • Loading branch information
clauBv23 committed Feb 7, 2025
1 parent 0903be1 commit 2583128
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
112 changes: 111 additions & 1 deletion packages/contracts/scripts/generate-proposal-json.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -8,6 +11,12 @@ interface Action {
description: string;
}

interface ProposalAction {
to: string;
value: number;
data: string;
}

const deployedContractsPath = path.join(
__dirname,
'../deployed_contracts.json'
Expand All @@ -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
Expand Down Expand Up @@ -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();
3 changes: 3 additions & 0 deletions packages/contracts/src/test/Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 2583128

Please sign in to comment.