Skip to content

Commit 3584a0d

Browse files
authored
Merge pull request #303 from BootNodeDev/hyperlane-fix
Fix Hyperlane
2 parents 8d1e92d + ce1e431 commit 3584a0d

File tree

4 files changed

+114
-85
lines changed

4 files changed

+114
-85
lines changed

src/adapters/hyperlane/index.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function bytes32ToAddress(bytes32: string) {
5858
return ethers.utils.getAddress('0x' + bytes32.slice(26));
5959
}
6060

61+
const cachedTokens: Record<string, Record<string, string>> = {};
62+
6163
function constructParams(chain: string) {
6264
let eventParams = [] as PartialContractEventParams[];
6365
const mailboxAddress = ethers.utils.getAddress(addresses[chain].mailbox);
@@ -88,15 +90,36 @@ function constructParams(chain: string) {
8890
logKeys: {
8991
blockNumber: "blockNumber",
9092
txHash: "transactionHash",
91-
from: "address",
9293
token: "address",
9394
},
95+
logGetters: {
96+
token: async (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => {
97+
cachedTokens[provider.chainId] ||= {};
98+
99+
if (cachedTokens[provider.chainId][log.address]) {
100+
return cachedTokens[provider.chainId][log.address];
101+
}
102+
103+
const data = iface.encodeFunctionData("wrappedToken");
104+
const tokenAddress =
105+
await provider.call({ to: log.address, data }).then((r) => {
106+
return iface.decodeFunctionResult("wrappedToken", r)[0];
107+
}).catch(() => log.address);
108+
109+
cachedTokens[provider.chainId][log.address] = tokenAddress;
110+
111+
return tokenAddress;
112+
}
113+
},
94114
argKeys: {
95115
to: "recipient",
96116
amount: "amount",
97117
},
98118
argGetters: {
99-
to: (log: any) => { bytes32ToAddress(log.recipient); }
119+
to: (logArgs: any) => { bytes32ToAddress(logArgs.recipient); }
120+
},
121+
txKeys: {
122+
from: "from",
100123
},
101124
};
102125
const depositParams: PartialContractEventParams = {
@@ -105,6 +128,7 @@ function constructParams(chain: string) {
105128
abi: [
106129
"event SentTransferRemote(uint32 indexed destination, bytes32 indexed recipient, uint256 amount)",
107130
"event Dispatch(address indexed sender, uint32 indexed destination, bytes32 indexed recipient, bytes message)",
131+
"function wrappedToken() external view returns (address)",
108132
],
109133
isDeposit: true,
110134
filter: {
@@ -118,6 +142,7 @@ function constructParams(chain: string) {
118142
abi: [
119143
"event ReceivedTransferRemote(uint32 indexed origin, bytes32 indexed recipient, uint256 amount)",
120144
"event Process(uint32 indexed origin, bytes32 indexed sender, address indexed recipient)",
145+
"function wrappedToken() external view returns (address)",
121146
],
122147
isDeposit: false,
123148
filter: {

src/data/bridgeNetworkData.ts

+80-80
Original file line numberDiff line numberDiff line change
@@ -1609,84 +1609,84 @@ export default [
16091609
bitlayer: "btr",
16101610
},
16111611
},
1612-
// {
1613-
// id: 72,
1614-
// displayName: "Hyperlane",
1615-
// bridgeDbName: "hyperlane",
1616-
// iconLink: "icons:hyperlane",
1617-
// largeTxThreshold: 10000,
1618-
// url: "https://hyperlane.xyz/",
1619-
// chains: [
1620-
// "Aleph Zero EVM",
1621-
// "Ancient8",
1622-
// "Arbitrum",
1623-
// "Arthera",
1624-
// "Astar",
1625-
// "Astar zkEVM",
1626-
// "Avalanche",
1627-
// "Base",
1628-
// "Bitlayer",
1629-
// "Blast",
1630-
// "BOB",
1631-
// "BSC",
1632-
// "Celo",
1633-
// // "CheeseChain",
1634-
// "Chiliz",
1635-
// "Core",
1636-
// "Cyber",
1637-
// "Degen",
1638-
// "Dogechain",
1639-
// "Endurance",
1640-
// "Ethereum",
1641-
// "Everclear",
1642-
// "Flare",
1643-
// "Forma",
1644-
// "Fraxtal",
1645-
// "Fuse",
1646-
// "Gnosis",
1647-
// "Immutable zkEVM",
1648-
// "Injective EVM",
1649-
// "KalyChain",
1650-
// "Kroma",
1651-
// "Linea",
1652-
// "Lisk",
1653-
// "LUKSO",
1654-
// // "Lumia Prism",
1655-
// "Manta",
1656-
// "Mantle",
1657-
// "Merlin",
1658-
// "Metis",
1659-
// "Mint",
1660-
// "Mode",
1661-
// "Molten",
1662-
// "Moonbeam",
1663-
// "Oort",
1664-
// "Optimism",
1665-
// "Polygon",
1666-
// "Polygon zkEVM",
1667-
// "Proof of Play Apex",
1668-
// "PulseChain",
1669-
// "RARI Chain",
1670-
// "re.al",
1671-
// "Redstone",
1672-
// "Rootstock",
1673-
// "Sanko",
1674-
// "Scroll",
1675-
// "Sei",
1676-
// "Shibarium",
1677-
// "Superposition",
1678-
// "Taiko",
1679-
// "Tangle",
1680-
// "Viction",
1681-
// "World Chain",
1682-
// "Xai",
1683-
// "X Layer",
1684-
// "ZetaChain",
1685-
// "Zircuit",
1686-
// "Zora",
1687-
// ],
1688-
// chainMapping: {
1689-
// avalanche: "avax",
1690-
// },
1691-
// },
1612+
{
1613+
id: 76,
1614+
displayName: "Hyperlane",
1615+
bridgeDbName: "hyperlane",
1616+
iconLink: "icons:hyperlane",
1617+
largeTxThreshold: 10000,
1618+
url: "https://hyperlane.xyz/",
1619+
chains: [
1620+
"Aleph Zero EVM",
1621+
"Ancient8",
1622+
"Arbitrum",
1623+
"Arthera",
1624+
"Astar",
1625+
"Astar zkEVM",
1626+
"Avalanche",
1627+
"Base",
1628+
"Bitlayer",
1629+
"Blast",
1630+
"BOB",
1631+
"BSC",
1632+
"Celo",
1633+
// "CheeseChain",
1634+
"Chiliz",
1635+
"Core",
1636+
"Cyber",
1637+
"Degen",
1638+
"Dogechain",
1639+
"Endurance",
1640+
"Ethereum",
1641+
"Everclear",
1642+
"Flare",
1643+
"Forma",
1644+
"Fraxtal",
1645+
"Fuse",
1646+
"Gnosis",
1647+
"Immutable zkEVM",
1648+
"Injective EVM",
1649+
"KalyChain",
1650+
"Kroma",
1651+
"Linea",
1652+
"Lisk",
1653+
"LUKSO",
1654+
// "Lumia Prism",
1655+
"Manta",
1656+
"Mantle",
1657+
"Merlin",
1658+
"Metis",
1659+
"Mint",
1660+
"Mode",
1661+
"Molten",
1662+
"Moonbeam",
1663+
"Oort",
1664+
"Optimism",
1665+
"Polygon",
1666+
"Polygon zkEVM",
1667+
"Proof of Play Apex",
1668+
"PulseChain",
1669+
"RARI Chain",
1670+
"re.al",
1671+
"Redstone",
1672+
"Rootstock",
1673+
"Sanko",
1674+
"Scroll",
1675+
"Sei",
1676+
"Shibarium",
1677+
"Superposition",
1678+
"Taiko",
1679+
"Tangle",
1680+
"Viction",
1681+
"World Chain",
1682+
"Xai",
1683+
"X Layer",
1684+
"ZetaChain",
1685+
"Zircuit",
1686+
"Zora",
1687+
],
1688+
chainMapping: {
1689+
avalanche: "avax",
1690+
},
1691+
},
16921692
] as BridgeNetwork[];

src/helpers/bridgeAdapter.type.ts

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type ContractEventParams = {
4343
topic: string;
4444
abi: string[];
4545
logKeys?: EventKeyMapping; // retrieve data from event log
46+
logGetters?: Partial<Record<keyof EventKeyMapping, (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => Promise<any>>>;
4647
argKeys?: EventKeyMapping; // retrieve data from parsed event log
4748
argGetters?: Partial<Record<keyof EventKeyMapping, (log: any) => any>>;
4849
txKeys?: EventKeyMapping; // retrieve data from transaction referenced in event log
@@ -68,6 +69,7 @@ export type PartialContractEventParams = {
6869
topic?: string;
6970
abi?: string[];
7071
logKeys?: EventKeyMapping;
72+
logGetters?: Partial<Record<keyof EventKeyMapping, (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => Promise<any>>>;
7173
argKeys?: EventKeyMapping;
7274
argGetters?: Partial<Record<keyof EventKeyMapping, (log: any) => any>>;
7375
txKeys?: EventKeyMapping;

src/helpers/processTransactions.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const getTxDataFromEVMEventLogs = async (
7878
mapTokens,
7979
getTokenFromReceipt,
8080
argGetters,
81+
logGetters,
8182
} = params;
8283
const targetValue = target
8384
// if this is ever used, need to also overwrite fromBlock and toBlock
@@ -157,8 +158,9 @@ export const getTxDataFromEVMEventLogs = async (
157158
.process(async (txLog: any, i) => {
158159
data[i] = data[i] || {};
159160
data[i]["isDeposit"] = isDeposit;
160-
Object.entries(logKeys!).map(([eventKey, logKey]) => {
161-
const value = txLog[logKey];
161+
await Promise.all(Object.entries(logKeys!).map(async ([eventKey, logKey]) => {
162+
// @ts-ignore
163+
const value = await logGetters?.[eventKey]?.(provider, iface, txLog) || txLog[logKey];
162164
if (typeof value !== EventKeyTypes[eventKey]) {
163165
throw new Error(
164166
`Type of ${eventKey} retrieved using ${logKey} is ${typeof value} when it must be ${
@@ -167,7 +169,7 @@ export const getTxDataFromEVMEventLogs = async (
167169
);
168170
}
169171
data[i][eventKey] = value;
170-
});
172+
}));
171173
let parsedLog = {} as any;
172174
try {
173175
parsedLog = iface.parseLog({

0 commit comments

Comments
 (0)