-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from cowprotocol/payment_status
Add query for payment status
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |