Skip to content

Commit af77be4

Browse files
committed
exported gnosis safe files for scheduledBatch and executeBatch
1 parent 5787b99 commit af77be4

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

contracts/utils/deploy.js

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,26 @@ async function useTransitionGovernance() {
936936
return guardianHasAccess;
937937
}
938938

939-
function buildAndWriteGnosisJson(targets, calldata, safeAddress) {
939+
function constructContractMethod(contract, functionSignature) {
940+
const functionFragment = contract.interface.getFunction(functionSignature);
941+
942+
const functionJson = JSON.parse(
943+
functionFragment.format(ethers.utils.FormatTypes.json)
944+
);
945+
return {
946+
inputs: functionJson.inputs,
947+
name: functionJson.name,
948+
payable: functionJson.payable,
949+
};
950+
}
951+
952+
function buildAndWriteGnosisJson(
953+
safeAddress,
954+
targets,
955+
contractMethods,
956+
contractInputsValues,
957+
name
958+
) {
940959
const json = {
941960
version: "1.0",
942961
chainId: "1",
@@ -951,16 +970,16 @@ function buildAndWriteGnosisJson(targets, calldata, safeAddress) {
951970
transactions: targets.map((target, i) => ({
952971
to: target,
953972
value: "0",
954-
data: calldata[i],
955-
contractMethod: null,
956-
contractInputValues: null,
973+
data: null,
974+
contractMethod: contractMethods[i],
975+
contractInputsValues: contractInputsValues[i],
957976
})),
958977
};
959978

960979
const fileName = path.join(
961980
__dirname,
962981
"..",
963-
Date.now().toString() + "-gov-tx.json"
982+
Date.now().toString() + `-${name}-gov-tx.json`
964983
);
965984

966985
fs.writeFileSync(fileName, JSON.stringify(json, undefined, 2));
@@ -999,18 +1018,32 @@ async function handleTransitionGovernance(propDesc, propArgs) {
9991018

10001019
const isScheduled = await timelock.isOperation(opHash);
10011020
const reduceTime = !isScheduled;
1021+
const delay = await timelock.getMinDelay();
10021022

10031023
if (!isScheduled) {
10041024
// Needs to be scheduled
1005-
const scheduleData = timelock.interface.encodeFunctionData(
1006-
"scheduleBatch(address[],uint256[],bytes[],bytes32,bytes32,uint256)",
1007-
[...args, await timelock.getMinDelay()]
1025+
1026+
const contractMethod = constructContractMethod(
1027+
timelock,
1028+
"scheduleBatch(address[],uint256[],bytes[],bytes32,bytes32,uint256)"
10081029
);
10091030

1031+
// construct contractInputsValues
1032+
const contractInputsValues = {
1033+
targets: JSON.stringify(propArgs[0]),
1034+
values: JSON.stringify(propArgs[1].map((arg) => arg.toString())),
1035+
payloads: JSON.stringify(payloads),
1036+
predecessor: args[3],
1037+
salt: args[4],
1038+
delay: delay.toString(),
1039+
};
1040+
10101041
buildAndWriteGnosisJson(
1042+
addresses.mainnet.Guardian,
10111043
[timelock.address],
1012-
[scheduleData],
1013-
addresses.mainnet.Guardian
1044+
[contractMethod],
1045+
[contractInputsValues],
1046+
"scheduleBatch"
10141047
);
10151048

10161049
if (reduceTime) {
@@ -1037,19 +1070,28 @@ async function handleTransitionGovernance(propDesc, propArgs) {
10371070
await advanceBlocks(2);
10381071
}
10391072

1040-
if (isScheduled) {
1041-
// Write execution data
1042-
const executeData = timelock.interface.encodeFunctionData(
1043-
"executeBatch(address[],uint256[],bytes[],bytes32,bytes32)",
1044-
[...args]
1045-
);
1073+
// Write execution data
1074+
const executionContractMethod = constructContractMethod(
1075+
timelock,
1076+
"executeBatch(address[],uint256[],bytes[],bytes32,bytes32)"
1077+
);
10461078

1047-
buildAndWriteGnosisJson(
1048-
[timelock.address],
1049-
[executeData],
1050-
addresses.mainnet.Guardian
1051-
);
1052-
}
1079+
// construct contractInputsValues
1080+
const executionContractInputsValues = {
1081+
targets: JSON.stringify(propArgs[0]),
1082+
values: JSON.stringify(propArgs[1].map((arg) => arg.toString())),
1083+
payloads: JSON.stringify(payloads),
1084+
predecessor: args[3],
1085+
salt: args[4],
1086+
};
1087+
1088+
buildAndWriteGnosisJson(
1089+
addresses.mainnet.Guardian,
1090+
[timelock.address],
1091+
[executionContractMethod],
1092+
[executionContractInputsValues],
1093+
"executeBatch"
1094+
);
10531095

10541096
log(`Executing batch on Timelock...`);
10551097
await timelock.connect(guradian).executeBatch(...args);

0 commit comments

Comments
 (0)