Skip to content

Commit

Permalink
fix: cover amounts were grouped on incorrect level before
Browse files Browse the repository at this point in the history
  • Loading branch information
tomfutago committed Dec 11, 2024
1 parent 3a1f89c commit b073cd6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 25 deletions.
123 changes: 98 additions & 25 deletions monitor/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,38 @@ queries:
---

```plan_list
with agg_wallet_positions as (
with
wallet_cover as (
select
plan_id,
plan,
count(distinct cover_id) as cnt_cover,
count(distinct monitored_wallet) as cnt_wallet,
sum(usd_cover_amount) as usd_cover,
sum(eth_cover_amount) as eth_cover,
sum(amount_usd) as usd_exposed,
sum(amount_eth) as eth_exposed
from ${wallet_positions}
sum(eth_cover_amount) as eth_cover
from (
select distinct
plan_id, plan, cover_id, usd_cover_amount, eth_cover_amount
from wallets.cover_wallets
) cw
group by 1, 2
),
agg_wallet_positions as (
select
c.plan_id,
c.plan,
c.cnt_cover,
count(distinct w.monitored_wallet) as cnt_wallet,
c.usd_cover,
c.eth_cover,
sum(w.amount_usd) as usd_exposed,
sum(w.amount_eth) as eth_exposed
from wallet_cover c
inner join ${wallet_positions} w on c.plan_id = w.plan_id
group by 1, 2, 3, 5, 6
)
select
plan,
cnt_cover,
Expand All @@ -31,15 +50,31 @@ order by plan_id
```

```plan_stack
with agg_wallet_positions as (
with
wallet_cover as (
select
plan_id,
plan,
'Covered Amount' as total_type,
sum(usd_cover_amount) as usd_total,
sum(eth_cover_amount) as eth_total
from ${wallet_positions}
count(distinct cover_id) as cnt_cover,
sum(usd_cover_amount) as usd_cover,
sum(eth_cover_amount) as eth_cover
from (
select distinct
plan_id, plan, cover_id, usd_cover_amount, eth_cover_amount
from wallets.cover_wallets
) cw
group by 1, 2
),
agg_wallet_positions as (
select
plan_id,
plan,
'Covered Amount' as total_type,
usd_cover as usd_total,
eth_cover as eth_total
from wallet_cover
union all
select
plan_id,
Expand All @@ -50,6 +85,7 @@ with agg_wallet_positions as (
from ${wallet_positions}
group by 1, 2
)
select
plan,
total_type,
Expand All @@ -60,20 +96,39 @@ order by plan_id
```

```plan_protocol_list
with agg_wallet_positions as (
with
wallet_cover as (
select
plan_id,
plan,
protocol,
count(distinct cover_id) as cnt_cover,
count(distinct monitored_wallet) as cnt_wallet,
sum(usd_cover_amount) as usd_cover,
sum(eth_cover_amount) as eth_cover,
sum(amount_usd) as usd_exposed,
sum(amount_eth) as eth_exposed
from ${wallet_positions}
group by 1, 2, 3
sum(eth_cover_amount) as eth_cover
from (
select distinct
plan_id, plan, cover_id, usd_cover_amount, eth_cover_amount
from wallets.cover_wallets
) cw
group by 1, 2
),
agg_wallet_positions as (
select
c.plan_id,
c.plan,
w.protocol,
c.cnt_cover,
count(distinct w.monitored_wallet) as cnt_wallet,
c.usd_cover,
c.eth_cover,
sum(w.amount_usd) as usd_exposed,
sum(w.amount_eth) as eth_exposed
from wallet_cover c
inner join ${wallet_positions} w on c.plan_id = w.plan_id
group by 1, 2, 3, 4, 6, 7
)
select
plan,
protocol,
Expand Down Expand Up @@ -168,15 +223,32 @@ order by plan_id, protocol
</ButtonGroup>

```protocol_stack
with agg_wallet_positions as (
with
wallet_cover as (
select
plan_id,
plan,
protocol,
'Covered Amount' as total_type,
sum(usd_cover_amount) as usd_total,
sum(eth_cover_amount) as eth_total
from ${wallet_positions}
count(distinct cover_id) as cnt_cover,
sum(usd_cover_amount) as usd_cover,
sum(eth_cover_amount) as eth_cover
from (
select distinct
plan_id, plan, cover_id, usd_cover_amount, eth_cover_amount
from wallets.cover_wallets
) cw
group by 1, 2
),
agg_wallet_positions as (
select
c.plan,
w.protocol,
'Covered Amount' as total_type,
usd_cover as usd_total,
eth_cover as eth_total
from wallet_cover c
inner join ${wallet_positions} w on c.plan_id = w.plan_id
union all
select
plan,
Expand All @@ -187,6 +259,7 @@ with agg_wallet_positions as (
from ${wallet_positions}
group by 1, 2
)
select
protocol,
total_type,
Expand Down
5 changes: 5 additions & 0 deletions monitor/sources/wallets/cover_wallets.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
select
cover_id,
case plan
when 'Entry Cover' then 1
when 'Essential Cover' then 2
when 'Elite Cover' then 3
end plan_id,
plan,
cover_start_date,
cover_end_date,
Expand Down

0 comments on commit b073cd6

Please sign in to comment.