Skip to content

Commit

Permalink
Generalize matching list agent config fn (#3458)
Browse files Browse the repository at this point in the history
### Description

Generalizes `routerMatchingList` to `matchingList` for use with
asymmetric app artifacts

### Drive-by changes

- migrate to `matchingList` for some app context agent config

### Related issues

- Fixes #3441

### Backward compatibility

- Yes

### Testing

Unit tests
  • Loading branch information
yorhodes authored Mar 20, 2024
1 parent dcb67e9 commit 5514ab1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
5 changes: 3 additions & 2 deletions typescript/infra/config/environments/mainnet3/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../../src/config';
import {
GasPaymentEnforcementConfig,
matchingList,
routerMatchingList,
} from '../../../src/config/agent/relayer';
import { ALL_KEY_ROLES, Role } from '../../../src/roles';
Expand Down Expand Up @@ -160,11 +161,11 @@ const hyperlane: RootAgentConfig = {
},
{
name: 'inevm_ethereum_usdc',
matchingList: routerMatchingList(inevmEthereumUsdcAddresses),
matchingList: matchingList(inevmEthereumUsdcAddresses),
},
{
name: 'inevm_ethereum_usdt',
matchingList: routerMatchingList(inevmEthereumUsdtAddresses),
matchingList: matchingList(inevmEthereumUsdtAddresses),
},
{
name: 'viction_ethereum_eth',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"inevm": {
"router": "0x8358D8291e3bEDb04804975eEa0fe9fe0fAfB147",
"type": "HypERC20"
"synthetic": "0x8358D8291e3bEDb04804975eEa0fe9fe0fAfB147"
},
"ethereum": {
"router": "0xED56728fb977b0bBdacf65bCdD5e17Bb7e84504f",
"type": "HypERC20Collateral"
"collateral": "0xED56728fb977b0bBdacf65bCdD5e17Bb7e84504f"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"inevm": {
"router": "0x97423A68BAe94b5De52d767a17aBCc54c157c0E5",
"type": "HypERC20"
"synthetic": "0x97423A68BAe94b5De52d767a17aBCc54c157c0E5"
},
"ethereum": {
"router": "0xab852e67bf03E74C89aF67C4BA97dd1088D3dA19",
"type": "HypERC20Collateral"
"collateral": "0xab852e67bf03E74C89aF67C4BA97dd1088D3dA19"
}
}
26 changes: 20 additions & 6 deletions typescript/infra/src/config/agent/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
AgentConfig,
ChainMap,
GasPaymentEnforcement,
HyperlaneAddresses,
HyperlaneAddressesMap,
HyperlaneFactories,
MatchingList,
RelayerConfig as RelayerAgentConfig,
chainMetadata,
getDomainId,
} from '@hyperlane-xyz/sdk';
import { ProtocolType, addressToBytes32 } from '@hyperlane-xyz/utils';
import { Address, ProtocolType, addressToBytes32 } from '@hyperlane-xyz/utils';

import { AgentAwsUser } from '../../agents/aws';
import { Role } from '../../roles';
Expand Down Expand Up @@ -152,11 +155,17 @@ export class RelayerConfigHelper extends AgentConfigHelper<RelayerConfig> {
}
}

// Create a matching list for the given router addresses
export function routerMatchingList(
routers: ChainMap<{ router: string }>,
routers: ChainMap<{ router: Address }>,
): MatchingList {
const chains = Object.keys(routers);
return matchingList(routers);
}

// Create a matching list for the given contract addresses
export function matchingList<F extends HyperlaneFactories>(
addressesMap: HyperlaneAddressesMap<F>,
): MatchingList {
const chains = Object.keys(addressesMap);

// matching list must have at least one element so bypass and check before returning
const matchingList: MatchingList = [];
Expand All @@ -167,11 +176,16 @@ export function routerMatchingList(
continue;
}

const uniqueAddresses = (addresses: HyperlaneAddresses<F>) =>
Array.from(new Set(Object.values(addresses)).values()).map((s) =>
addressToBytes32(s),
);

matchingList.push({
originDomain: getDomainId(chainMetadata[source]),
senderAddress: addressToBytes32(routers[source].router),
senderAddress: uniqueAddresses(addressesMap[source]),
destinationDomain: getDomainId(chainMetadata[destination]),
recipientAddress: addressToBytes32(routers[destination].router),
recipientAddress: uniqueAddresses(addressesMap[destination]),
});
}
}
Expand Down

0 comments on commit 5514ab1

Please sign in to comment.