fix: derived token supply to 0 (#4010)

### Description

Token deployer should always derive token metadata's total supply to 0,
otherwise the collateral token's total supply will be minted initially
on the synthetic, creating 2x the desired total supply.

### Related issues

- Regression introduced by
https://github.com/hyperlane-xyz/hyperlane-monorepo/pull/3820
- opens https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/4013

### Backward compatibility

Yes

### Testing

Unit Tests
pull/4016/head
Yorke Rhodes 5 months ago committed by GitHub
parent 6cff4a2a9e
commit f9bbdde764
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/bright-horses-give.md
  2. 15
      typescript/sdk/src/token/deploy.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---
Fix initial total supply of synthetic token deployments to 0

@ -87,6 +87,9 @@ abstract class TokenDeployer<
multiProvider: MultiProvider,
configMap: WarpRouteDeployConfig,
): Promise<TokenMetadata | undefined> {
// this is used for synthetic token metadata and should always be 0
const DERIVED_TOKEN_SUPPLY = 0;
for (const [chain, config] of Object.entries(configMap)) {
if (isTokenMetadata(config)) {
return config;
@ -95,7 +98,7 @@ abstract class TokenDeployer<
if (isNativeConfig(config)) {
const nativeToken = multiProvider.getChainMetadata(chain).nativeToken;
if (nativeToken) {
return { totalSupply: 0, ...nativeToken };
return { totalSupply: DERIVED_TOKEN_SUPPLY, ...nativeToken };
}
}
@ -107,27 +110,25 @@ abstract class TokenDeployer<
config.token,
provider,
);
const [name, symbol, totalSupply] = await Promise.all([
const [name, symbol] = await Promise.all([
erc721.name(),
erc721.symbol(),
erc721.totalSupply(),
]);
return {
name,
symbol,
totalSupply: totalSupply.toString(),
totalSupply: DERIVED_TOKEN_SUPPLY,
};
}
const erc20 = ERC20__factory.connect(config.token, provider);
const [name, symbol, totalSupply, decimals] = await Promise.all([
const [name, symbol, decimals] = await Promise.all([
erc20.name(),
erc20.symbol(),
erc20.totalSupply(),
erc20.decimals(),
]);
return { name, symbol, totalSupply: totalSupply.toString(), decimals };
return { name, symbol, decimals, totalSupply: DERIVED_TOKEN_SUPPLY };
}
}

Loading…
Cancel
Save