-
Notifications
You must be signed in to change notification settings - Fork 408
kaspabridge added #438
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
Closed
muhammadabubakar7526
wants to merge
15
commits into
DefiLlama:master
from
muhammadabubakar7526:kaspa-bridge
Closed
kaspabridge added #438
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bc5a7f1
kaspabridge added
muhammadabubakar7526 7d2af28
Merge branch 'master' into kaspa-bridge
muhammadabubakar7526 01660cb
Merge branch 'master' into kaspa-bridge
muhammadabubakar7526 761f867
updated logo
muhammadabubakar7526 0b219b6
pull from master branch
muhammadabubakar7526 21a2f9b
pull from kaspa bridge branch to update the code
muhammadabubakar7526 1297c08
fixed starkgate data entery
muhammadabubakar7526 6e0b35d
fixed id order as mentioned in comment
muhammadabubakar7526 e85ac9d
logo link updated from global repo of defilama icons
muhammadabubakar7526 64d9322
update kaspa bridge like aribtrum
muhammadabubakar7526 1de0840
Merge branch 'master' into kaspa-bridge
muhammadabubakar7526 5a27fd5
defilama sdk used as mentioned in comment
muhammadabubakar7526 ee5a504
pull from branch for update
muhammadabubakar7526 3a9fc41
updated zeor addresses conditionally
muhammadabubakar7526 a2b6beb
fildted events without from and to addresses
muhammadabubakar7526 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
Some comments aren't visible on the classic Files Changed page.
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
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,107 @@ | ||
| import * as sdk from "@defillama/sdk"; | ||
| import { BridgeAdapter } from "../../helpers/bridgeAdapter.type"; | ||
| import { BigNumber, utils } from "ethers"; | ||
|
|
||
| const MAILBOX_BSC = "0x5f297B3A1e8154c4D58702F7a880b7631bBf5340"; | ||
|
|
||
| const ABI = [ | ||
| "event Dispatch(bytes32 indexed id, uint32 indexed destinationDomain, bytes32 recipientAddress, bytes messageBody)", | ||
| "event Process(bytes32 indexed id, bool success)" | ||
| ]; | ||
|
|
||
| const iface = new utils.Interface(ABI); | ||
|
|
||
| function decodeMessageBody(body: string) { | ||
| try { | ||
| const coder = new utils.AbiCoder(); | ||
| const [from, to, token, amount] = coder.decode( | ||
| ["address", "address", "address", "uint256"], | ||
| body | ||
| ); | ||
| return { from, to, token, amount: BigNumber.from(amount) }; | ||
| } catch { | ||
| return null; // Important: return null to indicate failure | ||
| } | ||
| } | ||
|
|
||
| async function getKaspaBridgeEvents(fromBlock: number, toBlock: number) { | ||
| const events: any[] = []; | ||
|
|
||
| const dispatchMap = new Map< | ||
| string, | ||
| { from: string; to: string; token: string; amount: BigNumber } | ||
| >(); | ||
|
|
||
| // ---------------------- FETCH DISPATCH EVENTS ---------------------- | ||
| const dispatch = await sdk.api.util.getLogs({ | ||
| target: MAILBOX_BSC, | ||
| topic: "Dispatch(bytes32,uint32,bytes32,bytes)", | ||
| keys: [], | ||
| fromBlock, | ||
| toBlock, | ||
| chain: "bsc", | ||
| }); | ||
|
|
||
| for (const log of dispatch.output) { | ||
| const parsed = iface.parseLog({ | ||
| data: log.data, | ||
| // @ts-ignore | ||
| topics: log.topics, | ||
| }); | ||
|
|
||
| const decoded = decodeMessageBody(parsed.args.messageBody); | ||
| if (!decoded) continue; // Skip invalid message bodies | ||
|
|
||
| dispatchMap.set(log.transactionHash, decoded); | ||
|
|
||
| events.push({ | ||
| txHash: log.transactionHash, | ||
| blockNumber: log.blockNumber, | ||
| from: decoded.from, | ||
| to: decoded.to, | ||
| token: decoded.token, | ||
| isDeposit: true, | ||
| amount: decoded.amount, | ||
| }); | ||
| } | ||
|
|
||
| // ---------------------- FETCH PROCESS EVENTS ---------------------- | ||
| const process = await sdk.api.util.getLogs({ | ||
| target: MAILBOX_BSC, | ||
| topic: "Process(bytes32,bool)", | ||
| keys: [], | ||
| fromBlock, | ||
| toBlock, | ||
| chain: "bsc", | ||
| }); | ||
|
|
||
| for (const log of process.output) { | ||
| const dispatchData = dispatchMap.get(log.transactionHash); | ||
|
|
||
| // >>> Maintainer request: SKIP events without dispatch data | ||
| if (!dispatchData) continue; | ||
|
|
||
| events.push({ | ||
| txHash: log.transactionHash, | ||
| blockNumber: log.blockNumber, | ||
| from: dispatchData.from, | ||
| to: dispatchData.to, | ||
| token: dispatchData.token, | ||
| isDeposit: false, | ||
| amount: dispatchData.amount, | ||
| }); | ||
| } | ||
|
|
||
| return events; | ||
| } | ||
|
|
||
| export async function build(): Promise<BridgeAdapter> { | ||
| return { | ||
| bsc: getKaspaBridgeEvents, | ||
| }; | ||
| } | ||
|
|
||
| export default { | ||
| isAsync: true, | ||
| build, | ||
| }; | ||
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.
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.
lets filter events without from,to,token (without dispatch data)
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.
Done , please review now and merge it .