-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
contract ProxyMock is Initializable { | ||
|
||
/// @dev https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize() external initializer {} | ||
} |
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,58 @@ | ||
import { task } from 'hardhat/config'; | ||
import { DEFAULT_PROXY_FACTORY } from '../helpers/constants'; | ||
import { getProxyFactoryAt, getProxySalt, verify } from '../helpers'; | ||
|
||
/* | ||
* After deployment: | ||
* 1. Set initial validator set | ||
*/ | ||
|
||
task('deploy-proxy-mock', 'Deploys ProxyMock') | ||
.addParam('ledgerNetwork', 'The network name of ledger', 'mainnet') | ||
.addParam( | ||
'proxyFactoryAddr', | ||
'The ProxyFactory address', | ||
DEFAULT_PROXY_FACTORY | ||
) | ||
.addParam('contractName', 'The name of contract to be mocked') | ||
.addParam('admin', 'Admin of proxy') | ||
.setAction(async (taskArgs, hre) => { | ||
const { ledgerNetwork, admin, proxyFactoryAddr, contractName } = | ||
taskArgs; | ||
|
||
const factory = await getProxyFactoryAt(hre.ethers, proxyFactoryAddr); | ||
const saltHash = getProxySalt(hre.ethers, ledgerNetwork, contractName); | ||
|
||
const impl = await hre.ethers.deployContract('ProxyMock'); | ||
await impl.waitForDeployment(); | ||
|
||
const data = impl.interface.encodeFunctionData('initialize'); | ||
|
||
const tx = await factory.createTransparentProxy( | ||
await impl.getAddress(), | ||
admin, | ||
data, | ||
saltHash | ||
); | ||
await tx.wait(); | ||
|
||
const proxy = await factory.getDeployed(saltHash); | ||
console.log('Proxy address:', proxy); | ||
|
||
const proxyAdmin = await hre.upgrades.erc1967.getAdminAddress(proxy); | ||
console.log('Proxy admin:', proxyAdmin); | ||
|
||
await verify(run, await impl.getAddress()); | ||
await verify(run, proxyAdmin, { | ||
contract: | ||
'@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol:ProxyAdmin', | ||
constructorArguments: [admin], | ||
}); | ||
await verify(run, proxy, { | ||
contract: | ||
'@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy', | ||
constructorArguments: [await impl.getAddress(), admin, data], | ||
}); | ||
|
||
return { proxy, proxyAdmin }; | ||
}); |