greyswanDefault rate copy
    -- forked from e1d42c94-0200-4ff7-bb07-ec8e769bca5c

    with events as (
    select * from solana.core.fact_events
    where program_id = 'A66HabVL3DzNzeJgcHYtRRNW1ZRMKwBfrdSR4kLsZ9DJ'
    and succeeded = 'True'
    and block_id > {{DEPLOY_BLOCK}}
    ),

    stopLiquidations as (
    SELECT
    instructions[0].accounts[0] as loan,
    -- 'stop' as liq_type,
    date_trunc('month', block_timestamp) as block_timestamp
    from solana.core.fact_transactions as txs
    where txs.block_id > {{DEPLOY_BLOCK}}
    and txs.tx_id in (SELECT tx_id from events)
    and txs.log_messages[1] = 'Program log: Instruction: StopLiquidationRafflesByAdmin'
    ),
    redeems as (
    SELECT
    instructions[0].accounts[1] as loan,
    -- 'redeem' as liq_type,
    date_trunc('month', block_timestamp) as block_timestamp
    from solana.core.fact_transactions as txs
    where txs.block_id > {{DEPLOY_BLOCK}}
    and txs.tx_id in (SELECT tx_id from events)
    and txs.log_messages[1] = 'Program log: Instruction: RedeemWinningLotTicket'
    ),

    liquidations as (
    select
    DISTINCT loan as loan, block_timestamp
    from (
    SELECT * from stopLiquidations
    Run a query to Download Data