From 901e6c1bc9f9c7af8c9f06e85abfa1267b4ba030 Mon Sep 17 00:00:00 2001 From: Le Yu Date: Thu, 28 Mar 2024 16:52:36 -0400 Subject: [PATCH] Fix typing --- typescript/sdk/src/token/config.ts | 4 ++++ typescript/sdk/src/token/deploy.ts | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/typescript/sdk/src/token/config.ts b/typescript/sdk/src/token/config.ts index 7e2738a740..d8c0cc5610 100644 --- a/typescript/sdk/src/token/config.ts +++ b/typescript/sdk/src/token/config.ts @@ -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 => diff --git a/typescript/sdk/src/token/deploy.ts b/typescript/sdk/src/token/deploy.ts index 7088b7ac6c..32b907f5d5 100644 --- a/typescript/sdk/src/token/deploy.ts +++ b/typescript/sdk/src/token/deploy.ts @@ -28,6 +28,7 @@ import { TokenMetadata, TokenType, isCollateralConfig, + isCollateralVaultConfig, isErc20Metadata, isFastConfig, isNativeConfig, @@ -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)) { @@ -81,19 +86,27 @@ export class HypERC20Deployer extends GasRouterDeployer< } } - async constructorArgs(_: ChainName, config: ERC20RouterConfig): Promise { + async constructorArgs( + _: ChainName, + config: ERC20RouterConfig, + ): Promise> { 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 { + async initializeArgs(_: ChainName, config: HypERC20Config): Promise { + 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,