Remove GovernorCompatibilyBravo and add simpler GovernorStorage (#4360)

Co-authored-by: Ernesto García <ernestognw@gmail.com>
Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-08-03 17:51:07 +02:00
committed by GitHub
parent d39df78f6c
commit 21716722ad
27 changed files with 755 additions and 1259 deletions

View File

@ -1,17 +1,16 @@
const { rlp } = require('ethereumjs-util');
const RLP = require('rlp');
function computeCreateAddress(deployer, nonce) {
return web3.utils.toChecksumAddress(web3.utils.sha3(rlp.encode([deployer.address ?? deployer, nonce])).slice(-40));
return web3.utils.toChecksumAddress(web3.utils.sha3(RLP.encode([deployer.address ?? deployer, nonce])).slice(-40));
}
function computeCreate2Address(saltHex, bytecode, deployer) {
return web3.utils.toChecksumAddress(
web3.utils
.sha3(
'0x' +
['ff', deployer.address ?? deployer, saltHex, web3.utils.soliditySha3(bytecode)]
.map(x => x.replace(/0x/, ''))
.join(''),
`0x${['ff', deployer.address ?? deployer, saltHex, web3.utils.soliditySha3(bytecode)]
.map(x => x.replace(/0x/, ''))
.join('')}`,
)
.slice(-40),
);

View File

@ -1,3 +1,4 @@
const { web3 } = require('hardhat');
const { forward } = require('../helpers/time');
const { ProposalState } = require('./enums');
@ -15,6 +16,9 @@ function concatOpts(args, opts = null) {
return opts ? args.concat(opts) : args;
}
const timelockSalt = (address, descriptionHash) =>
'0x' + web3.utils.toBN(address).shln(96).xor(web3.utils.toBN(descriptionHash)).toString(16, 64);
class GovernorHelper {
constructor(governor, mode = 'blocknumber') {
this.governor = governor;
@ -245,4 +249,5 @@ function proposalStatesToBitMap(proposalStates, options = {}) {
module.exports = {
GovernorHelper,
proposalStatesToBitMap,
timelockSalt,
};