Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Make DiamondInit > init dynamically set networkName and fix CharityApplications modifiers error messages #236

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {AccountStorage} from "./../../storage.sol";
contract DiamondInit {
// You can add parameters to this function in order to pass in
// data to set your own state variables
function init(address owner, address registrar) external {
function init(address owner, address registrar, string memory networkName) external {
// adding ERC165 data
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
ds.supportedInterfaces[type(IERC165).interfaceId] = true;
Expand All @@ -39,7 +39,7 @@ contract DiamondInit {

state.config.owner = owner;
state.config.registrarContract = registrar;
state.config.networkName = "Polygon";
state.config.networkName = networkName;
state.config.nextAccountId = 1;

// add your own state variables
Expand Down
10 changes: 7 additions & 3 deletions contracts/core/accounts/scripts/deploy/cutDiamond.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {DiamondCutFacet__factory, DiamondInit} from "typechain-types";
import {logger} from "utils";

import {getAxlNetworkName, logger} from "utils";
import {FacetCut} from "./types";

export default async function cutDiamond(
Expand All @@ -16,8 +15,13 @@ export default async function cutDiamond(
) {
logger.out("Cutting the Diamond with new facets...");

const networkName = await getAxlNetworkName(hre);
const diamondCut = DiamondCutFacet__factory.connect(address, admin);
const calldata = diamondInit.interface.encodeFunctionData("init", [owner, registrar]);
const calldata = diamondInit.interface.encodeFunctionData("init", [
owner,
registrar,
networkName,
]);

const cuts = facetCuts.map((x) => x.cut);
const tx = await diamondCut.diamondCut(cuts, diamondInit.address, calldata);
Expand Down
5 changes: 2 additions & 3 deletions contracts/core/registrar/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Deployment,
getChainId,
getContractName,
getNetworkNameFromChainId,
getAxlNetworkName,
logger,
updateAddresses,
validateAddress,
Expand Down Expand Up @@ -37,8 +37,7 @@ export async function deployRegistrar(
logger.out("Deploying Registrar...");

try {
const chainId = await getChainId(hre);
const networkName = getNetworkNameFromChainId(chainId);
const networkName = await getAxlNetworkName(hre);

validateAddress(axelarGateway, "axelarGateway");
validateAddress(axelarGasService, "axelarGasService");
Expand Down
4 changes: 2 additions & 2 deletions contracts/multisigs/CharityApplications.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ contract CharityApplications is MultiSigGeneric, StorageApplications, ICharityAp
modifier proposalConfirmed(uint256 proposalId, address _owner) {
require(
proposalConfirmations[proposalId].confirmationsByOwner[_owner],
"Proposal is confirmed"
"Proposal is not confirmed"
);
_;
}

modifier proposalNotConfirmed(uint256 proposalId, address _owner) {
require(
!proposalConfirmations[proposalId].confirmationsByOwner[_owner],
"Proposal is not confirmed"
"Proposal is already confirmed"
);
_;
}
Expand Down
1 change: 0 additions & 1 deletion tasks/deploy/deployLocalRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {task} from "hardhat/config";
import {
confirmAction,
getAddresses,
getNetworkNameFromChainId,
getSigners,
isLocalNetwork,
logger,
Expand Down
5 changes: 2 additions & 3 deletions tasks/helpers/updateRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "typechain-types/contracts/core/registrar/interfaces/IRegistrar";
import {
NetworkConnectionAction,
getChainId,
getAxlNetworkName,
getNetworkNameFromChainId,
getSigners,
logger,
Expand All @@ -29,8 +29,7 @@ export async function updateRegistrarNetworkConnections(
networkName = getNetworkNameFromChainId(Number(networkInfo.chainId));
} else {
// we're updating this chains own network info and can safely lookup chain id
const chainId = await getChainId(hre);
networkName = getNetworkNameFromChainId(chainId);
networkName = await getAxlNetworkName(hre);
}

logger.out(`Updating Registrar network info for chain: ${networkName}`);
Expand Down
5 changes: 5 additions & 0 deletions utils/networkHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function getNetworkNameFromChainId(id: number): string {
return AxelarNetworks.get(id);
}

export async function getAxlNetworkName(hre: HardhatRuntimeEnvironment): Promise<string> {
const chainId = await getChainId(hre);
return AxelarNetworks.get(chainId);
}

export async function getChainId(hre: HardhatRuntimeEnvironment): Promise<number> {
const chainId = (await hre.ethers.provider.getNetwork()).chainId;
return chainId;
Expand Down