-
Notifications
You must be signed in to change notification settings - Fork 2
feat: track simple transfer completed oft #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
NikolasHaimerl
wants to merge
12
commits into
nikolas/track-FallbackHyperEVMFlowCompleted
Choose a base branch
from
nikolas/track-SimpleTransferCompleted-OFT
base: nikolas/track-FallbackHyperEVMFlowCompleted
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9839edc
refactor: extract SimpleTransferFlowCompleted event handling to share…
NikolasHaimerl 180f3f9
Merge branch 'nikolas/remove-default-mapping' into nikolas/track-Simp…
NikolasHaimerl 64f3f75
add addresses for hyperEVM
NikolasHaimerl e28de67
Merge branch 'nikolas/remove-default-mapping' into nikolas/track-Simp…
NikolasHaimerl 23b6a10
Merge branch 'nikolas/remove-default-mapping' into nikolas/track-Simp…
NikolasHaimerl 6a9e504
move endpoint address
NikolasHaimerl cec1bb8
Merge branch 'nikolas/remove-default-mapping' into nikolas/track-Fall…
NikolasHaimerl 321e944
Merge branch 'nikolas/track-FallbackHyperEVMFlowCompleted' into nikol…
NikolasHaimerl 7488068
Merge branch 'nikolas/track-FallbackHyperEVMFlowCompleted' into nikol…
NikolasHaimerl 2125cf0
update delete function
NikolasHaimerl 5deacb4
update delete function
NikolasHaimerl 2b99900
Optimize OFT indexer by conditionally fetching ComposeDelivered events
NikolasHaimerl 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
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
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
92 changes: 92 additions & 0 deletions
92
packages/indexer/src/data-indexing/service/hyperEvmExecutor.ts
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,92 @@ | ||
| import { ethers, providers } from "ethers"; | ||
| import { SimpleTransferFlowCompletedLog } from "../model"; | ||
| import { EventDecoder } from "../../web3/EventDecoder"; | ||
| import { entities, SaveQueryResult } from "@repo/indexer-database"; | ||
| import * as across from "@across-protocol/sdk"; | ||
| import { BlockchainEventRepository } from "../../../../indexer-database/dist/src/utils"; | ||
|
|
||
| /** | ||
| * Decodes and extracts `SimpleTransferFlowCompleted` events from a collection of transaction receipts. | ||
| * This function iterates over transaction receipts, decodes logs, and filters for `SimpleTransferFlowCompleted` events | ||
| * emitted by a specified HyperEVM executor contract. | ||
| * | ||
| * @param transactionReceipts A record of transaction receipts, indexed by their transaction hash. | ||
| * @param contractAddress The address of the HyperEVM executor contract to filter events from. | ||
| * @returns An array of decoded `SimpleTransferFlowCompletedLog` objects. | ||
| */ | ||
| export function getSimpleTransferFlowCompletedEventsFromTransactionReceipts( | ||
| transactionReceipts: Record<string, ethers.providers.TransactionReceipt>, | ||
| contractAddress: string, | ||
| ) { | ||
| const events: SimpleTransferFlowCompletedLog[] = []; | ||
| for (const txHash of Object.keys(transactionReceipts)) { | ||
| const transactionReceipt = transactionReceipts[ | ||
| txHash | ||
| ] as providers.TransactionReceipt; | ||
| const simpleTransferFlowCompletedEvents: SimpleTransferFlowCompletedLog[] = | ||
| EventDecoder.decodeSimpleTransferFlowCompletedEvents( | ||
| transactionReceipt, | ||
| contractAddress, | ||
| ); | ||
| if (simpleTransferFlowCompletedEvents.length > 0) { | ||
| events.push(...simpleTransferFlowCompletedEvents); | ||
| } | ||
| } | ||
|
|
||
| return events; | ||
| } | ||
|
|
||
| /** | ||
| * Formats and saves `SimpleTransferFlowCompleted` events to the database. | ||
| * This function maps the raw event data to the database entity format, marks them as finalized if they are within the finalized block range, | ||
| * and then saves them to the database in batches. | ||
| * | ||
| * @param repository The repository for database operations, specifically for saving blockchain events. | ||
| * @param simpleTransferFlowCompletedEvents An array of `SimpleTransferFlowCompletedLog` events to be processed. | ||
| * @param lastFinalisedBlock The last block number that is considered finalized. | ||
| * @param chainId The ID of the chain where these events were emitted. | ||
| * @param blockDates A record mapping block numbers to their corresponding `Date` objects. | ||
| * @param chunkSize The number of events to save in a single batch. Defaults to 100. | ||
| * @returns A promise that resolves to an array of `SaveQueryResult` for the saved events. | ||
| */ | ||
| export async function formatAndSaveSimpleTransferFlowCompletedEvents( | ||
| repository: BlockchainEventRepository, | ||
| simpleTransferFlowCompletedEvents: SimpleTransferFlowCompletedLog[], | ||
| lastFinalisedBlock: number, | ||
| chainId: number, | ||
| blockDates: Record<number, Date>, | ||
| chunkSize = 100, | ||
| ) { | ||
| const formattedEvents: Partial<entities.SimpleTransferFlowCompleted>[] = | ||
| simpleTransferFlowCompletedEvents.map((event) => { | ||
| return { | ||
| blockNumber: event.blockNumber, | ||
| logIndex: event.logIndex, | ||
| transactionHash: event.transactionHash, | ||
| transactionIndex: event.transactionIndex, | ||
| blockTimestamp: blockDates[event.blockNumber]!, | ||
| chainId: chainId.toString(), | ||
| quoteNonce: event.args.quoteNonce, | ||
| finalRecipient: event.args.finalRecipient, | ||
| finalToken: event.args.finalToken.toString(), | ||
| evmAmountIn: event.args.evmAmountIn.toString(), | ||
| bridgingFeesIncurred: event.args.bridgingFeesIncurred.toString(), | ||
| evmAmountSponsored: event.args.evmAmountSponsored.toString(), | ||
| finalised: event.blockNumber <= lastFinalisedBlock, | ||
| }; | ||
| }); | ||
|
|
||
| const chunkedEvents = across.utils.chunk(formattedEvents, chunkSize); | ||
| const savedEvents = await Promise.all( | ||
| chunkedEvents.map((eventsChunk) => | ||
| repository.saveAndHandleFinalisationBatch<entities.SimpleTransferFlowCompleted>( | ||
| entities.SimpleTransferFlowCompleted, | ||
| eventsChunk, | ||
| ["chainId", "blockNumber", "transactionHash", "logIndex"], | ||
| [], | ||
| ), | ||
| ), | ||
| ); | ||
| const result = savedEvents.flat(); | ||
| return result; | ||
| } |
Oops, something went wrong.
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.
Need this function to be able to share the storing function for Simple transfers for OFT and CCTP, see https://github.com/across-protocol/indexer/pull/433/files#diff-103d64d5e62515d16ca06086549eabe7dbc05b089ad0c69d013da5fc23918d84R52