Skip to content

Commit 5a29cd7

Browse files
committed
deploy modules: fix owner for proxy in deployOptions
1 parent 264cb13 commit 5a29cd7

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

deploy/utils/index.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DeployOptions, Deployment } from "hardhat-deploy/types";
33
import { promises as fs } from "fs";
44
import path from "path";
55
import { format } from "prettier";
6+
import { keccak256, toUtf8Bytes, defaultAbiCoder } from "ethers/lib/utils";
67
import deployConfig from "../deployConfig";
78

89
export const getConfig = async (hre: HardhatRuntimeEnvironment) => {
@@ -99,15 +100,35 @@ export const handleUpgradeDeploy = async ({
99100
hre: HardhatRuntimeEnvironment;
100101
contractName: string;
101102
deployOptions: DeployOptions;
102-
}): Promise<Deployment | undefined> => {
103-
const { deploy, network } = await getConfig(hre);
103+
}): Promise<Deployment> => {
104+
const { deploy, network, deployments } = await getConfig(hre);
105+
106+
const defaultProxyAdminDeployment = await getDeploymentFileByName(
107+
"DefaultProxyAdmin",
108+
network
109+
);
110+
const defaultProxyAdminContract = (
111+
await hre.ethers.getContractFactory(
112+
defaultProxyAdminDeployment.abi,
113+
defaultProxyAdminDeployment.bytecode
114+
)
115+
).attach(defaultProxyAdminDeployment.address);
116+
117+
// set the current owner of the proxy, in the deployOptions
118+
deployOptions.proxy = {
119+
...(typeof deployOptions.proxy === "object" ? deployOptions.proxy : {}),
120+
owner: await defaultProxyAdminContract.owner(),
121+
};
104122

105123
let deployment: Deployment | undefined = undefined;
106124
try {
107125
deployment = await deploy(contractName, deployOptions);
108126
} catch (e) {
109127
// update the deployment file for correct implementation address
110128
await setImplementation(contractName, network);
129+
deployment = await deployments.get(contractName);
130+
131+
console.log(e);
111132

112133
console.warn(
113134
`[⚠️ NOTE!] call "upgrade" on DefaultProxyAdmin to upgrade the implementation for ${contractName}`
@@ -117,6 +138,23 @@ export const handleUpgradeDeploy = async ({
117138
return deployment;
118139
};
119140

141+
const getEIP1967ProxyOwner = async (
142+
hre: HardhatRuntimeEnvironment,
143+
contractName: string
144+
) => {
145+
const khash = keccak256(toUtf8Bytes(`eip1967.proxy.admin`));
146+
const num = BigInt(khash);
147+
const storageSlot = num - BigInt(1);
148+
149+
const provider = hre.ethers.provider;
150+
const res = await provider.getStorageAt(contractName, storageSlot);
151+
152+
const owner: string = defaultAbiCoder.decode(["address"], res)[0];
153+
console.log({ owner });
154+
155+
return owner;
156+
};
157+
120158
export const setImplementation = async (
121159
contractName: string,
122160
network: Network
@@ -130,7 +168,10 @@ export const setImplementation = async (
130168
contract.implementation = contractImplementation.address;
131169

132170
await fs.writeFile(
133-
path.join(__dirname, `./deployments/${network.name}/${contractName}.json`),
171+
path.join(
172+
__dirname,
173+
`../../deployments/${network.name}/${contractName}.json`
174+
),
134175
format(JSON.stringify(contract), {
135176
semi: false,
136177
parser: "json",
@@ -146,7 +187,10 @@ export const getDeploymentFileByName = async (
146187
) => {
147188
return JSON.parse(
148189
await fs.readFile(
149-
path.join(__dirname, `./deployments/${network.name}/${fileName}.json`),
190+
path.join(
191+
__dirname,
192+
`../../deployments/${network.name}/${fileName}.json`
193+
),
150194
"utf8"
151195
)
152196
);

hardhat.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ const config: HardhatUserConfig = {
126126
timeout: 600000,
127127
},
128128
mainnet: {
129-
url: `https://rpc.nftx.xyz`,
129+
url: process.env.MAINNET_RPC_URL!,
130130
accounts: [process.env.DEPLOYER_PRIVATE_KEY!],
131-
timeout: 60000,
131+
timeout: 600000,
132132
},
133133
arbitrum: {
134134
url: `https://arb-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_ARBITRUM_API_KEY}`,

0 commit comments

Comments
 (0)