Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query for payment status #6

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading