Skip to content

Commit 6990d64

Browse files
authored
[Hotfix] Fix computation period of the fee for billing (#34)
1 parent 3d035a1 commit 6990d64

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/dune.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ export class QueryRunner {
111111
async getBillingData(date: Date): Promise<BillingData> {
112112
try {
113113
const billingDate = moment(date).format("YYYY-MM-DD 00:00:00");
114+
// The fee for the current period is the per block fee of the starting date (computed over the previous month)
115+
const billingFeeComputationStart = moment(date)
116+
.subtract(7, "day")
117+
.subtract(1, "month")
118+
.startOf("month")
119+
.format("YYYY-MM-DD 00:00:00");
120+
const billingFeeComputationEnd = moment(date)
121+
.subtract(7, "day")
122+
.startOf("month")
123+
.format("YYYY-MM-DD 00:00:00");
124+
125+
// The fee for the next period is the fee of the previous month
114126
const feeComputationStart = moment(date)
115127
.subtract(1, "month")
116128
.startOf("month")
@@ -120,7 +132,11 @@ export class QueryRunner {
120132
.format("YYYY-MM-DD 00:00:00");
121133
console.log(`Executing fee and payment queries this may take a while...`);
122134
const [dueAmounts, periodFee] = await Promise.all([
123-
this.getAmountsDue(billingDate, feeComputationStart, feeComputationEnd),
135+
this.getAmountsDue(
136+
billingDate,
137+
billingFeeComputationStart,
138+
billingFeeComputationEnd,
139+
),
124140
this.getPeriodFee(feeComputationStart, feeComputationEnd),
125141
]);
126142
return { dueAmounts, periodFee };

0 commit comments

Comments
 (0)