@merkl/api 0.21.4 → 0.21.6
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 +2 -2
- package/dist/database/api/.generated/index.js +2 -2
- package/dist/database/api/.generated/package.json +1 -1
- package/dist/database/api/.generated/schema.prisma +1 -0
- package/dist/src/eden/index.d.ts +1110 -581
- package/dist/src/engine/deprecated/dynamicData/implementations/EventBased.js +2 -11
- package/dist/src/engine/deprecated/dynamicData/utils/getCompV2ForksVaults.js +10 -3
- package/dist/src/engine/implementations/MultiLog/tvl.js +33 -0
- package/dist/src/index.d.ts +448 -261
- package/dist/src/modules/v4/campaign/campaign.controller.d.ts +11 -2
- package/dist/src/modules/v4/campaign/campaign.controller.js +3 -3
- package/dist/src/modules/v4/campaign/campaign.repository.d.ts +44 -3
- package/dist/src/modules/v4/campaign/campaign.repository.js +46 -2
- package/dist/src/modules/v4/campaign/campaign.service.d.ts +36 -2
- package/dist/src/modules/v4/campaign/campaign.service.js +20 -8
- package/dist/src/modules/v4/creator/creator.controller.d.ts +236 -34
- package/dist/src/modules/v4/creator/creator.controller.js +28 -21
- package/dist/src/modules/v4/creator/creator.model.d.ts +29 -5
- package/dist/src/modules/v4/creator/creator.model.js +21 -1
- package/dist/src/modules/v4/creator/creator.repository.d.ts +52 -6
- package/dist/src/modules/v4/creator/creator.repository.js +16 -13
- package/dist/src/modules/v4/creator/creator.service.d.ts +161 -14
- package/dist/src/modules/v4/creator/creator.service.js +49 -11
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +1 -1
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +4 -3
- package/dist/src/modules/v4/programPayload/programPayload.model.d.ts +14 -1
- package/dist/src/modules/v4/programPayload/programPayload.repository.d.ts +68 -7
- package/dist/src/modules/v4/programPayload/programPayload.repository.js +240 -12
- package/dist/src/modules/v4/router.d.ts +448 -261
- package/dist/src/modules/v4/user/user.controller.d.ts +177 -192
- package/dist/src/modules/v4/user/user.controller.js +38 -56
- package/dist/src/modules/v4/user/user.model.d.ts +1 -1
- package/dist/src/modules/v4/user/user.model.js +1 -1
- package/dist/src/modules/v4/user/user.repository.d.ts +1 -1
- package/dist/src/modules/v4/user/user.repository.js +1 -1
- package/dist/src/modules/v4/user/user.service.d.ts +1 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +3 -2
@@ -1,36 +1,43 @@
|
|
1
|
-
import { NotFoundError } from "@/errors";
|
2
1
|
import { AuthorizationHeadersDto, BackOfficeGuard } from "@/guards/BackOffice.guard";
|
3
2
|
import { Elysia } from "elysia";
|
4
|
-
import {
|
3
|
+
import { CampaignIdDto, CampaignQueryDto, CreateCreatorDto, CreatorAddressDto, GetManyCreatorQuery, UpdateCreatorDto, } from "./creator.model";
|
5
4
|
import { CreatorService } from "./creator.service";
|
6
|
-
// ─── Creators Controller
|
5
|
+
// ─── Creators Controller ─────────────────────────────────────────────────────
|
7
6
|
export const CreatorController = new Elysia({ prefix: "/creators", detail: { tags: ["Creator"] } })
|
8
|
-
// ───
|
9
|
-
|
10
|
-
query: GetManyCreatorQuery,
|
11
|
-
})
|
12
|
-
// ─── Get A Creator By Id ───────────────────────────────────────────
|
13
|
-
.get("/:id", async ({ params: { id } }) => {
|
14
|
-
const creator = await CreatorService.findUnique(id);
|
15
|
-
if (!creator)
|
16
|
-
throw new NotFoundError();
|
17
|
-
return CreatorService.format(creator);
|
18
|
-
})
|
19
|
-
// ─── Create A Creator ───────────────────────────────────────────────────
|
7
|
+
// ─── Crud OPS ────────────────────────────────────────────────────────────────
|
8
|
+
// ─── Create A Creator ────────────────────────────────────────────────
|
20
9
|
.post("/", async ({ body }) => await CreatorService.create(body), {
|
21
10
|
headers: AuthorizationHeadersDto,
|
22
|
-
body:
|
11
|
+
body: CreateCreatorDto,
|
23
12
|
beforeHandle: BackOfficeGuard,
|
24
13
|
})
|
25
|
-
// ───
|
26
|
-
.
|
14
|
+
// ─── Get Many Creators ───────────────────────────────────────────────
|
15
|
+
.get("/", async ({ query }) => await CreatorService.findMany(query), { query: GetManyCreatorQuery })
|
16
|
+
// ─── Get A Unique Creator By Id ──────────────────────────────────────
|
17
|
+
.get("/:address", async ({ params: { address } }) => CreatorService.findUnique(address), {
|
18
|
+
params: CreatorAddressDto,
|
19
|
+
})
|
20
|
+
// ─── Update A Creator ────────────────────────────────────────────────
|
21
|
+
.patch("/:address", async ({ params: { address }, body }) => CreatorService.update(address, body), {
|
27
22
|
headers: AuthorizationHeadersDto,
|
28
23
|
body: UpdateCreatorDto,
|
24
|
+
params: CreatorAddressDto,
|
29
25
|
beforeHandle: BackOfficeGuard,
|
30
26
|
})
|
31
|
-
// ───
|
32
|
-
.
|
27
|
+
// ─── Delete A Creator ────────────────────────────────────────────────
|
28
|
+
.delete("/:address", async ({ params: { address } }) => CreatorService.delete(address), {
|
33
29
|
headers: AuthorizationHeadersDto,
|
34
|
-
|
30
|
+
params: CreatorAddressDto,
|
35
31
|
beforeHandle: BackOfficeGuard,
|
32
|
+
})
|
33
|
+
// ─── Service Specific Methods ────────────────────────────────────────────────
|
34
|
+
.get("/:address/dashboard", async ({ params }) => CreatorService.getGlobalDashboard(params.address), {
|
35
|
+
params: CreatorAddressDto,
|
36
|
+
})
|
37
|
+
.get("/:address/campaigns", async ({ params: { address }, query }) => CreatorService.getCampaignsFor(address, query.status), {
|
38
|
+
params: CreatorAddressDto,
|
39
|
+
query: CampaignQueryDto,
|
40
|
+
})
|
41
|
+
.get("/campaigns/:id", async ({ params: { id } }) => CreatorService.getCampaignMetrics(id), {
|
42
|
+
params: CampaignIdDto,
|
36
43
|
});
|
@@ -4,11 +4,7 @@ import type { Resource } from "@/modules/v4/prisma";
|
|
4
4
|
* @description A group of user that represent a campaign creator
|
5
5
|
* @see {@link Resource}
|
6
6
|
*/
|
7
|
-
export type Creator = Resource<"Creator"
|
8
|
-
icon?: string;
|
9
|
-
addresses: string[];
|
10
|
-
rebateFee?: number;
|
11
|
-
}>;
|
7
|
+
export type Creator = Resource<"Creator">;
|
12
8
|
export declare const CreatorDto: import("@sinclair/typebox").TObject<{
|
13
9
|
addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
14
10
|
icon: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
@@ -16,7 +12,14 @@ export declare const CreatorDto: import("@sinclair/typebox").TObject<{
|
|
16
12
|
name: import("@sinclair/typebox").TString;
|
17
13
|
rebateFee: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
18
14
|
}>;
|
15
|
+
export declare const CreateCreatorDto: import("@sinclair/typebox").TObject<{
|
16
|
+
id: import("@sinclair/typebox").TString;
|
17
|
+
addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
18
|
+
icon: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
19
|
+
name: import("@sinclair/typebox").TString;
|
20
|
+
}>;
|
19
21
|
export declare const GetManyCreatorQuery: import("@sinclair/typebox").TObject<{
|
22
|
+
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
20
23
|
address: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
21
24
|
page: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
22
25
|
items: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
@@ -26,6 +29,27 @@ export declare const UpdateCreatorDto: import("@sinclair/typebox").TObject<{
|
|
26
29
|
icon: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
27
30
|
name: import("@sinclair/typebox").TString;
|
28
31
|
}>;
|
32
|
+
export declare const CreatorAddressDto: import("@sinclair/typebox").TObject<{
|
33
|
+
address: import("@sinclair/typebox").TString;
|
34
|
+
}>;
|
35
|
+
export declare const CampaignIdDto: import("@sinclair/typebox").TObject<{
|
36
|
+
id: import("@sinclair/typebox").TString;
|
37
|
+
}>;
|
38
|
+
export declare const CampaignStatusDto: import("@sinclair/typebox").TEnum<{
|
39
|
+
PAST: "PAST";
|
40
|
+
LIVE: "LIVE";
|
41
|
+
FUTURE: "FUTURE";
|
42
|
+
}>;
|
43
|
+
export declare const CampaignQueryDto: import("@sinclair/typebox").TObject<{
|
44
|
+
status: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TEnum<{
|
45
|
+
PAST: "PAST";
|
46
|
+
LIVE: "LIVE";
|
47
|
+
FUTURE: "FUTURE";
|
48
|
+
}>>;
|
49
|
+
}>;
|
50
|
+
export declare const CreatorIdDto: import("@sinclair/typebox").TObject<{
|
51
|
+
id: import("@sinclair/typebox").TString;
|
52
|
+
}>;
|
29
53
|
export declare const UpdateCreatorRebateDto: import("@sinclair/typebox").TObject<{
|
30
54
|
rebate: import("@sinclair/typebox").TNumber;
|
31
55
|
}>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { t } from "elysia";
|
2
|
-
// ───
|
2
|
+
// ─── DTOs ────────────────────────────────────────────────────────────────────
|
3
3
|
export const CreatorDto = t.Object({
|
4
4
|
addresses: t.Array(t.String()),
|
5
5
|
icon: t.Optional(t.String()),
|
@@ -7,7 +7,14 @@ export const CreatorDto = t.Object({
|
|
7
7
|
name: t.String(),
|
8
8
|
rebateFee: t.Optional(t.Number({ maximum: 100, minimum: 0 })),
|
9
9
|
});
|
10
|
+
export const CreateCreatorDto = t.Object({
|
11
|
+
id: t.String(),
|
12
|
+
addresses: t.Array(t.String()),
|
13
|
+
icon: t.Optional(t.String()),
|
14
|
+
name: t.String(),
|
15
|
+
});
|
10
16
|
export const GetManyCreatorQuery = t.Object({
|
17
|
+
id: t.Optional(t.String()),
|
11
18
|
address: t.Optional(t.String()),
|
12
19
|
page: t.Optional(t.Number()),
|
13
20
|
items: t.Optional(t.Number()),
|
@@ -17,6 +24,19 @@ export const UpdateCreatorDto = t.Object({
|
|
17
24
|
icon: t.Optional(t.String()),
|
18
25
|
name: t.String(),
|
19
26
|
});
|
27
|
+
export const CreatorAddressDto = t.Object({
|
28
|
+
address: t.String(),
|
29
|
+
});
|
30
|
+
export const CampaignIdDto = t.Object({
|
31
|
+
id: t.String(),
|
32
|
+
});
|
33
|
+
export const CampaignStatusDto = t.Enum({ PAST: "PAST", LIVE: "LIVE", FUTURE: "FUTURE" });
|
34
|
+
export const CampaignQueryDto = t.Object({
|
35
|
+
status: t.Optional(CampaignStatusDto),
|
36
|
+
});
|
37
|
+
export const CreatorIdDto = t.Object({
|
38
|
+
id: t.String(),
|
39
|
+
});
|
20
40
|
export const UpdateCreatorRebateDto = t.Object({
|
21
41
|
rebate: t.Number({ maximum: 100, minimum: 0 }),
|
22
42
|
});
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { Creator, GetManyCreatorModel, UpdateCreatorDto } from "./creator.model";
|
1
|
+
import type { CreateCreatorDto, Creator, GetManyCreatorModel, UpdateCreatorDto } from "./creator.model";
|
2
2
|
export declare abstract class CreatorRepository {
|
3
|
-
static findUnique(id: Creator["model"]["id"]): Promise<
|
3
|
+
static findUnique(id: Creator["model"]["id"]): Promise<{
|
4
4
|
Users: {
|
5
5
|
tags: string[];
|
6
6
|
address: string;
|
@@ -11,7 +11,7 @@ export declare abstract class CreatorRepository {
|
|
11
11
|
id: string;
|
12
12
|
icon: string | null;
|
13
13
|
rebateFee: number;
|
14
|
-
}
|
14
|
+
}>;
|
15
15
|
static findUniqueFromAddress(address: string): Promise<{
|
16
16
|
name: string;
|
17
17
|
id: string;
|
@@ -20,9 +20,7 @@ export declare abstract class CreatorRepository {
|
|
20
20
|
} | null>;
|
21
21
|
static findMany(query: GetManyCreatorModel): Promise<({
|
22
22
|
Users: {
|
23
|
-
tags: string[];
|
24
23
|
address: string;
|
25
|
-
creatorId: string | null;
|
26
24
|
}[];
|
27
25
|
} & {
|
28
26
|
name: string;
|
@@ -30,7 +28,7 @@ export declare abstract class CreatorRepository {
|
|
30
28
|
icon: string | null;
|
31
29
|
rebateFee: number;
|
32
30
|
})[]>;
|
33
|
-
static create({ addresses, ...creator }:
|
31
|
+
static create({ addresses, ...creator }: typeof CreateCreatorDto.static): Promise<{
|
34
32
|
name: string;
|
35
33
|
id: string;
|
36
34
|
icon: string | null;
|
@@ -42,6 +40,54 @@ export declare abstract class CreatorRepository {
|
|
42
40
|
icon: string | null;
|
43
41
|
rebateFee: number;
|
44
42
|
}>;
|
43
|
+
static delete(id: Creator["model"]["id"]): Promise<{
|
44
|
+
name: string;
|
45
|
+
id: string;
|
46
|
+
icon: string | null;
|
47
|
+
rebateFee: number;
|
48
|
+
}>;
|
49
|
+
static getCampaignsFor(creatorAddress: string): Promise<({
|
50
|
+
Opportunity: {
|
51
|
+
status: import("@db/api").$Enums.Status;
|
52
|
+
type: string;
|
53
|
+
name: string;
|
54
|
+
description: string;
|
55
|
+
id: string;
|
56
|
+
tags: string[];
|
57
|
+
identifier: string;
|
58
|
+
action: import("@db/api").$Enums.OpportunityAction;
|
59
|
+
manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
|
60
|
+
chainId: number;
|
61
|
+
howToSteps: string[];
|
62
|
+
depositUrl: string | null;
|
63
|
+
explorerAddress: string | null;
|
64
|
+
mainProtocolId: string | null;
|
65
|
+
tvl: number;
|
66
|
+
apr: number;
|
67
|
+
dailyRewards: number;
|
68
|
+
lastCampaignCreatedAt: Date;
|
69
|
+
};
|
70
|
+
} & {
|
71
|
+
type: string;
|
72
|
+
description: string | null;
|
73
|
+
id: string;
|
74
|
+
params: import("database/api/.generated/runtime/library").JsonValue;
|
75
|
+
subType: number | null;
|
76
|
+
computeChainId: number;
|
77
|
+
distributionChainId: number;
|
78
|
+
campaignId: string;
|
79
|
+
distributionType: import("@db/api").$Enums.DistributionType;
|
80
|
+
rewardTokenId: string;
|
81
|
+
amount: string;
|
82
|
+
opportunityId: string;
|
83
|
+
startTimestamp: bigint;
|
84
|
+
endTimestamp: bigint;
|
85
|
+
creatorAddress: string;
|
86
|
+
manualOverrides: import("@db/api").$Enums.CampaignManualOverride[];
|
87
|
+
createdAt: Date;
|
88
|
+
rootCampaignId: string | null;
|
89
|
+
parentCampaignId: string | null;
|
90
|
+
})[]>;
|
45
91
|
static updateRebate(id: Creator["model"]["id"], rebate: number): Promise<{
|
46
92
|
name: string;
|
47
93
|
id: string;
|
@@ -2,26 +2,27 @@ import { apiDbClient } from "@db";
|
|
2
2
|
// ─── Users Repository ────────────────────────────────────────────────────────
|
3
3
|
export class CreatorRepository {
|
4
4
|
static async findUnique(id) {
|
5
|
-
return await apiDbClient.creator.
|
5
|
+
return await apiDbClient.creator.findUniqueOrThrow({ where: { id }, include: { Users: true } });
|
6
6
|
}
|
7
7
|
static async findUniqueFromAddress(address) {
|
8
8
|
const creator = await apiDbClient.user.findUnique({ where: { address: address }, select: { Creator: true } });
|
9
9
|
return creator?.Creator ?? null;
|
10
10
|
}
|
11
11
|
static async findMany(query) {
|
12
|
-
const { page: _page, items: _items, ...filters } = query;
|
12
|
+
const { page: _page, items: _items, address, ...filters } = query;
|
13
13
|
const page = _page ? _page : 0;
|
14
14
|
const items = _items ? _items : 20;
|
15
15
|
return await apiDbClient.creator.findMany({
|
16
16
|
take: items,
|
17
17
|
skip: page * items,
|
18
|
-
include: { Users: true },
|
18
|
+
include: { Users: { select: { address: true } } },
|
19
19
|
where: {
|
20
|
-
|
20
|
+
...filters,
|
21
|
+
Users: address
|
21
22
|
? {
|
22
23
|
some: {
|
23
24
|
address: {
|
24
|
-
equals:
|
25
|
+
equals: address,
|
25
26
|
},
|
26
27
|
},
|
27
28
|
}
|
@@ -33,14 +34,7 @@ export class CreatorRepository {
|
|
33
34
|
return await apiDbClient.creator.create({
|
34
35
|
data: {
|
35
36
|
...creator,
|
36
|
-
Users: {
|
37
|
-
connectOrCreate: addresses.map(address => ({
|
38
|
-
create: {
|
39
|
-
address,
|
40
|
-
},
|
41
|
-
where: { address },
|
42
|
-
})),
|
43
|
-
},
|
37
|
+
Users: { connectOrCreate: addresses.map(address => ({ create: { address }, where: { address } })) },
|
44
38
|
},
|
45
39
|
});
|
46
40
|
}
|
@@ -60,6 +54,15 @@ export class CreatorRepository {
|
|
60
54
|
},
|
61
55
|
});
|
62
56
|
}
|
57
|
+
static async delete(id) {
|
58
|
+
return await apiDbClient.creator.delete({ where: { id } });
|
59
|
+
}
|
60
|
+
static async getCampaignsFor(creatorAddress) {
|
61
|
+
return await apiDbClient.campaign.findMany({
|
62
|
+
where: { creatorAddress },
|
63
|
+
include: { Opportunity: true },
|
64
|
+
});
|
65
|
+
}
|
63
66
|
static async updateRebate(id, rebate) {
|
64
67
|
return await apiDbClient.creator.update({ where: { id }, data: { rebateFee: rebate } });
|
65
68
|
}
|
@@ -1,17 +1,11 @@
|
|
1
|
-
import type { Creator, GetManyCreatorModel, UpdateCreatorDto, UpdateCreatorRebateDto } from "./creator.model";
|
1
|
+
import type { CreateCreatorDto, Creator, GetManyCreatorModel, UpdateCreatorDto, UpdateCreatorRebateDto } from "./creator.model";
|
2
2
|
export declare abstract class CreatorService {
|
3
|
-
/**
|
4
|
-
* Format creator into its model
|
5
|
-
* @param id
|
6
|
-
* @returns creator
|
7
|
-
*/
|
8
|
-
static format({ Users, icon, ...creator }: NonNullable<Awaited<ReturnType<typeof CreatorService.findUnique>>>): Creator["model"];
|
9
3
|
/**
|
10
4
|
* Finds a creator from its id (i.e. "uniswap")
|
11
5
|
* @param id
|
12
6
|
* @returns creator
|
13
7
|
*/
|
14
|
-
static findUnique(id: Creator["model"]["id"]): Promise<
|
8
|
+
static findUnique(id: Creator["model"]["id"]): Promise<{
|
15
9
|
Users: {
|
16
10
|
tags: string[];
|
17
11
|
address: string;
|
@@ -22,17 +16,15 @@ export declare abstract class CreatorService {
|
|
22
16
|
id: string;
|
23
17
|
icon: string | null;
|
24
18
|
rebateFee: number;
|
25
|
-
}
|
19
|
+
}>;
|
26
20
|
/**
|
27
|
-
* Finds many
|
21
|
+
* Finds many creators
|
28
22
|
* @param id
|
29
|
-
* @returns
|
23
|
+
* @returns creators[]
|
30
24
|
*/
|
31
25
|
static findMany(query: GetManyCreatorModel): Promise<({
|
32
26
|
Users: {
|
33
|
-
tags: string[];
|
34
27
|
address: string;
|
35
|
-
creatorId: string | null;
|
36
28
|
}[];
|
37
29
|
} & {
|
38
30
|
name: string;
|
@@ -44,7 +36,7 @@ export declare abstract class CreatorService {
|
|
44
36
|
* Creates a creator
|
45
37
|
* @param creator {addresses, id, name}
|
46
38
|
*/
|
47
|
-
static create(creator:
|
39
|
+
static create(creator: typeof CreateCreatorDto.static): Promise<{
|
48
40
|
name: string;
|
49
41
|
id: string;
|
50
42
|
icon: string | null;
|
@@ -62,6 +54,161 @@ export declare abstract class CreatorService {
|
|
62
54
|
icon: string | null;
|
63
55
|
rebateFee: number;
|
64
56
|
}>;
|
57
|
+
static delete(id: Creator["model"]["id"]): Promise<{
|
58
|
+
name: string;
|
59
|
+
id: string;
|
60
|
+
icon: string | null;
|
61
|
+
rebateFee: number;
|
62
|
+
}>;
|
63
|
+
static getCreatorIdFromAddress(address: string): Promise<string | null>;
|
64
|
+
static getCreatorAddresses(id: Creator["model"]["id"]): Promise<string[]>;
|
65
|
+
static getGlobalDashboard(creatorAddress: string): Promise<{
|
66
|
+
pastCampaigns: number;
|
67
|
+
liveCampaigns: number;
|
68
|
+
futureCampaigns: number;
|
69
|
+
incentivizedTvl: number;
|
70
|
+
totalCampaigns: number;
|
71
|
+
creatorId: string | null;
|
72
|
+
}>;
|
73
|
+
static getCampaignsFor(creatorAddress: string, status?: "PAST" | "LIVE" | "FUTURE"): Promise<({
|
74
|
+
Opportunity: {
|
75
|
+
status: import("@db/api").$Enums.Status;
|
76
|
+
type: string;
|
77
|
+
name: string;
|
78
|
+
description: string;
|
79
|
+
id: string;
|
80
|
+
tags: string[];
|
81
|
+
identifier: string;
|
82
|
+
action: import("@db/api").$Enums.OpportunityAction;
|
83
|
+
manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
|
84
|
+
chainId: number;
|
85
|
+
howToSteps: string[];
|
86
|
+
depositUrl: string | null;
|
87
|
+
explorerAddress: string | null;
|
88
|
+
mainProtocolId: string | null;
|
89
|
+
tvl: number;
|
90
|
+
apr: number;
|
91
|
+
dailyRewards: number;
|
92
|
+
lastCampaignCreatedAt: Date;
|
93
|
+
};
|
94
|
+
} & {
|
95
|
+
type: string;
|
96
|
+
description: string | null;
|
97
|
+
id: string;
|
98
|
+
params: import("database/api/.generated/runtime/library").JsonValue;
|
99
|
+
subType: number | null;
|
100
|
+
computeChainId: number;
|
101
|
+
distributionChainId: number;
|
102
|
+
campaignId: string;
|
103
|
+
distributionType: import("@db/api").$Enums.DistributionType;
|
104
|
+
rewardTokenId: string;
|
105
|
+
amount: string;
|
106
|
+
opportunityId: string;
|
107
|
+
startTimestamp: bigint;
|
108
|
+
endTimestamp: bigint;
|
109
|
+
creatorAddress: string;
|
110
|
+
manualOverrides: import("@db/api").$Enums.CampaignManualOverride[];
|
111
|
+
createdAt: Date;
|
112
|
+
rootCampaignId: string | null;
|
113
|
+
parentCampaignId: string | null;
|
114
|
+
})[] | {
|
115
|
+
params: any;
|
116
|
+
chain: {
|
117
|
+
name: string;
|
118
|
+
id: number;
|
119
|
+
icon: string;
|
120
|
+
};
|
121
|
+
endTimestamp: number;
|
122
|
+
startTimestamp: number;
|
123
|
+
rewardToken: {
|
124
|
+
symbol: string;
|
125
|
+
name: string | null;
|
126
|
+
id: string;
|
127
|
+
icon: string;
|
128
|
+
address: string;
|
129
|
+
chainId: number;
|
130
|
+
decimals: number;
|
131
|
+
verified: boolean;
|
132
|
+
isTest: boolean;
|
133
|
+
isPoint: boolean;
|
134
|
+
isPreTGE: boolean;
|
135
|
+
isNative: boolean;
|
136
|
+
} & {
|
137
|
+
price?: number | null | undefined;
|
138
|
+
};
|
139
|
+
distributionChain: {
|
140
|
+
name: string;
|
141
|
+
id: number;
|
142
|
+
icon: string;
|
143
|
+
} | undefined;
|
144
|
+
campaignStatus: {
|
145
|
+
computedUntil: number;
|
146
|
+
processingStarted: number;
|
147
|
+
status: import("@db/api").$Enums.RunStatus;
|
148
|
+
error: string;
|
149
|
+
details: import("database/api/.generated/runtime/library").JsonValue;
|
150
|
+
campaignId: string;
|
151
|
+
} | undefined;
|
152
|
+
creatorAddress: string;
|
153
|
+
creator: {
|
154
|
+
tags: string[];
|
155
|
+
address: string;
|
156
|
+
creatorId: string | null;
|
157
|
+
};
|
158
|
+
createdAt: string;
|
159
|
+
description: string | undefined;
|
160
|
+
parentCampaignId: string | undefined;
|
161
|
+
rootCampaignId: string | undefined;
|
162
|
+
Opportunity: {
|
163
|
+
status: import("@db/api").$Enums.Status;
|
164
|
+
type: string;
|
165
|
+
name: string;
|
166
|
+
description: string;
|
167
|
+
id: string;
|
168
|
+
tags: string[];
|
169
|
+
identifier: string;
|
170
|
+
action: import("@db/api").$Enums.OpportunityAction;
|
171
|
+
manualOverrides: import("@db/api").$Enums.OpportunityManualOverride[];
|
172
|
+
chainId: number;
|
173
|
+
howToSteps: string[];
|
174
|
+
depositUrl: string | null;
|
175
|
+
explorerAddress: string | null;
|
176
|
+
mainProtocolId: string | null;
|
177
|
+
tvl: number;
|
178
|
+
apr: number;
|
179
|
+
dailyRewards: number;
|
180
|
+
lastCampaignCreatedAt: Date;
|
181
|
+
};
|
182
|
+
type: string;
|
183
|
+
id: string;
|
184
|
+
subType: number | null;
|
185
|
+
computeChainId: number;
|
186
|
+
distributionChainId: number;
|
187
|
+
campaignId: string;
|
188
|
+
distributionType: import("@db/api").$Enums.DistributionType;
|
189
|
+
rewardTokenId: string;
|
190
|
+
amount: string;
|
191
|
+
opportunityId: string;
|
192
|
+
}[]>;
|
193
|
+
static getCampaignMetrics(campaignId: string): Promise<{
|
194
|
+
tvlRecords: {
|
195
|
+
total: number;
|
196
|
+
timestamp: bigint;
|
197
|
+
}[];
|
198
|
+
aprRecords: {
|
199
|
+
timestamp: bigint;
|
200
|
+
apr: number;
|
201
|
+
}[];
|
202
|
+
dailyRewardsRecords: {
|
203
|
+
total: number;
|
204
|
+
timestamp: bigint;
|
205
|
+
}[];
|
206
|
+
walletCount: {
|
207
|
+
timestamp: bigint;
|
208
|
+
walletCount: number;
|
209
|
+
}[];
|
210
|
+
tvlInflowPerDollar: bigint;
|
211
|
+
}>;
|
65
212
|
static updateRebate(id: Creator["model"]["id"], rebate: UpdateCreatorRebateDto["rebate"]): Promise<{
|
66
213
|
name: string;
|
67
214
|
id: string;
|
@@ -1,14 +1,10 @@
|
|
1
|
+
import { TTLPresets } from "../cache/cache.model";
|
2
|
+
import { CacheService } from "../cache/cache.service";
|
3
|
+
import { CampaignService } from "../campaign/campaign.service";
|
4
|
+
import { UserService } from "../user/user.service";
|
1
5
|
import { CreatorRepository } from "./creator.repository";
|
2
|
-
// ─── Creators
|
6
|
+
// ─── Creators Service ────────────────────────────────────────────────────────
|
3
7
|
export class CreatorService {
|
4
|
-
/**
|
5
|
-
* Format creator into its model
|
6
|
-
* @param id
|
7
|
-
* @returns creator
|
8
|
-
*/
|
9
|
-
static format({ Users, icon, ...creator }) {
|
10
|
-
return { ...creator, addresses: Users.map(({ address }) => address), icon: icon ?? undefined };
|
11
|
-
}
|
12
8
|
/**
|
13
9
|
* Finds a creator from its id (i.e. "uniswap")
|
14
10
|
* @param id
|
@@ -18,9 +14,9 @@ export class CreatorService {
|
|
18
14
|
return await CreatorRepository.findUnique(id);
|
19
15
|
}
|
20
16
|
/**
|
21
|
-
* Finds many
|
17
|
+
* Finds many creators
|
22
18
|
* @param id
|
23
|
-
* @returns
|
19
|
+
* @returns creators[]
|
24
20
|
*/
|
25
21
|
static async findMany(query) {
|
26
22
|
return await CreatorRepository.findMany(query);
|
@@ -41,6 +37,48 @@ export class CreatorService {
|
|
41
37
|
static async update(id, creator) {
|
42
38
|
return await CreatorRepository.update(id, creator);
|
43
39
|
}
|
40
|
+
static async delete(id) {
|
41
|
+
return await CreatorRepository.delete(id);
|
42
|
+
}
|
43
|
+
static async getCreatorIdFromAddress(address) {
|
44
|
+
return await CacheService.wrap(TTLPresets.MIN_30, async () => (await UserService.findUnique(address)).creatorId);
|
45
|
+
}
|
46
|
+
static async getCreatorAddresses(id) {
|
47
|
+
const creator = await CreatorRepository.findUnique(id);
|
48
|
+
return creator.Users.map(user => user.address);
|
49
|
+
}
|
50
|
+
static async getGlobalDashboard(creatorAddress) {
|
51
|
+
const [pastCampaigns, liveCampaigns, futureCampaigns, creatorId] = await Promise.all([
|
52
|
+
CampaignService.getPastCampaigns({ creatorAddress }),
|
53
|
+
CampaignService.getLiveCampaigns({ creatorAddress }),
|
54
|
+
CampaignService.getFutureCampaigns({ creatorAddress }),
|
55
|
+
CreatorService.getCreatorIdFromAddress(creatorAddress),
|
56
|
+
]);
|
57
|
+
const incentivizedTvl = liveCampaigns.reduce((acc, campaign) => acc + campaign.Opportunity.tvl, 0);
|
58
|
+
return {
|
59
|
+
pastCampaigns: pastCampaigns.length,
|
60
|
+
liveCampaigns: liveCampaigns.length,
|
61
|
+
futureCampaigns: futureCampaigns.length,
|
62
|
+
incentivizedTvl,
|
63
|
+
totalCampaigns: pastCampaigns.length + liveCampaigns.length + futureCampaigns.length,
|
64
|
+
creatorId,
|
65
|
+
};
|
66
|
+
}
|
67
|
+
static async getCampaignsFor(creatorAddress, status) {
|
68
|
+
switch (status) {
|
69
|
+
case "PAST":
|
70
|
+
return CampaignService.getPastCampaigns({ creatorAddress });
|
71
|
+
case "LIVE":
|
72
|
+
return CampaignService.getLiveCampaigns({ creatorAddress });
|
73
|
+
case "FUTURE":
|
74
|
+
return CampaignService.getFutureCampaigns({ creatorAddress });
|
75
|
+
default:
|
76
|
+
return CampaignService.findMany({ creatorAddress });
|
77
|
+
}
|
78
|
+
}
|
79
|
+
static async getCampaignMetrics(campaignId) {
|
80
|
+
return await CampaignService.getMetrics(campaignId);
|
81
|
+
}
|
44
82
|
static async updateRebate(id, rebate) {
|
45
83
|
return await CreatorRepository.updateRebate(id, rebate);
|
46
84
|
}
|
@@ -51,7 +51,7 @@ export class DynamicDataService {
|
|
51
51
|
identifier: r.campaign.mainParameter,
|
52
52
|
type: CampaignType[+type],
|
53
53
|
})));
|
54
|
-
const now = moment().unix();
|
54
|
+
const now = moment().utc().unix();
|
55
55
|
const updates = [];
|
56
56
|
for (const opportunityId of opportunityIds) {
|
57
57
|
const recordsForOpportunity = records.filter(r => OpportunityService.hashId({
|
@@ -407,6 +407,7 @@ export class OpportunityRepository {
|
|
407
407
|
* @returns
|
408
408
|
*/
|
409
409
|
static async updateDynamicData(opportunityId, apr, tvl, dailyRewards) {
|
410
|
+
const startOfTheDay = Math.floor(moment().unix() / DAY) * DAY;
|
410
411
|
const [aprRecord, tvlRecord, dailyRewardsRecord, opportunity] = await apiDbClient.$transaction([
|
411
412
|
apiDbClient.aprRecord.create({
|
412
413
|
data: {
|
@@ -451,19 +452,19 @@ export class OpportunityRepository {
|
|
451
452
|
apiDbClient.tVLRecord.deleteMany({
|
452
453
|
where: {
|
453
454
|
Opportunity: { id: opportunityId },
|
454
|
-
timestamp: { lt: tvl.timestamp,
|
455
|
+
timestamp: { lt: tvl.timestamp, gte: startOfTheDay },
|
455
456
|
},
|
456
457
|
}),
|
457
458
|
apiDbClient.aprRecord.deleteMany({
|
458
459
|
where: {
|
459
460
|
Opportunity: { id: opportunityId },
|
460
|
-
timestamp: { lt: apr.timestamp,
|
461
|
+
timestamp: { lt: apr.timestamp, gte: startOfTheDay },
|
461
462
|
},
|
462
463
|
}),
|
463
464
|
apiDbClient.dailyRewardsRecord.deleteMany({
|
464
465
|
where: {
|
465
466
|
Opportunity: { id: opportunityId },
|
466
|
-
timestamp: { lt: dailyRewards.timestamp,
|
467
|
+
timestamp: { lt: dailyRewards.timestamp, gte: startOfTheDay },
|
467
468
|
},
|
468
469
|
}),
|
469
470
|
]);
|