@merkl/api 0.15.5 → 0.15.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
|
|
1
1
|
// ─── Reward Breakdowns ETL ───────────────────────────────────────────────────
|
2
2
|
if (!process.env.ENV || !process.env.CHAIN_ID || !process.env.ROOT)
|
3
3
|
throw new Error("[ENV]: missing variable");
|
4
|
-
import { CampaignService } from "../../modules/v4";
|
5
4
|
import { log } from "../../utils/logger";
|
6
5
|
import { apiDbClient } from "../../utils/prisma";
|
7
6
|
import { withRetry } from "@sdk";
|
@@ -79,42 +78,44 @@ const transform = async (rewardBreakdowns) => {
|
|
79
78
|
// ─── Load ────────────────────────────────────────────────────────────────────
|
80
79
|
const load = async (rewardBreakdowns) => {
|
81
80
|
log.info(`pushing ${rewardBreakdowns.length} rewardBreakdowns`);
|
82
|
-
const missingCampaigns = [];
|
83
|
-
const foundCampaigns = [];
|
84
|
-
const campaigns = rewardBreakdowns.reduce(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
|
110
|
-
}
|
81
|
+
// const missingCampaigns: string[] = [];
|
82
|
+
// const foundCampaigns: string[] = [];
|
83
|
+
// const campaigns = rewardBreakdowns.reduce(
|
84
|
+
// (acc, x) => {
|
85
|
+
// const campaignUnique = {
|
86
|
+
// campaignId: x.campaignId,
|
87
|
+
// distributionChain: Number.parseInt(process.env.CHAIN_ID!),
|
88
|
+
// };
|
89
|
+
// if (!Object.keys(acc).includes(CampaignService.hashId(campaignUnique)))
|
90
|
+
// acc[CampaignService.hashId(campaignUnique)] = {
|
91
|
+
// campaignId: x.campaignId,
|
92
|
+
// distributionChain: Number.parseInt(process.env.CHAIN_ID!),
|
93
|
+
// };
|
94
|
+
// return acc;
|
95
|
+
// },
|
96
|
+
// {} as Record<string, CampaignUnique>
|
97
|
+
// );
|
98
|
+
// for (const campaign of Object.values(campaigns)) {
|
99
|
+
// const campaignExists = await CampaignService.checkIfExist(campaign);
|
100
|
+
// if (!campaignExists) {
|
101
|
+
// const { success, fail } = await CampaignService.fill([campaign]);
|
102
|
+
// if (fail === 1 || success !== 1) {
|
103
|
+
// missingCampaigns.push(CampaignService.hashId(campaign));
|
104
|
+
// log.warn(`createManyBreakdown - Missing campaign: ${campaign.campaignId}`);
|
105
|
+
// continue;
|
106
|
+
// }
|
107
|
+
// }
|
108
|
+
// foundCampaigns.push(CampaignService.hashId(campaign));
|
109
|
+
// }
|
110
|
+
// if (missingCampaigns.length !== 0) {
|
111
|
+
// log.warn(`createManyBreakdown - Missing ${missingCampaigns.length} campaigns: ${missingCampaigns.join(", ")}`);
|
112
|
+
// }
|
111
113
|
return (await apiDbClient.rewardBreakdown.createMany({
|
112
|
-
data: rewardBreakdowns
|
113
|
-
.map(x => {
|
114
|
+
data: rewardBreakdowns.map(x => {
|
114
115
|
const campaignId = Bun.hash(`${process.env.CHAIN_ID}${x.campaignId}`).toString();
|
115
116
|
return { ...x, campaignId };
|
116
|
-
})
|
117
|
-
|
117
|
+
}),
|
118
|
+
// .filter(x => !missingCampaigns.includes(x.campaignId)),
|
118
119
|
skipDuplicates: true,
|
119
120
|
})).count;
|
120
121
|
};
|