Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
olegkron committed Sep 17, 2024
1 parent d06db69 commit 7cf553c
Show file tree
Hide file tree
Showing 55 changed files with 567 additions and 509 deletions.
11 changes: 1 addition & 10 deletions packages/hardhat/constants/CLFSecrets.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { getEnvVar } from "../utils/getEnvVar";

type envString = string | undefined;
export type CLFSecrets = {
MESSENGER_0_PRIVATE_KEY: envString;
MESSENGER_1_PRIVATE_KEY: envString;
MESSENGER_2_PRIVATE_KEY: envString;
POOL_MESSENGER_0_PRIVATE_KEY: envString;
INFURA_API_KEY: envString;
ALCHEMY_API_KEY: envString;
};
import { CLFSecrets } from "../types/CLFSecrets";

const secrets: CLFSecrets = {
MESSENGER_0_PRIVATE_KEY: getEnvVar("MESSENGER_0_PRIVATE_KEY"),
Expand Down
9 changes: 3 additions & 6 deletions packages/hardhat/constants/CNetworks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Purpose: To have a single source of truth for networks across the project
import { type CNetwork, CNetworkNames } from "../types/CNetwork";
import { type CNetwork, CNetworkNames, NetworkType } from "../types/CNetwork";
import { HardhatNetworkUserConfig } from "hardhat/src/types/config";
import {
arbitrum,
Expand All @@ -14,15 +14,12 @@ import {
sepolia,
} from "viem/chains";
import { urls } from "./rpcUrls";
import { getEnvVar } from "../utils/getEnvVar";

const DEFAULT_BLOCK_CONFIRMATIONS = 2;
const deployerPK = getEnvVar("DEPLOYER_PRIVATE_KEY");
const proxyDeployerPK = getEnvVar("PROXY_DEPLOYER_PRIVATE_KEY");
const deployerPK = process.env.DEPLOYER_PRIVATE_KEY;
const proxyDeployerPK = process.env.PROXY_DEPLOYER_PRIVATE_KEY;
const saveDeployments = false;

export type NetworkType = "mainnet" | "testnet";

export const networkTypes: Record<NetworkType, string> = {
mainnet: "mainnet",
testnet: "testnet",
Expand Down
42 changes: 10 additions & 32 deletions packages/hardhat/constants/deploymentVariables.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEnvVar } from "../utils/getEnvVar";
import { getEnvVar } from "../utils";
import type { WaitForTransactionReceiptParameters } from "viem/actions/public/waitForTransactionReceipt";
import { WriteContractParameters } from "viem";
import { EnvPrefixes } from "../types/deploymentVariables";

export const messengers: string[] = [
getEnvVar("MESSENGER_0_ADDRESS"),
Expand All @@ -12,7 +13,6 @@ export const poolMessengers: string[] = [
getEnvVar("POOL_MESSENGER_0_ADDRESS"),
getEnvVar("POOL_MESSENGER_0_ADDRESS"),
];
// The address is the same on 4 chains: ARB,POL,BASE,AVAX. Can be deployed to others later using Lifi's Create3 Factory.

export const viemReceiptConfig: WaitForTransactionReceiptParameters = {
timeout: 0,
Expand All @@ -21,41 +21,13 @@ export const viemReceiptConfig: WaitForTransactionReceiptParameters = {
export const writeContractConfig: WriteContractParameters = {
gas: 3000000n, // 3M
};
export enum ProxyType {
export enum ProxyEnum {
infraProxy = "infraProxy",
parentPoolProxy = "parentPoolProxy",
childPoolProxy = "childPoolProxy",
}

export type IProxyType = keyof typeof ProxyType;

type ProxyDeploymentPrefixes = {
[key in ProxyType]: string;
};

export type DeploymentPrefixes = ProxyDeploymentPrefixes & {
infraProxyAdmin: string;
bridge: string;
dexSwap: string;
orchestrator: string;
parentPoolProxyAdmin: string;
parentPool: string;
childPoolProxyAdmin: string;
childPool: string;
automation: string;
lpToken: string;
create3Factory: string;
pause: string;
uniswapRouter: string;
poolMessenger0: string;
poolMessenger1: string;
poolMessenger2: string;
infraMessenger0: string;
infraMessenger1: string;
infraMessenger2: string;
};

export const deploymentPrefixes: DeploymentPrefixes = {
export const envPrefixes: EnvPrefixes = {
infraProxy: "CONCERO_INFRA_PROXY",
infraProxyAdmin: "CONCERO_INFRA_PROXY_ADMIN",
bridge: "CONCERO_BRIDGE",
Expand All @@ -72,4 +44,10 @@ export const deploymentPrefixes: DeploymentPrefixes = {
create3Factory: "CREATE3_FACTORY",
pause: "CONCERO_PAUSE",
uniswapRouter: "UNISWAP_ROUTER",
poolMessenger0: "POOL_MESSENGER_0_ADDRESS",
poolMessenger1: "POOL_MESSENGER_1_ADDRESS",
poolMessenger2: "POOL_MESSENGER_2_ADDRESS",
infraMessenger0: "MESSENGER_0_ADDRESS",
infraMessenger1: "MESSENGER_1_ADDRESS",
infraMessenger2: "MESSENGER_2_ADDRESS",
};
41 changes: 41 additions & 0 deletions packages/hardhat/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import secrets from "./CLFSecrets";
import CLFnetworks from "./CLFnetworks";
import CLFSimulationConfig from "./CLFSimulationConfig";
import CNetworks, { functionsGatewayUrls, networkEnvKeys, networkTypes } from "./CNetworks";
import {
envPrefixes,
messengers,
poolMessengers,
ProxyEnum,
viemReceiptConfig,
writeContractConfig,
} from "./deploymentVariables";
import { rpc, urls } from "./rpcUrls";
import { deployerTargetBalances, messengerTargetBalances } from "./targetBalances";
import { conceroChains, liveChains, mainnetChains, testnetChains } from "./liveChains";

export {
secrets,
CLFnetworks,
CLFSimulationConfig,
CNetworks,
networkTypes,
networkEnvKeys,
functionsGatewayUrls,
messengers,
poolMessengers,
viemReceiptConfig,
writeContractConfig,
ProxyEnum,
envPrefixes,
urls,
rpc,
messengerTargetBalances,
deployerTargetBalances,
liveChains,
mainnetChains,
testnetChains,
conceroChains,
};

export default CLFnetworks;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CNetwork } from "../../types/CNetwork";
import chains from "../../constants/CNetworks";
import { CNetwork } from "../types/CNetwork";
import chains from "./CNetworks";
import { ConceroChains } from "../types/chains";

// export const liveChains: CNetwork[] = [
// chains.baseSepolia,
Expand All @@ -11,19 +12,6 @@ import chains from "../../constants/CNetworks";

export const liveChains: CNetwork[] = [chains.polygon, chains.base, chains.arbitrum, chains.avalanche];

export interface ConceroChains {
testnet: {
parentPool: CNetwork[];
childPool: CNetwork[];
infra: CNetwork[];
};
mainnet: {
parentPool: CNetwork[];
childPool: CNetwork[];
infra: CNetwork[];
};
}

export const conceroChains: ConceroChains = {
testnet: {
parentPool: [chains.baseSepolia],
Expand All @@ -37,14 +25,10 @@ export const conceroChains: ConceroChains = {
},
};

export const testnetChains: CNetwork[] = Array.from(new Set([
...conceroChains.testnet.parentPool,
...conceroChains.testnet.childPool,
...conceroChains.testnet.infra,
]));
export const testnetChains: CNetwork[] = Array.from(
new Set([...conceroChains.testnet.parentPool, ...conceroChains.testnet.childPool, ...conceroChains.testnet.infra]),
);

export const mainnetChains: CNetwork[] = Array.from(new Set([
...conceroChains.mainnet.parentPool,
...conceroChains.mainnet.childPool,
...conceroChains.mainnet.infra,
]));
export const mainnetChains: CNetwork[] = Array.from(
new Set([...conceroChains.mainnet.parentPool, ...conceroChains.mainnet.childPool, ...conceroChains.mainnet.infra]),
);
2 changes: 1 addition & 1 deletion packages/hardhat/constants/rpcUrls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { INFURA_API_KEY, ALCHEMY_API_KEY, BLAST_API_KEY, CHAINSTACK_API_KEY, TENDERLY_API_KEY } = process.env;

const rpc: Record<string, string> = {
export const rpc: Record<string, string> = {
arbitrum: `https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}`,
arbitrumSepolia: `https://arbitrum-sepolia.infura.io/v3/${INFURA_API_KEY}`,
base: `https://base-sepolia.infura.io/v3/${INFURA_API_KEY}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/01_ConceroFakePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chains from "../constants/CNetworks";
import CNetworks, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { getEnvVar } from "../utils";

interface ConstructorArgs {
linkToken?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/deploy/03_ConceroDexSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import CNetworks, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { messengers } from "../constants/deploymentVariables";
import { getEnvVar } from "../utils";
import { messengers } from "../constants";

const deployConceroDexSwap: (hre: HardhatRuntimeEnvironment) => Promise<void> = async function (
hre: HardhatRuntimeEnvironment,
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/deploy/04_ConceroBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import path from "path";
import fs from "fs";
import { getEnvVar } from "../utils/getEnvVar";
import { messengers } from "../constants/deploymentVariables";
import { getEnvVar } from "../utils";
import { messengers } from "../constants";

interface ConstructorArgs {
slotId?: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/deploy/05_ConceroOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import chains, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { messengers } from "../constants/deploymentVariables";
import { getEnvVar } from "../utils";
import { messengers } from "../constants";

const deployConceroOrchestrator: (hre: HardhatRuntimeEnvironment) => Promise<void> = async function (
hre: HardhatRuntimeEnvironment,
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/07_LPToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import CNetworks, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { getEnvVar } from "../utils";

interface ConstructorArgs {
parentProxyAddress?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/deploy/08_ChildPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import chains, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { poolMessengers } from "../constants/deploymentVariables";
import { getEnvVar } from "../utils";
import { poolMessengers } from "../constants";

interface ConstructorArgs {
conceroProxyAddress?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/deploy/09_ParentPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import chains, { networkEnvKeys } from "../constants/CNetworks";
import updateEnvVariable from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { poolMessengers } from "../constants/deploymentVariables";
import { getEnvVar } from "../utils";
import { poolMessengers } from "../constants";

interface ConstructorArgs {
parentProxyAddress?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat/deploy/10_ConceroProxyAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Deployment } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import CNetworks from "../constants/CNetworks";
import { updateEnvAddress } from "../utils/updateEnvVariable";
import { getEnvVar, updateEnvAddress } from "../utils";
import log from "../utils/log";
import { getEnvVar } from "../utils/getEnvVar";
import { type IProxyType } from "../constants/deploymentVariables";

import { IProxyType } from "../types/deploymentVariables";

const deployProxyAdmin: (hre: HardhatRuntimeEnvironment, proxyType: IProxyType) => Promise<void> = async function (
hre: HardhatRuntimeEnvironment,
Expand Down
3 changes: 2 additions & 1 deletion packages/hardhat/deploy/11_TransparentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import CNetworks from "../constants/CNetworks";
import { updateEnvAddress } from "../utils/updateEnvVariable";
import log from "../utils/log";
import { getEnvAddress } from "../utils/getEnvVar";
import { type IProxyType, writeContractConfig } from "../constants/deploymentVariables";
import { writeContractConfig } from "../constants/deploymentVariables";
import { IProxyType } from "../types/deploymentVariables";

const deployTransparentProxy: (hre: HardhatRuntimeEnvironment, proxyType: IProxyType) => Promise<void> =
async function (hre: HardhatRuntimeEnvironment, proxyType: IProxyType) {
Expand Down
7 changes: 3 additions & 4 deletions packages/hardhat/tasks/CLF/donSecrets/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import chains, { networkEnvKeys } from "../../../constants/CNetworks";
import secrets from "../../../constants/CLFSecrets";
import updateEnvVariable from "../../../utils/updateEnvVariable";
import { CNetwork } from "../../../types/CNetwork";
import { getEthersV5FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider";
import { getEthersV5FallbackSignerAndProvider } from "../../../utils";
import log, { err } from "../../../utils/log";
import listSecrets from "./list";
import { setDonHostedSecretsVersion } from "../../concero/deployInfra/setContractVariables";
import load from "../../../utils/load";
import { liveChains } from "../../concero/deployInfra/deployInfra";
import { liveChains } from "../../../constants";

// const path = require("path");

Expand Down Expand Up @@ -84,7 +83,7 @@ task("clf-donsecrets-upload", "Encrypts and uploads secrets to the DON")
const processNetwork = async (chain: CNetwork) => {
await upload([chain], slotid, ttl);
if (updatecontracts) {
const { abi } = await load("../artifacts/contracts/Concero.sol/Concero.json");
const { abi } = await import("../artifacts/contracts/Concero.sol/Concero.json");
await setDonHostedSecretsVersion(chain, parseInt(slotid), abi);
}
};
Expand Down
Loading

0 comments on commit 7cf553c

Please sign in to comment.