Skip to content

Commit

Permalink
A few more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed Jan 27, 2025
1 parent 4b89a10 commit 6e1f249
Showing 1 changed file with 77 additions and 79 deletions.
156 changes: 77 additions & 79 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,77 @@ for (let i = 0; i <= 10; i++) {
privateKeys.push(wallet.privateKey);
}

const getDeployerAddressOrIndex = (fallbackAccountIndex = 0) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}
return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.deployer || MAINNET_DEPLOYER
);
};

const getGovernorAddressOrIndex = (fallbackAccountIndex = 1) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.governor || MAINNET_GOVERNOR
);
};

const getStrategistAddressOrIndex = (fallbackAccountIndex = 2) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.strategist || MAINNET_STRATEGIST
);
};

const getTimelockAddress = () => {
if (process.env.FORK !== "true") {
return ethers.constants.AddressZero;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.timelock || ethers.constants.AddressZero
);
};

const getDeployTags = () => {
const tags =
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.tags || [];

return { tags };
};

// Define network configurations
const networkConfigs = [
{
Expand Down Expand Up @@ -240,22 +311,23 @@ const networks = networkConfigs.reduce((acc, { name, networkConfig }) => {
return acc;
}, {});

const { provider, chainId } = getHardhatNetworkProperties();
const forkBlockNumber = adjustTheForkBlockNumber();

networks.hardhat = {
accounts: { mnemonic },
blockGasLimit: 1000000000,
allowUnlimitedContractSize: true,
chainId: getHardhatNetworkProperties().chainId,
chainId,
...getDeployTags(),
...(isForkTest
? {
timeout: 0,
initialBaseFeePerGas: 0,
forking: {
enabled: true,
url: getHardhatNetworkProperties().provider,
blockNumber: adjustTheForkBlockNumber()
? parseInt(adjustTheForkBlockNumber())
: undefined,
url: provider,
blockNumber: forkBlockNumber ? parseInt(forkBlockNumber) : undefined,
timeout: 0,
},
}
Expand All @@ -268,7 +340,6 @@ networks.hardhat = {

networks.localhost = {
timeout: 0,
...getDeployTags(),
};

// Account tasks.
Expand All @@ -287,79 +358,6 @@ const paths = {
cache: process.env.HARDHAT_CACHE_DIR || undefined,
};

const { provider, chainId } = getHardhatNetworkProperties();

const getDeployerAddressOrIndex = (fallbackAccountIndex = 0) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}
return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.deployer || MAINNET_DEPLOYER
);
};

const getGovernorAddressOrIndex = (fallbackAccountIndex = 1) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.governor || MAINNET_GOVERNOR
);
};

const getStrategistAddressOrIndex = (fallbackAccountIndex = 2) => {
if (process.env.FORK !== "true") {
return fallbackAccountIndex;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.strategist || MAINNET_STRATEGIST
);
};

const getTimelockAddress = () => {
if (process.env.FORK !== "true") {
return ethers.constants.AddressZero;
}

return (
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.addresses?.timelock || ethers.constants.AddressZero
);
};

const getDeployTags = () => {
const tags =
networkConfigs.find(({ name }) => {
return (
process.env.NETWORK_NAME == name ||
process.env.FORK_NETWORK_NAME == name
);
})?.tags || [];

return { tags };
};

module.exports = {
solidity: {
version: "0.8.28",
Expand Down

0 comments on commit 6e1f249

Please sign in to comment.