|
1 | 1 | import { DeployFunction } from "hardhat-deploy/types"; |
2 | 2 | import { HardhatRuntimeEnvironment } from "hardhat/types"; |
3 | 3 | import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre"; |
4 | | -import { FILL_DEADLINE_BUFFER, L2_ADDRESS_MAP, QUOTE_TIME_BUFFER, USDC, ZERO_ADDRESS } from "./consts"; |
| 4 | +import { |
| 5 | + EXPECTED_SAFE_ADDRESS, |
| 6 | + FILL_DEADLINE_BUFFER, |
| 7 | + L2_ADDRESS_MAP, |
| 8 | + QUOTE_TIME_BUFFER, |
| 9 | + USDC, |
| 10 | + ZERO_ADDRESS, |
| 11 | +} from "./consts"; |
5 | 12 | import { CHAIN_IDs, PRODUCTION_NETWORKS, TOKEN_SYMBOLS_MAP } from "../utils/constants"; |
6 | | -import { getOftEid, toWei } from "../utils/utils"; |
| 13 | +import { getOftEid, toWei, predictedSafe } from "../utils/utils"; |
| 14 | +import { getNodeUrl } from "../utils"; |
7 | 15 | import { getDeployedAddress } from "../src/DeploymentUtils"; |
| 16 | +import "@nomiclabs/hardhat-ethers"; |
| 17 | +import Safe from "@safe-global/protocol-kit"; |
8 | 18 |
|
9 | 19 | const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { |
10 | 20 | const { hubPool, hubChainId, spokeChainId } = await getSpokePoolDeploymentInfo(hre); |
@@ -53,7 +63,38 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { |
53 | 63 | // target address of the spoke pool. This is because the HubPool does not pass in the chainId when calling |
54 | 64 | // relayMessage() on the Adapter. Therefore, if Universal SpokePools share the same address, |
55 | 65 | // then a message designed to be sent to one chain could be sent to another's SpokePool. |
56 | | - await deployNewProxy("Universal_SpokePool", constructorArgs, initArgs); |
| 66 | + const { proxyAddress } = await deployNewProxy("Universal_SpokePool", constructorArgs, initArgs); |
| 67 | + |
| 68 | + if (!proxyAddress) { |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + const nodeUrl = getNodeUrl(spokeChainId); |
| 73 | + |
| 74 | + const protocolKit = await Safe.init({ |
| 75 | + provider: nodeUrl, |
| 76 | + predictedSafe, |
| 77 | + }); |
| 78 | + |
| 79 | + const existingProtocolKit = await protocolKit.connect({ |
| 80 | + safeAddress: EXPECTED_SAFE_ADDRESS, |
| 81 | + }); |
| 82 | + const isDeployed = await existingProtocolKit.isSafeDeployed(); |
| 83 | + |
| 84 | + if (!isDeployed) { |
| 85 | + throw new Error("Expected Safe address is not deployed, please deploy it first"); |
| 86 | + } |
| 87 | + |
| 88 | + const factory = await hre.ethers.getContractFactory("Universal_SpokePool"); |
| 89 | + const contract = factory.attach(proxyAddress); |
| 90 | + |
| 91 | + const owner = await contract.owner(); |
| 92 | + if (owner !== EXPECTED_SAFE_ADDRESS) { |
| 93 | + await (await contract.transferOwnership(EXPECTED_SAFE_ADDRESS)).wait(); |
| 94 | + console.log("Transferred ownership to Expected Safe address:", await contract.owner()); |
| 95 | + } else { |
| 96 | + console.log("Expected Safe address is already the owner of the Universal SpokePool"); |
| 97 | + } |
57 | 98 | }; |
58 | 99 | module.exports = func; |
59 | 100 | func.tags = ["UniversalSpokePool"]; |
0 commit comments