Skip to content

Commit

Permalink
sketch out hh script for registering a pool
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Mar 19, 2024
1 parent cef98d0 commit bfb50ff
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/hardhat/deploy/00_deploy_pools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { networkConfig } from "../helper.config";

// import { Contract } from "ethers";

/**
Expand All @@ -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,
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions packages/hardhat/helper.config.ts
Original file line number Diff line number Diff line change
@@ -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 };
85 changes: 85 additions & 0 deletions packages/hardhat/scripts/registerPool.ts
Original file line number Diff line number Diff line change
@@ -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<Contract>("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;
});

0 comments on commit bfb50ff

Please sign in to comment.