PaimaStudios / paima-engine

Novel trustless web3/blockchain gaming engine.
MIT License
53 stars 17 forks source link

Integrate name lookup system into Paima Engine #281

Open SebastienGllmt opened 8 months ago

SebastienGllmt commented 8 months ago

Goal

For most games, we want a human-readable name for players

Current state

Currently, Paima uses walletToName for this in the middleware, but there are a lot of more proper naming services out there

Ideally, in Paima, we would support all of them in a single aggregate library so that game developers don't have to bother learning how to integrate every single library

However, at the same time, every integration has a cost because

  1. We need to lookup the name somehow (either tracking stuff onchain or having some query to make to an RPC or server)
  2. We have to include additional packages in the paima-sdk bloating package size

Requirements

  1. We need to have sensible defaults
  2. Additional service should not degrade package size or performance (the time it takes to look up a name) if they are not included
  3. We need some way for people to easily extend defaults if they want to opt-in for more services

Challenges

I haven't been able to find anybody who has built this kind of aggregation service. Some of these namespaces support ENS + their service (to make it easy to integrate for platforms that use ENS already), but nobody has a plugin system where you can integrate many of them at once

One option that seems promising is RSS3 as they have many name services supported: https://docs.rss3.io/docs/name-service-resolution

Frontend or backend?

There are two ways to implement this:

  1. Have a package people integrate into their frontend. This is the easiest for game developers because it means any network request to lookup names is done on the user's client. However, this may run into issues due to package size complexity or performance
  2. Implement it in the Paima node API. This would be similar to how we want to implement the achievement system for Paima where the Paima node has a general concept of an achievement format with an agreed-upon API, and each game developer them specifies which platform they want to enable. This solution enables things like caching name lookups to increase performance and only bloats the Paima node size (which is not as big of a deal) while keeping the frontend slim
arthur812812 commented 2 months ago

I have created a simple prototype that meets the requirements. https://github.com/arthur812812/multichain-domain-resolver

Here are the details:

  1. Service Integration

    • The prototype uses RSS3 for querying EVM chains and Blockfrost indexer for Cardano.
    • Note that the Blockfrost API key is stored within the library, making it impractical to use on the client side.
  2. Dynamic Imports and Fetch Requests

    • RSS3 service employs dynamic imports, which will only be executed if called.
    • For Cardano, the prototype uses fetch requests without any additional imports.
  3. Service Addition

    • The built-in addServices function merges service objects and returns a new one in a functional manner, ensuring no mutation of defaultServices.
    • This allows overriding defaults and adding new services seamlessly.