Skip to content
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

feat: make bridge tasks prettier and display more info for L2 to L1 #783

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tasks/bridge/deposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ task(TASK_BRIDGE_DEPOSITS, 'List deposits initiated on L1GraphTokenGateway')
(await graph.l1.provider.getBlock(e.blockNumber)).timestamp * 1000,
).toLocaleString()})`,
tx: `${e.transactionHash} ${e.args.from} -> ${e.args.to}`,
amount: ethers.utils.formatEther(e.args.amount),
amount: prettyBigNumber(e.args.amount),
status: emojifyRetryableStatus(
await getL1ToL2MessageStatus(e.transactionHash, graph.l1.provider, graph.l2.provider),
),
Expand All @@ -48,12 +48,10 @@ task(TASK_BRIDGE_DEPOSITS, 'List deposits initiated on L1GraphTokenGateway')
(acc, e) => acc.add(ethers.utils.parseEther(e.amount)),
ethers.BigNumber.from(0),
)
console.log(
`Found ${events.length} deposits with a total of ${ethers.utils.formatEther(total)} GRT`,
)
console.log(`Found ${events.length} deposits with a total of ${prettyBigNumber(total)} GRT`)

console.log(
'L1 to L2 message status reference: 🚧 = not yet created, ❌ = creation failed, ⚠️ = funds deposited on L2, ✅ = redeemed, ⌛ = expired',
'\nL1 to L2 message status reference: 🚧 = not yet created, ❌ = creation failed, ⚠️ = funds deposited on L2, ✅ = redeemed, ⌛ = expired',
)

printEvents(events)
Expand Down Expand Up @@ -95,3 +93,8 @@ function emojifyRetryableStatus(status: L1ToL2MessageStatus): string {
return '❌'
}
}

// Format BigNumber to 2 decimal places
function prettyBigNumber(amount: ethers.BigNumber): string {
return (+ethers.utils.formatEther(amount)).toFixed(2)
}
54 changes: 39 additions & 15 deletions tasks/bridge/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,50 @@ task(TASK_BRIDGE_WITHDRAWALS, 'List withdrawals initiated on L2GraphTokenGateway
const endBlock = taskArgs.endBlock ? parseInt(taskArgs.endBlock) : 'latest'
console.log(`Searching blocks from block ${startBlock} to block ${endBlock}`)

let totalGRTClaimed = ethers.BigNumber.from(0)
let totalGRTConfirmed = ethers.BigNumber.from(0)
let totalGRTUnconfirmed = ethers.BigNumber.from(0)

const events = await Promise.all(
(
await gateway.queryFilter(gateway.filters.WithdrawalInitiated(), startBlock, endBlock)
).map(async (e) => ({
blockNumber: `${e.blockNumber} (${new Date(
(await graph.l2.provider.getBlock(e.blockNumber)).timestamp * 1000,
).toLocaleString()})`,
tx: `${e.transactionHash} ${e.args.from} -> ${e.args.to}`,
amount: ethers.utils.formatEther(e.args.amount),
status: emojifyL2ToL1Status(
await getL2ToL1MessageStatus(e.transactionHash, graph.l1.provider, graph.l2.provider),
),
})),
).map(async (e) => {
const status = await getL2ToL1MessageStatus(
e.transactionHash,
graph.l1.provider,
graph.l2.provider,
)
if (status === L2ToL1MessageStatus.EXECUTED)
totalGRTClaimed = totalGRTClaimed.add(e.args.amount)
if (status === L2ToL1MessageStatus.CONFIRMED)
totalGRTConfirmed = totalGRTConfirmed.add(e.args.amount)
if (status === L2ToL1MessageStatus.UNCONFIRMED)
totalGRTUnconfirmed = totalGRTUnconfirmed.add(e.args.amount)

return {
blockNumber: `${e.blockNumber} (${new Date(
(await graph.l2.provider.getBlock(e.blockNumber)).timestamp * 1000,
).toLocaleString()})`,
tx: `${e.transactionHash} ${e.args.from} -> ${e.args.to}`,
amount: prettyBigNumber(e.args.amount),
status: emojifyL2ToL1Status(status),
}
}),
)

const total = events.reduce(
(acc, e) => acc.add(ethers.utils.parseEther(e.amount)),
ethers.BigNumber.from(0),
console.log(
`Found ${events.length} withdrawals for a total of ${prettyBigNumber(
totalGRTClaimed.add(totalGRTConfirmed).add(totalGRTUnconfirmed),
)} GRT`,
)
console.log(`- Total GRT claimed on L1 (executed): ${prettyBigNumber(totalGRTClaimed)} GRT`)
console.log(
`Found ${events.length} withdrawals for a total of ${ethers.utils.formatEther(total)} GRT`,
`- Total GRT claimable on L1 (confirmed): ${prettyBigNumber(totalGRTConfirmed)} GRT`,
)
console.log(`- Total GRT on transit (unconfirmed): ${prettyBigNumber(totalGRTUnconfirmed)} GRT`)

console.log(
'L2 to L1 message status reference: 🚧 = unconfirmed, ⚠️ = confirmed, ✅ = executed',
'\nL2 to L1 message status reference: 🚧 = unconfirmed, ⚠️ = confirmed, ✅ = executed',
)

printEvents(events)
Expand Down Expand Up @@ -91,3 +110,8 @@ function emojifyL2ToL1Status(status: L2ToL1MessageStatus): string {
return '❌'
}
}

// Format BigNumber to 2 decimal places
function prettyBigNumber(amount: ethers.BigNumber): string {
return (+ethers.utils.formatEther(amount)).toFixed(2)
}