Query editor
-- The PYUSD received in the 24 hours before each repayment above 1 million, by how it reached the payer.-- Public Dune query: https://dune.com/queries/9186425. Aggregate only.-- Each transfer is counted once: it goes to the first repayment its receiver made in the 24 hours after it.-- A repayment is covered up to its own size, and the covered part is split across the kinds of transfer in-- proportion to their amounts. What is left is "not covered".-- A transfer gets the first kind that fits: minted to the payer, sent in a transaction that bought PYUSD on a-- DEX, sent in a transaction with a borrow on Morpho or Aave v3, from a labelled exchange, from another-- address active in this market, from an unlabelled contract, from an unlabelled wallet.-- Limits: this goes one step back and no further, so the origin of the token paid on the DEX is not traced.-- Kind 3 counts any borrow in the transaction, this market included, and does not check the borrowed asset.-- The payer is the transaction sender and the position owner. A share is a share of money received, not-- proof that those coins were the ones repaid. Exchange labels (Dune cex.addresses) are incomplete.-- Cutoff: only events before 2026-11-24 00:00:00 UTC are read, so a rerun gives the saved result.WITH rep AS (SELECT evt_tx_hash AS tx, min(evt_block_time) AS t, min(evt_tx_from) AS sender, min(onBehalf) AS owner,sum(CAST(assets AS double)) / 1e6 AS pyusdFROM morpho_blue_ethereum.morphoblue_evt_repayWHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND id = 0x90ef0c5a0dc7c4de4ad4585002d44e9d411d212d2f6258e94948beecf8b4c0d5GROUP BY 1),big AS (SELECT * FROM rep WHERE pyusd > 1e6),payers AS (SELECT tx, t, sender AS a FROM big UNION SELECT tx, t, owner FROM big),payer_set AS (SELECT DISTINCT a FROM payers),market_addr AS (SELECT DISTINCT onBehalf AS a FROM morpho_blue_ethereum.morphoblue_evt_borrowWHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND id = 0x90ef0c5a0dc7c4de4ad4585002d44e9d411d212d2f6258e94948beecf8b4c0d5UNIONSELECT DISTINCT receiver FROM morpho_blue_ethereum.morphoblue_evt_withdrawcollateralWHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND id = 0x90ef0c5a0dc7c4de4ad4585002d44e9d411d212d2f6258e94948beecf8b4c0d5),tr AS (SELECT evt_tx_hash AS h, evt_index AS ix, evt_block_time AS bt, "from" AS src, "to" AS dst, CAST(value AS double) / 1e6 AS amountFROM erc20_ethereum.evt_transferWHERE contract_address = 0x6c3ea9036406852006290770BEdFcAbA0e23A0e8 AND evt_block_date >= DATE '2025-11-30' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00'AND "to" IN (SELECT a FROM payer_set)),-- transactions that bought PYUSD on a DEX, with the token paidbuys AS (SELECT tx_hash AS h, max_by(token_sold_symbol, amount_usd) AS sold_symbolFROM dex.tradesWHERE blockchain = 'ethereum' AND block_date >= DATE '2025-11-30' AND block_time < TIMESTAMP '2026-11-24 00:00:00'AND token_bought_address = 0x6c3ea9036406852006290770BEdFcAbA0e23A0e8GROUP BY 1),-- transactions with any borrow on Morpho (any market, this one included) or on Aave v3 (any asset)loans AS (SELECT evt_tx_hash AS h FROM morpho_blue_ethereum.morphoblue_evt_borrow WHERE evt_block_date >= DATE '2025-11-30' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00'UNION SELECT evt_tx_hash FROM aave_v3_ethereum.pool_evt_borrow WHERE evt_block_date >= DATE '2025-11-30' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00'),contracts AS (SELECT DISTINCT address FROM ethereum.creation_traces WHERE block_time < TIMESTAMP '2026-11-24 00:00:00' AND address IN (SELECT DISTINCT src FROM tr)),-- each transfer goes to one repayment only: the first one by that payer in the 24 hours after itcand AS (SELECT tr.h, tr.ix, tr.src, tr.amount, p.tx,row_number() OVER (PARTITION BY tr.h, tr.ix ORDER BY p.t, p.tx) AS rnFROM tr JOIN payers p ON tr.dst = p.a AND tr.bt < p.t AND tr.bt >= p.t - INTERVAL '24' hourWHERE tr.src NOT IN (SELECT a FROM payers p2 WHERE p2.tx = p.tx)),inflow AS (SELECT x.tx,CASE WHEN x.src = 0x0000000000000000000000000000000000000000 THEN '1 newly issued PYUSD (mint to the payer)'