Query editor
-- Where the PYUSD in repayments above 1 million came from, in aggregate. Public Dune query: https://dune.com/queries/9186424-- Each repayment transaction above 1M PYUSD gets one class, tested in this order:-- 1 a flash loan in the same transaction (Morpho, Aave v3, Balancer v2)-- 2 a swap into PYUSD in the same transaction, for at least half of the repaid amount-- 3 a borrow on another Morpho market or on Aave v3 in the same transaction-- 4 PYUSD received by the transaction sender or the position owner in the 24 hours before,-- for at least 90% of the repaid amount, named by the largest kind of sender-- 5 none of these: held for more than 24 hours, or not seen-- Limits: one class per transaction, by the largest source. PYUSD received in the 24 hours before two close-- repayments counts for both. The payer is approximated by the transaction sender and the position owner.-- "Unlabelled" is not traced further. Exchange labels come from Dune's cex.addresses and 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),flash AS (SELECT evt_tx_hash AS tx FROM morpho_blue_ethereum.morphoblue_evt_flashloan WHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND evt_tx_hash IN (SELECT tx FROM big)UNIONSELECT evt_tx_hash FROM aave_v3_ethereum.pool_evt_flashloan WHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND evt_tx_hash IN (SELECT tx FROM big)UNIONSELECT evt_tx_hash FROM balancer_v2_ethereum.vault_evt_flashloan WHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND evt_tx_hash IN (SELECT tx FROM big)),swap AS (SELECT tx_hash AS tx, sum(token_bought_amount) AS pyusd_bought, max_by(token_sold_symbol, amount_usd) AS sold_symbolFROM dex.tradesWHERE blockchain = 'ethereum' AND block_date >= DATE '2025-12-01' AND block_time < TIMESTAMP '2026-11-24 00:00:00'AND token_bought_address = 0x6c3ea9036406852006290770BEdFcAbA0e23A0e8 AND tx_hash IN (SELECT tx FROM big)GROUP BY 1),borrow_same_tx AS (SELECT evt_tx_hash AS tx 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 <> 0x90ef0c5a0dc7c4de4ad4585002d44e9d411d212d2f6258e94948beecf8b4c0d5 AND evt_tx_hash IN (SELECT tx FROM big)UNIONSELECT evt_tx_hash FROM aave_v3_ethereum.pool_evt_borrow WHERE evt_block_date >= DATE '2025-12-01' AND evt_block_time < TIMESTAMP '2026-11-24 00:00:00' AND evt_tx_hash IN (SELECT tx FROM big)),tr AS (SELECT 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)),-- PYUSD that reached the payer in the 24 hours before the repayment, by kind of senderinflow AS (SELECT p.tx,sum(CASE WHEN tr.src = 0x0000000000000000000000000000000000000000 THEN tr.amount END) AS from_mint,sum(CASE WHEN c.address IS NOT NULL THEN tr.amount END) AS from_cex,