-
Notifications
You must be signed in to change notification settings - Fork 407
feat: track hyperbridge evm activity #433
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
Open
royvardhan
wants to merge
3
commits into
DefiLlama:master
Choose a base branch
from
royvardhan:hyperbridge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type"; | ||
| import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions"; | ||
| import { Chain } from "@defillama/sdk/build/general"; | ||
|
|
||
| const ismpHostAddresses = { | ||
| ethereum: "0x792A6236AF69787C40cF76b69B4c8c7B28c4cA20", | ||
| arbitrum: "0xE05AFD4Eb2ce6d65c40e1048381BD0Ef8b4B299e", | ||
| base: "0x6FFe92e4d7a9D589549644544780e6725E84b248", | ||
| bsc: "0x24B5d421Ec373FcA57325dd2F0C074009Af021F7", | ||
| polygon: "0xD8d3db17C1dF65b301D45C84405CcAC1395C559a", | ||
| unichain: "0x2A17C1c3616Bbc33FCe5aF5B965F166ba76cEDAf", | ||
| } as const; | ||
|
|
||
| type SupportedChains = keyof typeof ismpHostAddresses; | ||
|
|
||
| const constructParams = (chain: SupportedChains) => { | ||
| const ismpHost = ismpHostAddresses[chain]; | ||
|
|
||
| return async (fromBlock: number, toBlock: number) => { | ||
| const postRequestEventParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostRequestEvent(string,string,address,bytes,uint256,uint256,bytes,uint256)", | ||
| abi: [ | ||
| "event PostRequestEvent(string source, string dest, address indexed from, bytes to, uint256 nonce, uint256 timeoutTimestamp, bytes body, uint256 fee)", | ||
| ], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const postRequestHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostRequestHandled(bytes32,address)", | ||
| abi: ["event PostRequestHandled(bytes32 indexed commitment, address relayer)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const postResponseEventParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostResponseEvent(string,string,address,bytes,uint256,uint256,bytes,bytes,uint256,uint256)", | ||
| abi: [ | ||
| "event PostResponseEvent(string source, string dest, address indexed from, bytes to, uint256 nonce, uint256 timeoutTimestamp, bytes body, bytes response, uint256 responseTimeoutTimestamp, uint256 fee)", | ||
| ], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const postResponseHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostResponseHandled(bytes32,address)", | ||
| abi: ["event PostResponseHandled(bytes32 indexed commitment, address relayer)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| // ========== ISMP Host Get Request Events ========== | ||
|
|
||
| const getRequestEventParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "GetRequestEvent(string,string,address,bytes[],uint256,uint256,uint256,bytes,uint256)", | ||
| abi: [ | ||
| "event GetRequestEvent(string source, string dest, address indexed from, bytes[] keys, uint256 height, uint256 nonce, uint256 timeoutTimestamp, bytes context, uint256 fee)", | ||
| ], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const getRequestHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "GetRequestHandled(bytes32,address)", | ||
| abi: ["event GetRequestHandled(bytes32 indexed commitment, address relayer)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| // ========== ISMP Host Timeout Events ========== | ||
|
|
||
| const postRequestTimeoutHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostRequestTimeoutHandled(bytes32,string)", | ||
| abi: ["event PostRequestTimeoutHandled(bytes32 indexed commitment, string dest)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const postResponseTimeoutHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "PostResponseTimeoutHandled(bytes32,string)", | ||
| abi: ["event PostResponseTimeoutHandled(bytes32 indexed commitment, string dest)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const getRequestTimeoutHandledParams: PartialContractEventParams = { | ||
| target: ismpHost, | ||
| topic: "GetRequestTimeoutHandled(bytes32,string)", | ||
| abi: ["event GetRequestTimeoutHandled(bytes32 indexed commitment, string dest)"], | ||
| logKeys: { | ||
| blockNumber: "blockNumber", | ||
| txHash: "transactionHash", | ||
| }, | ||
| getTokenFromReceipt: { | ||
| token: true, | ||
| amount: true, | ||
| }, | ||
| }; | ||
|
|
||
| const ismpEventParams = [ | ||
| postRequestEventParams, | ||
| postRequestHandledParams, | ||
| postResponseEventParams, | ||
| postResponseHandledParams, | ||
| getRequestEventParams, | ||
| getRequestHandledParams, | ||
| postRequestTimeoutHandledParams, | ||
| postResponseTimeoutHandledParams, | ||
| getRequestTimeoutHandledParams, | ||
| ]; | ||
|
|
||
| const ismpEvents = await getTxDataFromEVMEventLogs( | ||
| "hyperbridge", | ||
| chain as Chain, | ||
| fromBlock, | ||
| toBlock, | ||
| ismpEventParams | ||
| ); | ||
|
|
||
| return ismpEvents; | ||
| }; | ||
| }; | ||
|
|
||
| const adapter: BridgeAdapter = { | ||
| ethereum: constructParams("ethereum"), | ||
| arbitrum: constructParams("arbitrum"), | ||
| base: constructParams("base"), | ||
| bsc: constructParams("bsc"), | ||
| polygon: constructParams("polygon"), | ||
| unichain: constructParams("unichain"), | ||
| }; | ||
|
|
||
| export default adapter; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing from and to in all events
please check by running tests
npm run test hyperbridge 1000There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If from and to denotes the transfer direction then I don't think it fits what we are doing here.
These are messaging layer events, and inside these events the transfer of tokens can happen from any dapp integrating Hyperbridge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dapp at Chain A can dispatch a GetRequest to get some data from Chain B, and when GetResponse is received, there may or may not be events of transfer.
In simple terms, a dapp can integrate Hyperbridge, use the messaging functions to execute certain operations, and in these operations, there can be transfer events.
So if we look at these messaging layer events, we will find the transfer events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there is from and to in event abi
event PostResponseEvent(string source, string dest, address indexed from, bytes towhat do they mean?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The events in this PR are all ISMP (Hyperbridge's messaging protocol) events, and the from and to addresses in the event signatures are the contract addresses that send or receive the message.
Our methodology for tracking volume on Hyperbridge is to sum all token Transfer events from any transaction that emits any ISMP event. The core idea is that any token Transfer event found in a transaction that emits an ISMP event was triggered by the processing or dispatch of a cross-chain message on the Hyperbridge protocol.