@merkl/api 0.20.179 → 0.21.0
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.
- package/dist/database/api/.generated/edge.js +3 -3
- package/dist/database/api/.generated/index.js +3 -3
- package/dist/database/api/.generated/package.json +1 -1
- package/dist/database/api/.generated/schema.prisma +3 -3
- package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +1 -1
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +52 -33
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -212,7 +212,7 @@ model AprBreakdown {
|
|
212
212
|
identifier String
|
213
213
|
type AprType
|
214
214
|
value Float
|
215
|
-
AprRecord AprRecord @relation(fields: [aprRecordId], references: [id])
|
215
|
+
AprRecord AprRecord @relation(fields: [aprRecordId], references: [id], onDelete: Cascade)
|
216
216
|
aprRecordId String
|
217
217
|
|
218
218
|
@@index([aprRecordId], type: Hash)
|
@@ -237,7 +237,7 @@ model TVLBreakdown {
|
|
237
237
|
type TvlType
|
238
238
|
value Float // In case type is TOKEN, this is the raw amount of tokens
|
239
239
|
|
240
|
-
TvlRecord TVLRecord @relation(fields: [tvlRecordId], references: [id])
|
240
|
+
TvlRecord TVLRecord @relation(fields: [tvlRecordId], references: [id], onDelete: Cascade)
|
241
241
|
tvlRecordId String
|
242
242
|
|
243
243
|
@@index([tvlRecordId], type: Hash)
|
@@ -261,7 +261,7 @@ model DailyRewardsBreakdown {
|
|
261
261
|
value Float
|
262
262
|
campaignId String
|
263
263
|
Campaign Campaign @relation(fields: [campaignId], references: [id])
|
264
|
-
DailyRewardsRecord DailyRewardsRecord @relation(fields: [dailyRewardsRecordId], references: [id])
|
264
|
+
DailyRewardsRecord DailyRewardsRecord @relation(fields: [dailyRewardsRecordId], references: [id], onDelete: Cascade)
|
265
265
|
dailyRewardsRecordId String
|
266
266
|
|
267
267
|
@@index([dailyRewardsRecordId], type: Hash)
|
@@ -947,7 +947,7 @@ export declare abstract class OpportunityRepository {
|
|
947
947
|
* @returns
|
948
948
|
*/
|
949
949
|
static updateDynamicData(opportunityId: string, apr: AprRecord["model"], tvl: TvlRecord["model"], dailyRewards: DailyRewardsRecord["model"]): Promise<{
|
950
|
-
aprRecord:
|
950
|
+
aprRecord: {
|
951
951
|
id: string;
|
952
952
|
opportunityId: string;
|
953
953
|
timestamp: bigint;
|
@@ -5,7 +5,7 @@ import { TvlService } from "@/modules/v4/tvl/tvl.service";
|
|
5
5
|
import { log } from "@/utils/logger";
|
6
6
|
import { apiDbClient } from "@db";
|
7
7
|
import { Status } from "@db/api";
|
8
|
-
import { bigIntToNumber } from "@sdk";
|
8
|
+
import { DAY, bigIntToNumber } from "@sdk";
|
9
9
|
import moment from "moment";
|
10
10
|
export class OpportunityRepository {
|
11
11
|
// ─── Utils ───────────────────────────────────────────────────────────
|
@@ -407,8 +407,8 @@ export class OpportunityRepository {
|
|
407
407
|
* @returns
|
408
408
|
*/
|
409
409
|
static async updateDynamicData(opportunityId, apr, tvl, dailyRewards) {
|
410
|
-
const aprRecord
|
411
|
-
|
410
|
+
const [aprRecord, tvlRecord, dailyRewardsRecord, opportunity] = await apiDbClient.$transaction([
|
411
|
+
apiDbClient.aprRecord.create({
|
412
412
|
data: {
|
413
413
|
id: AprService.hashId(opportunityId, apr.timestamp),
|
414
414
|
timestamp: apr.timestamp,
|
@@ -416,38 +416,57 @@ export class OpportunityRepository {
|
|
416
416
|
Opportunity: { connect: { id: opportunityId } },
|
417
417
|
AprBreakdown: { createMany: { data: apr.breakdowns } },
|
418
418
|
},
|
419
|
-
})
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
419
|
+
}),
|
420
|
+
apiDbClient.tVLRecord.create({
|
421
|
+
data: {
|
422
|
+
id: TvlService.hashId(opportunityId, tvl.timestamp),
|
423
|
+
timestamp: tvl.timestamp,
|
424
|
+
Opportunity: { connect: { id: opportunityId } },
|
425
|
+
total: tvl.total,
|
426
|
+
TvlBreakdown: { createMany: { data: tvl.breakdowns } },
|
427
|
+
},
|
428
|
+
include: { TvlBreakdown: true },
|
429
|
+
}),
|
430
|
+
apiDbClient.dailyRewardsRecord.create({
|
431
|
+
data: {
|
432
|
+
id: RewardService.hashDailyRewardsRecordId(opportunityId, dailyRewards.timestamp),
|
433
|
+
timestamp: dailyRewards.timestamp,
|
434
|
+
Opportunity: { connect: { id: opportunityId } },
|
435
|
+
total: dailyRewards.total,
|
436
|
+
DailyRewardsBreakdown: {
|
437
|
+
createMany: {
|
438
|
+
data: dailyRewards.breakdowns.map(breakdown => ({
|
439
|
+
campaignId: breakdown.campaignId,
|
440
|
+
value: bigIntToNumber(breakdown.amount, breakdown.token.decimals),
|
441
|
+
})),
|
442
|
+
},
|
442
443
|
},
|
443
444
|
},
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
445
|
+
include: { DailyRewardsBreakdown: true },
|
446
|
+
}),
|
447
|
+
apiDbClient.opportunity.update({
|
448
|
+
where: { id: opportunityId },
|
449
|
+
data: { apr: apr.cumulated, tvl: tvl.total, dailyRewards: dailyRewards.total },
|
450
|
+
}),
|
451
|
+
apiDbClient.tVLRecord.deleteMany({
|
452
|
+
where: {
|
453
|
+
Opportunity: { id: opportunityId },
|
454
|
+
timestamp: { lt: tvl.timestamp, gt: Math.floor(moment().unix() / DAY) },
|
455
|
+
},
|
456
|
+
}),
|
457
|
+
apiDbClient.aprRecord.deleteMany({
|
458
|
+
where: {
|
459
|
+
Opportunity: { id: opportunityId },
|
460
|
+
timestamp: { lt: apr.timestamp, gt: Math.floor(moment().unix() / DAY) },
|
461
|
+
},
|
462
|
+
}),
|
463
|
+
apiDbClient.dailyRewardsRecord.deleteMany({
|
464
|
+
where: {
|
465
|
+
Opportunity: { id: opportunityId },
|
466
|
+
timestamp: { lt: dailyRewards.timestamp, gt: Math.floor(moment().unix() / DAY) },
|
467
|
+
},
|
468
|
+
}),
|
469
|
+
]);
|
451
470
|
return {
|
452
471
|
aprRecord,
|
453
472
|
tvlRecord,
|