Skip to content

Commit

Permalink
🐛 Handle stats for every affiliation campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jan 17, 2025
1 parent d268a77 commit 113f90a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 4 additions & 7 deletions packages/ponder/src/campaign/campaignCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
interactionCampaignAbi,
referralCampaignAbi,
} from "../../abis/campaignAbis";
import { emptyCampaignStats } from "../interactions/stats";
import {
affiliationCampaignTypes,
emptyCampaignStats,
} from "../interactions/stats";
import { bytesToString } from "../utils/format";

/**
Expand All @@ -20,12 +23,6 @@ ponder.on("CampaignsFactory:CampaignCreated", async ({ event, context }) => {
});
});

const affiliationCampaignTypes = [
"frak.campaign.affiliation-fixed",
"frak.campaign.affiliation-range",
"frak.campaign.referral",
];

/**
* Upsert a fresh campaign in the db
* @param address
Expand Down
13 changes: 11 additions & 2 deletions packages/ponder/src/interactions/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
campaignTable,
productInteractionContractTable,
} from "ponder:schema";
import { and, desc, eq } from "ponder";
import { and, desc, eq, inArray } from "ponder";
import type { Address } from "viem";
import { interactionCampaignAbi } from "../../abis/campaignAbis";

Expand All @@ -25,6 +25,15 @@ export const emptyCampaignStats = {
rewardCount: 0n,
};

/**
* All the type of campaigns that are affiliation related
*/
export const affiliationCampaignTypes = [
"frak.campaign.affiliation-fixed",
"frak.campaign.affiliation-range",
"frak.campaign.referral",
];

export type StatsIncrementsParams = Partial<
Omit<typeof affiliationCampaignStatsTable.$inferSelect, "campaignId">
>;
Expand Down Expand Up @@ -106,7 +115,7 @@ async function increaseCampaignsStats({
.where(
and(
eq(campaignTable.productId, interactionContract.productId),
eq(campaignTable.type, "frak.campaign.referral"),
inArray(campaignTable.type, affiliationCampaignTypes),
eq(campaignTable.attached, true)
)
);
Expand Down

0 comments on commit 113f90a

Please sign in to comment.