diff --git a/packages/hardhat/constants/CLFSecrets.ts b/packages/hardhat/constants/CLFSecrets.ts index bd0794f59..e131603ca 100644 --- a/packages/hardhat/constants/CLFSecrets.ts +++ b/packages/hardhat/constants/CLFSecrets.ts @@ -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"), diff --git a/packages/hardhat/constants/CNetworks.ts b/packages/hardhat/constants/cNetworks.ts similarity index 97% rename from packages/hardhat/constants/CNetworks.ts rename to packages/hardhat/constants/cNetworks.ts index fa971f3e9..2f701b981 100644 --- a/packages/hardhat/constants/CNetworks.ts +++ b/packages/hardhat/constants/cNetworks.ts @@ -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, @@ -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 = { mainnet: "mainnet", testnet: "testnet", @@ -51,7 +48,7 @@ export const functionsGatewayUrls = { testnet: ["https://01.functions-gateway.testnet.chain.link/", "https://02.functions-gateway.testnet.chain.link/"], }; -const CNetworks: Record = { +export const cNetworks: Record = { localhost: { accounts: [deployerPK, proxyDeployerPK], // mock CLF data @@ -378,4 +375,4 @@ const CNetworks: Record = { name: "avalanche", }, }; -export default CNetworks; +export default cNetworks; diff --git a/packages/hardhat/constants/deploymentVariables.ts b/packages/hardhat/constants/deploymentVariables.ts index 14812df71..83a18fc91 100644 --- a/packages/hardhat/constants/deploymentVariables.ts +++ b/packages/hardhat/constants/deploymentVariables.ts @@ -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"), @@ -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, @@ -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", @@ -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", }; diff --git a/packages/hardhat/constants/index.ts b/packages/hardhat/constants/index.ts new file mode 100644 index 000000000..7b47eb96e --- /dev/null +++ b/packages/hardhat/constants/index.ts @@ -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; diff --git a/packages/hardhat/tasks/concero/liveChains.ts b/packages/hardhat/constants/liveChains.ts similarity index 54% rename from packages/hardhat/tasks/concero/liveChains.ts rename to packages/hardhat/constants/liveChains.ts index 745e9c753..8810b3304 100644 --- a/packages/hardhat/tasks/concero/liveChains.ts +++ b/packages/hardhat/constants/liveChains.ts @@ -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, @@ -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], @@ -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]), +); diff --git a/packages/hardhat/constants/rpcUrls.ts b/packages/hardhat/constants/rpcUrls.ts index ec1edcd3f..3ffafdf77 100644 --- a/packages/hardhat/constants/rpcUrls.ts +++ b/packages/hardhat/constants/rpcUrls.ts @@ -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 = { +export const rpc: Record = { 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}`, diff --git a/packages/hardhat/deploy/ChildPool.ts b/packages/hardhat/deploy/ChildPool.ts index 2474fee8a..5d6495015 100644 --- a/packages/hardhat/deploy/ChildPool.ts +++ b/packages/hardhat/deploy/ChildPool.ts @@ -1,10 +1,10 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains, { networkEnvKeys } from "../constants/CNetworks"; +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; diff --git a/packages/hardhat/deploy/ConceroAutomation.ts b/packages/hardhat/deploy/ConceroAutomation.ts index 158da241e..6866fae1a 100644 --- a/packages/hardhat/deploy/ConceroAutomation.ts +++ b/packages/hardhat/deploy/ConceroAutomation.ts @@ -1,6 +1,6 @@ // import { Deployment } from "hardhat-deploy/types"; // import { HardhatRuntimeEnvironment } from "hardhat/types"; -// import chains, { networkEnvKeys } from "../constants/CNetworks"; +// import chains, { networkEnvKeys } from "../constants/cNetworks"; // import updateEnvVariable from "../utils/updateEnvVariable"; // import log from "../utils/log"; // import getHashSum from "../utils/getHashSum"; diff --git a/packages/hardhat/deploy/ConceroBridge.ts b/packages/hardhat/deploy/ConceroBridge.ts index 08e5e78f4..64fba5da9 100644 --- a/packages/hardhat/deploy/ConceroBridge.ts +++ b/packages/hardhat/deploy/ConceroBridge.ts @@ -1,12 +1,12 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains, { networkEnvKeys } from "../constants/CNetworks"; +import chains, { networkEnvKeys } from "../constants/cNetworks"; 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; diff --git a/packages/hardhat/deploy/ConceroDexSwap.ts b/packages/hardhat/deploy/ConceroDexSwap.ts index 75310c6a1..eb5d0fb92 100644 --- a/packages/hardhat/deploy/ConceroDexSwap.ts +++ b/packages/hardhat/deploy/ConceroDexSwap.ts @@ -1,10 +1,10 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import CNetworks, { networkEnvKeys } 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 { messengers } from "../constants/deploymentVariables"; +import { getEnvVar } from "../utils"; +import { messengers } from "../constants"; const deployConceroDexSwap: (hre: HardhatRuntimeEnvironment) => Promise = async function ( hre: HardhatRuntimeEnvironment, @@ -12,7 +12,7 @@ const deployConceroDexSwap: (hre: HardhatRuntimeEnvironment) => Promise = const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; const conceroProxyAddress = getEnvVar(`CONCERO_INFRA_PROXY_${networkEnvKeys[name]}`); diff --git a/packages/hardhat/deploy/ConceroFakePool.ts b/packages/hardhat/deploy/ConceroFakePool.ts index 5b99edf31..9225c48eb 100644 --- a/packages/hardhat/deploy/ConceroFakePool.ts +++ b/packages/hardhat/deploy/ConceroFakePool.ts @@ -1,10 +1,10 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains from "../constants/CNetworks"; -import CNetworks, { networkEnvKeys } from "../constants/CNetworks"; +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; @@ -16,7 +16,7 @@ const deployConceroPool: (hre: HardhatRuntimeEnvironment, constructorArgs?: Cons const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; const { linkToken, ccipRouter } = chains[name]; diff --git a/packages/hardhat/deploy/ConceroOrchestrator.ts b/packages/hardhat/deploy/ConceroOrchestrator.ts index fc830fa73..12133288a 100644 --- a/packages/hardhat/deploy/ConceroOrchestrator.ts +++ b/packages/hardhat/deploy/ConceroOrchestrator.ts @@ -1,10 +1,10 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains, { networkEnvKeys } from "../constants/CNetworks"; +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 = async function ( hre: HardhatRuntimeEnvironment, diff --git a/packages/hardhat/deploy/ConceroProxyAdmin.ts b/packages/hardhat/deploy/ConceroProxyAdmin.ts index 2a8e365b7..32dd73895 100644 --- a/packages/hardhat/deploy/ConceroProxyAdmin.ts +++ b/packages/hardhat/deploy/ConceroProxyAdmin.ts @@ -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 cNetworks from "../constants/cNetworks"; +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 = async function ( hre: HardhatRuntimeEnvironment, @@ -13,7 +13,7 @@ const deployProxyAdmin: (hre: HardhatRuntimeEnvironment, proxyType: IProxyType) const { proxyDeployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; const initialOwner = getEnvVar(`PROXY_DEPLOYER_ADDRESS`); diff --git a/packages/hardhat/deploy/LPToken.ts b/packages/hardhat/deploy/LPToken.ts index fb562a8b1..2c75eb119 100644 --- a/packages/hardhat/deploy/LPToken.ts +++ b/packages/hardhat/deploy/LPToken.ts @@ -1,9 +1,9 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import CNetworks, { networkEnvKeys } 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 { parentProxyAddress?: string; @@ -15,7 +15,7 @@ const deployLPToken: (hre: HardhatRuntimeEnvironment, constructorArgs?: Construc const { proxyDeployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; const defaultArgs = { parentProxyAddress: getEnvVar(`PARENT_POOL_PROXY_${networkEnvKeys[name]}`), diff --git a/packages/hardhat/deploy/ParentPool.ts b/packages/hardhat/deploy/ParentPool.ts index 42e5d4fd5..30df4ca46 100644 --- a/packages/hardhat/deploy/ParentPool.ts +++ b/packages/hardhat/deploy/ParentPool.ts @@ -1,11 +1,11 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains, { networkEnvKeys } from "../constants/CNetworks"; +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 { zeroAddress } from "viem"; +import { getEnvVar } from "../utils"; +import { poolMessengers } from "../constants"; interface ConstructorArgs { automationForwarder?: string; diff --git a/packages/hardhat/deploy/PauseDummy.ts b/packages/hardhat/deploy/PauseDummy.ts index 085c08352..97eaccd62 100644 --- a/packages/hardhat/deploy/PauseDummy.ts +++ b/packages/hardhat/deploy/PauseDummy.ts @@ -1,6 +1,6 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import CNetworks, { networkEnvKeys } from "../constants/CNetworks"; +import cNetworks, { networkEnvKeys } from "../constants/cNetworks"; import updateEnvVariable from "../utils/updateEnvVariable"; import log from "../utils/log"; @@ -10,7 +10,7 @@ const deployPauseDummy: (hre: HardhatRuntimeEnvironment) => Promise = asyn const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; console.log("Deploying...", "deployPauseDummy", name); diff --git a/packages/hardhat/deploy/TransparentProxy.ts b/packages/hardhat/deploy/TransparentProxy.ts index d74970cb9..925bbcfbd 100644 --- a/packages/hardhat/deploy/TransparentProxy.ts +++ b/packages/hardhat/deploy/TransparentProxy.ts @@ -1,17 +1,18 @@ import { Deployment } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import CNetworks from "../constants/CNetworks"; +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 = async function (hre: HardhatRuntimeEnvironment, proxyType: IProxyType) { const { proxyDeployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; const { name, live } = hre.network; - const networkType = CNetworks[name].type; + const networkType = cNetworks[name].type; const [initialImplementation, initialImplementationAlias] = getEnvAddress("pause", name); const [proxyAdmin, proxyAdminAlias] = getEnvAddress(`${proxyType}Admin`, name); diff --git a/packages/hardhat/hardhat.config.ts b/packages/hardhat/hardhat.config.ts index 952419e5e..c722ad97f 100644 --- a/packages/hardhat/hardhat.config.ts +++ b/packages/hardhat/hardhat.config.ts @@ -11,7 +11,7 @@ import "hardhat-contract-sizer"; import { HardhatUserConfig } from "hardhat/config"; import "solidity-coverage"; import "@chainlink/hardhat-chainlink"; -import CNetworks from "./constants/CNetworks"; +import cNetworks from "./constants/cNetworks"; import "./tasks"; import { setup as setupTenderly } from "@tenderly/hardhat-tenderly"; @@ -51,7 +51,7 @@ const config: HardhatUserConfig = { default: 1, }, }, - networks: CNetworks, + networks: cNetworks, etherscan: { apiKey: { avalancheFuji: "snowtrace", diff --git a/packages/hardhat/tasks/CLF/donSecrets/list.ts b/packages/hardhat/tasks/CLF/donSecrets/list.ts index 21b8f816b..e43c93700 100644 --- a/packages/hardhat/tasks/CLF/donSecrets/list.ts +++ b/packages/hardhat/tasks/CLF/donSecrets/list.ts @@ -1,5 +1,5 @@ import { SecretsManager } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { liveChains } from "../../concero/deployInfra/deployInfra"; diff --git a/packages/hardhat/tasks/CLF/donSecrets/upload.ts b/packages/hardhat/tasks/CLF/donSecrets/upload.ts index 391cfc964..ed3653a56 100644 --- a/packages/hardhat/tasks/CLF/donSecrets/upload.ts +++ b/packages/hardhat/tasks/CLF/donSecrets/upload.ts @@ -1,15 +1,14 @@ import { task, types } from "hardhat/config"; import { SecretsManager } from "@chainlink/functions-toolkit"; -import chains, { networkEnvKeys } from "../../../constants/CNetworks"; +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"); @@ -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); } }; diff --git a/packages/hardhat/tasks/CLF/subscriptions/accept.ts b/packages/hardhat/tasks/CLF/subscriptions/accept.ts index 8493d17e0..6cce69c00 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/accept.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/accept.ts @@ -1,5 +1,5 @@ import { task } from "hardhat/config"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import log from "../../../utils/log"; import { formatEther } from "viem"; diff --git a/packages/hardhat/tasks/CLF/subscriptions/add.ts b/packages/hardhat/tasks/CLF/subscriptions/add.ts index 75b46975a..c63190fc6 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/add.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/add.ts @@ -1,5 +1,5 @@ import { SubscriptionManager } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { task } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { CNetwork } from "../../../types/CNetwork"; diff --git a/packages/hardhat/tasks/CLF/subscriptions/fund.ts b/packages/hardhat/tasks/CLF/subscriptions/fund.ts index 006ada750..c0139557b 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/fund.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/fund.ts @@ -1,6 +1,6 @@ import { task } from "hardhat/config"; import { SubscriptionManager } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { formatEther } from "viem"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import log from "../../../utils/log"; diff --git a/packages/hardhat/tasks/CLF/subscriptions/info.ts b/packages/hardhat/tasks/CLF/subscriptions/info.ts index 90eb41928..c86de3de2 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/info.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/info.ts @@ -1,6 +1,6 @@ import { task } from "hardhat/config"; import { SubscriptionManager } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { formatEther } from "viem"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { getEthersV5FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider"; @@ -15,12 +15,16 @@ task( const hre: HardhatRuntimeEnvironment = require("hardhat"); const { name, live } = hre.network; - const {linkToken, functionsRouter, functionsSubIds} = chains[name]; + const { linkToken, functionsRouter, functionsSubIds } = chains[name]; - const subscriptionId = taskArgs.subid? parseInt(taskArgs.subid) : functionsSubIds[0]; + const subscriptionId = taskArgs.subid ? parseInt(taskArgs.subid) : functionsSubIds[0]; - const { signer } = await getEthersV5FallbackSignerAndProvider(name) - const sm = new SubscriptionManager({ signer, linkTokenAddress:linkToken, functionsRouterAddress: functionsRouter }); + const { signer } = await getEthersV5FallbackSignerAndProvider(name); + const sm = new SubscriptionManager({ + signer, + linkTokenAddress: linkToken, + functionsRouterAddress: functionsRouter, + }); await sm.initialize(); console.log(`Getting info for subscription ${subscriptionId}...`); diff --git a/packages/hardhat/tasks/CLF/subscriptions/remove.ts b/packages/hardhat/tasks/CLF/subscriptions/remove.ts index b7b9f62f6..5a85422a9 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/remove.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/remove.ts @@ -1,4 +1,4 @@ -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { task, types } from "hardhat/config"; import { SubscriptionManager, TransactionOptions } from "@chainlink/functions-toolkit"; diff --git a/packages/hardhat/tasks/CLF/subscriptions/timeout.ts b/packages/hardhat/tasks/CLF/subscriptions/timeout.ts index cb740e4f1..f6b40c95d 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/timeout.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/timeout.ts @@ -1,6 +1,6 @@ import { task, types } from "hardhat/config"; import { fetchRequestCommitment, SubscriptionManager, TransactionOptions } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { getEthersV6FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider"; diff --git a/packages/hardhat/tasks/CLF/subscriptions/transfer.ts b/packages/hardhat/tasks/CLF/subscriptions/transfer.ts index 6de82be45..3dc887dc9 100644 --- a/packages/hardhat/tasks/CLF/subscriptions/transfer.ts +++ b/packages/hardhat/tasks/CLF/subscriptions/transfer.ts @@ -1,6 +1,6 @@ import { task } from "hardhat/config"; import { SubscriptionManager, TransactionOptions } from "@chainlink/functions-toolkit"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { HardhatRuntimeEnvironment } from "hardhat/types"; diff --git a/packages/hardhat/tasks/CLF/unused/Functions-billing/transfer.ts b/packages/hardhat/tasks/CLF/unused/Functions-billing/transfer.ts index fd8c416ea..f0a3a1aab 100644 --- a/packages/hardhat/tasks/CLF/unused/Functions-billing/transfer.ts +++ b/packages/hardhat/tasks/CLF/unused/Functions-billing/transfer.ts @@ -7,7 +7,7 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("hardhat/config"); const functions_toolkit_1 = require("@chainlink/functions-toolkit"); -const CNetworks_1 = __importDefault(require("../../../../constants/CNetworks")); +const CNetworks_1 = __importDefault(require("../../../../constants/cNetworks")); (0, config_1.task)("clf-sub-transfer", "Request ownership of an Functions subscription be transferred to a new address") .addParam("subid", "Subscription ID") .addParam("newowner", "Address of the new owner") diff --git a/packages/hardhat/tasks/CLF/unused/Functions-consumer/request.ts b/packages/hardhat/tasks/CLF/unused/Functions-consumer/request.ts index aed4f0b66..ae7fe9339 100644 --- a/packages/hardhat/tasks/CLF/unused/Functions-consumer/request.ts +++ b/packages/hardhat/tasks/CLF/unused/Functions-consumer/request.ts @@ -13,7 +13,7 @@ // import networks from "../../../constants/CLFnetworks"; // import { HardhatRuntimeEnvironment } from "hardhat/types"; // -// import chains from "../../../constants/CNetworks"; +// import chains from "../../../constants/cNetworks"; // // const utils = require("../../utils"); // const chalk = require("chalk"); diff --git a/packages/hardhat/tasks/CLF/unused/Functions-consumer/setDonId.ts b/packages/hardhat/tasks/CLF/unused/Functions-consumer/setDonId.ts index eb4f3e3d0..b960bc2db 100644 --- a/packages/hardhat/tasks/CLF/unused/Functions-consumer/setDonId.ts +++ b/packages/hardhat/tasks/CLF/unused/Functions-consumer/setDonId.ts @@ -1,4 +1,4 @@ -import chains from "../../../../constants/CNetworks"; +import chains from "../../../../constants/cNetworks"; import { task } from "hardhat/config"; task( diff --git a/packages/hardhat/tasks/CLFScripts/simulate.ts b/packages/hardhat/tasks/CLFScripts/simulate.ts index 6a2dc5067..140acead8 100644 --- a/packages/hardhat/tasks/CLFScripts/simulate.ts +++ b/packages/hardhat/tasks/CLFScripts/simulate.ts @@ -1,122 +1,122 @@ -import { task, types } from "hardhat/config"; -import fs from "fs"; -import secrets from "../../constants/CLFSecrets"; -import CLFSimulationConfig from "../../constants/CLFSimulationConfig"; -import { execSync } from "child_process"; -import getHashSum from "../../utils/getHashSum"; +import {task, types} from 'hardhat/config'; +import fs from 'fs'; +import secrets from '../../constants/CLFSecrets'; +import CLFSimulationConfig from '../../constants/CLFSimulationConfig'; +import {execSync} from 'child_process'; +import getHashSum from '../../utils/getHashSum'; import { - automationsJsCodeUrl, - ethersV6CodeUrl, - infraSrcJsCodeUrl, - parentPoolDistributeLiqJsCodeUrl, -} from "../../constants/functionsJsCodeUrls"; -import { getEnvVar } from "../../utils/getEnvVar"; + automationsJsCodeUrl, + ethersV6CodeUrl, + infraSrcJsCodeUrl, + parentPoolDistributeLiqJsCodeUrl, +} from '../../constants/functionsJsCodeUrls'; +import {getEnvVar} from '../../utils'; -const { simulateScript } = require("@chainlink/functions-toolkit"); +const {simulateScript} = require('@chainlink/functions-toolkit'); -const path = require("path"); -const process = require("process"); +const path = require('path'); +const process = require('process'); async function simulate(pathToFile, args) { - if (!fs.existsSync(pathToFile)) return console.error(`File not found: ${pathToFile}`); - console.log("Simulating script:", pathToFile); + if (!fs.existsSync(pathToFile)) return console.error(`File not found: ${pathToFile}`); + console.log('Simulating script:', pathToFile); - let promises = []; - for (let i = 0; i < 1; i++) { - promises.push( - simulateScript({ - source: fs.readFileSync(pathToFile, "utf8"), - bytesArgs: args, - secrets, - ...CLFSimulationConfig, - }), - ); - } + let promises = []; + for (let i = 0; i < 1; i++) { + promises.push( + simulateScript({ + source: fs.readFileSync(pathToFile, 'utf8'), + bytesArgs: args, + secrets, + ...CLFSimulationConfig, + }), + ); + } - let results = await Promise.all(promises); + let results = await Promise.all(promises); - for (const result of results) { - const { errorString, capturedTerminalOutput, responseBytesHexstring } = result; + for (const result of results) { + const {errorString, capturedTerminalOutput, responseBytesHexstring} = result; - if (errorString) { - console.log("CAPTURED ERROR:"); - console.log(errorString); - } + if (errorString) { + console.log('CAPTURED ERROR:'); + console.log(errorString); + } - if (capturedTerminalOutput) { - console.log("CAPTURED TERMINAL OUTPUT:"); - console.log(capturedTerminalOutput); - } + if (capturedTerminalOutput) { + console.log('CAPTURED TERMINAL OUTPUT:'); + console.log(capturedTerminalOutput); + } - if (responseBytesHexstring) { - console.log("RESPONSE BYTES HEXSTRING:"); - console.log(responseBytesHexstring); - } - } + if (responseBytesHexstring) { + console.log('RESPONSE BYTES HEXSTRING:'); + console.log(responseBytesHexstring); + } + } } /* run with: bunx hardhat clf-simulate-script */ -task("clf-script-simulate", "Executes the JavaScript source code locally") - // .addOptionalParam("path", "Path to script file", `${__dirn ame}/../Functions-request-config.js`, types.string) - .addParam("function", "Path to script file", "pool_get_total_balance", types.string) - .setAction(async (taskArgs, hre) => { - execSync(`bunx hardhat clf-script-build --all`, { stdio: "inherit" }); +task('clf-script-simulate', 'Executes the JavaScript source code locally') + // .addOptionalParam("path", "Path to script file", `${__dirn ame}/../Functions-request-config.js`, types.string) + .addParam('function', 'Path to script file', 'pool_get_total_balance', types.string) + .setAction(async (taskArgs, hre) => { + execSync(`bunx hardhat clf-script-build --all`, {stdio: 'inherit'}); - if (taskArgs.function === "infra_src") { - await simulate(path.join(__dirname, "../", "./CLFScripts/dist/infra/eval.min.js"), [ - getHashSum(await (await fetch(infraSrcJsCodeUrl)).text()), - getHashSum(await (await fetch(ethersV6CodeUrl)).text()), - "0x0", - getEnvVar("CONCERO_INFRA_PROXY_POLYGON"), // dst contractAddress - "0xf721b113e0a0401ba87f48aff9801c78f037cab36cb43c72bd115ccec7845d27", // ccipMessageId - "0x70E73f067a1fC9FE6D53151bd271715811746d3a", // sender - "0x70E73f067a1fC9FE6D53151bd271715811746d3a", // recipient - "0x" + 100000000000000000n.toString(16), // amount - "0x" + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_BASE).toString(16), // srcChainSelector - "0x" + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_POLYGON).toString(16), // dstChainSelector - "0x" + 1n.toString(16), // token - "0xA65233", // blockNumber - "0x00", //dst swap data - ]); - } else if (taskArgs.function === "infra_dst") { - await simulate(path.join(__dirname, "../", "./CLFScripts/dist/eval.min.js"), [ - "0xada5df165da01ec1249e7ae55303f8587fd50170729ed2b33a8b53be71f8d8ab", - "0x05f8cc312ae3687e5581353da9c5889b92d232f7776c8b81dc234fb330fda265", // ethers hash sum - "0x1", - process.env.CONCERO_BRIDGE_BASE_SEPOLIA, // srcContractAddress - "0x" + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_BASE_SEPOLIA).toString(16), // srcChainSelector, chain to get logs from - "0x92DA49", // blockNumber - // event params: - "0xc957703fb298a67ab8077f691dbf4cdb137be8fd39bd4afab67ef847f99a74c8", // messageId - "0x70E73f067a1fC9FE6D53151bd271715811746d3a", // sender - "0x70E73f067a1fC9FE6D53151bd271715811746d3a", // recipient - "0x" + 0n.toString(16), // token - "0x" + 40000000000000000n.toString(16), // amount - "0x" + 5224473277236331295n.toString(16), // dstChainSelector - ]); - } else if (taskArgs.function === "pool_get_total_balance") { - await simulate(path.join(__dirname, "../", "./CLFScripts/dist/pool/getTotalBalance.min.js"), [ - "0xef64cf53063700bbbd8e42b0282d3d8579aac289ea03f826cf16f9bd96c7703a", // srcJsHashSum - "0x984202f6c36a048a80e993557555488e5ae13ff86f2dfbcde698aacd0a7d4eb4", // ethers hash sum - ]); - } else if (taskArgs.function === "automation") { - await simulate(path.join(__dirname, "../", "./CLFScripts/dist/pool/collectLiquidity.min.js"), [ - getHashSum(await (await fetch(automationsJsCodeUrl)).text()), - getHashSum(await (await fetch(ethersV6CodeUrl)).text()), - "0xDddDDb8a8E41C194ac6542a0Ad7bA663A72741E0", - "0x147B0", - "0x3e63da41d93846072a115187efd804333da52256b8ec17e9c05163d6903d561d", - ]); - } else if (taskArgs.function === "pool_distribute_liq") { - await simulate(path.join(__dirname, "../", "./CLFScripts/dist/pool/distributeLiquidity.min.js"), [ - getHashSum(await (await fetch(parentPoolDistributeLiqJsCodeUrl)).text()), - getHashSum(await (await fetch(ethersV6CodeUrl)).text()), - "0x1", // functions req type - "0x383a1891ae1915b1", - "0x05f8cc312ae3687e5581353da9c5889b92d232f7776c8b81dc234fb330fda265", // req id - "0x1", // distribute liq type - ]); - } - }); + if (taskArgs.function === 'infra_src') { + await simulate(path.join(__dirname, '../', './CLFScripts/dist/infra/eval.min.js'), [ + getHashSum(await (await fetch(infraSrcJsCodeUrl)).text()), + getHashSum(await (await fetch(ethersV6CodeUrl)).text()), + '0x0', + getEnvVar('CONCERO_INFRA_PROXY_POLYGON'), // dst contractAddress + '0xf721b113e0a0401ba87f48aff9801c78f037cab36cb43c72bd115ccec7845d27', // ccipMessageId + '0x70E73f067a1fC9FE6D53151bd271715811746d3a', // sender + '0x70E73f067a1fC9FE6D53151bd271715811746d3a', // recipient + '0x' + 100000000000000000n.toString(16), // amount + '0x' + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_BASE).toString(16), // srcChainSelector + '0x' + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_POLYGON).toString(16), // dstChainSelector + '0x' + 1n.toString(16), // token + '0xA65233', // blockNumber + '0x00', //dst swap data + ]); + } else if (taskArgs.function === 'infra_dst') { + await simulate(path.join(__dirname, '../', './CLFScripts/dist/eval.min.js'), [ + '0xada5df165da01ec1249e7ae55303f8587fd50170729ed2b33a8b53be71f8d8ab', + '0x05f8cc312ae3687e5581353da9c5889b92d232f7776c8b81dc234fb330fda265', // ethers hash sum + '0x1', + process.env.CONCERO_BRIDGE_BASE_SEPOLIA, // srcContractAddress + '0x' + BigInt(process.env.CL_CCIP_CHAIN_SELECTOR_BASE_SEPOLIA).toString(16), // srcChainSelector, chain to get logs from + '0x92DA49', // blockNumber + // event params: + '0xc957703fb298a67ab8077f691dbf4cdb137be8fd39bd4afab67ef847f99a74c8', // messageId + '0x70E73f067a1fC9FE6D53151bd271715811746d3a', // sender + '0x70E73f067a1fC9FE6D53151bd271715811746d3a', // recipient + '0x' + 0n.toString(16), // token + '0x' + 40000000000000000n.toString(16), // amount + '0x' + 5224473277236331295n.toString(16), // dstChainSelector + ]); + } else if (taskArgs.function === 'pool_get_total_balance') { + await simulate(path.join(__dirname, '../', './CLFScripts/dist/pool/getTotalBalance.min.js'), [ + '0xef64cf53063700bbbd8e42b0282d3d8579aac289ea03f826cf16f9bd96c7703a', // srcJsHashSum + '0x984202f6c36a048a80e993557555488e5ae13ff86f2dfbcde698aacd0a7d4eb4', // ethers hash sum + ]); + } else if (taskArgs.function === 'automation') { + await simulate(path.join(__dirname, '../', './CLFScripts/dist/pool/collectLiquidity.min.js'), [ + getHashSum(await (await fetch(automationsJsCodeUrl)).text()), + getHashSum(await (await fetch(ethersV6CodeUrl)).text()), + '0xDddDDb8a8E41C194ac6542a0Ad7bA663A72741E0', + '0x147B0', + '0x3e63da41d93846072a115187efd804333da52256b8ec17e9c05163d6903d561d', + ]); + } else if (taskArgs.function === 'pool_distribute_liq') { + await simulate(path.join(__dirname, '../', './CLFScripts/dist/pool/distributeLiquidity.min.js'), [ + getHashSum(await (await fetch(parentPoolDistributeLiqJsCodeUrl)).text()), + getHashSum(await (await fetch(ethersV6CodeUrl)).text()), + '0x1', // functions req type + '0x383a1891ae1915b1', + '0x05f8cc312ae3687e5581353da9c5889b92d232f7776c8b81dc234fb330fda265', // req id + '0x1', // distribute liq type + ]); + } + }); export default {}; diff --git a/packages/hardhat/tasks/concero/callFunction.ts b/packages/hardhat/tasks/concero/callFunction.ts index bff760371..fa9f7b479 100644 --- a/packages/hardhat/tasks/concero/callFunction.ts +++ b/packages/hardhat/tasks/concero/callFunction.ts @@ -1,11 +1,10 @@ -import { getEnvVar } from "../../utils/getEnvVar"; +import { getEnvVar, getFallbackClients } from "../../utils"; import log from "../../utils/log"; import { task } from "hardhat/config"; -import CNetworks, { networkEnvKeys } from "../../constants/CNetworks"; -import { getFallbackClients } from "../../utils/getViemClients"; +import cNetworks, { networkEnvKeys } from "../../constants/cNetworks"; export async function callContractFunction() { - const chain = CNetworks.base; + const chain = cNetworks.base; const { walletClient, publicClient, account } = getFallbackClients(chain); const gasPrice = await publicClient.getGasPrice(); diff --git a/packages/hardhat/tasks/concero/changeOwnership.ts b/packages/hardhat/tasks/concero/changeOwnership.ts index 194ea92e1..cace9af82 100644 --- a/packages/hardhat/tasks/concero/changeOwnership.ts +++ b/packages/hardhat/tasks/concero/changeOwnership.ts @@ -1,4 +1,4 @@ -import CNetworks from "../../constants/CNetworks"; +import cNetworks from "../../constants/cNetworks"; import { privateKeyToAccount } from "viem/accounts"; import log from "../../utils/log"; import { task } from "hardhat/config"; @@ -9,7 +9,7 @@ import { getFallbackClients } from "../../utils/getViemClients"; export async function changeOwnership(hre, targetContract, newOwner: string) { const { name: chainName } = hre.network; const chainId = hre.network.config.chainId; - const { viemChain, url } = CNetworks[chainName]; + const { viemChain, url } = cNetworks[chainName]; if (!viemChain) { log(`Chain ${chainId} not found in live chains`, "changeOwnership"); diff --git a/packages/hardhat/tasks/concero/decodeClfFulfill.ts b/packages/hardhat/tasks/concero/decodeClfFulfill.ts index ba66a4518..988897c37 100644 --- a/packages/hardhat/tasks/concero/decodeClfFulfill.ts +++ b/packages/hardhat/tasks/concero/decodeClfFulfill.ts @@ -1,5 +1,5 @@ import { task } from "hardhat/config"; -import CNetworks from "../../constants/CNetworks"; +import cNetworks from "../../constants/cNetworks"; import { getFallbackClients } from "../../utils/getViemClients"; import { decodeAbiParameters, parseAbiParameters } from "viem"; @@ -23,7 +23,7 @@ const reportAbiParameters = parseAbiParameters([ task("decode-clf-fulfill", "Decodes CLF TX to get signers and fulfillment data") .addParam("txhash", "Transaction hash to decode") .setAction(async taskArgs => { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { publicClient } = getFallbackClients(chain); const tx = await publicClient.getTransaction({ hash: taskArgs.txhash, diff --git a/packages/hardhat/tasks/concero/deleteDepositsOTWIds.ts b/packages/hardhat/tasks/concero/deleteDepositsOTWIds.ts index 6b29ca538..7b3e12570 100644 --- a/packages/hardhat/tasks/concero/deleteDepositsOTWIds.ts +++ b/packages/hardhat/tasks/concero/deleteDepositsOTWIds.ts @@ -1,17 +1,17 @@ -import { viemReceiptConfig } from "../../constants/deploymentVariables"; +import { ProxyEnum, viemReceiptConfig } from "../../constants/deploymentVariables"; import { getFallbackClients } from "../../utils/getViemClients"; import { getEnvAddress } from "../../utils/getEnvVar"; import log from "../../utils/log"; import { task } from "hardhat/config"; -import CNetworks from "../../constants/CNetworks"; +import cNetworks from "../../constants/cNetworks"; export async function deleteDepositsOTWIds() { - const chain = CNetworks.base; + const chain = cNetworks.base; const { walletClient, publicClient, account } = getFallbackClients(chain); const gasPrice = await publicClient.getGasPrice(); - const [parentPoolProxy, _] = getEnvAddress("parentPoolProxy", chain.name); + const [parentPoolProxy, _] = getEnvAddress(ProxyEnum.parentPoolProxy, chain.name); const idsToDelete = [ "0xc6", "0xc5", diff --git a/packages/hardhat/tasks/concero/deployAutomations/deployAutomations.ts b/packages/hardhat/tasks/concero/deployAutomations/deployAutomations.ts index e8a6b0cca..134373523 100644 --- a/packages/hardhat/tasks/concero/deployAutomations/deployAutomations.ts +++ b/packages/hardhat/tasks/concero/deployAutomations/deployAutomations.ts @@ -2,14 +2,12 @@ import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import deployConceroAutomation from "../../../deploy/ConceroAutomation"; import { setAutomationsVariables } from "./setAutomationsVariables"; -import CNetworks, { networkEnvKeys } from "../../../constants/CNetworks"; -import { getEnvVar } from "../../../utils/getEnvVar"; +import cNetworks, { networkEnvKeys } from "../../../constants/cNetworks"; +import { compileContracts, getEnvVar, getFallbackClients } from "../../../utils"; import addCLFConsumer from "../../CLF/subscriptions/add"; import log from "../../../utils/log"; import abi from "@chainlink/contracts/abi/v0.8/AutomationRegistrar2_1.json"; -import { getFallbackClients } from "../../../utils/getViemClients"; import { erc20Abi } from "viem"; -import { compileContracts } from "../../../utils/compileContracts"; task("deploy-pool-clfcla", "Deploy the automations") .addFlag("skipdeploy", "Deploy the contract to a specific network") @@ -22,7 +20,7 @@ task("deploy-pool-clfcla", "Deploy the automations") const hre: HardhatRuntimeEnvironment = require("hardhat"); const { name } = hre.network; const slotId = parseInt(taskArgs.slotid); - const chain = CNetworks[name]; + const chain = cNetworks[name]; const { viemChain } = chain; if (!taskArgs.skipdeploy) { await deployConceroAutomation(hre, { slotId }); diff --git a/packages/hardhat/tasks/concero/deployAutomations/getSecretsBySlotId.ts b/packages/hardhat/tasks/concero/deployAutomations/getSecretsBySlotId.ts index 5c89b6c88..26b4ccceb 100644 --- a/packages/hardhat/tasks/concero/deployAutomations/getSecretsBySlotId.ts +++ b/packages/hardhat/tasks/concero/deployAutomations/getSecretsBySlotId.ts @@ -1,10 +1,10 @@ import { getEthersV5FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider"; import { SecretsManager } from "@chainlink/functions-toolkit"; import log from "../../../utils/log"; -import CNetworks from "../../../constants/CNetworks"; +import cNetworks from "../../../constants/cNetworks"; export async function getSecretsBySlotId(chainName: string, slotId: number) { - const chain = CNetworks[chainName]; + const chain = cNetworks[chainName]; const { functionsRouter: dcFunctionsRouter, functionsDonIdAlias: dcFunctionsDonIdAlias, diff --git a/packages/hardhat/tasks/concero/deployAutomations/setAutomationsVariables.ts b/packages/hardhat/tasks/concero/deployAutomations/setAutomationsVariables.ts index 6c0e73d3b..f2c9f0deb 100644 --- a/packages/hardhat/tasks/concero/deployAutomations/setAutomationsVariables.ts +++ b/packages/hardhat/tasks/concero/deployAutomations/setAutomationsVariables.ts @@ -1,16 +1,14 @@ import { getSecretsBySlotId } from "./getSecretsBySlotId"; -import load from "../../../utils/load"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import { getEnvVar } from "../../../utils/getEnvVar"; -import CNetworks, { networkEnvKeys } from "../../../constants/CNetworks"; +import { getEnvVar, getFallbackClients } from "../../../utils"; +import cNetworks, { networkEnvKeys } from "../../../constants/cNetworks"; import log, { err } from "../../../utils/log"; import getHashSum from "../../../utils/getHashSum"; import { automationsJsCodeUrl, ethersV6CodeUrl } from "../../../constants/functionsJsCodeUrls"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; +import { viemReceiptConfig } from "../../../constants"; const setDonHostedSecretsVersion = async (hre, slotId: number, abi) => { try { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { viemChain } = chain; const secretsVersion = (await getSecretsBySlotId(hre.network.name, slotId)).version; @@ -40,7 +38,7 @@ const setDonHostedSecretsVersion = async (hre, slotId: number, abi) => { const setDonHostedSecretsSlotId = async (hre, slotId: number, abi: any) => { try { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { viemChain } = chain; const { walletClient, publicClient, account } = getFallbackClients(chain); const automationsContract = getEnvVar(`CONCERO_AUTOMATION_${networkEnvKeys[chain.name]}`); @@ -70,7 +68,7 @@ const setDonHostedSecretsSlotId = async (hre, slotId: number, abi: any) => { const setForwarderAddress = async (hre, forwarderAddress: string, abi: any) => { const name = hre.network.name; try { - const chain = CNetworks[name]; + const chain = cNetworks[name]; const { viemChain } = chain; const { walletClient, publicClient, account } = getFallbackClients(chain); const automationsContract = getEnvVar(`CONCERO_AUTOMATION_${networkEnvKeys[chain.name]}`); @@ -99,7 +97,7 @@ const setForwarderAddress = async (hre, forwarderAddress: string, abi: any) => { const setHashSum = async (hre, abi: any) => { try { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { viemChain } = chain; const { walletClient, publicClient, account } = getFallbackClients(chain); const automationsContract = getEnvVar(`CONCERO_AUTOMATION_${networkEnvKeys[chain.name]}`); @@ -129,7 +127,7 @@ const setHashSum = async (hre, abi: any) => { const setEthersHashSum = async (hre, abi: any) => { try { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { viemChain } = chain; const { walletClient, publicClient, account } = getFallbackClients(chain); const automationsContract = getEnvVar(`CONCERO_AUTOMATION_${networkEnvKeys[chain.name]}`); @@ -158,7 +156,7 @@ const setEthersHashSum = async (hre, abi: any) => { }; export async function setAutomationsVariables(hre, slotId: number, forwarderAddress: string | undefined) { - const { abi } = await load("../artifacts/contracts/ConceroAutomation.sol/ConceroAutomation.json"); + const { abi } = await import("../artifacts/contracts/ConceroAutomation.sol/ConceroAutomation.json"); await setDonHostedSecretsVersion(hre, slotId, abi); await setDonHostedSecretsSlotId(hre, slotId, abi); diff --git a/packages/hardhat/tasks/concero/deployInfra/deployInfra.ts b/packages/hardhat/tasks/concero/deployInfra/deployInfra.ts index 12549fd39..612502709 100644 --- a/packages/hardhat/tasks/concero/deployInfra/deployInfra.ts +++ b/packages/hardhat/tasks/concero/deployInfra/deployInfra.ts @@ -1,19 +1,23 @@ import { task, types } from "hardhat/config"; -import CNetworks, { networkTypes } from "../../../constants/CNetworks"; +import CNetworks, { conceroChains, networkTypes, ProxyEnum } from "../../../constants"; import { setConceroProxyDstContracts, setContractVariables } from "./setContractVariables"; import { CNetwork } from "../../../types/CNetwork"; import uploadDonSecrets from "../../CLF/donSecrets/upload"; +import deployConcero from "../../../deploy/04_ConceroBridge"; +import deployConceroDexSwap from "../../../deploy/03_ConceroDexSwap"; +import deployConceroOrchestrator from "../../../deploy/05_ConceroOrchestrator"; import deployConcero from "../../../deploy/ConceroBridge"; import { conceroChains } from "../liveChains"; import deployConceroDexSwap from "../../../deploy/ConceroDexSwap"; import deployConceroOrchestrator from "../../../deploy/ConceroOrchestrator"; import addCLFConsumer from "../../CLF/subscriptions/add"; +import { compileContracts, getEnvAddress } from "../../../utils"; +import deployProxyAdmin from "../../../deploy/10_ConceroProxyAdmin"; +import deployTransparentProxy from "../../../deploy/11_TransparentProxy"; import { getEnvAddress } from "../../../utils/getEnvVar"; import deployProxyAdmin from "../../../deploy/ConceroProxyAdmin"; import deployTransparentProxy from "../../../deploy/TransparentProxy"; import { upgradeProxyImplementation } from "../upgradeProxyImplementation"; -import { compileContracts } from "../../../utils/compileContracts"; -import { ensureWalletBalance } from "../ensureBalances/ensureNativeBalances"; import { DeployInfraParams } from "./types"; import { deployerTargetBalances } from "../../../constants/targetBalances"; import { ProxyType } from "../../../constants/deploymentVariables"; @@ -57,26 +61,26 @@ task("deploy-infra", "Deploy the CCIP infrastructure") async function deployInfra(params: DeployInfraParams) { const { hre, deployableChains, deployProxy, deployImplementation, setVars, uploadSecrets, slotId } = params; const { name } = hre.network; - const { deployer, proxyDeployer } = await hre.getNamedAccounts(); + // const { deployer, proxyDeployer } = await hre.getNamedAccounts(); const isTestnet = deployableChains[0].type === "testnet"; if (deployProxy) { - await ensureWalletBalance(proxyDeployer, deployerTargetBalances, CNetworks[name]); - await deployProxyAdmin(hre, ProxyType.infraProxy); - await deployTransparentProxy(hre, ProxyType.infraProxy); + // await ensureWalletBalance(proxyDeployer, deployerTargetBalances, cNetworks[name]); + await deployProxyAdmin(hre, ProxyEnum.infraProxy); + await deployTransparentProxy(hre, ProxyEnum.infraProxy); - const [proxyAddress] = getEnvAddress(ProxyType.infraProxy, name); + const [proxyAddress] = getEnvAddress(ProxyEnum.infraProxy, name); const { functionsSubIds } = CNetworks[name]; await addCLFConsumer(CNetworks[name], [proxyAddress], functionsSubIds[0]); } - await ensureWalletBalance(deployer, deployerTargetBalances, CNetworks[name]); + // await ensureWalletBalance(deployer, deployerTargetBalances, cNetworks[name]); if (deployImplementation) { await deployConceroDexSwap(hre); await deployConcero(hre, { slotId }); await deployConceroOrchestrator(hre); - await upgradeProxyImplementation(hre, ProxyType.infraProxy, false); + await upgradeProxyImplementation(hre, ProxyEnum.infraProxy, false); } if (setVars) { diff --git a/packages/hardhat/tasks/concero/deployInfra/setContractVariables.ts b/packages/hardhat/tasks/concero/deployInfra/setContractVariables.ts index bfefec823..a61d3160d 100644 --- a/packages/hardhat/tasks/concero/deployInfra/setContractVariables.ts +++ b/packages/hardhat/tasks/concero/deployInfra/setContractVariables.ts @@ -1,16 +1,28 @@ -import CNetworks, { networkEnvKeys, networkTypes } from "../../../constants/CNetworks"; import { CNetwork, CNetworkNames } from "../../../types/CNetwork"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import load from "../../../utils/load"; -import { getEnvAddress, getEnvVar } from "../../../utils/getEnvVar"; -import log, { err } from "../../../utils/log"; -import { getEthersV5FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider"; +import { + err, + formatGas, + getEnvAddress, + getEnvVar, + getEthersV5FallbackSignerAndProvider, + getFallbackClients, + getHashSum, + log, + shorten, +} from "../../../utils"; import { SecretsManager } from "@chainlink/functions-toolkit"; -import getHashSum from "../../../utils/getHashSum"; -import { conceroChains, mainnetChains, testnetChains } from "../liveChains"; + +import { + cNetworks, + conceroChains, + mainnetChains, + networkEnvKeys, + networkTypes, + ProxyEnum, + testnetChains, + viemReceiptConfig, +} from "../../../constants"; import { ethersV6CodeUrl, infraDstJsCodeUrl, infraSrcJsCodeUrl } from "../../../constants/functionsJsCodeUrls"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; -import { formatGas, shorten } from "../../../utils/formatting"; const resetLastGasPrices = async (deployableChain: CNetwork, chains: CNetwork[], abi: any) => { const conceroProxyAddress = getEnvVar(`CONCERO_INFRA_PROXY_${networkEnvKeys[deployableChain.name]}`); @@ -41,20 +53,20 @@ const resetLastGasPrices = async (deployableChain: CNetwork, chains: CNetwork[], }; export async function setConceroProxyDstContracts(deployableChains: CNetwork[]) { - const { abi } = await load("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); + const { abi } = await import("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); for (const chain of deployableChains) { const chainsToBeSet = chain.type === networkTypes.mainnet ? conceroChains.mainnet.infra : conceroChains.testnet.infra; const { viemChain, name } = chain; - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", name); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, name); const { walletClient, publicClient, account } = getFallbackClients(chain); for (const dstChain of chainsToBeSet) { try { const { name: dstName, chainSelector: dstChainSelector } = dstChain; if (dstName !== name) { - const [dstProxy, dstProxyAlias] = getEnvAddress("infraProxy", dstName); + const [dstProxy, dstProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dstName); // const gasPrice = await publicClient.getGasPrice(); @@ -105,7 +117,7 @@ export async function setDonHostedSecretsVersion(deployableChain: CNetwork, slot name: dcName, } = deployableChain; try { - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", dcName); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dcName); const { walletClient, publicClient, account } = getFallbackClients(deployableChain); const { signer: dcSigner } = getEthersV5FallbackSignerAndProvider(dcName); @@ -152,7 +164,7 @@ async function setJsHashes(deployableChain: CNetwork, abi: any) { try { const { viemChain, name } = deployableChain; const { walletClient, publicClient, account } = getFallbackClients(deployableChain); - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", name); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, name); const conceroSrcCode = await (await fetch(infraSrcJsCodeUrl)).text(); const conceroDstCode = await (await fetch(infraDstJsCodeUrl)).text(); const ethersCode = await (await fetch(ethersV6CodeUrl)).text(); @@ -190,16 +202,16 @@ async function setJsHashes(deployableChain: CNetwork, abi: any) { export async function setDstConceroPools(deployableChain: CNetwork, abi: any) { const { viemChain: dcViemChain, name: dcName } = deployableChain; const { walletClient, publicClient, account } = getFallbackClients(deployableChain); - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", dcName); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dcName); const chainsToSet = deployableChain.type === networkTypes.mainnet ? mainnetChains : testnetChains; try { for (const chain of chainsToSet) { const { name: dstChainName, chainSelector: dstChainSelector } = chain; const [dstConceroPool, dstConceroPoolAlias] = - chain === CNetworks.base || chain === CNetworks.baseSepolia - ? getEnvAddress("parentPoolProxy", dstChainName) - : getEnvAddress("childPoolProxy", dstChainName); + chain === cNetworks.base || chain === cNetworks.baseSepolia + ? getEnvAddress(ProxyEnum.parentPoolProxy, dstChainName) + : getEnvAddress(ProxyEnum.childPoolProxy, dstChainName); const { request: setDstConceroPoolReq } = await publicClient.simulateContract({ address: conceroProxy, abi, @@ -227,7 +239,7 @@ export async function setDstConceroPools(deployableChain: CNetwork, abi: any) { export async function setDonSecretsSlotId(deployableChain: CNetwork, slotId: number, abi: any) { const { url: dcUrl, viemChain: dcViemChain, name: dcName } = deployableChain; const { walletClient, publicClient, account } = getFallbackClients(deployableChain); - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", dcName); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dcName); try { const { request: setDonSecretsSlotIdReq } = await publicClient.simulateContract({ @@ -255,7 +267,7 @@ export async function setDonSecretsSlotId(deployableChain: CNetwork, slotId: num export async function setDexSwapAllowedRouters(deployableChain: CNetwork, abi: any) { const { viemChain: dcViemChain, name: dcName } = deployableChain; - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", dcName); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dcName); const [allowedRouter, allowedRouterAlias] = getEnvAddress("uniswapRouter", dcName); const { walletClient, publicClient, account } = getFallbackClients(deployableChain); @@ -293,7 +305,7 @@ export async function setFunctionsPremiumFees(deployableChain: CNetwork, abi: an }; const { viemChain: dcViemChain, name: dcName, type } = deployableChain; - const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", dcName); + const [conceroProxy, conceroProxyAlias] = getEnvAddress(ProxyEnum.infraProxy, dcName); const { walletClient, publicClient, account } = getFallbackClients(deployableChain); const chainsToSet = type === networkTypes.mainnet ? mainnetChains : testnetChains; @@ -328,7 +340,7 @@ export async function setFunctionsPremiumFees(deployableChain: CNetwork, abi: an } export async function setContractVariables(deployableChains: CNetwork[], slotId: number, uploadsecrets: boolean) { - const { abi } = await load("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); + const { abi } = await import("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); for (const deployableChain of deployableChains) { if (deployableChain.type === networkTypes.mainnet) await setDexSwapAllowedRouters(deployableChain, abi); // once diff --git a/packages/hardhat/tasks/concero/deployInfra/setProxyImplementation.ts b/packages/hardhat/tasks/concero/deployInfra/setProxyImplementation.ts deleted file mode 100644 index 99ad3b4d0..000000000 --- a/packages/hardhat/tasks/concero/deployInfra/setProxyImplementation.ts +++ /dev/null @@ -1,46 +0,0 @@ -// import { getEnvVar } from "../../../utils/getEnvVar"; -// import { networkEnvKeys } from "../../../constants/CNetworks"; -// import { CNetwork } from "../../../types/CNetwork"; -// import { getClients } from "../../utils/getViemClients"; -// import { privateKeyToAccount } from "viem/accounts"; -// import { Address, parseAbi } from "viem"; -// import log from "../../../utils/log"; - -// REPLACED BY upgradeProxyImplementation.ts -// export async function setProxyImplementation(hre, liveChains: CNetwork[]) { -// const { name: chainName } = hre.network; -// const conceroProxyAddress = getEnvVar(`CONCERO_INFRA_PROXY_${networkEnvKeys[chainName]}`) -// const chainId = hre.network.config.chainId; -// const { viemChain } = liveChains.find(chain => chain.chainId === chainId); -// if (!viemChain) { -// log(`Chain ${chainId} not found in live chains`, "setProxyImplementation"); -// return; -// } -// const viemAccount = privateKeyToAccount(`0x${process.env.PROXY_DEPLOYER_PRIVATE_KEY}`); -// const { walletClient, publicClient } = getClients(viemChain, undefined, viemAccount); -// const conceroOrchestratorAddress = getEnvVar(`CONCERO_ORCHESTRATOR_${networkEnvKeys[chainName]}`) -// -// // const { request } = await publicClient.simulateContract({ -// // address: conceroProxyAddress , -// // abi: parseAbi(["function upgradeToAndCall(address newImplementation, bytes calldata data) external"]), -// // functionName: "upgradeToAndCall", -// // account: viemAccount, -// // args: [conceroOrchestratorAddress, "0x"], -// // chain: viemChain, -// // }); -// // const txHash = await walletClient.writeContract(request); -// -// const txHash = await walletClient.writeContract({ -// address: conceroProxyAddress, -// abi: parseAbi(["function upgradeToAndCall(address, bytes calldata) external payable"]), -// functionName: "upgradeToAndCall", -// account: viemAccount, -// args: [conceroOrchestratorAddress, "0x"], -// chain: viemChain, -// gas: 500_000n, -// }); -// -// const { cumulativeGasUsed } = await publicClient.waitForTransactionReceipt({ hash: txHash }); -// -// log(`Upgrade to CCIP implementation: gasUsed: ${cumulativeGasUsed}, hash: ${txHash}`, "setProxyImplementation"); -// } diff --git a/packages/hardhat/tasks/concero/deployInfra/types.ts b/packages/hardhat/tasks/concero/deployInfra/types.ts index f7df38050..81a95411c 100644 --- a/packages/hardhat/tasks/concero/deployInfra/types.ts +++ b/packages/hardhat/tasks/concero/deployInfra/types.ts @@ -1,5 +1,4 @@ -import { CNetwork } from "../../../types/CNetwork"; -import { NetworkType } from "../../../constants/CNetworks"; +import { CNetwork, NetworkType } from "../../../types/CNetwork"; export interface DeployInfraParams { hre: any; diff --git a/packages/hardhat/tasks/concero/deployPool/deployAllPools.ts b/packages/hardhat/tasks/concero/deployPool/deployAllPools.ts index 1bb452509..890511cdd 100644 --- a/packages/hardhat/tasks/concero/deployPool/deployAllPools.ts +++ b/packages/hardhat/tasks/concero/deployPool/deployAllPools.ts @@ -1,6 +1,6 @@ import { task, types } from "hardhat/config"; import { execSync } from "child_process"; -import { liveChains } from "../liveChains"; +import { liveChains } from "../../../constants/liveChains"; const executeCommand = (command: string) => { execSync(command, { stdio: "inherit" }); diff --git a/packages/hardhat/tasks/concero/deployPool/deployChildPool.ts b/packages/hardhat/tasks/concero/deployPool/deployChildPool.ts index 012b066e0..6d36d897f 100644 --- a/packages/hardhat/tasks/concero/deployPool/deployChildPool.ts +++ b/packages/hardhat/tasks/concero/deployPool/deployChildPool.ts @@ -5,8 +5,8 @@ import { setChildProxyVariables } from "./setChildProxyVariables"; import deployProxyAdmin from "../../../deploy/ConceroProxyAdmin"; import deployTransparentProxy from "../../../deploy/TransparentProxy"; import { upgradeProxyImplementation } from "../upgradeProxyImplementation"; -import { compileContracts } from "../../../utils/compileContracts"; -import { ProxyType } from "../../../constants/deploymentVariables"; +import { compileContracts } from "../../../utils"; +import { ProxyEnum } from "../../../constants"; task("deploy-child-pool", "Deploy the pool") .addFlag("deployproxy", "Deploy the proxy") @@ -17,13 +17,13 @@ task("deploy-child-pool", "Deploy the pool") compileContracts({ quiet: true }); if (taskArgs.deployproxy) { - await deployProxyAdmin(hre, ProxyType.childPoolProxy); - await deployTransparentProxy(hre, ProxyType.childPoolProxy); + await deployProxyAdmin(hre, ProxyEnum.childPoolProxy); + await deployTransparentProxy(hre, ProxyEnum.childPoolProxy); } if (taskArgs.deployimplementation) { await deployChildPool(hre); - await upgradeProxyImplementation(hre, ProxyType.childPoolProxy, false); + await upgradeProxyImplementation(hre, ProxyEnum.childPoolProxy, false); } if (taskArgs.setvars) { diff --git a/packages/hardhat/tasks/concero/deployPool/deployParentPool.ts b/packages/hardhat/tasks/concero/deployPool/deployParentPool.ts index d93443d31..cfe08b3ea 100644 --- a/packages/hardhat/tasks/concero/deployPool/deployParentPool.ts +++ b/packages/hardhat/tasks/concero/deployPool/deployParentPool.ts @@ -1,14 +1,14 @@ import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import chains from "../../../constants/CNetworks"; -import CNetworks from "../../../constants/CNetworks"; -import { getEnvAddress } from "../../../utils/getEnvVar"; +import { cNetworks, ProxyEnum } from "../../../constants"; +import { compileContracts, getEnvAddress } from "../../../utils"; import addCLFConsumer from "../../CLF/subscriptions/add"; import uploadDonSecrets from "../../CLF/donSecrets/upload"; import { CNetwork } from "../../../types/CNetwork"; import { setParentPoolVariables } from "./setParentPoolVariables"; import deployTransparentProxy from "../../../deploy/TransparentProxy"; import { compileContracts } from "../../../utils/compileContracts"; +import deployTransparentProxy from "../../../deploy/11_TransparentProxy"; import { upgradeProxyImplementation } from "../upgradeProxyImplementation"; import deployParentPool from "../../../deploy/ParentPool"; import deployProxyAdmin from "../../../deploy/ConceroProxyAdmin"; @@ -30,22 +30,22 @@ task("deploy-parent-pool", "Deploy the pool") const hre: HardhatRuntimeEnvironment = require("hardhat"); const slotId = parseInt(taskArgs.slotid); const { name } = hre.network; + const deployableChains: CNetwork[] = [cNetworks[hre.network.name]]; const deployableChains: CNetwork[] = [CNetworks[hre.network.name]]; const isTestnet = deployableChains[0].type === "testnet"; if (taskArgs.deployproxy) { - await deployProxyAdmin(hre, ProxyType.parentPoolProxy); - await deployTransparentProxy(hre, ProxyType.parentPoolProxy); - const [proxyAddress, _] = getEnvAddress(ProxyType.parentPoolProxy, name); - const { functionsSubIds } = chains[name]; - await addCLFConsumer(chains[name], [proxyAddress], functionsSubIds[0]); + await deployProxyAdmin(hre, ProxyEnum.parentPoolProxy); + await deployTransparentProxy(hre, ProxyEnum.parentPoolProxy); + const [proxyAddress, _] = getEnvAddress(ProxyEnum.parentPoolProxy, name); + const { functionsSubIds } = cNetworks[name]; + await addCLFConsumer(cNetworks[name], [proxyAddress], functionsSubIds[0]); } if (taskArgs.deployimplementation) { await deployParentPoolCLFCLA(hre, { automationForwarder: taskArgs.automationforwarder }); await deployParentPool(hre, { automationForwarder: taskArgs.automationforwarder }); - - await upgradeProxyImplementation(hre, ProxyType.parentPoolProxy, false); + await upgradeProxyImplementation(hre, ProxyEnum.parentPoolProxy, false); } if (taskArgs.uploadsecrets) { diff --git a/packages/hardhat/tasks/concero/deployPool/setChildPoolProxyImplementation.ts b/packages/hardhat/tasks/concero/deployPool/setChildPoolProxyImplementation.ts index 02b21ff2a..d72755079 100644 --- a/packages/hardhat/tasks/concero/deployPool/setChildPoolProxyImplementation.ts +++ b/packages/hardhat/tasks/concero/deployPool/setChildPoolProxyImplementation.ts @@ -1,11 +1,8 @@ import { CNetwork } from "../../../types/CNetwork"; -import { getEnvVar } from "../../../utils/getEnvVar"; -import { networkEnvKeys } from "../../../constants/CNetworks"; +import { getEnvVar, getFallbackClients, log } from "../../../utils"; +import { networkEnvKeys, viemReceiptConfig } from "../../../constants"; import { parseAbi } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import log from "../../../utils/log"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; export async function setChildPoolProxyImplementation(hre, liveChains: CNetwork[]) { const { name: chainName } = hre.network; diff --git a/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts b/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts index f1d653a83..0200d7ee5 100644 --- a/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts +++ b/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts @@ -1,17 +1,19 @@ -import load from "../../../utils/load"; -import { getEnvVar } from "../../../utils/getEnvVar"; -import CNetworks, { networkEnvKeys, networkTypes } from "../../../constants/CNetworks"; -import log, { err } from "../../../utils/log"; -import { mainnetChains, testnetChains } from "../liveChains"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { err, getEnvVar, getFallbackClients, log } from "../../../utils"; +import { + cNetworks, + mainnetChains, + networkEnvKeys, + networkTypes, + testnetChains, + viemReceiptConfig, +} from "../../../constants"; async function setConceroProxySender(hre) { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { name: chainName, viemChain, url, type } = chain; const clients = getFallbackClients(chain); const { publicClient, account, walletClient } = clients; - const { abi } = await load("../artifacts/contracts/ConceroChildPool.sol/ConceroChildPool.json"); + const { abi } = await import("../artifacts/contracts/ConceroChildPool.sol/ConceroChildPool.json"); if (!chainName) throw new Error("Chain name not found"); const chains = type === networkTypes.mainnet ? mainnetChains : testnetChains; @@ -23,7 +25,7 @@ async function setConceroProxySender(hre) { if (!dstChainSelector) throw new Error("Destination chain selector not found"); const dstConceroAddress = getEnvVar(`CONCERO_INFRA_PROXY_${networkEnvKeys[dstChainName]}`); const dstConceroPoolAddress = - dstChain.chainId === CNetworks.base.chainId || dstChain.chainId === CNetworks.baseSepolia.chainId + dstChain.chainId === cNetworks.base.chainId || dstChain.chainId === cNetworks.baseSepolia.chainId ? getEnvVar(`PARENT_POOL_PROXY_${networkEnvKeys[dstChainName]}`) : getEnvVar(`CHILD_POOL_PROXY_${networkEnvKeys[dstChainName]}`); const conceroPoolAddress = getEnvVar(`CHILD_POOL_PROXY_${networkEnvKeys[chainName]}`); @@ -79,11 +81,11 @@ async function setConceroProxySender(hre) { } async function addPoolsToAllChains(hre) { - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; const { name: chainName, viemChain, type } = chain; const clients = getFallbackClients(chain); const { publicClient, account, walletClient } = clients; - const { abi } = await load("../artifacts/contracts/ConceroChildPool.sol/ConceroChildPool.json"); + const { abi } = await import("../artifacts/contracts/ConceroChildPool.sol/ConceroChildPool.json"); if (!chainName) throw new Error("Chain name not found"); const chains = type === networkTypes.mainnet ? mainnetChains : testnetChains; @@ -92,7 +94,7 @@ async function addPoolsToAllChains(hre) { const { name: dstChainName, chainSelector: dstChainSelector } = dstChain; const poolAddressToAdd = - dstChain.chainId === CNetworks.base.chainId || dstChain.chainId === CNetworks.baseSepolia.chainId + dstChain.chainId === cNetworks.base.chainId || dstChain.chainId === cNetworks.baseSepolia.chainId ? getEnvVar(`PARENT_POOL_PROXY_${networkEnvKeys[dstChain.name]}`) : getEnvVar(`CHILD_POOL_PROXY_${networkEnvKeys[dstChain.name]}`); diff --git a/packages/hardhat/tasks/concero/deployPool/setParentPoolProxyImplementation.ts b/packages/hardhat/tasks/concero/deployPool/setParentPoolProxyImplementation.ts deleted file mode 100644 index 7475c0c2d..000000000 --- a/packages/hardhat/tasks/concero/deployPool/setParentPoolProxyImplementation.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { getEnvVar } from "../../../utils/getEnvVar"; -import { networkEnvKeys } from "../../../constants/CNetworks"; -import { parseAbi } from "viem"; -import { privateKeyToAccount } from "viem/accounts"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import log from "../../../utils/log"; -import { CNetwork } from "../../../types/CNetwork"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; - -export async function setParentPoolProxyImplementation(hre, liveChains: CNetwork[]) { - const { name: chainName } = hre.network; - const conceroProxyAddress = getEnvVar(`PARENT_POOL_PROXY_${networkEnvKeys[chainName]}`); - const chainId = hre.network.config.chainId; - const chain = liveChains.find(c => { - return c.chainId?.toString() === chainId.toString(); - }); - - if (!chain) { - throw new Error(`Chain not found: ${chainId}`); - } - - const { viemChain } = chain; - const viemAccount = privateKeyToAccount(`0x${process.env.PROXY_DEPLOYER_PRIVATE_KEY}`); - const { walletClient, publicClient } = getFallbackClients(chain, viemAccount); - const parentPoolAddress = getEnvVar(`PARENT_POOL_${networkEnvKeys[chainName]}`); - - const txHash = await walletClient.writeContract({ - address: conceroProxyAddress, - abi: parseAbi(["function upgradeToAndCall(address, bytes calldata) external payable"]), - functionName: "upgradeToAndCall", - account: viemAccount, - args: [parentPoolAddress, "0x"], - chain: viemChain, - gas: 500_000n, - }); - - const { cumulativeGasUsed } = await publicClient.waitForTransactionReceipt({ ...viemReceiptConfig, hash: txHash }); - - log( - `Upgrade to Parent Pool implementation: gasUsed: ${cumulativeGasUsed}, hash: ${txHash}`, - "setProxyImplementation", - ); -} diff --git a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts index 3a7537c65..ebaecaccc 100644 --- a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts +++ b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts @@ -1,23 +1,32 @@ import { CNetwork } from "../../../types/CNetwork"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import { getEnvAddress, getEnvVar } from "../../../utils/getEnvVar"; -import { networkEnvKeys, networkTypes } from "../../../constants/CNetworks"; +import { + formatGas, + getEnvAddress, + getEnvVar, + getEthersV5FallbackSignerAndProvider, + getFallbackClients, + shorten, +} from "../../../utils"; +import { + mainnetChains, + networkEnvKeys, + networkTypes, + ProxyEnum, + testnetChains, + viemReceiptConfig, +} from "../../../constants"; import { ethersV6CodeUrl, parentPoolJsCodeUrl } from "../../../constants/functionsJsCodeUrls"; import { Address } from "viem"; import log, { err } from "../../../utils/log"; import getHashSum from "../../../utils/getHashSum"; -import load from "../../../utils/load"; -import { getEthersV5FallbackSignerAndProvider } from "../../../utils/getEthersSignerAndProvider"; + import { SecretsManager } from "@chainlink/functions-toolkit"; -import { mainnetChains, testnetChains } from "../liveChains"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; -import { formatGas, shorten } from "../../../utils/formatting"; async function setParentPoolJsHashes(chain: CNetwork, abi: any) { const { viemChain, name } = chain; try { const { walletClient, publicClient, account } = getFallbackClients(chain); - const [parentPoolProxy, parentPoolAlias] = getEnvAddress("parentPoolProxy", name); + const [parentPoolProxy, parentPoolAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); const parentPoolJsCode = await (await fetch(parentPoolJsCodeUrl)).text(); const ethersCode = await (await fetch(ethersV6CodeUrl)).text(); @@ -50,7 +59,7 @@ async function setParentPoolCap(chain: CNetwork, abi: any) { const { name } = chain; try { const { walletClient, publicClient, account } = getFallbackClients(chain); - const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress("parentPoolProxy", name); + const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); const poolCap = 100_000n * 10n ** 6n; const { request: setCapReq } = await publicClient.simulateContract({ @@ -80,7 +89,7 @@ async function setParentPoolSecretsVersion(chain: CNetwork, abi: any, slotId: nu const { functionsRouter, functionsDonIdAlias, functionsGatewayUrls, name } = chain; try { const { walletClient, publicClient, account } = getFallbackClients(chain); - const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress("parentPoolProxy", name); + const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); const { signer: dcSigner } = getEthersV5FallbackSignerAndProvider(name); const secretsManager = new SecretsManager({ @@ -124,7 +133,7 @@ async function setParentPoolSecretsSlotId(chain: CNetwork, abi: any, slotId: num const { name } = chain; try { const { walletClient, publicClient, account } = getFallbackClients(chain); - const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress("parentPoolProxy", name); + const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); const { request } = await publicClient.simulateContract({ address: parentPoolProxy, @@ -153,7 +162,7 @@ async function setConceroContractSenders(chain: CNetwork, abi: any) { const clients = getFallbackClients(chain); const { publicClient, account, walletClient } = clients; - const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress("parentPoolProxy", name); + const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); const dstChains = type === networkTypes.mainnet ? mainnetChains : testnetChains; @@ -165,8 +174,8 @@ async function setConceroContractSenders(chain: CNetwork, abi: any) { if (!dstChainName) throw new Error("Destination chain name not found"); if (!dstChainSelector) throw new Error("Destination chain selector not found"); - const [dstConceroProxy, _] = getEnvAddress("infraProxy", dstChainName); - const [childPoolProxy, __] = getEnvAddress("childPoolProxy", dstChainName); + const [dstConceroProxy, _] = getEnvAddress(ProxyEnum.infraProxy, dstChainName); + const [childPoolProxy, __] = getEnvAddress(ProxyEnum.childPoolProxy, dstChainName); const setSender = async (sender: Address) => { const { request: setSenderReq } = await publicClient.simulateContract({ @@ -207,8 +216,8 @@ async function setPools(chain: CNetwork, abi: any) { if (dstChain.chainId === chain.chainId) continue; const { name: dstChainName, chainSelector: dstChainSelector } = dstChain; - const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress("parentPoolProxy", name); - const [childPoolProxy, childPoolProxyAlias] = getEnvAddress("childPoolProxy", dstChainName); + const [parentPoolProxy, parentPoolProxyAlias] = getEnvAddress(ProxyEnum.parentPoolProxy, name); + const [childPoolProxy, childPoolProxyAlias] = getEnvAddress(ProxyEnum.childPoolProxy, dstChainName); const { request: setReceiverReq } = await publicClient.simulateContract({ address: parentPoolProxy, @@ -302,7 +311,7 @@ async function removePool(chain: CNetwork, abi: any, networkName: string) { } export async function setParentPoolVariables(chain: CNetwork, slotId: number) { - const { abi: ParentPoolAbi } = await load("../artifacts/contracts/ParentPool.sol/ParentPool.json"); + const { abi: ParentPoolAbi } = await import("../artifacts/contracts/ParentPool.sol/ParentPool.json"); await setParentPoolSecretsVersion(chain, ParentPoolAbi, slotId); await setParentPoolSecretsSlotId(chain, ParentPoolAbi, slotId); diff --git a/packages/hardhat/tasks/concero/deployWithCreate3.ts b/packages/hardhat/tasks/concero/deployWithCreate3.ts index 4e6ce124a..522b298a4 100644 --- a/packages/hardhat/tasks/concero/deployWithCreate3.ts +++ b/packages/hardhat/tasks/concero/deployWithCreate3.ts @@ -1,4 +1,4 @@ -// import CNetworks, { networkEnvKeys } from "../../constants/CNetworks"; +// import cNetworks, { networkEnvKeys } from "../../constants/cNetworks"; // import { getClients } from "../utils/getViemClients"; // import { getEnvVar } from "../../utils/getEnvVar"; // import { HardhatRuntimeEnvironment } from "hardhat/types"; @@ -14,10 +14,10 @@ // const initCodeHash = keccak256(bytecode); // console.log("Initialization Code Hash:", initCodeHash); // return -// if (!CNetworks[hre.network.name]) return console.error("Network not supported"); +// if (!cNetworks[hre.network.name]) return console.error("Network not supported"); // // -// const { viemChain, url, name } = CNetworks[hre.network.name]; +// const { viemChain, url, name } = cNetworks[hre.network.name]; // const { walletClient, publicClient } = getFallbackClients(chain); // // let salt; diff --git a/packages/hardhat/tasks/concero/dripBnm.ts b/packages/hardhat/tasks/concero/dripBnm.ts index f55f5cf4a..2dc5dda39 100644 --- a/packages/hardhat/tasks/concero/dripBnm.ts +++ b/packages/hardhat/tasks/concero/dripBnm.ts @@ -1,5 +1,5 @@ import { CNetwork } from "../../types/CNetwork"; -import chains from "../../constants/CNetworks"; +import chains from "../../constants/cNetworks"; import liveChains from "./deployInfra/deployInfra"; import { task } from "hardhat/config"; import { viemReceiptConfig } from "../../constants/deploymentVariables"; diff --git a/packages/hardhat/tasks/concero/ensureBalances/checkERC20Balance.ts b/packages/hardhat/tasks/concero/ensureBalances/checkERC20Balance.ts index 3f04f3ddd..b22a7f376 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/checkERC20Balance.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/checkERC20Balance.ts @@ -1,15 +1,46 @@ import type { CNetwork } from "../../../types/CNetwork"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { getFallbackClients } from "../../../utils"; import { erc20Abi } from "viem"; +import { BalanceInfo } from "./types"; -async function checkERC20Balance(chain: CNetwork, token: string, address: string): Promise { +async function checkERC20Balance(chain: CNetwork, token: string, address: string): Promise { const { publicClient } = getFallbackClients(chain); - return await publicClient.readContract({ + const [balance, symbol, decimals] = await Promise.all([ + publicClient.readContract({ + address: token, + abi: erc20Abi, + functionName: "balanceOf", + args: [address], + }), + publicClient.readContract({ + address: token, + abi: erc20Abi, + functionName: "symbol", + }), + publicClient.readContract({ + address: token, + abi: erc20Abi, + functionName: "decimals", + }), + ]); + + const donorBalance = await publicClient.readContract({ address: token, abi: erc20Abi, functionName: "balanceOf", - args: [address] + args: [process.env.DEPLOYER_ADDRESS], }); + + return { + chain, + balance, + symbol, + decimals, + deficit: BigInt(0), // This will be calculated in the calling function + donorBalance, + type: "ERC20", + address, + }; } export default checkERC20Balance; diff --git a/packages/hardhat/tasks/concero/ensureBalances/ensureCLFSubscriptionBalances.ts b/packages/hardhat/tasks/concero/ensureBalances/ensureCLFSubscriptionBalances.ts index f4c231180..7a7adb654 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/ensureCLFSubscriptionBalances.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/ensureCLFSubscriptionBalances.ts @@ -1,15 +1,14 @@ -import { mainnetChains, testnetChains } from "../liveChains"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { mainnetChains, testnetChains, viemReceiptConfig } from "../../../constants"; +import { err, getFallbackClients, log } from "../../../utils"; import { privateKeyToAccount } from "viem/accounts"; import { task } from "hardhat/config"; import { formatEther, parseEther } from "viem"; import { type CNetwork } from "../../../types/CNetwork"; -import log, { err } from "../../../utils/log"; import readline from "readline"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; import functionsRouterAbi from "@chainlink/contracts/abi/v0.8/FunctionsRouter.json"; import checkERC20Balance from "./checkERC20Balance"; import linkTokenAbi from "@chainlink/contracts/abi/v0.8/LinkToken.json"; +import { BalanceInfo } from "./types"; const donorAccount = privateKeyToAccount(`0x${process.env.DEPLOYER_PRIVATE_KEY}`); const minBalance = parseEther("10"); @@ -17,14 +16,7 @@ const minBalance = parseEther("10"); const prompt = (question: string): Promise => new Promise(resolve => rl.question(question, resolve)); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); -interface SubscriptionInfo { - chain: CNetwork; - balance: bigint; - deficit: bigint; - donorBalance: bigint; -} - -async function checkSubscriptionBalance(chain: CNetwork): Promise { +async function checkSubscriptionBalance(chain: CNetwork): Promise { const { publicClient } = getFallbackClients(chain); const { functionsRouter, name, functionsSubIds, linkToken } = chain; const subId = functionsSubIds[0]; @@ -32,24 +24,21 @@ async function checkSubscriptionBalance(chain: CNetwork): Promise { const { publicClient, walletClient } = getFallbackClients(chain, donorAccount); const { functionsRouter, linkToken, name: chainName, functionsSubIds } = chain; const subId = functionsSubIds[0]; try { - const subIdHex = parseInt(subId, 10).toString(16).padStart(2, '0').padStart(64, '0'); + const subIdHex = parseInt(subId, 10).toString(16).padStart(2, "0").padStart(64, "0"); const hash = await walletClient.writeContract({ address: linkToken, abi: linkTokenAbi, @@ -65,7 +54,7 @@ async function topUpSubscription(chain: CNetwork, amount: bigint): Promise log( `Topped up subscription ${subId} with ${formatEther(amount)} LINK. Tx: ${hash} Gas used: ${cumulativeGasUsed}`, "topUpSubscription", - chainName + chainName, ); } catch (error) { err(`Error topping up subscription ${subId} on ${chainName}: ${error}`, "topUpSubscription"); @@ -94,7 +83,7 @@ async function ensureCLFSubscriptionBalances(isTestnet: boolean) { if (totalDeficit > BigInt(0)) { const answer = await prompt( - `Do you want to perform top-ups for a total of ${formatEther(totalDeficit)} LINK? (y/n): ` + `Do you want to perform top-ups for a total of ${formatEther(totalDeficit)} LINK? (y/n): `, ); if (answer.toLowerCase() === "y") { diff --git a/packages/hardhat/tasks/concero/ensureBalances/ensureErc20Balances.ts b/packages/hardhat/tasks/concero/ensureBalances/ensureErc20Balances.ts index 4a429dd96..b977d7611 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/ensureErc20Balances.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/ensureErc20Balances.ts @@ -1,45 +1,34 @@ -import { conceroChains } from "../liveChains"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { conceroChains, ProxyEnum, viemReceiptConfig } from "../../../constants"; +import { getEnvAddress, getFallbackClients } from "../../../utils"; import { privateKeyToAccount } from "viem/accounts"; import { task } from "hardhat/config"; import { erc20Abi, formatEther, parseEther } from "viem"; import { type CNetwork } from "../../../types/CNetwork"; import log, { err } from "../../../utils/log"; import readline from "readline"; -import { ProxyType, viemReceiptConfig } from "../../../constants/deploymentVariables"; -import { getEnvAddress } from "../../../utils/getEnvVar"; import checkERC20Balance from "./checkERC20Balance"; +import { type BalanceInfo } from "./types"; const donorAccount = privateKeyToAccount(`0x${process.env.DEPLOYER_PRIVATE_KEY}`); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const prompt = (question: string): Promise => new Promise(resolve => rl.question(question, resolve)); -interface BalanceInfo { - chain: CNetwork; - balance: bigint; - deficit: bigint; - donorBalance: bigint; - contractType: ProxyType; - address: string; - alias: string; -} - -const minBalances: Record = { +const minBalances: Record = { parentPoolProxy: parseEther("7"), childPoolProxy: parseEther("1"), - infraProxy: parseEther("1"), + infraProxy: parseEther("5"), }; -async function checkChainBalance(chain: CNetwork, contractType: ProxyType): Promise { +async function checkChainBalance(chain: CNetwork, contractType: ProxyEnum): Promise { const { linkToken } = chain; const minBalance = minBalances[contractType]; const [address, alias] = getEnvAddress(contractType, chain.name); - const balance = await checkERC20Balance(chain, linkToken, address); + const { balance } = await checkERC20Balance(chain, linkToken, address); const deficit = balance < minBalance ? minBalance - balance : BigInt(0); - const donorBalance = await checkERC20Balance(chain, linkToken, donorAccount.address); + const { balance: donorBalance } = await checkERC20Balance(chain, linkToken, donorAccount.address); return { chain, address, alias, balance, deficit, donorBalance, contractType }; } diff --git a/packages/hardhat/tasks/concero/ensureBalances/ensureNativeBalances.ts b/packages/hardhat/tasks/concero/ensureBalances/ensureNativeBalances.ts index badae1286..5e1def46e 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/ensureNativeBalances.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/ensureNativeBalances.ts @@ -1,66 +1,65 @@ -import { mainnetChains, testnetChains } from "../liveChains"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { mainnetChains, messengerTargetBalances, testnetChains, viemReceiptConfig } from "../../../constants"; +import { getEnvAddress, getEnvVar, getFallbackClients } from "../../../utils"; import { privateKeyToAccount } from "viem/accounts"; import { task } from "hardhat/config"; import { formatEther, parseEther } from "viem"; import { type CNetwork } from "../../../types/CNetwork"; import log, { err } from "../../../utils/log"; import { type BalanceInfo } from "./types"; -import { getEnvVar } from "../../../utils/getEnvVar"; import readline from "readline"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; -import { messengerTargetBalances } from "../../../constants/targetBalances"; - -const donorAccount = privateKeyToAccount(`0x${process.env.DEPLOYER_PRIVATE_KEY}`); - +const donorAccount = privateKeyToAccount(`0x${getEnvVar("DEPLOYER_PRIVATE_KEY")}`); const wallets = [ - getEnvVar("MESSENGER_0_ADDRESS"), - getEnvVar("POOL_MESSENGER_0_ADDRESS") + getEnvAddress("poolMessenger0"), + getEnvAddress("infraMessenger0"), + // getEnvAddress("infraMessenger1"), + // getEnvAddress("infraMessenger2"), ]; const prompt = (question: string): Promise => new Promise(resolve => rl.question(question, resolve)); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); -export async function ensureWalletBalance(wallet: string, targetBalances: Record, chain: CNetwork) { - const balance = await checkWalletBalance(wallet, targetBalances, chain); - const displayedWalletBalances = { - chain: balance.chain.name, - address: balance.address, - balance: balance.balance, - target: balance.target, - deficit: balance.deficit, - }; - - if (parseFloat(balance.deficit) > 0) { - err( - `Insufficient balance for ${wallet}. Balance: ${balance.balance}. Deficit: ${balance.deficit}`, - "ensureWalletBalance", - chain.name, - ); - throw new Error(); - } - console.table([displayedWalletBalances]); - return balance; -} - -export async function checkWalletBalance( - wallet: string, +// export async function ensureWalletBalance(wallet: string, targetBalances: Record, chain: CNetwork) { +// const balance = await checkNativeBalance(wallet, targetBalances, chain); +// const displayedWalletBalances = { +// chain: balance.chain.name, +// address: balance.address, +// balance: balance.balance, +// targetBalance: balance.targetBalance, +// deficit: balance.deficit, +// }; +// +// if (parseFloat(balance.deficit) > 0) { +// err( +// `Insufficient balance for ${wallet}. Balance: ${balance.balance}. Deficit: ${balance.deficit}`, +// "ensureWalletBalance", +// chain.name, +// ); +// throw new Error(); +// } +// console.table([displayedWalletBalances]); +// return balance; +// } + +async function checkNativeBalance( + address: string, + alias: string, targetBalances: Record, chain: CNetwork, ): Promise { const { publicClient } = getFallbackClients(chain); - - const balance = await publicClient.getBalance({ address: wallet }); + const balance = await publicClient.getBalance({ address }); const targetBalance = targetBalances[chain.name] || BigInt(0); const deficit = balance < targetBalance ? targetBalance - balance : BigInt(0); return { chain, - address: wallet, - balance: formatEther(balance), - target: formatEther(targetBalance), - deficit: formatEther(deficit), + address, + alias, + balance, + donorBalance: BigInt(0), + targetBalance, + deficit, }; } @@ -81,66 +80,63 @@ async function topUpWallet(wallet: string, publicClient: any, walletClient: any, } } -async function getBalanceInfo(targetAddresses: [], chain: CNetwork): Promise { - const walletInfos: BalanceInfo[] = []; - for (const wallet of targetAddresses) { - const walletInfo = await checkWalletBalance(wallet, messengerTargetBalances, chain); - walletInfos.push(walletInfo); - } - - return walletInfos; +async function getBalanceInfo(addresses: [string, string][], chain: CNetwork): Promise { + const balancePromises = addresses.map(([address, alias]) => + checkNativeBalance(address, alias, messengerTargetBalances, chain), + ); + return await Promise.all(balancePromises); } async function performTopUps(walletBalances: BalanceInfo[], donorAccount: any): Promise { - for (const walletInfo of walletBalances) { + const topUpPromises = walletBalances.map(async walletInfo => { const deficit = parseEther(walletInfo.deficit); - if (deficit > BigInt(0)) { const { publicClient, walletClient } = getFallbackClients(walletInfo.chain, donorAccount); await topUpWallet(walletInfo.address, publicClient, walletClient, deficit); } - } + }); + await Promise.all(topUpPromises); } async function ensureNativeBalances(isTestnet: boolean) { - const donorBalances: BalanceInfo[] = []; - const walletBalances: BalanceInfo[] = []; const chains = isTestnet ? testnetChains : mainnetChains; + const allBalances: Record = {}; try { - for (const chain of chains) { + const balancePromises = chains.map(async chain => { const walletInfos = await getBalanceInfo(wallets, chain); - const donorInfo = await getBalanceInfo([donorAccount.address], chain); - - donorBalances.push(...donorInfo); - walletBalances.push(...walletInfos); - } - - const displayedDonorBalances = donorBalances.map(info => ({ - chain: info.chain.name, - balance: info.balance, - })); - - const displayedWalletBalances = walletBalances.map(info => ({ - chain: info.chain.name, - address: info.address, - balance: info.balance, - target: info.target, - deficit: info.deficit, - })); + const donorInfo = await getBalanceInfo([[donorAccount.address, "Donor"]], chain); + allBalances[chain.name] = [...walletInfos, ...donorInfo]; + }); - console.log("\nDonor Balances:"); - console.table(displayedDonorBalances); + await Promise.all(balancePromises); + + const displayedBalances = Object.entries(allBalances).flatMap(([chainName, balances]) => { + const donorBalance = balances.find(b => b.alias === "Donor"); + return balances + .filter(b => b.alias !== "Donor") + .map(info => ({ + chain: chainName, + address: info.alias, + balance: formatEther(info.balance), + target: formatEther(info.targetBalance), + deficit: formatEther(info.deficit), + donorBalance: formatEther(donorBalance?.balance || BigInt(0)), + })); + }); - console.log("\nWallet Balances:"); - console.table(displayedWalletBalances); + console.log("\nWallet and Donor Balances:"); + console.table(displayedBalances); - const totalDeficit = walletBalances.reduce((sum, info) => sum + parseFloat(info.deficit), 0); + const totalDeficit = displayedBalances.reduce((sum, info) => sum + parseFloat(info.deficit), 0); if (totalDeficit > 0) { const answer = await prompt( - `Do you want to perform top-ups for a total of ${totalDeficit.toFixed(6)} ETH? (y/n): `, + `Do you want to perform top-ups for a total of ${formatEther(totalDeficit)} ETH? (y/n): `, ); if (answer.toLowerCase() === "y") { + const walletBalances = Object.values(allBalances) + .flat() + .filter(b => b.alias !== "Donor"); await performTopUps(walletBalances, donorAccount); } else { console.log("Top-ups cancelled."); diff --git a/packages/hardhat/tasks/concero/ensureBalances/types.ts b/packages/hardhat/tasks/concero/ensureBalances/types.ts index e7b9fa2e8..60d966bd8 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/types.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/types.ts @@ -1,9 +1,16 @@ import type { CNetwork } from "../../../types/CNetwork"; +import { ProxyEnum } from "../../../constants/deploymentVariables"; export interface BalanceInfo { chain: CNetwork; - address: string; - balance: string; - target: string; - deficit: string; + balance: bigint; + donorBalance: bigint; + deficit: bigint; + targetBalance: bigint; + id?: string; + type?: ProxyEnum; + symbol?: string; + decimals?: number; + address?: string; + alias?: string; } diff --git a/packages/hardhat/tasks/concero/ensureBalances/viewTokenBalances.ts b/packages/hardhat/tasks/concero/ensureBalances/viewTokenBalances.ts index 65abb43b0..f17212e52 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/viewTokenBalances.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/viewTokenBalances.ts @@ -1,21 +1,9 @@ -import { mainnetChains, testnetChains } from "../liveChains"; -import { getFallbackClients } from "../../../utils/getViemClients"; +import { mainnetChains, networkEnvKeys, ProxyEnum, testnetChains } from "../../../constants"; +import { err, getEnvAddress, getEnvVar, getFallbackClients } from "../../../utils"; import { task } from "hardhat/config"; import { erc20Abi, formatUnits } from "viem"; import { type CNetwork } from "../../../types/CNetwork"; -import { err } from "../../../utils/log"; -import { ProxyType } from "../../../constants/deploymentVariables"; -import { getEnvAddress, getEnvVar } from "../../../utils/getEnvVar"; -import { networkEnvKeys } from "../../../constants/CNetworks"; - -interface BalanceInfo { - chainName: string; - contractAddress: string; - contractAlias: string; - symbol: string; - balance: bigint; - tokenDecimals: number; -} +import { BalanceInfo } from "./types"; const tokensToMonitor = [ { symbol: "USDC", decimals: 6 }, @@ -24,7 +12,7 @@ const tokensToMonitor = [ async function checkTokenBalance( chain: CNetwork, - contractType: ProxyType, + contractType: ProxyEnum, symbol: string, tokenDecimals: number, ): Promise { @@ -59,7 +47,7 @@ async function monitorTokenBalances(isTestnet: boolean): Promise for (const chain of Object.values(chains)) { for (const token of tokensToMonitor) { - balancePromises.push(checkTokenBalance(chain, "infraProxy", token.symbol, token.decimals)); + balancePromises.push(checkTokenBalance(chain, ProxyEnum.infraProxy, token.symbol, token.decimals)); } } diff --git a/packages/hardhat/tasks/concero/ensureBalances/withdrawTokens.ts b/packages/hardhat/tasks/concero/ensureBalances/withdrawTokens.ts index f9a0d6e99..3a5c41707 100644 --- a/packages/hardhat/tasks/concero/ensureBalances/withdrawTokens.ts +++ b/packages/hardhat/tasks/concero/ensureBalances/withdrawTokens.ts @@ -1,14 +1,14 @@ import { task } from "hardhat/config"; -import monitorTokenBalances, { BalanceInfo } from "./viewTokenBalances"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import { getEnvVar } from "../../../utils/getEnvVar"; -import CNetworks, { networkEnvKeys } from "../../../constants/CNetworks"; -import load from "../../../utils/load"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; +import monitorTokenBalances from "./viewTokenBalances"; +import { getEnvVar, getFallbackClients } from "../../../utils"; +import cNetworks, { networkEnvKeys } from "../../../constants/cNetworks"; +import { viemReceiptConfig } from "../../../constants"; import log from "../../../utils/log"; +import { formatUnits } from "viem"; +import { type BalanceInfo } from "./types"; async function withdrawTokens(isTestnet: boolean) { - const { abi } = await load("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); + const { abi } = await import("../../../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); // Step 1: Get balances const balances: BalanceInfo[] = await monitorTokenBalances(isTestnet); @@ -43,7 +43,7 @@ async function withdrawTokens(isTestnet: boolean) { // Step 4: Withdraw the tokens for (const token of tokensWithBalance) { const { chainName, contractAddress, symbol, balance } = token; - const chain = CNetworks[chainName]; + const chain = cNetworks[chainName]; const viemChain = chain.viemChain; const tokenAddress = getEnvVar(`${symbol}_${networkEnvKeys[chainName]}`); @@ -65,7 +65,7 @@ async function withdrawTokens(isTestnet: boolean) { hash, }); - log(`Withdrawn ${balance} ${symbol}(Gas Used: ${cumulativeGasUsed})`, "withdrawToken", chain.name); + log(`Withdrawn ${formatUnits(balance, 6)} ${symbol}(Gas Used: ${cumulativeGasUsed})`, "withdrawToken", chain.name); } } diff --git a/packages/hardhat/tasks/concero/fundContract.ts b/packages/hardhat/tasks/concero/fundContract.ts index 232801d06..5eabfe461 100644 --- a/packages/hardhat/tasks/concero/fundContract.ts +++ b/packages/hardhat/tasks/concero/fundContract.ts @@ -1,12 +1,12 @@ import { CNetwork } from "../../types/CNetwork"; import ierc20Abi from "@chainlink/contracts/abi/v0.8/IERC20.json"; -import chains, { networkEnvKeys } from "../../constants/CNetworks"; +import chains, { networkEnvKeys } from "../../constants/cNetworks"; import { dripBnm } from "./dripBnm"; import { task } from "hardhat/config"; import { liveChains } from "./deployInfra/deployInfra"; -import { getEnvVar } from "../../utils/getEnvVar"; +import { getEnvVar } from "../../utils"; import log, { err } from "../../utils/log"; -import { viemReceiptConfig } from "../../constants/deploymentVariables"; +import { viemReceiptConfig } from "../../constants"; export async function ensureDeployerBnMBalance(chains: CNetwork[]) { //checks balance of CCIPBnm of deployer @@ -29,6 +29,7 @@ export async function ensureDeployerBnMBalance(chains: CNetwork[]) { } } } + export async function fundContract(chains: CNetwork[], amount: number = 1) { for (const chain of chains) { const { name, viemChain, ccipBnmToken, url } = chain; diff --git a/packages/hardhat/tasks/concero/fundSubscription.ts b/packages/hardhat/tasks/concero/fundSubscription.ts index d9860620e..d59f8f6f7 100644 --- a/packages/hardhat/tasks/concero/fundSubscription.ts +++ b/packages/hardhat/tasks/concero/fundSubscription.ts @@ -3,7 +3,8 @@ import functionsRouterAbi from "@chainlink/contracts/abi/v0.8/FunctionsRouter.js import linkTokenAbi from "@chainlink/contracts/abi/v0.8/LinkToken.json"; import { CNetwork } from "../../types/CNetwork"; import log from "../../utils/log"; -import { viemReceiptConfig } from "../../constants/deploymentVariables"; +import { viemReceiptConfig } from "../../constants"; +import { getFallbackClients } from "../../utils"; export async function fundSubscription(selectedChains: CNetwork[]) { for (const chain of selectedChains) { diff --git a/packages/hardhat/tasks/concero/test.ts b/packages/hardhat/tasks/concero/test.ts index 9d47e6397..7522fe148 100644 --- a/packages/hardhat/tasks/concero/test.ts +++ b/packages/hardhat/tasks/concero/test.ts @@ -1,5 +1,5 @@ import { task } from "hardhat/config"; -import CNetworks from "../../constants/CNetworks"; +import cNetworks from "../../constants/cNetworks"; function getHashSum(sourceCode: string) { const hash = require("crypto").createHash("sha256"); @@ -9,15 +9,15 @@ function getHashSum(sourceCode: string) { task("test-script", "A test script").setAction(async taskArgs => { console.log(hre.network.name); - const chain = CNetworks[hre.network.name]; + const chain = cNetworks[hre.network.name]; console.log("Running test-script"); // const [conceroProxy, conceroProxyAlias] = getEnvAddress("infraProxy", chain.name); // console.log(conceroProxy, conceroProxyAlias); - // await deployProxyAdmin(hre, ProxyType.parentPool); - // await deployTransparentProxy(hre, ProxyType.parentPool); - // await upgradeProxyImplementation(hre, ProxyType.parentPool, false); + // await deployProxyAdmin(hre, ProxyEnum.parentPool); + // await deployTransparentProxy(hre, ProxyEnum.parentPool); + // await upgradeProxyImplementation(hre, ProxyEnum.parentPool, false); }); export default {}; diff --git a/packages/hardhat/tasks/concero/transferTokens.ts b/packages/hardhat/tasks/concero/transferTokens.ts index 481c3cb22..d0945e318 100644 --- a/packages/hardhat/tasks/concero/transferTokens.ts +++ b/packages/hardhat/tasks/concero/transferTokens.ts @@ -1,6 +1,6 @@ import { ethers } from "ethers"; import { createPublicClient } from "viem"; -import chains from "../../constants/CNetworks"; +import chains from "../../constants/cNetworks"; import { BigNumber } from "ethers-v5"; import { task } from "hardhat/config"; import { multicall } from "viem/actions"; diff --git a/packages/hardhat/tasks/concero/upgradeProxyImplementation.ts b/packages/hardhat/tasks/concero/upgradeProxyImplementation.ts index d486cfcf4..ee5b0ea9b 100644 --- a/packages/hardhat/tasks/concero/upgradeProxyImplementation.ts +++ b/packages/hardhat/tasks/concero/upgradeProxyImplementation.ts @@ -1,31 +1,26 @@ import { getEnvAddress } from "../../utils/getEnvVar"; -import CNetworks from "../../constants/CNetworks"; +import cNetworks from "../../constants/cNetworks"; import { privateKeyToAccount } from "viem/accounts"; import log, { err } from "../../utils/log"; import { task } from "hardhat/config"; import { getFallbackClients } from "../../utils/getViemClients"; -import { - DeploymentPrefixes, - type IProxyType, - ProxyType, - viemReceiptConfig, - writeContractConfig, -} from "../../constants/deploymentVariables"; +import { ProxyEnum, viemReceiptConfig, writeContractConfig } from "../../constants/deploymentVariables"; import { formatGas } from "../../utils/formatting"; +import { EnvPrefixes, IProxyType } from "../../types/deploymentVariables"; export async function upgradeProxyImplementation(hre, proxyType: IProxyType, shouldPause: boolean) { const { name: chainName } = hre.network; - const { viemChain } = CNetworks[chainName]; + const { viemChain } = cNetworks[chainName]; - let implementationKey: keyof DeploymentPrefixes; + let implementationKey: keyof EnvPrefixes; if (shouldPause) { implementationKey = "pause"; - } else if (proxyType === ProxyType.infraProxy) { + } else if (proxyType === ProxyEnum.infraProxy) { implementationKey = "orchestrator"; - } else if (proxyType === ProxyType.childPoolProxy) { + } else if (proxyType === ProxyEnum.childPoolProxy) { implementationKey = "childPool"; - } else if (proxyType === ProxyType.parentPoolProxy) { + } else if (proxyType === ProxyEnum.parentPoolProxy) { implementationKey = "parentPool"; } else { err(`Proxy type ${proxyType} not found`, "upgradeProxyImplementation", chainName); @@ -37,7 +32,7 @@ export async function upgradeProxyImplementation(hre, proxyType: IProxyType, sho ); const viemAccount = privateKeyToAccount(`0x${process.env.PROXY_DEPLOYER_PRIVATE_KEY}`); - const { walletClient, publicClient } = getFallbackClients(CNetworks[chainName], viemAccount); + const { walletClient, publicClient } = getFallbackClients(cNetworks[chainName], viemAccount); const [conceroProxy, conceroProxyAlias] = getEnvAddress(proxyType, chainName); const [proxyAdmin, proxyAdminAlias] = getEnvAddress(`${proxyType}Admin`, chainName); @@ -65,6 +60,7 @@ export async function upgradeProxyImplementation(hre, proxyType: IProxyType, sho chainName, ); } + export default {}; task("upgrade-proxy-implementation", "Upgrades the proxy implementation") diff --git a/packages/hardhat/tasks/concero/withdraw/withdrawInfraProxy.ts b/packages/hardhat/tasks/concero/withdraw/withdrawInfraProxy.ts index 016a7f36d..2ad94725e 100644 --- a/packages/hardhat/tasks/concero/withdraw/withdrawInfraProxy.ts +++ b/packages/hardhat/tasks/concero/withdraw/withdrawInfraProxy.ts @@ -1,12 +1,10 @@ import { task } from "hardhat/config"; -import chains, { networkEnvKeys } from "../../../constants/CNetworks"; +import chains, { networkEnvKeys } from "../../../constants/cNetworks"; import { CNetwork } from "../../../types/CNetwork"; -import { getFallbackClients } from "../../../utils/getViemClients"; -import { getEnvVar } from "../../../utils/getEnvVar"; +import { getEnvVar, getFallbackClients } from "../../../utils"; import { Address, erc20Abi } from "viem"; import log, { err } from "../../../utils/log"; -import load from "../../../utils/load"; -import { viemReceiptConfig } from "../../../constants/deploymentVariables"; +import { viemReceiptConfig } from "../../../constants"; const getBalance = async (tokenAddress: Address, account: Address, chain: CNetwork) => { const { publicClient } = getFallbackClients(chain); @@ -31,7 +29,7 @@ const withdrawToken = async (chain: CNetwork, tokenAddress: Address, contractTyp const { url: dcUrl, viemChain: dcViemChain, name: dcName } = chain; const { walletClient, publicClient, account } = getFallbackClients(chain); const conceroProxy = getEnvVar(`${contractKeys[contractType]}_${networkEnvKeys[dcName]}`); - const { abi } = await load("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); + const { abi } = await import("../artifacts/contracts/Orchestrator.sol/Orchestrator.json"); const amountToWithdraw = BigInt(amount); try { const usdBalance = await getBalance(tokenAddress, conceroProxy, chain); diff --git a/packages/hardhat/tasks/concero/withdraw/withdrawParentPoolDepositFee.ts b/packages/hardhat/tasks/concero/withdraw/withdrawParentPoolDepositFee.ts index 5d4f0ace2..629c318b4 100644 --- a/packages/hardhat/tasks/concero/withdraw/withdrawParentPoolDepositFee.ts +++ b/packages/hardhat/tasks/concero/withdraw/withdrawParentPoolDepositFee.ts @@ -1,16 +1,14 @@ import { task } from "hardhat/config"; -import chains from "../../../constants/CNetworks"; +import chains from "../../../constants/cNetworks"; import { CNetwork } from "../../../types/CNetwork"; -import { getClients } from "../../../utils/getViemClients"; -import { getEnvVar } from "../../../utils/getEnvVar"; +import { getClients, getEnvVar } from "../../../utils"; import log, { err } from "../../../utils/log"; -import load from "../../../utils/load"; const withdrawToken = async (chain: CNetwork) => { const { url: dcUrl, viemChain: dcViemChain, name: dcName } = chain; const { walletClient, publicClient, account } = getClients(dcViemChain, dcUrl); const conceroProxy = getEnvVar(`PARENT_POOL_PROXY_BASE`); - const { abi } = await load("../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"); + const { abi } = await import("../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"); try { const { request: withdrawReq } = await publicClient.simulateContract({ diff --git a/packages/hardhat/test/Bridge.ts b/packages/hardhat/test/Bridge.ts index 8c51e2c00..efb9ce351 100644 --- a/packages/hardhat/test/Bridge.ts +++ b/packages/hardhat/test/Bridge.ts @@ -3,7 +3,7 @@ import { formatUnits } from "viem"; import ERC20ABI from "../abi/ERC20.json"; import { abi as ConceroOrchestratorAbi } from "../artifacts/contracts/Orchestrator.sol/Orchestrator.json"; import { getFallbackClients } from "../utils/getViemClients"; -import chains from "../constants/CNetworks"; +import chains from "../constants/cNetworks"; import log from "../utils/log"; import { PublicClient } from "viem/clients/createPublicClient"; import { WalletClient } from "viem/clients/createWalletClient"; diff --git a/packages/hardhat/test/DexSwap.ts b/packages/hardhat/test/DexSwap.ts index 1d5e3ec98..56e9ccd56 100644 --- a/packages/hardhat/test/DexSwap.ts +++ b/packages/hardhat/test/DexSwap.ts @@ -3,7 +3,7 @@ import { encodeAbiParameters, formatUnits } from "viem"; import ERC20ABI from "../abi/ERC20.json"; import { abi as ConceroOrchestratorAbi } from "../artifacts/contracts/Orchestrator.sol/Orchestrator.json"; import { getFallbackClients } from "../utils/getViemClients"; -import chains from "../constants/CNetworks"; +import chains from "../constants/cNetworks"; import log from "../utils/log"; import { PublicClient } from "viem/clients/createPublicClient"; import { WalletClient } from "viem/clients/createWalletClient"; diff --git a/packages/hardhat/types/CLFSecrets.ts b/packages/hardhat/types/CLFSecrets.ts new file mode 100644 index 000000000..ef468801f --- /dev/null +++ b/packages/hardhat/types/CLFSecrets.ts @@ -0,0 +1,9 @@ +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; +}; diff --git a/packages/hardhat/types/CNetwork.d.ts b/packages/hardhat/types/CNetwork.d.ts index bdf8cf9ed..daad054d5 100644 --- a/packages/hardhat/types/CNetwork.d.ts +++ b/packages/hardhat/types/CNetwork.d.ts @@ -2,12 +2,14 @@ import { NetworkUserConfig } from "hardhat/types"; import { HttpNetworkUserConfig } from "hardhat/src/types/config"; import { Chain } from "viem"; -import { NetworkType } from "../constants/CNetworks"; export type envString = string | undefined; + export type CNetworkNames = "localhost" | "mainnet" | "arbitrum" | "optimism" | "polygon" | "polygonZkEvm" | "avalanche" | "base" | "sepolia" | "optimismSepolia" | "arbitrumSepolia" | "avalancheFuji" | "baseSepolia" | "polygonAmoy"; +export type NetworkType = "mainnet" | "testnet"; + export type CLFNetwork = { saveDeployments: boolean; functionsRouter: envString; diff --git a/packages/hardhat/types/chains.ts b/packages/hardhat/types/chains.ts new file mode 100644 index 000000000..ec81e38b5 --- /dev/null +++ b/packages/hardhat/types/chains.ts @@ -0,0 +1,14 @@ +import { CNetwork } from "./CNetwork"; + +export interface ConceroChains { + testnet: { + parentPool: CNetwork[]; + childPool: CNetwork[]; + infra: CNetwork[]; + }; + mainnet: { + parentPool: CNetwork[]; + childPool: CNetwork[]; + infra: CNetwork[]; + }; +} diff --git a/packages/hardhat/types/deploymentVariables.ts b/packages/hardhat/types/deploymentVariables.ts new file mode 100644 index 000000000..0f26642a5 --- /dev/null +++ b/packages/hardhat/types/deploymentVariables.ts @@ -0,0 +1,36 @@ +import { ProxyEnum } from "../constants/deploymentVariables"; + +export type IProxyType = keyof typeof ProxyEnum; + +type ProxyEnvPrefixes = { + [key in ProxyEnum]: string; +}; +export type EnvPrefixes = ProxyEnvPrefixes & { + 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; +}; +/** + * Update an environment variable in the .env file + * @param key The key of the environment variable to update + * @param newValue The new value of the environment variable + * @param envFileName The name of the .env file to update + * usage: // updateEnvVariable("CLF_DON_SECRETS_VERSION_SEPOLIA", "1712841283", "../../../.env.clf"); + */ +export type EnvFileName = "cla" | "clf" | "ccip" | "deployments.mainnet" | "deployments.testnet" | "apikeys" | "tokens"; diff --git a/packages/hardhat/utils/dotenvConfig.ts b/packages/hardhat/utils/dotenvConfig.ts index 8006922ac..6ecf84a3b 100644 --- a/packages/hardhat/utils/dotenvConfig.ts +++ b/packages/hardhat/utils/dotenvConfig.ts @@ -24,7 +24,7 @@ function configureDotEnv(basePath = "../../") { } configureDotEnv(); -export function reloadDotEnv(basePath = "../../") { +function reloadDotEnv(basePath = "../../") { const normalizedBasePath = basePath.endsWith("/") ? basePath : `${basePath}/`; ENV_FILES.forEach(file => { diff --git a/packages/hardhat/utils/getEnvVar.ts b/packages/hardhat/utils/getEnvVar.ts index cce58989d..37f7ce284 100644 --- a/packages/hardhat/utils/getEnvVar.ts +++ b/packages/hardhat/utils/getEnvVar.ts @@ -1,28 +1,24 @@ import { type env } from "../types/env"; import process from "process"; import { shorten } from "./formatting"; -import { networkEnvKeys } from "../constants/CNetworks"; -import { deploymentPrefixes, DeploymentPrefixes } from "../constants/deploymentVariables"; +import { envPrefixes, networkEnvKeys } from "../constants"; import { CNetworkNames } from "../types/CNetwork"; import { Address } from "viem"; +import { EnvPrefixes } from "../types/deploymentVariables"; -export function getEnvVar(key: keyof env): string { +function getEnvVar(key: keyof env): string { const value = process.env[key]; if (value === undefined) throw new Error(`Missing required environment variable ${key}`); if (value === "") throw new Error(`${key} must not be empty`); return value; } -export function getEnvAddress( - prefix: keyof DeploymentPrefixes, - networkName?: CNetworkNames | string, -): [Address, string] { - const searchKey = networkName - ? `${deploymentPrefixes[prefix]}_${networkEnvKeys[networkName]}` - : deploymentPrefixes[prefix]; - +function getEnvAddress(prefix: keyof EnvPrefixes, networkName?: CNetworkNames | string): [Address, string] { + const searchKey = networkName ? `${envPrefixes[prefix]}_${networkEnvKeys[networkName]}` : envPrefixes[prefix]; const value = getEnvVar(searchKey) as Address; const friendlyName = `${prefix}(${shorten(value)})`; return [value, friendlyName]; } + +export { getEnvVar, getEnvAddress }; diff --git a/packages/hardhat/utils/getEthersSignerAndProvider.ts b/packages/hardhat/utils/getEthersSignerAndProvider.ts index 1c90dc1d9..26682e5dc 100644 --- a/packages/hardhat/utils/getEthersSignerAndProvider.ts +++ b/packages/hardhat/utils/getEthersSignerAndProvider.ts @@ -1,6 +1,6 @@ import { ethers } from "ethers-v5"; import { ethers as ethersv6 } from "ethers"; -import { urls } from "../constants/rpcUrls"; +import { urls } from "../constants"; import { type CNetworkNames } from "../types/CNetwork"; //todo: deployer PK to be passed as arg //todo: rename to getEthersV5SignerAndProvider diff --git a/packages/hardhat/utils/index.ts b/packages/hardhat/utils/index.ts new file mode 100644 index 000000000..e8fbe33e4 --- /dev/null +++ b/packages/hardhat/utils/index.ts @@ -0,0 +1,35 @@ +import { compileContracts } from "./compileContracts"; +import configureDotEnv from "./dotenvConfig"; +import { formatGas, shorten } from "./formatting"; +import { + getEthersSignerAndProvider, + getEthersV5FallbackSignerAndProvider, + getEthersV6FallbackSignerAndProvider, + getEthersV6SignerAndProvider, +} from "./getEthersSignerAndProvider"; +import getHashSum from "./getHashSum"; +import { getClients, getFallbackClients } from "./getViemClients"; +import { err, log, warn } from "./log"; +import { getEnvAddress, getEnvVar } from "./getEnvVar"; +import { updateEnvAddress, updateEnvVariable } from "./updateEnvVariable"; + +export { + compileContracts, + configureDotEnv, + shorten, + formatGas, + getEnvVar, + getEnvAddress, + getEthersV5FallbackSignerAndProvider, + getEthersSignerAndProvider, + getEthersV6FallbackSignerAndProvider, + getEthersV6SignerAndProvider, + getHashSum, + getClients, + getFallbackClients, + log, + warn, + err, + updateEnvVariable, + updateEnvAddress, +}; diff --git a/packages/hardhat/utils/load.ts b/packages/hardhat/utils/load.ts deleted file mode 100644 index 0423281a3..000000000 --- a/packages/hardhat/utils/load.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* -Tries to load file asynchroniously -WARNING: path must be relative to THIS FILE, not the file that uses the function. -*/ -async function load(path: string) { - return await import(path); -} - -export default load; diff --git a/packages/hardhat/utils/log.ts b/packages/hardhat/utils/log.ts index 4ebac04ed..837a89f72 100644 --- a/packages/hardhat/utils/log.ts +++ b/packages/hardhat/utils/log.ts @@ -1,6 +1,6 @@ import { CNetworkNames } from "../types/CNetwork"; -export const networkColors: Record = { +const networkColors: Record = { mainnet: "\x1b[30m", // grey arbitrum: "\x1b[34m", // blue polygon: "\x1b[35m", // magenta diff --git a/packages/hardhat/utils/updateEnvVariable.ts b/packages/hardhat/utils/updateEnvVariable.ts index 52bec8fdf..0643f79ed 100644 --- a/packages/hardhat/utils/updateEnvVariable.ts +++ b/packages/hardhat/utils/updateEnvVariable.ts @@ -1,20 +1,11 @@ import { readFileSync, writeFileSync } from "fs"; import path from "path"; import log from "./log"; -import { deploymentPrefixes, DeploymentPrefixes } from "../constants/deploymentVariables"; +import { envPrefixes, networkEnvKeys } from "../constants"; import { CNetworkNames } from "../types/CNetwork"; -import { networkEnvKeys } from "../constants/CNetworks"; - -/** - * Update an environment variable in the .env file - * @param key The key of the environment variable to update - * @param newValue The new value of the environment variable - * @param envFileName The name of the .env file to update - * usage: // updateEnvVariable("CLF_DON_SECRETS_VERSION_SEPOLIA", "1712841283", "../../../.env.clf"); - */ -type EnvFileName = "cla" | "clf" | "ccip" | "deployments.mainnet" | "deployments.testnet" | "apikeys" | "tokens"; - -function updateEnvVariable(key: string, newValue: string, envFileName: EnvFileName) { +import { EnvFileName, EnvPrefixes } from "../types/deploymentVariables"; + +export function updateEnvVariable(key: string, newValue: string, envFileName: EnvFileName) { const filePath = path.join(__dirname, `../../../.env.${envFileName}`); if (!filePath) throw new Error(`File not found: ${filePath}`); @@ -39,14 +30,12 @@ function updateEnvVariable(key: string, newValue: string, envFileName: EnvFileNa } export function updateEnvAddress( - prefix: keyof DeploymentPrefixes, + prefix: keyof EnvPrefixes, networkPostfix?: CNetworkNames | string, newValue: string, envFileName: EnvFileName, ): void { - const searchKey = networkPostfix - ? `${deploymentPrefixes[prefix]}_${networkEnvKeys[networkPostfix]}` - : deploymentPrefixes[prefix]; + const searchKey = networkPostfix ? `${envPrefixes[prefix]}_${networkEnvKeys[networkPostfix]}` : envPrefixes[prefix]; updateEnvVariable(searchKey, newValue, envFileName); }