@merkl/api 0.10.410 → 0.10.412

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.
@@ -5,10 +5,8 @@ import { log } from "../../utils/logger";
5
5
  import { apiDbClient } from "../../utils/prisma";
6
6
  import { S3Client } from "bun";
7
7
  import moment from "moment";
8
- // ─── Constants ───────────────────────────────────────────────
9
- const BATCH_SIZE = 5_000;
10
8
  // ─── Global Variables ────────────────────────────────────────
11
- const [chainIdString, root, campaignId] = process.env.FILENAME.split("_");
9
+ const [chainIdString, root, campaignId] = process.env.FILENAME.replace(".gz", "").split("_");
12
10
  const chainId = Number.parseInt(chainIdString);
13
11
  const gcsClient = new S3Client({
14
12
  accessKeyId: process.env.GCS_ACCESS_ID,
@@ -33,16 +31,14 @@ const extract = async () => {
33
31
  buffer = lines.pop() || "";
34
32
  for (const line of lines) {
35
33
  data.push(JSON.parse(line));
36
- if (data.length >= BATCH_SIZE) {
37
- try {
38
- count += await load(data);
39
- }
40
- catch (err) {
41
- console.error(`Failed to insert a batch, adding it to the fail queue.\n${err}`);
42
- failedBatches.push(data);
43
- data.length = 0;
44
- }
45
- }
34
+ }
35
+ try {
36
+ count += await load(data);
37
+ }
38
+ catch (err) {
39
+ console.error(`Failed to insert a batch, adding it to the fail queue.\n${err}`);
40
+ failedBatches.push(data);
41
+ data.length = 0;
46
42
  }
47
43
  }
48
44
  return count;
@@ -135,21 +131,21 @@ const updatePendings = async (data) => {
135
131
  }));
136
132
  let users = toCreate.map(x => x.recipient);
137
133
  await apiDbClient.user.createMany({ data: users.map(x => ({ address: x, tags: [] })), skipDuplicates: true });
138
- await apiDbClient.$transaction(toCreate.map(x => {
139
- const rewardId = Bun.hash(`${root}${x.recipient}${rewardTokenId}`).toString();
140
- return apiDbClient.reward.create({
141
- data: {
134
+ await apiDbClient.reward.createMany({
135
+ data: toCreate.map(x => {
136
+ const rewardId = Bun.hash(`${root}${x.recipient}${rewardTokenId}`).toString();
137
+ return {
142
138
  id: rewardId,
143
- MerklRoot: { connect: { root } },
144
- User: { connect: { address: x.recipient } },
145
- RewardToken: { connect: { id: rewardTokenId } },
139
+ root,
140
+ recipient: x.recipient,
141
+ rewardTokenId,
146
142
  proofs: [],
147
143
  amount: "0",
148
144
  pending: x.pending,
149
145
  claimed: "0",
150
- },
151
- });
152
- }));
146
+ };
147
+ }),
148
+ });
153
149
  await apiDbClient.$transaction(breakdownToUpdate.map(x => {
154
150
  return apiDbClient.rewardBreakdown.update({
155
151
  where: {
@@ -166,23 +162,19 @@ const updatePendings = async (data) => {
166
162
  }));
167
163
  users = toCreate.map(x => x.recipient);
168
164
  await apiDbClient.user.createMany({ data: users.map(x => ({ address: x, tags: [] })), skipDuplicates: true });
169
- await apiDbClient.$transaction(breakdownToCreate.map(x => {
170
- const rewardId = Bun.hash(`${root}${x.recipient}${rewardTokenId}`).toString();
171
- return apiDbClient.rewardBreakdown.create({
172
- data: {
165
+ await apiDbClient.rewardBreakdown.createMany({
166
+ data: breakdownToCreate.map(x => {
167
+ const rewardId = Bun.hash(`${root}${x.recipient}${rewardTokenId}`).toString();
168
+ return {
173
169
  reason: x.reason,
174
170
  amount: "0",
175
171
  pending: x.pending,
176
172
  claimed: "0",
177
- Reward: {
178
- connect: {
179
- id: rewardId,
180
- },
181
- },
182
- Campaign: { connect: { id: campaignId } },
183
- },
184
- });
185
- }));
173
+ rewardId,
174
+ campaignId,
175
+ };
176
+ }),
177
+ });
186
178
  return { created: breakdownToCreate.length, updated: breakdownToUpdate.length };
187
179
  };
188
180
  // ─────────────────────────────────────────────────────────────────────────────
@@ -197,7 +189,7 @@ export const main = async () => {
197
189
  }
198
190
  if (failedBatches.length === 0) {
199
191
  // await file.delete();
200
- log.info("Object deleted");
192
+ // log.info("Object deleted");
201
193
  }
202
194
  };
203
195
  main();