duneanalytics / duneanalytics/spellbook

lending.* on Base: moonwell misses newer mToken markets (~7x borrow undercount); compound v3 missing the cAEROv3 comet

Open
#9,980 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
1.4k
Avg merge
3d 16h
Merged PRs (30d)
22

Description

While reconciling decoded event tables against the curated lending.* sector on Base, two coverage gaps showed up. Both look like the same root cause: the market lists appear to come from static seeds (the in-schema ctokens views list only 7 moonwell markets and 3 comets) rather than from onchain listing/deploy events.

1. Moonwell: newer mToken markets are missing. The comptroller (0xfBb21d0380beE3312B33c4353c8936a0F13EF26C) has listed 21 markets (moonwell_base.comptroller_evt_marketlisted), but lending.borrow only carries rows for roughly the original set. Over the last 30 days that's a ~7× undercount on borrows (decoded 17,356 vs curated 2,421) and ~5× on repays; supplies/withdraws are ~8–10% low because most volume is still in older markets, but most borrowing now happens in markets decoded under merc20delegate_*/merc20delegator_* (AERO, cbBTC, and other newer listings).

2. Compound v3: the cAEROv3 comet (0x784efeB622244d2348d4F2522f8860B96fbEcE89, deployed 2025-02-20 via configurator_evt_cometdeployed) is absent — it has 49k+ decoded supply events but zero rows in lending.supply/lending.borrow (and is also missing from compound_v3_base.ctokens). 30d decoded supply events across all 4 comets: 16,045 vs 12,407 curated rows.

Counts are from 2026-08-31 runs; the queries below are self-contained and reproduce with current data.

Proving query (event counts, last 30d):

WITH decoded AS (
    SELECT 'moonwell' AS project, 'borrow' AS verb, COUNT(*) AS n
    FROM (
        SELECT evt_block_date FROM moonwell_base.maero_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mamo_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mcbbtc_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mcbeth_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mdai_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mreth_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.musdc_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.musdcnative_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mweth_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.mwsteth_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.merc20delegate_evt_borrow
        UNION ALL SELECT evt_block_date FROM moonwell_base.merc20delegator_evt_borrow
    ) WHERE evt_block_date >= current_date - INTERVAL '30' DAY
    UNION ALL
    SELECT 'compound', 'supply', COUNT(*)
    FROM (
        SELECT evt_block_date FROM compound_v3_base.cusdcv3_evt_supply
        UNION ALL SELECT evt_block_date FROM compound_v3_base.cusdbcv3comet_evt_supply
        UNION ALL SELECT evt_block_date FROM compound_v3_base.cwethv3_evt_supply
        UNION ALL SELECT evt_block_date FROM compound_v3_base.caerov3_evt_supply
    ) WHERE evt_block_date >= current_date - INTERVAL '30' DAY
),
curated AS (
    SELECT 'moonwell' AS project, 'borrow' AS verb, COUNT(*) AS n
    FROM lending.borrow
    WHERE blockchain = 'base' AND project = 'moonwell' AND transaction_type = 'borrow'
      AND block_month >= DATE_TRUNC('month', current_date - INTERVAL '30' DAY)
      AND block_time >= CAST(current_date - INTERVAL '30' DAY AS TIMESTAMP)
    UNION ALL
    SELECT 'compound', 'supply', COUNT(*)
    FROM lending.supply
    WHERE blockchain = 'base' AND project = 'compound' AND version = '3'
      AND transaction_type = 'supply'
      AND block_month >= DATE_TRUNC('month', current_date - INTERVAL '30' DAY)
      AND block_time >= CAST(current_date - INTERVAL '30' DAY AS TIMESTAMP)
)
SELECT d.project, d.verb, d.n AS decoded_events, c.n AS curated_rows
FROM decoded d
LEFT JOIN curated c ON c.project = d.project AND c.verb = d.verb

Market-coverage drill (which listed moonwell markets lending.* knows about):

SELECT CAST(m.mtoken AS VARCHAR) AS mtoken,
       CASE WHEN l.addr IS NULL THEN 'MISSING from lending.borrow' ELSE 'covered' END AS status
FROM (SELECT DISTINCT mtoken FROM moonwell_base.comptroller_evt_marketlisted) m
LEFT JOIN (
    SELECT DISTINCT project_contract_address AS addr FROM lending.borrow
    WHERE blockchain = 'base' AND project = 'moonwell'
      AND block_month >= DATE_TRUNC('month', current_date - INTERVAL '90' DAY)
) l ON l.addr = m.mtoken
ORDER BY status, mtoken

And the AERO comet specifically: SELECT COUNT(*) FROM lending.supply WHERE blockchain='base' AND project='compound' AND project_contract_address = 0x784efeB622244d2348d4F2522f8860B96fbEcE89 returns 0 against 49k+ decoded events.

Suggested fix: derive the moonwell market list from comptroller_evt_marketlisted and the comet list from configurator_evt_cometdeployed (distinct cometProxy) instead of static seeds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the lending.borrow and lending.supply models, then run the proving and market-coverage queries in the issue. Compare their inputs with moonwell_base.comptroller_evt_marketlisted and compound_v3_base.configurator_evt_cometdeployed, including the listed mToken addresses and distinct cometProxy values. Done means newer Moonwell markets and the cAEROv3 comet produce the expected curated rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
data-engineering, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.