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: token hub #3479

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

Conversation

matijamarjanovic
Copy link
Contributor

@matijamarjanovic matijamarjanovic commented Jan 10, 2025

Description

Token hub is a registry for tokens and NFTs created on gno.land. Since all the tokens are visible in each their own realms, as it is right now there is no easy way that a user can check which tokens belong to him by his address. Token hub bypasses this by concentrating each each token in it's own realm and allows operations over these tokens providing a easier way to communicate with the realms in which the tokens are originally made. Since grc20 registry already exists the idea is to combine it's functionality with similar concept used for other tokens to create a realm that will contain information about all tokens, this way you will be able to get all your token balances in one place.

See more details

How it works

In the realm where token is being made, tokenhub needs to be imported and the newly made token has to be registered to the token hub by using RegisterToken function and passing the token as an argument. This is everything token hub needs to be able to operate. Simiraly how it is done here for GRC20 token hub registers a pointer to the token in it's registry.

  • For GRC20 the mentioned registry is used in Token Hub
  • For GRC721 similar approach as in that registry is implemented; note: each NFT has to be registered after minting because each NFT has his own ID. Although nft collection could be registered without keeping track of IDs, this would prove to be useless for anything besides statistics (how many NFTs are minted in that collection)
  • For GRC1155 the method is a bit different - since multiple fungible and non-fungible tokens are a part of the same collection, to keep track of balances one would need both collection (getter) and the token ID, this is why in this case tokens of the same collection are registered separately, which at the end of the day makes sence, but does represent an extra step both in registration and in getting the balance

More Details

In order to make this work I had to make minor additions to other realms as one would probably notice in the code - I had to add Getters (pointers) in the grc721 and grc1155 so storing the token instance itself is avoided, like it is done with GRC20 for grc20reg.gno purposes. I also needed to add Iterate and IterateN functions to grc20 only to be able to get the tokens of that registry which shouldn't undermine any of it's functionality or security.

Dillema

Since the hub uses existing grc20reg and extends it's usage, if a token is registered through the hub it would mean an incorrect realm path would be written in the grc20reg since the prevrealm would now point to the hub. I have not thought of an ideal solution to this. Here are some ideas I got:

  • Transfering the whole realm to the /r/demo/grc20reg package, if I got the author's permission (@moul)
  • Alternatively, I could add a "RegisterWithTokenHub(token, path)" in grc20reg and check if PrevRealm() is TokenHub. This way tokenhub can pass his PrevRealm.Pkgpath(). This is solution currently implemented

(because of this probelm this is not yet ready to be merged but I would like an opinion)

See screenshots

image
image
image

All feedback is welcome

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jan 10, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 10, 2025

🛠 PR Checks Summary

🔴 Pending initial approval by a review team member, or review from tech-staff

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: matijamarjanovic/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🔴 Requirement not satisfied
└── 🔴 If
    ├── 🔴 Condition
    │   └── 🔴 Or
    │       ├── 🔴 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🔴 Else
        └── 🔴 And
            ├── 🟢 This label is applied to pull request: review/triage-pending
            └── 🔴 On no pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@leohhhn
Copy link
Contributor

leohhhn commented Jan 10, 2025

Check this out, it's a similar idea: https://github.com/gnolang/gno/blob/master/examples/gno.land/r/demo/grc20reg/grc20reg.gno

@matijamarjanovic
Copy link
Contributor Author

Check this out, it's a similar idea

Thanks for pointing out, I will consider implementation for different token types

-change tokenhub to be a hub for nfts rather than a hub for fungible tokens
@matijamarjanovic matijamarjanovic changed the title feat : token hub feat: token hub Jan 10, 2025
@matijamarjanovic
Copy link
Contributor Author

matijamarjanovic commented Jan 21, 2025

Good start but there's more to be worked on. Check out the comments I left below.

All comments have been addressed and changes made. I have also made tests for new funcs. Can you please check out the "Dillema" section of the PR description and maybe provide an opinion 🙏 Thanks!!

@Kouteki Kouteki removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 22, 2025
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 22, 2025
@Gno2D2 Gno2D2 requested a review from a team January 23, 2025 17:15
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages. review/triage-pending PRs opened by external contributors that are waiting for the 1st review
Projects
Status: In Review
Status: Triage
Development

Successfully merging this pull request may close these issues.

4 participants