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(eventindexer): Index nfts #14418

Merged
merged 9 commits into from
Aug 9, 2023
Merged

feat(eventindexer): Index nfts #14418

merged 9 commits into from
Aug 9, 2023

Conversation

cyberhorsey
Copy link
Contributor

This PR adds ERC721 / ERC1155 event indexing and balance calculations for our NFT Bridge, and exposes them via the HTTP API for consuming. It adds a new flag --index-nfts to the eventindexer command, to determine whether to index or not.

The route can be paginated like other queryable routes by adding &page={pageNum} to the request URL.

Route:
http://localhost:4100/nftsByAddress?address=0x02e725b7e99091bd4ccbf15228384e160ecdf78f&chainID=167006

Response:

{
"items": [
{
"id": 14,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 2,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1134,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 455,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1147,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 520,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1151,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 512,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1153,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 14,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1155,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 45,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1157,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 501,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1158,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 495,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1169,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 487,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1172,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 727,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1187,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 776,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1189,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 792,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1201,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 804,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1280,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 469,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
},
{
"id": 1288,
"chainID": 167006,
"address": "0x02e725b7e99091bd4ccbf15228384e160ecdf78f",
"amount": 1,
"tokenID": 1,
"contractAddress": "0xf030B643D6Bc433A5905d18d3f20CCfc446b8CC6",
"contractType": "ERC721"
}
],
"page": 0,
"size": 100,
"max_page": 1,
"total_pages": 1,
"total": 15,
"last": false,
"first": true,
"visible": 15
}
Etherscan account to verify the correct balance (15) of the relevant NFTs after 27 transfers in, 12 transfers out:
https://explorer.l3test.taiko.xyz/address/0x02E725B7e99091Bd4cCBf15228384e160eCdf78f

Using this information, the contractAddress and tokenID, the bridge (or other apps) can look up their current NFT balance, then call the Bridge to see if the token is canonical or bridged, and then look up the tokenURI and retreive the Metadata to display.

@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Merging #14418 (942cd87) into main (1eeba9d) will decrease coverage by 11.93%.
Report is 19 commits behind head on main.
The diff coverage is 27.56%.

@@             Coverage Diff             @@
##             main   #14418       +/-   ##
===========================================
- Coverage   77.34%   65.41%   -11.93%     
===========================================
  Files          56       90       +34     
  Lines        1452     3155     +1703     
  Branches      112      112               
===========================================
+ Hits         1123     2064      +941     
- Misses        297      965      +668     
- Partials       32      126       +94     
Flag Coverage Δ *Carryforward flag
bridge-ui 94.25% <ø> (ø) Carriedforward from 1eeba9d
eventindexer 43.90% <8.06%> (-8.16%) ⬇️
relayer 59.06% <67.21%> (?)

*This pull request uses carry forward flags. Click here to find out more.

Files Changed Coverage Δ
...r/http/get_nft_balances_by_address_and_chain_id.go 0.00% <0.00%> (ø)
packages/eventindexer/http/get_pos_stats.go 26.31% <0.00%> (ø)
packages/eventindexer/repo/event.go 52.77% <0.00%> (-4.80%) ⬇️
packages/eventindexer/repo/nft_balance.go 0.00% <0.00%> (ø)
packages/relayer/cli/cli.go 59.77% <ø> (ø)
...ackages/relayer/indexer/detect_and_handle_reorg.go 33.33% <0.00%> (ø)
...ayer/indexer/save_message_status_changed_events.go 12.50% <0.00%> (ø)
packages/relayer/indexer/subscribe.go 58.33% <58.82%> (ø)
packages/relayer/message/wait_header_synced.go 65.00% <64.28%> (ø)
packages/relayer/indexer/handle_event.go 40.54% <75.00%> (ø)
... and 6 more

... and 22 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@cyberhorsey cyberhorsey added this pull request to the merge queue Aug 9, 2023
Merged via the queue into main with commit 364b09b Aug 9, 2023
@cyberhorsey cyberhorsey deleted the index_nfts branch August 9, 2023 07:03
@github-actions github-actions bot mentioned this pull request Aug 9, 2023
2manslkh pushed a commit that referenced this pull request Aug 11, 2023
Co-authored-by: David <david@taiko.xyz>
Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com>
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