Skip to content

Commit

Permalink
fix: filter undefined factory addresses (#5340)
Browse files Browse the repository at this point in the history
### Description

When deploying Hyperlane contracts using `warp deploy`, the core
addresses obtained using older version of `core deploy` may not include
addresses of newer factories
(`staticMessageIdWeightedMultisigIsmFactory` and
`staticMessageIdWeightedMultisigIsmFactory`). These `undefined`
addresses would cause warp deploy to fail, even though they aren't
absolutely necessary for warping.

This fix handles undefined factory addresses that are filtered out
during `warp deploy`. This way, warp deploy can proceed the weighted
factories, and users won't have to pay gas fees for core deployment once
again to.

Attached LogX chain core deployment lacking weighted factory addresses &
the resulting error message from `warp deploy`

![2025-01-30 16 30
55](https://github.com/user-attachments/assets/cbe86080-a944-487f-a8d7-beb5f746b007)

![2025-01-30 16 30
39](https://github.com/user-attachments/assets/b118fe99-4894-43bf-a17b-6561d3052d31)

### Drive-by changes

- Added `undefined` address filtering in the `filterAddressesMap`
function

### Related issues

None

### Backward compatibility

Yes

### Testing

Manual
  • Loading branch information
ljankovic-txfusion authored Jan 31, 2025
1 parent ba50e62 commit ac984a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-fishes-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---

Fix contract address filtering to remove undefined factory addresses from the addresses map
31 changes: 29 additions & 2 deletions typescript/sdk/src/contracts/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from 'ethers';
import { Contract, constants } from 'ethers';

import { Ownable, Ownable__factory } from '@hyperlane-xyz/core';
import {
Expand All @@ -12,6 +12,7 @@ import {
objMap,
pick,
promiseObjAll,
rootLogger,
} from '@hyperlane-xyz/utils';

import { ChainMetadataManager } from '../metadata/ChainMetadataManager.js';
Expand Down Expand Up @@ -62,9 +63,35 @@ export function filterAddressesMap<F extends HyperlaneFactories>(
const pickedAddressesMap = objMap(addressesMap, (_, addresses) =>
pick(addresses, factoryKeys),
);

const chainsWithMissingAddresses = new Set<string>();
const filledAddressesMap = objMap(
pickedAddressesMap,
(chainName, addresses) =>
objMap(addresses, (key, value) => {
if (!value) {
rootLogger.warn(
`Missing address for contract "${key}" on chain ${chainName}`,
);
chainsWithMissingAddresses.add(chainName);
return constants.AddressZero;
}
return value;
}),
);
// Add summary warning if any addresses were missing
if (chainsWithMissingAddresses.size > 0) {
rootLogger.warn(
`Warning: Core deployment incomplete for chain(s): ${Array.from(
chainsWithMissingAddresses,
).join(', ')}. ` +
`Please run 'core deploy' again for these chains to fix the deployment.`,
);
}

// Filter out chains for which we do not have a complete set of addresses
return objFilter(
pickedAddressesMap,
filledAddressesMap,
(_, addresses): addresses is HyperlaneAddresses<F> => {
return Object.keys(addresses).every((a) => factoryKeys.includes(a));
},
Expand Down

0 comments on commit ac984a1

Please sign in to comment.