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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"pre-commit-hook": "sh scripts/preCommitHook.sh"
},
"dependencies": {
"@across-protocol/constants": "^3.1.35",
"@across-protocol/constants": "^3.1.37",
"@coral-xyz/anchor": "^0.30.1",
"@defi-wonderland/smock": "^2.3.4",
"@eth-optimism/contracts": "^0.5.40",
Expand Down
52 changes: 34 additions & 18 deletions tasks/enableL1TokenAcrossEcosystem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { task } from "hardhat/config";
import assert from "assert";
import { CHAIN_IDs, MAINNET_CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants";
import { CHAIN_IDs, MAINNET_CHAIN_IDs, TESTNET_CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants";
import { askYesNoQuestion, resolveTokenOnChain, isTokenSymbol, minimalSpokePoolInterface } from "./utils";
import { TokenSymbol } from "./types";

Expand All @@ -9,13 +9,13 @@ const NO_SYMBOL = "----";
const NO_ADDRESS = "------------------------------------------";

// Supported mainnet chain IDs.
const enabledChainIds = Object.values(MAINNET_CHAIN_IDs)
.map(Number)
.filter((chainId) => chainId !== CHAIN_IDs.BOBA)
.sort((x, y) => x - y);

const chainPadding = enabledChainIds[enabledChainIds.length - 1].toString().length;
const formatChainId = (chainId: number): string => chainId.toString().padStart(chainPadding, " ");
const enabledChainIds = (hubChainId: number) => {
Copy link
Member

Choose a reason for hiding this comment

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

We should probably read this from a config store to be safe, just a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a subtle bootstrapping problem with that - it doesn't work for new chains because the entries don't exist at the point where we're using this script to generate the routes :(

const chainIds = hubChainId === CHAIN_IDs.MAINNET ? MAINNET_CHAIN_IDs : TESTNET_CHAIN_IDs;
return Object.values(chainIds)
.map(Number)
.filter((chainId) => chainId !== CHAIN_IDs.BOBA)
.sort((x, y) => x - y);
};

const getChainsFromList = (taskArgInput: string): number[] =>
taskArgInput
Expand Down Expand Up @@ -62,21 +62,23 @@ 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.
const _enabledChainIds = enabledChainIds(hubChainId);
let inputChains: number[] = [];
try {
inputChains = (chains?.split(",") ?? enabledChainIds).map(Number);
inputChains = (chains?.split(",") ?? _enabledChainIds).map(Number);
console.log(`\nParsed 'chains' argument:`, inputChains);
} catch (error) {
throw new Error(`Failed to parse 'chains' argument ${chains} as a comma-separated list of numbers.`);
}
if (inputChains.length === 0) inputChains = enabledChainIds;
if (inputChains.length === 0) inputChains = _enabledChainIds;
else if (inputChains.some((chain) => isNaN(chain) || !Number.isInteger(chain) || chain < 0)) {
throw new Error(`Invalid chains list: ${inputChains}`);
}
const chainIds = enabledChainIds.filter((chainId) => inputChains.includes(chainId));
const chainIds = _enabledChainIds.filter((chainId) => inputChains.includes(chainId));

console.log("\nLoading L2 companion token address for provided L1 token.");
const tokens = Object.fromEntries(
Expand Down Expand Up @@ -107,23 +109,37 @@ 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 } = await hubPool.pooledTokens(l1Token);
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(l1Token);
console.log(`\nAdding calldata to enable liquidity provision on ${l1Token} (LP token ${lpToken})`);

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.
console.log(
`\nAdding calldata to enable ensure atomic deposit of L1 token for LP token ${lpToken}` +
"\n\n\tNOTE: ENSURE TO BURN AT LEAST 1 UNIT OF THE LP TOKEN AFTER EXECUTING."
);
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.

}

console.log("\nAdding calldata to enable routes between all chains and tokens:");
let i = 0; // counter for logging.
const skipped: { [originChainId: number]: number[] } = {};
const routeChainIds = Object.keys(tokens).map(Number);
const chainPadding = _enabledChainIds[enabledChainIds.length - 1].toString().length;
const formatChainId = (chainId: number): string => chainId.toString().padStart(chainPadding, " ");
routeChainIds.forEach((fromId) => {
const formattedFromId = formatChainId(fromId);
const { symbol, address: inputToken } = tokens[fromId];
const { address: inputToken } = tokens[fromId];
skipped[fromId] = [];
routeChainIds.forEach((toId) => {
if (fromId === toId || [fromId, toId].some((chainId) => tokens[chainId].symbol === NO_SYMBOL)) {
Expand Down
1 change: 1 addition & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
MAINNET_CHAIN_IDs,
PRODUCTION_NETWORKS,
PUBLIC_NETWORKS,
TESTNET_CHAIN_IDs,
TOKEN_SYMBOLS_MAP,
} from "@across-protocol/constants";

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@across-protocol/constants@^3.1.35":
version "3.1.35"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.35.tgz#80ee8e569bc5c1fc94b5087d357d9612fd782151"
integrity sha512-2Fj9mqBEVQu4Bsq6o7helUkhEjpce+uqni0pTV51y1QOEQdgAJU5U5BNQFXUMUDMQRaM3DqB4ys89GVJ4TuA/w==
"@across-protocol/constants@^3.1.37":
version "3.1.37"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.37.tgz#7f1da248abe809eb9fb621f1876fbde78ec3509b"
integrity sha512-qPRntmeIDxgOwfXhPl90Mf61Fb4k20ecCc0N9Cco+5fSJE9PM4oI6Jq8VYnewyMPglYHZ1kMcdCPWYGebUs0Aw==

"@across-protocol/contracts@^0.1.4":
version "0.1.4"
Expand Down
Loading