Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed Apr 6, 2023
1 parent 52acb95 commit 47e655a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This repo contains the base Hyperlane ERC20 and ERC721 tokens (HypERC20 and HypERC721). These tokens extend the base standards with an additional `transferRemote` function. Warp Routes make any token or native asset interchain without custom contracts. Read more about Warp Routes and how to deploy your own at [Warp API docs](https://docs.hyperlane.xyz/docs/developers/warp-api).

**NOTE:** ERC721 collateral variants are assumed to [enumerable](https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#IERC721Enumerable) and [metadata](https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#IERC721Metadata) compliant.

## Versions

| Git Ref | Release Date | Notes |
Expand Down
8 changes: 4 additions & 4 deletions contracts/HypERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/
* @dev Supply on each chain is not constant but the aggregate supply across all chains is.
*/
contract HypERC20 is ERC20Upgradeable, TokenRouter {
uint8 private immutable decimalsConfig;
uint8 private immutable _decimals;

constructor(uint8 _decimals) {
decimalsConfig = _decimals;
constructor(uint8 decimals) {
_decimals = decimals;
}

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ contract HypERC20 is ERC20Upgradeable, TokenRouter {
}

function decimals() public view override returns (uint8) {
return decimalsConfig;
return _decimals;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ export type NativeConfig = {
type: TokenType.native;
};

export type TokenConfig = { type: TokenType } & (
| SyntheticConfig
| CollateralConfig
| NativeConfig
);
export type TokenConfig = SyntheticConfig | CollateralConfig | NativeConfig;

export const isCollateralConfig = (
config: TokenConfig,
Expand Down
63 changes: 31 additions & 32 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
isUriConfig,
} from './config';
import { isTokenMetadata } from './config';
import { ERC721RouterConfig } from './config';
import { ERC20RouterConfig } from './config';
import { HypERC20Factories, HypERC721Factories } from './contracts';
import {
ERC20__factory,
Expand All @@ -44,8 +46,6 @@ import {
HypNative,
HypNative__factory,
} from './types';
import { ERC721RouterConfig } from './config';
import { ERC20RouterConfig } from './config';

export class HypERC20Deployer extends GasRouterDeployer<
ERC20RouterConfig,
Expand All @@ -60,10 +60,13 @@ export class HypERC20Deployer extends GasRouterDeployer<
config: CollateralConfig,
): Promise<ERC20Metadata> {
const erc20 = ERC20__factory.connect(config.token, provider);
const name = await erc20.name();
const symbol = await erc20.symbol();
const totalSupply = await erc20.totalSupply();
const decimals = await erc20.decimals();

const [name, symbol, totalSupply, decimals] = await Promise.all([
erc20.name(),
erc20.symbol(),
erc20.totalSupply(),
erc20.decimals(),
]);

return { name, symbol, totalSupply, decimals };
}
Expand Down Expand Up @@ -182,12 +185,12 @@ export class HypERC20Deployer extends GasRouterDeployer<
tokenMetadata = config;
}
}

if (!isErc20Metadata(tokenMetadata)) {
throw new Error('Invalid ERC20 token metadata');
}

return objMap(configMap, () => (tokenMetadata!));
return objMap(configMap, () => tokenMetadata!);
}

buildGasOverhead(configMap: ChainMap<TokenConfig>): ChainMap<GasConfig> {
Expand All @@ -199,16 +202,13 @@ export class HypERC20Deployer extends GasRouterDeployer<
async deploy(configMap: ChainMap<TokenConfig & RouterConfig>) {
const tokenMetadata = await this.buildTokenMetadata(configMap);
const gasOverhead = this.buildGasOverhead(configMap);
const mergedConfig = objMap(
configMap,
(chain, config) => {
return {
...tokenMetadata[chain],
...gasOverhead[chain],
...config,
};
},
) as ChainMap<ERC20RouterConfig>;
const mergedConfig = objMap(configMap, (chain, config) => {
return {
...tokenMetadata[chain],
...gasOverhead[chain],
...config,
};
}) as ChainMap<ERC20RouterConfig>;

return super.deploy(mergedConfig);
}
Expand All @@ -230,9 +230,11 @@ export class HypERC721Deployer extends GasRouterDeployer<
config.token,
provider,
);
const name = await erc721.name();
const symbol = await erc721.symbol();
const totalSupply = await erc721.totalSupply();
const [name, symbol, totalSupply] = await Promise.all([
erc721.name(),
erc721.symbol(),
erc721.totalSupply(),
]);

return { name, symbol, totalSupply };
}
Expand Down Expand Up @@ -350,7 +352,7 @@ export class HypERC721Deployer extends GasRouterDeployer<
throw new Error('Invalid ERC721 token metadata');
}

return objMap(configMap, () => (tokenMetadata!));
return objMap(configMap, () => tokenMetadata!);
}

buildGasOverhead(configMap: ChainMap<TokenConfig>): ChainMap<GasConfig> {
Expand All @@ -362,16 +364,13 @@ export class HypERC721Deployer extends GasRouterDeployer<
async deploy(configMap: ChainMap<TokenConfig & RouterConfig>) {
const tokenMetadata = await this.buildTokenMetadata(configMap);
const gasOverhead = this.buildGasOverhead(configMap);
const mergedConfig = objMap(
configMap,
(chain, config) => {
return {
...tokenMetadata[chain],
...gasOverhead[chain],
...config,
};
},
) as ChainMap<ERC721RouterConfig>;
const mergedConfig = objMap(configMap, (chain, config) => {
return {
...tokenMetadata[chain],
...gasOverhead[chain],
...config,
};
}) as ChainMap<ERC721RouterConfig>;

return super.deploy(mergedConfig);
}
Expand Down

0 comments on commit 47e655a

Please sign in to comment.