Skip to content

Commit

Permalink
Remove routerContractNameConstant. Add router() logic for dependent c…
Browse files Browse the repository at this point in the history
…lasses. Add defaultArgs for 721 deploy
  • Loading branch information
ltyu committed Mar 26, 2024
1 parent ce8c0a3 commit 74c3549
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
14 changes: 12 additions & 2 deletions typescript/sdk/src/middleware/account/InterchainAccountDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ethers } from 'ethers';

import { Router } from '@hyperlane-xyz/core';
import { objKeys } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../../contracts/types';
import { ContractVerifier } from '../../deploy/verify/ContractVerifier';
import { MultiProvider } from '../../providers/MultiProvider';
Expand All @@ -19,8 +22,6 @@ export class InterchainAccountDeployer extends ProxiedRouterDeployer<
InterchainAccountFactories,
'interchainAccountRouter'
> {
readonly routerContractNameConstant = 'interchainAccountRouter';

constructor(
multiProvider: MultiProvider,
contractVerifier?: ContractVerifier,
Expand All @@ -36,6 +37,15 @@ export class InterchainAccountDeployer extends ProxiedRouterDeployer<
return 'interchainAccountRouter' as K;
}

router(contracts: HyperlaneContracts<InterchainAccountFactories>): Router {
for (const key of objKeys(interchainAccountFactories)) {
if (contracts[key]) {
return contracts[key] as Router;
}
}
throw new Error('No matching contract found');
}

async constructorArgs(_: string, config: RouterConfig): Promise<[string]> {
return [config.mailbox];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import {
CircleBridgeAdapter,
LiquidityLayerRouter,
PortalAdapter,
Router,
} from '@hyperlane-xyz/core';
import { Address, eqAddress, objFilter, objMap } from '@hyperlane-xyz/utils';
import {
Address,
eqAddress,
objFilter,
objKeys,
objMap,
} from '@hyperlane-xyz/utils';

import {
HyperlaneContracts,
Expand Down Expand Up @@ -56,8 +63,6 @@ export class LiquidityLayerDeployer extends ProxiedRouterDeployer<
LiquidityLayerFactories,
'liquidityLayerRouter'
> {
readonly routerContractNameConstant = 'liquidityLayerRouter';

constructor(
multiProvider: MultiProvider,
contractVerifier?: ContractVerifier,
Expand All @@ -73,6 +78,15 @@ export class LiquidityLayerDeployer extends ProxiedRouterDeployer<
return 'liquidityLayerRouter' as K;
}

router(contracts: HyperlaneContracts<LiquidityLayerFactories>): Router {
for (const key of objKeys(liquidityLayerFactories)) {
if (contracts[key]) {
return contracts[key] as Router;
}
}
throw new Error('No matching contract found');
}

async constructorArgs(
_: string,
config: LiquidityLayerConfig,
Expand Down
15 changes: 13 additions & 2 deletions typescript/sdk/src/middleware/query/InterchainQueryDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ethers } from 'ethers';

import { Router } from '@hyperlane-xyz/core';
import { objKeys } from '@hyperlane-xyz/utils';

import { HyperlaneContracts } from '../../contracts/types';
import { ContractVerifier } from '../../deploy/verify/ContractVerifier';
import { MultiProvider } from '../../providers/MultiProvider';
import { ProxiedRouterDeployer } from '../../router/ProxiedRouterDeployer';
Expand All @@ -17,8 +21,6 @@ export class InterchainQueryDeployer extends ProxiedRouterDeployer<
InterchainQueryFactories,
'interchainQueryRouter'
> {
readonly routerContractNameConstant = 'interchainQueryRouter';

constructor(
multiProvider: MultiProvider,
contractVerifier?: ContractVerifier,
Expand All @@ -34,6 +36,15 @@ export class InterchainQueryDeployer extends ProxiedRouterDeployer<
return 'interchainQueryRouter' as K;
}

router(contracts: HyperlaneContracts<InterchainQueryFactories>): Router {
for (const key of objKeys(interchainQueryFactories)) {
if (contracts[key]) {
return contracts[key] as Router;
}
}
throw new Error('No matching contract found');
}

async constructorArgs(_: string, config: RouterConfig): Promise<[string]> {
return [config.mailbox];
}
Expand Down
6 changes: 1 addition & 5 deletions typescript/sdk/src/router/ProxiedRouterDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export abstract class ProxiedRouterDeployer<
Factories extends ProxiedFactories,
RouterKey extends keyof Factories,
> extends HyperlaneRouterDeployer<Config, Factories> {
abstract routerContractNameConstant: RouterKey; // @dev this is for backwards compatibility, should refactor later

router(contracts: HyperlaneContracts<Factories>): Router {
return contracts[this.routerContractNameConstant] as Router;
}
abstract router(contracts: HyperlaneContracts<Factories>): Router;

/**
* Returns the contract name
Expand Down
13 changes: 7 additions & 6 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export class HypERC20Deployer extends GasRouterDeployer<
HypERC20Factories,
TokenType.native
> {
readonly routerContractNameConstant = TokenType.native;

constructor(
multiProvider: MultiProvider,
ismFactory?: HyperlaneIsmFactory,
Expand Down Expand Up @@ -255,8 +253,6 @@ export class HypERC721Deployer extends GasRouterDeployer<
HypERC721Factories,
TokenType.collateral
> {
readonly routerContractNameConstant = TokenType.collateral;

constructor(
multiProvider: MultiProvider,
contractVerifier?: ContractVerifier,
Expand Down Expand Up @@ -296,10 +292,15 @@ export class HypERC721Deployer extends GasRouterDeployer<

//@ts-ignore ignore for now until the contracts get fixed
async initializeArgs(_: ChainName, config: ERC721RouterConfig): Promise<any> {
const defaultArgs = [
config.hook ?? ethers.constants.AddressZero,
config.interchainSecurityModule ?? ethers.constants.AddressZero,
config.owner,
];
if (isCollateralConfig(config)) {
return [config.token, config.mailbox];
return defaultArgs;
} else if (isSyntheticConfig(config)) {
return [config.totalSupply, config.name, config.symbol];
return [config.totalSupply, config.name, config.symbol, ...defaultArgs];
} else {
throw new Error('Unknown collateral type when initializing arguments');
}
Expand Down

0 comments on commit 74c3549

Please sign in to comment.