diff --git a/packages/hardhat/deploy/00_deploy_pools.ts b/packages/hardhat/deploy/00_deploy_pools.ts index cb931a26..304ae51a 100644 --- a/packages/hardhat/deploy/00_deploy_pools.ts +++ b/packages/hardhat/deploy/00_deploy_pools.ts @@ -1,5 +1,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; +import { networkConfig } from "../helper.config"; + // import { Contract } from "ethers"; /** @@ -21,14 +23,15 @@ const deployConstantPricePool: DeployFunction = async function (hre: HardhatRunt */ const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; + const chainId = Number(await hre.ethers.provider.getNetwork().then(network => network.chainId)); - // Vault address is the same for all pools - const VAULT_ADDRESS = "0x1FC7F1F84CFE61a04224AC8D3F87f56214FeC08c"; + // Vault address is same for all pools + const { vaultAddr } = networkConfig[chainId].balancer; // Deploy ConstantPricePool const constantPoolName = "Balancer Constant Price Pool"; const constantPoolSymbol = "B-50DAI-50USDe"; - const constantPoolArgs = [VAULT_ADDRESS, constantPoolName, constantPoolSymbol]; + const constantPoolArgs = [vaultAddr, constantPoolName, constantPoolSymbol]; await deploy("ConstantPricePool", { from: deployer, @@ -39,7 +42,7 @@ const deployConstantPricePool: DeployFunction = async function (hre: HardhatRunt // Deploy DynamicPricePool const dynamicPoolName = "Balancer Dynamic Price Pool"; const dynamicPoolSymbol = "weETH/ezETH/rswETH"; - const dynamicPoolArgs = [VAULT_ADDRESS, dynamicPoolName, dynamicPoolSymbol]; + const dynamicPoolArgs = [vaultAddr, dynamicPoolName, dynamicPoolSymbol]; await deploy("DynamicPricePool", { from: deployer, diff --git a/packages/hardhat/helper.config.ts b/packages/hardhat/helper.config.ts new file mode 100644 index 00000000..2bd96737 --- /dev/null +++ b/packages/hardhat/helper.config.ts @@ -0,0 +1,26 @@ +interface NetworkConfigEntryTypes { + name: string; + balancer: { + vaultAddr: string; + vaultExtensionAddr: string; + routerAddr: string; + batchRouterAddr: string; + }; +} + +// Contracts have constructors that require contract address args that are network specific +const networkConfig: { [key: number]: NetworkConfigEntryTypes } = { + 11155111: { + name: "sepolia", + balancer: { + vaultAddr: "0x1FC7F1F84CFE61a04224AC8D3F87f56214FeC08c", + vaultExtensionAddr: "0x718e1176f01dDBb2409A77B2847B749c8dF4457f", + routerAddr: "0xA0De078cd5cFa7088821B83e0bD7545ccfb7c883", + batchRouterAddr: "0x8A8B9f35765899B3a0291700141470D79EA2eA88", + }, + }, +}; + +const developmentChains: string[] = ["hardhat", "foundry", "localhost"]; + +export { networkConfig, developmentChains }; diff --git a/packages/hardhat/scripts/registerPool.ts b/packages/hardhat/scripts/registerPool.ts new file mode 100644 index 00000000..b8ab80d5 --- /dev/null +++ b/packages/hardhat/scripts/registerPool.ts @@ -0,0 +1,85 @@ +import hre from "hardhat"; +import { networkConfig } from "../helper.config"; +import { Contract } from "ethers"; + +/** + * registerPool function + * https://github.com/balancer/balancer-v3-monorepo/blob/2ad8501c85e8afb2f25d970344af700a571b1d0b/pkg/vault/contracts/VaultExtension.sol#L130-L149 + * + * VaultTypes (TokenType, TokenConfig, IRateProvider) + * https://github.com/balancer/balancer-v3-monorepo/blob/main/pkg/interfaces/contracts/vault/VaultTypes.sol + * + */ +async function main() { + const privateKey = process.env.DEPLOYER_PRIVATE_KEY; + if (!privateKey) { + console.log("🚫️ Please set a PRIVATE_KEY var at packages/hardhat/.env"); + return; + } + if (hre.network.name !== "sepolia") { + throw new Error("This script is only configured for sepolia network"); + } + const chainId = Number(await hre.ethers.provider.getNetwork().then(network => network.chainId)); + + // grab the VaultExtension contract + const { vaultExtensionAddr } = networkConfig[chainId].balancer; + const { abi: vaultExtensionAbi } = await hre.artifacts.readArtifact("IVaultExtension"); + const [signer] = await hre.ethers.getSigners(); + const vaultExtension = await hre.ethers.getContractAt(vaultExtensionAbi, vaultExtensionAddr, signer); + + // args for registerPool + const { target: poolAddress } = await hre.ethers.getContract("ConstantPricePool", signer); + const tokenConfig = [ + { + token: "0xB77EB1A70A96fDAAeB31DB1b42F2b8b5846b2613", // sepoliaDAI + tokenType: 0, // STANDARD + rateProvider: "???", // contract address that satisfies IRateProvider? + yieldFeeExempt: false, + }, + { + token: "0x80D6d3946ed8A1Da4E226aa21CCdDc32bd127d1A", // sepoliaUSDC + tokenType: 0, // STANDARD + rateProvider: "???", // contract address that satisfies IRateProvider? + yieldFeeExempt: false, + }, + ]; + const pauseWindowEndTime = 0; // The timestamp after which it is no longer possible to pause the pool + const pauseManager = hre.ethers.ZeroAddress; // Optional contract the Vault will allow to pause the pool + const hookConfig = [ + // Flags indicating which hooks the pool supports + { + shouldCallBeforeInitialize: false, + shouldCallAfterInitialize: false, + shouldCallBeforeSwap: false, + shouldCallAfterSwap: false, + shouldCallBeforeAddLiquidity: false, + shouldCallAfterAddLiquidity: false, + shouldCallBeforeRemoveLiquidity: false, + shouldCallAfterRemoveLiquidity: false, + }, + ]; + const liquidityManagement = { + supportsAddLiquidityCustom: false, + supportsRemoveLiquidityCustom: false, + }; + + console.log("Sending tx to register pool..."); + const txResponse = await vaultExtension.registerPool( + poolAddress, + tokenConfig, + pauseWindowEndTime, + pauseManager, + hookConfig, + liquidityManagement, + ); + console.log(txResponse); + console.log("Waiting for tx to be mined..."); + const txReceipt = await txResponse.wait(); + console.log("Pool registered!!!"); + console.log(txReceipt); +} + +main().catch(error => { + console.error(error); + process.exitCode = 1; +});