Skip to content

Commit

Permalink
Merge pull request #6 from cowprotocol/payment_status
Browse files Browse the repository at this point in the history
Add query for payment status
  • Loading branch information
fleupold committed Aug 28, 2024
2 parents 822caf7 + 043cc8d commit 2adad87
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mevblocker/fees/payment_status_4016152.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
with
latest_bill_date as (
select max(call_block_time) as bill_date
from mev_blocker_ethereum.MevBlockerFeeTill_call_bill
where call_success = true
),

lastest_billing as (
select
usr,
evt_block_time as bill_time,
amt as bill_amount
from mev_blocker_ethereum.MevBlockerFeeTill_evt_Billed
where evt_block_time = (select bill_date from latest_bill_date)
),

latest_payments as (
select
usr,
evt_block_time as paid_time,
amt as paid_amount
from mev_blocker_ethereum.MevBlockerFeeTill_evt_Paid
where evt_block_time > (select bill_date from latest_bill_date)
),

payment_status as (
select
lb.usr,
bill_amount,
bill_time,
paid_time,
coalesce(paid_amount, 0) as paid_amount
from lastest_billing as lb
left outer join latest_payments as lp
on lb.usr = lp.usr
)

select
*,
(case
when paid_amount = bill_amount then 'PAID'
when paid_amount < bill_amount then 'UNPAID'
else 'OVERPAID'
end) as status
from payment_status

0 comments on commit 2adad87

Please sign in to comment.