Skip to content

Commit

Permalink
proxy mock
Browse files Browse the repository at this point in the history
  • Loading branch information
hashxtree committed Dec 26, 2024
1 parent b87f497 commit a818ea0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contracts/mock/ProxyMock.sol
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 {}
}
1 change: 1 addition & 0 deletions scripts/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './teller-mock';
export * from './teller-depositor';
export * from './partner-vault';
export * from './timelock';
export * from './proxy-mock';
58 changes: 58 additions & 0 deletions scripts/deployments/proxy-mock.ts
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 };
});

0 comments on commit a818ea0

Please sign in to comment.