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: fetch token deposits from event logs #2168

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

fionnachan
Copy link
Member

Closes FS-1071

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
arbitrum-token-bridge ✅ Ready (Inspect) Visit Preview Jan 13, 2025 0:44am


expect(result).toHaveLength(1)
expect(result).toEqual(
expect.arrayContaining([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are the results significantly different from fetchDepositsFromSubgraph test? I'd assume fetching deposits through event logs, with an additional sender condition, would be a subset of overall deposits being fetched via subgraph, but there seems to be no intersection. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchDepositsFromSubgraph only tests for ETH deposits so this token deposits tests will be all different

in fact, we need to add tests for token deposits fetches to the subgraph test

parentChainId: 1,
pageSize: 100,
parentGatewayAddresses: [
'0xa3A7B6F88361F48403514059F1F16C8E78d60EeC', // Parent Standard Gateway
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't redefine the addresses here. Instead, should reuse them from an existing source. Eg. getArbitrumNetwork(42161).tokenBridge.parentErc20Gateway if that works.

pageSize: 100
childChainId: 42161,
parentChainId: 1,
pageSize: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pageSize required in the API?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is reused between subgraph and event logs tests

}

/**
* Fetches initiated token withdrawals from event logs in range of [fromBlock, toBlock].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fetches initiated token withdrawals from event logs in range of [fromBlock, toBlock].
* Fetches initiated token deposits from event logs in range of [fromBlock, toBlock].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls update the remainder of comments to have deposits instead of withdrawals~~

* @param query.parentGatewayAddresses L2 gateway addresses to use
*/
export async function fetchTokenDepositsFromEventLogs({
sender,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must decide between sender vs fromAddress, and receiver vs toAddress in this file and stick to one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDepositEvents is following the format of getWithdrawalEvents in arbitrum sdk's erc20Bridger
we'll move this function to arbitrum sdk later so i'll keep fromAddress and toAddress for it


parentGatewayAddresses.forEach(gatewayAddress => {
// funds sent by this address
if (sender) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we okay with returning empty data if no sender or receiver is passed?
getDepositEvents supports sender and receiver being null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we're handling it at the moment with fetchTokenWithdrawalsFromEventLogs so following that format and i think that's fine

L1ERC20Gateway__factory,
contract =>
contract.filters.DepositInitiated(
null, // parentToken
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pass parentTokenAddress here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fairly sure it's a typechain typing issue
we are doing the same with withdrawals

image

childChainId: 42161,
parentChainId: 1,
parentGatewayAddresses: [
getArbitrumNetwork(42161).tokenBridge!.parentErc20Gateway,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could have getArbitrumNetwork(42161) as a variable

) {
return [...new Map(events.map(item => [item.txHash, item])).values()]
}
import { dedupeEvents } from '../deposits/helpers'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdrawals shouldn't really import from deposits helpers, maybe we can move it to /TransactionHistory/helpers instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants