Skip to content

Commit

Permalink
fix: warp route deployment verification (#3494)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalaji authored Mar 27, 2024
1 parent 4e7a43b commit a9881dc
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 29 deletions.
4 changes: 2 additions & 2 deletions typescript/cli/src/deploy/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async function executeDeploy(params: DeployParams) {

log('Writing deployment artifacts');
writeTokenDeploymentArtifacts(contractsFilePath, deployedContracts, params);
writeWarpUiTokenConfig(tokenConfigPath, deployedContracts, params);
writeWarpConfig(tokenConfigPath, deployedContracts, params);

logBlue('Deployment is complete!');
logBlue(`Contract address artifacts are in ${contractsFilePath}`);
Expand Down Expand Up @@ -330,7 +330,7 @@ function writeTokenDeploymentArtifacts(
writeJson(filePath, artifacts);
}

function writeWarpUiTokenConfig(
function writeWarpConfig(
filePath: string,
contracts: HyperlaneContractsMap<TokenFactories>,
{ configMap, metadata }: DeployParams,
Expand Down
41 changes: 37 additions & 4 deletions typescript/sdk/src/deploy/HyperlaneDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,23 @@ export abstract class HyperlaneDeployer<
return contract;
}

async deployContract<K extends keyof Factories>(
/**
* Deploys a contract with a specified name.
*
* This is a generic function capable of deploying any contract type, defined within the `Factories` type, to a specified chain.
*
* @param {ChainName} chain - The name of the chain on which the contract is to be deployed.
* @param {K} contractKey - The key identifying the factory to use for deployment.
* @param {string} contractName - The name of the contract to deploy. This must match the contract source code.
* @param {Parameters<Factories[K]['deploy']>} constructorArgs - Arguments for the contract's constructor.
* @param {Parameters<Awaited<ReturnType<Factories[K]['deploy']>>['initialize']>?} initializeArgs - Optional arguments for the contract's initialization function.
* @param {boolean} shouldRecover - Flag indicating whether to attempt recovery if deployment fails.
* @returns {Promise<HyperlaneContracts<Factories>[K]>} A promise that resolves to the deployed contract instance.
*/
async deployContractWithName<K extends keyof Factories>(
chain: ChainName,
contractName: K,
contractKey: K,
contractName: string,
constructorArgs: Parameters<Factories[K]['deploy']>,
initializeArgs?: Parameters<
Awaited<ReturnType<Factories[K]['deploy']>>['initialize']
Expand All @@ -395,8 +409,8 @@ export abstract class HyperlaneDeployer<
): Promise<HyperlaneContracts<Factories>[K]> {
const contract = await this.deployContractFromFactory(
chain,
this.factories[contractName],
contractName.toString(),
this.factories[contractKey],
contractName,
constructorArgs,
initializeArgs,
shouldRecover,
Expand All @@ -405,6 +419,25 @@ export abstract class HyperlaneDeployer<
return contract;
}

async deployContract<K extends keyof Factories>(
chain: ChainName,
contractKey: K,
constructorArgs: Parameters<Factories[K]['deploy']>,
initializeArgs?: Parameters<
Awaited<ReturnType<Factories[K]['deploy']>>['initialize']
>,
shouldRecover = true,
): Promise<HyperlaneContracts<Factories>[K]> {
return this.deployContractWithName(
chain,
contractKey,
contractKey.toString(),
constructorArgs,
initializeArgs,
shouldRecover,
);
}

protected async changeAdmin(
chain: ChainName,
proxy: ITransparentUpgradeableProxy,
Expand Down
10 changes: 7 additions & 3 deletions typescript/sdk/src/deploy/verify/ContractVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class ContractVerifier {
verificationLogger: Logger,
options?: FormOptions<typeof action>,
): Promise<any> {
const { apiUrl, family } = this.multiProvider.getExplorerApi(chain);
const {
apiUrl,
family,
apiKey = this.apiKeys[chain],
} = this.multiProvider.getExplorerApi(chain);
const params = new URLSearchParams();
params.set('module', 'contract');
params.set('action', action);
Expand All @@ -84,8 +88,8 @@ export class ContractVerifier {
}

// only include apikey if provided & not blockscout
if (family !== ExplorerFamily.Blockscout && this.apiKeys[chain]) {
params.set('apikey', this.apiKeys[chain]);
if (family !== ExplorerFamily.Blockscout && apiKey) {
params.set('apikey', apiKey);
}

const url = new URL(apiUrl);
Expand Down
16 changes: 15 additions & 1 deletion typescript/sdk/src/token/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import {

import { TokenType } from './config';

export const hypERC20contracts = {
[TokenType.fastCollateral]: 'FastHypERC20Collateral',
[TokenType.fastSynthetic]: 'FastHypERC20',
[TokenType.synthetic]: 'HypERC20',
[TokenType.collateral]: 'HypERC20Collateral',
[TokenType.collateralVault]: 'HypERC20CollateralVaultDeposit',
[TokenType.native]: 'HypNative',
[TokenType.nativeScaled]: 'HypNativeScaled',
};
export const hypERC20factories = {
[TokenType.fastCollateral]: new FastHypERC20Collateral__factory(),
[TokenType.fastSynthetic]: new FastHypERC20__factory(),
Expand All @@ -25,13 +34,18 @@ export const hypERC20factories = {
};
export type HypERC20Factories = typeof hypERC20factories;

export const hypERC721contracts = {
[TokenType.collateralUri]: 'HypERC721URICollateral',
[TokenType.collateral]: 'HypERC721Collateral',
[TokenType.syntheticUri]: 'HypERC721URIStorage',
[TokenType.synthetic]: 'HypERC721',
};
export const hypERC721factories = {
[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;

export type TokenFactories = HypERC20Factories | HypERC721Factories;
61 changes: 42 additions & 19 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import {
import {
HypERC20Factories,
HypERC721Factories,
hypERC20contracts,
hypERC20factories,
hypERC721contracts,
hypERC721factories,
} from './contracts';

Expand Down Expand Up @@ -134,50 +136,63 @@ export class HypERC20Deployer extends GasRouterDeployer<
chain: ChainName,
config: HypERC20CollateralConfig,
): Promise<HypERC20Collateral> {
let contractName:
let tokenType:
| TokenType.fastCollateral
| TokenType.collateral
| TokenType.collateralVault;
switch (config.type) {
case TokenType.fastSynthetic || TokenType.fastCollateral:
contractName = TokenType.fastCollateral;
tokenType = TokenType.fastCollateral;
break;
case TokenType.collateral:
contractName = TokenType.collateral;
tokenType = TokenType.collateral;
break;
case TokenType.collateralVault:
contractName = TokenType.collateralVault;
tokenType = TokenType.collateralVault;
break;
default:
throw new Error(`Unknown collateral type ${config.type}`);
}
return this.deployContract(chain, contractName, [
config.token,
config.mailbox,
]);
return this.deployContractWithName(
chain,
tokenType,
hypERC20contracts[tokenType],
[config.token, config.mailbox],
);
}

protected async deployNative(
chain: ChainName,
config: HypNativeConfig,
): Promise<HypNative> {
if (config.scale) {
return this.deployContract(chain, TokenType.nativeScaled, [
config.scale,
config.mailbox,
]);
return this.deployContractWithName(
chain,
TokenType.nativeScaled,
hypERC20contracts[TokenType.nativeScaled],
[config.scale, config.mailbox],
);
} else {
return this.deployContract(chain, TokenType.native, [config.mailbox]);
return this.deployContractWithName(
chain,
TokenType.native,
hypERC20contracts[TokenType.native],
[config.mailbox],
);
}
}

protected async deploySynthetic(
chain: ChainName,
config: HypERC20Config,
): Promise<HypERC20> {
const router: HypERC20 = await this.deployContract(
const tokenType = isFastConfig(config)
? TokenType.fastSynthetic
: TokenType.synthetic;
const router: HypERC20 = await this.deployContractWithName(
chain,
isFastConfig(config) ? TokenType.fastSynthetic : TokenType.synthetic,
tokenType,
hypERC20contracts[tokenType],
[config.decimals, config.mailbox],
);
try {
Expand Down Expand Up @@ -326,9 +341,13 @@ export class HypERC721Deployer extends GasRouterDeployer<
chain: ChainName,
config: HypERC721CollateralConfig,
): Promise<HypERC721Collateral> {
return this.deployContract(
const tokenType = isUriConfig(config)
? TokenType.collateralUri
: TokenType.collateral;
return this.deployContractWithName(
chain,
isUriConfig(config) ? TokenType.collateralUri : TokenType.collateral,
tokenType,
hypERC721contracts[tokenType],
[config.token, config.mailbox],
);
}
Expand All @@ -337,9 +356,13 @@ export class HypERC721Deployer extends GasRouterDeployer<
chain: ChainName,
config: HypERC721Config,
): Promise<HypERC721> {
const router = await this.deployContract(
const tokenType = isUriConfig(config)
? TokenType.syntheticUri
: TokenType.synthetic;
const router = await this.deployContractWithName(
chain,
isUriConfig(config) ? TokenType.syntheticUri : TokenType.synthetic,
tokenType,
hypERC721contracts[tokenType],
[config.mailbox],
);
await this.multiProvider.handleTx(
Expand Down

0 comments on commit a9881dc

Please sign in to comment.