rw2023Loan KPIs monthly
    Updated 2025-05-25
    WITH repay_events AS (
    SELECT
    DATE_TRUNC('month', block_timestamp) AS month,
    inner_instruction:instructions[0]:parsed:info:lamports / 1e9 AS sol_repaid, -- Monto total repagado en SOL
    inner_instruction:instructions[1]:parsed:info:destination AS platform_fee_address, -- Dirección de la plataforma
    inner_instruction:instructions[1]:parsed:info:lamports / 1e9 AS platform_fee_amount, -- Monto a la plataforma en SOL
    inner_instruction:instructions[2]:parsed:info:destination AS community_fee_address, -- Dirección de la comunidad
    inner_instruction:instructions[2]:parsed:info:lamports / 1e9 AS community_fee_amount -- Monto a la comunidad en SOL
    FROM
    solana.core.fact_events
    WHERE
    program_id LIKE 'SHARK%'
    AND succeeded = TRUE
    AND block_timestamp >= CURRENT_DATE - INTERVAL '2 YEAR'
    AND inner_instruction:instructions[0]:parsed:type = 'transfer'
    AND inner_instruction:instructions[1]:parsed:type = 'transfer'
    AND inner_instruction:instructions[2]:parsed:type = 'transfer'
    ),
    repaid_loans_agg AS (
    SELECT
    month,
    SUM(sol_repaid) AS total_sol_repaid,
    COUNT(*) AS num_loans_repaid,
    CASE
    WHEN COUNT(*) > 0 THEN SUM(sol_repaid) / COUNT(*)
    ELSE 0
    END AS avg_sol_per_loan,
    SUM(platform_fee_amount) AS total_platform_fees,
    SUM(community_fee_amount) AS total_community_fees
    FROM
    repay_events
    GROUP BY
    month
    ),
    financial_metrics_with_variation AS (
    SELECT
    Last run: 2 months ago
    MONTH
    TOTAL_SOL_REPAID
    NUM_LOANS_REPAID
    AVG_SOL_PER_LOAN
    TOTAL_PLATFORM_FEES
    TOTAL_COMMUNITY_FEES
    PCT_DIFF_TOTAL_SOL_REPAID
    PCT_DIFF_NUM_LOANS_REPAID
    PCT_DIFF_AVG_SOL_PER_LOAN
    PCT_DIFF_TOTAL_PLATFORM_FEES
    PCT_DIFF_TOTAL_COMMUNITY_FEES
    1
    2025-05-01 00:00:00.0005520.63560514430071.83592803620.5998011246.866598724-42.883119117-33.4145-14.220208158-28.063805554-28.063806036
    2
    2025-04-01 00:00:00.0009665.5060986745162.14028035828.6362119699.545401759-28.347641758-3.5043-25.745563204-23.256628878-23.256632987
    3
    2025-03-01 00:00:00.00013489.44589656946802.88236023437.31424818912.43808048915.6164324029.62755.46293801812.00311600312.00311628
    4
    2025-02-01 00:00:00.00011667.41233601242692.73305512733.31536614411.10512002-32.118281066-22.1554-12.798466472-33.372378969-33.372380692
    5
    2025-01-01 00:00:00.00017187.85634672854843.13418241250.0023348116.667442324-3.428912862-18.489918.477438779-7.084274776-7.08427336
    6
    2024-12-01 00:00:00.00017798.13902500567282.64538332753.8147172517.93823599873.85485232126.205237.75568039974.87288003674.872892605
    7
    2024-11-01 00:00:00.00010237.355349853311.92034427930.77362095210.257871149-13.8727578953.7967-17.023163487-13.290036536-13.290040131
    8
    2024-10-01 00:00:00.00011886.31506086351362.3143136835.4902939911.830095602-8.611774738-8.70960.10711747-8.660197359-8.660197693
    9
    2024-09-01 00:00:00.00013006.39664107656262.31183729838.85523393312.95174207-17.097950061-30.085718.576750064-17.528684128-17.528681836
    10
    2024-08-01 00:00:00.00015688.87216983980471.94965479947.11363402215.7045411166.4469170630.97885.4151214214.8009330164.800936084
    11
    2024-07-01 00:00:00.00014738.68159146179691.84950201944.95535742514.98511530810.4467934710.3410.07258548711.30210573811.302107799
    12
    2024-06-01 00:00:00.00013344.59890435879421.68025672440.39039255113.46346049-23.363792884-27.56955.806599222-25.410305653-25.410305051
    13
    2024-05-01 00:00:00.00017412.916696416109651.58804529854.15009795218.050027553-80.98786446-52.2742-60.16381085-76.544005698-76.544009065
    14
    2024-04-01 00:00:00.00091588.431292882229753.986438794230.85824993976.95273929417.435177673-2.267320.1595715669.5579596069.557961704
    15
    2024-03-01 00:00:00.00077990.626921032235083.317620679210.71791658870.23929443128.09861187123.33683.8607938686.3142149526.314212683
    16
    2024-02-01 00:00:00.00060883.272489868190603.194295514198.20295591166.06764294121.0744232366.563813.61684858420.71901244420.719014642
    17
    2024-01-01 00:00:00.00050285.824918609178862.811462871164.18536889854.728447823-43.757133313-19.0789-30.496696724-42.949658846-42.949661309
    18
    2023-12-01 00:00:00.00089408.360349113221034.045078059287.79033670295.93010151845.1464705530.527644.38471918145.84333998645.843346408
    19
    2023-11-01 00:00:00.00061598.714738564219872.801597068197.32840507465.776124781-25.501946649-12.5835-14.778048943-28.123388063-28.123389855
    20
    2023-10-01 00:00:00.00082684.999093915251523.287412496274.53771088791.512558325-31.890106696-6.9788-26.780239939-31.151706343-31.151708658
    25
    4KB
    12s