Skip to content

Commit 984cc71

Browse files
committed
deploy script: update transferOwnership
1 parent 5a29cd7 commit 984cc71

File tree

5 files changed

+104
-33
lines changed

5 files changed

+104
-33
lines changed

deploy/NFTXV3.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { deployInventoryStaking } from "./modules/InventoryStaking";
66
import { deployUniswapV3Periphery } from "./modules/UniswapV3Periphery";
77
import { deployNFTXRouter } from "./modules/NFTXRouter";
88
import { deployFeeDistributor } from "./modules/FeeDistributor";
9+
import { deployFailSafe } from "./modules/FailSafe";
910

1011
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
1112
const { vaultFactory } = await deployVaultFactory({ hre });
@@ -41,6 +42,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
4142
inventoryStaking,
4243
vaultFactory,
4344
});
45+
46+
const { failSafe } = await deployFailSafe({
47+
hre,
48+
inventoryStaking,
49+
vaultFactory,
50+
feeDistributor,
51+
nftxRouter,
52+
});
4453
};
4554
export default func;
4655
func.tags = ["NFTXV3"];

deploy/modules/FailSafe.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { getConfig } from "../utils";
3+
4+
export const deployFailSafe = async ({
5+
hre,
6+
inventoryStaking,
7+
vaultFactory,
8+
feeDistributor,
9+
nftxRouter,
10+
}: {
11+
hre: HardhatRuntimeEnvironment;
12+
inventoryStaking: string;
13+
vaultFactory: string;
14+
feeDistributor: string;
15+
nftxRouter: string;
16+
}) => {
17+
const { deploy, deployer } = await getConfig(hre);
18+
19+
const failSafe = await deploy("FailSafe", {
20+
args: [
21+
[
22+
{
23+
addr: inventoryStaking,
24+
lastLockId: 4,
25+
},
26+
{
27+
addr: vaultFactory,
28+
lastLockId: 0,
29+
},
30+
{
31+
addr: feeDistributor,
32+
lastLockId: 1,
33+
},
34+
{
35+
addr: nftxRouter,
36+
lastLockId: 4,
37+
},
38+
],
39+
],
40+
from: deployer,
41+
log: true,
42+
});
43+
44+
return { failSafe: failSafe.address };
45+
};

deploy/modules/FeeDistributor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ export const deployFeeDistributor = async ({
8383
}
8484

8585
return {
86-
feeDistributor,
86+
feeDistributor: feeDistributor.address,
8787
};
8888
};

deploy/scripts/TransferOwnership.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
import { HardhatRuntimeEnvironment, Network } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import { utils } from "ethers";
4-
import deployConfig from "../deployConfig";
3+
import { getConfig, getContract } from "../utils";
54

65
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7-
const { deployments, getNamedAccounts, network } = hre;
8-
const { deploy, execute } = deployments;
6+
const { execute, deployments, deployer, config } = await getConfig(hre);
97

10-
const { deployer } = await getNamedAccounts();
11-
const config = deployConfig[network.name];
12-
13-
// `transferOwnership`:
14-
if (!config.multisig) return;
8+
if (!config.multisig) {
9+
console.log("🚨 No multisig set");
10+
return;
11+
}
1512

1613
await Promise.all(
1714
[
1815
"DefaultProxyAdmin",
1916
"MarketplaceUniversalRouterZap",
17+
"MigratorZap",
18+
"FailSafe",
2019
"NFTXFeeDistributorV3",
2120
"NFTXInventoryStakingV3Upgradeable",
2221
"NFTXRouter",
23-
"NFTXVaultFactoryUpgradeable",
22+
"NFTXVaultFactoryUpgradeableV3",
2423
"NonfungiblePositionManager",
2524
"UniswapV3FactoryUpgradeable",
2625
].map(async (name) => {
27-
console.log(`Transferring ownership of ${name}...`);
28-
await execute(
29-
name,
30-
{ from: deployer },
31-
"transferOwnership",
32-
config.multisig
33-
);
34-
console.log(`Ownership of ${name} transferred`);
26+
const contract = await getContract(hre, name);
27+
const owner = await contract.owner();
28+
29+
if (owner.toLowerCase() === config.multisig.toLowerCase()) {
30+
console.log(`Ownership of ${name} already transferred`);
31+
} else {
32+
try {
33+
console.log(`⌛ Transferring ownership of ${name}...`);
34+
35+
await execute(
36+
name,
37+
{ from: deployer },
38+
"transferOwnership",
39+
config.multisig
40+
);
41+
42+
console.log(`✅ Ownership of ${name} transferred`);
43+
} catch (e) {
44+
console.log(`🚨 Failed to transfer ownership of ${name}`);
45+
console.log(e);
46+
}
47+
}
3548
})
3649
);
3750
};

deploy/utils/index.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,31 @@ export const getContract = async (
2727
hre: HardhatRuntimeEnvironment,
2828
contractName: string,
2929
// keeping this param and not using deployments.get() because it helps to see the module's dependencies on other contracts
30-
contractAddress: string
30+
// making optional for querying DefaultProxyAdmin
31+
contractAddress?: string
3132
) => {
33+
// this fails to read "DefaultProxyAdmin":
34+
/**
3235
const { deployments } = hre;
33-
3436
const artifact = await deployments.getArtifact(contractName);
3537
const contractFactory = await hre.ethers.getContractFactory(
3638
artifact.abi,
3739
artifact.bytecode
3840
);
3941
const contract = contractFactory.attach(contractAddress);
42+
*/
43+
44+
const contractDeployment = await getDeploymentFileByName(
45+
contractName,
46+
hre.network
47+
);
48+
const contract = (
49+
await hre.ethers.getContractFactory(
50+
contractDeployment.abi,
51+
contractDeployment.bytecode
52+
)
53+
).attach(contractAddress ?? contractDeployment.address);
54+
4055
return contract;
4156
};
4257

@@ -103,16 +118,7 @@ export const handleUpgradeDeploy = async ({
103118
}): Promise<Deployment> => {
104119
const { deploy, network, deployments } = await getConfig(hre);
105120

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);
121+
const defaultProxyAdminContract = await getContract(hre, "DefaultProxyAdmin");
116122

117123
// set the current owner of the proxy, in the deployOptions
118124
deployOptions.proxy = {
@@ -128,8 +134,6 @@ export const handleUpgradeDeploy = async ({
128134
await setImplementation(contractName, network);
129135
deployment = await deployments.get(contractName);
130136

131-
console.log(e);
132-
133137
console.warn(
134138
`[⚠️ NOTE!] call "upgrade" on DefaultProxyAdmin to upgrade the implementation for ${contractName}`
135139
);

0 commit comments

Comments
 (0)