-
Notifications
You must be signed in to change notification settings - Fork 64
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
pxrl
wants to merge
11
commits into
master
Choose a base branch
from
pxrl/depositAndBurn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+30
−11
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
454f70b
improve(tasks): Auto deposit-and-burn for new LP tokens
pxrl 9f47735
reflow
pxrl 7219466
Apply suggestions from code review
pxrl 038e971
Apply suggestions from code review
pxrl b1a3d4d
Update & fix
pxrl 44e71b1
chore: Bump constants & update enable token script (#900)
pxrl 36eaca3
Make lp deposit amount configurable
pxrl 36fa204
Add type validation
pxrl 096112e
Merge remote-tracking branch 'origin/master' into pxrl/depositAndBurn
pxrl 9f72b2e
Back out bad change
pxrl 7b46d5e
fix
pxrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
@@ -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) => { | ||
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 | ||
|
@@ -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( | ||
|
@@ -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])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :(