Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Mar 28, 2024
1 parent 3d48777 commit 901e6c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions typescript/sdk/src/token/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const isCollateralConfig = (
config.type === TokenType.fastCollateral ||
config.type == TokenType.collateralVault;

export const isCollateralVaultConfig = (
config: TokenConfig,
): config is CollateralConfig => config.type === TokenType.collateralVault;

export const isSyntheticConfig = (
config: TokenConfig,
): config is SyntheticConfig =>
Expand Down
29 changes: 21 additions & 8 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
TokenMetadata,
TokenType,
isCollateralConfig,
isCollateralVaultConfig,
isErc20Metadata,
isFastConfig,
isNativeConfig,
Expand Down Expand Up @@ -67,9 +68,13 @@ export class HypERC20Deployer extends GasRouterDeployer<

routerContractKey(config: ERC20RouterConfig) {
if (isCollateralConfig(config)) {
return isFastConfig(config)
? TokenType.fastCollateral
: TokenType.collateral;
if (isFastConfig(config)) {
return TokenType.fastCollateral;
} else if (isCollateralVaultConfig(config)) {
return TokenType.collateralVault;
} else {
return TokenType.collateral;
}
} else if (isNativeConfig(config)) {
return config.scale ? TokenType.nativeScaled : TokenType.native;
} else if (isSyntheticConfig(config)) {
Expand All @@ -81,19 +86,27 @@ export class HypERC20Deployer extends GasRouterDeployer<
}
}

async constructorArgs(_: ChainName, config: ERC20RouterConfig): Promise<any> {
async constructorArgs<K extends keyof HypERC20Factories>(
_: ChainName,
config: ERC20RouterConfig,
): Promise<Parameters<HypERC20Factories[K]['deploy']>> {
if (isCollateralConfig(config)) {
return [config.token, config.mailbox];
return [config.token, config.mailbox] as any;
} else if (isNativeConfig(config)) {
return config.scale ? [config.scale, config.mailbox] : [config.mailbox];
return config.scale
? [config.scale, config.mailbox]
: ([config.mailbox] as any);
} else if (isSyntheticConfig(config)) {
return [config.decimals, config.mailbox];
return [config.decimals, config.mailbox] as any;
} else {
throw new Error('Unknown collateral type when constructing arguments');
}
}

async initializeArgs(_: ChainName, config: ERC20RouterConfig): Promise<any> {
async initializeArgs(_: ChainName, config: HypERC20Config): Promise<any> {
if (typeof config.interchainSecurityModule !== 'string') {
throw new Error('Token deployer does not support ISM objects currently');
}
const defaultArgs = [
config.hook ?? constants.AddressZero,
config.interchainSecurityModule ?? constants.AddressZero,
Expand Down

0 comments on commit 901e6c1

Please sign in to comment.