|
|
@ -4,7 +4,7 @@ import type { types } from '@hyperlane-xyz/utils'; |
|
|
|
|
|
|
|
|
|
|
|
import { MultiProvider } from './providers/MultiProvider'; |
|
|
|
import { MultiProvider } from './providers/MultiProvider'; |
|
|
|
import { ChainMap, Connection } from './types'; |
|
|
|
import { ChainMap, Connection } from './types'; |
|
|
|
import { objMap, pick } from './utils/objects'; |
|
|
|
import { objFilter, objMap, pick } from './utils/objects'; |
|
|
|
|
|
|
|
|
|
|
|
export type HyperlaneFactories = { |
|
|
|
export type HyperlaneFactories = { |
|
|
|
[key: string]: ethers.ContractFactory; |
|
|
|
[key: string]: ethers.ContractFactory; |
|
|
@ -53,20 +53,30 @@ function getFactory( |
|
|
|
return factories[key]; |
|
|
|
return factories[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function filterAddresses( |
|
|
|
export function filterAddressesMap( |
|
|
|
addresses: HyperlaneAddresses<any>, |
|
|
|
addressesMap: HyperlaneAddressesMap<any>, |
|
|
|
factories: HyperlaneFactories, |
|
|
|
factories: HyperlaneFactories, |
|
|
|
): HyperlaneAddresses<any> { |
|
|
|
): HyperlaneAddressesMap<typeof factories> { |
|
|
|
return pick(addresses, Object.keys(factories)); |
|
|
|
const factoryKeys = Object.keys(factories); |
|
|
|
|
|
|
|
// Filter out addresses that we do not have factories for
|
|
|
|
|
|
|
|
const pickedAddressesMap = objMap(addressesMap, (_, addresses) => |
|
|
|
|
|
|
|
pick(addresses, factoryKeys), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
// Filter out chains for which we do not have a complete set of addresses
|
|
|
|
|
|
|
|
return objFilter( |
|
|
|
|
|
|
|
pickedAddressesMap, |
|
|
|
|
|
|
|
(_, addresses): addresses is HyperlaneAddresses<typeof factories> => { |
|
|
|
|
|
|
|
return Object.keys(addresses).every((a) => factoryKeys.includes(a)); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function attachContracts<F extends HyperlaneFactories>( |
|
|
|
export function attachContracts<F extends HyperlaneFactories>( |
|
|
|
addresses: HyperlaneAddresses<F>, |
|
|
|
addresses: HyperlaneAddresses<F>, |
|
|
|
factories: F, |
|
|
|
factories: F, |
|
|
|
): HyperlaneContracts<F> { |
|
|
|
): HyperlaneContracts<F> { |
|
|
|
return objMap( |
|
|
|
return objMap(addresses, (key, address: types.Address) => |
|
|
|
filterAddresses(addresses, factories), |
|
|
|
getFactory(key, factories).attach(address), |
|
|
|
(key, address: types.Address) => getFactory(key, factories).attach(address), |
|
|
|
|
|
|
|
) as HyperlaneContracts<F>; |
|
|
|
) as HyperlaneContracts<F>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -74,9 +84,10 @@ export function attachContractsMap<F extends HyperlaneFactories>( |
|
|
|
addressesMap: HyperlaneAddressesMap<F>, |
|
|
|
addressesMap: HyperlaneAddressesMap<F>, |
|
|
|
factories: F, |
|
|
|
factories: F, |
|
|
|
): HyperlaneContractsMap<F> { |
|
|
|
): HyperlaneContractsMap<F> { |
|
|
|
return objMap(addressesMap, (_, addresses) => |
|
|
|
const filteredAddressesMap = filterAddressesMap(addressesMap, factories); |
|
|
|
|
|
|
|
return objMap(filteredAddressesMap, (_, addresses) => |
|
|
|
attachContracts(addresses, factories), |
|
|
|
attachContracts(addresses, factories), |
|
|
|
); |
|
|
|
) as HyperlaneContractsMap<F>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function connectContracts<F extends HyperlaneFactories>( |
|
|
|
export function connectContracts<F extends HyperlaneFactories>( |
|
|
|