Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter undefined factory addresses #5340

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading