-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add WithdrawalTransaction entity to L2 subgraph
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
- Loading branch information
1 parent
7b84b26
commit a82459d
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import { WithdrawalInitiated } from '../types/L2GraphTokenGateway/L2GraphTokenGateway' | ||
import { GraphNetwork } from '../types/schema' | ||
import { createOrLoadGraphNetwork } from './helpers' | ||
import { BridgeWithdrawalTransaction } from '../types/schema' | ||
|
||
export function handleWithdrawalInitiated(event: WithdrawalInitiated): void { | ||
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) | ||
|
||
// Save the withdrawal transaction | ||
let withdrawalTransaction = new BridgeWithdrawalTransaction( | ||
event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), | ||
) | ||
|
||
// Note that this only runs on L2, so we can fix block number to the current L1 estimate | ||
withdrawalTransaction.blockNumber = graphNetwork.currentL1BlockNumber!.toI32() | ||
withdrawalTransaction.timestamp = event.block.timestamp.toI32() | ||
withdrawalTransaction.signer = event.params.from.toHexString() | ||
withdrawalTransaction.type = 'BridgeWithdrawal' | ||
withdrawalTransaction.txHash = event.transaction.hash | ||
withdrawalTransaction.from = event.params.from | ||
withdrawalTransaction.to = event.params.to | ||
withdrawalTransaction.transactionIndex = event.params.l2ToL1Id | ||
withdrawalTransaction.exitNum = event.params.exitNum | ||
withdrawalTransaction.amount = event.params.amount | ||
withdrawalTransaction.l1Token = event.params.l1Token | ||
withdrawalTransaction.save() | ||
|
||
// Update total GRT withdrawn | ||
graphNetwork.totalGRTWithdrawn = graphNetwork.totalGRTWithdrawn.plus(event.params.amount) | ||
graphNetwork.save() | ||
} |