Skip to content

Commit

Permalink
refactor: dedupe HyperlaneIsmFactory and IsmModule.create (#4732)
Browse files Browse the repository at this point in the history
### Description

- Uses HyperlaneIsmFactory in IsmModuleCreate for deduping redundant
code

### Backward compatibility

Yes

### Testing

Unit tests
  • Loading branch information
yorhodes authored Oct 28, 2024
1 parent c622bfb commit e104cf6
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 868 deletions.
6 changes: 6 additions & 0 deletions .changeset/dirty-swans-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperlane-xyz/utils': patch
'@hyperlane-xyz/sdk': patch
---

Dedupe internals of hook and ISM module deploy code
31 changes: 30 additions & 1 deletion typescript/sdk/src/contracts/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Contract } from 'ethers';

import { Ownable } from '@hyperlane-xyz/core';
import { Ownable, Ownable__factory } from '@hyperlane-xyz/core';
import {
Address,
ProtocolType,
ValueOf,
eqAddress,
hexOrBase58ToHex,
objFilter,
objMap,
pick,
promiseObjAll,
} from '@hyperlane-xyz/utils';

import { OwnableConfig } from '../deploy/types.js';
import { ChainMetadataManager } from '../metadata/ChainMetadataManager.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { AnnotatedEV5Transaction } from '../providers/ProviderType.js';
import { ChainMap, Connection } from '../types.js';

import {
Expand Down Expand Up @@ -257,3 +260,29 @@ export function appFromAddressesMapHelper<F extends HyperlaneFactories>(
multiProvider,
};
}

export function transferOwnershipTransactions(
chainId: number,
contract: Address,
actual: OwnableConfig,
expected: OwnableConfig,
label?: string,
): AnnotatedEV5Transaction[] {
if (eqAddress(actual.owner, expected.owner)) {
return [];
}

return [
{
chainId,
annotation: `Transferring ownership of ${label ?? contract} from ${
actual.owner
} to ${expected.owner}`,
to: contract,
data: Ownable__factory.createInterface().encodeFunctionData(
'transferOwnership',
[expected.owner],
),
},
];
}
15 changes: 8 additions & 7 deletions typescript/sdk/src/core/EvmCoreModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
import {
attachContractsMap,
serializeContractsMap,
transferOwnershipTransactions,
} from '../contracts/contracts.js';
import {
HyperlaneAddresses,
HyperlaneContractsMap,
} from '../contracts/types.js';
import { DeployedCoreAddresses } from '../core/schemas.js';
import { CoreConfig } from '../core/types.js';
import { EvmModuleDeployer } from '../deploy/EvmModuleDeployer.js';
import { HyperlaneProxyFactoryDeployer } from '../deploy/HyperlaneProxyFactoryDeployer.js';
import {
ProxyFactoryFactories,
Expand Down Expand Up @@ -202,12 +202,13 @@ export class EvmCoreModule extends HyperlaneModule<
actualConfig: CoreConfig,
expectedConfig: CoreConfig,
): AnnotatedEV5Transaction[] {
return EvmModuleDeployer.createTransferOwnershipTx({
actualOwner: actualConfig.owner,
expectedOwner: expectedConfig.owner,
deployedAddress: this.args.addresses.mailbox,
chainId: this.domainId,
});
return transferOwnershipTransactions(
this.domainId,
this.args.addresses.mailbox,
actualConfig,
expectedConfig,
'Mailbox',
);
}

/**
Expand Down
Loading

0 comments on commit e104cf6

Please sign in to comment.