@merkl/api 0.16.9 → 0.16.10
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/src/eden/index.d.ts +5 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/modules/v4/campaign/campaign.controller.d.ts +1 -0
- package/dist/src/modules/v4/campaign/campaign.repository.d.ts +3 -3
- package/dist/src/modules/v4/campaign/campaign.repository.js +5 -13
- package/dist/src/modules/v4/campaign/campaign.service.d.ts +14 -7
- package/dist/src/modules/v4/campaign/campaign.service.js +38 -32
- package/dist/src/modules/v4/dynamicData/dynamicData.service.d.ts +1 -1
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +3 -3
- package/dist/src/modules/v4/router.d.ts +1 -0
- package/dist/src/modules/v4/status/status.repository.d.ts +9 -2
- package/dist/src/modules/v4/status/status.repository.js +22 -11
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/eden/index.d.ts
CHANGED
@@ -1048,6 +1048,7 @@ declare const eden: {
|
|
1048
1048
|
campaignId: string;
|
1049
1049
|
CampaignStatus: {
|
1050
1050
|
computedUntil: bigint;
|
1051
|
+
processingStarted: bigint;
|
1051
1052
|
}[];
|
1052
1053
|
}[];
|
1053
1054
|
}>>;
|
@@ -4160,6 +4161,7 @@ declare const eden: {
|
|
4160
4161
|
campaignId: string;
|
4161
4162
|
CampaignStatus: {
|
4162
4163
|
computedUntil: bigint;
|
4164
|
+
processingStarted: bigint;
|
4163
4165
|
}[];
|
4164
4166
|
}[];
|
4165
4167
|
}>>;
|
@@ -8126,6 +8128,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
8126
8128
|
campaignId: string;
|
8127
8129
|
CampaignStatus: {
|
8128
8130
|
computedUntil: bigint;
|
8131
|
+
processingStarted: bigint;
|
8129
8132
|
}[];
|
8130
8133
|
}[];
|
8131
8134
|
};
|
@@ -12735,6 +12738,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
12735
12738
|
campaignId: string;
|
12736
12739
|
CampaignStatus: {
|
12737
12740
|
computedUntil: bigint;
|
12741
|
+
processingStarted: bigint;
|
12738
12742
|
}[];
|
12739
12743
|
}[];
|
12740
12744
|
}>>;
|
@@ -15847,6 +15851,7 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
|
|
15847
15851
|
campaignId: string;
|
15848
15852
|
CampaignStatus: {
|
15849
15853
|
computedUntil: bigint;
|
15854
|
+
processingStarted: bigint;
|
15850
15855
|
}[];
|
15851
15856
|
}[];
|
15852
15857
|
}>>;
|
package/dist/src/index.d.ts
CHANGED
@@ -107,9 +107,8 @@ export declare abstract class CampaignRepository {
|
|
107
107
|
mainParameter: string;
|
108
108
|
campaignParameters: import("database/engine/.generated/runtime/library").JsonValue;
|
109
109
|
}[]>;
|
110
|
-
static checkIfExist(
|
111
|
-
static
|
112
|
-
static findUnique(campaign: CampaignUnique): Promise<{
|
110
|
+
static checkIfExist(id: string): Promise<boolean>;
|
111
|
+
static findUnique(id: string): Promise<{
|
113
112
|
type: string;
|
114
113
|
id: string;
|
115
114
|
params: Prisma.JsonValue;
|
@@ -144,6 +143,7 @@ export declare abstract class CampaignRepository {
|
|
144
143
|
campaignId: string;
|
145
144
|
CampaignStatus: {
|
146
145
|
computedUntil: bigint;
|
146
|
+
processingStarted: bigint;
|
147
147
|
}[];
|
148
148
|
}[]>;
|
149
149
|
static findMany(query: GetCampaignQueryModel): Promise<({
|
@@ -195,17 +195,7 @@ export class CampaignRepository {
|
|
195
195
|
},
|
196
196
|
});
|
197
197
|
}
|
198
|
-
static async checkIfExist(
|
199
|
-
return !!(await apiDbClient.campaign.findFirst({
|
200
|
-
select: {
|
201
|
-
id: true,
|
202
|
-
},
|
203
|
-
where: {
|
204
|
-
id: CampaignService.hashId(campaign),
|
205
|
-
},
|
206
|
-
}));
|
207
|
-
}
|
208
|
-
static async checkIfIdExist(id) {
|
198
|
+
static async checkIfExist(id) {
|
209
199
|
return !!(await apiDbClient.campaign.findFirst({
|
210
200
|
select: {
|
211
201
|
id: true,
|
@@ -215,10 +205,10 @@ export class CampaignRepository {
|
|
215
205
|
},
|
216
206
|
}));
|
217
207
|
}
|
218
|
-
static async findUnique(
|
208
|
+
static async findUnique(id) {
|
219
209
|
return await apiDbClient.campaign.findUnique({
|
220
210
|
where: {
|
221
|
-
id
|
211
|
+
id,
|
222
212
|
},
|
223
213
|
});
|
224
214
|
}
|
@@ -247,6 +237,7 @@ export class CampaignRepository {
|
|
247
237
|
status: {
|
248
238
|
not: RunStatus.PROCESSING,
|
249
239
|
},
|
240
|
+
computedUntil: { lt: currentTime }, // more than 10 min ago
|
250
241
|
},
|
251
242
|
{
|
252
243
|
status: RunStatus.PROCESSING,
|
@@ -266,6 +257,7 @@ export class CampaignRepository {
|
|
266
257
|
take: 1,
|
267
258
|
select: {
|
268
259
|
computedUntil: true,
|
260
|
+
processingStarted: true,
|
269
261
|
},
|
270
262
|
},
|
271
263
|
},
|
@@ -19,6 +19,14 @@ export declare abstract class CampaignService {
|
|
19
19
|
opportunityId: string;
|
20
20
|
creatorAddress: string;
|
21
21
|
} | undefined>;
|
22
|
+
static createMany(campaigns: Omit<CreateCampaignModel, "id">[], upsert?: boolean): Promise<{
|
23
|
+
success: number;
|
24
|
+
fail: number;
|
25
|
+
}>;
|
26
|
+
/**
|
27
|
+
* @dev back-office function
|
28
|
+
* @dev deprecated should be replaced with a manual override
|
29
|
+
*/
|
22
30
|
static updateMetaData(campaign: Omit<UpdateMetaDataCampaignModel, "id">): Promise<{
|
23
31
|
type: string;
|
24
32
|
id: string;
|
@@ -34,11 +42,10 @@ export declare abstract class CampaignService {
|
|
34
42
|
opportunityId: string;
|
35
43
|
creatorAddress: string;
|
36
44
|
}>;
|
45
|
+
/**
|
46
|
+
* @dev back-office function
|
47
|
+
*/
|
37
48
|
static moveToOpportunity(campaign: Omit<UpdateCampaignModel, "id">, upsert?: boolean): Promise<string>;
|
38
|
-
static createMany(campaigns: Omit<CreateCampaignModel, "id">[], upsert?: boolean): Promise<{
|
39
|
-
success: number;
|
40
|
-
fail: number;
|
41
|
-
}>;
|
42
49
|
/**
|
43
50
|
* Get the list of campaigns satisfying the query
|
44
51
|
* @param query
|
@@ -103,9 +110,8 @@ export declare abstract class CampaignService {
|
|
103
110
|
*/
|
104
111
|
static countMany(query: GetCampaignQueryModel): Promise<number>;
|
105
112
|
static countLives(chainId: number): Promise<number>;
|
106
|
-
static checkIfExist(campaign: CampaignUnique): Promise<boolean>;
|
107
|
-
static
|
108
|
-
static findUnique(campaign: CampaignUnique): Promise<{
|
113
|
+
static checkIfExist(campaign: CampaignUnique | string): Promise<boolean>;
|
114
|
+
static findUnique(campaign: CampaignUnique | string): Promise<{
|
109
115
|
type: string;
|
110
116
|
id: string;
|
111
117
|
params: import("database/api/.generated/runtime/library").JsonValue;
|
@@ -140,6 +146,7 @@ export declare abstract class CampaignService {
|
|
140
146
|
campaignId: string;
|
141
147
|
CampaignStatus: {
|
142
148
|
computedUntil: bigint;
|
149
|
+
processingStarted: bigint;
|
143
150
|
}[];
|
144
151
|
}[]>;
|
145
152
|
static findNextCampaignToProcess(chainId: ChainId): Promise<{
|
@@ -26,6 +26,31 @@ export class CampaignService {
|
|
26
26
|
await OpportunityService.createFromCampaign(campaign);
|
27
27
|
return await CampaignRepository.upsert({ id, ...campaign });
|
28
28
|
}
|
29
|
+
static async createMany(campaigns, upsert = false) {
|
30
|
+
const failedToFetchMetadata = [];
|
31
|
+
const campaignsToInsert = [];
|
32
|
+
await Promise.all(campaigns.map(async (campaign) => {
|
33
|
+
const id = CampaignService.hashId({ distributionChain: campaign.chainId, campaignId: campaign.campaignId });
|
34
|
+
campaign.computeChainId = campaign.computeChainId === 0 ? campaign.chainId : campaign.computeChainId;
|
35
|
+
try {
|
36
|
+
if (upsert || !(await CampaignService.checkIfExist(id))) {
|
37
|
+
await OpportunityService.createFromCampaign(campaign);
|
38
|
+
campaignsToInsert.push({ id, ...campaign });
|
39
|
+
}
|
40
|
+
}
|
41
|
+
catch (err) {
|
42
|
+
log.error(`Cannot get Opportunity metadata for campaign ${campaign.campaignId} of type ${campaign.type}`, err);
|
43
|
+
failedToFetchMetadata.push(campaign);
|
44
|
+
}
|
45
|
+
}));
|
46
|
+
let { success, fail } = await CampaignRepository.upsertMany(campaignsToInsert);
|
47
|
+
fail += failedToFetchMetadata.length;
|
48
|
+
return { success, fail };
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* @dev back-office function
|
52
|
+
* @dev deprecated should be replaced with a manual override
|
53
|
+
*/
|
29
54
|
static async updateMetaData(campaign) {
|
30
55
|
const id = CampaignService.hashId({
|
31
56
|
distributionChain: campaign.distributionChain,
|
@@ -39,6 +64,9 @@ export class CampaignService {
|
|
39
64
|
const updatedParams = JSON.stringify(params);
|
40
65
|
return await CampaignRepository.updateMetaData(id, updatedParams);
|
41
66
|
}
|
67
|
+
/**
|
68
|
+
* @dev back-office function
|
69
|
+
*/
|
42
70
|
static async moveToOpportunity(campaign, upsert = false) {
|
43
71
|
const id = CampaignService.hashId({
|
44
72
|
distributionChain: campaign.distributionChain,
|
@@ -87,31 +115,6 @@ export class CampaignService {
|
|
87
115
|
// Return new opportunityId
|
88
116
|
return (await CampaignService.findUniqueOrThrow(campaign)).opportunityId;
|
89
117
|
}
|
90
|
-
static async createMany(campaigns, upsert = false) {
|
91
|
-
const failedToFetchMetadata = [];
|
92
|
-
const campaignsToInsert = [];
|
93
|
-
await Promise.all(campaigns.map(async (campaign) => {
|
94
|
-
const id = CampaignService.hashId({ distributionChain: campaign.chainId, campaignId: campaign.campaignId });
|
95
|
-
campaign.computeChainId = campaign.computeChainId === 0 ? campaign.chainId : campaign.computeChainId;
|
96
|
-
try {
|
97
|
-
if (upsert || !(await CampaignService.checkIfIdExist(id))) {
|
98
|
-
await OpportunityService.createFromCampaign(campaign);
|
99
|
-
campaignsToInsert.push({ id, ...campaign });
|
100
|
-
}
|
101
|
-
// } else {
|
102
|
-
// console.log("Updating status from campaign");
|
103
|
-
// await OpportunityService.updateStatusFromCampaign(campaign);
|
104
|
-
// }
|
105
|
-
}
|
106
|
-
catch (err) {
|
107
|
-
log.error(`Cannot get Opportunity metadata for campaign ${campaign.campaignId} of type ${campaign.type}`, err);
|
108
|
-
failedToFetchMetadata.push(campaign);
|
109
|
-
}
|
110
|
-
}));
|
111
|
-
let { success, fail } = await CampaignRepository.upsertMany(campaignsToInsert);
|
112
|
-
fail += failedToFetchMetadata.length;
|
113
|
-
return { success, fail };
|
114
|
-
}
|
115
118
|
/**
|
116
119
|
* Get the list of campaigns satisfying the query
|
117
120
|
* @param query
|
@@ -140,24 +143,27 @@ export class CampaignService {
|
|
140
143
|
return await CampaignRepository.countLives(chainId);
|
141
144
|
}
|
142
145
|
static async checkIfExist(campaign) {
|
143
|
-
|
144
|
-
|
145
|
-
static async checkIfIdExist(id) {
|
146
|
-
return await CampaignRepository.checkIfIdExist(id);
|
146
|
+
const id = typeof campaign === "string" ? campaign : CampaignService.hashId(campaign);
|
147
|
+
return await CampaignRepository.checkIfExist(id);
|
147
148
|
}
|
148
149
|
static async findUnique(campaign) {
|
149
|
-
|
150
|
+
const id = typeof campaign === "string" ? campaign : CampaignService.hashId(campaign);
|
151
|
+
return await CampaignRepository.findUnique(id);
|
150
152
|
}
|
151
153
|
static async findUniqueOrThrow(campaign) {
|
152
154
|
const id = typeof campaign === "string" ? campaign : CampaignService.hashId(campaign);
|
153
155
|
return await CampaignRepository.findUniqueOrThrow(id);
|
154
156
|
}
|
155
157
|
static async findCampaignsToProcess(distributionChainId) {
|
156
|
-
return (await CampaignRepository.findCampaignsToProcess(distributionChainId))
|
158
|
+
return (await CampaignRepository.findCampaignsToProcess(distributionChainId))
|
159
|
+
.filter(campaign => campaign.endTimestamp > campaign?.CampaignStatus?.[0]?.computedUntil)
|
160
|
+
?.sort((a, b) => Number(a.CampaignStatus?.[0]?.processingStarted - b.CampaignStatus?.[0]?.processingStarted));
|
157
161
|
}
|
158
162
|
static async findNextCampaignToProcess(chainId) {
|
159
163
|
const campaigns = await CampaignService.findCampaignsToProcess(chainId);
|
160
|
-
return {
|
164
|
+
return {
|
165
|
+
campaignId: campaigns?.[0]?.campaignId,
|
166
|
+
};
|
161
167
|
}
|
162
168
|
static async pickCampaignToProcess(chainId) {
|
163
169
|
const campaigns = await CampaignService.findCampaignsToProcess(chainId);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type ChainId } from "@sdk";
|
2
|
-
import {
|
2
|
+
import type { GetCampaignQueryModel } from "../campaign";
|
3
3
|
import type { FilledCampaignDtoModel, SimplifiedCampaignDtoModel } from "./dynamicData.model";
|
4
4
|
export declare class DynamicDataService {
|
5
5
|
#private;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { campaignsDynamicData } from "../../../libs/campaigns/campaignsDynamicData";
|
2
|
+
import { CampaignRepository } from "../campaign/campaign.repository";
|
3
|
+
import { CampaignService } from "../campaign/campaign.service";
|
4
|
+
import { OpportunityService } from "../opportunity/opportunity.service";
|
2
5
|
import { executeSimple } from "../../../utils/execute";
|
3
6
|
import { log } from "../../../utils/logger";
|
4
7
|
import { Campaign, NETWORK_LABELS } from "@sdk";
|
5
8
|
import { utils } from "ethers";
|
6
|
-
import { CampaignService } from "../campaign";
|
7
|
-
import { CampaignRepository } from "../campaign/campaign.repository";
|
8
|
-
import { OpportunityService } from "../opportunity";
|
9
9
|
export class DynamicDataService {
|
10
10
|
static async queryERC20DynamicData(chainId, tokenAddress, decimals = 18) {
|
11
11
|
const campaigns = [
|
@@ -59,14 +59,21 @@ export declare class StatusRepository {
|
|
59
59
|
computedUntil: bigint;
|
60
60
|
processingStarted: bigint;
|
61
61
|
}>;
|
62
|
-
static updateProcessing(campaignUnique: CampaignUnique): Promise<{
|
62
|
+
static updateProcessing(campaignUnique: CampaignUnique): Promise<[{
|
63
63
|
error: string;
|
64
64
|
details: Prisma.JsonValue;
|
65
65
|
status: import("../../../../database/api/.generated").$Enums.RunStatus;
|
66
66
|
campaignId: string;
|
67
67
|
computedUntil: bigint;
|
68
68
|
processingStarted: bigint;
|
69
|
-
}
|
69
|
+
}, {
|
70
|
+
error: string;
|
71
|
+
details: Prisma.JsonValue;
|
72
|
+
status: import("../../../../database/api/.generated").$Enums.RunStatus;
|
73
|
+
campaignId: string;
|
74
|
+
computedUntil: bigint;
|
75
|
+
processingStarted: bigint;
|
76
|
+
}]>;
|
70
77
|
static findManyDelay(query: DelayModel): Promise<{
|
71
78
|
startTimestamp: bigint;
|
72
79
|
endTimestamp: bigint;
|
@@ -71,17 +71,28 @@ export class StatusRepository {
|
|
71
71
|
});
|
72
72
|
}
|
73
73
|
static async updateProcessing(campaignUnique) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
},
|
84
|
-
|
74
|
+
const campaignId = CampaignService.hashId(campaignUnique);
|
75
|
+
return await apiDbClient.$transaction([
|
76
|
+
apiDbClient.campaignStatus.findUniqueOrThrow({
|
77
|
+
where: {
|
78
|
+
campaignId,
|
79
|
+
status: {
|
80
|
+
not: "PROCESSING",
|
81
|
+
},
|
82
|
+
},
|
83
|
+
}),
|
84
|
+
apiDbClient.campaignStatus.update({
|
85
|
+
where: {
|
86
|
+
campaignId,
|
87
|
+
},
|
88
|
+
data: {
|
89
|
+
status: "PROCESSING",
|
90
|
+
processingStarted: moment().unix(),
|
91
|
+
error: "",
|
92
|
+
details: "{}",
|
93
|
+
},
|
94
|
+
}),
|
95
|
+
]);
|
85
96
|
}
|
86
97
|
static async findManyDelay(query) {
|
87
98
|
return await apiDbClient.campaign.findMany({
|