Skip to content

Commit

Permalink
draft push
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalaji committed May 1, 2024
1 parent 3528b28 commit cc7206a
Show file tree
Hide file tree
Showing 4 changed files with 510 additions and 43 deletions.
18 changes: 4 additions & 14 deletions typescript/sdk/src/crud/AbstractCrudModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@ import { Logger } from 'pino';

import { Address, Annotated, ProtocolType } from '@hyperlane-xyz/utils';

import { ChainMetadataManager } from '../metadata/ChainMetadataManager.js';
import {
ProtocolTypedProvider,
ProtocolTypedTransaction,
} from '../providers/ProviderType.js';
import { ProtocolTypedTransaction } from '../providers/ProviderType.js';
import { ChainNameOrId } from '../types.js';

export type CrudModuleArgs<
TProtocol extends ProtocolType,
TConfig,
TAddressMap extends Record<string, Address>,
> = {
export type CrudModuleArgs<TConfig, TAddressMap extends Record<string, any>> = {
addresses: TAddressMap;
chain: ChainNameOrId;
chainMetadataManager: ChainMetadataManager;
config: TConfig;
provider: ProtocolTypedProvider<TProtocol>['provider'];
};

export abstract class CrudModule<
TProtocol extends ProtocolType,
TConfig,
TAddressMap extends Record<string, Address>,
TAddressMap extends Record<string, any>,
> {
protected abstract readonly logger: Logger;

protected constructor(
protected readonly args: CrudModuleArgs<TProtocol, TConfig, TAddressMap>,
protected readonly args: CrudModuleArgs<TConfig, TAddressMap>,
) {}

public serialize(): TAddressMap {
Expand Down
14 changes: 2 additions & 12 deletions typescript/sdk/src/crud/EvmHookModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ export class EvmHookModule extends CrudModule<

protected constructor(
protected readonly multiProvider: MultiProvider,
args: Omit<
CrudModuleArgs<
ProtocolType.Ethereum,
HookConfig,
HyperlaneAddresses<HookFactories>
>,
'provider'
>,
args: CrudModuleArgs<HookConfig, HyperlaneAddresses<HookFactories>>,
) {
super({
...args,
provider: multiProvider.getProvider(args.chain),
});
super(args);

this.reader = new EvmHookReader(multiProvider, args.chain);
}
Expand Down
59 changes: 42 additions & 17 deletions typescript/sdk/src/crud/EvmIsmModule.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
import { Address, ProtocolType, rootLogger } from '@hyperlane-xyz/utils';

import { HyperlaneAddresses } from '../contracts/types.js';
import { HyperlaneContracts } from '../contracts/types.js';
import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer.js';
import { ProxyFactoryFactories } from '../deploy/contracts.js';
import { EvmIsmCreator } from '../ism/EvmIsmCreator.js';
import { EvmIsmReader } from '../ism/read.js';
import { IsmConfig } from '../ism/types.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { EthersV5Transaction } from '../providers/ProviderType.js';
import { ChainNameOrId } from '../types.js';

import { CrudModule, CrudModuleArgs } from './AbstractCrudModule.js';

// WIP example implementation of EvmIsmModule
export class EvmIsmModule extends CrudModule<
ProtocolType.Ethereum,
IsmConfig,
HyperlaneAddresses<ProxyFactoryFactories>
HyperlaneContracts<ProxyFactoryFactories> & {
deployedIsm: Address;
}
> {
protected logger = rootLogger.child({ module: 'EvmIsmModule' });
protected reader: EvmIsmReader;

protected constructor(
protected readonly multiProvider: MultiProvider,
args: Omit<
CrudModuleArgs<
ProtocolType.Ethereum,
IsmConfig,
HyperlaneAddresses<ProxyFactoryFactories>
>,
'provider'
args: CrudModuleArgs<
IsmConfig,
HyperlaneContracts<ProxyFactoryFactories> & {
deployedIsm: Address;
}
>,
) {
super({
...args,
provider: multiProvider.getProvider(args.chain),
});
super(args);

this.reader = new EvmIsmReader(multiProvider, args.chain);
}

public async read(address: Address): Promise<IsmConfig> {
return await this.reader.deriveIsmConfig(address);
public async read(): Promise<IsmConfig> {
return await this.reader.deriveIsmConfig(this.args.addresses.deployedIsm);
}

public async update(_config: IsmConfig): Promise<EthersV5Transaction[]> {
throw new Error('Method not implemented.');
}

// manually write static create function
public static create(_config: IsmConfig): Promise<EvmIsmModule> {
throw new Error('not implemented');
public static async create({
chain,
config,
deployer,
factories,
multiProvider,
}: {
chain: ChainNameOrId;
config: IsmConfig;
deployer: HyperlaneDeployer<any, any>;
factories: HyperlaneContracts<ProxyFactoryFactories>;
multiProvider: MultiProvider;
}): Promise<EvmIsmModule> {
const destination = multiProvider.getChainName(chain);
const ismCreator = new EvmIsmCreator(deployer, multiProvider, factories);
const deployedIsm = await ismCreator.deploy({
config,
destination,
});
return new EvmIsmModule(multiProvider, {
addresses: {
...factories,
deployedIsm: deployedIsm.address,
},
chain,
config,
});
}
}
Loading

0 comments on commit cc7206a

Please sign in to comment.