@merkl/api 0.10.296 → 0.10.297

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.
@@ -132,6 +132,18 @@ export declare abstract class RewardRepository {
132
132
  recipient: string;
133
133
  };
134
134
  }[]>;
135
+ static upsertPendings(rewardTokenId: string, root: string, campaignId: string, toUpdate: PendingEntity[]): Promise<{
136
+ reason: string;
137
+ pending: string;
138
+ id: number;
139
+ campaignId: string;
140
+ amount: string;
141
+ protocolId: string | null;
142
+ claimed: string;
143
+ auxiliaryData1: string | null;
144
+ auxiliaryData2: string | null;
145
+ rewardId: string;
146
+ }[]>;
135
147
  static updatePendings(rewardTokenId: string, root: string, campaignId: string, toUpdate: PendingEntity[]): Promise<{
136
148
  reason: string;
137
149
  pending: string;
@@ -158,6 +158,46 @@ export class RewardRepository {
158
158
  },
159
159
  });
160
160
  }
161
+ static async upsertPendings(rewardTokenId, root, campaignId, toUpdate) {
162
+ const users = toUpdate.map(x => x.recipient);
163
+ await UserService.createMany(users.map(x => ({ address: x, tags: [] })));
164
+ return await apiDbClient.$transaction(toUpdate.map(x => {
165
+ const rewardId = RewardService.hashId(root, x.recipient, rewardTokenId);
166
+ return apiDbClient.rewardBreakdown.upsert({
167
+ where: {
168
+ rewardId_campaignId_reason: {
169
+ rewardId: RewardService.hashId(root, x.recipient, rewardTokenId),
170
+ campaignId: campaignId,
171
+ reason: x.reason,
172
+ },
173
+ },
174
+ update: {
175
+ pending: x.pending,
176
+ auxiliaryData1: x.auxiliaryData1,
177
+ auxiliaryData2: x.auxiliaryData2,
178
+ },
179
+ create: {
180
+ reason: x.reason,
181
+ amount: "0",
182
+ pending: x.pending,
183
+ claimed: "0",
184
+ Reward: {
185
+ connectOrCreate: {
186
+ where: { id: rewardId },
187
+ create: {
188
+ id: rewardId,
189
+ MerklRoot: { connect: { root } },
190
+ User: { connect: { address: x.recipient } },
191
+ RewardToken: { connect: { id: rewardTokenId } },
192
+ proofs: [],
193
+ },
194
+ },
195
+ },
196
+ Campaign: { connect: { id: campaignId } },
197
+ },
198
+ });
199
+ }));
200
+ }
161
201
  static async updatePendings(rewardTokenId, root, campaignId, toUpdate) {
162
202
  return await apiDbClient.$transaction(toUpdate.map(x => {
163
203
  return apiDbClient.rewardBreakdown.update({
@@ -170,7 +210,6 @@ export class RewardRepository {
170
210
  },
171
211
  data: {
172
212
  pending: x.pending,
173
- reason: x.reason,
174
213
  auxiliaryData1: x.auxiliaryData1,
175
214
  auxiliaryData2: x.auxiliaryData2,
176
215
  },
@@ -238,20 +238,23 @@ export class RewardService {
238
238
  distributionChain: data.distributionChainId,
239
239
  campaignId: data.campaignId,
240
240
  });
241
- const ids = (await RewardRepository.findManyBreakdownUniques(rewardTokenId, data.root, campaignId)).map(({ Reward, reason }) => Bun.hash(`${Reward.recipient}${reason}`).toString());
242
- const toUpdate = [];
243
- const toCreate = [];
244
- for (const point of data.data) {
245
- if (ids.includes(Bun.hash(`${point.recipient}${point.reason}`).toString())) {
246
- toUpdate.push(point);
247
- }
248
- else {
249
- toCreate.push(point);
250
- }
251
- }
252
- await RewardRepository.updatePendings(rewardTokenId, data.root, campaignId, toUpdate);
253
- await RewardRepository.createPendings(rewardTokenId, data.root, campaignId, toCreate);
254
- return { created: toCreate.length, updated: toUpdate.length };
241
+ // const ids = (await RewardRepository.findManyBreakdownUniques(rewardTokenId, data.root, campaignId)).map(
242
+ // ({ Reward, reason }) => Bun.hash(`${Reward.recipient}${reason}`).toString()
243
+ // );
244
+ // const toUpdate = [];
245
+ // const toCreate = [];
246
+ // for (const point of data.data) {
247
+ // if (ids.includes(Bun.hash(`${point.recipient}${point.reason}`).toString())) {
248
+ // toUpdate.push(point);
249
+ // } else {
250
+ // toCreate.push(point);
251
+ // }
252
+ // }
253
+ // await RewardRepository.updatePendings(rewardTokenId, data.root, campaignId, toUpdate);
254
+ // await RewardRepository.createPendings(rewardTokenId, data.root, campaignId, toCreate);
255
+ // return { created: toCreate.length, updated: toUpdate.length };
256
+ await RewardRepository.upsertPendings(rewardTokenId, data.root, campaignId, data.data);
257
+ return { created: data.data.length, updated: 0 };
255
258
  }
256
259
  static async countAllchains() {
257
260
  const rewardPerRewardTokenId = await RewardRepository.countRewardPerRewardTokenIdAndRoot();