Skip to content

Commit

Permalink
back to just type
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Mar 15, 2024
1 parent b41199e commit dca6b63
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@
"router": "0x26f32245fCF5Ad53159E875d5Cae62aEcf19c2d4"
}
}

// {
// "injective": [{,
// "type": "sythetic",
// "standard": "ERC20",
// "name": "USDC",
// "router": "inj1mv9tjvkaw7x8w8y9vds8pkfq46g2vcfkjehc6k"
// }],
// }
15 changes: 6 additions & 9 deletions typescript/infra/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { objMap } from '@hyperlane-xyz/utils';

import { Contexts } from '../config/contexts';
import { safes } from '../config/environments/mainnet3/owners';
import { deployEnvToSdkEnv } from '../src/config/environment';
import { deployWithArtifacts } from '../src/deployment/deploy';
import { TestQuerySenderDeployer } from '../src/deployment/testcontracts/testquerysender';
Expand Down Expand Up @@ -121,19 +120,17 @@ async function main() {
multiProvider,
);
const routerConfig = core.getRouterConfig(envConfig.owners);
const inevm = {
...routerConfig.inevm,
const plumetestnet = {
...routerConfig.plumetestnet,
type: TokenType.native,
interchainSecurityModule: ethers.constants.AddressZero,
owner: safes.inevm,
};
const injective = {
...routerConfig.injective,
const sepolia = {
...routerConfig.sepolia,
type: TokenType.native,
};
config = {
inevm,
injective,
plumetestnet,
sepolia,
};
deployer = new HypERC20Deployer(
multiProvider,
Expand Down
1 change: 0 additions & 1 deletion typescript/infra/src/deployment/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { DeployEnvironment } from '../config';
import {
readJSONAtPath,
writeJsonAtPath,
writeMergedJSON,
writeMergedJSONAtPath,
} from '../utils/utils';

Expand Down
2 changes: 1 addition & 1 deletion typescript/sdk/src/providers/MultiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
// setup contract factory
const overrides = this.getTransactionOverrides(chainNameOrId);
const signer = this.getSigner(chainNameOrId);
const contractFactory = factory.connect(signer);
const contractFactory = await factory.connect(signer);

// estimate gas
const deployTx = contractFactory.getDeployTransaction(...params, overrides);
Expand Down
8 changes: 3 additions & 5 deletions typescript/sdk/src/token/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ethers } from 'ethers';

import { GasRouterConfig } from '../router/types';

import { TokenStandard } from './TokenStandard';

export enum TokenType {
synthetic = 'synthetic',
fastSynthetic = 'fastSynthetic',
Expand All @@ -10,11 +12,7 @@ export enum TokenType {
fastCollateral = 'fastCollateral',
collateralUri = 'collateralUri',
native = 'native',
}

export enum TokenStandard {
ERC20 = 'ERC20',
ERC721 = 'ERC721',
nativeScaled = 'nativeScaled',
}

// this is for getting a unique artifact key; to differentiate between ERC20/ERC721
Expand Down
31 changes: 11 additions & 20 deletions typescript/sdk/src/token/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,23 @@ import {
HypNative__factory,
} from '@hyperlane-xyz/core';

import { TokenStandard, TokenType, getTokenType } from './config';
import { TokenType } from './config';

export const hypERC20factories = {
[getTokenType(TokenType.fastCollateral, TokenStandard.ERC20)]:
new FastHypERC20Collateral__factory(),
[getTokenType(TokenType.fastSynthetic, TokenStandard.ERC20)]:
new FastHypERC20__factory(),
[getTokenType(TokenType.synthetic, TokenStandard.ERC20)]:
new HypERC20__factory(),
[getTokenType(TokenType.collateral, TokenStandard.ERC20)]:
new HypERC20Collateral__factory(),
[getTokenType(TokenType.native, TokenStandard.ERC20)]:
new HypNative__factory(),
nativescaledERC20: new HypNativeScaled__factory(),
[TokenType.fastCollateral]: new FastHypERC20Collateral__factory(),
[TokenType.fastSynthetic]: new FastHypERC20__factory(),
[TokenType.synthetic]: new HypERC20__factory(),
[TokenType.collateral]: new HypERC20Collateral__factory(),
[TokenType.native]: new HypNative__factory(),
[TokenType.nativeScaled]: new HypNativeScaled__factory(),
};
export type HypERC20Factories = typeof hypERC20factories;

export const hypERC721factories = {
[getTokenType(TokenType.collateralUri, TokenStandard.ERC721)]:
new HypERC721URICollateral__factory(),
[getTokenType(TokenType.collateral, TokenStandard.ERC721)]:
new HypERC721Collateral__factory(),
[getTokenType(TokenType.syntheticUri, TokenStandard.ERC721)]:
new HypERC721URIStorage__factory(),
[getTokenType(TokenType.synthetic, TokenStandard.ERC721)]:
new HypERC721__factory(),
[TokenType.collateralUri]: new HypERC721URICollateral__factory(),
[TokenType.collateral]: new HypERC721Collateral__factory(),
[TokenType.syntheticUri]: new HypERC721URIStorage__factory(),
[TokenType.synthetic]: new HypERC721__factory(),
};

export type HypERC721Factories = typeof hypERC721factories;
Expand Down
106 changes: 68 additions & 38 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import {
HypNativeConfig,
TokenConfig,
TokenMetadata,
TokenStandard,
getTokenType,
TokenType,
isCollateralConfig,
isErc20Metadata,
isFastConfig,
isNativeConfig,
isSyntheticConfig,
isTokenMetadata,
isUriConfig,
} from './config';
import {
HypERC20Factories,
Expand Down Expand Up @@ -134,42 +135,57 @@ export class HypERC20Deployer extends GasRouterDeployer<
chain: ChainName,
config: HypERC20CollateralConfig,
): Promise<HypERC20Collateral> {
return (await this.deployContract(
chain,
getTokenType(config.type, TokenStandard.ERC20),
[config.token, config.mailbox],
)) as HypERC20Collateral;
const isFast = isFastConfig(config);
if (isFast) {
return this.deployContract<TokenType.fastCollateral>(
chain,
TokenType.fastCollateral,
[config.token, config.mailbox],
);
} else {
return this.deployContract<TokenType.collateral>(
chain,
TokenType.collateral,
[config.token, config.mailbox],
);
}
}

protected async deployNative(
chain: ChainName,
config: HypNativeConfig,
): Promise<HypNative> {
let router: HypNative;
if (config.scale) {
router = (await this.deployContract(chain, 'nativescaledERC20', [
config.scale,
config.mailbox,
])) as HypNative;
} else {
router = (await this.deployContract(
return this.deployContract<TokenType.nativeScaled>(
chain,
getTokenType(config.type, TokenStandard.ERC20),
[config.mailbox],
)) as HypNative;
TokenType.nativeScaled,
[config.scale, config.mailbox],
);
} else {
return this.deployContract<TokenType.native>(chain, TokenType.native, [
config.mailbox,
]);
}
return router;
}

protected async deploySynthetic(
chain: ChainName,
config: HypERC20Config,
): Promise<HypERC20> {
const router = (await this.deployContract(
chain,
getTokenType(config.type, TokenStandard.ERC20),
[config.decimals, config.mailbox],
)) as HypERC20;
let router: HypERC20;
if (isFastConfig(config)) {
router = await this.deployContract<TokenType.fastSynthetic>(
chain,
TokenType.fastSynthetic,
[config.decimals, config.mailbox],
);
} else {
router = await this.deployContract<TokenType.synthetic>(
chain,
TokenType.synthetic,
[config.decimals, config.mailbox],
);
}

try {
await this.multiProvider.handleTx(
Expand All @@ -180,9 +196,7 @@ export class HypERC20Deployer extends GasRouterDeployer<
if (!e.message.includes('already initialized')) {
throw e;
}
this.logger(
`${getTokenType(config.type, TokenStandard.ERC20)} already initialized`,
);
this.logger(`${config.type} already initialized`);
}
return router;
}
Expand All @@ -208,7 +222,7 @@ export class HypERC20Deployer extends GasRouterDeployer<
throw new Error('Invalid ERC20 token router config');
}
await this.configureClient(chain, router, config);
return { [getTokenType(config.type, TokenStandard.ERC20)]: router } as any;
return { [config.type]: router } as any;
}

async buildTokenMetadata(
Expand Down Expand Up @@ -319,22 +333,38 @@ export class HypERC721Deployer extends GasRouterDeployer<
chain: ChainName,
config: HypERC721CollateralConfig,
): Promise<HypERC721Collateral> {
return (await this.deployContract(
chain,
getTokenType(config.type, TokenStandard.ERC721),
[config.token, config.mailbox],
)) as HypERC721Collateral;
if (isUriConfig(config)) {
return this.deployContract<TokenType.collateralUri>(
chain,
TokenType.collateralUri,
[config.token, config.mailbox],
);
} else {
return this.deployContract<TokenType.collateral>(
chain,
TokenType.collateral,
[config.token, config.mailbox],
);
}
}

protected async deploySynthetic(
chain: ChainName,
config: HypERC721Config,
): Promise<HypERC721> {
return (await this.deployContract(
chain,
getTokenType(config.type, TokenStandard.ERC721),
[config.mailbox],
)) as HypERC721;
if (isUriConfig(config)) {
return this.deployContract<TokenType.syntheticUri>(
chain,
TokenType.syntheticUri,
[config.mailbox],
);
} else {
return this.deployContract<TokenType.synthetic>(
chain,
TokenType.synthetic,
[config.mailbox],
);
}
}

router(contracts: HyperlaneContracts<HypERC721Factories>) {
Expand All @@ -355,7 +385,7 @@ export class HypERC721Deployer extends GasRouterDeployer<
} else {
throw new Error('Invalid ERC721 token router config');
}
return { [getTokenType(config.type, TokenStandard.ERC721)]: router } as any;
return { [config.type]: router } as any;
}

async buildTokenMetadata(
Expand Down

0 comments on commit dca6b63

Please sign in to comment.