diff --git a/tasks/enableL1TokenAcrossEcosystem.ts b/tasks/enableL1TokenAcrossEcosystem.ts index ba0988d23..cf92201fe 100644 --- a/tasks/enableL1TokenAcrossEcosystem.ts +++ b/tasks/enableL1TokenAcrossEcosystem.ts @@ -1,4 +1,4 @@ -import { task } from "hardhat/config"; +import { task, types } from "hardhat/config"; import assert from "assert"; import { CHAIN_IDs, MAINNET_CHAIN_IDs, TESTNET_CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants"; import { askYesNoQuestion, resolveTokenOnChain, isTokenSymbol, minimalSpokePoolInterface } from "./utils"; @@ -28,6 +28,7 @@ task("enable-l1-token-across-ecosystem", "Enable a provided token across the ent .addFlag("disableRoutes", "Set to disable deposit routes for the specified chains") .addParam("token", "Symbol of token to enable") .addOptionalParam("chains", "Comma-delimited list of chains to enable the token on. Defaults to all supported chains") + .addOptionalParam("lpAmount", "Amount of LP token to burn when enabling a new token", 1, types.int) .addOptionalParam( "customoptimismbridge", "Custom token bridge to set for optimism, for example used with SNX and DAI" @@ -47,8 +48,8 @@ task("enable-l1-token-across-ecosystem", "Enable a provided token across the ent assert(isTokenSymbol(_matchedSymbol)); const matchedSymbol = _matchedSymbol as TokenSymbol; - const l1Token = TOKEN_SYMBOLS_MAP[matchedSymbol].addresses[hubChainId]; - assert(l1Token !== undefined, `Could not find ${symbol} in TOKEN_SYMBOLS_MAP`); + const l1TokenAddr = TOKEN_SYMBOLS_MAP[matchedSymbol].addresses[hubChainId]; + assert(l1TokenAddr !== undefined, `Could not find ${symbol} in TOKEN_SYMBOLS_MAP`); // If deposit routes chains are provided then we'll only add routes involving these chains. This is used to add new // deposit routes to a new chain for an existing L1 token, so we also won't add a new LP token if this is defined. @@ -62,9 +63,11 @@ task("enable-l1-token-across-ecosystem", "Enable a provided token across the ent ); if (!hasSetConfigStore) process.exit(0); - console.log(`\nRunning task to enable L1 token over entire Across ecosystem 🌉. L1 token: ${l1Token}`); + console.log(`\nRunning task to enable L1 token over entire Across ecosystem 🌉. L1 token: ${l1TokenAddr}`); const { deployments, ethers } = hre; + const { AddressZero: ZERO_ADDRESS } = ethers.constants; const [signer] = await hre.ethers.getSigners(); + const { BigNumber } = ethers; // Remove chainIds that are in the ignore list. const _enabledChainIds = enabledChainIds(hubChainId); @@ -110,14 +113,30 @@ task("enable-l1-token-across-ecosystem", "Enable a provided token across the ent // Construct calldata to enable these tokens. const callData = []; - // If deposit route chains are defined then we don't want to add a new LP token: - if (depositRouteChains.length === 0) { - console.log(`\nAdding calldata to enable liquidity provision on ${l1Token}`); - callData.push(hubPool.interface.encodeFunctionData("enableL1TokenForLiquidityProvision", [l1Token])); - } else { - depositRouteChains.forEach((chainId) => - assert(tokens[chainId].symbol !== NO_SYMBOL, `Token ${symbol} is not defined for chain ${chainId}`) + // If the l1 token is not yet enabled for LP, enable it. + let { lpToken } = await hubPool.pooledTokens(l1TokenAddr); + if (lpToken === ZERO_ADDRESS) { + const [lpFactoryAddr, { abi: lpFactoryABI }] = await Promise.all([ + hubPool.lpTokenFactory(), + deployments.get("LpTokenFactory"), + ]); + const lpTokenFactory = new ethers.Contract(lpFactoryAddr, lpFactoryABI, signer); + lpToken = await lpTokenFactory.callStatic.createLpToken(l1TokenAddr); + console.log(`\nAdding calldata to enable liquidity provision on ${l1TokenAddr} (LP token ${lpToken})`); + + callData.push(hubPool.interface.encodeFunctionData("enableL1TokenForLiquidityProvision", [l1TokenAddr])); + + const l1Token = (await ethers.getContractFactory("ExpandedERC20")).attach(l1TokenAddr); + const decimals = await l1Token.symbol(); + const depositAmount = BigNumber.from(taskArguments.lpAmount).mul(BigNumber.from(10).pow(decimals)); + + // Ensure to always seed the LP with at least 1 unit of the LP token. + console.log( + `\nAdding calldata to enable ensure atomic deposit of L1 token for LP token ${lpToken}` + + "\n\n\tNOTE: ENSURE TO BURN ${depositAmount} UNITS OF THE LP TOKEN AFTER EXECUTING." ); + + callData.push(hubPool.interface.encodeFunctionData("addLiquidity", [l1Token, depositAmount])); } console.log("\nAdding calldata to enable routes between all chains and tokens:");