Skip to content

Commit

Permalink
Merge pull request #303 from BootNodeDev/hyperlane-fix
Browse files Browse the repository at this point in the history
Fix Hyperlane
  • Loading branch information
vrtnd authored Nov 17, 2024
2 parents 8d1e92d + ce1e431 commit 3584a0d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 85 deletions.
29 changes: 27 additions & 2 deletions src/adapters/hyperlane/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function bytes32ToAddress(bytes32: string) {
return ethers.utils.getAddress('0x' + bytes32.slice(26));
}

const cachedTokens: Record<string, Record<string, string>> = {};

function constructParams(chain: string) {
let eventParams = [] as PartialContractEventParams[];
const mailboxAddress = ethers.utils.getAddress(addresses[chain].mailbox);
Expand Down Expand Up @@ -88,15 +90,36 @@ function constructParams(chain: string) {
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
from: "address",
token: "address",
},
logGetters: {
token: async (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => {
cachedTokens[provider.chainId] ||= {};

if (cachedTokens[provider.chainId][log.address]) {
return cachedTokens[provider.chainId][log.address];
}

const data = iface.encodeFunctionData("wrappedToken");
const tokenAddress =
await provider.call({ to: log.address, data }).then((r) => {
return iface.decodeFunctionResult("wrappedToken", r)[0];
}).catch(() => log.address);

cachedTokens[provider.chainId][log.address] = tokenAddress;

return tokenAddress;
}
},
argKeys: {
to: "recipient",
amount: "amount",
},
argGetters: {
to: (log: any) => { bytes32ToAddress(log.recipient); }
to: (logArgs: any) => { bytes32ToAddress(logArgs.recipient); }
},
txKeys: {
from: "from",
},
};
const depositParams: PartialContractEventParams = {
Expand All @@ -105,6 +128,7 @@ function constructParams(chain: string) {
abi: [
"event SentTransferRemote(uint32 indexed destination, bytes32 indexed recipient, uint256 amount)",
"event Dispatch(address indexed sender, uint32 indexed destination, bytes32 indexed recipient, bytes message)",
"function wrappedToken() external view returns (address)",
],
isDeposit: true,
filter: {
Expand All @@ -118,6 +142,7 @@ function constructParams(chain: string) {
abi: [
"event ReceivedTransferRemote(uint32 indexed origin, bytes32 indexed recipient, uint256 amount)",
"event Process(uint32 indexed origin, bytes32 indexed sender, address indexed recipient)",
"function wrappedToken() external view returns (address)",
],
isDeposit: false,
filter: {
Expand Down
160 changes: 80 additions & 80 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1609,84 +1609,84 @@ export default [
bitlayer: "btr",
},
},
// {
// id: 72,
// displayName: "Hyperlane",
// bridgeDbName: "hyperlane",
// iconLink: "icons:hyperlane",
// largeTxThreshold: 10000,
// url: "https://hyperlane.xyz/",
// chains: [
// "Aleph Zero EVM",
// "Ancient8",
// "Arbitrum",
// "Arthera",
// "Astar",
// "Astar zkEVM",
// "Avalanche",
// "Base",
// "Bitlayer",
// "Blast",
// "BOB",
// "BSC",
// "Celo",
// // "CheeseChain",
// "Chiliz",
// "Core",
// "Cyber",
// "Degen",
// "Dogechain",
// "Endurance",
// "Ethereum",
// "Everclear",
// "Flare",
// "Forma",
// "Fraxtal",
// "Fuse",
// "Gnosis",
// "Immutable zkEVM",
// "Injective EVM",
// "KalyChain",
// "Kroma",
// "Linea",
// "Lisk",
// "LUKSO",
// // "Lumia Prism",
// "Manta",
// "Mantle",
// "Merlin",
// "Metis",
// "Mint",
// "Mode",
// "Molten",
// "Moonbeam",
// "Oort",
// "Optimism",
// "Polygon",
// "Polygon zkEVM",
// "Proof of Play Apex",
// "PulseChain",
// "RARI Chain",
// "re.al",
// "Redstone",
// "Rootstock",
// "Sanko",
// "Scroll",
// "Sei",
// "Shibarium",
// "Superposition",
// "Taiko",
// "Tangle",
// "Viction",
// "World Chain",
// "Xai",
// "X Layer",
// "ZetaChain",
// "Zircuit",
// "Zora",
// ],
// chainMapping: {
// avalanche: "avax",
// },
// },
{
id: 76,
displayName: "Hyperlane",
bridgeDbName: "hyperlane",
iconLink: "icons:hyperlane",
largeTxThreshold: 10000,
url: "https://hyperlane.xyz/",
chains: [
"Aleph Zero EVM",
"Ancient8",
"Arbitrum",
"Arthera",
"Astar",
"Astar zkEVM",
"Avalanche",
"Base",
"Bitlayer",
"Blast",
"BOB",
"BSC",
"Celo",
// "CheeseChain",
"Chiliz",
"Core",
"Cyber",
"Degen",
"Dogechain",
"Endurance",
"Ethereum",
"Everclear",
"Flare",
"Forma",
"Fraxtal",
"Fuse",
"Gnosis",
"Immutable zkEVM",
"Injective EVM",
"KalyChain",
"Kroma",
"Linea",
"Lisk",
"LUKSO",
// "Lumia Prism",
"Manta",
"Mantle",
"Merlin",
"Metis",
"Mint",
"Mode",
"Molten",
"Moonbeam",
"Oort",
"Optimism",
"Polygon",
"Polygon zkEVM",
"Proof of Play Apex",
"PulseChain",
"RARI Chain",
"re.al",
"Redstone",
"Rootstock",
"Sanko",
"Scroll",
"Sei",
"Shibarium",
"Superposition",
"Taiko",
"Tangle",
"Viction",
"World Chain",
"Xai",
"X Layer",
"ZetaChain",
"Zircuit",
"Zora",
],
chainMapping: {
avalanche: "avax",
},
},
] as BridgeNetwork[];
2 changes: 2 additions & 0 deletions src/helpers/bridgeAdapter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type ContractEventParams = {
topic: string;
abi: string[];
logKeys?: EventKeyMapping; // retrieve data from event log
logGetters?: Partial<Record<keyof EventKeyMapping, (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => Promise<any>>>;
argKeys?: EventKeyMapping; // retrieve data from parsed event log
argGetters?: Partial<Record<keyof EventKeyMapping, (log: any) => any>>;
txKeys?: EventKeyMapping; // retrieve data from transaction referenced in event log
Expand All @@ -68,6 +69,7 @@ export type PartialContractEventParams = {
topic?: string;
abi?: string[];
logKeys?: EventKeyMapping;
logGetters?: Partial<Record<keyof EventKeyMapping, (provider: LlamaProvider, iface: ethers.utils.Interface, log: any) => Promise<any>>>;
argKeys?: EventKeyMapping;
argGetters?: Partial<Record<keyof EventKeyMapping, (log: any) => any>>;
txKeys?: EventKeyMapping;
Expand Down
8 changes: 5 additions & 3 deletions src/helpers/processTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const getTxDataFromEVMEventLogs = async (
mapTokens,
getTokenFromReceipt,
argGetters,
logGetters,
} = params;
const targetValue = target
// if this is ever used, need to also overwrite fromBlock and toBlock
Expand Down Expand Up @@ -157,8 +158,9 @@ export const getTxDataFromEVMEventLogs = async (
.process(async (txLog: any, i) => {
data[i] = data[i] || {};
data[i]["isDeposit"] = isDeposit;
Object.entries(logKeys!).map(([eventKey, logKey]) => {
const value = txLog[logKey];
await Promise.all(Object.entries(logKeys!).map(async ([eventKey, logKey]) => {
// @ts-ignore
const value = await logGetters?.[eventKey]?.(provider, iface, txLog) || txLog[logKey];
if (typeof value !== EventKeyTypes[eventKey]) {
throw new Error(
`Type of ${eventKey} retrieved using ${logKey} is ${typeof value} when it must be ${
Expand All @@ -167,7 +169,7 @@ export const getTxDataFromEVMEventLogs = async (
);
}
data[i][eventKey] = value;
});
}));
let parsedLog = {} as any;
try {
parsedLog = iface.parseLog({
Expand Down

0 comments on commit 3584a0d

Please sign in to comment.