Skip to content

Commit

Permalink
feat: add xerc20 limit lookups to warp read (#4020)
Browse files Browse the repository at this point in the history
### Description

Adds xerc20 mint and burn limit fetching to `warp read --symbol`

### Backward compatibility

Yes

### Testing

Manual
![Screenshot 2024-06-20 at 3 19
13 PM](https://github.com/hyperlane-xyz/hyperlane-monorepo/assets/3020995/9692e3fd-eecb-4758-af39-04639639b482)
  • Loading branch information
yorhodes authored Jun 25, 2024
1 parent c81721e commit 4dd2651
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-owls-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperlane-xyz/cli": patch
---

Add xerc20 limit lookups to warp read
48 changes: 47 additions & 1 deletion typescript/cli/src/commands/warp.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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!]),
);
Expand Down

0 comments on commit 4dd2651

Please sign in to comment.