forked from DMDcoin/diamond-contracts-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DMDcoin#250 from axel-muller/get-contract-upgrade-…
…calldata task to get transaction calldata to upgrade core contracts using DAO
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './make_spec.ts' | ||
import './getContractUpgradeCalldata.ts' |