Make TransparentUpgradeableProxy deploy its ProxyAdmin and optimize proxy interfaces (#4382)
Co-authored-by: Francisco <fg@frang.io> Co-authored-by: Eric Lau <ericglau@outlook.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
14
test/helpers/account.js
Normal file
14
test/helpers/account.js
Normal file
@ -0,0 +1,14 @@
|
||||
const { web3 } = require('hardhat');
|
||||
const { impersonateAccount, setBalance } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
// Hardhat default balance
|
||||
const DEFAULT_BALANCE = web3.utils.toBN('10000000000000000000000');
|
||||
|
||||
async function impersonate(account, balance = DEFAULT_BALANCE) {
|
||||
await impersonateAccount(account);
|
||||
await setBalance(account, balance);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
impersonate,
|
||||
};
|
||||
23
test/helpers/create.js
Normal file
23
test/helpers/create.js
Normal file
@ -0,0 +1,23 @@
|
||||
const { rlp } = require('ethereumjs-util');
|
||||
|
||||
function computeCreateAddress(deployer, nonce) {
|
||||
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(''),
|
||||
)
|
||||
.slice(-40),
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
computeCreateAddress,
|
||||
computeCreate2Address,
|
||||
};
|
||||
@ -1,11 +0,0 @@
|
||||
function computeCreate2Address(saltHex, bytecode, deployer) {
|
||||
return web3.utils.toChecksumAddress(
|
||||
`0x${web3.utils
|
||||
.sha3(`0x${['ff', deployer, saltHex, web3.utils.soliditySha3(bytecode)].map(x => x.replace(/0x/, '')).join('')}`)
|
||||
.slice(-40)}`,
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
computeCreate2Address,
|
||||
};
|
||||
@ -1,3 +1,5 @@
|
||||
const { getStorageAt, setStorageAt } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const ImplementationLabel = 'eip1967.proxy.implementation';
|
||||
const AdminLabel = 'eip1967.proxy.admin';
|
||||
const BeaconLabel = 'eip1967.proxy.beacon';
|
||||
@ -7,15 +9,25 @@ function labelToSlot(label) {
|
||||
}
|
||||
|
||||
function getSlot(address, slot) {
|
||||
return web3.eth.getStorageAt(
|
||||
return getStorageAt(
|
||||
web3.utils.isAddress(address) ? address : address.address,
|
||||
web3.utils.isHex(slot) ? slot : labelToSlot(slot),
|
||||
);
|
||||
}
|
||||
|
||||
function setSlot(address, slot, value) {
|
||||
const hexValue = web3.utils.isHex(value) ? value : web3.utils.toHex(value);
|
||||
|
||||
return setStorageAt(
|
||||
web3.utils.isAddress(address) ? address : address.address,
|
||||
web3.utils.isHex(slot) ? slot : labelToSlot(slot),
|
||||
web3.utils.padLeft(hexValue, 64),
|
||||
);
|
||||
}
|
||||
|
||||
async function getAddressInSlot(address, slot) {
|
||||
const slotValue = await getSlot(address, slot);
|
||||
return web3.utils.toChecksumAddress(slotValue.substr(-40));
|
||||
return web3.utils.toChecksumAddress(slotValue.substring(slotValue.length - 40));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@ -25,6 +37,7 @@ module.exports = {
|
||||
ImplementationSlot: labelToSlot(ImplementationLabel),
|
||||
AdminSlot: labelToSlot(AdminLabel),
|
||||
BeaconSlot: labelToSlot(BeaconLabel),
|
||||
setSlot,
|
||||
getSlot,
|
||||
getAddressInSlot,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user