Skip to content

improve(tasks): Auto deposit for new LP tokens #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
28 changes: 21 additions & 7 deletions tasks/enableL1TokenAcrossEcosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ task("enable-l1-token-across-ecosystem", "Enable a provided token across the ent

console.log(`\nRunning task to enable L1 token over entire Across ecosystem 🌉. L1 token: ${l1Token}`);
const { deployments, ethers } = hre;
const { AddressZero: ZERO_ADDRESS } = ethers.constants;
const [signer] = await hre.ethers.getSigners();

// Remove chainIds that are in the ignore list.
Expand Down Expand Up @@ -107,14 +108,27 @@ 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}`);
// If the l1 token is not yet enabled for LP, enable it.
let { lpToken: lpTokenAddress } = await hubPool.pooledTokens(l1Token);
if (lpTokenAddress === ZERO_ADDRESS) {
const [lpFactoryAddr, { abi: lpFactoryABI }] = await Promise.all([
hubPool.lpTokenFactory(),
deployments.get("LpTokenFactory"),
]);
const lpTokenFactory = new ethers.Contract(lpFactoryAddr, lpFactoryABI, signer);
lpTokenAddress = await lpTokenFactory.callStatic.createLpToken(l1Token);
console.log(`\nAdding calldata to enable liquidity provision on ${l1Token} (LP token ${lpTokenAddress})`);

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}`)
);

// Ensure to always seed the LP with at least 1 unit of the LP token. Burn the LP token to prevent 0 LP.
console.log(`\nAdding calldata to enable ensure atomic deposit-and-burn of LP token ${lpTokenAddress}`);

const minDeposit = "1";
callData.push(hubPool.interface.encodeFunctionData("addLiquidity", [l1Token, minDeposit]));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this implies that the owner address must have made an l1Token approval for the HubPool in advance of executing this. That should be prepended before this HubPool multicall.


const lpToken = (await ethers.getContractFactory("ExpandedERC20")).attach(lpTokenAddress);
callData.push(lpToken.interface.encodeFunctionData("transfer", [ZERO_ADDRESS, minDeposit]));
}

console.log("\nAdding calldata to enable routes between all chains and tokens:");
Expand Down
Loading