Skip to content

Commit

Permalink
add missing transfers for cDAI deposits and withdraws
Browse files Browse the repository at this point in the history
looks at event logs of the savings dai contract and adds a
- AMM_IN transfers for Withdraw events
- AMM_OUT transfers for Deposit events
  • Loading branch information
fhenneke committed Dec 13, 2023
1 parent b04d99e commit bbecaba
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions queries/dune_v2/period_slippage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ batch_meta as (
-- ETH transfers to traders are already part of USER_OUT
and not contains(traders_out, to)
)
-- sDAI emit only one transfer event for deposits and withdrawls.
-- This reconstructs the missing transfer from event logs.
,sdai_deposit_withdrawl_transfers as (
-- withdraw events result in additional AMM_IN transfer
select
tx_hash,
0x9008d19f58aabd9ed0d60971565aa8510560ab41 as sender,
0x0000000000000000000000000000000000000000 as receiver,
contract_address as token,
cast(shares as int256) as amount_wei,
'AMM_IN' as transfer_type
from batch_meta bm
join maker_ethereum.SavingsDai_evt_Withdraw w
on w.evt_tx_hash= bm.tx_hash
union all
-- for deposit events result in additional AMM_OUT transfer
select
tx_hash,
0x0000000000000000000000000000000000000000 as sender,
0x9008d19f58aabd9ed0d60971565aa8510560ab41 as receiver,
contract_address as token,
cast(shares as int256) as amount_wei,
'AMM_OUT' as transfer_type
from batch_meta bm
join maker_ethereum.SavingsDai_evt_Deposit w
on w.evt_tx_hash= bm.tx_hash
)
,pre_batch_transfers as (
select * from (
select * from user_in
Expand All @@ -134,6 +161,8 @@ batch_meta as (
select * from other_transfers
union all
select * from eth_transfers
union all
select * from sdai_deposit_withdrawl_transfers
) as _
order by tx_hash
)
Expand Down

0 comments on commit bbecaba

Please sign in to comment.