Skip to content

Commit

Permalink
Merge pull request DMDcoin#250 from axel-muller/get-contract-upgrade-…
Browse files Browse the repository at this point in the history
…calldata

task to get transaction calldata to upgrade core contracts using DAO
  • Loading branch information
SurfingNerd authored Oct 14, 2024
2 parents 5f18a74 + 99e6816 commit eee4cc3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'solidity-docgen';
import 'hardhat-tracer';

import './tasks/make_spec';
import './tasks/getContractUpgradeCalldata';


const getMnemonic = () => {
Expand Down
57 changes: 57 additions & 0 deletions tasks/getContractUpgradeCalldata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { task, types } from 'hardhat/config';
import { attachProxyAdminV5 } from '@openzeppelin/hardhat-upgrades/dist/utils';

let KnownContracts = new Map<string, string>([
["ValidatorSetHbbft", "0x1000000000000000000000000000000000000001"],
["BlockRewardHbbft", "0x2000000000000000000000000000000000000001"],
["RandomHbbft", "0x3000000000000000000000000000000000000001"],
["TxPermissionHbbft", "0x4000000000000000000000000000000000000001"],
["CertifierHbbft", "0x5000000000000000000000000000000000000001"],
["KeyGenHistory", "0x7000000000000000000000000000000000000001"],
["StakingHbbft", "0x1100000000000000000000000000000000000001"],
["ConnectivityTrackerHbbft", "0x1200000000000000000000000000000000000001"],
["BonusScoreSystem", "0x1300000000000000000000000000000000000001"],
]);


task("getUpgradeCalldata", "Get contract upgrade calldata to use in DAO proposal")
.addParam("contract", "The core contract address to upgrade")
.addOptionalParam("impl", "Address of new core contract implementation", undefined, types.string)
.setAction(async (taskArgs, hre) => {
const { contract, impl } = taskArgs;

if (!KnownContracts.has(contract)) {
throw new Error(`${contract} is unknown`);
}

const proxyAddress = KnownContracts.get(contract)!;

let implementationAddress: string = impl;
if (impl == undefined) {
const [deployer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory(contract, deployer);

const result = await hre.upgrades.deployImplementation(
contractFactory,
{
getTxResponse: false,
redeployImplementation: 'always',
}
);
implementationAddress = result as string;
}

const proxyAdminAddress = await hre.upgrades.erc1967.getAdminAddress(proxyAddress);

const proxyAdmin = await attachProxyAdminV5(hre, proxyAdminAddress);

const calldata = proxyAdmin.interface.encodeFunctionData("upgradeAndCall", [
proxyAddress,
implementationAddress,
hre.ethers.hexlify(new Uint8Array()),
]);

console.log("contract:", contract);
console.log("calldata:", calldata);
console.log(" target:", proxyAdminAddress);
});
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './make_spec.ts'
import './getContractUpgradeCalldata.ts'

0 comments on commit eee4cc3

Please sign in to comment.