diff --git a/.changeset/five-owls-learn.md b/.changeset/five-owls-learn.md new file mode 100644 index 0000000000..222e2e65f5 --- /dev/null +++ b/.changeset/five-owls-learn.md @@ -0,0 +1,5 @@ +--- +"@hyperlane-xyz/cli": patch +--- + +Add xerc20 limit lookups to warp read diff --git a/typescript/cli/src/commands/warp.ts b/typescript/cli/src/commands/warp.ts index 905d2420f0..7a1367779e 100644 --- a/typescript/cli/src/commands/warp.ts +++ b/typescript/cli/src/commands/warp.ts @@ -1,9 +1,16 @@ +import { ethers } from 'ethers'; import { stringify as yamlStringify } from 'yaml'; import { CommandModule } from 'yargs'; +import { + HypXERC20Lockbox__factory, + HypXERC20__factory, + IXERC20__factory, +} from '@hyperlane-xyz/core'; import { ChainMap, EvmERC20WarpRouteReader, + TokenStandard, WarpCoreConfig, } from '@hyperlane-xyz/sdk'; import { objMap, promiseObjAll } from '@hyperlane-xyz/utils'; @@ -18,7 +25,7 @@ import { } from '../context/types.js'; import { evaluateIfDryRunFailure } from '../deploy/dry-run.js'; import { runWarpRouteDeploy } from '../deploy/warp.js'; -import { log, logGray, logGreen, logRed } from '../logger.js'; +import { log, logGray, logGreen, logRed, logTable } from '../logger.js'; import { sendTestTransfer } from '../send/transfer.js'; import { indentYamlOrJson, writeYamlOrJson } from '../utils/files.js'; import { selectRegistryWarpRoute } from '../utils/tokens.js'; @@ -144,6 +151,45 @@ export const read: CommandModuleWithContext<{ context.registry, symbol, ); + + // TODO: merge with XERC20TokenAdapter and WarpRouteReader + const xerc20Limits = await Promise.all( + warpCoreConfig.tokens + .filter( + (t) => + t.standard === TokenStandard.EvmHypXERC20 || + t.standard === TokenStandard.EvmHypXERC20Lockbox, + ) + .map(async (t) => { + const provider = multiProvider.getProvider(t.chainName); + const router = t.addressOrDenom!; + const xerc20Address = + t.standard === TokenStandard.EvmHypXERC20Lockbox + ? await HypXERC20Lockbox__factory.connect( + router, + provider, + ).xERC20() + : await HypXERC20__factory.connect( + router, + provider, + ).wrappedToken(); + + const xerc20 = IXERC20__factory.connect(xerc20Address, provider); + const mint = await xerc20.mintingCurrentLimitOf(router); + const burn = await xerc20.burningCurrentLimitOf(router); + + const formattedLimits = objMap({ mint, burn }, (_, v) => + ethers.utils.formatUnits(v, t.decimals), + ); + + return [t.chainName, formattedLimits]; + }), + ); + if (xerc20Limits.length > 0) { + logGray('xERC20 Limits:'); + logTable(Object.fromEntries(xerc20Limits)); + } + addresses = Object.fromEntries( warpCoreConfig.tokens.map((t) => [t.chainName, t.addressOrDenom!]), );