h4wkMarginFI KPI Action 3
Updated 2023-10-24
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
-- forked from MarginFI KPI Action @ https://flipsidecrypto.xyz/edit/queries/b01aae43-6363-494d-b378-faea468b72d7
-- Program log: Instruction: LendingAccountDeposit -- LEND
-- Program log: Instruction: LendingAccountBorrow -- BORROW
-- Program log: Instruction: LendingAccountRepay -- REPAY
-- Program log: Instruction: LendingAccountWithdraw -- WITHDRAW
with base as(
select block_timestamp::date as date,
case when logs.value = 'Program log: Instruction: LendingAccountDeposit' then 'LEND'
when logs.value = 'Program log: Instruction: LendingAccountBorrow' then 'BORROW'
when logs.value = 'Program log: Instruction: LendingAccountRepay' then 'REPAY'
when logs.value = 'Program log: Instruction: LendingAccountWithdraw' then 'WITHDRAW'
end as type,
tx.tx_id,
tx.signers[0] as user,
upper(symbol) as token
from solana.core.fact_transactions tx
join lateral flatten (input => log_messages) logs
join (select distinct block_timestamp, tx_id
from solana.core.fact_events where succeeded = True
and program_id = 'MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA') events
using(tx_id, block_timestamp)
join solana.core.fact_transfers transfer using(tx_id, block_timestamp)
join solana.core.dim_tokens on mint = token_address
where block_timestamp::date >= '2023-08-01' and block_timestamp::date < CURRENT_DATE
and logs.value in (
'Program log: Instruction: LendingAccountDeposit', -- LEND
'Program log: Instruction: LendingAccountBorrow', -- BORROW
'Program log: Instruction: LendingAccountRepay', -- REPAY
'Program log: Instruction: LendingAccountWithdraw' -- WITHDRAW
)
)
select
-- date,
type,
Run a query to Download Data