Skip to content

Create ENS Referral Program leaderboard API as (temporary new) Hono app backend to be consumed by ENSAwards frontend #1185

@djstrong

Description

@djstrong

Background

  • We are launching ENS Holiday Awards as an ENS Referral Incentive Program starting Dec 1. Details are here: https://discuss.ens.domains/t/rfc-ens-holiday-awards/21359
  • The ENSAwards site is planned to serve as the main landing page for the ENS Holiday Awards program. Expected functionality on the ENSAwards site includes the creation of a Leaderboard, showing which referrers are currently the top referrers.
  • @lightwalker-eth and @tk-o Are working on a refined data model for ENS registrations and referrals. Once this work is complete the exact SQL query and response data model will need to also be refined, but it's important not to be blocked on this. We should proceed now with a demonstration of the overall proof of concept here using the existing registrations and referrals data model.
  • @shrugs Is working to build a new app called ENSApi. Eventually we may want to transition the API discussed in this GitHub issue into ENSApi, but it's also important for the goals in this GitHub issue not to be blocked by the work on ENSApi. Therefore, the work on this issue requires the creation of an all new Hono app dedicated exclusively for this 1 new API that is needed at the moment.
  • The database query to calculate the leaderboard of top referrers is expected to be large and slow to execute dynamically for each visitor to the ENSAwards leaderboards. Therefore, here we propose the creation of ENSAnalytics which will implement a caching strategy as described below.

Subtasks

  • Create a new Hono app under a new GitHub repo for "ENSAnalytics". We can later explore adding this new Hono app to the ENSNode monorepo, but this is not suggested for initial steps.
  • Implement a REST API into ENSAnalytics to query the "top referrers".
    • Implement an in-memory caching strategy into the ENSAnalytics app such that when it starts up it stores the "top referrers" in memory and then asynchronously works to refresh the "top referrers" every 5 minutes.
    • The API to get the "top referrers" must only ever return the "top referrers" that ENSAnalytics has already stored into memory. No API request to get the "top referrers" may ever be allowed to trigger a database query. If ENSAnalytics receives an API request to get the "top referrers" and this data hasn't been successfully stored in memory yet, ENSAnalytics should return a HTTP 500 error.
    • ENSAnalytics need an environment variable to configure both the ENSDb URL (Postgres connection string) and the ENSDb schema name (Postgres schema name) to read data from.
    • The full list of all referrers (accounts with 1 or more referrals) must be calculated with each database query and stored in memory.
    • The API should only return a subset of the cached referrer list. More specifically, pagination must be implemented, such that only 25 referrers are returned per requested page. All referrers will always be returned in the order of top referrer to lowest referrer.
  • ENSAwards (code found at https://github.com/namehash/ensawards) needs to be updated such that it has an additional environment variable for the hostname of the ENSAnalytics server it should query for the "top referrers" endpoint.
  • Initially, a "secret" (not publicly discoverable, but that technically exists if we navigate directly to it) page should be added to ENSAwards demonstrating use of the "top referrers" endpoint.

It should get data from a database with query similar to the following, but NOTE that the query below is quick pseudocode and the real query will need to be different.

SELECT
    referrer_address,
    COUNT(*) AS total_referrals
FROM
    referrals
WHERE
    referral_time >= '2025-12-01 00:00:00+00'
    AND referral_time <  '2026-01-01 00:00:00+00'
GROUP BY
    referrer_address
ORDER BY
    total_referrals DESC;

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions